RFR (S): 8026502: java/lang/invoke/MethodHandleConstants.java fails on all platforms

Igor Veresov igor.veresov at oracle.com
Tue Oct 22 20:33:13 PDT 2013


Looks fine.

igor

On Oct 22, 2013, at 8:24 PM, Christian Thalinger <christian.thalinger at oracle.com> wrote:

> https://bugs.openjdk.java.net/browse/JDK-8026502
> 
> 8026502: java/lang/invoke/MethodHandleConstants.java fails on all platforms
> Reviewed-by:
> 
> There are two sides to this fix:
> 
> 1) hardening the VM so it doesn't fall over input it shouldn't get:
> 
> diff -r 36e17466dd39 src/share/vm/classfile/systemDictionary.cpp
> --- a/src/share/vm/classfile/systemDictionary.cpp	Tue Oct 22 14:02:15 2013 +0000
> +++ b/src/share/vm/classfile/systemDictionary.cpp	Tue Oct 22 20:17:52 2013 -0700
> @@ -2360,6 +2360,11 @@ methodHandle SystemDictionary::find_meth
>   objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
>   assert(appendix_box->obj_at(0) == NULL, "");
> 
> +  // This should not happen.  JDK code should take care of that.
> +  if (accessing_klass.is_null() || method_type.is_null()) {
> +    THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
> +  }
> +
>   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
>   JavaCallArguments args;
>   args.push_oop(accessing_klass()->java_mirror());
> @@ -2485,6 +2490,9 @@ Handle SystemDictionary::link_method_han
>   Handle type;
>   if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') {
>     type = find_method_handle_type(signature, caller, CHECK_(empty));
> +  } else if (caller.is_null()) {
> +    // This should not happen.  JDK code should take care of that.
> +    THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty);
>   } else {
>     ResourceMark rm(THREAD);
>     SignatureStream ss(signature, false);
> @@ -2548,6 +2556,11 @@ methodHandle SystemDictionary::find_dyna
>   Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty));
>   Handle method_type = find_method_handle_type(type, caller, CHECK_(empty));
> 
> +  // This should not happen.  JDK code should take care of that.
> +  if (caller.is_null() || method_type.is_null()) {
> +    THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty);
> +  }
> +
>   objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty));
>   assert(appendix_box->obj_at(0) == NULL, "");
> 
> 2) fix the JDK code so it doesn't pass input to the VM it shouldn't:
> 
> diff -r 0913c3bab168 src/share/classes/java/lang/invoke/MethodHandles.java
> --- a/src/share/classes/java/lang/invoke/MethodHandles.java	Tue Oct 22 15:12:22 2013 -0700
> +++ b/src/share/classes/java/lang/invoke/MethodHandles.java	Tue Oct 22 19:49:01 2013 -0700
> @@ -1716,6 +1716,13 @@ return mh1;
>                 checkSymbolicClass(defc);
>                 return mh;
>             }
> +            // Treat MethodHandle.invoke and invokeExact specially.
> +            if (defc == MethodHandle.class && refKind == REF_invokeVirtual) {
> +                mh = findVirtualForMH(member.getName(), member.getMethodType());
> +                if (mh != null) {
> +                    return mh;
> +                }
> +            }
>             MemberName resolved = resolveOrFail(refKind, member);
>             mh = getDirectMethodForConstant(refKind, defc, resolved);
>             if (mh instanceof DirectMethodHandle
> @@ -1768,12 +1775,6 @@ return mh1;
>             if (MethodHandleNatives.refKindIsField(refKind)) {
>                 return getDirectFieldNoSecurityManager(refKind, defc, member);
>             } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
> -                if (defc == MethodHandle.class && refKind == REF_invokeVirtual) {
> -                    MethodHandle mh = findVirtualForMH(member.getName(), member.getMethodType());
> -                    if (mh != null) {
> -                        return mh;
> -                    }
> -                }
>                 return getDirectMethodNoSecurityManager(refKind, defc, member, lookupClass);
>             } else if (refKind == REF_newInvokeSpecial) {
>                 return getDirectConstructorNoSecurityManager(defc, member);
> 
> 



More information about the hotspot-compiler-dev mailing list