Minor tweaks.

Use dexOpCodeFromCodeUnit instead of (*insns & 0xff).  (Not strictly
necessary in its current incarnation, but the code will soon be checking
opcode flags.)

Mark some local functions "static".

Make instruction widths >= 65536 a warning rather than an error.  I
don't think you can get there with converted Java bytecode because of
the method size limit, but it's possible in directly-generated DEX.

Change-Id: Ic9714b855c606f8b5c618793b271436e1c2cdc44
diff --git a/vm/analysis/CodeVerify.c b/vm/analysis/CodeVerify.c
index e1465b8..fe963b5 100644
--- a/vm/analysis/CodeVerify.c
+++ b/vm/analysis/CodeVerify.c
@@ -20,12 +20,6 @@
  *
  * TODO: might benefit from a signature-->class lookup cache.  Could avoid
  * some string-peeling and wouldn't need to compute hashes.
- *
- * TODO: we do too much stuff in here that could be done in the static
- * verification pass.  It's convenient, because we have all of the
- * necessary information, but it's more efficient to do it over in
- * DexVerify.c because in here we may have to process instructions
- * multiple times.
  */
 #include "Dalvik.h"
 #include "analysis/CodeVerify.h"
@@ -478,7 +472,7 @@
  * Entries, once set, do not change -- a given address can only allocate
  * one type of object.
  */
-int dvmSetUninitInstance(UninitInstanceMap* uninitMap, int addr,
+static int setUninitInstance(UninitInstanceMap* uninitMap, int addr,
     ClassObject* clazz)
 {
     int idx;
@@ -512,7 +506,8 @@
 /*
  * Get the class object at the specified index.
  */
-ClassObject* dvmGetUninitInstance(const UninitInstanceMap* uninitMap, int idx)
+static ClassObject* getUninitInstance(const UninitInstanceMap* uninitMap,
+    int idx)
 {
     assert(idx >= 0 && idx < uninitMap->numEntries);
     return uninitMap->map[idx].clazz;
@@ -555,7 +550,7 @@
     assert(regTypeIsReference(type) && type != kRegTypeZero);
     if (regTypeIsUninitReference(type)) {
         assert(uninitMap != NULL);
-        return dvmGetUninitInstance(uninitMap, regTypeToUninitIndex(type));
+        return getUninitInstance(uninitMap, regTypeToUninitIndex(type));
     } else {
         return (ClassObject*) type;
     }
@@ -787,7 +782,7 @@
          * field access until the superclass constructor is called.
          */
         if (isInitMethod(meth) && meth->clazz != gDvm.classJavaLangObject) {
-            int uidx = dvmSetUninitInstance(uninitMap, kUninitThisArgAddr,
+            int uidx = setUninitInstance(uninitMap, kUninitThisArgAddr,
                             meth->clazz);
             assert(uidx == 0);
             regTypes[argStart + actualArgs] = regTypeFromUninitIndex(uidx);
@@ -1699,7 +1694,7 @@
     RegType initType;
     int i, changed;
 
-    clazz = dvmGetUninitInstance(uninitMap, regTypeToUninitIndex(uninitType));
+    clazz = getUninitInstance(uninitMap, regTypeToUninitIndex(uninitType));
     if (clazz == NULL) {
         LOGE("VFY: unable to find type=0x%x (idx=%d)\n",
             uninitType, regTypeToUninitIndex(uninitType));
@@ -4122,7 +4117,7 @@
             }
 
             /* add resolved class to uninit map if not already there */
-            int uidx = dvmSetUninitInstance(uninitMap, insnIdx, resClass);
+            int uidx = setUninitInstance(uninitMap, insnIdx, resClass);
             assert(uidx >= 0);
             uninitType = regTypeFromUninitIndex(uidx);
 
diff --git a/vm/analysis/CodeVerify.h b/vm/analysis/CodeVerify.h
index be7231c..85b2e5e 100644
--- a/vm/analysis/CodeVerify.h
+++ b/vm/analysis/CodeVerify.h
@@ -304,28 +304,6 @@
 void dvmFreeUninitInstanceMap(UninitInstanceMap* uninitMap);
 
 /*
- * Associate a class with an address.  Returns the map slot index, or -1
- * if the address isn't listed in the map (shouldn't happen) or if a
- * different class is already associated with the address (shouldn't
- * happen either).
- */
-//int dvmSetUninitInstance(UninitInstanceMap* uninitMap, int addr,
-//    ClassObject* clazz);
-
-/*
- * Return the class associated with an uninitialized reference.  Pass in
- * the map index.
- */
-//ClassObject* dvmGetUninitInstance(const UninitInstanceMap* uninitMap, int idx);
-
-/*
- * Clear the class associated with an uninitialized reference.  Pass in
- * the map index.
- */
-//void dvmClearUninitInstance(UninitInstanceMap* uninitMap, int idx);
-
-
-/*
  * Verify bytecode in "meth".  "insnFlags" should be populated with
  * instruction widths and "in try" flags.
  */
diff --git a/vm/analysis/DexVerify.c b/vm/analysis/DexVerify.c
index 9a07559..feb5fba 100644
--- a/vm/analysis/DexVerify.c
+++ b/vm/analysis/DexVerify.c
@@ -96,18 +96,17 @@
         if (width == 0) {
             LOG_VFY_METH(meth, "VFY: invalid instruction (0x%04x)\n", *insns);
             goto bail;
+        } else if (width > 65535) {
+            LOG_VFY_METH(meth,
+                "VFY: warning: unusually large instr width (%d)\n", width);
         }
 
-        if ((*insns & 0xff) == OP_NEW_INSTANCE)
+        OpCode opcode = dexOpCodeFromCodeUnit(*insns);
+        if (opcode == OP_NEW_INSTANCE)
             newInstanceCount++;
-        if ((*insns & 0xff) == OP_MONITOR_ENTER)
+        if (opcode == OP_MONITOR_ENTER)
             monitorEnterCount++;
 
-        if (width > 65535) {
-            LOG_VFY_METH(meth, "VFY: insane width %d\n", width);
-            goto bail;
-        }
-
         insnFlags[i] |= width;
         i += width;
         insns += width;