changeset 3272:6acf2c8bf289

Enhancement: Remove dynamic instance tests from Code.java
author mcimadamore
date Tue, 08 Dec 2015 18:41:55 +0000
parents e7cdaa508aea
children 0c84a5536918
files src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java
diffstat 1 files changed, 62 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java	Tue Dec 08 16:29:38 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java	Tue Dec 08 18:41:55 2015 +0000
@@ -27,7 +27,6 @@
 
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.code.Types.UniqueType;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 
@@ -39,6 +38,17 @@
 import static com.sun.tools.javac.code.TypeTag.BOT;
 import static com.sun.tools.javac.code.TypeTag.INT;
 import static com.sun.tools.javac.jvm.ByteCodes.*;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Class;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Double;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Fieldref;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Float;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Integer;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_InterfaceMethodref;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Long;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_MethodHandle;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_MethodType;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Methodref;
+import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_String;
 import static com.sun.tools.javac.jvm.UninitializedType.*;
 import static com.sun.tools.javac.jvm.ClassWriter.StackMapTableFrame;
 
@@ -490,7 +500,7 @@
         emitop(invokespecial);
         if (!alive) return;
         emit2(meth);
-        Symbol sym = symbolForPool(pool.get(meth).data.get());
+        Symbol sym = memberForPool(meth);
         state.pop(argsize);
         if (sym.isConstructor())
             state.markInitialized((UninitializedType)state.peek());
@@ -952,7 +962,7 @@
             state.push(syms.intType);
             break;
         case ldc1:
-            state.push(typeForPool(pool.get(od).data.get()));
+            state.push(typeForPool(od));
             break;
         default:
             throw new AssertionError(mnem(op));
@@ -961,29 +971,51 @@
     }
 
     /** The type of a constant pool entry. */
-    private Type typeForPool(Object o) {
-        if (o instanceof Integer) return syms.intType;
-        if (o instanceof Float) return syms.floatType;
-        if (o instanceof String) return syms.stringType;
-        if (o instanceof Long) return syms.longType;
-        if (o instanceof Double) return syms.doubleType;
-        if (o instanceof ClassSymbol) return syms.classType;
-        if (o instanceof MethodHandleSymbol) return syms.methodHandleType;
-        if (o instanceof UniqueType) return typeForPool(((UniqueType)o).type);
-        if (o instanceof Type) {
-            Type ty = (Type) o;
-            if (ty instanceof Type.TypeVar) return syms.classType;
-            if (ty instanceof Type.ClassType) return syms.classType;
-            if (ty instanceof Type.ArrayType) return syms.classType;
-            if (ty instanceof Type.MethodType) return syms.methodTypeType;
+    private Type typeForPool(int idx) {
+        Pool.Entry e = pool.get(idx);
+        switch (e.tag) {
+            case CONSTANT_Integer: return syms.intType;
+            case CONSTANT_Float: return syms.floatType;
+            case CONSTANT_Long: return syms.longType;
+            case CONSTANT_Double: return syms.doubleType;
+            case CONSTANT_String: return syms.stringType;
+            case CONSTANT_Class: return syms.classType;
+            case CONSTANT_MethodHandle: return syms.methodHandleType;
+            case CONSTANT_MethodType: return syms.methodTypeType;
+            default:
+                Type t = (Type)e.data.get();
+                switch (t.getTag()) {
+                    case TYPEVAR:
+                    case CLASS:
+                    case ARRAY:
+                        return syms.classType;
+                    default:
+                        throw new AssertionError("Invalid type of constant pool entry: " + t.getClass());
+                }
         }
-        throw new AssertionError("Invalid type of constant pool entry: " + o.getClass());
+    }
+
+    /** The type of a class pool entry. */
+    private Type classForPool(int idx) {
+        Pool.Entry e = pool.get(idx);
+        switch (e.tag) {
+            case CONSTANT_Class: return (Type)e.data.get();
+            default:
+                throw new AssertionError("Invalid type of constant pool entry: " + e.data.get());
+        }
     }
 
     /** The symbol of a constant pool entry. */
-    private Symbol symbolForPool(Object o) {
-        if (o instanceof Symbol) return (Symbol)o;
-        throw new AssertionError("Invalid symbol of constant pool entry: " + o.getClass());
+    private Symbol memberForPool(int idx) {
+        Pool.Entry e = pool.get(idx);
+        switch (e.tag) {
+            case CONSTANT_Fieldref:
+            case CONSTANT_InterfaceMethodref:
+            case CONSTANT_Methodref:
+                return (Symbol)e.data.get();
+            default:
+                throw new AssertionError("Invalid symbol of constant pool entry: " + e.data.get().getClass());
+        }
     }
 
     /** Emit an opcode with a one-byte operand field;
@@ -1076,21 +1108,14 @@
         emit2(od);
         switch (op) {
         case getstatic:
-            state.push(symbolForPool(pool.get(od).data.get()).externalType(types));
+            state.push(memberForPool(od).externalType(types));
             break;
         case putstatic:
-            state.pop(symbolForPool(pool.get(od).data.get()).externalType(types));
+            state.pop(memberForPool(od).externalType(types));
             break;
         case vnew:
         case new_:
-            Type t;
-            if (pool.get(od).data.get() instanceof Type) {
-                // Required by change in Gen.makeRef to allow
-                // annotated types.
-                t = (Type)pool.get(od).data.get();
-            } else {
-                t = ((Symbol)(pool.get(od).data.get())).type;
-            }
+            Type t = classForPool(od);
             state.push(uninitializedObject(t, cp-3));
             break;
         case sipush:
@@ -1120,31 +1145,28 @@
             markDead();
             break;
         case putfield:
-            state.pop(symbolForPool(pool.get(od).data.get()).externalType(types));
+            state.pop(memberForPool(od).externalType(types));
             state.pop(1); // object ref
             break;
         case getfield:
         case vgetfield:
             state.pop(1); // object ref
-            state.push(symbolForPool(pool.get(od).data.get()).externalType(types));
+            state.push(memberForPool(od).externalType(types));
             break;
         case checkcast: {
             state.pop(1); // object ref
-            Object o = pool.get(od).data.get();
-            Type cat = (o instanceof Symbol)
-                ? ((Symbol)o).erasure(types)
-                : (Type)o;
+            Type cat = classForPool(od);
             state.push(cat);
             break; }
         case ldc2w:
-            state.push(typeForPool(pool.get(od).data.get()));
+            state.push(typeForPool(od));
             break;
         case instanceof_:
             state.pop(1);
             state.push(syms.intType);
             break;
         case ldc2:
-            state.push(typeForPool(pool.get(od).data.get()));
+            state.push(typeForPool(od));
             break;
         case jsr:
         case typed: