# HG changeset patch # User twisti # Date 1388090248 28800 # Node ID 37ec2cabf3976c547aab5c5ee67e9e21e7e4e521 # Parent 7824f0c4dfcdbb1b7a05099932c31eceddd4b9c0 moved JavaType creation in CompilerToVM.lookupType into Java diff -r 7824f0c4dfcd -r 37ec2cabf397 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 26 12:13:28 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Thu Dec 26 12:37:28 2013 -0800 @@ -341,13 +341,36 @@ return compilerToGpu; } - public JavaType lookupType(String name, HotSpotResolvedObjectType accessingClass, boolean eagerResolve) { + /** + * Converts a name to a Java type. + * + * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format + * @param accessingType the context of resolution (may be null) + * @param eagerResolve force resolution to a {@link ResolvedJavaType}. If true, this method will + * either return a {@link ResolvedJavaType} or throw an exception + * @return a Java type for {@code name} which is guaranteed to be of type + * {@link ResolvedJavaType} if {@code eagerResolve == true} + * @throws LinkageError if {@code eagerResolve == true} and the resolution failed + */ + public JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean eagerResolve) { // If the name represents a primitive type we can short-circuit the lookup. if (name.length() == 1) { Kind kind = Kind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); return HotSpotResolvedPrimitiveType.fromKind(kind); } - return compilerToVm.lookupType(name, accessingClass, eagerResolve); + + // Handle non-primitive types. + Class accessingClass = null; + if (accessingType != null) { + accessingClass = accessingType.mirror(); + } + + // Resolve the type in the VM. + final long metaspaceKlass = compilerToVm.lookupType(name, accessingClass, eagerResolve); + if (metaspaceKlass == 0) { + return vmToCompiler.createUnresolvedJavaType(name); + } + return HotSpotResolvedObjectType.fromMetaspaceKlass(metaspaceKlass); } public HotSpotRuntimeInterpreterInterface getRuntimeInterpreterInterface() { diff -r 7824f0c4dfcd -r 37ec2cabf397 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 26 12:13:28 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Dec 26 12:37:28 2013 -0800 @@ -95,17 +95,16 @@ void initializeMethod(long metaspaceMethod, HotSpotResolvedJavaMethod method); /** - * Converts a name to a Java type. + * Converts a name to a metaspace klass. * * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format * @param accessingClass the context of resolution (may be null) * @param eagerResolve force resolution to a {@link ResolvedJavaType}. If true, this method will * either return a {@link ResolvedJavaType} or throw an exception - * @return a Java type for {@code name} which is guaranteed to be of type - * {@link ResolvedJavaType} if {@code eagerResolve == true} + * @return a metaspace klass for {@code name} * @throws LinkageError if {@code eagerResolve == true} and the resolution failed */ - JavaType lookupType(String name, HotSpotResolvedObjectType accessingClass, boolean eagerResolve); + long lookupType(String name, Class accessingClass, boolean eagerResolve); Object lookupConstantInPool(long metaspaceConstantPool, int cpi); diff -r 7824f0c4dfcd -r 37ec2cabf397 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 26 12:13:28 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Dec 26 12:37:28 2013 -0800 @@ -62,7 +62,7 @@ public native long getKlassImplementor(long metaspaceKlass); @Override - public native JavaType lookupType(String name, HotSpotResolvedObjectType accessingClass, boolean eagerResolve); + public native long lookupType(String name, Class accessingClass, boolean eagerResolve); @Override public native Object lookupConstantInPool(long metaspaceConstantPool, int cpi); diff -r 7824f0c4dfcd -r 37ec2cabf397 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Dec 26 12:13:28 2013 -0800 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Dec 26 12:37:28 2013 -0800 @@ -206,41 +206,29 @@ return code == NULL ? 0 : code->insts_size(); C2V_END -C2V_VMENTRY(jobject, lookupType, (JNIEnv *env, jobject, jstring jname, jobject accessingClass, jboolean eagerResolve)) +C2V_VMENTRY(jlong, lookupType, (JNIEnv *env, jobject, jstring jname, jclass accessing_class, jboolean eagerResolve)) ResourceMark rm; - 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"); + Symbol* class_name = java_lang_String::as_symbol(name, THREAD); + assert(class_name != NULL, "name to symbol creation failed"); + assert(class_name->size() > 1, "primitive types should be handled in Java code"); - oop result = NULL; - Klass* resolved_type = NULL; - Handle classloader; - Handle protectionDomain; - if (JNIHandles::resolve(accessingClass) != NULL) { - classloader = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaClass(accessingClass))->class_loader(); - protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaClass(accessingClass))->protection_domain(); + Klass* resolved_klass = NULL; + Handle class_loader; + Handle protection_domain; + if (JNIHandles::resolve(accessing_class) != NULL) { + Klass* accessing_klass = java_lang_Class::as_Klass(JNIHandles::resolve(accessing_class)); + class_loader = accessing_klass->class_loader(); + protection_domain = accessing_klass->protection_domain(); } if (eagerResolve) { - resolved_type = SystemDictionary::resolve_or_fail(nameSymbol, classloader, protectionDomain, true, THREAD); + resolved_klass = SystemDictionary::resolve_or_fail(class_name, class_loader, protection_domain, true, THREAD); } else { - resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD); + resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, 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 = VMToCompiler::createResolvedJavaType(resolved_type->java_mirror(), CHECK_NULL); - result = type(); - } - } - - return JNIHandles::make_local(THREAD, result); + return (jlong) (address) resolved_klass; C2V_END C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index)) @@ -859,7 +847,7 @@ {CC"doNotInlineOrCompile", CC"("METASPACE_METHOD")V", FN_PTR(doNotInlineOrCompile)}, {CC"isMethodCompilable", CC"("METASPACE_METHOD")Z", FN_PTR(isMethodCompilable)}, {CC"getCompiledCodeSize", CC"("METASPACE_METHOD")I", FN_PTR(getCompiledCodeSize)}, - {CC"lookupType", CC"("STRING HS_RESOLVED_TYPE"Z)"TYPE, FN_PTR(lookupType)}, + {CC"lookupType", CC"("STRING CLASS"Z)"METASPACE_KLASS, FN_PTR(lookupType)}, {CC"lookupConstantInPool", CC"("METASPACE_CONSTANT_POOL"I)"OBJECT, FN_PTR(lookupConstantInPool)}, {CC"lookupAppendixInPool", CC"("METASPACE_CONSTANT_POOL"IB)"OBJECT, FN_PTR(lookupAppendixInPool)}, {CC"lookupMethodInPool", CC"("METASPACE_CONSTANT_POOL"IB)"METHOD, FN_PTR(lookupMethodInPool)},