changeset 53177:a2d1bb5a17dc lworld

8215259: [lworld]: Evolve the byte code API library to handle Q type forms
author sadayapalam
date Wed, 12 Dec 2018 13:12:17 +0530
parents 8dfebd4f5126
children 6c828d9cf6e8
files src/java.base/share/classes/java/lang/invoke/LambdaFormBuilder.java src/java.base/share/classes/jdk/experimental/bytecode/BasicTypeHelper.java src/java.base/share/classes/jdk/experimental/bytecode/BytePoolHelper.java src/java.base/share/classes/jdk/experimental/bytecode/CodeBuilder.java src/java.base/share/classes/jdk/experimental/bytecode/IsolatedMethodBuilder.java src/java.base/share/classes/jdk/experimental/bytecode/Pool.java src/java.base/share/classes/jdk/experimental/bytecode/PoolHelper.java src/java.base/share/classes/jdk/experimental/bytecode/TypeHelper.java src/java.base/share/classes/jdk/experimental/bytecode/TypedCodeBuilder.java src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java
diffstat 10 files changed, 85 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/LambdaFormBuilder.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/LambdaFormBuilder.java	Wed Dec 12 13:12:17 2018 +0530
@@ -407,7 +407,11 @@
                 }
             }
             if (InvokerBytecodeGenerator.isStaticallyNameable(cls)) {
-                checkcast(cls);
+                if (cls.isValue()) {
+                    checkvaluecast(cls);
+                } else {
+                    checkcast(cls);
+                }
             } else {
                 ldc(cls)
                     .checkcast(Class.class)
--- a/src/java.base/share/classes/jdk/experimental/bytecode/BasicTypeHelper.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/BasicTypeHelper.java	Wed Dec 12 13:12:17 2018 +0530
@@ -48,11 +48,21 @@
     }
 
     @Override
+    public boolean isValue(String t) {
+        return t.charAt(0) == 'Q' && t.endsWith(";");
+    }
+
+    @Override
     public String type(String s) {
         return "L" + s + ";";
     }
 
     @Override
+    public String valueType(String s) {
+        return "Q" + s + ";";
+    }
+
+    @Override
     public TypeTag tag(String s) {
         switch (s.charAt(0)) {
             case '[':
--- a/src/java.base/share/classes/jdk/experimental/bytecode/BytePoolHelper.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/BytePoolHelper.java	Wed Dec 12 13:12:17 2018 +0530
@@ -373,6 +373,11 @@
         return putClassInternal(symbolToString.apply(symbol));
     }
 
+    @Override
+    public int putValueClass(S symbol) {
+        return putClassInternal("Q" + symbolToString.apply(symbol) + ";");
+    }
+
     private int putClassInternal(String symbol) {
         key.setClass(symbol);
         PoolKey poolKey = entries.lookup(key);
--- a/src/java.base/share/classes/jdk/experimental/bytecode/CodeBuilder.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/CodeBuilder.java	Wed Dec 12 13:12:17 2018 +0530
@@ -180,12 +180,24 @@
         return thisBuilder();
     }
 
+    public C anewvaluearray(S array) {
+        emitOp(Opcode.ANEWARRAY, array);
+        code.writeChar(poolHelper.putValueClass(array));
+        return thisBuilder();
+    }
+
     public C checkcast(S target) {
         emitOp(Opcode.CHECKCAST);
         code.writeChar(poolHelper.putClass(target));
         return thisBuilder();
     }
 
+    public C checkvaluecast(S target) {
+        emitOp(Opcode.CHECKCAST);
+        code.writeChar(poolHelper.putValueClass(target));
+        return thisBuilder();
+    }
+
     public C instanceof_(S target) {
         emitOp(Opcode.INSTANCEOF);
         code.writeChar(poolHelper.putClass(target));
@@ -405,6 +417,10 @@
             return CodeBuilder.this.anewarray(s);
         }
 
+        public C anewvaluearray(S s) {
+            return CodeBuilder.this.anewvaluearray(s);
+        }
+
         public C aconst_null() {
             return CodeBuilder.this.aconst_null();
         }
@@ -1277,7 +1293,8 @@
                     } else {
                         //TODO: uninit this, top?
                         stackmaps.writeByte(7);
-                        stackmaps.writeChar(poolHelper.putClass(typeHelper.symbol(t)));
+                        stackmaps.writeChar(typeHelper.isValue(t) ?
+                                poolHelper.putValueClass(typeHelper.symbol(t)) : poolHelper.putClass(typeHelper.symbol(t)));
                     }
                     break;
                 default:
