Bug 1834537 - Part 1: Simplify JIT nursery allocation r=jandem
[gecko.git] / js / src / jit / InterpreterEntryTrampoline.h
blob4f49f3fe1321bc25c63fa96edfef540babb87d8c
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/. */
7 #ifndef jit_InterpreterEntryTrampoline_h
8 #define jit_InterpreterEntryTrampoline_h
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"
17 namespace js {
19 void ClearInterpreterEntryMap(JSRuntime* runtime);
21 namespace jit {
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.
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.
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.
38 * During a moving GC, the table is rekeyed in case any scripts
39 * have relocated.
42 class EntryTrampoline {
43 HeapPtr<JitCode*> entryTrampoline_;
45 public:
46 void trace(JSTracer* trc) {
47 TraceNullableEdge(trc, &entryTrampoline_, "interpreter-entry-trampoline");
50 explicit EntryTrampoline(JSContext* cx, JitCode* code) {
51 MOZ_ASSERT(code);
52 entryTrampoline_ = code;
55 uint8_t* raw() {
56 MOZ_ASSERT(entryTrampoline_, "Empty trampoline code.");
57 return entryTrampoline_->raw();
60 #ifdef JSGC_HASH_TABLE_CHECKS
61 void checkTrampolineAfterMovingGC();
62 #endif
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
77 } // namespace jit
78 } // namespace js
79 #endif /* jit_InterpreterEntryTrampoline_h */