Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java @ 15040:288c23143d47
Fix most raw type references.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 09 Apr 2014 19:08:53 +0200 |
parents | f3a5036cc13c |
children | e728b9d4905c |
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 */ |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.options; |
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 |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 /** |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
35 * 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
|
36 * {@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
|
37 * 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
|
38 * <p> |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
39 * 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
|
40 * used: |
14763 | 41 * |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
42 * <pre> |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
43 * 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
|
44 * // 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
|
45 * } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
46 * </pre> |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
47 */ |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
48 public static OverrideScope override(OptionValue<?> option, Object value) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
49 OverrideScope current = overrideScopes.get(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
50 if (current == null) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
51 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
|
52 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
|
53 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
54 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
|
55 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
|
56 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
57 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
|
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 /** |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
61 * 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
|
62 * 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
|
63 * 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
|
64 * this method. |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
65 * <p> |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
66 * 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
|
67 * used: |
14763 | 68 * |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
69 * <pre> |
14906 | 70 * Map<OptionValue, Object> overrides = new HashMap<>(); |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
71 * overrides.put(myOption1, myValue1); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
72 * overrides.put(myOption2, myValue2); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
73 * 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
|
74 * // 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
|
75 * } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
76 * </pre> |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
77 */ |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
78 public static OverrideScope override(Map<OptionValue<?>, Object> overrides) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
79 OverrideScope current = overrideScopes.get(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
80 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
|
81 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
|
82 OptionValue<?> option = single.getKey(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
83 Object overrideValue = single.getValue(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
84 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
|
85 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
|
86 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
87 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
88 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
|
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 /** |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
92 * 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
|
93 * 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
|
94 * 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
|
95 * this method. |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
96 * <p> |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
97 * 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
|
98 * used: |
14763 | 99 * |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
100 * <pre> |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
101 * 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
|
102 * // 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
|
103 * } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
104 * </pre> |
14763 | 105 * |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
106 * @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
|
107 */ |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
108 public static OverrideScope override(Object... overrides) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
109 OverrideScope current = overrideScopes.get(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
110 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
|
111 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
|
112 Object overrideValue = overrides[1]; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
113 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
|
114 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
|
115 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
116 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 if (map.isEmpty()) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
123 map = new HashMap<>(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
124 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
125 map.put(option, overrideValue); |
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 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
128 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
|
129 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
130 |
14017
e34f406850e5
ThreadLocals should be final
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
12735
diff
changeset
|
131 private static final ThreadLocal<OverrideScope> overrideScopes = new ThreadLocal<>(); |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
132 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
133 /** |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
134 * The raw option value. |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
135 */ |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
136 protected T value; |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
137 |
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
|
138 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
|
139 |
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
|
140 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
|
141 private OptionValue<?> next; |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
142 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
|
143 |
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
|
144 private static final boolean ShowReadsHistogram = Boolean.getBoolean("graal.showOptionValueReadsHistogram"); |
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
|
145 |
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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 } |
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 } |
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
|
153 } |
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 |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
155 public OptionValue(T value) { |
9912
fbad7372eccd
added support for stable options
Doug Simon <doug.simon@oracle.com>
parents:
9863
diff
changeset
|
156 this.value = value; |
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
|
157 addToHistogram(this); |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
158 } |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
159 |
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
|
160 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
|
161 |
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
|
162 /** |
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
|
163 * Creates an uninitialized option value for a subclass that initializes itself |
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
|
164 * {@link #initialValue() lazily}. |
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
|
165 */ |
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
|
166 @SuppressWarnings("unchecked") |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
167 protected OptionValue() { |
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
|
168 this.value = (T) UNINITIALIZED; |
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
|
169 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
|
170 } |
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
|
171 |
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 /** |
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 * Lazy initialization of value. |
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 */ |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
175 protected T initialValue() { |
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
|
176 throw new InternalError("Uninitialized option value must override initialValue()"); |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
177 } |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
178 |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
179 /** |
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
|
180 * 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
|
181 */ |
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
|
182 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
|
183 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
|
184 } |
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
|
185 |
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
|
186 /** |
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
|
187 * 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
|
188 * {@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
|
189 * {@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
|
190 */ |
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
|
191 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
|
192 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
|
193 } |
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 @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
|
196 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
|
197 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
|
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 |
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
|
200 /** |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
201 * Gets the value of this option. |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
202 */ |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 } |
12674
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
207 if (!(this instanceof StableOptionValue)) { |
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
208 OverrideScope overrideScope = overrideScopes.get(); |
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
209 if (overrideScope != null) { |
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
210 T override = overrideScope.getOverride(this); |
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
211 if (override != null) { |
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
212 return override; |
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
213 } |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
214 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
215 } |
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
|
216 if (value == UNINITIALIZED) { |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
217 value = initialValue(); |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
218 } |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
219 return value; |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
220 } |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
221 |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
222 /** |
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
|
223 * Gets the values of this option including overridden values. |
14763 | 224 * |
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
|
225 * @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
|
226 * @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
|
227 * 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
|
228 */ |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
229 @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
|
230 public Collection<T> getValues(Collection<T> c) { |
14763 | 231 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
|
232 if (!(this instanceof StableOptionValue)) { |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
233 OverrideScope overrideScope = overrideScopes.get(); |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
234 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
|
235 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
|
236 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
237 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
238 values.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
|
239 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
|
240 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
241 |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
242 /** |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
243 * Sets the value of this option. |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
244 */ |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
245 @SuppressWarnings("unchecked") |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
246 public void setValue(Object v) { |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
247 this.value = (T) v; |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
248 } |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
249 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
250 /** |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
251 * 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
|
252 * {@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
|
253 */ |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
254 public abstract static class OverrideScope implements AutoCloseable { |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
255 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
|
256 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
257 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
|
258 |
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
|
259 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
|
260 |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
261 public abstract void close(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
262 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
263 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
264 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
|
265 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
266 private final OptionValue<?> option; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
267 private final Object value; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
268 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
269 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
|
270 if (option instanceof StableOptionValue) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
271 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
|
272 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
273 this.option = option; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
274 this.value = value; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
275 overrideScopes.set(this); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
276 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
277 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
278 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
279 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
|
280 inherited.put(option, value); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
281 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
282 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
283 @SuppressWarnings("unchecked") |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
284 @Override |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
285 <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
|
286 if (key == this.option) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
287 return (T) value; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
288 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
289 return null; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
290 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
291 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
292 @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
|
293 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
|
294 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
|
295 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
|
296 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
297 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
298 |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
299 @Override |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
300 public void close() { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
301 overrideScopes.set(null); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
302 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
303 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
304 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
305 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
|
306 final OverrideScope parent; |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
307 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
|
308 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
309 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
|
310 this.parent = parent; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
311 this.overrides = new HashMap<>(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
312 if (parent != null) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
313 parent.addToInherited(overrides); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
314 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
315 if (option instanceof StableOptionValue) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
316 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
|
317 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
318 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
|
319 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
|
320 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
321 if (!overrides.isEmpty()) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
322 overrideScopes.set(this); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
323 } |
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 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
|
327 this.parent = parent; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
328 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
|
329 this.overrides = Collections.emptyMap(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
330 return; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
331 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
332 this.overrides = new HashMap<>(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
333 if (parent != null) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
334 parent.addToInherited(this.overrides); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
335 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
336 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
|
337 OptionValue<?> option = e.getKey(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
338 if (option instanceof StableOptionValue) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
339 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
|
340 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
341 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
|
342 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
|
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 if (!this.overrides.isEmpty()) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
346 overrideScopes.set(this); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
347 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
348 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
349 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
350 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
351 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
|
352 if (parent != null) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
353 parent.addToInherited(inherited); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
354 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
355 inherited.putAll(overrides); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
356 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
357 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
358 @SuppressWarnings("unchecked") |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
359 @Override |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
360 <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
|
361 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
|
362 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
363 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
364 @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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
370 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
|
371 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
|
372 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
373 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
374 |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
375 @Override |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
376 public void close() { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
377 if (!overrides.isEmpty()) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
378 overrideScopes.set(parent); |
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 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
381 } |
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
|
382 |
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
|
383 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
|
384 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
|
385 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
|
386 @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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 } |
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
|
392 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
|
393 |
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
|
394 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
|
395 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
|
396 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
|
397 } 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
|
398 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
|
399 } 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
|
400 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
|
401 } |
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
|
402 } |
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
|
403 }); |
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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 } |
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
|
409 } |
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
|
410 }); |
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
|
411 } |
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
|
412 } |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
413 } |