2 messages in net.java.dev.jna.users[jna-users] FPU control word safeguard?
FromSent OnAttachments
Hueneke, ImmoOct 27, 2008 5:33 am 
Timothy WallOct 27, 2008 6:24 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[jna-users] FPU control word safeguard?Actions...
From:Hueneke, Immo (ih@zuhlke.com)
Date:Oct 27, 2008 5:33:10 am
List:net.java.dev.jna.users

Hi all,

When using JNI, there is a well known method of crashing the JVM by changing the
value of the FPU control word within the native code and failing to restore it.
Whenever the VM executes the so-called "Safepoint Blob" to switch threads, it
has to pop all the floating-point registers into a thread context area and does
not expect the FPU to raise an exception when it underflows. Some native
libraries need to unmask floating-point exceptions, so to honour the JNI
contract they should restore the CW register afterwards (a relatively slow
operation, which is why the JNI implementation doesn't do this).

I can't find any documentation on this issue where JNA is concerned. Does JNA
safeguard the FPUCW each time execution passes between Java and native code, or
does the native library have to conform to a contract similar to JNI? Are there
any documented instances of VMs crashing sporadically with error messages along
the following lines?

- Java HotSpot(TM) Client VM warning: Floating point control word
changed by native JNI code. - An unexpected error has been detected by HotSpot Virtual Machine:
EXCEPTION_ACCESS_VIOLATION - EXCEPTION_FLT_DIVIDE_BY_ZERO - EXCEPTION_FLT_STACK_CHECK

Thanks in advance for any information.

More background: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6346124 and
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5105765

Best regards, Immo

___________________________________

Consulting · Development · Integration

Immo Hüneke Senior Systems Architect

Zühlke Engineering Ltd<http://tinyurl.com/34mdeb> Marble Arch Tower 55 Bryanston Street London W1H 7AA United Kingdom

Zuhlke Engineering Ltd Registered in England Company No: 4103211 Registered Office: 25 Moorgate London EC2R 6AY