Mercurial > hg > truffle
annotate graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java @ 18683:823f499a247c
Store initial value (the value set in source code) of an option
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Mon, 15 Dec 2014 11:32:59 -0800 |
parents | e728b9d4905c |
children | 18d0f83cd290 |
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 |
16871
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
131 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 |
18683
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
133 private T initialValue; |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
134 |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
135 /** |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
136 * The raw option value. |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
137 */ |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
138 protected T value; |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
139 |
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
|
140 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
|
141 |
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
|
142 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
|
143 private OptionValue<?> next; |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
144 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
|
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 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
|
147 |
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 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
|
149 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
|
150 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
|
151 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
|
152 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
|
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 } |
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 } |
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 |
18683
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
157 @SuppressWarnings("unchecked") |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
158 public OptionValue(T value) { |
18683
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
159 this.initialValue = value; |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
160 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
|
161 addToHistogram(this); |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
162 } |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
163 |
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
|
164 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
|
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 /** |
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
|
167 * 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
|
168 * {@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
|
169 */ |
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 @SuppressWarnings("unchecked") |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
171 protected OptionValue() { |
18683
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
172 this.initialValue = (T) UNINITIALIZED; |
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
|
173 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
|
174 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
|
175 } |
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 |
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 * 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
|
179 */ |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
180 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
|
181 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
|
182 } |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
183 |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
184 /** |
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
|
185 * 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
|
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 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
|
188 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
|
189 } |
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 /** |
18683
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
192 * 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
|
193 * {@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
|
194 */ |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
195 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
|
196 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
|
197 } |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
198 |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
199 /** |
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
|
200 * 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
|
201 * {@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
|
202 * {@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
|
203 */ |
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
|
204 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
|
205 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
|
206 } |
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
|
207 |
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 @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
|
209 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
|
210 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
|
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 |
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
|
213 /** |
18683
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
214 * 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
|
215 * {@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
|
216 * 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
|
217 */ |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
218 public T getInitialValue() { |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
219 if (initialValue == UNINITIALIZED) { |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
220 initialValue = initialValue(); |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
221 } |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
222 return initialValue; |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
223 } |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
224 |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
225 /** |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
226 * 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
|
227 */ |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
228 public boolean hasInitialValue() { |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
229 if (!(this instanceof StableOptionValue)) { |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
230 OverrideScope overrideScope = overrideScopes.get(); |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
231 if (overrideScope != null) { |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
232 T override = overrideScope.getOverride(this); |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
233 if (override != null) { |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
234 return false; |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
235 } |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
236 } |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
237 } |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
238 return value == UNINITIALIZED || Objects.equals(value, getInitialValue()); |
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)) { |
ecd519b39f10
don't try and get override for StableOptionValues
Doug Simon <doug.simon@oracle.com>
parents:
12672
diff
changeset
|
249 OverrideScope overrideScope = overrideScopes.get(); |
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 } |
18683
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
257 if (value != UNINITIALIZED) { |
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 { |
823f499a247c
Store initial value (the value set in source code) of an option
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16871
diff
changeset
|
260 return getInitialValue(); |
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 | 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 | 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)) { |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
275 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
|
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 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
280 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
|
281 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
|
282 } |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
283 |
bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
Doug Simon <doug.simon@oracle.com>
parents:
12682
diff
changeset
|
284 /** |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
285 * Sets the value of this option. |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
286 */ |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
287 @SuppressWarnings("unchecked") |
9914
84890660eefb
cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
9912
diff
changeset
|
288 public void setValue(Object v) { |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
289 this.value = (T) v; |
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
290 } |
12672
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 /** |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
293 * 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
|
294 * {@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
|
295 */ |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
296 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
|
297 |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
298 private Map<DerivedOptionValue<?>, Object> derivedCache = null; |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
299 |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
300 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
|
301 if (derivedCache == null) { |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
302 derivedCache = new HashMap<>(); |
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 @SuppressWarnings("unchecked") |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
305 T ret = (T) derivedCache.get(key); |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
306 if (ret == null) { |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
307 ret = key.createValue(); |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
308 derivedCache.put(key, ret); |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
309 } |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
310 return ret; |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
311 } |
e728b9d4905c
Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
15040
diff
changeset
|
312 |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
313 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
|
314 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
315 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
|
316 |
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
|
317 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
|
318 |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
319 public abstract void close(); |
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 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
322 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
|
323 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
324 private final OptionValue<?> option; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
325 private final Object value; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
326 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
327 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
|
328 if (option instanceof StableOptionValue) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
329 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
|
330 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
331 this.option = option; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
332 this.value = value; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
333 overrideScopes.set(this); |
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 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
336 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
337 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
|
338 inherited.put(option, value); |
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 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
341 @SuppressWarnings("unchecked") |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
342 @Override |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
343 <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
|
344 if (key == this.option) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
345 return (T) value; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
346 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
347 return null; |
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 |
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
|
351 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
|
352 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
|
353 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
|
354 } |
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 } |
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 |
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 @Override |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
358 public void close() { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
359 overrideScopes.set(null); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
360 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
361 } |
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 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
|
364 final OverrideScope parent; |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
365 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
|
366 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
367 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
|
368 this.parent = parent; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
369 this.overrides = new HashMap<>(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
370 if (parent != null) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
371 parent.addToInherited(overrides); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
372 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
373 if (option instanceof StableOptionValue) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
374 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
|
375 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
376 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
|
377 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
|
378 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
379 if (!overrides.isEmpty()) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
380 overrideScopes.set(this); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
381 } |
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 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
384 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
|
385 this.parent = parent; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
386 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
|
387 this.overrides = Collections.emptyMap(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
388 return; |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
389 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
390 this.overrides = new HashMap<>(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
391 if (parent != null) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
392 parent.addToInherited(this.overrides); |
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 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
|
395 OptionValue<?> option = e.getKey(); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
396 if (option instanceof StableOptionValue) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
397 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
|
398 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
399 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
|
400 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
|
401 } |
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 (!this.overrides.isEmpty()) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
404 overrideScopes.set(this); |
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 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
408 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
409 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
|
410 if (parent != null) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
411 parent.addToInherited(inherited); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
412 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
413 inherited.putAll(overrides); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
414 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
415 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
416 @SuppressWarnings("unchecked") |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
417 @Override |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
418 <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
|
419 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
|
420 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
421 |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
422 @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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 } |
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 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
|
429 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
|
430 } |
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 |
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 @Override |
12672
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
434 public void close() { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
435 if (!overrides.isEmpty()) { |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
436 overrideScopes.set(parent); |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
437 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
438 } |
38bf986ce231
added support for scoped overriding of OptionValues (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
12671
diff
changeset
|
439 } |
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
|
440 |
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
|
441 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
|
442 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
|
443 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
|
444 @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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 } |
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 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
|
451 |
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 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
|
453 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
|
454 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
|
455 } 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
|
456 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
|
457 } 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
|
458 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
|
459 } |
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 } |
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 }); |
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 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
|
463 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
|
464 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
|
465 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
|
466 } |
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 } |
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 }); |
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 } |
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 } |
9849
e876c2a6954f
extensible option system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
471 } |