# HG changeset patch # User twisti # Date 1386465109 28800 # Node ID fdd6ef90d66d91fe24070dc3fd94bce58dacbb52 # Parent 4eacfd0767ed4158d148e01de12c7a9bedc35ed9 move HotSpotResolvedPrimitiveType's from VMToCompilerImpl to HotSpotGraalRuntime diff -r 4eacfd0767ed -r fdd6ef90d66d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Thu Dec 05 19:28:30 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Sat Dec 07 17:11:49 2013 -0800 @@ -189,6 +189,16 @@ protected final HotSpotVMConfig config; private final HotSpotBackend hostBackend; + public final HotSpotResolvedPrimitiveType typeBoolean; + public final HotSpotResolvedPrimitiveType typeByte; + public final HotSpotResolvedPrimitiveType typeChar; + public final HotSpotResolvedPrimitiveType typeShort; + public final HotSpotResolvedPrimitiveType typeInt; + public final HotSpotResolvedPrimitiveType typeLong; + public final HotSpotResolvedPrimitiveType typeFloat; + public final HotSpotResolvedPrimitiveType typeDouble; + public final HotSpotResolvedPrimitiveType typeVoid; + private final Map, HotSpotBackend> backends = new HashMap<>(); private HotSpotGraalRuntime() { @@ -201,6 +211,26 @@ vmToCompiler = toCompiler; config = new HotSpotVMConfig(compilerToVm); + typeBoolean = new HotSpotResolvedPrimitiveType(Kind.Boolean); + typeByte = new HotSpotResolvedPrimitiveType(Kind.Byte); + typeChar = new HotSpotResolvedPrimitiveType(Kind.Char); + typeShort = new HotSpotResolvedPrimitiveType(Kind.Short); + typeInt = new HotSpotResolvedPrimitiveType(Kind.Int); + typeLong = new HotSpotResolvedPrimitiveType(Kind.Long); + typeFloat = new HotSpotResolvedPrimitiveType(Kind.Float); + typeDouble = new HotSpotResolvedPrimitiveType(Kind.Double); + typeVoid = new HotSpotResolvedPrimitiveType(Kind.Void); + + initMirror(typeBoolean); + initMirror(typeByte); + initMirror(typeChar); + initMirror(typeShort); + initMirror(typeInt); + initMirror(typeLong); + initMirror(typeFloat); + initMirror(typeDouble); + initMirror(typeVoid); + // Set some global options: if (config.compileTheWorld) { GraalOptions.CompileTheWorld.setValue(CompileTheWorld.SUN_BOOT_CLASS_PATH); @@ -242,6 +272,13 @@ } } + private void initMirror(HotSpotResolvedPrimitiveType type) { + Class mirror = type.mirror(); + final long offset = config.graalMirrorInClassOffset; + unsafe.putObject(mirror, offset, type); + assert unsafe.getObject(mirror, offset) == type; + } + private HotSpotBackend registerBackend(HotSpotBackend backend) { Class arch = backend.getTarget().arch.getClass(); HotSpotBackend oldValue = backends.put(arch, backend); @@ -324,32 +361,31 @@ } public JavaType lookupType(String name, HotSpotResolvedObjectType accessingClass, boolean eagerResolve) { - if (name.length() == 1 && vmToCompiler instanceof VMToCompilerImpl) { - VMToCompilerImpl impl = (VMToCompilerImpl) vmToCompiler; + if (name.length() == 1) { Kind kind = Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); switch (kind) { case Boolean: - return impl.typeBoolean; + return typeBoolean; case Byte: - return impl.typeByte; + return typeByte; case Char: - return impl.typeChar; + return typeChar; + case Short: + return typeShort; + case Int: + return typeInt; + case Long: + return typeLong; + case Float: + return typeFloat; case Double: - return impl.typeDouble; - case Float: - return impl.typeFloat; + return typeDouble; + case Void: + return typeVoid; + case Object: + break; case Illegal: break; - case Int: - return impl.typeInt; - case Long: - return impl.typeLong; - case Object: - break; - case Short: - return impl.typeShort; - case Void: - return impl.typeVoid; } } return compilerToVm.lookupType(name, accessingClass, eagerResolve); diff -r 4eacfd0767ed -r fdd6ef90d66d 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 Dec 05 19:28:30 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Sat Dec 07 17:11:49 2013 -0800 @@ -45,8 +45,6 @@ */ byte[] initializeBytecode(long metaspaceMethod, byte[] code); - String getSignature(long metaspaceMethod); - ExceptionHandler[] initializeExceptionHandlers(long metaspaceMethod, ExceptionHandler[] handlers); /** diff -r 4eacfd0767ed -r fdd6ef90d66d 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 Dec 05 19:28:30 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Sat Dec 07 17:11:49 2013 -0800 @@ -55,9 +55,6 @@ public native byte[] initializeBytecode(long metaspaceMethod, byte[] code); @Override - public native String getSignature(long metaspaceMethod); - - @Override public native ExceptionHandler[] initializeExceptionHandlers(long metaspaceMethod, ExceptionHandler[] handlers); @Override diff -r 4eacfd0767ed -r fdd6ef90d66d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Thu Dec 05 19:28:30 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Sat Dec 07 17:11:49 2013 -0800 @@ -81,16 +81,6 @@ private final HotSpotGraalRuntime runtime; - public final HotSpotResolvedPrimitiveType typeBoolean; - public final HotSpotResolvedPrimitiveType typeChar; - public final HotSpotResolvedPrimitiveType typeFloat; - public final HotSpotResolvedPrimitiveType typeDouble; - public final HotSpotResolvedPrimitiveType typeByte; - public final HotSpotResolvedPrimitiveType typeShort; - public final HotSpotResolvedPrimitiveType typeInt; - public final HotSpotResolvedPrimitiveType typeLong; - public final HotSpotResolvedPrimitiveType typeVoid; - private ThreadPoolExecutor compileQueue; private AtomicInteger compileTaskIds = new AtomicInteger(); @@ -102,22 +92,6 @@ public VMToCompilerImpl(HotSpotGraalRuntime runtime) { this.runtime = runtime; - - typeBoolean = new HotSpotResolvedPrimitiveType(Kind.Boolean); - typeChar = new HotSpotResolvedPrimitiveType(Kind.Char); - typeFloat = new HotSpotResolvedPrimitiveType(Kind.Float); - typeDouble = new HotSpotResolvedPrimitiveType(Kind.Double); - typeByte = new HotSpotResolvedPrimitiveType(Kind.Byte); - typeShort = new HotSpotResolvedPrimitiveType(Kind.Short); - typeInt = new HotSpotResolvedPrimitiveType(Kind.Int); - typeLong = new HotSpotResolvedPrimitiveType(Kind.Long); - typeVoid = new HotSpotResolvedPrimitiveType(Kind.Void); - } - - private static void initMirror(HotSpotResolvedPrimitiveType type, long offset) { - Class mirror = type.mirror(); - unsafe.putObject(mirror, offset, type); - assert unsafe.getObject(mirror, offset) == type; } public void startCompiler(boolean bootstrapEnabled) throws Throwable { @@ -126,18 +100,6 @@ bootstrapRunning = bootstrapEnabled; - final HotSpotVMConfig config = runtime.getConfig(); - long offset = config.graalMirrorInClassOffset; - initMirror(typeBoolean, offset); - initMirror(typeChar, offset); - initMirror(typeFloat, offset); - initMirror(typeDouble, offset); - initMirror(typeByte, offset); - initMirror(typeShort, offset); - initMirror(typeInt, offset); - initMirror(typeLong, offset); - initMirror(typeVoid, offset); - if (LogFile.getValue() != null) { try { final boolean enableAutoflush = true; @@ -622,23 +584,23 @@ public ResolvedJavaType createPrimitiveJavaType(int basicType) { switch (basicType) { case 4: - return typeBoolean; + return runtime.typeBoolean; case 5: - return typeChar; + return runtime.typeChar; case 6: - return typeFloat; + return runtime.typeFloat; case 7: - return typeDouble; + return runtime.typeDouble; case 8: - return typeByte; + return runtime.typeByte; case 9: - return typeShort; + return runtime.typeShort; case 10: - return typeInt; + return runtime.typeInt; case 11: - return typeLong; + return runtime.typeLong; case 14: - return typeVoid; + return runtime.typeVoid; default: throw new IllegalArgumentException("Unknown basic type: " + basicType); } diff -r 4eacfd0767ed -r fdd6ef90d66d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Thu Dec 05 19:28:30 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Sat Dec 07 17:11:49 2013 -0800 @@ -115,9 +115,11 @@ */ public static ResolvedJavaType fromClass(Class javaClass) { assert javaClass != null; - ResolvedJavaType type = (ResolvedJavaType) unsafe.getObject(javaClass, (long) runtime().getConfig().graalMirrorInClassOffset); + HotSpotGraalRuntime runtime = runtime(); + ResolvedJavaType type = (ResolvedJavaType) unsafe.getObject(javaClass, (long) runtime.getConfig().graalMirrorInClassOffset); if (type == null) { - type = runtime().getCompilerToVM().getResolvedType(javaClass); + assert !javaClass.isPrimitive() : "primitive type " + javaClass + " should have its mirror initialized"; + type = runtime.getCompilerToVM().getResolvedType(javaClass); assert type != null; } return type; diff -r 4eacfd0767ed -r fdd6ef90d66d src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Dec 05 19:28:30 2013 -0800 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Sat Dec 07 17:11:49 2013 -0800 @@ -133,12 +133,6 @@ return result; C2V_END -C2V_VMENTRY(jstring, getSignature, (JNIEnv *env, jobject, jlong metaspace_method)) - Method* method = asMethod(metaspace_method); - assert(method != NULL && method->signature() != NULL, "signature required"); - return (jstring)JNIHandles::make_local(java_lang_String::create_from_symbol(method->signature(), THREAD)()); -C2V_END - C2V_VMENTRY(jobjectArray, initializeExceptionHandlers, (JNIEnv *, jobject, jlong metaspace_method, jobjectArray java_handlers)) ResourceMark rm; methodHandle method = asMethod(metaspace_method); @@ -306,50 +300,31 @@ Handle name = JNIHandles::resolve(jname); Symbol* nameSymbol = java_lang_String::as_symbol(name, THREAD); assert(nameSymbol != NULL, "name to symbol creation failed"); + assert(nameSymbol->size() > 1, "primitive types should be handled in Java code"); oop result = NULL; - if (nameSymbol == vmSymbols::int_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_INT, THREAD); - } else if (nameSymbol == vmSymbols::long_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_LONG, THREAD); - } else if (nameSymbol == vmSymbols::bool_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_BOOLEAN, THREAD); - } else if (nameSymbol == vmSymbols::char_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_CHAR, THREAD); - } else if (nameSymbol == vmSymbols::short_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_SHORT, THREAD); - } else if (nameSymbol == vmSymbols::byte_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_BYTE, THREAD); - } else if (nameSymbol == vmSymbols::double_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_DOUBLE, THREAD); - } else if (nameSymbol == vmSymbols::float_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_FLOAT, THREAD); - } else if (nameSymbol == vmSymbols::void_signature()) { - result = VMToCompiler::createPrimitiveJavaType((int) T_VOID, THREAD); + Klass* resolved_type = NULL; + Handle classloader; + Handle protectionDomain; + if (JNIHandles::resolve(accessingClass) != NULL) { + classloader = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->class_loader(); + protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->protection_domain(); + } + + if (eagerResolve) { + resolved_type = SystemDictionary::resolve_or_fail(nameSymbol, classloader, protectionDomain, true, THREAD); } else { - Klass* resolved_type = NULL; - Handle classloader; - Handle protectionDomain; - if (JNIHandles::resolve(accessingClass) != NULL) { - classloader = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->class_loader(); - protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->protection_domain(); - } + resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD); + } - if (eagerResolve) { - resolved_type = SystemDictionary::resolve_or_fail(nameSymbol, classloader, protectionDomain, true, THREAD); + if (!HAS_PENDING_EXCEPTION) { + if (resolved_type == NULL) { + assert(!eagerResolve, "failed eager resolution should have caused an exception"); + Handle type = VMToCompiler::createUnresolvedJavaType(name, THREAD); + result = type(); } else { - resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD); - } - - if (!HAS_PENDING_EXCEPTION) { - if (resolved_type == NULL) { - assert(!eagerResolve, "failed eager resolution should have caused an exception"); - Handle type = VMToCompiler::createUnresolvedJavaType(name, THREAD); - result = type(); - } else { - Handle type = GraalCompiler::createHotSpotResolvedObjectType(resolved_type, name, CHECK_NULL); - result = type(); - } + Handle type = GraalCompiler::createHotSpotResolvedObjectType(resolved_type, name, CHECK_NULL); + result = type(); } } @@ -360,27 +335,19 @@ ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants(); 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())); } - return JNIHandles::make_local(THREAD, result); C2V_END @@ -389,7 +356,6 @@ index = GraalCompiler::to_cp_index(index, bc); constantPoolHandle cpool(InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants()); oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, index); - return JNIHandles::make_local(THREAD, appendix_oop); C2V_END @@ -1026,7 +992,6 @@ JNINativeMethod CompilerToVM_methods[] = { {CC"initializeBytecode", CC"("METASPACE_METHOD"[B)[B", FN_PTR(initializeBytecode)}, - {CC"getSignature", CC"("METASPACE_METHOD")"STRING, FN_PTR(getSignature)}, {CC"initializeExceptionHandlers", CC"("METASPACE_METHOD EXCEPTION_HANDLERS")"EXCEPTION_HANDLERS, FN_PTR(initializeExceptionHandlers)}, {CC"hasBalancedMonitors", CC"("METASPACE_METHOD")Z", FN_PTR(hasBalancedMonitors)}, {CC"getUniqueConcreteMethod", CC"("METASPACE_METHOD"["HS_RESOLVED_TYPE")"METASPACE_METHOD, FN_PTR(getUniqueConcreteMethod)},