Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Given a Java application which was written with performance in mind (i.e. 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.i.u-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)?

like image 669
user2524735 Avatar asked Jun 26 '13 15:06

user2524735


1 Answers

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:

  • http://docs.oracle.com/cd/E15289_01/doc.40/e15062/optionxx.htm#BABHBDAH
  • http://stas-blogspot.blogspot.com.au/2011/07/most-complete-list-of-xx-options-for.html
like image 120
Stephen C Avatar answered Sep 23 '22 02:09

Stephen C