JDK-7132180 : JSR 292: C1 JVM crash with ClassValue/MethodHandle
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2012-01-21
  • Updated: 2012-03-22
  • Resolved: 2012-02-21
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 7 JDK 8 Other
7u4Fixed 8Fixed hs23Fixed
Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)

FULL OS VERSION :
Windows Vista (32 bit)

A DESCRIPTION OF THE PROBLEM :
The JVM crashes if I run a simple program.



THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: No

REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample program in with JRE 1.70.2.


EXPECTED VERSUS ACTUAL BEHAVIOR :
  Program completes normally and displays "COMPLETED".

ERROR MESSAGES/STACK TRACES THAT OCCUR :

# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (c1/c1_ValueType.hpp:300), pid=8120, tid=7232
#  Error: ShouldNotReachHere()
#
# JRE version: 7.0_02-b13
# Java VM: Java HotSpot(TM) Client VM (22.0-b10 mixed mode, sharing windows-x86 )
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#

---------------  T H R E A D  ---------------

Current thread (0x0220b000):  JavaThread "C1 CompilerThread0" daemon [_thread_in_native, id=7232, stack(0x045a0000,0x045f0000)]

Stack: [0x045a0000,0x045f0000],  sp=0x045ef1e8,  free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0x162f81]
V  [jvm.dll+0x15d8cb]
V  [jvm.dll+0x2283ef]
V  [jvm.dll+0x2312cf]
V  [jvm.dll+0x2331e0]
V  [jvm.dll+0x233ca1]
V  [jvm.dll+0x236ae6]
V  [jvm.dll+0x236c49]
V  [jvm.dll+0x2268a2]
V  [jvm.dll+0x226fd3]
V  [jvm.dll+0x2270fa]
V  [jvm.dll+0x227257]
V  [jvm.dll+0x2274dd]
V  [jvm.dll+0x44935]
V  [jvm.dll+0x44d94]
V  [jvm.dll+0x14394f]
V  [jvm.dll+0x1720b9]
C  [msvcr100.dll+0x5c6de]  endthreadex+0x3a
C  [msvcr100.dll+0x5c788]  endthreadex+0xe4
C  [kernel32.dll+0x4d309]  BaseThreadInitThunk+0x12
C  [ntdll.dll+0x41603]  RtlInitializeExceptionChain+0x63
C  [ntdll.dll+0x415d6]  RtlInitializeExceptionChain+0x36


Current CompileTask:
C1:    349    1 %           ClassValueTest2::test @ 32 (55 bytes)


---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x047a9000 JavaThread "ReaderThread" [_thread_in_native, id=3276, stack(0x04540000,0x04590000)]
  0x02210000 JavaThread "Service Thread" daemon [_thread_blocked, id=7700, stack(0x044c0000,0x04510000)]
=>0x0220b000 JavaThread "C1 CompilerThread0" daemon [_thread_in_native, id=7232, stack(0x045a0000,0x045f0000)]
  0x02209c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=6224, stack(0x043f0000,0x04440000)]
  0x02206800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=7724, stack(0x01990000,0x019e0000)]
  0x021f3400 JavaThread "Finalizer" daemon [_thread_blocked, id=7652, stack(0x04440000,0x04490000)]
  0x021ee800 JavaThread "Reference Handler" daemon [_thread_blocked, id=6988, stack(0x04360000,0x043b0000)]
  0x0213a000 JavaThread "main" [_thread_in_Java, id=8136, stack(0x020d0000,0x02120000)]

Other Threads:
  0x021ed000 VMThread [stack: 0x04300000,0x04350000] [id=8060]
  0x02222c00 WatcherThread [stack: 0x04740000,0x04790000] [id=6080]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 4928K, used 2851K [0x23f30000, 0x24480000, 0x29480000)
  eden space 4416K,  52% used [0x23f30000, 0x24178c50, 0x24380000)
  from space 512K, 100% used [0x24400000, 0x24480000, 0x24480000)
  to   space 512K,   0% used [0x24380000, 0x24380000, 0x24400000)
 tenured generation   total 10944K, used 261K [0x29480000, 0x29f30000, 0x33f30000)
   the space 10944K,   2% used [0x29480000, 0x294c1468, 0x294c1600, 0x29f30000)
 compacting perm gen  total 12288K, used 1167K [0x33f30000, 0x34b30000, 0x37f30000)
   the space 12288K,   9% used [0x33f30000, 0x34053e08, 0x34054000, 0x34b30000)
    ro space 10240K,  45% used [0x37f30000, 0x383b2710, 0x383b2800, 0x38930000)
    rw space 12288K,  54% used [0x38930000, 0x38fb6488, 0x38fb6600, 0x39530000)

Code Cache  [0x022b0000, 0x02380000, 0x042b0000)
 total_blobs=290 nmethods=147 adapters=78 free_code_cache=31936Kb largest_free_block=32702784

