# HG changeset patch # User twisti # Date 1435246246 25200 # Node ID 13a50cb905b7fc8b0b338a01a80ba472adf38284 # Parent b68929da1ac574ad13a8586b50382a37b6ae0a90 Only invokevirtual and invokespecial are invokehandle aliases. diff -r b68929da1ac5 -r 13a50cb905b7 jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java --- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java Thu Jun 25 15:08:08 2015 +0200 +++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java Thu Jun 25 08:30:46 2015 -0700 @@ -70,6 +70,19 @@ return false; } } + + /** + * See: {@code Rewriter::maybe_rewrite_invokehandle}. + */ + static boolean isInvokeHandleAlias(int opcode) { + switch (opcode) { + case INVOKEVIRTUAL: + case INVOKESPECIAL: + return true; + default: + return false; + } + } } /** @@ -612,23 +625,19 @@ index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index); } - JVM_CONSTANT tag = getTagAt(index); + final JVM_CONSTANT tag = getTagAt(index); if (tag == null) { assert getTagAt(index - 1) == JVM_CONSTANT.Double || getTagAt(index - 1) == JVM_CONSTANT.Long; return; } - int methodRefCacheIndex = -1; switch (tag) { case MethodRef: - if (Bytecodes.isInvoke(opcode)) { - methodRefCacheIndex = toConstantPoolIndex(cpi, opcode); - } - // fall through case Fieldref: case InterfaceMethodref: index = getUncachedKlassRefIndexAt(index); - tag = getTagAt(index); - assert tag == JVM_CONSTANT.Class || tag == JVM_CONSTANT.UnresolvedClass || tag == JVM_CONSTANT.UnresolvedClassInError : tag; + // Read the tag only once because it could change between multiple reads. + final JVM_CONSTANT klassTag = getTagAt(index); + assert klassTag == JVM_CONSTANT.Class || klassTag == JVM_CONSTANT.UnresolvedClass || klassTag == JVM_CONSTANT.UnresolvedClassInError : klassTag; // fall through case Class: case UnresolvedClass: @@ -639,8 +648,14 @@ if (!klass.isPrimitive() && !klass.isArray()) { unsafe.ensureClassInitialized(klass); } - if (methodRefCacheIndex != -1 && isInvokeHandle(methodRefCacheIndex, type)) { - runtime().getCompilerToVM().resolveInvokeHandle(metaspaceConstantPool, methodRefCacheIndex); + switch (tag) { + case MethodRef: + if (Bytecodes.isInvokeHandleAlias(opcode)) { + final int methodRefCacheIndex = toConstantPoolIndex(cpi, opcode); + if (isInvokeHandle(methodRefCacheIndex, type)) { + runtime().getCompilerToVM().resolveInvokeHandle(metaspaceConstantPool, methodRefCacheIndex); + } + } } break; case InvokeDynamic: @@ -654,9 +669,9 @@ } } - private boolean isInvokeHandle(int methodRefCpi, HotSpotResolvedObjectTypeImpl klass) { - assert getTagAt(runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, methodRefCpi)) == JVM_CONSTANT.MethodRef; - return ResolvedJavaMethod.isSignaturePolymorphic(klass, getNameRefAt(methodRefCpi), runtime().getHostJVMCIBackend().getMetaAccess()); + private boolean isInvokeHandle(int methodRefCacheIndex, HotSpotResolvedObjectTypeImpl klass) { + assertTag(runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, methodRefCacheIndex), JVM_CONSTANT.MethodRef); + return ResolvedJavaMethod.isSignaturePolymorphic(klass, getNameRefAt(methodRefCacheIndex), runtime().getHostJVMCIBackend().getMetaAccess()); } @Override