Bug 1422043: Use pointer arithmetic to determine a wasm function index; r=luke
authorBenjamin Bouvier <benj@benj.me>
Tue, 13 Feb 2018 12:46:28 +0100
changeset 404135 bdeee319fd1a6ae8e99c08913d7c10d8622ebfdd
parent 404134 5f2344531e28852f2daf6cf5a5871cc5a94e4040
child 404136 12219bfe0748a9bef50559e5c8eefca83655627a
push id99939
push userbbouvier@mozilla.com
push dateFri, 16 Feb 2018 10:00:41 +0000
treeherdermozilla-inbound@a274eb9c8f1f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1422043
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1422043: Use pointer arithmetic to determine a wasm function index; r=luke MozReview-Commit-ID: 8Dn0zqqmIdD
js/src/wasm/WasmCode.cpp
js/src/wasm/WasmCode.h
js/src/wasm/WasmJS.cpp
--- a/js/src/wasm/WasmCode.cpp
+++ b/js/src/wasm/WasmCode.cpp
@@ -794,21 +794,21 @@ void
 Code::setTier2(UniqueModuleSegment segment) const
 {
     MOZ_RELEASE_ASSERT(segment->tier() == Tier::Ion && segment1_->tier() != Tier::Ion);
     MOZ_RELEASE_ASSERT(!segment2_.get());
     segment2_ = takeOwnership(Move(segment));
 }
 
 uint32_t
-Code::lookupFuncIndex(JSFunction* fun) const
+Code::getFuncIndex(JSFunction* fun) const
 {
     if (fun->isAsmJSNative())
         return fun->asmJSFuncIndex();
-    return lookupRange(*fun->wasmJitEntry())->funcIndex();
+    return jumpTables_.funcIndexFromJitEntry(fun->wasmJitEntry());
 }
 
 Tiers
 Code::tiers() const
 {
     if (hasTier2())
         return Tiers(segment1_->tier(), segment2_->tier());
     return Tiers(segment1_->tier());
--- a/js/src/wasm/WasmCode.h
+++ b/js/src/wasm/WasmCode.h
@@ -506,16 +506,23 @@ class JumpTables
         jit_.get()[2 * i] = target;
         jit_.get()[2 * i + 1] = target;
     }
     void** getAddressOfJitEntry(size_t i) const {
         MOZ_ASSERT(i < numFuncs_);
         MOZ_ASSERT(jit_.get()[2 * i]);
         return &jit_.get()[2 * i];
     }
+    size_t funcIndexFromJitEntry(void** target) const {
+        MOZ_ASSERT(target >= &jit_.get()[0]);
+        MOZ_ASSERT(target <= &(jit_.get()[2 * numFuncs_ - 1]));
+        size_t index = (intptr_t*)target - (intptr_t*)&jit_.get()[0];
+        MOZ_ASSERT(index % 2 == 0);
+        return index / 2;
+    }
 
     void setTieringEntry(size_t i, void* target) const {
         MOZ_ASSERT(i < numFuncs_);
         // See comment in wasm::Module::finishTier2.
         if (mode_ == CompileMode::Tier1)
             tiering_.get()[i] = target;
     }
     void** tiering() const {
@@ -551,17 +558,17 @@ class Code : public ShareableBase<Code>
     Code();
     Code(UniqueModuleSegment tier, const Metadata& metadata, JumpTables&& maybeJumpTables);
 
     void setTieringEntry(size_t i, void* target) const { jumpTables_.setTieringEntry(i, target); }
     void** tieringJumpTable() const { return jumpTables_.tiering(); }
 
     void setJitEntry(size_t i, void* target) const { jumpTables_.setJitEntry(i, target); }
     void** getAddressOfJitEntry(size_t i) const { return jumpTables_.getAddressOfJitEntry(i); }
-    uint32_t lookupFuncIndex(JSFunction* fun) const;
+    uint32_t getFuncIndex(JSFunction* fun) const;
 
     bool hasTier2() const { return metadata_->hasTier2(); }
     void setTier2(UniqueModuleSegment segment) const;
     Tiers tiers() const;
     bool hasTier(Tier t) const;
 
     Tier stableTier() const;    // This is stable during a run
     Tier bestTier() const;      // This may transition from Baseline -> Ion at any time
--- a/js/src/wasm/WasmJS.cpp
+++ b/js/src/wasm/WasmJS.cpp
@@ -1273,17 +1273,17 @@ wasm::ExportedFunctionToInstanceObject(J
     return &v.toObject().as<WasmInstanceObject>();
 }
 
 uint32_t
 wasm::ExportedFunctionToFuncIndex(JSFunction* fun)
 {
     MOZ_ASSERT(IsExportedFunction(fun));
     Instance& instance = ExportedFunctionToInstanceObject(fun)->instance();
-    return instance.code().lookupFuncIndex(fun);
+    return instance.code().getFuncIndex(fun);
 }
 
 // ============================================================================
 // WebAssembly.Memory class and methods
 
 const ClassOps WasmMemoryObject::classOps_ =
 {
     nullptr, /* addProperty */