简体   繁体   中英

Force all Java arithmetic to strictfp at runtime, using javassist?

Given a Java application which was written with performance in mind (ie methods are deliberately not declared 'strictfp' in the source code), is it possible to allow users to run the entire application in strictfp mode?

It looks like a crude approach would be to simply add the "strictfp" attribute to all methods of all classes using a custom class loader written using javassist. This would be similar to:

http://www.verious.com/qa/no-strictfp-in-scala-workarounds/

However, the class loader would need to add the strictpf attribute to all class methods in the application, including private ones. (The application is simply too large and complex to explicitly list all possible methods which might requre the strictfp attribute.)

The reflection API in javassist does not seem to support listing private methods:

http://www.csg.ci.iu-tokyo.ac.jp/~chiba/javassist/html/javassist/CtClass.html#getMethods()

Is what I want to do possible in javassist (or at all via the custom class loader approach)?

I don't know if this will help you, but if you could change to using the Oracle JRockit JVM, it has a JVM option to enable strictfp globally - '-XX+:-StrictFP`

(There is a '-XX+:-UseStrictFP' option on Hotspot JVMs, but it has the reverse effect to what you want.)

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM