Anonymous avatar Anonymous committed 1c1559c

added opcount patch

Comments (0)

Files changed (2)

-The patch applies to Tracemonkey. It instruments the JS engine to log what
-activity the engine is doing at a given time to /tmp/jsacts.
+Both patches apply to Tracemonkey.
+
+metric-lwact.diff -- instruments the JS engine to log what activity the
+                     engine is doing at a given time to /tmp/jsacts.
+
+metric-opcounts.diff -- instruments the JS engine to log how many opcodes
+                     are executed interpreted, recorded, and natively to
+                     /tmp/jsopcounts.

patches/metric-opcount.diff

+diff -r 23b500845c92 js/src/jsapi.cpp
+--- a/js/src/jsapi.cpp	Fri Mar 20 14:24:27 2009 -0700
++++ b/js/src/jsapi.cpp	Fri Mar 20 16:21:22 2009 -0700
+@@ -722,6 +722,8 @@ JS_NewRuntime(uint32 maxbytes)
+ {
+     if (!mon_logFile)
+         mon_logFile = fopen("/tmp/jsacts", "wb");
++    if (!mon_opCountFile)
++        mon_opCountFile = fopen("/tmp/jsopcounts", "w");
+ 
+     JSRuntime *rt;
+ 
+@@ -899,6 +901,13 @@ JS_ShutDown(void)
+ {
+     if (mon_logFile)
+         fclose(mon_logFile);
++
++    if (mon_opCountFile) {
++        for (int i = 0; i < S_COUNT; ++i) {
++            fprintf(mon_opCountFile, "%d\n", mon_opCounts[i]);
++        }
++        fclose(mon_opCountFile);
++    }
+ 
+ #ifdef JS_OPMETER
+     extern void js_DumpOpMeters();
+diff -r 23b500845c92 js/src/jsinterp.cpp
+--- a/js/src/jsinterp.cpp	Fri Mar 20 14:24:27 2009 -0700
++++ b/js/src/jsinterp.cpp	Fri Mar 20 16:21:22 2009 -0700
+@@ -2563,6 +2563,7 @@ js_Interpret(JSContext *cx)
+ # endif
+ 
+ # define DO_OP()            JS_BEGIN_MACRO                                    \
++        ++mon_opCounts[jumpTable == interruptJumpTable ? S_RECORD : S_INTERP]; \
+                                 CHECK_RECORDER();                             \
+                                 JS_EXTENSION_(goto *jumpTable[op]);           \
+                             JS_END_MACRO
+diff -r 23b500845c92 js/src/jstracer.cpp
+--- a/js/src/jstracer.cpp	Fri Mar 20 14:24:27 2009 -0700
++++ b/js/src/jstracer.cpp	Fri Mar 20 16:21:22 2009 -0700
+@@ -77,6 +77,8 @@
+ #include "imacros.c.out"
+ 
+ FILE* mon_logFile = NULL;
++FILE* mon_opCountFile = NULL;
++int mon_opCounts[S_COUNT] = { 0 };
+ 
+ /* Never use JSVAL_IS_BOOLEAN because it restricts the value (true, false) and
+    the type. What you want to use is JSVAL_TAG(x) == JSVAL_BOOLEAN and then
+@@ -4446,6 +4448,9 @@ TraceRecorder::monitorRecording(JSContex
+     /* If op is not a break or a return from a loop, continue recording and follow the
+        trace. We check for imacro-calling bytecodes inside each switch case to resolve
+        the if (JSOP_IS_IMACOP(x)) conditions at compile time. */
++    
++    if (0 <= op && op <= 232)
++        tr->record_Op();
+ 
+     bool flag;
+     switch (op) {
+@@ -6113,6 +6118,16 @@ TraceRecorder::clearFrameSlotsFromCache(
+     vpstop = &fp->slots[fp->script->nslots];
+     while (vp < vpstop)
+         nativeFrameTracker.set(vp++, (LIns*)0);
++}
++
++void
++TraceRecorder::record_Op()
++{
++    /* Increment the op counter */
++    LIns* count_addr = lir->insImmPtr(&mon_opCounts[S_NATIVE]);
++    LIns* count = lir->insLoad(LIR_ld, count_addr, lir->insImm(0));
++    LIns* count1 = lir->ins2(LIR_add, count, lir->insImm(1));
++    lir->insStore(count1, count_addr, lir->insImm(0));
+ }
+ 
+ JS_REQUIRES_STACK bool
+diff -r 23b500845c92 js/src/jstracer.h
+--- a/js/src/jstracer.h	Fri Mar 20 14:24:27 2009 -0700
++++ b/js/src/jstracer.h	Fri Mar 20 16:21:22 2009 -0700
+@@ -581,6 +581,9 @@ public:
+     void popAbortStack();
+     void removeFragmentoReferences();
+ 
++    /* Recording action to do for every op. */
++    void record_Op();
++
+     JS_REQUIRES_STACK bool record_EnterFrame();
+     JS_REQUIRES_STACK bool record_LeaveFrame();
+     JS_REQUIRES_STACK bool record_SetPropHit(JSPropCacheEntry* entry, JSScopeProperty* sprop);
+@@ -659,6 +662,8 @@ enum mon_State {
+     S_COMPILE,
+     S_EXECUTE,
+     S_NATIVE,
++
++    S_COUNT,
+ };
+ 
+ /* Reason for an exit to the interpreter. */
+@@ -715,6 +720,15 @@ mon_ExitState(mon_ExitReason r)
+     mon_LogState(S_EXITLAST, r);
+ }
+ 
++extern FILE* mon_opCountFile;
++extern int mon_opCounts[S_COUNT];
++
++inline void
++mon_LogOp(mon_State s) 
++{
++    ++mon_opCounts[s];
++}
++
+ struct mon_StateObj {
+     mon_ExitReason r;
+ 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.