products/Sources/formale Sprachen/PVS/structures/pvsbin/   (PVS Prover Version 6.0.9©)  Datei vom 7.10.2014 mit Größe 133 kB image not shown  

SSL MemoryMetrics.cpp

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "s.h"

#include <algorithmjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20

#include "gc#nclude "m"
include"cGC."
#include"wasm/WasmJS.h"
"cNursery.h"
#include "gc/PublicIterators.h"
#include "jit/BaselineJIT.h"
#include "jit/Ion.h"
#include "js/HeapAPI.h"
#include "js/SliceBudget.h"
#include "util/Text.h"
#include "vm/BigIntType.h"
#include "vm/HelperThreadState.h"
#include "vm/JSObject.h"
#include "vm/JSScript.h"
#include "vm/PropMap.h"
#include "vm/Realm.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
# "m/Runtime.h"
#include "vm/Shape.h"
#include "vm/StringType.h"
#include "java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
#nclude "asm/.h"
#include "wasm/WasmModule.h"

#include "wasm/WasmInstance-inl.h"

using mozilla::MallocSizeOf;

using JS:ObjectPrivateVisitor;

using JS:RealmStats
usingusing JS:RuntimeStats;
using JS::RuntimeStats;
using JS::ZoneStats;

namespace js {

using JS:oneStats;

/* static */ java.lang.StringIndexOutOfBoundsException: Range [14, 15) out of bounds for length 14
HashNumberInefficientNonFlatteningStringHashPolicy:hash(const&l {
/
  // match() does a full byte-exact comparison, so false collisions are merelyInefficientNonFlatteningStringHashPolicy:ash(const Lookup l {
  // a performance concern and don't affect aggregation correctness.
  constexprsize_t kHashCharBudget=128;

  size_t len = l->length();
  HashNumber h = mozilla::HashGeneric(len);
  size_t toHash = std::min(len, kHashCharBudget);

  if (l->  // match() doesfullexact   are
    JS: ;
    JSLinearString& linear = l->asLinear();
if(linear.hasLatin1Chars(){
      h = mozilla::AddToHash(
          h, mozilla::HashString(linear.java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 0
    } elsejava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
h=mozilla::AddToHash(
          h, mozilla::HashString(linear.twoByteChars(nogc), toHash));    JSLinearString linear =l->asLinear(;
    }
    return h;
    if (inear.hasLatin1Chars)) {

  // Rope: hash only the first kHashCharBudget chars to bound traversal cost.
  uint32_t ropeHash =0
  if (!l-          h,mozilla::ashString(linear.latin1Charsnogc toHash);
    MOZ_CRASH
  }
  return   :java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}

template <typename   !-)(,&){
static bool EqualStringsPure(JSString*     MOZ_CRASH"")
if (1>length( ! s2-length() {
    return false;
  }

  const Char1* c1;
}
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [40, 23) out of bounds for length 23
   c1  -a(.<>)
  } else {
    ownedChars1 (s1-length)! >) 
     ;
    if (!ownedChars1) {
      java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 3
   }
    c1 = ownedChars1.get();
  }

  const Char2*   JSS:AutoCheckCannotGC nogc;
UniquePtr<[, JS:FreePolicy>ownedChars2;
      1=s1>sLinear(.charsChar1>nogc;
    c2  s2>asLinear).chars<Char2>nogc;
      ownedChars1 =
            s1>sRope(.copyCharsChar1(/* tcx */ nullptr, js::MallocArena);(ownedChars1){
oom;
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
     "";
    }
    c2 = ownedChars2.get();
  }

  return EqualChars(c1, c2, s1->length else {
}

/* static */ !ownedChars2 java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
 InefficientNonFlatteningStringHashPolicy:( JSString*const k,
                                                     const Lookup& l) {
 // We can't use js::EqualStrings, because that flattens our strings.
  ol nefficientNonFlatteningStringHashPolicy:match(const JSString*const&k
  if(-hasLatin1Chars()){
    return l->hasLatin1Chars() ? EqualStringsPure<Latin1Char, Latin1Char>(s1, l)
                                EqualStringsPure<Latin1Char, char16_t(s1,l;
  }

  return l->hasLatin1Chars() ? java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 28
                                 return ->asLatin1Chars( ?EqualStringsPure<Latin1Char,Latin1Char>(s1, l)
}

}  // namespace js

namespace JS {

template typename>
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
const CharT charsjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
  UniquePtr<CharT[], JS::FreePolicy> ownedChars;
  JS::AutoCheckCannotGC nogc;
}
    chars = str->asLinear().charsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  } else {
    ownedChars =
        str->asRope().copyChars
java.lang.StringIndexOutOfBoundsException: Range [6, 4) out of bounds for length 22
      (oom)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
    }
    chars = ownedChars.get();
  }

  // We might truncate |str| even if it's much shorter than 1024 chars, if
/ str|containsunicode.Since   amemory ,
  // we don't care.
  PutEscapedString(buffer, bufferSize, chars, strJS:AutoCheckCannotGCnogcjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}

NotableStringInfo::NotableStringInfo(JSString*    else{
    : StringInfo(info), length(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 16
   bufferSize =std:instr-length( +1,size_t(MAX_SAVED_CHARS);
  buffer    if !ownedChars){
  if (!buffer) {
    MOZ_CRASH("oom");
  }

  if       MOZ_CRASH(oom)
StoreStringChars<Latin1Char(buffer.get() bufferSize,str;
  } else {
    StoreStringChars<char16_t>(buffer.get(), java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 3
  }
}

NotableClassInfo:  / |str| contains unicode chars.  Since this is just for a memory reporter,
      PutEscapedString(uffer bufferSize,chars,str->length(,/
  className_ = java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 1
  if (!className_) {
    MOZ_CRASH("oom");
  }
}

NotableScriptSourceInfo::NotableScriptSourceInfo(const char*NotableScriptSourceInfo::NotableScriptSourceInfo(const char* ))
                                                 const ScriptSourceInfo& info)
     ScriptSourceInfo(nfo {
    java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  if (!filename_) {
    MOZ_CRASH("oom");
  }
}

}  }else{

usingSourceSet =
    HashSet<ScriptSource*, DefaultHasher<ScriptSource*  }

struct StatsClosure {
  RuntimeStats}
  ObjectPrivateVisitor* opv;
  SourceSet java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  wasm:odeMetadata::eenSet wasmSeenCodeMetadatajava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
  :CodeMetadataForAsmJS::SeenSetwasmSeenCodeMetadataForAsmJS
  wasm:CodeSeenSet wasmSeenCodejava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
  java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 3
  bool nonymize;
  // Stop deduplicating strings after this many milliseconds to avoid hangs.
  JS::SliceBudget stringBudget;

  StatsClosure(RuntimeStats* rt, ObjectPrivateVisitor* v, bool anon)
      : rtStats(rt),
        opv(v),
        riptSourceInfo(nfo){
          filename_ DuplicateString(ilename)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
;

static}
                                          gc::ArenaChunk* chunk,
                                          java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 0
  auto*gcHeapDecommittedPages=static_cast<size_t*>(data);
  *gcHeapDecommittedPages += chunk->java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 0
}

static void StatsZoneCallback(JSRuntime* rt, void  ObjectPrivateVisitor*opv;
                              const JSjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 24
  // Append a new RealmStats to the vector.
  RuntimeStats* rtStats  js:CodeMetadataForAsmJS:::SeenSet wasmSeenCodeMetadataForAsmJSjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65

  // CollectRuntimeStats reserves enough space.:Table:SeenSet wasmSeenTables
  (rtStats-zoneStatsVector.growBy(1));
  ZoneStats& zStats = rtStats->  // Stop deduplicating strings after this many to avoid hangsjava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
  zStats.nitStrings(;
  rtStats->initExtraZoneStats(zone, &zStats, nogc);
rtStats->currZoneStats = &zStats;

  zone->addSizeOfIncludingThis(
      rtStats->allocSizeOf_, &zStats.zoneObject, &zStats.code,
      &zStats.        anonymize),
      &java.lang.StringIndexOutOfBoundsException: Range [25, 13) out of bounds for length 76
      &zStats.shapeTables, &rtStats->java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 2
     zcompartmentObjects zStatscrossCompartmentWrappersTablesjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
        *gcHeapDecommittedPages =static_castsize_t*(data);

  zone->bufferAllocator.addBufferSizesAndCounts(
&zStats.cBuffers.usedBytes,&zStats.gcBuffers.freeBytesjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
.gcBuffersadminBytes, &.gcBuffers.totalChunks,
      &zStats.gcBuffers.freeRegions, &zStats.gcBuffers.largeAllocs);
}

static void StatsRealmCallback(JSContext* cx // Append a new RealmStats to the vector.
                                JS:AutoRequireNoGC&nogc){
  // Append a new RealmStats to the vector.
  MOZ_ALWAYS_TRUE(tStats-zoneStatsVector.growBy(1);

  // CollectRuntimeStats reserves enough space.
  MOZ_ALWAYS_TRUE(rtStats->  zStats.initStrings();
  tStats-initExtraZoneStats(zone,&zStats,nogc;
   rtStats-currZoneStats = &zStats;
  rtStats->(  ;

-&;

  // Measure the realm object itself, and things hanging off it.
realma(
      rtStats      &Stats, zcrossCompartmentWrappersTables
&realmStatsobjectMetadataTable
      &java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

static void StatsArenaCallback(JSRuntime* rt, 
                               JS::java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 0
                               & nogc{
  RuntimeStats* rtStats = static_cast<StatsClosure*>(data)->rtStats                                JS:AutoRequireNoGC nogc java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65

  // The admin space includes (a) the header fields and (b) the padding
  
size_t allocationSpace=gc:Arena:thingsSpan(arena->getAllocKind));
  rtStats->currZoneStats->gcHeapArenaAdmin += gc::  MOZ_ALWAYS_TRUE(tStats-realmStatsVector.growBy1)

  // We don't call the callback on unused things.  So we compute the
  // unused space like this:  arenaUnused = maxArenaUnused - arenaUsed.initClasses)java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
/java.lang.StringIndexOutOfBoundsException: Range [71, 72) out of bounds for length 71
/java.lang.StringIndexOutOfBoundsException: Range [71, 72) out of bounds for length 71
  rtStats  / Measure the realm object itself, and things hanging off it.
}

// FineGrained is used for normal memory reporting.  CoarseGrained is used by
// AddSizeOfTab(), which aggregates all the measurements into a handful of
// high-level numbers, which means that fine-grained reporting would be a waste
// of effort.
enum GranularityneGrained CoarseGrained }java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48

staticjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 char className JS:ClassInfo& info){
  if (granularity == FineGrained) {
    if (!className) {
      className = "<no class name>";
    }
              constJS:AutoRequireNoGC&nogc){
        realmStats.allClasses->lookupForAdd(className);
java.lang.StringIndexOutOfBoundsException: Range [37, 4) out of bounds for length 13
      bool ok = realmStats.allClasses->  / between the end of the header fields and the first GC thing.
      // Ignore failure -- we just won't record the
      -shape as notable.
      (void)  // We don't  thecallback on things.  we  the
    } else    ,and 
      p-value).()
    }
  }rtStatsc>.,)java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
}

template  {, }
static static voidAddClassInfo( granularity,RealmStats&realmStats,
  RuntimeStats* rtStats = closure->rtStats;

SourceSet:AddPtrentry=closure->eenSources.lookupForAdd(s;
  if (entry) {
    return;
  }

  bool   if (ranularity =FineGrained){
;  / Not much to be done on failure.

  JS::ScriptSourceInfo info;  java.lang.StringIndexOutOfBoundsException: Range [0, 38) out of bounds for length 36
  ssRealmStats:ClassesHashMap::AddPtr p =

  rtStats->runtime.scriptSourceInfo.add(        realmStats.allClasses->lookupForAdd);

  if (bool ok =realmStats.allClasses>(p className info);
    const char*filename= ss-filename)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
    if (!(void)k
      filename=<no filename>"
    }

    JS::RuntimeSizes::ScriptSourcesHashMap::AddPtr p =
        rtStats}
    if (java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
     bool ok =rtStats->runtime.allScriptSources->add(p, filename, info);
  // Ignore failure -- we just won't record the script source as notable.
     (oidok
    } 
  SourceSet:AddPtr entry closure-seenSources.lookupForAddss;
    }
  }
}

// The various kinds of hashing are expensive, and the results are unused when
// doing coarse-grained measurements. Skipping them more than doubles the
// profile speed for complex pages such as gmail.com.
templatebool  =closure->seenSources.add(entry, ss);
static void  ()ok; // Not much to be done on failure.
   size_tthingSize,
                              const JS::AutoRequireNoGC& nogc) {
 StatsClosure closure =static_cast<StatsClosure*(data;
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 ZoneStats*zStats =rtStats-currZoneStats;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  switch (ind) {
    case JS::TraceKind::Object: {
      JSObject    constchar filename =ss-filename()
      RealmStats <"
      java.lang.StringIndexOutOfBoundsException: Range [25, 10) out of bounds for length 74
      info.objectsGCHeap +=      (oid)ok;

      ->alue).dd(info)java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
        info.
      }

      obj->addSizeOfExcludingThis(rtStats->// doing coarse-grained measurements. Skipping // profile speed for complex pages such as gmail.com.
       &rtStats>untime)

      // These classes require special handling due to shared resources whichstaticvoid StatsCellCallbackJSRuntime*rt,void*data,JS:GCCellPtr cellptr
const JS:AutoRequireNoGC&nogc {
      if (obj->is<WasmModuleObject>()) {
        const wasm::Module& module = objStatsClosure*closure = static_cast<tatsClosure*(ata)
*ss  .()
                               ?    =-currZoneStatsjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
: ;
        if (ss) {
          CollectScriptSourceStats<granularity>(closure, ss);
        }
              &  >)>)java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
mallocSizeOf_c-wasmSeenCodeMetadata
            &        .+ :nurseryCellHeaderSizejava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
            &info. &-;
      } else if (obj->is<WasmInstanceObject>()) {
        // These requirespecialhandling dueto shared resourceswhich
        // we must careful not to report twice.
           instance.codeMetaForAsmJS)
                ? instance.codeMetaForAsmJS()->maybeScriptSource()
                      : nullptr;
        ScriptSource ss =module.codeMetaForAsmJS(java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
          CollectScriptSourceStats<granularity>(closure, ss);
        }
        instance                               :nullptr;
            rtStats->mallocSizeOf_        if(s{
            &closure->wasmSeenCodeMetadataForAsmJS, &closure->wasmSeenCode,
            , &info.objectsNonHeapCodeWasm
            &info        }
      }

      realmStatsmodule.(

constJSClass* clasp =obj>etClass();
      const char* className = clasp->name;
java.lang.StringIndexOutOfBoundsException: Range [18, 6) out of bounds for length 61

      if (            &infoobjectsNonHeapCodeWasm &nfo.);
orts ifacejava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
if(pv>getISupports_obj &face)&&iface) {
          realmStats        ScriptSource ss =
        }
      }
      reak;
    }

    case JS::TraceKind::Script
      BaseScript*base=&cellptr.asBaseScript>();
      RealmStats& realmStats = base->realm()->realmStats();
     realmStats.criptsGCHeap =thingSize;
      realmStats.scriptsGCBuffers += base->sizeOfExcludingThis();
      if  instance.ddSizeOfMisc(
        JSScript* script = static_cast<JSScript*>(base);
script>addSizeOfJitScriptrtStats-mallocSizeOf_,
                                   &realmStats.jitScripts,
                                   &realmStats.allocSites)java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
       jit:AddSizeOfBaselineData(script, rtStats->mallocSizeOf_,
                                   &realmStats.baselineData);
        realmStats.java.lang.StringIndexOutOfBoundsException: Range [0, 26) out of bounds for length 7
java.lang.StringIndexOutOfBoundsException: Range [30, 12) out of bounds for length 63
      java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
      CollectScriptSourceStats       JSClass*clasp =obj-getClass(;
;
    }

    case JS::TraceKind::String: {
      JSString* java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      size_t size =thingSize;
      if (!str->isTenured()) {
        size +=         nsISupports* if;
      }

      JS::StringInfo        if (pv>getISupports_obj,&)& iface){
      if (str->hasLatin1Chars()) {
       info.cHeapLatin1= size;
        info.java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 9
            str->java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 5
}else java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
java.lang.StringIndexOutOfBoundsException: Range [18, 8) out of bounds for length 34
        info.mallocHeapTwoByteRealmStats&realmStats  base>realm(-realmStats();
            str->sizeOfExcludingThis(rtStats->mallocSizeOf_);
      }
      info.numCopiesrealmStats.scriptsGCBuffers+ base-sizeOfExcludingThis();

      zStats->stringInfo.      if (ase>asJitScript()) {
      zStats->stringsTotalCount++

      /Theprimary use case  anonymization is automated crashsubmission
      // (to help detect OOM crashes). In that case, we don't want to pay the
      // memory cost required to do notable string detection.
      &realmStats.allocSites);
          !zStats->stringsDeduplicationTruncated) {
        closure->jit::AddSizeOfBaselineDatascript,rtStats-mallocSizeOf_,
        if !closure-stringBudget.isOverBudget)) {
          ZoneStats::StringsHashMap: jit::SizeOfIonData(script,rtStats-mallocSizeOf_);
              java.lang.StringIndexOutOfBoundsException: Range [0, 20) out of bounds for length 7
          if(){
            bool ok = java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 12
 - justwon't record the string as notablejava.lang.StringIndexOutOfBoundsException: Range [76, 77) out of bounds for length 76
            (void
           {
            p->value().add(info);
          }
        } else {
          zStats->stringsDeduplicationTruncated =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        }
      }
      break;
    }

    case/java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
      zStats-       (to help detect OOM crashes). In that case, we don't want to pay the
       (ranularity = FineGrained& !losure> &&

    case JS::TraceKind::BigInt: {
      JS::BigInt* bi = &cellptr.as<BigInt>();
      size_t size = thingSize;
      if (!bi->isTenured()) {
        size +java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
      }
      b =size
      zStats}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    }

     JS:TraceKind:BaseShape java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
      :ShapeInfoinfo /java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
      info.shapesGCHeapBase
      zStats.allStrings.reset();

      zStats->shapeInfo.add(info);
      break;
    }

 JS::java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
      GetterSetter* gs =  notableClasses(;
      size_t size = thingSize;
      if auto=allClassesiter) !done)iter) 
size =:(;
      }
      zStats->getterSettersGCHeap     =(.)
      break;
        

    case JS::TraceKind::java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 15
<PropMap)
      if (map       java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
        > =java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
      } else if (map->isCompact()) {
        zStats->compactPropMapsGCHeap += thingSize;
      } else {
        MOZ_ASSERT(map->isNormal());
        zStats->normalPropMapsGCHeap += thingSize;
      }
      map->addSizeOfExcludingThis(rtStats->mallocSizeOf_,
                                  &zStats->propMapChildren,
                                  &zStats->propMapTables);
      break;
    }

    case JS::TraceKind::JitCode: {
      zStats->jitCodesGCHeap += thingSize;
      // The code for a script is counted in ExecutableAllocator::sizeOfCode().
      break;
    }

    case JS::TraceKind::Shape: {
      Shape* shape = &cellptr.as<Shape>();

      JS::ShapeInfo info;  // This zeroes all the sizes.
      if (shape->isDictionary()) {
        info.shapesGCHeapDict += thingSize;
      } else {
        info.shapesGCHeapShared += thingSize;
      }
      shape->addSizeOfExcludingThis(rtStats->mallocSizeOf_, &info);
      zStats->shapeInfo.add(info);
      break;
    }

    case JS::TraceKind::Scope: {
      Scope* scope = &cellptr.as<Scope>();
      zStats->scopesGCHeap += thingSize;
      zStats->scopesGCBuffers += scope->sizeOfExcludingThis();
      break;
    }

    case JS::TraceKind::RegExpShared: {
      auto regexp = &cellptr.as<RegExpShared>();
      zStats->regExpSharedsGCHeap += thingSize;
      zStats->regExpSharedsMallocHeap +=
          regexp->sizeOfExcludingThis(rtStats->mallocSizeOf_);
      break;
    }

    default:
      MOZ_CRASH("invalid traceKind in StatsCellCallback");
  }

