# HG changeset patch # User Doug Simon # Date 1332762553 -7200 # Node ID 482265e41a1a215052478380ad6cec66b8ac239a # Parent 51fb8bc5ecf6ffdb561484ef4edbd3d16e9c8850 added -G:+PrintFlags flag for printing the Graal flags; tightened format checking of Graal options to be consistent with HotSpot diff -r 51fb8bc5ecf6 -r 482265e41a1a graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Fri Mar 23 12:13:04 2012 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Mon Mar 26 13:49:13 2012 +0200 @@ -196,6 +196,11 @@ */ public static boolean AllocSSA = false; + /** + * Prints all the available GraalOptions. + */ + public static boolean PrintFlags = false; + static { // turn detailed assertions on when the general assertions are on (misusing the assert keyword for this) assert (DetailedAsserts = true) == true; diff -r 51fb8bc5ecf6 -r 482265e41a1a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Fri Mar 23 12:13:04 2012 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Mon Mar 26 13:49:13 2012 +0200 @@ -24,6 +24,7 @@ package com.oracle.graal.hotspot; import java.lang.reflect.*; +import java.util.*; import com.oracle.graal.compiler.*; import com.oracle.graal.hotspot.logging.*; @@ -35,6 +36,7 @@ GraalOptions.ResolveClassBeforeStaticInvoke = false; } + // Called from VM code public static boolean setOption(String option) { if (option.length() == 0) { return false; @@ -62,28 +64,35 @@ Field f; try { f = GraalOptions.class.getDeclaredField(fieldName); + Class< ? > fType = f.getType(); if (value == null) { - if (f.getType() == Float.TYPE) { + if (fType == Boolean.TYPE) { + Logger.info("Value for boolean option '" + fieldName + "' must use '-G:+" + fieldName + "' or '-G:-" + fieldName + "' format"); + return false; + } + + if (valueString == null) { + Logger.info("Value for option '" + fieldName + "' must use '-G:" + fieldName + "=' format"); + return false; + } + + if (fType == Float.TYPE) { value = Float.parseFloat(valueString); - } else if (f.getType() == Double.TYPE) { + } else if (fType == Double.TYPE) { value = Double.parseDouble(valueString); - } else if (f.getType() == Integer.TYPE) { + } else if (fType == Integer.TYPE) { value = Integer.parseInt(valueString); - } else if (f.getType() == Boolean.TYPE) { - if (valueString == null || valueString.length() == 0) { - value = true; - } else { - value = Boolean.parseBoolean(valueString); - } - } else if (f.getType() == String.class) { - if (valueString == null) { - value = ""; - } else { - value = valueString; - } + } else if (fType == String.class) { + value = valueString; + } + } else { + if (fType != Boolean.TYPE) { + Logger.info("Value for option '" + fieldName + "' must use '-G:" + fieldName + "=' format"); + return false; } } + if (value != null) { f.setAccessible(true); f.set(null, value); @@ -106,6 +115,31 @@ return false; } + if (option.equals("+PrintFlags")) { + printFlags(); + } + return true; } + + private static void printFlags() { + Logger.info("[Graal flags]"); + Field[] flags = GraalOptions.class.getDeclaredFields(); + Arrays.sort(flags, new Comparator() { + public int compare(Field o1, Field o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + for (Field f : flags) { + if (Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())) { + f.setAccessible(true); + try { + Object value = f.get(null); + Logger.info(String.format("%9s %-40s = %s", f.getType().getSimpleName(), f.getName(), value)); + } catch (Exception e) { + } + } + } + System.exit(0); + } } diff -r 51fb8bc5ecf6 -r 482265e41a1a src/share/vm/graal/graalCompiler.cpp --- a/src/share/vm/graal/graalCompiler.cpp Fri Mar 23 12:13:04 2012 -0700 +++ b/src/share/vm/graal/graalCompiler.cpp Mon Mar 26 13:49:13 2012 +0200 @@ -80,7 +80,7 @@ Handle option = java_lang_String::create_from_str(arg, THREAD); jboolean result = VMToCompiler::setOption(option); if (!result) { - tty->print_cr("Invalid option for graal!"); + tty->print_cr("Invalid option for graal: -G:%s", arg); vm_abort(false); } }