Another clarifying rename and a bit more automation.

kNumDalvikInstructions is now kNumPackedOpcodes, there is a new
kMaxOpcodeValue, and both are generated by opcode-gen.

Change-Id: Ic46f1f52d2d21382452c8e777024f4a985ad31d3
Bonus: Reworded the switch and array data comment for clarity.
diff --git a/vm/Globals.h b/vm/Globals.h
index fe36673..c2639cb 100644
--- a/vm/Globals.h
+++ b/vm/Globals.h
@@ -618,7 +618,7 @@
     Method**    inlinedMethods;
 
     /*
-     * Dalvik instruction counts (kNumDalvikInstructions entries).
+     * Dalvik instruction counts (kNumPackedOpcodes entries).
      */
     int*        executedInstrCounts;
     int         instructionCountEnableCount;
diff --git a/vm/Profile.c b/vm/Profile.c
index 6463dab..9b356f6 100644
--- a/vm/Profile.c
+++ b/vm/Profile.c
@@ -164,10 +164,10 @@
     /*
      * Allocate storage for instruction counters.
      */
-    gDvm.executedInstrCounts = (int*) malloc(kNumDalvikInstructions * sizeof(int));
+    gDvm.executedInstrCounts = (int*) malloc(kNumPackedOpcodes * sizeof(int));
     if (gDvm.executedInstrCounts == NULL)
         return false;
-    memset(gDvm.executedInstrCounts, 0, kNumDalvikInstructions * sizeof(int));
+    memset(gDvm.executedInstrCounts, 0, kNumPackedOpcodes * sizeof(int));
 
 #ifdef UPDATE_MAGIC_PAGE
     /*
diff --git a/vm/compiler/CompilerIR.h b/vm/compiler/CompilerIR.h
index c83c0ba..712ca4c 100644
--- a/vm/compiler/CompilerIR.h
+++ b/vm/compiler/CompilerIR.h
@@ -78,7 +78,7 @@
 } LIR;
 
 enum ExtendedMIROpcode {
-    kMirOpFirst = kNumDalvikInstructions,
+    kMirOpFirst = kNumPackedOpcodes,
     kMirOpPhi = kMirOpFirst,
     kMirOpNullNRangeUpCheck,
     kMirOpNullNRangeDownCheck,
diff --git a/vm/compiler/Dataflow.c b/vm/compiler/Dataflow.c
index 924ba62..82f52b9 100644
--- a/vm/compiler/Dataflow.c
+++ b/vm/compiler/Dataflow.c
@@ -21,7 +21,7 @@
 
 /*
  * Main table containing data flow attributes for each bytecode. The
- * first kNumDalvikInstructions entries are for Dalvik bytecode
+ * first kNumPackedOpcodes entries are for Dalvik bytecode
  * instructions, where extended opcode at the MIR level are appended
  * afterwards.
  *
diff --git a/vm/compiler/Loop.c b/vm/compiler/Loop.c
index c03d6f5..031464c 100644
--- a/vm/compiler/Loop.c
+++ b/vm/compiler/Loop.c
@@ -309,7 +309,7 @@
             dvmCompilerDataFlowAttributes[mir->dalvikInsn.opcode];
 
         /* Skip extended MIR instructions */
-        if (dInsn->opcode >= kNumDalvikInstructions) continue;
+        if (dInsn->opcode >= kNumPackedOpcodes) continue;
 
         int instrFlags = dexGetFlagsFromOpcode(dInsn->opcode);
 
diff --git a/vm/compiler/codegen/arm/CodegenCommon.c b/vm/compiler/codegen/arm/CodegenCommon.c
index 05cead3..4a20579 100644
--- a/vm/compiler/codegen/arm/CodegenCommon.c
+++ b/vm/compiler/codegen/arm/CodegenCommon.c
@@ -30,7 +30,7 @@
 static intptr_t templateEntryOffsets[TEMPLATE_LAST_MARK];
 
 /* Track exercised opcodes */
-static int opcodeCoverage[kNumDalvikInstructions];
+static int opcodeCoverage[kNumPackedOpcodes];
 
 static void setMemRefType(ArmLIR *lir, bool isLoad, int memType)
 {
diff --git a/vm/compiler/codegen/arm/CodegenDriver.c b/vm/compiler/codegen/arm/CodegenDriver.c
index 0c5b617..98236b6 100644
--- a/vm/compiler/codegen/arm/CodegenDriver.c
+++ b/vm/compiler/codegen/arm/CodegenDriver.c
@@ -4383,13 +4383,13 @@
 
     streak = i = 0;
     buf[0] = 0;
-    while (opcodeCoverage[i] == 0 && i < kNumDalvikInstructions) {
+    while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
         i++;
     }
-    if (i == kNumDalvikInstructions) {
+    if (i == kNumPackedOpcodes) {
         return;
     }
-    for (start = i++, streak = 1; i < kNumDalvikInstructions; i++) {
+    for (start = i++, streak = 1; i < kNumPackedOpcodes; i++) {
         if (opcodeCoverage[i]) {
             streak++;
         } else {
@@ -4399,10 +4399,10 @@
                 sprintf(buf+strlen(buf), "%x-%x,", start, start + streak - 1);
             }
             streak = 0;
-            while (opcodeCoverage[i] == 0 && i < kNumDalvikInstructions) {
+            while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
                 i++;
             }
-            if (i < kNumDalvikInstructions) {
+            if (i < kNumPackedOpcodes) {
                 streak = 1;
                 start = i;
             }
diff --git a/vm/compiler/codegen/x86/CodegenDriver.c b/vm/compiler/codegen/x86/CodegenDriver.c
index 60f003b..69f637e 100644
--- a/vm/compiler/codegen/x86/CodegenDriver.c
+++ b/vm/compiler/codegen/x86/CodegenDriver.c
@@ -24,7 +24,7 @@
  * applicable directory below this one.
  */
 
-static int opcodeCoverage[kNumDalvikInstructions];
+static int opcodeCoverage[kNumPackedOpcodes];
 static intptr_t templateEntryOffsets[TEMPLATE_LAST_MARK];
 
 /*
@@ -196,13 +196,13 @@
 
     streak = i = 0;
     buf[0] = 0;
-    while (opcodeCoverage[i] == 0 && i < kNumDalvikInstructions) {
+    while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
         i++;
     }
-    if (i == kNumDalvikInstructions) {
+    if (i == kNumPackedOpcodes) {
         return;
     }
-    for (start = i++, streak = 1; i < kNumDalvikInstructions; i++) {
+    for (start = i++, streak = 1; i < kNumPackedOpcodes; i++) {
         if (opcodeCoverage[i]) {
             streak++;
         } else {
@@ -212,10 +212,10 @@
                 sprintf(buf+strlen(buf), "%x-%x,", start, start + streak - 1);
             }
             streak = 0;
-            while (opcodeCoverage[i] == 0 && i < kNumDalvikInstructions) {
+            while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
                 i++;
             }
-            if (i < kNumDalvikInstructions) {
+            if (i < kNumPackedOpcodes) {
                 streak = 1;
                 start = i;
             }
diff --git a/vm/compiler/template/gen-template.py b/vm/compiler/template/gen-template.py
index addb21e..02e9107 100755
--- a/vm/compiler/template/gen-template.py
+++ b/vm/compiler/template/gen-template.py
@@ -146,7 +146,7 @@
 
 #
 # Extract an ordered list of instructions from the VM sources.  We use the
-# "goto table" definition macro, which has exactly kNumDalvikInstructions
+# "goto table" definition macro, which has exactly kNumPackedOpcodes
 # entries.
 #
 def getOpcodeList():
@@ -164,7 +164,7 @@
 
 
 #
-# Load and emit opcodes for all kNumDalvikInstructions instructions.
+# Load and emit opcodes for all kNumPackedOpcodes instructions.
 #
 def loadAndEmitOpcodes():
     sister_list = []
diff --git a/vm/mterp/Mterp.c b/vm/mterp/Mterp.c
index 2b2e0d1..f4740fe 100644
--- a/vm/mterp/Mterp.c
+++ b/vm/mterp/Mterp.c
@@ -48,7 +48,7 @@
      */
     const int width = 64;
     int interpSize = dvmAsmInstructionEnd - dvmAsmInstructionStart;
-    if (interpSize != 0 && interpSize != kNumDalvikInstructions*width) {
+    if (interpSize != 0 && interpSize != kNumPackedOpcodes*width) {
         LOGE("ERROR: unexpected asm interp size %d\n", interpSize);
         LOGE("(did an instruction handler exceed %d bytes?)\n", width);
         dvmAbort();
diff --git a/vm/mterp/README.txt b/vm/mterp/README.txt
index 058312e..9e28ebc 100644
--- a/vm/mterp/README.txt
+++ b/vm/mterp/README.txt
@@ -90,7 +90,7 @@
 
   op-end
 
-    Indicates the end of the opcode list.  All kNumDalvikInstructions
+    Indicates the end of the opcode list.  All kNumPackedOpcodes
     opcodes are emitted when this is seen, followed by any code that
     didn't fit inside the fixed-size instruction handler space.
 
@@ -108,7 +108,7 @@
 is special in two ways: (1) the sources are assumed to be C code, and
 will be inserted into the generated C file; (2) when a C implementation
 is emitted, a "glue stub" is emitted in the assembly source file.
-(The generator script always emits kNumDalvikInstructions assembly
+(The generator script always emits kNumPackedOpcodes assembly
 instructions, unless "asm-stub" was left blank, in which case it only
 emits some labels.)
 
diff --git a/vm/mterp/gen-mterp.py b/vm/mterp/gen-mterp.py
index 2c072ac..b55ed58 100755
--- a/vm/mterp/gen-mterp.py
+++ b/vm/mterp/gen-mterp.py
@@ -23,7 +23,7 @@
 from string import Template
 
 interp_defs_file = "../../libdex/DexOpcodes.h" # need opcode list
-kNumDalvikInstructions = 256 # TODO: Derive this from DexOpcodes.h.
+kNumPackedOpcodes = 256 # TODO: Derive this from DexOpcodes.h.
 
 verbose = False
 handler_size_bits = -1000
@@ -152,7 +152,7 @@
 
 #
 # Extract an ordered list of instructions from the VM sources.  We use the
-# "goto table" definition macro, which has exactly kNumDalvikInstructions
+# "goto table" definition macro, which has exactly kNumPackedOpcodes
 # entries.
 #
 def getOpcodeList():
@@ -166,19 +166,19 @@
         opcodes.append("OP_" + match.group(1))
     opcode_fp.close()
 
-    if len(opcodes) != kNumDalvikInstructions:
+    if len(opcodes) != kNumPackedOpcodes:
         print "ERROR: found %d opcodes in Interp.h (expected %d)" \
-                % (len(opcodes), kNumDalvikInstructions)
+                % (len(opcodes), kNumPackedOpcodes)
         raise SyntaxError, "bad opcode count"
     return opcodes
 
 
 #
-# Load and emit opcodes for all kNumDalvikInstructions instructions.
+# Load and emit opcodes for all kNumPackedOpcodes instructions.
 #
 def loadAndEmitOpcodes():
     sister_list = []
-    assert len(opcodes) == kNumDalvikInstructions
+    assert len(opcodes) == kNumPackedOpcodes
     need_dummy_start = False
 
     # point dvmAsmInstructionStart at the first handler or stub
@@ -187,7 +187,7 @@
     asm_fp.write("dvmAsmInstructionStart = " + label_prefix + "_OP_NOP\n")
     asm_fp.write("    .text\n\n")
 
-    for i in xrange(kNumDalvikInstructions):
+    for i in xrange(kNumPackedOpcodes):
         op = opcodes[i]
 
         if opcode_locations.has_key(op):
diff --git a/vm/native/dalvik_system_VMDebug.c b/vm/native/dalvik_system_VMDebug.c
index c5a72e4..bbb62dc 100644
--- a/vm/native/dalvik_system_VMDebug.c
+++ b/vm/native/dalvik_system_VMDebug.c
@@ -537,11 +537,11 @@
         u4 length = countArray->length;
 
         /*
-         * Ensure that we copy at most kNumDalvikInstructions
+         * Ensure that we copy at most kNumPackedOpcodes
          * elements, but no more than the length of the given array.
          */
-        if (length > kNumDalvikInstructions) {
-            length = kNumDalvikInstructions;
+        if (length > kNumPackedOpcodes) {
+            length = kNumPackedOpcodes;
         }
 
         sched_yield();
@@ -560,7 +560,7 @@
     JValue* pResult)
 {
     sched_yield();
-    memset(gDvm.executedInstrCounts, 0, kNumDalvikInstructions * sizeof(int));
+    memset(gDvm.executedInstrCounts, 0, kNumPackedOpcodes * sizeof(int));
     RETURN_VOID();
 }