changeset 9863:b2141bc6e98e

option values are either initialized upon creation or they must provide a lazily initialized value
author Doug Simon <doug.simon@oracle.com>
date Tue, 04 Jun 2013 15:42:42 +0200
parents 538ac2cf3383
children 063a712fe8d8
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java
diffstat 2 files changed, 18 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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<Integer> TimedBootstrap = new OptionValue<>(-1);
 
     @Option(help = "Number of compilation threads to use")
-    private static final OptionValue<Integer> Threads = new OptionValue<Integer>(1) {
+    private static final OptionValue<Integer> Threads = new OptionValue<Integer>() {
 
         @Override
         public Integer initialValue() {
--- 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;
     }
 }