Title: [236430] trunk/Source/_javascript_Core
Revision
236430
Author
tzaga...@apple.com
Date
2018-09-24 15:03:34 -0700 (Mon, 24 Sep 2018)

Log Message

Add forEach method for iterating CodeBlock's ValueProfiles
https://bugs.webkit.org/show_bug.cgi?id=189897

Reviewed by Mark Lam.

Add method to abstract how we find ValueProfiles in a CodeBlock in
preparation for https://bugs.webkit.org/show_bug.cgi?id=189785, when
ValueProfiles will be stored in the MetadataTable.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::updateAllPredictionsAndCountLiveness):
(JSC::CodeBlock::updateAllValueProfilePredictions):
(JSC::CodeBlock::shouldOptimizeNow):
(JSC::CodeBlock::dumpValueProfiles):
* bytecode/CodeBlock.h:
(JSC::CodeBlock::forEachValueProfile):
(JSC::CodeBlock::numberOfArgumentValueProfiles):
(JSC::CodeBlock::valueProfileForArgument):
(JSC::CodeBlock::numberOfValueProfiles):
(JSC::CodeBlock::valueProfile):
(JSC::CodeBlock::totalNumberOfValueProfiles): Deleted.
(JSC::CodeBlock::getFromAllValueProfiles): Deleted.
* tools/HeapVerifier.cpp:
(JSC::HeapVerifier::validateJSCell):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (236429 => 236430)


--- trunk/Source/_javascript_Core/ChangeLog	2018-09-24 21:48:13 UTC (rev 236429)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-09-24 22:03:34 UTC (rev 236430)
@@ -1,3 +1,30 @@
+2018-09-24  Tadeu Zagallo  <tzaga...@apple.com>
+
+        Add forEach method for iterating CodeBlock's ValueProfiles
+        https://bugs.webkit.org/show_bug.cgi?id=189897
+
+        Reviewed by Mark Lam.
+
+        Add method to abstract how we find ValueProfiles in a CodeBlock in
+        preparation for https://bugs.webkit.org/show_bug.cgi?id=189785, when
+        ValueProfiles will be stored in the MetadataTable.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::updateAllPredictionsAndCountLiveness):
+        (JSC::CodeBlock::updateAllValueProfilePredictions):
+        (JSC::CodeBlock::shouldOptimizeNow):
+        (JSC::CodeBlock::dumpValueProfiles):
+        * bytecode/CodeBlock.h:
+        (JSC::CodeBlock::forEachValueProfile):
+        (JSC::CodeBlock::numberOfArgumentValueProfiles):
+        (JSC::CodeBlock::valueProfileForArgument):
+        (JSC::CodeBlock::numberOfValueProfiles):
+        (JSC::CodeBlock::valueProfile):
+        (JSC::CodeBlock::totalNumberOfValueProfiles): Deleted.
+        (JSC::CodeBlock::getFromAllValueProfiles): Deleted.
+        * tools/HeapVerifier.cpp:
+        (JSC::HeapVerifier::validateJSCell):
+
 2018-09-24  Saam barati  <sbar...@apple.com>
 
         ArgumentsEliminationPhase should snip basic blocks after proven OSR exits

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (236429 => 236430)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2018-09-24 21:48:13 UTC (rev 236429)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2018-09-24 22:03:34 UTC (rev 236430)
@@ -2575,8 +2575,7 @@
     numberOfLiveNonArgumentValueProfiles = 0;
     numberOfSamplesInProfiles = 0; // If this divided by ValueProfile::numberOfBuckets equals numberOfValueProfiles() then value profiles are full.
 
