+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.
#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
/*
* 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
#include <wtf/Assertions.h>
namespace KJS {
-
+
+#define DUMP_OPCODE_STATS 0
+
#define FOR_EACH_OPCODE_ID(macro) \
macro(op_load) \
macro(op_new_object) \
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
+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.