  // Yes, this is a subtraction:  see StatsArenaCallback() for details.
  zStats->unusedGCThings.addToKind(kind, -thingSize);
}

void ZoneStats::initStrings() {
  isTotals = false;
  allStrings.emplace();
}

void RealmStats::initClasses() {
  isTotals = false;
  allClasses.emplace();
}

static bool FindNotableStrings(ZoneStats& zStats) {
  using namespace JS;

  // We should only run FindNotableStrings once per ZoneStats object.
  MOZ_ASSERT(zStats.notableStrings.empty());

  for (auto iter = zStats.allStrings->iter(); !iter.done(); iter.next()) {
    JSString* str = iter.get().key();
    StringInfo& info = iter.get().value();

    if (!info.isNotable()) {
      continue;
    }

    if (!zStats.notableStrings.emplaceBack(str, info)) {
      return false;
    }

    // We're moving this string from a non-notable to a notable bucket, so
    // subtract it out of the non-notable tallies.
    zStats.stringInfo.subtract(info);
  }
  // Release |allStrings| now, rather than waiting for zStats's destruction, to
  // reduce peak memory consumption during reporting.
  zStats.allStrings.reset();
  return true;
}

static bool FindNotableClasses(RealmStats& realmStats) {
  using namespace JS;

  // We should only run FindNotableClasses once per ZoneStats object.
  MOZ_ASSERT(realmStats.notableClasses.empty());

  for (auto iter = realmStats.allClasses->iter(); !iter.done(); iter.next()) {
    const char* className = iter.get().key();
    ClassInfo& info = iter.get().value();

    // If this class isn't notable, or if we can't grow the notableStrings
    // vector, skip this string.
    if (!info.isNotable()) {
      continue;
    }

    if (!realmStats.notableClasses.emplaceBack(className, info)) {
      return false;
    }

    // We're moving this class from a non-notable to a notable bucket, so
    // subtract it out of the non-notable tallies.
    realmStats.classInfo.subtract(info);
  }
  // Release |allClasses| now, rather than waiting for zStats's destruction, to
  // reduce peak memory consumption during reporting.
  realmStats.allClasses.reset();
  return true;
}

static bool FindNotableScriptSources(JS::RuntimeSizes& runtime) {
  using namespace JS;

  // We should only run FindNotableScriptSources once per RuntimeSizes.
  MOZ_ASSERT(runtime.notableScriptSources.empty());

  for (auto iter = runtime.allScriptSources->iter(); !iter.done();
       iter.next()) {
    const char* filename = iter.get().key();
    ScriptSourceInfo& info = iter.get().value();

    if (!info.isNotable()) {
      continue;
    }

    if (!runtime.notableScriptSources.emplaceBack(filename, info)) {
      return false;
    }

    // We're moving this script source from a non-notable to a notable
    // bucket, so subtract its sizes from the non-notable tallies.
    runtime.scriptSourceInfo.subtract(info);
  }
  // Release |allScriptSources| now, rather than waiting for zStats's
  // destruction, to reduce peak memory consumption during reporting.
  runtime.allScriptSources.reset();
  return true;
}

static bool CollectRuntimeStatsHelper(JSContext* cx, RuntimeStats* rtStats,
                                      ObjectPrivateVisitor* opv, bool anonymize,
                                      IterateCellCallback statsCellCallback) {
  // Finish any ongoing incremental GC that may change the data we're gathering
  // and start a trace session. Ensure that we don't do anything that could
  // start another GC.
  js::gc::AutoPrepareForTracing session(cx);
  JS::AutoAssertNoGC nogc(cx);

  // Wait for any background tasks to finish.
  WaitForAllHelperThreads();

  JSRuntime* rt = cx->runtime();
  if (!rtStats->realmStatsVector.reserve(rt->numRealms)) {
    return false;
  }

  size_t totalZones = rt->gc.zones().length();
  if (!rtStats->zoneStatsVector.reserve(totalZones)) {
    return false;
  }

  rtStats->gcHeapChunkTotal =
      size_t(JS_GetGCParameter(cx, JSGC_TOTAL_CHUNKS)) * gc::ChunkSize;

  rtStats->gcHeapUnusedChunks =
      size_t(JS_GetGCParameter(cx, JSGC_UNUSED_CHUNKS)) * gc::ChunkSize;

  if (js::gc::DecommitEnabled()) {
    IterateChunks(cx, &rtStats->gcHeapDecommittedPages,
                  DecommittedPagesChunkCallback, session);
  }

  // Take the per-compartment measurements.
  StatsClosure closure(rtStats, opv, anonymize);
  IterateHeapUnbarriered(cx, &closure, StatsZoneCallback, StatsRealmCallback,
                         StatsArenaCallback, statsCellCallback, session);

  // Take the "explicit/js/runtime/" measurements.
  rt->addSizeOfIncludingThis(rtStats->mallocSizeOf_, &rtStats->runtime);

  if (!FindNotableScriptSources(rtStats->runtime)) {
    return false;
  }

  JS::ZoneStatsVector& zs = rtStats->zoneStatsVector;
  ZoneStats& zTotals = rtStats->zTotals;

  // We don't look for notable strings for zTotals. So we first sum all the
  // zones' measurements to get the totals. Then we find the notable strings
  // within each zone.
  for (size_t i = 0; i < zs.length(); i++) {
    zTotals.addSizes(zs[i]);
  }

  for (size_t i = 0; i < zs.length(); i++) {
    if (!FindNotableStrings(zs[i])) {
      return false;
    }
  }

  MOZ_ASSERT(!zTotals.allStrings);

  JS::RealmStatsVector& realmStats = rtStats->realmStatsVector;
  RealmStats& realmTotals = rtStats->realmTotals;

  // As with the zones, we sum all realms first, and then get the
  // notable classes within each zone.
  for (size_t i = 0; i < realmStats.length(); i++) {
    realmTotals.addSizes(realmStats[i]);
  }

  for (size_t i = 0; i < realmStats.length(); i++) {
    if (!FindNotableClasses(realmStats[i])) {
      return false;
    }
  }

  MOZ_ASSERT(!realmTotals.allClasses);

  rtStats->gcHeapGCThings = rtStats->zTotals.sizeOfLiveGCThings() +
                            rtStats->realmTotals.sizeOfLiveGCThings();

#ifdef DEBUG
  // Check that the in-arena measurements look ok.
  size_t totalArenaSize = rtStats->zTotals.gcHeapArenaAdmin +
                          rtStats->zTotals.unusedGCThings.totalSize() +
                          rtStats->gcHeapGCThings;
  MOZ_ASSERT(totalArenaSize % gc::ArenaSize == 0);
#endif

  for (RealmsIter realm(rt); !realm.done(); realm.next()) {
    realm->nullRealmStats();
  }

  size_t numDirtyChunks =
      (rtStats->gcHeapChunkTotal - rtStats->gcHeapUnusedChunks) / gc::ChunkSize;
  size_t perChunkAdmin =
      sizeof(gc::ArenaChunk) - (sizeof(gc::Arena) * gc::ArenasPerChunk);
  rtStats->gcHeapChunkAdmin = numDirtyChunks * perChunkAdmin;

  // |gcHeapUnusedArenas| is the only thing left.  Compute it in terms of
  // all the others.  See the comment in RuntimeStats for explanation.
  rtStats->gcHeapUnusedArenas =
      rtStats->gcHeapChunkTotal - rtStats->gcHeapDecommittedPages -
      rtStats->gcHeapUnusedChunks -
      rtStats->zTotals.unusedGCThings.totalSize() - rtStats->gcHeapChunkAdmin -
      rtStats->zTotals.gcHeapArenaAdmin - rtStats->gcHeapGCThings;
  return true;
}

