Changeset 213295 in webkit
- Timestamp:
- Mar 2, 2017, 12:35:37 PM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r213294 r213295 1 2017-03-02 Mark Lam <mark.lam@apple.com> 2 3 Add support for selective handling of VM traps. 4 https://bugs.webkit.org/show_bug.cgi?id=169087 5 6 Reviewed by Keith Miller. 7 8 This is needed because there are some places in the VM where it's appropriate to 9 handle some types of VM traps but not others. 10 11 We implement this selection by using a VMTraps::Mask that allows the user to 12 specify which traps should be serviced. 13 14 * interpreter/Interpreter.cpp: 15 (JSC::Interpreter::executeProgram): 16 (JSC::Interpreter::executeCall): 17 (JSC::Interpreter::executeConstruct): 18 (JSC::Interpreter::execute): 19 * runtime/VM.cpp: 20 (JSC::VM::handleTraps): 21 * runtime/VM.h: 22 * runtime/VMTraps.cpp: 23 (JSC::VMTraps::takeTrap): Deleted. 24 * runtime/VMTraps.h: 25 (JSC::VMTraps::Mask::Mask): 26 (JSC::VMTraps::Mask::allEventTypes): 27 (JSC::VMTraps::Mask::bits): 28 (JSC::VMTraps::Mask::init): 29 (JSC::VMTraps::needTrapHandling): 30 (JSC::VMTraps::hasTrapForEvent): 31 1 32 2017-03-02 Alex Christensen <achristensen@webkit.org> 2 33 -
trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
r213107 r213295 862 862 863 863 if (UNLIKELY(vm.needTrapHandling())) { 864 vm.handleTraps(callFrame); 864 VMTraps::Mask mask(VMTraps::NeedTermination, VMTraps::NeedWatchdogCheck); 865 vm.handleTraps(callFrame, mask); 865 866 RETURN_IF_EXCEPTION(throwScope, throwScope.exception()); 866 867 } … … 922 923 923 924 if (UNLIKELY(vm.needTrapHandling())) { 924 vm.handleTraps(callFrame); 925 VMTraps::Mask mask(VMTraps::NeedTermination, VMTraps::NeedWatchdogCheck); 926 vm.handleTraps(callFrame, mask); 925 927 RETURN_IF_EXCEPTION(throwScope, throwScope.exception()); 926 928 } … … 987 989 988 990 if (UNLIKELY(vm.needTrapHandling())) { 989 vm.handleTraps(callFrame); 991 VMTraps::Mask mask(VMTraps::NeedTermination, VMTraps::NeedWatchdogCheck); 992 vm.handleTraps(callFrame, mask); 990 993 RETURN_IF_EXCEPTION(throwScope, throwScope.exception()); 991 994 } … … 1051 1054 1052 1055 if (UNLIKELY(vm.needTrapHandling())) { 1053 vm.handleTraps(closure.oldCallFrame); 1056 VMTraps::Mask mask(VMTraps::NeedTermination, VMTraps::NeedWatchdogCheck); 1057 vm.handleTraps(closure.oldCallFrame, mask); 1054 1058 RETURN_IF_EXCEPTION(throwScope, throwScope.exception()); 1055 1059 } … … 1154 1158 1155 1159 if (UNLIKELY(vm.needTrapHandling())) { 1156 vm.handleTraps(callFrame); 1160 VMTraps::Mask mask(VMTraps::NeedTermination, VMTraps::NeedWatchdogCheck); 1161 vm.handleTraps(callFrame, mask); 1157 1162 RETURN_IF_EXCEPTION(throwScope, throwScope.exception()); 1158 1163 } … … 1195 1200 1196 1201 if (UNLIKELY(vm.needTrapHandling())) { 1197 vm.handleTraps(callFrame); 1202 VMTraps::Mask mask(VMTraps::NeedTermination, VMTraps::NeedWatchdogCheck); 1203 vm.handleTraps(callFrame, mask); 1198 1204 RETURN_IF_EXCEPTION(throwScope, throwScope.exception()); 1199 1205 } -
trunk/Source/JavaScriptCore/runtime/VM.cpp
r213238 r213295 947 947 #endif 948 948 949 void VM::handleTraps(ExecState* exec )949 void VM::handleTraps(ExecState* exec, VMTraps::Mask mask) 950 950 { 951 951 auto scope = DECLARE_THROW_SCOPE(*this); 952 952 953 ASSERT(needTrapHandling( ));954 while (needTrapHandling( )) {955 auto trapEventType = m_traps.takeTopPriorityTrap( );953 ASSERT(needTrapHandling(mask)); 954 while (needTrapHandling(mask)) { 955 auto trapEventType = m_traps.takeTopPriorityTrap(mask); 956 956 switch (trapEventType) { 957 case VMTraps::NeedDebuggerBreak: 958 RELEASE_ASSERT_NOT_REACHED(); 959 957 960 case VMTraps::NeedWatchdogCheck: 958 961 ASSERT(m_watchdog); -
trunk/Source/JavaScriptCore/runtime/VM.h
r213238 r213295 672 672 void logEvent(CodeBlock*, const char* summary, const Func& func); 673 673 674 void handleTraps(ExecState* );675 676 bool needTrapHandling( ) { return m_traps.needTrapHandling(); }674 void handleTraps(ExecState*, VMTraps::Mask = VMTraps::Mask::allEventTypes()); 675 676 bool needTrapHandling(VMTraps::Mask mask = VMTraps::Mask::allEventTypes()) { return m_traps.needTrapHandling(mask); } 677 677 void* needTrapHandlingAddress() { return m_traps.needTrapHandlingAddress(); } 678 678 -
trunk/Source/JavaScriptCore/runtime/VMTraps.cpp
r213107 r213295 35 35 } 36 36 37 bool VMTraps::takeTrap(VMTraps::EventType eventType) 37 auto VMTraps::takeTopPriorityTrap(VMTraps::Mask mask) -> EventType 38 38 { 39 39 auto locker = holdLock(m_lock); 40 if (hasTrapForEvent(locker, eventType)) {41 clearTrapForEvent(locker, eventType);42 return true;43 }44 return false;45 }46 47 auto VMTraps::takeTopPriorityTrap() -> EventType48 {49 40 for (int i = 0; i < NumberOfEventTypes; ++i) { 50 41 EventType eventType = static_cast<EventType>(i); 51 if (takeTrap(eventType)) 42 if (hasTrapForEvent(locker, eventType, mask)) { 43 clearTrapForEvent(locker, eventType); 52 44 return eventType; 45 } 53 46 } 54 47 return Invalid; -
trunk/Source/JavaScriptCore/runtime/VMTraps.h
r213107 r213295 34 34 35 35 class VMTraps { 36 typedef uint8_t BitField; 36 37 public: 37 38 enum EventType { 38 39 // Sorted in servicing priority order from highest to lowest. 40 NeedDebuggerBreak, 39 41 NeedTermination, 40 42 NeedWatchdogCheck, … … 43 45 }; 44 46 45 bool needTrapHandling() { return m_needTrapHandling; } 47 class Mask { 48 public: 49 enum AllEventTypes { AllEventTypesTag }; 50 Mask(AllEventTypes) 51 : m_mask(std::numeric_limits<BitField>::max()) 52 { } 53 static Mask allEventTypes() { return Mask(AllEventTypesTag); } 54 55 template<typename... Arguments> 56 Mask(Arguments... args) 57 : m_mask(0) 58 { 59 init(args...); 60 } 61 62 BitField bits() const { return m_mask; } 63 64 private: 65 template<typename... Arguments> 66 void init(EventType eventType, Arguments... args) 67 { 68 ASSERT(eventType < NumberOfEventTypes); 69 m_mask |= (1 << eventType); 70 init(args...); 71 } 72 73 void init() { } 74 75 BitField m_mask; 76 }; 77 78 bool needTrapHandling(Mask mask) { return m_needTrapHandling & mask.bits(); } 46 79 void* needTrapHandlingAddress() { return &m_needTrapHandling; } 47 80 48 81 JS_EXPORT_PRIVATE void fireTrap(EventType); 49 82 50 bool takeTrap(EventType); 51 EventType takeTopPriorityTrap(); 83 EventType takeTopPriorityTrap(Mask); 52 84 53 85 private: 54 86 VM& vm() const; 55 87 56 bool hasTrapForEvent(Locker<Lock>&, EventType eventType )88 bool hasTrapForEvent(Locker<Lock>&, EventType eventType, Mask mask) 57 89 { 58 90 ASSERT(eventType < NumberOfEventTypes); 59 return (m_trapsBitField & (1 << eventType));91 return (m_trapsBitField & mask.bits() & (1 << eventType)); 60 92 } 61 93 void setTrapForEvent(Locker<Lock>&, EventType eventType) … … 72 104 Lock m_lock; 73 105 union { 74 uint8_t m_needTrapHandling { false};75 uint8_tm_trapsBitField;106 BitField m_needTrapHandling { 0 }; 107 BitField m_trapsBitField; 76 108 }; 77 109
Note:
See TracChangeset
for help on using the changeset viewer.