InterpreterEntryTrampoline.h (2388B)
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_InterpreterEntryTrampoline_h 8 #define jit_InterpreterEntryTrampoline_h 9 10 #include "gc/Barrier.h" 11 #include "gc/Tracer.h" 12 #include "jit/JitCode.h" 13 #include "js/AllocPolicy.h" 14 #include "js/HashTable.h" 15 #include "js/RootingAPI.h" 16 17 namespace js { 18 19 void ClearInterpreterEntryMap(JSRuntime* runtime); 20 21 namespace jit { 22 23 /* 24 * The EntryTrampolineMap is used to cache the trampoline code for 25 * each script as they are created. These trampolines are created 26 * only under --emit-interpreter-entry and are used to identify which 27 * script is being interpeted when profiling with external profilers 28 * such as perf. 29 * 30 * The map owns the JitCode objects that are created for each script, 31 * and keeps them alive at least as long as the script associated 32 * with it in case we need to re-enter the trampoline again. 33 * 34 * As each script is finalized, the entry is manually removed from 35 * the table in BaseScript::finalize which will also release the 36 * trampoline code associated with it. 37 * 38 * During a moving GC, the table is rekeyed in case any scripts 39 * have relocated. 40 */ 41 42 class EntryTrampoline { 43 HeapPtr<JitCode*> entryTrampoline_; 44 45 public: 46 void trace(JSTracer* trc) { 47 TraceNullableEdge(trc, &entryTrampoline_, "interpreter-entry-trampoline"); 48 } 49 50 explicit EntryTrampoline(JSContext* cx, JitCode* code) { 51 MOZ_ASSERT(code); 52 entryTrampoline_ = code; 53 } 54 55 uint8_t* raw() { 56 MOZ_ASSERT(entryTrampoline_, "Empty trampoline code."); 57 return entryTrampoline_->raw(); 58 } 59 60 #ifdef JSGC_HASH_TABLE_CHECKS 61 void checkTrampolineAfterMovingGC() const; 62 #endif 63 }; 64 65 using JSScriptToTrampolineMap = 66 HashMap<HeapPtr<BaseScript*>, EntryTrampoline, 67 DefaultHasher<HeapPtr<BaseScript*>>, SystemAllocPolicy>; 68 class EntryTrampolineMap : public JSScriptToTrampolineMap { 69 public: 70 void traceTrampolineCode(JSTracer* trc); 71 void updateScriptsAfterMovingGC(void); 72 #ifdef JSGC_HASH_TABLE_CHECKS 73 void checkScriptsAfterMovingGC(); 74 #endif 75 }; 76 77 } // namespace jit 78 } // namespace js 79 #endif /* jit_InterpreterEntryTrampoline_h */