Changeset 222009 in webkit for trunk/Source/JavaScriptCore/assembler
- Timestamp:
- Sep 13, 2017, 9:21:05 PM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore/assembler
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/assembler/MacroAssembler.cpp
r221832 r222009 39 39 static void stdFunctionCallback(Probe::Context& context) 40 40 { 41 auto func = context.arg<const std::function<void(Probe::Context&)>*>();41 auto func = static_cast<const std::function<void(Probe::Context&)>*>(context.arg); 42 42 (*func)(context); 43 43 } -
trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp
r221832 r222009 176 176 { 177 177 auto& out = WTF::dataFile(); 178 PrintRecordList& list = * probeContext.arg<PrintRecordList*>();178 PrintRecordList& list = *reinterpret_cast<PrintRecordList*>(probeContext.arg); 179 179 for (size_t i = 0; i < list.size(); i++) { 180 180 auto& record = list[i]; -
trunk/Source/JavaScriptCore/assembler/ProbeContext.h
r221832 r222009 46 46 inline double& fpr(FPRegisterID); 47 47 48 template<typename T> T gpr(RegisterID) const; 49 template<typename T> T spr(SPRegisterID) const; 48 template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr> 49 T gpr(RegisterID) const; 50 template<typename T, typename std::enable_if<std::is_pointer<T>::value>::type* = nullptr> 51 T gpr(RegisterID) const; 52 template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr> 53 T spr(SPRegisterID) const; 54 template<typename T, typename std::enable_if<std::is_pointer<T>::value>::type* = nullptr> 55 T spr(SPRegisterID) const; 50 56 template<typename T> T fpr(FPRegisterID) const; 51 57 … … 80 86 } 81 87 82 template<typename T >88 template<typename T, typename std::enable_if<std::is_integral<T>::value>::type*> 83 89 T CPUState::gpr(RegisterID id) const 84 90 { 85 91 CPUState* cpu = const_cast<CPUState*>(this); 86 auto& from = cpu->gpr(id); 87 typename std::remove_const<T>::type to { }; 88 std::memcpy(&to, &from, sizeof(to)); // Use std::memcpy to avoid strict aliasing issues. 89 return to; 90 } 91 92 template<typename T> 92 return static_cast<T>(cpu->gpr(id)); 93 } 94 95 template<typename T, typename std::enable_if<std::is_pointer<T>::value>::type*> 96 T CPUState::gpr(RegisterID id) const 97 { 98 CPUState* cpu = const_cast<CPUState*>(this); 99 return reinterpret_cast<T>(cpu->gpr(id)); 100 } 101 102 template<typename T, typename std::enable_if<std::is_integral<T>::value>::type*> 93 103 T CPUState::spr(SPRegisterID id) const 94 104 { 95 105 CPUState* cpu = const_cast<CPUState*>(this); 96 auto& from = cpu->spr(id); 97 typename std::remove_const<T>::type to { }; 98 std::memcpy(&to, &from, sizeof(to)); // Use std::memcpy to avoid strict aliasing issues. 99 return to; 106 return static_cast<T>(cpu->spr(id)); 107 } 108 109 template<typename T, typename std::enable_if<std::is_pointer<T>::value>::type*> 110 T CPUState::spr(SPRegisterID id) const 111 { 112 CPUState* cpu = const_cast<CPUState*>(this); 113 return reinterpret_cast<T>(cpu->spr(id)); 100 114 } 101 115 … … 192 206 193 207 Context(State* state) 194 : cpu(state->cpu) 195 , m_state(state) 208 : m_state(state) 209 , arg(state->arg) 210 , cpu(state->cpu) 196 211 { } 197 212 198 template<typename T> 199 T arg() { return reinterpret_cast<T>(m_state->arg); } 200 201 uintptr_t& gpr(RegisterID id) { return cpu.gpr(id); } 202 uintptr_t& spr(SPRegisterID id) { return cpu.spr(id); } 203 double& fpr(FPRegisterID id) { return cpu.fpr(id); } 204 const char* gprName(RegisterID id) { return cpu.gprName(id); } 205 const char* sprName(SPRegisterID id) { return cpu.sprName(id); } 206 const char* fprName(FPRegisterID id) { return cpu.fprName(id); } 207 208 template<typename T> T gpr(RegisterID id) const { return cpu.gpr<T>(id); } 209 template<typename T> T spr(SPRegisterID id) const { return cpu.spr<T>(id); } 210 template<typename T> T fpr(FPRegisterID id) const { return cpu.fpr<T>(id); } 211 212 void*& pc() { return cpu.pc(); } 213 void*& fp() { return cpu.fp(); } 214 void*& sp() { return cpu.sp(); } 215 216 template<typename T> T pc() { return cpu.pc<T>(); } 217 template<typename T> T fp() { return cpu.fp<T>(); } 218 template<typename T> T sp() { return cpu.sp<T>(); } 213 uintptr_t& gpr(RegisterID id) { return m_state->cpu.gpr(id); } 214 uintptr_t& spr(SPRegisterID id) { return m_state->cpu.spr(id); } 215 double& fpr(FPRegisterID id) { return m_state->cpu.fpr(id); } 216 const char* gprName(RegisterID id) { return m_state->cpu.gprName(id); } 217 const char* sprName(SPRegisterID id) { return m_state->cpu.sprName(id); } 218 const char* fprName(FPRegisterID id) { return m_state->cpu.fprName(id); } 219 220 void*& pc() { return m_state->cpu.pc(); } 221 void*& fp() { return m_state->cpu.fp(); } 222 void*& sp() { return m_state->cpu.sp(); } 223 224 template<typename T> T pc() { return m_state->cpu.pc<T>(); } 225 template<typename T> T fp() { return m_state->cpu.fp<T>(); } 226 template<typename T> T sp() { return m_state->cpu.sp<T>(); } 219 227 220 228 Stack& stack() … … 227 235 Stack* releaseStack() { return new Stack(WTFMove(m_stack)); } 228 236 229 CPUState& cpu;230 231 237 private: 232 238 State* m_state; 239 public: 240 void* arg; 241 CPUState& cpu; 242 243 private: 233 244 Stack m_stack; 234 245 -
trunk/Source/JavaScriptCore/assembler/ProbeStack.cpp
r221832 r222009 36 36 Page::Page(void* baseAddress) 37 37 : m_baseLogicalAddress(baseAddress) 38 , m_physicalAddressOffset(reinterpret_cast<uint8_t*>(&m_buffer) - reinterpret_cast<uint8_t*>(baseAddress))39 38 { 40 39 memcpy(&m_buffer, baseAddress, s_pageSize); -
trunk/Source/JavaScriptCore/assembler/ProbeStack.h
r221832 r222009 57 57 T get(void* logicalAddress) 58 58 { 59 void* from = physicalAddressFor(logicalAddress); 60 typename std::remove_const<T>::type to { }; 61 std::memcpy(&to, from, sizeof(to)); // Use std::memcpy to avoid strict aliasing issues. 62 return to; 63 } 64 template<typename T> 65 T get(void* logicalBaseAddress, ptrdiff_t offset) 66 { 67 return get<T>(reinterpret_cast<uint8_t*>(logicalBaseAddress) + offset); 59 return *physicalAddressFor<T*>(logicalAddress); 68 60 } 69 61 … … 72 64 { 73 65 m_dirtyBits |= dirtyBitFor(logicalAddress); 74 void* to = physicalAddressFor(logicalAddress); 75 std::memcpy(to, &value, sizeof(T)); // Use std::memcpy to avoid strict aliasing issues. 76 } 77 template<typename T> 78 void set(void* logicalBaseAddress, ptrdiff_t offset, T value) 79 { 80 set<T>(reinterpret_cast<uint8_t*>(logicalBaseAddress) + offset, value); 66 *physicalAddressFor<T*>(logicalAddress) = value; 81 67 } 82 68 … … 95 81 } 96 82 97 void* physicalAddressFor(void* logicalAddress) 83 template<typename T, typename = typename std::enable_if<std::is_pointer<T>::value>::type> 84 T physicalAddressFor(void* logicalAddress) 98 85 { 99 return reinterpret_cast<uint8_t*>(logicalAddress) + m_physicalAddressOffset; 86 uintptr_t offset = reinterpret_cast<uintptr_t>(logicalAddress) & s_pageMask; 87 void* physicalAddress = reinterpret_cast<uint8_t*>(&m_buffer) + offset; 88 return reinterpret_cast<T>(physicalAddress); 100 89 } 101 90 … … 104 93 void* m_baseLogicalAddress { nullptr }; 105 94 uintptr_t m_dirtyBits { 0 }; 106 ptrdiff_t m_physicalAddressOffset;107 95 108 96 static constexpr size_t s_pageSize = 1024; … … 133 121 Stack(Stack&& other); 134 122 135 void* lowWatermark() 136 { 137 // We use the chunkAddress for the low watermark because we'll be doing write backs 138 // to the stack in increments of chunks. Hence, we'll treat the lowest address of 139 // the chunk as the low watermark of any given set address. 140 return Page::chunkAddressFor(m_lowWatermark); 141 } 123 void* lowWatermark() { return m_lowWatermark; } 142 124 143 125 template<typename T> 144 Tget(void* address)126 typename std::enable_if<!std::is_same<double, typename std::remove_cv<T>::type>::value, T>::type get(void* address) 145 127 { 146 128 Page* page = pageFor(address); 147 129 return page->get<T>(address); 148 130 } 149 template<typename T>150 T get(void* logicalBaseAddress, ptrdiff_t offset)151 {152 return get<T>(reinterpret_cast<uint8_t*>(logicalBaseAddress) + offset);153 }154 131 155 template<typename T >132 template<typename T, typename = typename std::enable_if<!std::is_same<double, typename std::remove_cv<T>::type>::value>::type> 156 133 void set(void* address, T value) 157 134 { … … 159 136 page->set<T>(address, value); 160 137 161 if (address < m_lowWatermark) 162 m_lowWatermark = address; 138 // We use the chunkAddress for the low watermark because we'll be doing write backs 139 // to the stack in increments of chunks. Hence, we'll treat the lowest address of 140 // the chunk as the low watermark of any given set address. 141 void* chunkAddress = Page::chunkAddressFor(address); 142 if (chunkAddress < m_lowWatermark) 143 m_lowWatermark = chunkAddress; 163 144 } 145 164 146 template<typename T> 165 void set(void* logicalBaseAddress, ptrdiff_t offset, T value)147 typename std::enable_if<std::is_same<double, typename std::remove_cv<T>::type>::value, T>::type get(void* address) 166 148 { 167 set<T>(reinterpret_cast<uint8_t*>(logicalBaseAddress) + offset, value); 149 Page* page = pageFor(address); 150 return bitwise_cast<double>(page->get<uint64_t>(address)); 151 } 152 153 template<typename T, typename = typename std::enable_if<std::is_same<double, typename std::remove_cv<T>::type>::value>::type> 154 void set(void* address, double value) 155 { 156 set<uint64_t>(address, bitwise_cast<uint64_t>(value)); 168 157 } 169 158
Note:
See TracChangeset
for help on using the changeset viewer.