2008-06-04 Cameron Zwarich <cwzwarich@uwaterloo.ca>
authorcwzwarich@webkit.org <cwzwarich@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jun 2008 04:39:09 +0000 (04:39 +0000)
committercwzwarich@webkit.org <cwzwarich@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jun 2008 04:39:09 +0000 (04:39 +0000)
        Reviewed by Oliver.

        Add an option to dump statistics on executed instructions.

        JavaScriptCore:

        * VM/Machine.cpp:
        (KJS::Machine::privateExecute):
        * VM/Opcode.cpp:
        (KJS::):
        (KJS::OpcodeStats::~OpcodeStats):
        (KJS::OpcodeStats::recordInstruction):
        * VM/Opcode.h:

        WebKitTools:

        * Scripts/check-for-global-initializers:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@34371 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/VM/Machine.cpp
JavaScriptCore/VM/Opcode.cpp
JavaScriptCore/VM/Opcode.h
WebKitTools/ChangeLog
WebKitTools/Scripts/check-for-global-initializers

index f31d6f9c08a5825784a4ed36a46c075bcc63675d..accdaf96825e71c162d7700d2d9f12280e3522fe 100644 (file)
@@ -1,3 +1,17 @@
+2008-06-04  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
+
+        Reviewed by Oliver.
+
+        Add an option to dump statistics on executed instructions.
+
+        * VM/Machine.cpp:
+        (KJS::Machine::privateExecute):
+        * VM/Opcode.cpp:
+        (KJS::):
+        (KJS::OpcodeStats::~OpcodeStats):
+        (KJS::OpcodeStats::recordInstruction):
+        * VM/Opcode.h:
+
 2008-06-04  Kevin McCullough  <kmccullough@apple.com>
 
         Reviewed by Geoff.
index 2d1b6904df4e7e74fdf7b12875a11f0c00e96ef7..2511862854e96db4f194d398883c1cf8eee3623b 100644 (file)
@@ -908,11 +908,19 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
 
 #if HAVE(COMPUTED_GOTO)
     #define NEXT_OPCODE goto *vPC->u.opcode
+#if DUMP_OPCODE_STATS
+    #define BEGIN_OPCODE(opcode) opcode: OpcodeStats::recordInstruction(opcode);
+#else
     #define BEGIN_OPCODE(opcode) opcode:
+#endif
     NEXT_OPCODE;
 #else
     #define NEXT_OPCODE continue
+#if DUMP_OPCODE_STATS
+    #define BEGIN_OPCODE(opcode) case opcode: OpcodeStats::recordInstruction(opcode);
+#else
     #define BEGIN_OPCODE(opcode) case opcode:
+#endif
     while(1) // iterator loop begins
     switch (vPC->u.opcode)
 #endif
index 84a64c5ea02a14778811e0990d33f3cb1001fadf..c23f78ab28ee5d87a7d641d111a0047e8952d5f6 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #include "Opcode.h"
 
+namespace KJS {
+
+#if DUMP_OPCODE_STATS
+
+unsigned OpcodeStats::opcodeCounts[numOpcodeIDs];
+
+static OpcodeStats logger;
+
+static const char* opcodeNames[] = {
+    "load",
+    "new_object",
+    "new_array",
+    "new_regexp",
+    "mov",
+    
+    "not",
+    "eq",
+    "neq",
+    "stricteq",
+    "nstricteq",
+    "less",
+    "lesseq",
+    
+    "pre_inc",
+    "pre_dec",
+    "post_inc",
+    "post_dec",
+    "to_jsnumber",
+    "negate",
+    "add",
+    "mul",
+    "div",
+    "mod",
+    "sub",
+    
+    "lshift",
+    "rshift",
+    "urshift",
+    "bitand",
+    "bitxor",
+    "bitor",
+    "bitnot",
+    
+    "instanceof",
+    "typeof",
+    "in",
+
+    "resolve",
+    "resolve_skip",
+    "get_scoped_var",
+    "put_scoped_var",
+    "resolve_base",
+    "resolve_with_base",
+    "resolve_func",
+    "get_by_id",
+    "put_by_id",
+    "del_by_id",
+    "get_by_val",
+    "put_by_val",
+    "del_by_val",
+    "put_by_index",
+    "put_getter",
+    "put_setter",
+
+    "jmp",
+    "jtrue",
+    "jfalse",
+    "jmp_scopes",
+
+    "new_func",
+    "new_func_exp",
+    "call",
+    "call_eval",
+    "ret",
+
+    "construct",
+
+    "get_pnames",
+    "next_pname",
+
+    "push_scope",
+    "pop_scope",
+
+    "catch",
+    "throw",
+    "new_error",
+
+    "jsr",
+    "sret",
+
+    "debug",
+
+    "end"    
+};
+
+OpcodeStats::OpcodeStats()
+{
+    for (int i = 0; i < numOpcodeIDs; ++i)
+        opcodeCounts[i] = 0;
+}
+
+OpcodeStats::~OpcodeStats()
+{
+    int totalInstructions = 0;
+    int sortedIndices[numOpcodeIDs];
+    
+    for (int i = 0; i < numOpcodeIDs; ++i) {
+        totalInstructions += opcodeCounts[i];
+        sortedIndices[i] = i;
+    }
+        
+    for (int i = 0; i < numOpcodeIDs - 1; ++i) {
+        int max = i;
+        
+        for (int j = i + 1; j < numOpcodeIDs; ++j) {
+            if (opcodeCounts[sortedIndices[j]] > opcodeCounts[sortedIndices[max]])
+                max = j;
+        }
+        
+        int temp = sortedIndices[i];
+        sortedIndices[i] = sortedIndices[max];
+        sortedIndices[max] = temp;
+    }
+    printf("\nExecuted opcode statistics:\n\n"); 
+    
+    printf("Total instructions executed: %d\n\n", totalInstructions);
+
+    for (int i = 0; i < numOpcodeIDs; ++i) {
+        int index = sortedIndices[i];
+        printf("%s: %.2f%%\n", opcodeNames[index], ((double) opcodeCounts[index]) / ((double) totalInstructions) * 100.0);    
+    }
+    
+    printf("\n");
+}
+
+void OpcodeStats::recordInstruction(int opcode)
+{
+    opcodeCounts[opcode]++;
+}
+
+#endif
+
+} // namespace WTF
index 5f9360607b3f1eb6c6f246cc9232fc2a4446f370..cf9d4b131441ca05392aad6c12da088dc68e4fb3 100644 (file)
@@ -33,7 +33,9 @@
 #include <wtf/Assertions.h>
 
 namespace KJS {
-        
+
+#define DUMP_OPCODE_STATS 0
+
     #define FOR_EACH_OPCODE_ID(macro) \
         macro(op_load) \
         macro(op_new_object) \
@@ -136,6 +138,17 @@ namespace KJS {
     typedef OpcodeID Opcode;
 #endif
 
+#if DUMP_OPCODE_STATS
+
+    struct OpcodeStats {
+        OpcodeStats();
+        ~OpcodeStats();
+        static unsigned opcodeCounts[numOpcodeIDs];
+        static void recordInstruction(int opcode);
+    };
+
+#endif
+
 } // namespace KJS
 
 #endif // Opcodes_h
index ac180796a4aee9a1ffc842cac7623bbeb188df06..dadbe132c1675a8949bd2c33ba410b3fd73ea449 100644 (file)
@@ -1,3 +1,12 @@
+2008-06-04  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
+
+        Reviewed by Oliver.
+
+        Add an exception for Opcode.o to the global initializers check so that
+        we can dump instruction statistics in the JavaScript virtual machine.
+
+        * Scripts/check-for-global-initializers:
+
 2008-05-30  Steve Falkenburg  <sfalken@apple.com>
 
         Generate an isolated COM manifest for registry free COM.
index c73b8cc050603fd1bb4116ae4f14c7c173d4ecbb..c6cae8b496455f498d0f04ebb7ad980632070ce0 100755 (executable)
@@ -96,6 +96,7 @@ for my $file (sort @files) {
             if ($target eq "JavaScriptCore") {
                 next if $shortName eq "nodes.o";
                 next if $shortName eq "AllInOneFile.o";
+                next if $shortName eq "Opcode.o";
             }
             if ($target eq "WebCore") {
                 next if $shortName eq "CachedPage.o";