Bug 1541404 part 23 - Implement more BaselineInterpreterGenerator bits. r=djvj
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 10 May 2019 09:55:49 +0000
changeset 532190 8da1d9e605dd7218ced00da67ec09c3e37565147
parent 532189 b84d8c19fdea4022e92173ae3cb8b1ab284cf7af
child 532191 8c4c1145857040627723cf4913e4d30702bd171c
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdjvj
bugs1541404
milestone68.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 1541404 part 23 - Implement more BaselineInterpreterGenerator bits. r=djvj Differential Revision: https://phabricator.services.mozilla.com/D29989
js/src/jit/BaselineCompiler.cpp
js/src/jit/BaselineCompiler.h
js/src/jit/BaselineJIT.cpp
--- a/js/src/jit/BaselineCompiler.cpp
+++ b/js/src/jit/BaselineCompiler.cpp
@@ -1540,16 +1540,26 @@ void BaselineCodeGen<Handler>::emitProfi
   profilerExitFrameToggleOffset_ = toggleOffset;
 }
 
 template <typename Handler>
 bool BaselineCodeGen<Handler>::emit_JSOP_NOP() {
   return true;
 }
 
+template <>
+bool BaselineCompilerCodeGen::emit_JSOP_FORCEINTERPRETER() {
+  MOZ_CRASH("Unexpected JSOP_FORCEINTERPRETER in compiler");
+}
+
+template <>
+bool BaselineInterpreterCodeGen::emit_JSOP_FORCEINTERPRETER() {
+  return true;
+}
+
 template <typename Handler>
 bool BaselineCodeGen<Handler>::emit_JSOP_ITERNEXT() {
   return true;
 }
 
 template <typename Handler>
 bool BaselineCodeGen<Handler>::emit_JSOP_NOP_DESTRUCTURING() {
   return true;
@@ -6629,16 +6639,66 @@ bool BaselineInterpreterGenerator::emitD
   if (!debugTrapOffsets_.append(offset.offset())) {
     ReportOutOfMemory(cx);
     return false;
   }
 
   return true;
 }
 
+bool BaselineInterpreterGenerator::emitInterpreterLoop() {
+  MOZ_CRASH("NYI: interpreter emitInterpreterLoop");
+
+  return true;
+}
+
+bool BaselineInterpreterGenerator::generate(BaselineInterpreter& interpreter) {
+  if (!emitPrologue()) {
+    return false;
+  }
+
+  if (!emitInterpreterLoop()) {
+    return false;
+  }
+
+  if (!emitEpilogue()) {
+    return false;
+  }
+
+  if (!emitOutOfLinePostBarrierSlot()) {
+    return false;
+  }
+
+  Linker linker(masm, "BaselineInterpreter");
+  if (masm.oom()) {
+    ReportOutOfMemory(cx);
+    return false;
+  }
+
+  JitCode* code = linker.newCode(cx, CodeKind::Other);
+  if (!code) {
+    return false;
+  }
+
+#ifdef JS_ION_PERF
+  writePerfSpewerJitCodeProfile(code, "BaselineInterpreter");
+#endif
+
+#ifdef MOZ_VTUNE
+  vtune::MarkStub(code, "BaselineInterpreter");
+#endif
+
+  interpreter.init(
+      code, interpretOpOffset_, profilerEnterFrameToggleOffset_.offset(),
+      profilerExitFrameToggleOffset_.offset(),
+      handler.debuggeeCheckOffset().offset(), std::move(debugTrapOffsets_));
+
+  return true;
+}
+
 JitCode* JitRuntime::generateDebugTrapHandler(JSContext* cx,
                                               DebugTrapHandlerKind kind) {
   StackMacroAssembler masm;
 
   AllocatableGeneralRegisterSet regs(GeneralRegisterSet::All());
   regs.takeUnchecked(BaselineFrameReg);
   regs.takeUnchecked(ICStubReg);
   regs.takeUnchecked(PCRegAtStart);
@@ -6730,13 +6790,10 @@ JitCode* JitRuntime::generateDebugTrapHa
 #endif
 #ifdef MOZ_VTUNE
   vtune::MarkStub(handlerCode, "DebugTrapHandler");
 #endif
 
   return handlerCode;
 }
 
-// Instantiate explicitly for now to make sure it compiles.
-template class jit::BaselineCodeGen<BaselineInterpreterHandler>;
-
 }  // namespace jit
 }  // namespace js
--- a/js/src/jit/BaselineCompiler.h
+++ b/js/src/jit/BaselineCompiler.h
@@ -414,16 +414,17 @@ class BaselineCodeGen {
   MOZ_MUST_USE bool emitNextIC();
   MOZ_MUST_USE bool emitInterruptCheck();
   MOZ_MUST_USE bool emitWarmUpCounterIncrement();
   MOZ_MUST_USE bool emitTraceLoggerResume(Register script,
                                           AllocatableGeneralRegisterSet& regs);
 
 #define EMIT_OP(op) bool emit_##op();
   OPCODE_LIST(EMIT_OP)
+  EMIT_OP(JSOP_FORCEINTERPRETER)
 #undef EMIT_OP
 
   // JSOP_NEG, JSOP_BITNOT, JSOP_INC, JSOP_DEC
   MOZ_MUST_USE bool emitUnaryArith();
 
   // JSOP_BITXOR, JSOP_LSH, JSOP_ADD etc.
   MOZ_MUST_USE bool emitBinaryArith();
 
@@ -695,19 +696,25 @@ class BaselineInterpreterHandler {
 };
 
 using BaselineInterpreterCodeGen = BaselineCodeGen<BaselineInterpreterHandler>;
 
 class BaselineInterpreterGenerator final : private BaselineInterpreterCodeGen {
   // Offsets of patchable call instructions for debugger breakpoints/stepping.
   js::Vector<uint32_t, 0, SystemAllocPolicy> debugTrapOffsets_;
 
+  // Offset of the code to start interpreting a bytecode op.
+  uint32_t interpretOpOffset_ = 0;
+
  public:
   explicit BaselineInterpreterGenerator(JSContext* cx);
 
+  MOZ_MUST_USE bool generate(BaselineInterpreter& interpreter);
+
  private:
+  MOZ_MUST_USE bool emitInterpreterLoop();
   MOZ_MUST_USE bool emitDebugTrap();
 };
 
 }  // namespace jit
 }  // namespace js
 
 #endif /* jit_BaselineCompiler_h */
--- a/js/src/jit/BaselineJIT.cpp
+++ b/js/src/jit/BaselineJIT.cpp
@@ -1426,13 +1426,14 @@ void BaselineInterpreter::init(JitCode* 
   debuggeeCheckOffset_ = debuggeeCheckOffset;
   debugTrapOffsets_ = std::move(debugTrapOffsets);
 }
 
 bool jit::GenerateBaselineInterpreter(JSContext* cx,
                                       BaselineInterpreter& interpreter) {
   // Temporary JitOptions check to prevent crashes for now.
   if (JitOptions.baselineInterpreter) {
-    MOZ_CRASH("NYI: GenerateBaselineInterpreter");
+    BaselineInterpreterGenerator generator(cx);
+    return generator.generate(interpreter);
   }
 
   return true;
 }