Category: Java/C++ Runtime
There is no configuration method for a JVM option I want to specify. Am I out of luck?
No, of course not. Even if we did not provide a special getter/setter pair for a certain JVM option, you can configure it via the the setDashXOption() or setOtherOption() APIs.
Use the setDashXOption() function for any JVM options that start with "-X" and for which we did not provide a more convenient wrapper API. The following snippet illustrates the correct usage:
xmog_jvm_loader & loader = xmog_jvm_loader::get_jvm_loader(); // this sets the maximum heapsize to 256MB loader.setDashXOption( "mx", "256m" ); // this sets the maximum heapsize to 512MB, overriding the // first option loader.setMaximumHeapSizeInMB( 512 );
Notice how we broke up the "-Xmx256m" setting into a name ("mx") and a value ("256m"). This helps the runtime library to resolve conflicting settings correctly. You could also have written this:
/// *** don't do this *** /// xmog_jvm_loader & loader = xmog_jvm_loader::get_jvm_loader(); // this correctly sets the maximum heapsize to 256MB loader.setDashXOption( "mx256m" ); // what happens now ??? loader.setMaximumHeapSizeInMB( 512 );
The problem with this snippet is that the second configuration call does not know that it overrides the first call's value. Officially, the behavior is undefined, but in all likelihood you will end up with two configuration options: -Xmx256m followed by -Xmx512m. The JVM might treat that as a legal configuration or not, which is why we don't make any claims as to its behavior. To summarize: iIf your -X option has "name" and "value" parts (as in the first snippet above) use the two argument form, otherwise you can use the one argument form.
On top of the pretty freeform setDashXOption() function, there is the setOtherOption() function. setOtherOption() allows you to set any string/pointer combination as a JVM initialization argument.