We're using various older versions of Java 1.6 at work which can't be updated for assorted reasons outside my control.
Some support -XX:ReduceInitialCardMarks, some do not, and exit if you try to use an unsupported option.
I'd like a shell script which calls java with the -XX:ReduceInitialCardMarks option if it is available, but otherwise without.
Things I've tried/considering
- -X, this only prints out -X arguments not -XX
- Testing the version? How? Would need upfront knowledge of which versions support what
- Calling with a dummy application and testing return value, e.g. java -XX:ReduceInitialCardMarks -jar dummy.jar. No suitable classes in rt.jar with static void main() to use, so have to make my own.
Best approach so far, grepping the output for Unrecognized VM option when calling with -version, note -version has to be after the argument as otherwise it doesn't test it.
if java -XX:-ReduceInitialCardMarks -version 2>&1 | grep -q 'Unrecognized VM option'; then echo "Not supported"; else echo "Supported"; fi
Is there any clean way of doing this?