# HG changeset patch # User twisti # Date 1394662348 25200 # Node ID 82c3b54d1f08af6bc6a7469f182f3cbb6b7e3f36 # Parent 41ecd18552b2231bf5e5eadfb68ac379bbeae96c added HotSpotConstantPool.JVM_CONSTANT enum diff -r 41ecd18552b2 -r 82c3b54d1f08 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 13 21:16:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Wed Mar 12 15:12:28 2014 -0700 @@ -118,7 +118,9 @@ */ long lookupType(String name, Class accessingClass, boolean resolve); - Object lookupConstantInPool(long metaspaceConstantPool, int cpi); + Object resolveConstantInPool(long metaspaceConstantPool, int cpi); + + Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi); int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi); diff -r 41ecd18552b2 -r 82c3b54d1f08 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 13 21:16:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Wed Mar 12 15:12:28 2014 -0700 @@ -63,8 +63,9 @@ @Override public native long lookupType(String name, Class accessingClass, boolean eagerResolve); - @Override - public native Object lookupConstantInPool(long metaspaceConstantPool, int cpi); + public native Object resolveConstantInPool(long metaspaceConstantPool, int cpi); + + public native Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi); @Override public native int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi); diff -r 41ecd18552b2 -r 82c3b54d1f08 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java Thu Mar 13 21:16:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java Wed Mar 12 15:12:28 2014 -0700 @@ -40,6 +40,51 @@ private static final long serialVersionUID = -5443206401485234850L; /** + * Enum of all {@code JVM_CONSTANT} constants used in the VM. This includes the public and + * internal ones. + */ + private enum JVM_CONSTANT { + // @formatter:off + Utf8(config().jvmConstantUtf8), + Integer(config().jvmConstantInteger), + Long(config().jvmConstantLong), + Float(config().jvmConstantFloat), + Double(config().jvmConstantDouble), + Class(config().jvmConstantClass), + UnresolvedClass(config().jvmConstantUnresolvedClass), + UnresolvedClassInError(config().jvmConstantUnresolvedClassInError), + String(config().jvmConstantString), + Fieldref(config().jvmConstantFieldref), + MethodRef(config().jvmConstantMethodref), + InterfaceMethodref(config().jvmConstantInterfaceMethodref), + NameAndType(config().jvmConstantNameAndType), + MethodHandle(config().jvmConstantMethodHandle), + MethodHandleInError(config().jvmConstantMethodHandleInError), + MethodType(config().jvmConstantMethodType), + MethodTypeInError(config().jvmConstantMethodTypeInError); + // @formatter:on + + private final int value; + + private JVM_CONSTANT(int value) { + this.value = value; + } + + private static HotSpotVMConfig config() { + return runtime().getConfig(); + } + + public static JVM_CONSTANT getEnum(int value) { + for (JVM_CONSTANT e : values()) { + if (e.value == value) { + return e; + } + } + throw GraalInternalError.shouldNotReachHere("unknown enum value " + value); + } + } + + /** * Reference to the C++ ConstantPool object. */ private final long metaspaceConstantPool; @@ -86,11 +131,12 @@ * @param index constant pool index * @return constant pool tag */ - private int getTagAt(int index) { + private JVM_CONSTANT getTagAt(int index) { assertBounds(index); HotSpotVMConfig config = runtime().getConfig(); - long tags = unsafe.getAddress(metaspaceConstantPool + config.constantPoolTagsOffset); - return unsafe.getByteVolatile(null, tags + config.arrayU1DataOffset + index); + final long metaspaceConstantPoolTags = unsafe.getAddress(metaspaceConstantPool + config.constantPoolTagsOffset); + final int tag = unsafe.getByteVolatile(null, metaspaceConstantPoolTags + config.arrayU1DataOffset + index); + return JVM_CONSTANT.getEnum(tag); } /** @@ -112,9 +158,8 @@ * @return integer constant pool entry at index */ private int getIntAt(int index) { - HotSpotVMConfig config = runtime().getConfig(); - assertTag(index, config.jvmConstantInteger); - return unsafe.getInt(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize); + assertTag(index, JVM_CONSTANT.Integer); + return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize); } /** @@ -124,9 +169,8 @@ * @return long constant pool entry */ private long getLongAt(int index) { - HotSpotVMConfig config = runtime().getConfig(); - assertTag(index, config.jvmConstantLong); - return unsafe.getLong(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize); + assertTag(index, JVM_CONSTANT.Long); + return unsafe.getLong(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize); } /** @@ -136,9 +180,8 @@ * @return float constant pool entry */ private float getFloatAt(int index) { - HotSpotVMConfig config = runtime().getConfig(); - assertTag(index, config.jvmConstantFloat); - return unsafe.getFloat(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize); + assertTag(index, JVM_CONSTANT.Float); + return unsafe.getFloat(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize); } /** @@ -148,9 +191,8 @@ * @return float constant pool entry */ private double getDoubleAt(int index) { - HotSpotVMConfig config = runtime().getConfig(); - assertTag(index, config.jvmConstantDouble); - return unsafe.getDouble(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize); + assertTag(index, JVM_CONSTANT.Double); + return unsafe.getDouble(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize); } /** @@ -160,9 +202,8 @@ * @return {@code JVM_CONSTANT_NameAndType} constant pool entry */ private int getNameAndTypeAt(int index) { - HotSpotVMConfig config = runtime().getConfig(); - assertTag(index, config.jvmConstantNameAndType); - return unsafe.getInt(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize); + assertTag(index, JVM_CONSTANT.NameAndType); + return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize); } /** @@ -253,115 +294,52 @@ * @param index constant pool index * @param tag expected tag */ - private void assertTag(int index, int tag) { - assert getTagAt(index) == tag : "constant pool tag at index " + index + " is " + getNameForTag(getTagAt(index)) + " but expected " + getNameForTag(tag); - } - - private static String getNameForTag(int tag) { - HotSpotVMConfig config = runtime().getConfig(); - if (tag == config.jvmConstantUtf8) { - return "JVM_CONSTANT_Utf8"; - } - if (tag == config.jvmConstantInteger) { - return "JVM_CONSTANT_Integer"; - } - if (tag == config.jvmConstantLong) { - return "JVM_CONSTANT_Long"; - } - if (tag == config.jvmConstantFloat) { - return "JVM_CONSTANT_Float"; - } - if (tag == config.jvmConstantDouble) { - return "JVM_CONSTANT_Double"; - } - if (tag == config.jvmConstantClass) { - return "JVM_CONSTANT_Class"; - } - if (tag == config.jvmConstantUnresolvedClass) { - return "JVM_CONSTANT_UnresolvedClass"; - } - if (tag == config.jvmConstantUnresolvedClassInError) { - return "JVM_CONSTANT_UnresolvedClassInError"; - } - if (tag == config.jvmConstantString) { - return "JVM_CONSTANT_String"; - } - if (tag == config.jvmConstantFieldref) { - return "JVM_CONSTANT_Fieldref"; - } - if (tag == config.jvmConstantMethodref) { - return "JVM_CONSTANT_Methodref"; - } - if (tag == config.jvmConstantInterfaceMethodref) { - return "JVM_CONSTANT_InterfaceMethodref"; - } - if (tag == config.jvmConstantNameAndType) { - return "JVM_CONSTANT_NameAndType"; - } - if (tag == config.jvmConstantMethodHandle) { - return "JVM_CONSTANT_MethodHandle"; - } - if (tag == config.jvmConstantMethodHandleInError) { - return "JVM_CONSTANT_MethodHandleInError"; - } - if (tag == config.jvmConstantMethodType) { - return "JVM_CONSTANT_MethodType"; - } - if (tag == config.jvmConstantMethodTypeInError) { - return "JVM_CONSTANT_MethodTypeInError"; - } - return "unknown constant tag " + tag; + private void assertTag(int index, JVM_CONSTANT tag) { + assert getTagAt(index) == tag : "constant pool tag at index " + index + " is " + getTagAt(index) + " but expected " + tag; } @Override public int length() { - HotSpotVMConfig config = runtime().getConfig(); - return unsafe.getInt(metaspaceConstantPool + config.constantPoolLengthOffset); + return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolLengthOffset); } @Override public Object lookupConstant(int cpi) { assert cpi != 0; - - HotSpotVMConfig config = runtime().getConfig(); - final int tag = getTagAt(cpi); - - // Handle primitive constant pool entries directly. - if (tag == config.jvmConstantInteger) { - return Constant.forInt(getIntAt(cpi)); - } - if (tag == config.jvmConstantLong) { - return Constant.forLong(getLongAt(cpi)); - } - if (tag == config.jvmConstantFloat) { - return Constant.forFloat(getFloatAt(cpi)); - } - if (tag == config.jvmConstantDouble) { - return Constant.forDouble(getDoubleAt(cpi)); + final JVM_CONSTANT tag = getTagAt(cpi); + switch (tag) { + case Integer: + return Constant.forInt(getIntAt(cpi)); + case Long: + return Constant.forLong(getLongAt(cpi)); + case Float: + return Constant.forFloat(getFloatAt(cpi)); + case Double: + return Constant.forDouble(getDoubleAt(cpi)); + case Class: + case UnresolvedClass: + case UnresolvedClassInError: + final int opcode = -1; // opcode is not used + return lookupType(cpi, opcode); + case String: + Object string = runtime().getCompilerToVM().resolvePossiblyCachedConstantInPool(metaspaceConstantPool, cpi); + return Constant.forObject(string); + case MethodHandle: + case MethodHandleInError: + case MethodType: + case MethodTypeInError: + Object obj = runtime().getCompilerToVM().resolveConstantInPool(metaspaceConstantPool, cpi); + return Constant.forObject(obj); + default: + throw GraalInternalError.shouldNotReachHere("unknown constant pool tag " + tag); } - - // All the other constant pool entries need special attention so we call down into the VM. - if (tag == config.jvmConstantClass || tag == config.jvmConstantUnresolvedClass || tag == config.jvmConstantUnresolvedClassInError) { - final int opcode = -1; // opcode is not used - return lookupType(cpi, opcode); - } - if (tag == config.jvmConstantString) { - Object string = runtime().getCompilerToVM().lookupConstantInPool(metaspaceConstantPool, cpi); - return Constant.forObject(string); - } - if (tag == config.jvmConstantMethodHandle || tag == config.jvmConstantMethodHandleInError || tag == config.jvmConstantMethodType || tag == config.jvmConstantMethodTypeInError) { - Object obj = runtime().getCompilerToVM().lookupConstantInPool(metaspaceConstantPool, cpi); - return Constant.forObject(obj); - } - - throw GraalInternalError.shouldNotReachHere("unknown constant pool tag " + tag); } @Override public String lookupUtf8(int cpi) { - assertTag(cpi, runtime().getConfig().jvmConstantUtf8); - long signature = getEntryAt(cpi); - HotSpotSymbol symbol = new HotSpotSymbol(signature); + assertTag(cpi, JVM_CONSTANT.Utf8); + final long metaspaceSymbol = getEntryAt(cpi); + HotSpotSymbol symbol = new HotSpotSymbol(metaspaceSymbol); return symbol.asString(); } diff -r 41ecd18552b2 -r 82c3b54d1f08 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Mar 13 21:16:57 2014 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Wed Mar 12 15:12:28 2014 -0700 @@ -378,23 +378,15 @@ return (jlong) (address) resolved_klass; C2V_END -C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index)) +C2V_VMENTRY(jobject, resolveConstantInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index)) ConstantPool* cp = (ConstantPool*) metaspace_constant_pool; - oop result = NULL; - constantTag tag = cp->tag_at(index); - switch (tag.value()) { - case JVM_CONSTANT_String: - result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL); - break; - case JVM_CONSTANT_MethodHandle: - case JVM_CONSTANT_MethodHandleInError: - case JVM_CONSTANT_MethodType: - case JVM_CONSTANT_MethodTypeInError: - result = cp->resolve_constant_at(index, CHECK_NULL); - break; - default: - fatal(err_msg_res("unknown constant pool tag %s at cpi %d in %s", tag.internal_name(), index, cp->pool_holder()->name()->as_C_string())); - } + oop result = cp->resolve_constant_at(index, CHECK_NULL); + return JNIHandles::make_local(THREAD, result); +C2V_END + +C2V_VMENTRY(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index)) + ConstantPool* cp = (ConstantPool*) metaspace_constant_pool; + oop result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL); return JNIHandles::make_local(THREAD, result); C2V_END @@ -823,6 +815,8 @@ #define METASPACE_SYMBOL "J" JNINativeMethod CompilerToVM_methods[] = { +#if 0 +<<<<<<< local {CC"initializeBytecode", CC"("METASPACE_METHOD"[B)[B", FN_PTR(initializeBytecode)}, {CC"exceptionTableStart", CC"("METASPACE_METHOD")J", FN_PTR(exceptionTableStart)}, {CC"exceptionTableLength", CC"("METASPACE_METHOD")I", FN_PTR(exceptionTableLength)}, @@ -870,6 +864,57 @@ {CC"allocateCompileId", CC"("METASPACE_METHOD"I)I", FN_PTR(allocateCompileId)}, {CC"isMature", CC"("METASPACE_METHOD_DATA")Z", FN_PTR(isMature)}, {CC"hasCompiledCodeForOSR", CC"("METASPACE_METHOD"II)Z", FN_PTR(hasCompiledCodeForOSR)}, +======= +#endif + {CC"initializeBytecode", CC"("METASPACE_METHOD"[B)[B", FN_PTR(initializeBytecode)}, + {CC"exceptionTableStart", CC"("METASPACE_METHOD")J", FN_PTR(exceptionTableStart)}, + {CC"exceptionTableLength", CC"("METASPACE_METHOD")I", FN_PTR(exceptionTableLength)}, + {CC"hasBalancedMonitors", CC"("METASPACE_METHOD")Z", FN_PTR(hasBalancedMonitors)}, + {CC"findUniqueConcreteMethod", CC"("METASPACE_METHOD")"METASPACE_METHOD, FN_PTR(findUniqueConcreteMethod)}, + {CC"getKlassImplementor", CC"("METASPACE_KLASS")"METASPACE_KLASS, FN_PTR(getKlassImplementor)}, + {CC"getStackTraceElement", CC"("METASPACE_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(getStackTraceElement)}, + {CC"initializeMethod", CC"("METASPACE_METHOD HS_RESOLVED_METHOD")V", FN_PTR(initializeMethod)}, + {CC"doNotInlineOrCompile", CC"("METASPACE_METHOD")V", FN_PTR(doNotInlineOrCompile)}, + {CC"canInlineMethod", CC"("METASPACE_METHOD")Z", FN_PTR(canInlineMethod)}, + {CC"shouldInlineMethod", CC"("METASPACE_METHOD")Z", FN_PTR(shouldInlineMethod)}, + {CC"getCompiledCodeSize", CC"("METASPACE_METHOD")I", FN_PTR(getCompiledCodeSize)}, + {CC"lookupType", CC"("STRING CLASS"Z)"METASPACE_KLASS, FN_PTR(lookupType)}, + {CC"resolveConstantInPool", CC"("METASPACE_CONSTANT_POOL"I)"OBJECT, FN_PTR(resolveConstantInPool)}, + {CC"resolvePossiblyCachedConstantInPool", CC"("METASPACE_CONSTANT_POOL"I)"OBJECT, FN_PTR(resolvePossiblyCachedConstantInPool)}, + {CC"lookupNameRefInPool", CC"("METASPACE_CONSTANT_POOL"I)"METASPACE_SYMBOL, FN_PTR(lookupNameRefInPool)}, + {CC"lookupNameAndTypeRefIndexInPool", CC"("METASPACE_CONSTANT_POOL"I)I", FN_PTR(lookupNameAndTypeRefIndexInPool)}, + {CC"lookupSignatureRefInPool", CC"("METASPACE_CONSTANT_POOL"I)"METASPACE_SYMBOL, FN_PTR(lookupSignatureRefInPool)}, + {CC"lookupKlassRefIndexInPool", CC"("METASPACE_CONSTANT_POOL"I)I", FN_PTR(lookupKlassRefIndexInPool)}, + {CC"lookupKlassInPool", CC"("METASPACE_CONSTANT_POOL"I)"METASPACE_KLASS, FN_PTR(lookupKlassInPool)}, + {CC"lookupAppendixInPool", CC"("METASPACE_CONSTANT_POOL"I)"OBJECT, FN_PTR(lookupAppendixInPool)}, + {CC"lookupMethodInPool", CC"("METASPACE_CONSTANT_POOL"IB)"METASPACE_METHOD, FN_PTR(lookupMethodInPool)}, + {CC"loadReferencedTypeInPool", CC"("METASPACE_CONSTANT_POOL"IB)V", FN_PTR(loadReferencedTypeInPool)}, + {CC"resolveField", CC"("METASPACE_CONSTANT_POOL"IB[J)"METASPACE_KLASS, FN_PTR(resolveField)}, + {CC"resolveMethod", CC"("METASPACE_KLASS STRING STRING")"METASPACE_METHOD, FN_PTR(resolveMethod)}, + {CC"getClassInitializer", CC"("METASPACE_KLASS")"METASPACE_METHOD, FN_PTR(getClassInitializer)}, + {CC"hasFinalizableSubclass", CC"("METASPACE_KLASS")Z", FN_PTR(hasFinalizableSubclass)}, + {CC"getMaxCallTargetOffset", CC"(J)J", FN_PTR(getMaxCallTargetOffset)}, + {CC"getMetaspaceMethod", CC"("CLASS"I)"METASPACE_METHOD, FN_PTR(getMetaspaceMethod)}, + {CC"initializeConfiguration", CC"("HS_CONFIG")V", FN_PTR(initializeConfiguration)}, + {CC"installCode0", CC"("HS_COMPILED_CODE HS_INSTALLED_CODE SPECULATION_LOG")I", FN_PTR(installCode0)}, + {CC"notifyCompilationStatistics", CC"(I"HS_RESOLVED_METHOD"ZIJJ"HS_INSTALLED_CODE")V", FN_PTR(notifyCompilationStatistics)}, + {CC"printCompilationStatistics", CC"(ZZ)V", FN_PTR(printCompilationStatistics)}, + {CC"resetCompilationStatistics", CC"()V", FN_PTR(resetCompilationStatistics)}, + {CC"disassembleCodeBlob", CC"(J)"STRING, FN_PTR(disassembleCodeBlob)}, + {CC"executeCompiledMethodVarargs", CC"(["OBJECT HS_INSTALLED_CODE")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, + {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, + {CC"getLineNumberTable", CC"("METASPACE_METHOD")[J", FN_PTR(getLineNumberTable)}, + {CC"getLocalVariableTableStart", CC"("METASPACE_METHOD")J", FN_PTR(getLocalVariableTableStart)}, + {CC"getLocalVariableTableLength", CC"("METASPACE_METHOD")I", FN_PTR(getLocalVariableTableLength)}, + {CC"reprofile", CC"("METASPACE_METHOD")V", FN_PTR(reprofile)}, + {CC"invalidateInstalledCode", CC"("HS_INSTALLED_CODE")V", FN_PTR(invalidateInstalledCode)}, + {CC"readUnsafeUncompressedPointer", CC"("OBJECT"J)"OBJECT, FN_PTR(readUnsafeUncompressedPointer)}, + {CC"readUnsafeKlassPointer", CC"("OBJECT")J", FN_PTR(readUnsafeKlassPointer)}, + {CC"collectCounters", CC"()[J", FN_PTR(collectCounters)}, + {CC"getGPUs", CC"()"STRING, FN_PTR(getGPUs)}, + {CC"allocateCompileId", CC"("METASPACE_METHOD"I)I", FN_PTR(allocateCompileId)}, + {CC"isMature", CC"("METASPACE_METHOD_DATA")Z", FN_PTR(isMature)}, + {CC"hasCompiledCodeForOSR", CC"("METASPACE_METHOD"II)Z", FN_PTR(hasCompiledCodeForOSR)}, }; int CompilerToVM_methods_count() {