tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TrampolineNatives.h (1925B)


      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_TrampolineNatives_h
      8 #define jit_TrampolineNatives_h
      9 
     10 #include <stdint.h>
     11 
     12 #include "js/TypeDecls.h"
     13 
     14 // [SMDOC] Trampoline Natives
     15 //
     16 // Trampoline natives are JS builtin functions that use the NATIVE_JIT_ENTRY
     17 // mechanism. This means they have two implementations: the usual native C++
     18 // implementation and a generated JIT trampoline that JIT callers can call
     19 // directly using the JIT ABI calling convention. (This is very similar to how
     20 // calls from JS to WebAssembly are optimized in the JITs.)
     21 //
     22 // The JIT trampoline lets us implement some natives in a more efficient way. In
     23 // particular, it's much faster to call (other) JS functions with JIT code from
     24 // a JIT trampoline than from C++ code.
     25 //
     26 // Trampoline frames use FrameType::TrampolineNative.
     27 
     28 class JSJitInfo;
     29 
     30 namespace JS {
     31 class CallArgs;
     32 }  // namespace JS
     33 
     34 // List of all trampoline natives.
     35 #define TRAMPOLINE_NATIVE_LIST(_) \
     36  _(ArraySort)                    \
     37  _(TypedArraySort)
     38 
     39 namespace js {
     40 namespace jit {
     41 
     42 enum class TrampolineNative : uint16_t {
     43 #define ADD_NATIVE(native) native,
     44  TRAMPOLINE_NATIVE_LIST(ADD_NATIVE)
     45 #undef ADD_NATIVE
     46      Count
     47 };
     48 
     49 #define ADD_NATIVE(native) extern const JSJitInfo JitInfo_##native;
     50 TRAMPOLINE_NATIVE_LIST(ADD_NATIVE)
     51 #undef ADD_NATIVE
     52 
     53 void SetTrampolineNativeJitEntry(JSContext* cx, JSFunction* fun,
     54                                 TrampolineNative native);
     55 
     56 bool CallTrampolineNativeJitCode(JSContext* cx, TrampolineNative native,
     57                                 JS::CallArgs& args);
     58 
     59 }  // namespace jit
     60 }  // namespace js
     61 
     62 #endif /* jit_TrampolineNatives_h */