JDK-8148926 : Call site profiling fails on braces-wrapped anonymous function
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u71,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2016-01-30
  • Updated: 2016-07-21
  • Resolved: 2016-02-04
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
8u102Fixed 9 b105Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_71"
Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.71-b15, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
When execution Nashorn with call site profiling enabled, scripts that directly invoke a braces-wrapped function literal will cause the engine to fail with an IllegalArgumentException / BootstrapMethodError during call site initialization. The same function literal invoked instead via the call or apply functions will not be affected by this problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the following scripts with jjs --profile-callsites=true

Script 1: (function(){ print('test');}())

Script 2: (function(){ print('test');})()

Script 3: (function(){ print('test');}).call(this);

Script 4: (function(){ print('test');}.call(this));

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Script 1 through 4 are executed successfully and 'test' is printed to the console four times
ACTUAL -
Script 1 and 2 fail with an IllegalArgumentException / BootstrapMethodError
Script 3 and 4 succeeed and print 'test' to the console twice

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
        at java.lang.invoke.CallSite.makeSite(CallSite.java:341)
        at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307)
        at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297)
        at jdk.nashorn.internal.scripts.Script$2$\^shell\_.:program(<shell>:1)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
        at jdk.nashorn.internal.runtime.Context.eval(Context.java:740)
        at jdk.nashorn.internal.runtime.Context.eval(Context.java:675)
        at jdk.nashorn.tools.Shell.readEvalPrint(Shell.java:442)
        at jdk.nashorn.tools.Shell.run(Shell.java:161)
        at jdk.nashorn.tools.Shell.main(Shell.java:136)
        at jdk.nashorn.tools.Shell.main(Shell.java:112)
Caused by: java.lang.IllegalArgumentException: target and filter types do not match: (ScriptObject,ScriptObject)Object, (Object)Object
        at java.lang.invoke.MethodHandleStatics.newIllegalArgumentException(MethodHandleStatics.java:145)
        at java.lang.invoke.MethodHandles.filterArgumentChecks(MethodHandles.java:2631)
        at java.lang.invoke.MethodHandles.filterArgument(MethodHandles.java:2608)
        at java.lang.invoke.MethodHandles.filterArguments(MethodHandles.java:2601)
        at jdk.nashorn.internal.lookup.MethodHandleFactory$StandardMethodHandleFunctionality.filterArguments(MethodHandleFactory.java:383)
        at jdk.nashorn.internal.runtime.linker.LinkerCallSite$ProfilingLinkerCallSite.setTarget(LinkerCallSite.java:241)
        at jdk.internal.dynalink.support.AbstractRelinkableCallSite.initialize(AbstractRelinkableCallSite.java:115)
        at jdk.internal.dynalink.DynamicLinker.link(DynamicLinker.java:201)
        at jdk.nashorn.internal.runtime.linker.Bootstrap.bootstrap(Bootstrap.java:207)
        at java.lang.invoke.CallSite.makeSite(CallSite.java:294)
        ... 12 more

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Use invocations via functions from Function prototype (call / apply) to execute braces-wrapped (anonymous) function literal.


Comments
Tried the steps outlined in the bug description. Following are the results: JDK 8u72 - Fail JDK 9ea b103 - fail
03-02-2016