annotate jvmci/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionValue.java @ 21798:395ac43a8578

moved JVMCI sources from graal/ to jvmci/ directory
author Doug Simon <doug.simon@oracle.com>
date Tue, 09 Jun 2015 00:22:49 +0200
parents graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionValue.java@47bebae7454f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 18935
diff changeset
23 package com.oracle.jvmci.options;
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
25 import java.io.*;
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
26 import java.util.*;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
27 import java.util.Map.Entry;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
28
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 /**
9919
af909f4b80a9 options are grouped per top level class/interface when accessed via the service mechanism
Doug Simon <doug.simon@oracle.com>
parents: 9914
diff changeset
30 * An option value.
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 */
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 public class OptionValue<T> {
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 /**
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
34 * Temporarily changes the value for an option. The {@linkplain OptionValue#getValue() value} of
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
35 * {@code option} is set to {@code value} until {@link OverrideScope#close()} is called on the
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
36 * object returned by this method.
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
37 * <p>
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
38 * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
39 * used:
14763
a6c1c3eb20c4 transition to JDK8
Doug Simon <doug.simon@oracle.com>
parents: 14017
diff changeset
40 *
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
41 * <pre>
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
42 * try (OverrideScope s = OptionValue.override(myOption, myValue) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
43 * // code that depends on myOption == myValue
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
44 * }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
45 * </pre>
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
46 */
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
47 public static OverrideScope override(OptionValue<?> option, Object value) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
48 OverrideScope current = getOverrideScope();
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
49 if (current == null) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
50 if (!value.equals(option.getValue())) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
51 return new SingleOverrideScope(option, value);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
52 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
53 Map<OptionValue<?>, Object> overrides = Collections.emptyMap();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
54 return new MultipleOverridesScope(current, overrides);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
55 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
56 return new MultipleOverridesScope(current, option, value);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
57 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
58
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
59 /**
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
60 * Temporarily changes the values for a set of options. The {@linkplain OptionValue#getValue()
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
61 * value} of each {@code option} in {@code overrides} is set to the corresponding {@code value}
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
62 * in {@code overrides} until {@link OverrideScope#close()} is called on the object returned by
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
63 * this method.
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
64 * <p>
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
65 * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
66 * used:
14763
a6c1c3eb20c4 transition to JDK8
Doug Simon <doug.simon@oracle.com>
parents: 14017
diff changeset
67 *
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
68 * <pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14763
diff changeset
69 * Map&lt;OptionValue, Object&gt; overrides = new HashMap&lt;&gt;();
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
70 * overrides.put(myOption1, myValue1);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
71 * overrides.put(myOption2, myValue2);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
72 * try (OverrideScope s = OptionValue.override(overrides) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
73 * // code that depends on myOption == myValue
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
74 * }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
75 * </pre>
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
76 */
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
77 public static OverrideScope override(Map<OptionValue<?>, Object> overrides) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
78 OverrideScope current = getOverrideScope();
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
79 if (current == null && overrides.size() == 1) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
80 Entry<OptionValue<?>, Object> single = overrides.entrySet().iterator().next();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
81 OptionValue<?> option = single.getKey();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
82 Object overrideValue = single.getValue();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
83 if (!overrideValue.equals(option.getValue())) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
84 return new SingleOverrideScope(option, overrideValue);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
85 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
86 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
87 return new MultipleOverridesScope(current, overrides);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
88 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
89
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
90 /**
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
91 * Temporarily changes the values for a set of options. The {@linkplain OptionValue#getValue()
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
92 * value} of each {@code option} in {@code overrides} is set to the corresponding {@code value}
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
93 * in {@code overrides} until {@link OverrideScope#close()} is called on the object returned by
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
94 * this method.
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
95 * <p>
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
96 * Since the returned object is {@link AutoCloseable} the try-with-resource construct can be
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
97 * used:
14763
a6c1c3eb20c4 transition to JDK8
Doug Simon <doug.simon@oracle.com>
parents: 14017
diff changeset
98 *
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
99 * <pre>
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
100 * try (OverrideScope s = OptionValue.override(myOption1, myValue1, myOption2, myValue2) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
101 * // code that depends on myOption == myValue
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
102 * }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
103 * </pre>
14763
a6c1c3eb20c4 transition to JDK8
Doug Simon <doug.simon@oracle.com>
parents: 14017
diff changeset
104 *
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
105 * @param overrides overrides in the form {@code [option1, override1, option2, override2, ...]}
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
106 */
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
107 public static OverrideScope override(Object... overrides) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
108 OverrideScope current = getOverrideScope();
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
109 if (current == null && overrides.length == 2) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
110 OptionValue<?> option = (OptionValue<?>) overrides[0];
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
111 Object overrideValue = overrides[1];
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
112 if (!overrideValue.equals(option.getValue())) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
113 return new SingleOverrideScope(option, overrideValue);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
114 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
115 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
116 Map<OptionValue<?>, Object> map = Collections.emptyMap();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
117 for (int i = 0; i < overrides.length; i += 2) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
118 OptionValue<?> option = (OptionValue<?>) overrides[i];
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
119 Object overrideValue = overrides[i + 1];
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
120 if (!overrideValue.equals(option.getValue())) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
121 if (map.isEmpty()) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
122 map = new HashMap<>();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
123 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
124 map.put(option, overrideValue);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
125 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
126 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
127 return new MultipleOverridesScope(current, map);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
128 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
129
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
130 private static final ThreadLocal<OverrideScope> overrideScopeTL = new ThreadLocal<>();
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
131
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
132 protected static OverrideScope getOverrideScope() {
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
133 return overrideScopeTL.get();
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
134 }
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
135
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
136 protected static void setOverrideScope(OverrideScope overrideScope) {
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
137 overrideScopeTL.set(overrideScope);
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
138 }
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
139
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
140 private T defaultValue;
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
141
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
142 /**
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 * The raw option value.
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 */
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
145 protected T value;
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146
12671
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
147 private OptionDescriptor descriptor;
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
148
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
149 private long reads;
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
150 private OptionValue<?> next;
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 14906
diff changeset
151 private static OptionValue<?> head;
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
152
21558
d563baeca9df changed uses of Graal terminology to JVMCI (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
153 private static final boolean ShowReadsHistogram = Boolean.getBoolean("jvmci.showOptionValueReadsHistogram");
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
154
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
155 private static void addToHistogram(OptionValue<?> option) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
156 if (ShowReadsHistogram) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
157 synchronized (OptionValue.class) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
158 option.next = head;
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
159 head = option;
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
160 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
161 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
162 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
163
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
164 @SuppressWarnings("unchecked")
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents: 9912
diff changeset
165 public OptionValue(T value) {
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
166 this.defaultValue = value;
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
167 this.value = (T) DEFAULT;
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
168 addToHistogram(this);
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
169 }
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
170
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
171 private static final Object DEFAULT = "DEFAULT";
9863
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
172 private static final Object UNINITIALIZED = "UNINITIALIZED";
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
173
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
174 /**
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
175 * Creates an uninitialized option value for a subclass that initializes itself
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
176 * {@link #defaultValue() lazily}.
9863
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
177 */
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
178 @SuppressWarnings("unchecked")
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents: 9912
diff changeset
179 protected OptionValue() {
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
180 this.defaultValue = (T) UNINITIALIZED;
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
181 this.value = (T) DEFAULT;
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
182 addToHistogram(this);
9863
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
183 }
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
184
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
185 /**
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
186 * Lazy initialization of default value.
9863
b2141bc6e98e option values are either initialized upon creation or they must provide a lazily initialized value
Doug Simon <doug.simon@oracle.com>
parents: 9849
diff changeset
187 */
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
188 protected T defaultValue() {
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
189 throw new InternalError("Option without a default value value must override defaultValue()");
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190 }
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
192 /**
12671
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
193 * Sets the descriptor for this option.
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
194 */
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
195 public void setDescriptor(OptionDescriptor descriptor) {
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
196 this.descriptor = descriptor;
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
197 }
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
198
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
199 /**
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
200 * Returns the descriptor for this option, if it has been set by
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
201 * {@link #setDescriptor(OptionDescriptor)}.
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
202 */
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
203 public OptionDescriptor getDescriptor() {
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
204 return descriptor;
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
205 }
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
206
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
207 /**
12671
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
208 * Gets the name of this option. The name for an option value with a null
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
209 * {@linkplain #setDescriptor(OptionDescriptor) descriptor} is the value of
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
210 * {@link Object#toString()}.
12671
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
211 */
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
212 public String getName() {
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
213 return descriptor == null ? super.toString() : (descriptor.getDeclaringClass().getName() + "." + descriptor.getName());
12671
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
214 }
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
215
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
216 @Override
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
217 public String toString() {
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
218 return getName() + "=" + getValue();
12671
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
219 }
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
220
582b3d24c6ad record an OptionDescriptor in an OptionValue so that it can be queried for a name
Doug Simon <doug.simon@oracle.com>
parents: 9919
diff changeset
221 /**
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
222 * The initial value specified in source code. The returned value is not affected by calls to
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
223 * {@link #setValue(Object)} or registering {@link OverrideScope}s. Therefore, it is also not
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
224 * affected by options set on the command line.
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
225 */
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
226 public T getDefaultValue() {
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
227 if (defaultValue == UNINITIALIZED) {
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
228 defaultValue = defaultValue();
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
229 }
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
230 return defaultValue;
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
231 }
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
232
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
233 /**
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
234 * Returns true if the option has the same value that was set in the source code.
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
235 */
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
236 public boolean hasDefaultValue() {
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
237 getValue(); // ensure initialized
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
238 return value == DEFAULT || Objects.equals(value, getDefaultValue());
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
239 }
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
240
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
241 /**
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
242 * Gets the value of this option.
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
243 */
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents: 9912
diff changeset
244 public T getValue() {
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
245 if (ShowReadsHistogram) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
246 reads++;
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
247 }
12674
ecd519b39f10 don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents: 12672
diff changeset
248 if (!(this instanceof StableOptionValue)) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
249 OverrideScope overrideScope = getOverrideScope();
12674
ecd519b39f10 don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents: 12672
diff changeset
250 if (overrideScope != null) {
ecd519b39f10 don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents: 12672
diff changeset
251 T override = overrideScope.getOverride(this);
ecd519b39f10 don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents: 12672
diff changeset
252 if (override != null) {
ecd519b39f10 don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents: 12672
diff changeset
253 return override;
ecd519b39f10 don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents: 12672
diff changeset
254 }
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
255 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
256 }
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
257 if (value != DEFAULT) {
18683
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
258 return value;
823f499a247c Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16871
diff changeset
259 } else {
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
260 return getDefaultValue();
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
261 }
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
262 }
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
263
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
264 /**
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
265 * Gets the values of this option including overridden values.
14763
a6c1c3eb20c4 transition to JDK8
Doug Simon <doug.simon@oracle.com>
parents: 14017
diff changeset
266 *
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
267 * @param c the collection to which the values are added. If null, one is allocated.
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
268 * @return the collection to which the values were added in order from most overridden to
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
269 * current value
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
270 */
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
271 @SuppressWarnings("unchecked")
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
272 public Collection<T> getValues(Collection<T> c) {
14763
a6c1c3eb20c4 transition to JDK8
Doug Simon <doug.simon@oracle.com>
parents: 14017
diff changeset
273 Collection<T> values = c == null ? new ArrayList<>() : c;
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
274 if (!(this instanceof StableOptionValue)) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
275 OverrideScope overrideScope = getOverrideScope();
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
276 if (overrideScope != null) {
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
277 overrideScope.getOverrides(this, (Collection<Object>) values);
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
278 }
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
279 }
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
280 if (value != DEFAULT) {
18685
18d0f83cd290 Add code missing in initial value handling for options
Christian Wimmer <christian.wimmer@oracle.com>
parents: 18683
diff changeset
281 values.add(value);
18d0f83cd290 Add code missing in initial value handling for options
Christian Wimmer <christian.wimmer@oracle.com>
parents: 18683
diff changeset
282 } else {
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18935
diff changeset
283 values.add(getDefaultValue());
18685
18d0f83cd290 Add code missing in initial value handling for options
Christian Wimmer <christian.wimmer@oracle.com>
parents: 18683
diff changeset
284 }
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
285 return values;
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
286 }
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
287
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
288 /**
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents: 9912
diff changeset
289 * Sets the value of this option.
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
290 */
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
291 @SuppressWarnings("unchecked")
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents: 9912
diff changeset
292 public void setValue(Object v) {
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
293 this.value = (T) v;
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
294 }
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
295
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
296 /**
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
297 * An object whose {@link #close()} method reverts the option value overriding initiated by
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
298 * {@link OptionValue#override(OptionValue, Object)} or {@link OptionValue#override(Map)}.
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
299 */
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
300 public abstract static class OverrideScope implements AutoCloseable {
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
301
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
302 private Map<DerivedOptionValue<?>, Object> derivedCache = null;
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
303
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
304 public <T> T getDerived(DerivedOptionValue<T> key) {
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
305 if (derivedCache == null) {
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
306 derivedCache = new HashMap<>();
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
307 }
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
308 @SuppressWarnings("unchecked")
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
309 T ret = (T) derivedCache.get(key);
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
310 if (ret == null) {
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
311 ret = key.createValue();
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
312 derivedCache.put(key, ret);
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
313 }
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
314 return ret;
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
315 }
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents: 15040
diff changeset
316
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 14906
diff changeset
317 abstract void addToInherited(Map<OptionValue<?>, Object> inherited);
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
318
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
319 abstract <T> T getOverride(OptionValue<T> option);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
320
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
321 abstract void getOverrides(OptionValue<?> option, Collection<Object> c);
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
322
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
323 public abstract void close();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
324 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
325
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
326 static class SingleOverrideScope extends OverrideScope {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
327
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
328 private final OptionValue<?> option;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
329 private final Object value;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
330
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
331 public SingleOverrideScope(OptionValue<?> option, Object value) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
332 if (option instanceof StableOptionValue) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
333 throw new IllegalArgumentException("Cannot override stable option " + option);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
334 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
335 this.option = option;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
336 this.value = value;
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
337 setOverrideScope(this);
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
338 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
339
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
340 @Override
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 14906
diff changeset
341 void addToInherited(Map<OptionValue<?>, Object> inherited) {
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
342 inherited.put(option, value);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
343 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
344
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
345 @SuppressWarnings("unchecked")
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
346 @Override
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
347 <T> T getOverride(OptionValue<T> key) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
348 if (key == this.option) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
349 return (T) value;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
350 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
351 return null;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
352 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
353
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
354 @Override
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
355 void getOverrides(OptionValue<?> key, Collection<Object> c) {
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
356 if (key == this.option) {
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
357 c.add(value);
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
358 }
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
359 }
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
360
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
361 @Override
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
362 public void close() {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
363 setOverrideScope(null);
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
364 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
365 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
366
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
367 static class MultipleOverridesScope extends OverrideScope {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
368 final OverrideScope parent;
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 14906
diff changeset
369 final Map<OptionValue<?>, Object> overrides;
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
370
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
371 public MultipleOverridesScope(OverrideScope parent, OptionValue<?> option, Object value) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
372 this.parent = parent;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
373 this.overrides = new HashMap<>();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
374 if (parent != null) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
375 parent.addToInherited(overrides);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
376 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
377 if (option instanceof StableOptionValue) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
378 throw new IllegalArgumentException("Cannot override stable option " + option);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
379 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
380 if (!value.equals(option.getValue())) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
381 this.overrides.put(option, value);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
382 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
383 if (!overrides.isEmpty()) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
384 setOverrideScope(this);
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
385 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
386 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
387
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
388 MultipleOverridesScope(OverrideScope parent, Map<OptionValue<?>, Object> overrides) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
389 this.parent = parent;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
390 if (overrides.isEmpty() && parent == null) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
391 this.overrides = Collections.emptyMap();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
392 return;
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
393 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
394 this.overrides = new HashMap<>();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
395 if (parent != null) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
396 parent.addToInherited(this.overrides);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
397 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
398 for (Map.Entry<OptionValue<?>, Object> e : overrides.entrySet()) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
399 OptionValue<?> option = e.getKey();
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
400 if (option instanceof StableOptionValue) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
401 throw new IllegalArgumentException("Cannot override stable option " + option);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
402 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
403 if (!e.getValue().equals(option.getValue())) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
404 this.overrides.put(option, e.getValue());
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
405 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
406 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
407 if (!this.overrides.isEmpty()) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
408 setOverrideScope(this);
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
409 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
410 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
411
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
412 @Override
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 14906
diff changeset
413 void addToInherited(Map<OptionValue<?>, Object> inherited) {
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
414 if (parent != null) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
415 parent.addToInherited(inherited);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
416 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
417 inherited.putAll(overrides);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
418 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
419
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
420 @SuppressWarnings("unchecked")
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
421 @Override
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
422 <T> T getOverride(OptionValue<T> option) {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
423 return (T) overrides.get(option);
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
424 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
425
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
426 @Override
12735
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
427 void getOverrides(OptionValue<?> option, Collection<Object> c) {
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
428 Object v = overrides.get(option);
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
429 if (v != null) {
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
430 c.add(v);
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
431 }
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
432 if (parent != null) {
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
433 parent.getOverrides(option, c);
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
434 }
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
435 }
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
436
bb85b81258a0 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents: 12682
diff changeset
437 @Override
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
438 public void close() {
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
439 if (!overrides.isEmpty()) {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18685
diff changeset
440 setOverrideScope(parent);
12672
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
441 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
442 }
38bf986ce231 added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 12671
diff changeset
443 }
12682
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
444
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
445 static {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
446 if (ShowReadsHistogram) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
447 Runtime.getRuntime().addShutdownHook(new Thread() {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
448 @Override
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
449 public void run() {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
450 ArrayList<OptionValue<?>> options = new ArrayList<>();
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
451 for (OptionValue<?> option = head; option != null; option = option.next) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
452 options.add(option);
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
453 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
454 Collections.sort(options, new Comparator<OptionValue<?>>() {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
455
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
456 public int compare(OptionValue<?> o1, OptionValue<?> o2) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
457 if (o1.reads < o2.reads) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
458 return -1;
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
459 } else if (o1.reads > o2.reads) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
460 return 1;
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
461 } else {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
462 return o1.getName().compareTo(o2.getName());
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
463 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
464 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
465 });
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
466 PrintStream out = System.out;
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
467 out.println("=== OptionValue reads histogram ===");
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
468 for (OptionValue<?> option : options) {
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
469 out.println(option.reads + "\t" + option);
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
470 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
471 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
472 });
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
473 }
5dbfb4d5eaba added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read
Doug Simon <doug.simon@oracle.com>
parents: 12674
diff changeset
474 }
9849
e876c2a6954f extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
475 }