Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / src / jit / FlushICache.h
blobdd15bdc8ff4c87295bc61d912e5c9b4a025a93cb
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 /* Flush the instruction cache of instructions in an address range. */
9 #ifndef jit_FlushICache_h
10 #define jit_FlushICache_h
12 #include "mozilla/Assertions.h" // MOZ_CRASH
14 #include <stddef.h> // size_t
16 namespace js {
17 namespace jit {
19 #if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
21 inline void FlushICache(void* code, size_t size) {
22 // No-op. Code and data caches are coherent on x86 and x64.
25 #elif (defined(JS_CODEGEN_ARM) || defined(JS_CODEGEN_ARM64)) || \
26 (defined(JS_CODEGEN_MIPS32) || defined(JS_CODEGEN_MIPS64)) || \
27 defined(JS_CODEGEN_LOONG64) || defined(JS_CODEGEN_RISCV64)
29 // Invalidate the given code range from the icache. This will also flush the
30 // execution context for this core. If this code is to be executed on another
31 // thread, that thread must perform an execution context flush first using
32 // `FlushExecutionContext` below.
33 extern void FlushICache(void* code, size_t size);
35 #elif defined(JS_CODEGEN_NONE) || defined(JS_CODEGEN_WASM32)
37 inline void FlushICache(void* code, size_t size) { MOZ_CRASH(); }
39 #else
40 # error "Unknown architecture!"
41 #endif
43 #if (defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)) || \
44 (defined(JS_CODEGEN_MIPS32) || defined(JS_CODEGEN_MIPS64)) || \
45 defined(JS_CODEGEN_LOONG64) || defined(JS_CODEGEN_RISCV64)
47 inline void FlushExecutionContext() {
48 // No-op. Execution context is coherent with instruction cache.
50 inline bool CanFlushExecutionContextForAllThreads() { return true; }
51 inline void FlushExecutionContextForAllThreads() {
52 // No-op. Execution context is coherent with instruction cache.
55 #elif defined(JS_CODEGEN_NONE) || defined(JS_CODEGEN_WASM32)
57 inline void FlushExecutionContext() { MOZ_CRASH(); }
58 inline bool CanFlushExecutionContextForAllThreads() { MOZ_CRASH(); }
59 inline void FlushExecutionContextForAllThreads() { MOZ_CRASH(); }
61 #elif defined(JS_CODEGEN_ARM) || defined(JS_CODEGEN_ARM64)
63 // ARM and ARM64 must flush the instruction pipeline of the current core
64 // before executing newly JIT'ed code. This will remove any stale data from
65 // the pipeline that may have referenced invalidated instructions.
67 // `FlushICache` will perform this for the thread that compiles the code, but
68 // other threads that may execute the code are responsible to call
69 // this method.
70 extern void FlushExecutionContext();
72 // Some platforms can flush the excecution context for other threads using a
73 // syscall. This is required when JIT'ed code will be published to multiple
74 // threads without a synchronization point where a `FlushExecutionContext`
75 // could be inserted.
76 extern bool CanFlushExecutionContextForAllThreads();
78 // Flushes the execution context of all threads in this process, equivalent to
79 // running `FlushExecutionContext` on every thread.
81 // Callers must ensure `CanFlushExecutionContextForAllThreads` is true, or
82 // else this will crash.
83 extern void FlushExecutionContextForAllThreads();
85 #else
86 # error "Unknown architecture!"
87 #endif
89 } // namespace jit
90 } // namespace js
92 #endif // jit_FlushICache_h