JDK-8062280 : C2: inlining failure due to access checks being too strict
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8u60,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-10-28
  • Updated: 2015-09-29
  • Resolved: 2015-04-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b64Fixed
Description
Paul Sandoz reported a problem with method inlining through method handles: 
http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2014-October/015993.html

_@ 48   MHInlineTest::testPackageMH (24 bytes)   inline (hot)
__@ 7   java.lang.invoke.LambdaForm$MH/314265080::invokeExact_MT (17 bytes)   force inline by annotation
___@ 2   java.lang.invoke.Invokers::checkExactType (30 bytes)   force inline by annotation
____@ 11   java.lang.invoke.MethodHandle::type (5 bytes)   accessor
___@ 13   java.lang.invoke.LambdaForm$DMH/285377351::invokeVirtual_LL_V (15 bytes)   force inline by annotation
____@ 1   java.lang.invoke.DirectMethodHandle::internalMemberName (8 bytes)   force inline by annotation
____@ 11   MHInlineTest$A::package_x (6 bytes)   virtual call
 
Failing test:
public class MHInlineTest {
    public static class A {
        void package_x(String s) { ... }
    }

    public static final class B extends A {
        void package_x(String s) { ... }
    }

    static final MethodHandle A_PUBLIC_X;
    static final MethodHandle A_PROTECTED_X;
    static final MethodHandle A_PACKAGE_X;
    static final MethodHandle A_PACKAGE_FINAL_X;

    static {
        try {
            A_PACKAGE_X = MethodHandles.lookup().findVirtual(
                    A.class, "package_x", MethodType.methodType(void.class, String.class));
        } catch (Exception e) {
            throw new Error(e);
        }
    }

    static final A a = new B();

    public static void main(String[] args) {
        for (int i = 0; i < 1000_0000; i++) {
            try {
                A_PROTECTED_X.invokeExact(a, x);
            } catch (Throwable throwable) {
                throw new Error(throwable);
            }
        }
    }
}

Comments
Strictly speaking, it's not a functional bug, but a missed optimization opportunity. It is present in previous HS/JDK versions. Reclassifying it as an enhancement.
26-11-2014

Call tree: Reflection::verify_field_access() LinkResolver::check_method_accessability() at linkResolver.cpp:452 LinkResolver::resolve_method() at linkResolver.cpp:578 LinkResolver::linktime_resolve_virtual_method() at linkResolver.cpp:1095 LinkResolver::resolve_virtual_call() at linkResolver.cpp:1086 LinkResolver::resolve_virtual_call_or_null() at linkResolver.cpp:1398 ciMethod::resolve_invoke() at ciMethod.cpp:792 ciMethod::find_monomorphic_target() at ciMethod.cpp:694 Compile::optimize_inlining() at doCall.cpp:1012 Compile::optimize_virtual_call() at doCall.cpp:957 CallGenerator::for_method_handle_inline() at callGenerator.cpp:877 CallGenerator::for_method_handle_call() at callGenerator.cpp:769 Compile::call_generator() at doCall.cpp:148 Parse::do_call() at doCall.cpp:496
30-10-2014