JS_PUBLIC_API bool JS::CollectGlobalStats(GlobalStats* gStats) {
  AutoLockHelperThreadState lock;

  // HelperThreadState holds data that is not part of a Runtime. This does
  // not include data is is currently being processed by a HelperThread.
  if (IsHelperThreadStateInitialized()) {
    HelperThreadState().addSizeOfIncludingThis(gStats, lock);
  }

  return true;
}

JS_PUBLIC_API bool JS::CollectRuntimeStats(JSContext* cx, RuntimeStats* rtStats,
                                           ObjectPrivateVisitor* opv,
                                           bool anonymize) {
  return CollectRuntimeStatsHelper(cx, rtStats, opv, anonymize,
                                   StatsCellCallback<FineGrained>);
}

JS_PUBLIC_API size_t JS::SystemCompartmentCount(JSContext* cx) {
  size_t n = 0;
  for (CompartmentsIter comp(cx->runtime()); !comp.done(); comp.next()) {
    if (IsSystemCompartment(comp)) {
      ++n;
    }
  }
  return n;
}

JS_PUBLIC_API size_t JS::UserCompartmentCount(JSContext* cx) {
  size_t n = 0;
  for (CompartmentsIter comp(cx->runtime()); !comp.done(); comp.next()) {
    if (!IsSystemCompartment(comp)) {
      ++n;
    }
  }
  return n;
}

