changeset 22274:b6d504612b3f

fix HotSpotConstantPool#lookupConstant for pseudo-string entries
author Andreas Woess <andreas.woess@oracle.com>
date Tue, 21 Jul 2015 14:55:47 +0200
parents e8dc090e167f
children 329f734a9803 d86b226e331a
files jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java
diffstat 1 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java	Tue Jul 21 14:14:41 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java	Tue Jul 21 14:55:47 2015 +0200
@@ -739,7 +739,12 @@
                 final int opcode = -1;  // opcode is not used
                 return lookupType(cpi, opcode);
             case String:
-                String string;
+                /*
+                 * Normally, we would expect a String here, but anonymous classes can have
+                 * "pseudo strings" (arbitrary live objects) patched into a String entry. Such
+                 * entries do not have a symbol in the constant pool slot.
+                 */
+                Object string;
                 if (Options.UseConstantPoolCacheJavaCode.getValue()) {
                     // See: ConstantPool::resolve_constant_at_impl
                     /*
@@ -748,24 +753,23 @@
                      */
                     Object[] localResolvedReferences = resolvedReferences.getArray();
                     final int index = resolvedReferences.constantPoolIndexToResolvedReferencesIndex(cpi);
-                    if (index >= 0) {
-                        string = (String) localResolvedReferences[index];
-                        if (string != null) {
-                            return HotSpotObjectConstantImpl.forObject(string);
+                    assert index >= 0;
+                    // See: ConstantPool::string_at_impl
+                    string = localResolvedReferences[index];
+                    if (string != null) {
+                        assert string instanceof String || getEntryAt(index) == 0L;
+                        return HotSpotObjectConstantImpl.forObject(string);
+                    } else {
+                        final long metaspaceSymbol = getEntryAt(cpi);
+                        if (metaspaceSymbol != 0L) {
+                            HotSpotSymbol symbol = new HotSpotSymbol(metaspaceSymbol);
+                            string = symbol.asString().intern();
+                            // See: ConstantPool::string_at_put
+                            localResolvedReferences[index] = string;
                         }
                     }
-                    assert index != -1;
-                    // See: ConstantPool::string_at_impl
-                    string = (String) localResolvedReferences[index];
-                    if (string == null) {
-                        final long metaspaceSymbol = getEntryAt(cpi);
-                        HotSpotSymbol symbol = new HotSpotSymbol(metaspaceSymbol);
-                        string = symbol.asString().intern();
-                        // See: ConstantPool::string_at_put
-                        localResolvedReferences[index] = string;
-                    }
                 } else {
-                    string = (String) runtime().getCompilerToVM().resolvePossiblyCachedConstantInPool(metaspaceConstantPool, cpi);
+                    string = runtime().getCompilerToVM().resolvePossiblyCachedConstantInPool(metaspaceConstantPool, cpi);
                 }
                 return HotSpotObjectConstantImpl.forObject(string);
             case MethodHandle: