summaryrefslogtreecommitdiffstats
path: root/js/src/jit/CacheIRHealth.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit/CacheIRHealth.h
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit/CacheIRHealth.h')
-rw-r--r--js/src/jit/CacheIRHealth.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/js/src/jit/CacheIRHealth.h b/js/src/jit/CacheIRHealth.h
new file mode 100644
index 0000000000..b8146da6e3
--- /dev/null
+++ b/js/src/jit/CacheIRHealth.h
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ * 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/. */
+
+#ifndef jit_CacheIRHealth_h
+#define jit_CacheIRHealth_h
+
+#ifdef JS_CACHEIR_SPEW
+
+# include "mozilla/Sprintf.h"
+
+# include "jit/CacheIR.h"
+
+namespace js {
+namespace jit {
+
+class ICEntry;
+
+// [SMDOC] CacheIR Health Report
+//
+// The goal of CacheIR health report is to make the costlier
+// CacheIR stubs more apparent and easier to diagnose.
+// This is done by using the scores assigned to different CacheIROps in
+// CacheIROps.yaml (see the description of cost_estimate in the
+// aforementioned file for how these scores are determined), summing
+// the score of each op generated for a particular stub together, and displaying
+// this score for each stub in an inline cache. The higher the total stub score,
+// the more expensive the stub is.
+//
+// There are a few ways to generate a health report for a script:
+// 1. Simply running a JS program with the evironment variable
+// SPEW=RateMyCacheIR. We generate a health report for a script whenever we
+// reach the trial inlining threshold.
+// ex) SPEW=RateMyCacheIR dist/bin/js jsprogram.js
+// 2. In the shell you can call rateMyCacheIR() with no arguments and a report
+// will be generated for all scripts in the current zone.
+// ex) rateMyCacheIR()
+// 3. You may also call rateMyCacheIR() on a particular function to see the
+// health report associated with that function's script.
+// ex) rateMyCacheIR(foo)
+//
+// Once you have generated a health report, you may go to
+// https://carolinecullen.github.io/cacheirhealthreport/ to visualize the data
+// and aid in understanding what may be going wrong with the CacheIR for a
+// particular stub. For more information about the tool and why a particular
+// script, inline cache entry, or stub is unhappy go to:
+// https://carolinecullen.github.io/cacheirhealthreport/info.html
+//
+enum SpewContext : uint8_t { Shell, Transition, TrialInlining };
+
+class CacheIRHealth {
+ enum Happiness : uint8_t { Sad, MediumSad, MediumHappy, Happy };
+
+ // Get happiness from health score.
+ Happiness determineStubHappiness(uint32_t stubHealthScore);
+ // Health of an individual stub.
+ Happiness spewStubHealth(AutoStructuredSpewer& spew, ICCacheIRStub* stub);
+ // Health of all the stubs in an individual CacheIR Entry.
+ Happiness spewHealthForStubsInCacheIREntry(AutoStructuredSpewer& spew,
+ ICEntry* entry);
+ // Show JSOps present in the script, formatted for CacheIR
+ // health report.
+ Happiness spewJSOpAndCacheIRHealth(AutoStructuredSpewer& spew,
+ HandleScript script, jit::ICEntry* entry,
+ jsbytecode* pc, JSOp op);
+
+ public:
+ // Spews the final hit count for scripts where we care about its final hit
+ // count.
+ void spewScriptFinalWarmUpCount(JSContext* cx, const char* filename,
+ JSScript* script, uint32_t warmUpCount);
+ // Spew the health of a particular ICEntry only.
+ void rateIC(JSContext* cx, ICEntry* entry, HandleScript script,
+ SpewContext context);
+ // If a JitScript exists, spew the health of all ICEntries that exist
+ // for the specified script.
+ void rateScript(JSContext* cx, HandleScript script, SpewContext context);
+};
+
+} // namespace jit
+} // namespace js
+
+#endif /* JS_CACHEIR_SPEW */
+#endif /* jit_CacheIRHealth_h */