--- a/src/java.base/share/classes/jdk/experimental/bytecode/IsolatedMethodBuilder.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/IsolatedMethodBuilder.java	Wed Dec 12 13:12:17 2018 +0530
@@ -55,6 +55,11 @@
         }
 
         @Override
+        public int putValueClass(Class<?> symbol) {
+            return putIfAbsent(symbol);
+        }
+
+        @Override
         public int putFieldRef(Class<?> owner, CharSequence name, String type) {
             try {
                 Field f = owner.getDeclaredField(name.toString()); //TODO: we should unreflect for a var handle
--- a/src/java.base/share/classes/jdk/experimental/bytecode/Pool.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/Pool.java	Wed Dec 12 13:12:17 2018 +0530
@@ -335,6 +335,8 @@
             String name = getName();
             if (name.startsWith("[")) {
                 int index = name.indexOf("[L");
+                if (index == -1)
+                    index = name.indexOf("[Q");
                 if (index == -1) {
                     return null;
                 }
--- a/src/java.base/share/classes/jdk/experimental/bytecode/PoolHelper.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/PoolHelper.java	Wed Dec 12 13:12:17 2018 +0530
@@ -38,6 +38,8 @@
 public interface PoolHelper<S, T, R> {
     int putClass(S symbol);
 
+    int putValueClass(S symbol);
+
     int putFieldRef(S owner, CharSequence name, T type);
 
     int putMethodRef(S owner, CharSequence name, T type, boolean isInterface);
--- a/src/java.base/share/classes/jdk/experimental/bytecode/TypeHelper.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/TypeHelper.java	Wed Dec 12 13:12:17 2018 +0530
@@ -86,6 +86,24 @@
     T type(S s);
 
     /**
+     * Return true if the parameter is a value type.
+     *
+     * @param t the type descreiptor
+     * @return true if the given type is a value type
+     */
+    boolean isValue(T t);
+
+    /**
+     * For a symbol that corresponds to a value type, return the type descriptor.
+     *
+     * @param s the symbol
+     * @return the type descriptor
+     */
+    default T valueType(S s) {
+        return type(s);
+    }
+
+    /**
      * Return the symbol corresponding to a type descriptor.
      *
      * @param type the type descriptor
--- a/src/java.base/share/classes/jdk/experimental/bytecode/TypedCodeBuilder.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/TypedCodeBuilder.java	Wed Dec 12 13:12:17 2018 +0530
@@ -200,6 +200,14 @@
         }
 
         @Override
+        public C anewvaluearray(S s) {
+            super.anewvaluearray(s);
+            state.pop();
+            state.push(typeHelper.arrayOf(typeHelper.valueType(s)));
+            return thisBuilder();
+        }
+
+        @Override
         public C aconst_null() {
             super.aconst_null();
             state.pop();
@@ -966,6 +974,11 @@
             }
 
             @Override
+            public int putValueClass(S symbol) {
+                throw new IllegalStateException();
+            }
+
+            @Override
             public int putInt(int i) {
                 type = typeHelper.fromTag(TypeTag.I);
                 return poolHelper.putInt(i);
--- a/src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java	Wed Dec 12 12:36:24 2018 +0530
+++ b/src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java	Wed Dec 12 13:12:17 2018 +0530
@@ -174,11 +174,17 @@
                 if (aClass.isArray()) {
                     return classToInternalName(aClass);
                 } else {
-                    return "L" + classToInternalName(aClass) + ";";
+                    return (aClass.isValue() ? "Q" : "L") + classToInternalName(aClass) + ";";
                 }
             }
 
             @Override
+            public boolean isValue(String desc) {
+                Class<?> aClass = symbol(desc);
+                return aClass != null && aClass.isValue();
+            }
+
+            @Override
             public Class<?> symbol(String desc) {
                 try {
                     if (desc.startsWith("[")) {