RFR (S): make lookupConstantInPool use ConstantPool logic

Doug Simon doug.simon at oracle.com
Mon May 6 14:28:31 PDT 2013


Looks good to me.

Not sure why we never used tag.value() in the first place - probably just another bit of HotSpot internal API we weren't aware of.

-Doug

On May 6, 2013, at 11:24 PM, Christian Thalinger <christian.thalinger at oracle.com> wrote:

> This change uses the ConstantPool logic to do the lookups.  It also implements missing constant pool types like JVM_CONSTANT_MethodHandle and JVM_CONSTANT_MethodType.
> 
> test.java.lang.invoke.InvokeDynamicPrintArgs can now be run like:
> 
> $ java -XX:-BootstrapGraal -Xcomp -XX:CompileCommand=compileonly,test.java.lang.invoke.*::* -XX:+PrintCompilation -cp test/java/lang/invoke/:. indify.Indify --java test.java.lang.invoke.InvokeDynamicPrintArgs
> 
> -- Chris
> 
> diff --git a/src/share/vm/graal/graalCompilerToVM.cpp b/src/share/vm/graal/graalCompilerToVM.cpp
> --- a/src/share/vm/graal/graalCompilerToVM.cpp
> +++ b/src/share/vm/graal/graalCompilerToVM.cpp
> @@ -391,35 +391,52 @@
> 
>   oop result = NULL;
>   constantTag tag = cp->tag_at(index);
> -  if (tag.is_int()) {
> -    result = VMToCompiler::createConstant(Kind::Int(), cp->int_at(index), CHECK_0);
> -  } else if (tag.is_long()) {
> -    result = VMToCompiler::createConstant(Kind::Long(), cp->long_at(index), CHECK_0);
> -  } else if (tag.is_float()) {
> -    result = VMToCompiler::createConstantFloat(cp->float_at(index), CHECK_0);
> -  } else if (tag.is_double()) {
> -    result = VMToCompiler::createConstantDouble(cp->double_at(index), CHECK_0);
> -  } else if (tag.is_string()) {
> -    oop string = NULL;
> -    if (cp->is_pseudo_string_at(index)) {
> -      int obj_index = cp->cp_to_object_index(index);
> -      string = cp->pseudo_string_at(index, obj_index);
> -    } else {
> -      string = cp->string_at(index, THREAD);
> -      if (HAS_PENDING_EXCEPTION) {
> -        CLEAR_PENDING_EXCEPTION;
> -        // TODO: Gracefully exit compilation.
> -        fatal("out of memory during compilation!");
> -        return NULL;
> -      }
> +
> +  switch (tag.value()) {
> +  case JVM_CONSTANT_Integer:
> +    result = VMToCompiler::createConstant(Kind::Int(), cp->int_at(index), CHECK_NULL);
> +    break;
> +
> +  case JVM_CONSTANT_Long:
> +    result = VMToCompiler::createConstant(Kind::Long(), cp->long_at(index), CHECK_NULL);
> +    break;
> +
> +  case JVM_CONSTANT_Float:
> +    result = VMToCompiler::createConstantFloat(cp->float_at(index), CHECK_NULL);
> +    break;
> +
> +  case JVM_CONSTANT_Double:
> +    result = VMToCompiler::createConstantDouble(cp->double_at(index), CHECK_NULL);
> +    break;
> +
> +  case JVM_CONSTANT_Class:
> +  case JVM_CONSTANT_UnresolvedClass:
> +  case JVM_CONSTANT_UnresolvedClassInError:
> +    {
> +      Handle type = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
> +      result = type();
> +      break;
>     }
> -    result = VMToCompiler::createConstantObject(string, CHECK_0);
> -  } else if (tag.is_klass() || tag.is_unresolved_klass()) {
> -    Handle type = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
> -    result = type();
> -  } else {
> -    tty->print("unknown constant pool tag (%s) at cpi %d in %s: ", tag.internal_name(), index, cp->pool_holder()->name()->as_C_string());
> -    ShouldNotReachHere();
> +
> +  case JVM_CONSTANT_String:
> +    {
> +      oop result_oop = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
> +      result = VMToCompiler::createConstantObject(result_oop, CHECK_NULL);
> +      break;
> +    }
> +
> +  case JVM_CONSTANT_MethodHandle:
> +  case JVM_CONSTANT_MethodHandleInError:
> +  case JVM_CONSTANT_MethodType:
> +  case JVM_CONSTANT_MethodTypeInError:
> +    {
> +      oop result_oop = cp->resolve_constant_at(index, CHECK_NULL);
> +      result = VMToCompiler::createConstantObject(result_oop, 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);
> 



More information about the graal-dev mailing list