# HG changeset patch # User Doug Simon # Date 1370353362 -7200 # Node ID b2141bc6e98e90d3271e557caa37ef8f7a72f086 # Parent 538ac2cf3383d6149cd743e2c1845eda82c014da option values are either initialized upon creation or they must provide a lazily initialized value diff -r 538ac2cf3383 -r b2141bc6e98e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Tue Jun 04 15:22:43 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Tue Jun 04 15:42:42 2013 +0200 @@ -75,7 +75,7 @@ private static final OptionValue TimedBootstrap = new OptionValue<>(-1); @Option(help = "Number of compilation threads to use") - private static final OptionValue Threads = new OptionValue(1) { + private static final OptionValue Threads = new OptionValue() { @Override public Integer initialValue() { diff -r 538ac2cf3383 -r b2141bc6e98e graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java --- a/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Tue Jun 04 15:22:43 2013 +0200 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Tue Jun 04 15:42:42 2013 +0200 @@ -39,13 +39,7 @@ protected T value; /** - * Guards whether {@link #initialValue()} should be called to give a subclass an opportunity to - * provide a context-sensitive initial value for this option. - */ - protected boolean initialValueCalled; - - /** - * Create an option. + * Creates an option value. * * @param value the initial/default value of the option */ @@ -53,17 +47,30 @@ this.value = value; } + private static final Object UNINITIALIZED = "UNINITIALIZED"; + + /** + * Creates an uninitialized option value for a subclass that initializes itself + * {@link #initialValue() lazily}. + */ + @SuppressWarnings("unchecked") + protected OptionValue() { + this.value = (T) UNINITIALIZED; + } + + /** + * Lazy initialization of value. + */ protected T initialValue() { - return value; + throw new InternalError("Uninitialized option value must override initialValue()"); } /** * Gets the value of this option. */ public final T getValue() { - if (!initialValueCalled) { + if (value == UNINITIALIZED) { value = initialValue(); - initialValueCalled = true; } return value; } @@ -74,6 +81,5 @@ @SuppressWarnings("unchecked") public final void setValue(Object v) { this.value = (T) v; - this.initialValueCalled = true; } }