Bug 249943

Summary: jni JVM init fails when using valgrind
Product: [Developer tools] valgrind Reporter: pepp <pelloux+kde>
Component: vexAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: konstantin.s.serebryany, tom
Priority: NOR    
Version: 3.6 SVN   
Target Milestone: wanted3.6.0   
Platform: Unlisted Binaries   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Simple test case
patch proposal for eflag AC handling for amd64

Description pepp 2010-09-02 21:51:35 UTC
Created attachment 51249 [details]
Simple test case

Version:           3.6 SVN (using Devel) 
OS:                Linux

I have a simple JNI program which works properly without valgrind, and fails when using valgrind (I'm not sure which of OpenJDK/valgrind is guilty).

Exact output from java is : 
"Error occurred during initialization of VM
Unknown x64 processor: SSE2 not supported"

which occurs when calling : JNI_CreateJavaVM

I've made a few researchs, so here's a quick summary :
- when running "valgrind cpuid" sse2 is listed in cpu features
- it seems that OpenJDK method to check sse2 presence is split between those functions/files :
     * supports_sse2() and feature_flags() / vm_version_x86.hpp
     * VM_Version_StubGenerator::generate_getPsrInfo() / vm_version_x86.cpp
(maybe it could be useful to someone with better asm knowledge than me :-) )


My computer specs :
- Core 2 Duo
- Ubunto 10.04 (amd64)


Reproducible: Always

Steps to Reproduce:
Compile the attached program then run "valgrind PROGRAM"
Comment 1 pepp 2010-09-04 10:59:15 UTC
I guess I've found the problem ; OpenJDK code does this before early in the features detection code : 
"// if we are unable to change the AC flag, we have a 386"
If it happens, it skips the feature detection, then the assert 'supports_sse2()' fails later.

If this early test is removed, my test program works correctly.

After looking in valgrind sources, it seems that eflag's AC bit is handled only in x86 code.
I've attached a simple patch which tries to implement AC flag support for amd64 - it works here and with this patch applied the test program is running OK.

I hope this could be useful.
Comment 2 pepp 2010-09-04 11:00:09 UTC
Created attachment 51299 [details]
patch proposal for eflag AC handling for amd64
Comment 3 Konstantin Serebryany 2010-09-28 12:25:08 UTC
We see the same problem with OpenJDK and the attached patch helps. 
Any chance to get the patch into 3.6? 

Thanks!
Comment 4 Julian Seward 2010-09-28 18:00:31 UTC
Committed, r2050 + followup fix in r11388.  Thanks.