JDK-8221577 : [Graal] Implement basic type consistency checks for Low level MH intrinsics
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 13
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2019-03-27
  • Updated: 2019-07-17
  • Resolved: 2019-06-11
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 13 JDK 14
13Fixed 14 b05Resolved
Related Reports
Duplicate :  
Sub Tasks
JDK-8222229 :  
JDK-8222235 :  
Description
compiler/jsr292/InvokerSignatureMismatch.java fails with
Thread[JVMCI CompilerThread0,9,system]: Compilation of compiler.jsr292.InvokerSignatureMismatch.mainLink(int) failed:
org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: java.lang.AssertionError
	at parsing compiler.jsr292.InvokerSignatureMismatch.bodyI(InvokerSignatureMismatch.java:51)
	at parsing java.base@13-internal/java.lang.invoke.MethodHandleHelper.linkToStatic(MethodHandleHelper.java:53)
	at parsing compiler.jsr292.InvokerSignatureMismatch.mainLink(InvokerSignatureMismatch.java:42)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2435)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3189)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:2993)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:891)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.parseAndInlineCallee(BytecodeParser.java:2454)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.inline(BytecodeParser.java:2356)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.tryInline(BytecodeParser.java:2219)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.appendInvoke(BytecodeParser.java:1725)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.handleReplacedInvoke(BytecodeParser.java:1655)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.replacements.MethodHandlePlugin.handleInvoke(MethodHandlePlugin.java:112)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.tryNodePluginForInvocation(BytecodeParser.java:2198)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.appendInvoke(BytecodeParser.java:1704)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1476)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1456)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5020)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3184)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:2993)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:891)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.parseAndInlineCallee(BytecodeParser.java:2454)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.inline(BytecodeParser.java:2356)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.tryInline(BytecodeParser.java:2230)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.appendInvoke(BytecodeParser.java:1725)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1476)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1456)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5020)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3184)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:2993)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:891)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:785)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:95)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.GraphBuilderPhase.run(GraphBuilderPhase.java:59)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.GraphBuilderPhase.run(GraphBuilderPhase.java:43)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:197)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:139)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.phases.PhaseSuite.run(PhaseSuite.java:212)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:197)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:139)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.core.GraalCompiler.emitFrontEnd(GraalCompiler.java:213)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.core.GraalCompiler.compile(GraalCompiler.java:144)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.core.GraalCompiler.compileGraph(GraalCompiler.java:129)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileHelper(HotSpotGraalCompiler.java:185)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compile(HotSpotGraalCompiler.java:198)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:190)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:98)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.core.CompilationWrapper.run(CompilationWrapper.java:177)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.hotspot.CompilationTask.runCompilation(CompilationTask.java:339)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:138)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:105)
	at jdk.internal.vm.ci/jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.compileMethod(HotSpotJVMCIRuntime.java:524)
Caused by: java.lang.AssertionError
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.FrameStateBuilder.verifyKind(FrameStateBuilder.java:703)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.FrameStateBuilder.loadLocal(FrameStateBuilder.java:718)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.loadLocal(BytecodeParser.java:3710)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:4865)
	at jdk.internal.vm.compiler@13-internal/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3184)
	... 47 more

when running with Graal as JIT mode.

To reproduce run:
> make run-test TEST="compiler/jsr292/InvokerSignatureMismatch.java" LOG=cmdlines TEST_VM_OPTS="-server -ea -esa -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+TieredCompilation -XX:+UseJVMCICompiler -Djvmci.Compiler=graal"

Comments
Upstream graal fix: https://github.com/oracle/graal/commit/d880341edf09d6a14021e2c7f09f70eda56c1c9d
03-07-2019

[~kvn] what's the expected semantics when using a MethodHandle to invoke a static method with a single int parameter where the invocation passes a float instead? Graal is assuming this is a type error like it would be with java.lang.reflect.Method.
10-05-2019

epavlova pushed Changeset 3ff63a to the ClosedJDK 8221099 Add testing with AOTed JCK in mach5 changed this test to run with -ea and -esa
09-04-2019

sure Vladimir. Thank you.
04-04-2019

[~jcm] please look.
03-04-2019

[~rraghavan] please re-assign to JPG compiler team. Porting the C2 behavior to Graal (in org.graalvm.compiler.replacements.MethodHandlePlugin.handleInvoke I think) should be straightforward.
03-04-2019

Method handle linkers (MethodHandle.linkTo*) are inherently unsafe: it's possible to use arbitrary signature to invoke a method and behavior is implementation/platform-specific when argument type mismatch occurs (e.g., int vs float). Type checking for method handle invocation happens earlier: either in MethodHandle.invoke/invokeExact() or as part of invokedynamic linkage. MH linkers implement low-level semantics of different invocation modes. Though such type mismatches (int vs float) shouldn't occur at runtime (it's guaranteed by how method handles are constructed), JIT-compiler can observe it on unreachable branches which can't be proved as such at compile-time. (See JDK-8166110 for an example.) In order to avoid paradoxes in IR, C2 doesn't inline through MH.linkTo* methods if there's type mismatch for any argument or return type (decision is made in ciMethod::is_consistent_info()).
30-03-2019

[~vlivanov] can you answer Doug's question?
29-03-2019