Bug 1615143 - Cleanup UBI JSScript size computation. r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Thu, 13 Feb 2020 09:39:38 +0000
changeset 513772 97de2c9ab0a1a6e9c061081b05d336f69d023225
parent 513771 867db08a6fee8d4c305360b3d5402df0052d4aca
child 513773 06a0f1b9929e39885c56d7fa1929923cd523bc17
push id107238
push usertcampbell@mozilla.com
push dateThu, 13 Feb 2020 14:40:57 +0000
treeherderautoland@987a7f91bc32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1615143
milestone75.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 1615143 - Cleanup UBI JSScript size computation. r=jandem Generalize the code to handle BaseScript types to prepare for eliminating TraceKind::LazyScript. Also remove JSScript::sizeOfData method in favour of the equivalent BaseScript::sizeOfExcludingThis. Differential Revision: https://phabricator.services.mozilla.com/D62679
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
js/src/vm/MemoryMetrics.cpp
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -4606,20 +4606,16 @@ void JSScript::assertValidJumpTargets() 
 
     jsbytecode* tryTarget = tryStart + tn.length;
     MOZ_ASSERT(main() <= tryTarget && tryTarget < codeEnd());
     MOZ_ASSERT(BytecodeIsJumpTarget(JSOp(*tryTarget)));
   }
 }
 #endif
 
-size_t JSScript::sizeOfData(mozilla::MallocSizeOf mallocSizeOf) const {
-  return mallocSizeOf(data_);
-}
-
 void JSScript::addSizeOfJitScript(mozilla::MallocSizeOf mallocSizeOf,
                                   size_t* sizeOfJitScript,
                                   size_t* sizeOfBaselineFallbackStubs) const {
   if (!hasJitScript()) {
     return;
   }
 
   jitScript()->addSizeOfIncludingThis(mallocSizeOf, sizeOfJitScript,
@@ -5730,31 +5726,37 @@ void JSScript::AutoDelazify::dropScript(
   if (script_ && !script_->realm()->isSelfHostingRealm()) {
     script_->setDoNotRelazify(oldDoNotRelazify_);
   }
   script_ = nullptr;
 }
 
 JS::ubi::Base::Size JS::ubi::Concrete<JSScript>::size(
     mozilla::MallocSizeOf mallocSizeOf) const {
-  Size size = gc::Arena::thingSize(get().asTenured().getAllocKind());
-
-  size += get().sizeOfData(mallocSizeOf);
-
-  size_t jitScriptSize = 0;
-  size_t fallbackStubSize = 0;
-  get().addSizeOfJitScript(mallocSizeOf, &jitScriptSize, &fallbackStubSize);
-  size += jitScriptSize;
-  size += fallbackStubSize;
-
-  size_t baselineSize = 0;
-  jit::AddSizeOfBaselineData(&get(), mallocSizeOf, &baselineSize);
-  size += baselineSize;
-
-  size += jit::SizeOfIonData(&get(), mallocSizeOf);
+  BaseScript* base = &get();
+
+  Size size = gc::Arena::thingSize(base->getAllocKind());
+  size += base->sizeOfExcludingThis(mallocSizeOf);
+
+  // Include any JIT data if it exists.
+  if (base->hasJitScript()) {
+    JSScript* script = static_cast<JSScript*>(base);
+
+    size_t jitScriptSize = 0;
+    size_t fallbackStubSize = 0;
+    script->addSizeOfJitScript(mallocSizeOf, &jitScriptSize, &fallbackStubSize);
+    size += jitScriptSize;
+    size += fallbackStubSize;
+
+    size_t baselineSize = 0;
+    jit::AddSizeOfBaselineData(script, mallocSizeOf, &baselineSize);
+    size += baselineSize;
+
+    size += jit::SizeOfIonData(script, mallocSizeOf);
+  }
 
   MOZ_ASSERT(size > 0);
   return size;
 }
 
 const char* JS::ubi::Concrete<JSScript>::scriptFilename() const {
   return get().filename();
 }
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -3042,22 +3042,16 @@ class JSScript : public js::BaseScript {
   js::BytecodeLocation endLocation() const {
     return js::BytecodeLocation(this, codeEnd());
   }
 
   js::BytecodeLocation offsetToLocation(uint32_t offset) const {
     return js::BytecodeLocation(this, offsetToPC(offset));
   }
 
-  /*
-   * sizeOfData() is the size of the block allocated to hold all the data
-   * sections (which can be larger than the in-use size).
-   */
-  size_t sizeOfData(mozilla::MallocSizeOf mallocSizeOf) const;
-
   void addSizeOfJitScript(mozilla::MallocSizeOf mallocSizeOf,
                           size_t* sizeOfJitScript,
                           size_t* sizeOfBaselineFallbackStubs) const;
 
   mozilla::Span<const JSTryNote> trynotes() const {
     return immutableScriptData()->tryNotes();
   }
 
--- a/js/src/vm/MemoryMetrics.cpp
+++ b/js/src/vm/MemoryMetrics.cpp
@@ -376,17 +376,17 @@ static void StatsCellCallback(JSRuntime*
       break;
     }
 
     case JS::TraceKind::Script: {
       JSScript* script = &cellptr.as<JSScript>();
       RealmStats& realmStats = script->realm()->realmStats();
       realmStats.scriptsGCHeap += thingSize;
       realmStats.scriptsMallocHeapData +=
-          script->sizeOfData(rtStats->mallocSizeOf_);
+          script->sizeOfExcludingThis(rtStats->mallocSizeOf_);
       script->addSizeOfJitScript(rtStats->mallocSizeOf_, &realmStats.jitScripts,
                                  &realmStats.baselineStubsFallback);
       jit::AddSizeOfBaselineData(script, rtStats->mallocSizeOf_,
                                  &realmStats.baselineData);
       realmStats.ionData += jit::SizeOfIonData(script, rtStats->mallocSizeOf_);
       CollectScriptSourceStats<granularity>(closure, script->scriptSource());
       break;
     }