# HG changeset patch # User Doug Simon # Date 1353945103 -3600 # Node ID 58dbea9fb973496dc35434096461ef82d60ab8a3 # Parent f31d374e81954aeb028d7860e66fe99049ec6fce CompilerToVM.lookupType() now fails with an exception if eagerResolve is true and resolution fails diff -r f31d374e8195 -r 58dbea9fb973 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 Mon Nov 26 16:18:56 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon Nov 26 16:51:43 2012 +0100 @@ -104,6 +104,17 @@ */ void initializeMethodData(long metaspaceMethodData, HotSpotMethodData methodData); + /** + * Converts a name to a Java type. + * + * @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} + * @throws LinkageError if {@code eagerResolve == true} and the resolution failed + */ JavaType lookupType(String name, HotSpotResolvedJavaType accessingClass, boolean eagerResolve); Object lookupConstantInPool(HotSpotResolvedJavaType pool, int cpi); diff -r f31d374e8195 -r 58dbea9fb973 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java Mon Nov 26 16:18:56 2012 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java Mon Nov 26 16:51:43 2012 +0100 @@ -82,12 +82,13 @@ private void tryIntrinsify(Invoke invoke) { ResolvedJavaMethod target = invoke.methodCallTarget().targetMethod(); NodeIntrinsic intrinsic = target.getAnnotation(Node.NodeIntrinsic.class); + ResolvedJavaType declaringClass = target.getDeclaringClass(); if (intrinsic != null) { assert target.getAnnotation(Fold.class) == null; assert Modifier.isNative(target.getModifiers()) : "node intrinsic " + target + " should be native"; - Class< ? >[] parameterTypes = MetaUtil.signatureToTypes(target.getSignature(), target.getDeclaringClass()); - ResolvedJavaType returnType = (ResolvedJavaType) target.getSignature().getReturnType(target.getDeclaringClass()); + Class< ? >[] parameterTypes = MetaUtil.signatureToTypes(target.getSignature(), declaringClass); + ResolvedJavaType returnType = target.getSignature().getReturnType(declaringClass).resolve(declaringClass); // Prepare the arguments for the reflective constructor call on the node class. Object[] nodeConstructorArguments = prepareArguments(invoke, parameterTypes, target, false); @@ -103,7 +104,7 @@ // Clean up checkcast instructions inserted by javac if the return type is generic. cleanUpReturnCheckCast(newInstance); } else if (target.getAnnotation(Fold.class) != null) { - Class< ? >[] parameterTypes = MetaUtil.signatureToTypes(target.getSignature(), target.getDeclaringClass()); + Class< ? >[] parameterTypes = MetaUtil.signatureToTypes(target.getSignature(), declaringClass); // Prepare the arguments for the reflective method call Object[] arguments = prepareArguments(invoke, parameterTypes, target, true); @@ -114,7 +115,7 @@ } // Call the method - Constant constant = callMethod(target.getSignature().getReturnKind(), target.getDeclaringClass().toJava(), target.getName(), parameterTypes, receiver, arguments); + Constant constant = callMethod(target.getSignature().getReturnKind(), declaringClass.toJava(), target.getName(), parameterTypes, receiver, arguments); if (constant != null) { // Replace the invoke with the result of the call diff -r f31d374e8195 -r 58dbea9fb973 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/WordTypeRewriterPhase.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/WordTypeRewriterPhase.java Mon Nov 26 16:18:56 2012 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/WordTypeRewriterPhase.java Mon Nov 26 16:51:43 2012 +0100 @@ -169,7 +169,8 @@ case W2A: { assert arguments.size() == 1; ValueNode value = arguments.first(); - ResolvedJavaType targetType = (ResolvedJavaType) targetMethod.getSignature().getReturnType(targetMethod.getDeclaringClass()); + ResolvedJavaType declaringClass = targetMethod.getDeclaringClass(); + ResolvedJavaType targetType = targetMethod.getSignature().getReturnType(declaringClass).resolve(declaringClass); UnsafeCastNode cast = graph.unique(new UnsafeCastNode(value, targetType)); replace(invoke, cast); break; diff -r f31d374e8195 -r 58dbea9fb973 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Mon Nov 26 16:18:56 2012 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Mon Nov 26 16:51:43 2012 +0100 @@ -301,8 +301,9 @@ Symbol* nameSymbol = VmIds::toSymbol(jname); Handle name = JNIHandles::resolve(jname); + assert(nameSymbol != NULL, "name to symbol creation failed"); - oop result; + oop result = NULL; if (nameSymbol == vmSymbols::int_signature()) { result = VMToCompiler::createPrimitiveJavaType((int) T_INT, THREAD); } else if (nameSymbol == vmSymbols::long_signature()) { @@ -323,38 +324,28 @@ result = VMToCompiler::createPrimitiveJavaType((int) T_VOID, THREAD); } else { Klass* resolved_type = NULL; - // if the name isn't in the symbol table then the class isn't loaded anyway... - if (nameSymbol != NULL) { - Handle classloader; - Handle protectionDomain; - if (JNIHandles::resolve(accessingClass) != NULL) { - classloader = java_lang_Class::as_Klass(HotSpotResolvedJavaType::javaMirror(accessingClass))->class_loader(); - protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedJavaType::javaMirror(accessingClass))->protection_domain(); - } - if (eagerResolve) { - resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD); + Handle classloader; + Handle protectionDomain; + if (JNIHandles::resolve(accessingClass) != NULL) { + classloader = java_lang_Class::as_Klass(HotSpotResolvedJavaType::javaMirror(accessingClass))->class_loader(); + protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedJavaType::javaMirror(accessingClass))->protection_domain(); + } + + if (eagerResolve) { + resolved_type = SystemDictionary::resolve_or_fail(nameSymbol, classloader, protectionDomain, true, THREAD); + } 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 { - if (FieldType::is_obj(nameSymbol)) { - ResourceMark rm(THREAD); - // Ignore wrapping L and ;. - TempNewSymbol tmp_name = SymbolTable::new_symbol(nameSymbol->as_C_string() + 1, - nameSymbol->utf8_length() - 2, CHECK_NULL); - resolved_type = SystemDictionary::find_instance_or_array_klass(tmp_name, classloader, protectionDomain, THREAD); - } else { - resolved_type = SystemDictionary::find_instance_or_array_klass(nameSymbol, classloader, protectionDomain, THREAD); - } + Handle type = GraalCompiler::createHotSpotResolvedJavaType(resolved_type, name, CHECK_NULL); + result = type(); } - if (HAS_PENDING_EXCEPTION) { - CLEAR_PENDING_EXCEPTION; - resolved_type = NULL; - } - } - if (resolved_type != NULL) { - Handle type = GraalCompiler::createHotSpotResolvedJavaType(resolved_type, name, CHECK_NULL); - result = type(); - } else { - Handle type = VMToCompiler::createUnresolvedJavaType(name, THREAD); - result = type(); } }