Bug 1271010 - Baldr: tidy CodeRange (r=bbouvier)
authorLuke Wagner <luke@mozilla.com>
Sat, 28 May 2016 16:51:03 -0500
changeset 338588 520c9c228706376f3285bff5e693cad017db3435
parent 338587 ff7d5e4ca750c0ad228e5e4dc0dfc70e9770efee
child 338589 d9a0b729a7be40ae0f8d1f8ce4bd15415fba0914
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1271010
milestone49.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 1271010 - Baldr: tidy CodeRange (r=bbouvier) MozReview-Commit-ID: EjhwbDpwMOU
js/src/asmjs/WasmFrameIterator.cpp
js/src/asmjs/WasmModule.cpp
js/src/asmjs/WasmModule.h
--- a/js/src/asmjs/WasmFrameIterator.cpp
+++ b/js/src/asmjs/WasmFrameIterator.cpp
@@ -764,17 +764,17 @@ wasm::EnableProfilingThunk(const Module&
 // Replace all the nops in all the epilogues of asm.js functions with jumps
 // to the profiling epilogues.
 void
 wasm::EnableProfilingEpilogue(const Module& module, const CodeRange& codeRange, bool enabled)
 {
     if (!codeRange.isFunction())
         return;
 
-    uint8_t* jump = module.code() + codeRange.functionProfilingJump();
+    uint8_t* jump = module.code() + codeRange.funcProfilingJump();
     uint8_t* profilingEpilogue = module.code() + codeRange.funcProfilingEpilogue();
 
 #if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
     // An unconditional jump with a 1 byte offset immediate has the opcode
     // 0x90. The offset is relative to the address of the instruction after
     // the jump. 0x66 0x90 is the canonical two-byte nop.
     ptrdiff_t jumpImmediate = profilingEpilogue - jump - 2;
     MOZ_ASSERT(jumpImmediate > 0 && jumpImmediate <= 127);
--- a/js/src/asmjs/WasmModule.cpp
+++ b/js/src/asmjs/WasmModule.cpp
@@ -354,64 +354,62 @@ Import::clone(JSContext* cx, Import* out
 
 size_t
 Import::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const
 {
     return SizeOfSigExcludingThis(sig_, mallocSizeOf);
 }
 
 CodeRange::CodeRange(Kind kind, Offsets offsets)
-  : funcIndex_(0),
+  : begin_(offsets.begin),
+    profilingReturn_(0),
+    end_(offsets.end),
+    funcIndex_(0),
     funcLineOrBytecode_(0),
-    begin_(offsets.begin),
-    profilingReturn_(0),
-    end_(offsets.end)
+    funcBeginToNonProfilingEntry_(0),
+    funcProfilingJumpToProfilingReturn_(0),
+    funcProfilingEpilogueToProfilingReturn_(0),
+    kind_(kind)
 {
-    PodZero(&u);  // zero padding for Valgrind
-    u.kind_ = kind;
-
     MOZ_ASSERT(begin_ <= end_);
-    MOZ_ASSERT(u.kind_ == Entry || u.kind_ == Inline || u.kind_ == CallThunk);
+    MOZ_ASSERT(kind_ == Entry || kind_ == Inline || kind_ == CallThunk);
 }
 
 CodeRange::CodeRange(Kind kind, ProfilingOffsets offsets)
-  : funcIndex_(0),
-    funcLineOrBytecode_(0),
-    begin_(offsets.begin),
+  : begin_(offsets.begin),
     profilingReturn_(offsets.profilingReturn),
-    end_(offsets.end)
+    end_(offsets.end),
+    funcIndex_(0),
+    funcLineOrBytecode_(0),
+    funcBeginToNonProfilingEntry_(0),
+    funcProfilingJumpToProfilingReturn_(0),
+    funcProfilingEpilogueToProfilingReturn_(0),
+    kind_(kind)
 {
-    PodZero(&u);  // zero padding for Valgrind
-    u.kind_ = kind;
-
     MOZ_ASSERT(begin_ < profilingReturn_);
     MOZ_ASSERT(profilingReturn_ < end_);
-    MOZ_ASSERT(u.kind_ == ImportJitExit || u.kind_ == ImportInterpExit);
+    MOZ_ASSERT(kind_ == ImportJitExit || kind_ == ImportInterpExit);
 }
 
 CodeRange::CodeRange(uint32_t funcIndex, uint32_t funcLineOrBytecode, FuncOffsets offsets)
-  : funcIndex_(funcIndex),
-    funcLineOrBytecode_(funcLineOrBytecode)
+  : begin_(offsets.begin),
+    profilingReturn_(offsets.profilingReturn),
+    end_(offsets.end),
+    funcIndex_(funcIndex),
+    funcLineOrBytecode_(funcLineOrBytecode),
+    funcBeginToNonProfilingEntry_(offsets.nonProfilingEntry - begin_),
+    funcProfilingJumpToProfilingReturn_(profilingReturn_ - offsets.profilingJump),
+    funcProfilingEpilogueToProfilingReturn_(profilingReturn_ - offsets.profilingEpilogue),
+    kind_(Function)
 {
-    PodZero(&u);  // zero padding for Valgrind
-    u.kind_ = Function;
-
-    MOZ_ASSERT(offsets.nonProfilingEntry - offsets.begin <= UINT8_MAX);
-    begin_ = offsets.begin;
-    u.func.beginToEntry_ = offsets.nonProfilingEntry - begin_;
-
-    MOZ_ASSERT(offsets.nonProfilingEntry < offsets.profilingReturn);
-    MOZ_ASSERT(offsets.profilingReturn - offsets.profilingJump <= UINT8_MAX);
-    MOZ_ASSERT(offsets.profilingReturn - offsets.profilingEpilogue <= UINT8_MAX);
-    profilingReturn_ = offsets.profilingReturn;
-    u.func.profilingJumpToProfilingReturn_ = profilingReturn_ - offsets.profilingJump;
-    u.func.profilingEpilogueToProfilingReturn_ = profilingReturn_ - offsets.profilingEpilogue;
-
-    MOZ_ASSERT(offsets.nonProfilingEntry < offsets.end);
-    end_ = offsets.end;
+    MOZ_ASSERT(begin_ < profilingReturn_);
+    MOZ_ASSERT(profilingReturn_ < end_);
+    MOZ_ASSERT(funcBeginToNonProfilingEntry_ == offsets.nonProfilingEntry - begin_);
+    MOZ_ASSERT(funcProfilingJumpToProfilingReturn_ == profilingReturn_ - offsets.profilingJump);
+    MOZ_ASSERT(funcProfilingEpilogueToProfilingReturn_ == profilingReturn_ - offsets.profilingEpilogue);
 }
 
 static size_t
 NullableStringLength(const char* chars)
 {
     return chars ? strlen(chars) : 0;
 }
 
--- a/js/src/asmjs/WasmModule.h
+++ b/js/src/asmjs/WasmModule.h
@@ -190,90 +190,88 @@ class Import
 typedef Vector<Import, 0, SystemAllocPolicy> ImportVector;
 
 // A CodeRange describes a single contiguous range of code within a wasm
 // module's code segment. A CodeRange describes what the code does and, for
 // function bodies, the name and source coordinates of the function.
 
 class CodeRange
 {
+  public:
+    enum Kind { Function, Entry, ImportJitExit, ImportInterpExit, Inline, CallThunk };
+
+  private:
     // All fields are treated as cacheable POD:
-    uint32_t funcIndex_;
-    uint32_t funcLineOrBytecode_;
     uint32_t begin_;
     uint32_t profilingReturn_;
     uint32_t end_;
-    union {
-        struct {
-            uint8_t kind_;
-            uint8_t beginToEntry_;
-            uint8_t profilingJumpToProfilingReturn_;
-            uint8_t profilingEpilogueToProfilingReturn_;
-        } func;
-        uint8_t kind_;
-    } u;
-
-    void assertValid();
+    uint32_t funcIndex_;
+    uint32_t funcLineOrBytecode_;
+    uint8_t funcBeginToNonProfilingEntry_;
+    uint8_t funcProfilingJumpToProfilingReturn_;
+    uint8_t funcProfilingEpilogueToProfilingReturn_;
+    Kind kind_ : 8;
 
   public:
-    enum Kind { Function, Entry, ImportJitExit, ImportInterpExit, Inline, CallThunk };
-
     CodeRange() = default;
     CodeRange(Kind kind, Offsets offsets);
     CodeRange(Kind kind, ProfilingOffsets offsets);
     CodeRange(uint32_t funcIndex, uint32_t lineOrBytecode, FuncOffsets offsets);
 
     // All CodeRanges have a begin and end.
 
     uint32_t begin() const {
         return begin_;
     }
     uint32_t end() const {
         return end_;
     }
 
     // Other fields are only available for certain CodeRange::Kinds.
 
-    Kind kind() const { return Kind(u.kind_); }
+    Kind kind() const {
+        return kind_;
+    }
+
+    bool isFunction() const {
+        return kind() == Function;
+    }
+    bool isImportExit() const {
+        return kind() == ImportJitExit || kind() == ImportInterpExit;
+    }
+    bool isInline() const {
+        return kind() == Inline;
+    }
 
     // Every CodeRange except entry and inline stubs has a profiling return
     // which is used for asynchronous profiling to determine the frame pointer.
 
     uint32_t profilingReturn() const {
         MOZ_ASSERT(isFunction() || isImportExit());
         return profilingReturn_;
     }
 
     // Functions have offsets which allow patching to selectively execute
     // profiling prologues/epilogues.
 
-    bool isFunction() const {
-        return kind() == Function;
-    }
-    bool isImportExit() const {
-        return kind() == ImportJitExit || kind() == ImportInterpExit;
-    }
-    bool isInline() const {
-        return kind() == Inline;
-    }
     uint32_t funcProfilingEntry() const {
         MOZ_ASSERT(isFunction());
         return begin();
     }
     uint32_t funcNonProfilingEntry() const {
         MOZ_ASSERT(isFunction());
-        return begin_ + u.func.beginToEntry_;
+        return begin_ + funcBeginToNonProfilingEntry_;
     }
-    uint32_t functionProfilingJump() const {
+    uint32_t funcProfilingJump() const {
         MOZ_ASSERT(isFunction());
-        return profilingReturn_ - u.func.profilingJumpToProfilingReturn_;
+        return profilingReturn_ - funcProfilingJumpToProfilingReturn_;
     }
     uint32_t funcProfilingEpilogue() const {
         MOZ_ASSERT(isFunction());
-        return profilingReturn_ - u.func.profilingEpilogueToProfilingReturn_;
+        return profilingReturn_ - funcProfilingEpilogueToProfilingReturn_;
     }
     uint32_t funcIndex() const {
         MOZ_ASSERT(isFunction());
         return funcIndex_;
     }
     uint32_t funcLineOrBytecode() const {
         MOZ_ASSERT(isFunction());
         return funcLineOrBytecode_;