Bug 249943 - jni JVM init fails when using valgrind
Summary: jni JVM init fails when using valgrind
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: vex (show other bugs)
Version: 3.6 SVN
Platform: Unlisted Binaries Linux
: NOR normal
Target Milestone: wanted3.6.0
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-02 21:51 UTC by pepp
Modified: 2010-09-28 18:00 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Simple test case (421 bytes, text/x-c++src)
2010-09-02 21:51 UTC, pepp
Details
patch proposal for eflag AC handling for amd64 (4.04 KB, patch)
2010-09-04 11:00 UTC, pepp
Details

Note You need to log in before you can comment on or make changes to this bug.
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.