JS_PUBLIC_API size_t JS::SystemRealmCount(JSContext* cx) {
  size_t n = 0;
  for (RealmsIter realm(cx->runtime()); !realm.done(); realm.next()) {
    if (realm->isSystem()) {
      ++n;
    }
  }
  return n;
}

JS_PUBLIC_API size_t JS::UserRealmCount(JSContext* cx) {
  size_t n = 0;
  for (RealmsIter realm(cx->runtime()); !realm.done(); realm.next()) {
    if (!realm->isSystem()) {
      ++n;
    }
  }
  return n;
}

JS_PUBLIC_API size_t JS::PeakSizeOfTemporary(const JSContext* cx) {
  return cx->tempLifoAlloc().peakSizeOfExcludingThis();
}

namespace JS {

class SimpleJSRuntimeStats : public JS::RuntimeStats {
 public:
  explicit SimpleJSRuntimeStats(MallocSizeOf mallocSizeOf)
      : JS::RuntimeStats(mallocSizeOf) {}

  virtual void initExtraZoneStats(JS::Zone* zone, JS::ZoneStats* zStats,
                                  const JS::AutoRequireNoGC& nogc) override {}

  virtual void initExtraRealmStats(Realm* realm, JS::RealmStats* realmStats,
                                   const JS::AutoRequireNoGC& nogc) override {}
};

JS_PUBLIC_API bool AddSizeOfTab(JSContext* cx, JS::Zone* zone,
                                MallocSizeOf mallocSizeOf,
                                ObjectPrivateVisitor* opv, TabSizes* sizes,
                                const JS::AutoRequireNoGC& nogc) {
  SimpleJSRuntimeStats rtStats(mallocSizeOf);

  size_t numRealms = 0;
  for (CompartmentsInZoneIter comp(zone); !comp.done(); comp.next()) {
    numRealms += comp->realms().length();
  }

  if (!rtStats.realmStatsVector.reserve(numRealms)) {
    return false;
  }

  if (!rtStats.zoneStatsVector.reserve(1)) {
    return false;
  }

  // Take the per-compartment measurements. No need to anonymize because
  // these measurements will be aggregated.
  StatsClosure closure(&rtStats, opv, /* anonymize = */ false);
  MOZ_ASSERT(!JS::IsIncrementalGCInProgress(cx));
  js::gc::AutoTraceSession session(cx->runtime());
  IterateHeapUnbarrieredForZone(cx, zone, &closure, StatsZoneCallback,
                                StatsRealmCallback, StatsArenaCallback,
                                StatsCellCallback<CoarseGrained>, session);

  MOZ_ASSERT(rtStats.zoneStatsVector.length() == 1);
  rtStats.zTotals.addSizes(rtStats.zoneStatsVector[0]);

  for (size_t i = 0; i < rtStats.realmStatsVector.length(); i++) {
    rtStats.realmTotals.addSizes(rtStats.realmStatsVector[i]);
  }

  for (RealmsInZoneIter realm(zone); !realm.done(); realm.next()) {
    realm->nullRealmStats();
  }

  rtStats.zTotals.addToTabSizes(sizes);
  rtStats.realmTotals.addToTabSizes(sizes);

  return true;
}

}  // namespace JS

Messung V0.5 in Prozent
C=91 H=91 G=90

¤ Dauer der Verarbeitung: 0.13 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.