Mercurial > hg > truffle
changeset 18683:823f499a247c
Store initial value (the value set in source code) of an option
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Mon, 15 Dec 2014 11:32:59 -0800 |
parents | 0a109f5d5873 |
children | 137773e5250c |
files | graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java |
diffstat | 1 files changed, 46 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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<OverrideScope> 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; } /**