changeset 14979:5dfaaa91be37

fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
author twisti
date Fri, 04 Apr 2014 16:40:24 -0700
parents e302df8bf51c
children a00b26a70011
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java
diffstat 2 files changed, 58 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Fri Apr 04 18:32:32 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Fri Apr 04 16:40:24 2014 -0700
@@ -1109,6 +1109,7 @@
     @HotSpotVMConstant(name = "JVM_CONSTANT_MethodHandleInError") @Stable public int jvmConstantMethodHandleInError;
     @HotSpotVMConstant(name = "JVM_CONSTANT_MethodType") @Stable public int jvmConstantMethodType;
     @HotSpotVMConstant(name = "JVM_CONSTANT_MethodTypeInError") @Stable public int jvmConstantMethodTypeInError;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_InvokeDynamic") @Stable public int jvmConstantInvokeDynamic;
 
     @HotSpotVMConstant(name = "HeapWordSize") @Stable public int heapWordSize;
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java	Fri Apr 04 18:32:32 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java	Fri Apr 04 16:40:24 2014 -0700
@@ -61,7 +61,8 @@
         MethodHandle(config().jvmConstantMethodHandle),
         MethodHandleInError(config().jvmConstantMethodHandleInError),
         MethodType(config().jvmConstantMethodType),
-        MethodTypeInError(config().jvmConstantMethodTypeInError);
+        MethodTypeInError(config().jvmConstantMethodTypeInError),
+        InvokeDynamic(config().jvmConstantInvokeDynamic);
         // @formatter:on
 
         private final int value;
@@ -95,7 +96,7 @@
 
     /**
      * Gets the holder for this constant pool as {@link HotSpotResolvedObjectType}.
-     * 
+     *
      * @return holder for this constant pool
      */
     private HotSpotResolvedObjectType getHolder() {
@@ -106,7 +107,7 @@
     /**
      * Converts a raw index from the bytecodes to a constant pool index by adding a
      * {@link HotSpotVMConfig#constantPoolCpCacheIndexTag constant}.
-     * 
+     *
      * @param rawIndex index from the bytecode
      * @param opcode bytecode to convert the index for
      * @return constant pool index
@@ -126,8 +127,39 @@
     }
 
     /**
+     * Decode a constant pool cache index to a constant pool index.
+     *
+     * See {@code ConstantPool::decode_cpcache_index}.
+     *
+     * @param index constant pool cache index
+     * @return decoded index
+     */
+    private static int decodeConstantPoolCacheIndex(int index) {
+        if (isInvokedynamicIndex(index)) {
+            return decodeInvokedynamicIndex(index);
+        } else {
+            return index - runtime().getConfig().constantPoolCpCacheIndexTag;
+        }
+    }
+
+    /**
+     * See {@code ConstantPool::is_invokedynamic_index}.
+     */
+    private static boolean isInvokedynamicIndex(int index) {
+        return index < 0;
+    }
+
+    /**
+     * See {@code ConstantPool::decode_invokedynamic_index}.
+     */
+    private static int decodeInvokedynamicIndex(int i) {
+        assert isInvokedynamicIndex(i) : i;
+        return ~i;
+    }
+
+    /**
      * Gets the constant pool tag at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return constant pool tag
      */
@@ -141,7 +173,7 @@
 
     /**
      * Gets the constant pool entry at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return constant pool entry
      */
@@ -152,7 +184,7 @@
 
     /**
      * Gets the integer constant pool entry at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return integer constant pool entry at index
      */
@@ -163,7 +195,7 @@
 
     /**
      * Gets the long constant pool entry at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return long constant pool entry
      */
@@ -174,7 +206,7 @@
 
     /**
      * Gets the float constant pool entry at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return float constant pool entry
      */
@@ -185,7 +217,7 @@
 
     /**
      * Gets the double constant pool entry at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return float constant pool entry
      */
@@ -196,7 +228,7 @@
 
     /**
      * Gets the {@code JVM_CONSTANT_NameAndType} constant pool entry at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return {@code JVM_CONSTANT_NameAndType} constant pool entry
      */
@@ -208,7 +240,7 @@
     /**
      * Gets the {@code JVM_CONSTANT_NameAndType} reference index constant pool entry at index
      * {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return {@code JVM_CONSTANT_NameAndType} reference constant pool entry
      */
@@ -219,7 +251,7 @@
     /**
      * Gets the name of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index
      * {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return name as {@link String}
      */
@@ -232,7 +264,7 @@
     /**
      * Gets the name reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry at
      * index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return name reference index
      */
@@ -245,7 +277,7 @@
     /**
      * Gets the signature of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index
      * {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return signature as {@link String}
      */
@@ -258,7 +290,7 @@
     /**
      * Gets the signature reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry
      * at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return signature reference index
      */
@@ -270,7 +302,7 @@
 
     /**
      * Gets the klass reference index constant pool entry at index {@code index}.
-     * 
+     *
      * @param index constant pool index
      * @return klass reference index
      */
@@ -281,7 +313,7 @@
     /**
      * Gets the uncached klass reference index constant pool entry at index {@code index}. See:
      * {@code ConstantPool::uncached_klass_ref_index_at}.
-     * 
+     *
      * @param index constant pool index
      * @return klass reference index
      */
@@ -294,7 +326,7 @@
 
     /**
      * Asserts that the constant pool index {@code index} is in the bounds of the constant pool.
-     * 
+     *
      * @param index constant pool index
      */
     private void assertBounds(int index) {
@@ -303,7 +335,7 @@
 
     /**
      * Asserts that the constant pool tag at index {@code index} is equal to {@code tag}.
-     * 
+     *
      * @param index constant pool index
      * @param tag expected tag
      */
@@ -371,7 +403,7 @@
     /**
      * Gets a {@link JavaType} corresponding a given metaspace Klass or a metaspace Symbol depending
      * on the {@link HotSpotVMConfig#compilerToVMKlassTag tag}.
-     * 
+     *
      * @param metaspacePointer either a metaspace Klass or a metaspace Symbol
      */
     private static JavaType getJavaType(final long metaspacePointer) {
@@ -462,6 +494,11 @@
             case Bytecodes.LDC2_W:
                 index = cpi;
                 break;
+            case Bytecodes.INVOKEDYNAMIC:
+                // invokedynamic instructions point to a constant pool cache entry.
+                index = decodeConstantPoolCacheIndex(cpi);
+                index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index);
+                break;
             default:
                 index = toConstantPoolIndex(cpi, opcode);
                 index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index);