Changeset 38428 in webkit for trunk/JavaScriptCore/VM/Opcode.cpp
- Timestamp:
- Nov 15, 2008, 1:37:49 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/Opcode.cpp
r38425 r38428 35 35 namespace JSC { 36 36 37 #if ENABLE( BYTECODE_SAMPLING) || ENABLE(CODEBLOCK_SAMPLING) || ENABLE(BYTECODE_STATS)37 #if ENABLE(OPCODE_SAMPLING) || ENABLE(CODEBLOCK_SAMPLING) || ENABLE(OPCODE_STATS) 38 38 39 const char* const bytecodeNames[] = {40 #define BYTECODE_NAME_ENTRY(bytecode) #bytecode,41 FOR_EACH_ BYTECODE_ID(BYTECODE_NAME_ENTRY)42 #undef BYTECODE_NAME_ENTRY39 const char* const opcodeNames[] = { 40 #define OPCODE_NAME_ENTRY(opcode) #opcode, 41 FOR_EACH_OPCODE_ID(OPCODE_NAME_ENTRY) 42 #undef OPCODE_NAME_ENTRY 43 43 }; 44 44 45 45 #endif 46 46 47 #if ENABLE( BYTECODE_STATS)47 #if ENABLE(OPCODE_STATS) 48 48 49 long long BytecodeStats::bytecodeCounts[numBytecodeIDs];50 long long BytecodeStats::bytecodePairCounts[numBytecodeIDs][numBytecodeIDs];51 int BytecodeStats::lastBytecode = -1;49 long long OpcodeStats::opcodeCounts[numOpcodeIDs]; 50 long long OpcodeStats::opcodePairCounts[numOpcodeIDs][numOpcodeIDs]; 51 int OpcodeStats::lastOpcode = -1; 52 52 53 static BytecodeStats logger;53 static OpcodeStats logger; 54 54 55 BytecodeStats::BytecodeStats()55 OpcodeStats::OpcodeStats() 56 56 { 57 for (int i = 0; i < num BytecodeIDs; ++i)58 bytecodeCounts[i] = 0;57 for (int i = 0; i < numOpcodeIDs; ++i) 58 opcodeCounts[i] = 0; 59 59 60 for (int i = 0; i < num BytecodeIDs; ++i)61 for (int j = 0; j < num BytecodeIDs; ++j)62 bytecodePairCounts[i][j] = 0;60 for (int i = 0; i < numOpcodeIDs; ++i) 61 for (int j = 0; j < numOpcodeIDs; ++j) 62 opcodePairCounts[i][j] = 0; 63 63 } 64 64 65 static int compare BytecodeIndices(const void* left, const void* right)65 static int compareOpcodeIndices(const void* left, const void* right) 66 66 { 67 long long leftValue = BytecodeStats::bytecodeCounts[*(int*) left];68 long long rightValue = BytecodeStats::bytecodeCounts[*(int*) right];67 long long leftValue = OpcodeStats::opcodeCounts[*(int*) left]; 68 long long rightValue = OpcodeStats::opcodeCounts[*(int*) right]; 69 69 70 70 if (leftValue < rightValue) … … 76 76 } 77 77 78 static int compare BytecodePairIndices(const void* left, const void* right)78 static int compareOpcodePairIndices(const void* left, const void* right) 79 79 { 80 80 pair<int, int> leftPair = *(pair<int, int>*) left; 81 long long leftValue = BytecodeStats::bytecodePairCounts[leftPair.first][leftPair.second];81 long long leftValue = OpcodeStats::opcodePairCounts[leftPair.first][leftPair.second]; 82 82 pair<int, int> rightPair = *(pair<int, int>*) right; 83 long long rightValue = BytecodeStats::bytecodePairCounts[rightPair.first][rightPair.second];83 long long rightValue = OpcodeStats::opcodePairCounts[rightPair.first][rightPair.second]; 84 84 85 85 if (leftValue < rightValue) … … 91 91 } 92 92 93 BytecodeStats::~BytecodeStats()93 OpcodeStats::~OpcodeStats() 94 94 { 95 95 long long totalInstructions = 0; 96 for (int i = 0; i < num BytecodeIDs; ++i)97 totalInstructions += bytecodeCounts[i];96 for (int i = 0; i < numOpcodeIDs; ++i) 97 totalInstructions += opcodeCounts[i]; 98 98 99 99 long long totalInstructionPairs = 0; 100 for (int i = 0; i < num BytecodeIDs; ++i)101 for (int j = 0; j < num BytecodeIDs; ++j)102 totalInstructionPairs += bytecodePairCounts[i][j];100 for (int i = 0; i < numOpcodeIDs; ++i) 101 for (int j = 0; j < numOpcodeIDs; ++j) 102 totalInstructionPairs += opcodePairCounts[i][j]; 103 103 104 int sortedIndices[num BytecodeIDs];105 for (int i = 0; i < num BytecodeIDs; ++i)104 int sortedIndices[numOpcodeIDs]; 105 for (int i = 0; i < numOpcodeIDs; ++i) 106 106 sortedIndices[i] = i; 107 qsort(sortedIndices, num BytecodeIDs, sizeof(int), compareBytecodeIndices);107 qsort(sortedIndices, numOpcodeIDs, sizeof(int), compareOpcodeIndices); 108 108 109 pair<int, int> sortedPairIndices[num BytecodeIDs * numBytecodeIDs];109 pair<int, int> sortedPairIndices[numOpcodeIDs * numOpcodeIDs]; 110 110 pair<int, int>* currentPairIndex = sortedPairIndices; 111 for (int i = 0; i < num BytecodeIDs; ++i)112 for (int j = 0; j < num BytecodeIDs; ++j)111 for (int i = 0; i < numOpcodeIDs; ++i) 112 for (int j = 0; j < numOpcodeIDs; ++j) 113 113 *(currentPairIndex++) = make_pair(i, j); 114 qsort(sortedPairIndices, num BytecodeIDs * numBytecodeIDs, sizeof(pair<int, int>), compareBytecodePairIndices);114 qsort(sortedPairIndices, numOpcodeIDs * numOpcodeIDs, sizeof(pair<int, int>), compareOpcodePairIndices); 115 115 116 printf("\nExecuted bytecode statistics\n");116 printf("\nExecuted opcode statistics\n"); 117 117 118 118 printf("Total instructions executed: %lld\n\n", totalInstructions); 119 119 120 printf("All bytecodes by frequency:\n\n");120 printf("All opcodes by frequency:\n\n"); 121 121 122 for (int i = 0; i < num BytecodeIDs; ++i) {122 for (int i = 0; i < numOpcodeIDs; ++i) { 123 123 int index = sortedIndices[i]; 124 printf("%s:%s %lld - %.2f%%\n", bytecodeNames[index], padBytecodeName((BytecodeID)index, 28), bytecodeCounts[index], ((double) bytecodeCounts[index]) / ((double) totalInstructions) * 100.0);124 printf("%s:%s %lld - %.2f%%\n", opcodeNames[index], padOpcodeName((OpcodeID)index, 28), opcodeCounts[index], ((double) opcodeCounts[index]) / ((double) totalInstructions) * 100.0); 125 125 } 126 126 127 127 printf("\n"); 128 printf("2- bytecode sequences by frequency: %lld\n\n", totalInstructions);128 printf("2-opcode sequences by frequency: %lld\n\n", totalInstructions); 129 129 130 for (int i = 0; i < num BytecodeIDs * numBytecodeIDs; ++i) {130 for (int i = 0; i < numOpcodeIDs * numOpcodeIDs; ++i) { 131 131 pair<int, int> indexPair = sortedPairIndices[i]; 132 long long count = bytecodePairCounts[indexPair.first][indexPair.second];132 long long count = opcodePairCounts[indexPair.first][indexPair.second]; 133 133 134 134 if (!count) 135 135 break; 136 136 137 printf("%s%s %s:%s %lld %.2f%%\n", bytecodeNames[indexPair.first], padBytecodeName((BytecodeID)indexPair.first, 28), bytecodeNames[indexPair.second], padBytecodeName((BytecodeID)indexPair.second, 28), count, ((double) count) / ((double) totalInstructionPairs) * 100.0);137 printf("%s%s %s:%s %lld %.2f%%\n", opcodeNames[indexPair.first], padOpcodeName((OpcodeID)indexPair.first, 28), opcodeNames[indexPair.second], padOpcodeName((OpcodeID)indexPair.second, 28), count, ((double) count) / ((double) totalInstructionPairs) * 100.0); 138 138 } 139 139 140 140 printf("\n"); 141 printf("Most common bytecodes and sequences:\n");141 printf("Most common opcodes and sequences:\n"); 142 142 143 for (int i = 0; i < num BytecodeIDs; ++i) {143 for (int i = 0; i < numOpcodeIDs; ++i) { 144 144 int index = sortedIndices[i]; 145 long long bytecodeCount = bytecodeCounts[index];146 double bytecodeProportion = ((double) bytecodeCount) / ((double) totalInstructions);147 if ( bytecodeProportion < 0.0001)145 long long opcodeCount = opcodeCounts[index]; 146 double opcodeProportion = ((double) opcodeCount) / ((double) totalInstructions); 147 if (opcodeProportion < 0.0001) 148 148 break; 149 printf("\n%s:%s %lld - %.2f%%\n", bytecodeNames[index], padBytecodeName((BytecodeID)index, 28), bytecodeCount, bytecodeProportion * 100.0);149 printf("\n%s:%s %lld - %.2f%%\n", opcodeNames[index], padOpcodeName((OpcodeID)index, 28), opcodeCount, opcodeProportion * 100.0); 150 150 151 for (int j = 0; j < num BytecodeIDs * numBytecodeIDs; ++j) {151 for (int j = 0; j < numOpcodeIDs * numOpcodeIDs; ++j) { 152 152 pair<int, int> indexPair = sortedPairIndices[j]; 153 long long pairCount = bytecodePairCounts[indexPair.first][indexPair.second];153 long long pairCount = opcodePairCounts[indexPair.first][indexPair.second]; 154 154 double pairProportion = ((double) pairCount) / ((double) totalInstructionPairs); 155 155 156 if (!pairCount || pairProportion < 0.0001 || pairProportion < bytecodeProportion / 100)156 if (!pairCount || pairProportion < 0.0001 || pairProportion < opcodeProportion / 100) 157 157 break; 158 158 … … 160 160 continue; 161 161 162 printf(" %s%s %s:%s %lld - %.2f%%\n", bytecodeNames[indexPair.first], padBytecodeName((BytecodeID)indexPair.first, 28), bytecodeNames[indexPair.second], padBytecodeName((BytecodeID)indexPair.second, 28), pairCount, pairProportion * 100.0);162 printf(" %s%s %s:%s %lld - %.2f%%\n", opcodeNames[indexPair.first], padOpcodeName((OpcodeID)indexPair.first, 28), opcodeNames[indexPair.second], padOpcodeName((OpcodeID)indexPair.second, 28), pairCount, pairProportion * 100.0); 163 163 } 164 164 … … 167 167 } 168 168 169 void BytecodeStats::recordInstruction(int bytecode)169 void OpcodeStats::recordInstruction(int opcode) 170 170 { 171 bytecodeCounts[bytecode]++;171 opcodeCounts[opcode]++; 172 172 173 if (last Bytecode != -1)174 bytecodePairCounts[lastBytecode][bytecode]++;173 if (lastOpcode != -1) 174 opcodePairCounts[lastOpcode][opcode]++; 175 175 176 last Bytecode = bytecode;176 lastOpcode = opcode; 177 177 } 178 178 179 void BytecodeStats::resetLastInstruction()179 void OpcodeStats::resetLastInstruction() 180 180 { 181 last Bytecode = -1;181 lastOpcode = -1; 182 182 } 183 183
Note:
See TracChangeset
for help on using the changeset viewer.