# HG changeset patch # User Christian Wimmer # Date 1418671979 28800 # Node ID 823f499a247cea743e202d0fac6f41f7d84de930 # Parent 0a109f5d587362a57f5be18a20185c3394a47bdb Store initial value (the value set in source code) of an option diff -r 0a109f5d5873 -r 823f499a247c 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 Mon Dec 15 19:15:39 2014 +0100 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Mon Dec 15 11:32:59 2014 -0800 @@ -130,6 +130,8 @@ static final ThreadLocal overrideScopes = new ThreadLocal<>(); + private T initialValue; + /** * The raw option value. */ @@ -152,8 +154,10 @@ } } + @SuppressWarnings("unchecked") public OptionValue(T value) { - this.value = value; + this.initialValue = value; + this.value = (T) UNINITIALIZED; addToHistogram(this); } @@ -165,6 +169,7 @@ */ @SuppressWarnings("unchecked") protected OptionValue() { + this.initialValue = (T) UNINITIALIZED; this.value = (T) UNINITIALIZED; addToHistogram(this); } @@ -184,6 +189,14 @@ } /** + * Returns the descriptor for this option, if it has been set by + * {@link #setDescriptor(OptionDescriptor)}. + */ + public OptionDescriptor getDescriptor() { + return descriptor; + } + + /** * Gets the name of this option. The name for an option value with a null * {@linkplain #setDescriptor(OptionDescriptor) descriptor} is the value of * {@link Object#toString()}. @@ -198,6 +211,34 @@ } /** + * The initial value specified in source code. The returned value is not affected by calls to + * {@link #setValue(Object)} or registering {@link OverrideScope}s. Therefore, it is also not + * affected by options set on the command line. + */ + public T getInitialValue() { + if (initialValue == UNINITIALIZED) { + initialValue = initialValue(); + } + return initialValue; + } + + /** + * Returns true if the option has the same value that was set in the source code. + */ + public boolean hasInitialValue() { + if (!(this instanceof StableOptionValue)) { + OverrideScope overrideScope = overrideScopes.get(); + if (overrideScope != null) { + T override = overrideScope.getOverride(this); + if (override != null) { + return false; + } + } + } + return value == UNINITIALIZED || Objects.equals(value, getInitialValue()); + } + + /** * Gets the value of this option. */ public T getValue() { @@ -213,10 +254,11 @@ } } } - if (value == UNINITIALIZED) { - value = initialValue(); + if (value != UNINITIALIZED) { + return value; + } else { + return getInitialValue(); } - return value; } /**