Safepoints.h (4253B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef jit_Safepoints_h 8 #define jit_Safepoints_h 9 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include "jit/BitSet.h" 14 #include "jit/CompactBuffer.h" 15 #include "jit/RegisterSets.h" 16 17 namespace js { 18 namespace jit { 19 20 class CodeLocationLabel; 21 class IonScript; 22 class SafepointIndex; 23 struct SafepointSlotEntry; 24 class TempAllocator; 25 26 class LAllocation; 27 class LSafepoint; 28 29 static const uint32_t INVALID_SAFEPOINT_OFFSET = uint32_t(-1); 30 31 class SafepointWriter { 32 CompactBufferWriter stream_; 33 BitSet localSlots_; 34 BitSet argumentSlots_; 35 36 public: 37 explicit SafepointWriter(uint32_t localSlotsSize, uint32_t argumentsSize); 38 [[nodiscard]] bool init(TempAllocator& alloc); 39 40 private: 41 // A safepoint entry is written in the order these functions appear. 42 uint32_t startEntry(); 43 44 void writeOsiCallPointOffset(uint32_t osiPointOffset); 45 void writeGcRegs(LSafepoint* safepoint); 46 void writeGcSlots(LSafepoint* safepoint); 47 48 void writeSlotsOrElementsSlots(LSafepoint* safepoint); 49 void writeWasmAnyRefSlots(LSafepoint* safepoint); 50 51 #ifdef JS_PUNBOX64 52 void writeValueSlots(LSafepoint* safepoint); 53 #else 54 void writeNunboxParts(LSafepoint* safepoint); 55 #endif 56 57 void endEntry(); 58 59 public: 60 void encode(LSafepoint* safepoint); 61 62 size_t size() const { return stream_.length(); } 63 const uint8_t* buffer() const { return stream_.buffer(); } 64 bool oom() const { return stream_.oom(); } 65 }; 66 67 class SafepointReader { 68 CompactBufferReader stream_; 69 uint32_t localSlots_; 70 uint32_t argumentSlots_; 71 uint32_t currentSlotChunk_; 72 bool currentSlotsAreStack_; 73 uint32_t nextSlotChunkNumber_; 74 uint32_t osiCallPointOffset_; 75 GeneralRegisterSet gcSpills_; 76 GeneralRegisterSet valueSpills_; 77 GeneralRegisterSet slotsOrElementsSpills_; 78 GeneralRegisterSet allGprSpills_; 79 GeneralRegisterSet wasmAnyRefSpills_; 80 FloatRegisterSet allFloatSpills_; 81 uint32_t nunboxSlotsRemaining_; 82 uint32_t slotsOrElementsSlotsRemaining_; 83 uint32_t wasmAnyRefSlotsRemaining_; 84 85 private: 86 void advanceFromGcRegs(); 87 void advanceFromGcSlots(); 88 void advanceFromNunboxOrValueSlots(); 89 void advanceFromSlotsOrElementsSlots(); 90 [[nodiscard]] bool getSlotFromBitmap(SafepointSlotEntry* entry); 91 92 public: 93 SafepointReader(IonScript* script, const SafepointIndex* si); 94 95 static CodeLocationLabel InvalidationPatchPoint(IonScript* script, 96 const SafepointIndex* si); 97 98 uint32_t osiCallPointOffset() const { return osiCallPointOffset_; } 99 LiveGeneralRegisterSet gcSpills() const { 100 return LiveGeneralRegisterSet(gcSpills_); 101 } 102 LiveGeneralRegisterSet slotsOrElementsSpills() const { 103 return LiveGeneralRegisterSet(slotsOrElementsSpills_); 104 } 105 LiveGeneralRegisterSet wasmAnyRefSpills() const { 106 return LiveGeneralRegisterSet(wasmAnyRefSpills_); 107 } 108 LiveGeneralRegisterSet valueSpills() const { 109 return LiveGeneralRegisterSet(valueSpills_); 110 } 111 LiveGeneralRegisterSet allGprSpills() const { 112 return LiveGeneralRegisterSet(allGprSpills_); 113 } 114 LiveFloatRegisterSet allFloatSpills() const { 115 return LiveFloatRegisterSet(allFloatSpills_); 116 } 117 uint32_t osiReturnPointOffset() const; 118 119 // Returns true if a slot was read, false if there are no more slots. 120 [[nodiscard]] bool getGcSlot(SafepointSlotEntry* entry); 121 122 // Returns true if a slot was read, false if there are no more value slots. 123 [[nodiscard]] bool getValueSlot(SafepointSlotEntry* entry); 124 125 // Returns true if a nunbox slot was read, false if there are no more 126 // nunbox slots. 127 [[nodiscard]] bool getNunboxSlot(LAllocation* type, LAllocation* payload); 128 129 // Returns true if a slot was read, false if there are no more slots. 130 [[nodiscard]] bool getSlotsOrElementsSlot(SafepointSlotEntry* entry); 131 132 // Returns true if a slot was read, false if there are no more slots. 133 [[nodiscard]] bool getWasmAnyRefSlot(SafepointSlotEntry* entry); 134 }; 135 136 } // namespace jit 137 } // namespace js 138 139 #endif /* jit_Safepoints_h */