United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7047697 MethodHandle.invokeExact call for wrong method causes VM failure if run with -Xcomp
JDK-7047697 : MethodHandle.invokeExact call for wrong method causes VM failure if run with -Xcomp

Details
Type:
Bug
Submit Date:
2011-05-24
Status:
Closed
Updated Date:
2013-06-26
Project Name:
JDK
Resolved Date:
2012-06-05
Component:
hotspot
OS:
generic
Sub-Component:
compiler
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
hs21 (b16)

Related Reports
Backport:
Backport:
Backport:
Relates:
Relates:
Relates:

Sub Tasks

Description
The test below causes VM failure instead of WrongMethodTypeException if uncomment any of invokeExact calls and run the test with -Xcomp option:
----------------------------------------------------------
import java.lang.invoke.*;

class A {
    public static String foo(){return "";}
}   
public class Test {
    public static void main(String argv[]) throws Throwable {
        MethodHandle handle = MethodHandles.lookup().findStatic
            (A.class, "foo", MethodType.methodType(String.class));
        String inv1 = (String) handle.invokeExact(null);
//        String inv2 = (String) handle.invokeExact(new Object[]{});
//        String inv3 = (String) handle.invokeExact(-1);
//        CharSequence cs = (CharSequence) handle.invokeExact();
//        Object obj = handle.invokeExact();
    }
}
----------------------------------------------------------

C:\JDK\7\bin>java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b143)
Java HotSpot(TM) Client VM (build 21.0-b13, mixed mode)
C:\JDK\7\bin>javac Test.java
C:\JDK\7\bin>java -Xcomp Test
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x66029cd6, pid=324, tid=3976
#
# JRE version: 7.0-b143
# Java VM: Java HotSpot(TM) Client VM (21.0-b13 compiled mode windows-x86 )
# Problematic frame:
# V  [jvm.dll+0x39cd6]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\JCK7\292\hs_err_pid324.log
Phoning home...
Using server: 10.161.186.18, port 4711
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
The issue is also reproducible on Linux and Solaris with "-client" option.
The problem is reproducible on b144:
---------------------------------------------------------
<dm154731@zenit> /set/java/re/jdk/7/latest/binaries/solaris-amd64/bin/java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b144)
Java HotSpot(TM) Server VM (build 21.0-b14, mixed mode)
<dm154731@zenit> /set/java/re/jdk/7/latest/binaries/solaris-amd64/bin/java -Xcomp -client Test
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xfea8b557, pid=15125, tid=2
#
# JRE version: 7.0-b144
# Java VM: Java HotSpot(TM) Client VM (21.0-b14 compiled mode solaris-x86 )
# Problematic frame:
# V  [libjvm.so+0x68b557]  int methodOopDesc::validate_bci_from_bcx(int)const+0x27
#
# Core dump written. Default location: /home/dm154731/292/core or core.15125
#
# An error report file with more information is saved as:
# /home/dm154731/292/hs_err_pid15125.log
Phoning home...
Using server: 10.161.186.18, port 4711
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
Abort (core dumped)
---------------------------------------------------------

                                    

Comments
EVALUATION

Appears to be fixed in b144; likely to be a dup of this bug:
  7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp  

Expected output, with test lines split under switch(N):

--------
	for N in 1 2 3 4 5; do $JAVA7X_HOME/bin/java -Xcomp -DN=$N -cp . Test7047697; done
Exception in thread "main" java.lang.invoke.WrongMethodTypeException: ()Ljava/lang/String; cannot be called with a different arity as (Ljava/lang/Void;)Ljava/lang/String;
	at Test7047697.main(Test7047697.java:20)
Exception in thread "main" java.lang.invoke.WrongMethodTypeException: ()Ljava/lang/String; cannot be called with a different arity as ([Ljava/lang/Object;)Ljava/lang/String;
	at Test7047697.main(Test7047697.java:23)
Exception in thread "main" java.lang.invoke.WrongMethodTypeException: ()Ljava/lang/String; cannot be called with a different arity as (I)Ljava/lang/String;
	at Test7047697.main(Test7047697.java:26)
Exception in thread "main" java.lang.invoke.WrongMethodTypeException: ()Ljava/lang/String; cannot be called as ()Ljava/lang/CharSequence;
	at Test7047697.main(Test7047697.java:29)
Exception in thread "main" java.lang.invoke.WrongMethodTypeException: ()Ljava/lang/String; cannot be called as ()Ljava/lang/Object;
	at Test7047697.main(Test7047697.java:32)
--------
                                     
2011-06-01
EVALUATION

The problem occurs when a compiled method makes a method handle call that then calls into the VM.

Possible examples:
- Creating a WrongMethodTypeException to throw from a failed invokeExact.
- Throwing a stack overflow.
- Allocating a wrapper when boxing a primitive.

In the reported case, the failure can occur when the new WrongMethodTypeException object executes fillInStackTrace.  The resulting stack walk attempts to find the sender frame from the VM call frame (which is an entry_frame).  The sender is a compiled frame, which needs careful treatment if it is a method handle invoke (to set the unextended_sp).  This is not done, and so the sp value used to parse the compiler frame is moved (if the method handle invocation extended the stack to adapt arguments).
                                     
2011-06-08
EVALUATION

http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/5cf771a79037
                                     
2011-06-09
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot/hotspot/rev/07c2e7ffd1fc
                                     
2011-06-15
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-rt/hotspot/rev/07c2e7ffd1fc
                                     
2011-06-18
EVALUATION

http://hg.openjdk.java.net/hsx/hotspot-rt/hotspot/rev/5cf771a79037
                                     
2011-06-18



Hardware and Software, Engineered to Work Together