Dynamic libraries:
0x002e0000 - 0x0030f000 	P:\java\jdk1.7.0_02\bin\javaw.exe
0x76fc0000 - 0x770e8000 	C:\Windows\system32\ntdll.dll
0x76d50000 - 0x76e2c000 	C:\Windows\system32\kernel32.dll
0x75510000 - 0x75544000 	C:\Program Files\Alwil Software\Avast5\snxhk.dll
0x75c10000 - 0x75cd6000 	C:\Windows\system32\ADVAPI32.dll
0x77150000 - 0x77213000 	C:\Windows\system32\RPCRT4.dll
0x76b80000 - 0x76c1d000 	C:\Windows\system32\USER32.dll
0x75a20000 - 0x75a6b000 	C:\Windows\system32\GDI32.dll
0x74390000 - 0x7452e000 	C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18305_none_5cb72f2a088b0ed3\COMCTL32.dll
0x76c20000 - 0x76cca000 	C:\Windows\system32\msvcrt.dll
0x758a0000 - 0x758f9000 	C:\Windows\system32\SHLWAPI.dll
0x770f0000 - 0x7710e000 	C:\Windows\system32\IMM32.DLL
0x75750000 - 0x75818000 	C:\Windows\system32\MSCTF.dll
0x75740000 - 0x75749000 	C:\Windows\system32\LPK.DLL
0x76cd0000 - 0x76d4d000 	C:\Windows\system32\USP10.dll
0x63870000 - 0x6392e000 	P:\java\jdk1.7.0_02\jre\bin\msvcr100.dll
0x72ac0000 - 0x72de8000 	P:\java\jdk1.7.0_02\jre\bin\client\jvm.dll
0x726b0000 - 0x726b7000 	C:\Windows\system32\WSOCK32.dll
0x75680000 - 0x756ad000 	C:\Windows\system32\WS2_32.dll
0x76920000 - 0x76926000 	C:\Windows\system32\NSI.dll
0x73ae0000 - 0x73b12000 	C:\Windows\system32\WINMM.dll
0x75ac0000 - 0x75c05000 	C:\Windows\system32\ole32.dll
0x756b0000 - 0x7573d000 	C:\Windows\system32\OLEAUT32.dll
0x73aa0000 - 0x73ade000 	C:\Windows\system32\OLEACC.dll
0x75670000 - 0x75677000 	C:\Windows\system32\PSAPI.DLL
0x72aa0000 - 0x72aac000 	P:\java\jdk1.7.0_02\jre\bin\verify.dll
0x72a60000 - 0x72a80000 	P:\java\jdk1.7.0_02\jre\bin\java.dll
0x72a40000 - 0x72a53000 	P:\java\jdk1.7.0_02\jre\bin\zip.dll
0x72a20000 - 0x72a34000 	P:\java\jdk1.7.0_02\jre\bin\net.dll
0x74d20000 - 0x74d5b000 	C:\Windows\system32\mswsock.dll
0x74d00000 - 0x74d05000 	C:\Windows\System32\wship6.dll

VM Arguments:
jvm_args: -Dfile.encoding=UTF-8
java_command: org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 54629 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -test ClassValueTest2:test
Launcher Type: SUN_STANDARD

Environment Variables:
XXXXXXXXXXXXXX
USERNAME=XXXXX
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 11, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows Vista Build 6002 Service Pack 2

CPU:total 4 (4 cores per cpu, 1 threads per core) family 6 model 15 stepping 11, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3

Memory: 4k page, physical 3142880k(1160836k free), swap 6518112k(3051360k free)

vm_info: Java HotSpot(TM) Client VM (22.0-b10) for windows-x86 JRE (1.7.0_02-b13), built on Nov 17 2011 17:17:32 by "java_re" with unknown MS VC++:1600

time: Sat Jan 21 16:20:58 2012
elapsed time: 0 seconds




REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------


import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import org.junit.Test;

public class SimpleTest {
    

    static final ClassValue<MethodHandle> CLASS_VALUE = new ClassValue<MethodHandle>() {
        @Override
        protected MethodHandle computeValue(Class clas) {
            try {
                return MethodHandles.lookup().findVirtual(clas, "sayHello", MethodType.methodType(void.class));
            }
            catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    };

    static class Example {
        public void sayHello() {  }
    }
       
        
    @Test
    public void test() throws Throwable {
        
        Object obj = new Example();
        MethodHandle mh = CLASS_VALUE.get(obj.getClass());
        
        mh.invoke(obj); // no crash if removed
        
        for (int i=0; i<1000000; i++)
            mh.invoke(obj); // <== crash here?
        
        System.out.println("COMPLETED");
    }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use JDK 1.7.0.0

Comments
EVALUATION http://hg.openjdk.java.net/lambda/lambda/hotspot/rev/2f5980b127e3
22-03-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/2f5980b127e3
31-01-2012

SUGGESTED FIX Check for is_constant on the ObjectType of both inputs.
30-01-2012

EVALUATION The logic for detecting the selectAlternative idiom in GraphBuilder::for_method_handle_inline assumes that both inputs of the phi node are constant. This might now be the case.
30-01-2012

EVALUATION I can reproduce the crash with 7u2 and 7u4: $ /java/re/jdk/7u4/promoted/latest/binaries/solaris-i586/bin/java -showversion -client SimpleTest java version "1.7.0_04-ea" Java(TM) SE Runtime Environment (build 1.7.0_04-ea-b09) Java HotSpot(TM) Client VM (build 23.0-b11, mixed mode) # # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (c1_ValueType.hpp:300), pid=10919, tid=7 # Error: ShouldNotReachHere() # # JRE version: 7.0_04-b09 # Java VM: Java HotSpot(TM) Client VM (23.0-b11 mixed mode solaris-x86 ) # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
30-01-2012