-    for (unsigned i = 0; i < totalNumberOfValueProfiles(); ++i) {
-        ValueProfile& profile = ""
+    forEachValueProfile([&](ValueProfile& profile) {
         unsigned numSamples = profile.totalNumberOfSamples();
         if (numSamples > ValueProfile::numberOfBuckets)
             numSamples = ValueProfile::numberOfBuckets; // We don't want profiles that are extremely hot to be given more weight.
@@ -2583,12 +2582,12 @@
         numberOfSamplesInProfiles += numSamples;
         if (profile.m_bytecodeOffset < 0) {
             profile.computeUpdatedPrediction(locker);
-            continue;
+            return;
         }
         if (profile.numberOfSamples() || profile.m_prediction != SpecNone)
             numberOfLiveNonArgumentValueProfiles++;
         profile.computeUpdatedPrediction(locker);
-    }
+    });
 
     for (auto& profileBucket : m_catchProfiles) {
         profileBucket->forEach([&] (ValueProfileAndOperand& profile) {
@@ -2642,13 +2641,13 @@
     if (Options::verboseOSR()) {
         dataLogF(
             "Profile hotness: %lf (%u / %u), %lf (%u / %u)\n",
-            (double)numberOfLiveNonArgumentValueProfiles / numberOfValueProfiles(),
-            numberOfLiveNonArgumentValueProfiles, numberOfValueProfiles(),
-            (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / numberOfValueProfiles(),
-            numberOfSamplesInProfiles, ValueProfile::numberOfBuckets * numberOfValueProfiles());
+            (double)numberOfLiveNonArgumentValueProfiles / numberOfNonArgumentValueProfiles(),
+            numberOfLiveNonArgumentValueProfiles, numberOfNonArgumentValueProfiles(),
+            (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / numberOfNonArgumentValueProfiles(),
+            numberOfSamplesInProfiles, ValueProfile::numberOfBuckets * numberOfNonArgumentValueProfiles());
     }
 
-    if ((!numberOfValueProfiles() || (double)numberOfLiveNonArgumentValueProfiles / numberOfValueProfiles() >= Options::desiredProfileLivenessRate())
+    if ((!numberOfNonArgumentValueProfiles() || (double)numberOfLiveNonArgumentValueProfiles / numberOfNonArgumentValueProfiles() >= Options::desiredProfileLivenessRate())
         && (!totalNumberOfValueProfiles() || (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / totalNumberOfValueProfiles() >= Options::desiredProfileFullnessRate())
         && static_cast<unsigned>(m_optimizationDelayCounter) + 1 >= Options::minimumOptimizationDelay())
         return true;
@@ -2700,8 +2699,7 @@
 void CodeBlock::dumpValueProfiles()
 {
     dataLog("ValueProfile for ", *this, ":\n");
-    for (unsigned i = 0; i < totalNumberOfValueProfiles(); ++i) {
-        ValueProfile& profile = ""
+    forEachValueProfile([](ValueProfile& profile) {
         if (profile.m_bytecodeOffset < 0) {
             ASSERT(profile.m_bytecodeOffset == -1);
             dataLogF("   arg = %u: ", i);
@@ -2713,7 +2711,7 @@
         }
         profile.dump(WTF::dataFile());
         dataLogF("\n");
-    }
+    });
     dataLog("RareCaseProfile for ", *this, ":\n");
     for (unsigned i = 0; i < numberOfRareCaseProfiles(); ++i) {
         RareCaseProfile* profile = ""

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.h (236429 => 236430)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2018-09-24 21:48:13 UTC (rev 236429)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2018-09-24 22:03:34 UTC (rev 236430)
@@ -415,6 +415,7 @@
         ASSERT(m_argumentValueProfiles.size() == static_cast<unsigned>(m_numParameters) || !vm()->canUseJIT());
         return m_argumentValueProfiles.size();
     }
+
     ValueProfile& valueProfileForArgument(unsigned argumentIndex)
     {
         ASSERT(vm()->canUseJIT()); // This is only called from the various JIT compilers or places that first check numberOfArgumentValueProfiles before calling this.
@@ -423,10 +424,7 @@
         return result;
     }
 
-    unsigned numberOfValueProfiles() { return m_valueProfiles.size(); }
-    ValueProfile& valueProfile(int index) { return m_valueProfiles[index]; }
     ValueProfile& valueProfileForBytecodeOffset(int bytecodeOffset);
-    ValueProfile* tryGetValueProfileForBytecodeOffset(int bytecodeOffset);
     SpeculatedType valueProfilePredictionForBytecodeOffset(const ConcurrentJSLocker& locker, int bytecodeOffset)
     {
         if (ValueProfile* valueProfile = tryGetValueProfileForBytecodeOffset(bytecodeOffset))
@@ -434,16 +432,13 @@
         return SpecNone;
     }
 
-    unsigned totalNumberOfValueProfiles()
+    template<typename Functor> void forEachValueProfile(const Functor& func)
     {
-        return numberOfArgumentValueProfiles() + numberOfValueProfiles();
+        for (unsigned i = 0; i < numberOfArgumentValueProfiles(); ++i)
+            func(valueProfileForArgument(i));
+        for (unsigned i = 0; i < numberOfValueProfiles(); ++i)
+            func(valueProfile(i));
     }
-    ValueProfile& getFromAllValueProfiles(unsigned index)
-    {
-        if (index < numberOfArgumentValueProfiles())
-            return valueProfileForArgument(index);
-        return valueProfile(index - numberOfArgumentValueProfiles());
-    }
 
     RareCaseProfile* addRareCaseProfile(int bytecodeOffset);
     unsigned numberOfRareCaseProfiles() { return m_rareCaseProfiles.size(); }
@@ -926,6 +921,12 @@
     void stronglyVisitWeakReferences(const ConcurrentJSLocker&, SlotVisitor&);
     void visitOSRExitTargets(const ConcurrentJSLocker&, SlotVisitor&);
 
+    unsigned numberOfValueProfiles() { return m_valueProfiles.size(); }
+    unsigned numberOfNonArgumentValueProfiles() { return numberOfValueProfiles(); }
+    unsigned totalNumberOfValueProfiles() { return numberOfArgumentValueProfiles() + numberOfNonArgumentValueProfiles(); }
+    ValueProfile& valueProfile(int index) { return m_valueProfiles[index]; }
+    ValueProfile* tryGetValueProfileForBytecodeOffset(int bytecodeOffset);
+
     Seconds timeSinceCreation()
     {
         return MonotonicTime::now() - m_creationTime;

Modified: trunk/Source/_javascript_Core/tools/HeapVerifier.cpp (236429 => 236430)


--- trunk/Source/_javascript_Core/tools/HeapVerifier.cpp	2018-09-24 21:48:13 UTC (rev 236429)
+++ trunk/Source/_javascript_Core/tools/HeapVerifier.cpp	2018-09-24 22:03:34 UTC (rev 236430)
@@ -330,8 +330,7 @@
         CodeBlock* codeBlock = jsDynamicCast<CodeBlock*>(vm, cell);
         if (UNLIKELY(codeBlock)) {
             bool success = true;
-            for (unsigned i = 0; i < codeBlock->totalNumberOfValueProfiles(); ++i) {
-                ValueProfile& valueProfile = codeBlock->getFromAllValueProfiles(i);
+            codeBlock->forEachValueProfile([&](ValueProfile& valueProfile) {
                 for (unsigned i = 0; i < ValueProfile::totalNumberOfBuckets; ++i) {
                     JSValue value = JSValue::decode(valueProfile.m_buckets[i]);
                     if (!value)
@@ -346,7 +345,7 @@
                         continue;
                     }
                 }
-            }
+            });
             if (!success)
                 return false;
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to