Bug 1505689 part 7 - Rename DestroyJitScripts to JSScript::releaseJitScriptOnFinalize. r=tcampbell
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 15 Aug 2019 16:14:04 +0000
changeset 488279 f7a4be5909d3ee0fcf36d64979f50036e2938a07
parent 488278 8bf0e43c0df043e3527a419e095e641ff52bfcb4
child 488280 11d01998d8f72baa0994f4a967dbe259fe7d55d1
push id36440
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 03:57:48 +0000
treeherdermozilla-central@a58b7dc85887 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1505689
milestone70.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 1505689 part 7 - Rename DestroyJitScripts to JSScript::releaseJitScriptOnFinalize. r=tcampbell This is more consistent with the rest of the code. Differential Revision: https://phabricator.services.mozilla.com/D41709
js/src/jit/Ion.cpp
js/src/jit/Ion.h
js/src/jit/JitScript.cpp
js/src/jit/JitScript.h
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/jit/Ion.cpp
+++ b/js/src/jit/Ion.cpp
@@ -2995,36 +2995,16 @@ size_t jit::SizeOfIonData(JSScript* scri
 
   if (script->hasIonScript()) {
     result += script->ionScript()->sizeOfIncludingThis(mallocSizeOf);
   }
 
   return result;
 }
 
-void jit::DestroyJitScripts(JSFreeOp* fop, JSScript* script) {
-  if (!script->hasJitScript()) {
-    return;
-  }
-
-  if (script->hasIonScript()) {
-    IonScript* ion = script->ionScript();
-    script->jitScript()->clearIonScript(fop, script);
-    jit::IonScript::Destroy(fop, ion);
-  }
-
-  if (script->hasBaselineScript()) {
-    BaselineScript* baseline = script->baselineScript();
-    script->jitScript()->clearBaselineScript(fop, script);
-    jit::BaselineScript::Destroy(fop, baseline);
-  }
-
-  script->releaseJitScript(fop);
-}
-
 bool jit::JitSupportsSimd() { return js::jit::MacroAssembler::SupportsSimd(); }
 
 bool jit::JitSupportsAtomics() {
 #if defined(JS_CODEGEN_ARM)
   // Bug 1146902, bug 1077318: Enable Ion inlining of Atomics
   // operations on ARM only when the CPU has byte, halfword, and
   // doubleword load-exclusive and store-exclusive instructions,
   // until we can add support for systems that don't have those.
--- a/js/src/jit/Ion.h
+++ b/js/src/jit/Ion.h
@@ -249,17 +249,16 @@ class MOZ_RAII AutoEnterIonBackend {
   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 bool OffThreadCompilationAvailable(JSContext* cx);
 
 void ForbidCompilation(JSContext* cx, JSScript* script);
 
 size_t SizeOfIonData(JSScript* script, mozilla::MallocSizeOf mallocSizeOf);
-void DestroyJitScripts(JSFreeOp* fop, JSScript* script);
 
 bool JitSupportsSimd();
 bool JitSupportsAtomics();
 
 }  // namespace jit
 }  // namespace js
 
 #endif /* jit_Ion_h */
--- a/js/src/jit/JitScript.cpp
+++ b/js/src/jit/JitScript.cpp
@@ -179,25 +179,45 @@ void JSScript::maybeReleaseJitScript(JSF
       jitScript_->active()) {
     return;
   }
 
   releaseJitScript(fop);
 }
 
 void JSScript::releaseJitScript(JSFreeOp* fop) {
+  MOZ_ASSERT(hasJitScript());
+  MOZ_ASSERT(!hasBaselineScript());
   MOZ_ASSERT(!hasIonScript());
 
   fop->removeCellMemory(this, jitScript_->allocBytes(), MemoryUse::JitScript);
 
   JitScript::Destroy(zone(), jitScript_);
   jitScript_ = nullptr;
   updateJitCodeRaw(fop->runtime());
 }
 
+void JSScript::releaseJitScriptOnFinalize(JSFreeOp* fop) {
+  MOZ_ASSERT(hasJitScript());
+
+  if (hasIonScript()) {
+    IonScript* ion = ionScript();
+    jitScript()->clearIonScript(fop, this);
+    jit::IonScript::Destroy(fop, ion);
+  }
+
+  if (hasBaselineScript()) {
+    BaselineScript* baseline = baselineScript();
+    jitScript()->clearBaselineScript(fop, this);
+    jit::BaselineScript::Destroy(fop, baseline);
+  }
+
+  releaseJitScript(fop);
+}
+
 void JitScript::CachedIonData::trace(JSTracer* trc) {
   TraceNullableEdge(trc, &templateEnv, "jitscript-iondata-template-env");
 }
 
 void JitScript::trace(JSTracer* trc) {
   if (hasBaselineScript()) {
     baselineScript()->trace(trc);
   }
--- a/js/src/jit/JitScript.h
+++ b/js/src/jit/JitScript.h
@@ -234,16 +234,20 @@ class alignas(uintptr_t) JitScript final
             uint32_t bytecodeTypeMapOffset, uint32_t allocBytes,
             const char* profileString);
 
 #ifdef DEBUG
   ~JitScript() {
     // The contents of the fallback stub space are removed and freed
     // separately after the next minor GC. See prepareForDestruction.
     MOZ_ASSERT(fallbackStubSpace_.isEmpty());
+
+    // BaselineScript and IonScript must have been destroyed at this point.
+    MOZ_ASSERT(!hasBaselineScript());
+    MOZ_ASSERT(!hasIonScript());
   }
 #endif
 
   MOZ_MUST_USE bool initICEntriesAndBytecodeTypeMap(JSContext* cx,
                                                     JSScript* script);
 
   MOZ_MUST_USE bool ensureHasCachedIonData(JSContext* cx, HandleScript script);
 
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -4141,17 +4141,19 @@ void JSScript::finalize(JSFreeOp* fop) {
   MOZ_ASSERT_IF(hasScriptName(), coverage::IsLCovEnabled());
   if (coverage::IsLCovEnabled() && hasScriptName()) {
     realm()->lcovOutput.collectCodeCoverageInfo(realm(), this, getScriptName());
     destroyScriptName();
   }
 
   fop->runtime()->geckoProfiler().onScriptFinalized(this);
 
-  jit::DestroyJitScripts(fop, this);
+  if (hasJitScript()) {
+    releaseJitScriptOnFinalize(fop);
+  }
 
   destroyScriptCounts();
   DebugAPI::destroyDebugScript(fop, this);
 
 #ifdef MOZ_VTUNE
   if (realm()->scriptVTuneIdMap) {
     // Note: we should only get here if the VTune JIT profiler is running.
     realm()->scriptVTuneIdMap->remove(this);
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -2697,16 +2697,17 @@ class JSScript : public js::BaseScript {
   /* Ensure the script has a JitScript. */
   inline bool ensureHasJitScript(JSContext* cx, js::jit::AutoKeepJitScripts&);
 
   bool hasJitScript() const { return jitScript_ != nullptr; }
   js::jit::JitScript* jitScript() { return jitScript_; }
 
   void maybeReleaseJitScript(JSFreeOp* fop);
   void releaseJitScript(JSFreeOp* fop);
+  void releaseJitScriptOnFinalize(JSFreeOp* fop);
 
   inline bool hasBaselineScript() const;
   inline bool hasIonScript() const;
 
   inline js::jit::BaselineScript* baselineScript() const;
   inline js::jit::IonScript* ionScript() const;
 
   inline bool isIonCompilingOffThread() const;