author | kvn |
Wed, 01 May 2019 12:31:29 -0700 | |
changeset 54669 | ad45b3802d4e |
parent 52381 | 7f90bc64b0fc |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package jdk.vm.ci.hotspot; |
|
24 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
25 |
import java.util.Set; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
26 |
import java.util.stream.Collectors; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
27 |
|
43972 | 28 |
import jdk.vm.ci.common.JVMCIError; |
29 |
||
30 |
/** |
|
31 |
* Access to VM configuration data. |
|
32 |
*/ |
|
33 |
public class HotSpotVMConfigAccess { |
|
34 |
||
35 |
/** |
|
36 |
* Gets the available configuration data. |
|
37 |
*/ |
|
38 |
public HotSpotVMConfigStore getStore() { |
|
39 |
return store; |
|
40 |
} |
|
41 |
||
42 |
/** |
|
43 |
* Gets the address of a C++ symbol. |
|
44 |
* |
|
45 |
* @param name name of C++ symbol |
|
46 |
* @param notPresent if non-null and the symbol is not present then this value is returned |
|
47 |
* @return the address of the symbol |
|
48 |
* @throws JVMCIError if the symbol is not present and {@code notPresent == null} |
|
49 |
*/ |
|
50 |
public long getAddress(String name, Long notPresent) { |
|
51 |
Long entry = store.vmAddresses.get(name); |
|
52 |
if (entry == null) { |
|
53 |
if (notPresent != null) { |
|
54 |
return notPresent; |
|
55 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
56 |
throw missingEntry("address", name, store.vmFlags.keySet()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
57 |
|
43972 | 58 |
} |
59 |
return entry; |
|
60 |
} |
|
61 |
||
62 |
/** |
|
63 |
* Gets the address of a C++ symbol. |
|
64 |
* |
|
65 |
* @param name name of C++ symbol |
|
66 |
* @return the address of the symbol |
|
67 |
* @throws JVMCIError if the symbol is not present |
|
68 |
*/ |
|
69 |
public long getAddress(String name) { |
|
70 |
return getAddress(name, null); |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Gets the value of a C++ constant. |
|
75 |
* |
|
76 |
* @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"}) |
|
77 |
* @param type the boxed type to which the constant value will be converted |
|
78 |
* @param notPresent if non-null and the constant is not present then this value is returned |
|
79 |
* @return the constant value converted to {@code type} |
|
80 |
* @throws JVMCIError if the constant is not present and {@code notPresent == null} |
|
81 |
*/ |
|
82 |
public <T> T getConstant(String name, Class<T> type, T notPresent) { |
|
83 |
Long c = store.vmConstants.get(name); |
|
84 |
if (c == null) { |
|
85 |
if (notPresent != null) { |
|
86 |
return notPresent; |
|
87 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
88 |
throw missingEntry("constant", name, store.vmConstants.keySet()); |
43972 | 89 |
} |
90 |
return type.cast(convertValue(name, type, c, null)); |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Gets the value of a C++ constant. |
|
95 |
* |
|
96 |
* @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"}) |
|
97 |
* @param type the boxed type to which the constant value will be converted |
|
98 |
* @return the constant value converted to {@code type} |
|
99 |
* @throws JVMCIError if the constant is not present |
|
100 |
*/ |
|
101 |
public <T> T getConstant(String name, Class<T> type) { |
|
102 |
return getConstant(name, type, null); |
|
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Gets the offset of a non-static C++ field. |
|
107 |
* |
|
108 |
* @param name fully qualified name of the field |
|
109 |
* @param type the boxed type to which the offset value will be converted (must be |
|
110 |
* {@link Integer} or {@link Long}) |
|
111 |
* @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) |
|
112 |
* @param notPresent if non-null and the field is not present then this value is returned |
|
113 |
* @return the offset in bytes of the requested field |
|
114 |
* @throws JVMCIError if the field is static or not present and {@code notPresent} is null |
|
115 |
*/ |
|
116 |
public <T> T getFieldOffset(String name, Class<T> type, String cppType, T notPresent) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
117 |
return getFieldOffset0(name, type, notPresent, cppType, null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
118 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
119 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
120 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
121 |
* Gets the offset of a non-static C++ field. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
122 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
123 |
* @param name fully qualified name of the field |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
124 |
* @param type the boxed type to which the offset value will be converted (must be |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
125 |
* {@link Integer} or {@link Long}) |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
126 |
* @param notPresent if non-null and the field is not present then this value is returned |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
127 |
* @param outCppType if non-null, the C++ type of the field (e.g., {@code "HeapWord*"}) is |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
128 |
* returned in element 0 of this array |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
129 |
* @return the offset in bytes of the requested field |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
130 |
* @throws JVMCIError if the field is static or not present and {@code notPresent} is null |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
131 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
132 |
public <T> T getFieldOffset(String name, Class<T> type, T notPresent, String[] outCppType) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
133 |
return getFieldOffset0(name, type, notPresent, null, outCppType); |
43972 | 134 |
} |
135 |
||
136 |
/** |
|
137 |
* Gets the offset of a non-static C++ field. |
|
138 |
* |
|
139 |
* @param name fully qualified name of the field |
|
140 |
* @param type the boxed type to which the offset value will be converted (must be |
|
141 |
* {@link Integer} or {@link Long}) |
|
142 |
* @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) |
|
143 |
* @return the offset in bytes of the requested field |
|
144 |
* @throws JVMCIError if the field is static or not present |
|
145 |
*/ |
|
146 |
public <T> T getFieldOffset(String name, Class<T> type, String cppType) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
147 |
return getFieldOffset0(name, type, null, cppType, null); |
43972 | 148 |
} |
149 |
||
150 |
/** |
|
151 |
* Gets the offset of a non-static C++ field. |
|
152 |
* |
|
153 |
* @param name fully qualified name of the field |
|
154 |
* @param type the boxed type to which the offset value will be converted (must be |
|
155 |
* {@link Integer} or {@link Long}) |
|
156 |
* @return the offset in bytes of the requested field |
|
157 |
* @throws JVMCIError if the field is static or not present |
|
158 |
*/ |
|
159 |
public <T> T getFieldOffset(String name, Class<T> type) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
160 |
return getFieldOffset0(name, type, null, null, null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
161 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
162 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
163 |
private <T> T getFieldOffset0(String name, Class<T> type, T notPresent, String inCppType, String[] outCppType) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
164 |
assert type == Integer.class || type == Long.class; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
165 |
VMField entry = getField(name, inCppType, notPresent == null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
166 |
if (entry == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
167 |
return notPresent; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
168 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
169 |
if (entry.address != 0) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
170 |
throw new JVMCIError("cannot get offset of static field " + name); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
171 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
172 |
if (outCppType != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
173 |
outCppType[0] = entry.type; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
174 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
175 |
return type.cast(convertValue(name, type, entry.offset, inCppType)); |
43972 | 176 |
} |
177 |
||
178 |
/** |
|
179 |
* Gets the address of a static C++ field. |
|
180 |
* |
|
181 |
* @param name fully qualified name of the field |
|
182 |
* @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) |
|
183 |
* @param notPresent if non-null and the field is not present then this value is returned |
|
184 |
* @return the address of the requested field |
|
185 |
* @throws JVMCIError if the field is not static or not present and {@code notPresent} is null |
|
186 |
*/ |
|
187 |
public long getFieldAddress(String name, String cppType, Long notPresent) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
188 |
return getFieldAddress0(name, notPresent, cppType, null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
189 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
190 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
191 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
192 |
* Gets the address of a static C++ field. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
193 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
194 |
* @param name fully qualified name of the field |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
195 |
* @param notPresent if non-null and the field is not present then this value is returned |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
196 |
* @param outCppType if non-null, the C++ type of the field (e.g., {@code "HeapWord*"}) is |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
197 |
* returned in element 0 of this array |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
198 |
* @return the address of the requested field |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
199 |
* @throws JVMCIError if the field is not static or not present and {@code notPresent} is null |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
200 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
201 |
public long getFieldAddress(String name, Long notPresent, String[] outCppType) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
202 |
return getFieldAddress0(name, notPresent, null, outCppType); |
43972 | 203 |
} |
204 |
||
205 |
/** |
|
206 |
* Gets the address of a static C++ field. |
|
207 |
* |
|
208 |
* @param name fully qualified name of the field |
|
209 |
* @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) |
|
210 |
* @return the address of the requested field |
|
211 |
* @throws JVMCIError if the field is not static or not present |
|
212 |
*/ |
|
213 |
public long getFieldAddress(String name, String cppType) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
214 |
return getFieldAddress0(name, null, cppType, null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
215 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
216 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
217 |
private long getFieldAddress0(String name, Long notPresent, String inCppType, String[] outCppType) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
218 |
VMField entry = getField(name, inCppType, notPresent == null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
219 |
if (entry == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
220 |
return notPresent; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
221 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
222 |
if (entry.address == 0) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
223 |
throw new JVMCIError(name + " is not a static field"); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
224 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
225 |
if (outCppType != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
226 |
outCppType[0] = entry.type; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
227 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
228 |
return entry.address; |
43972 | 229 |
} |
230 |
||
231 |
/** |
|
232 |
* Gets the value of a static C++ field. |
|
233 |
* |
|
234 |
* @param name fully qualified name of the field |
|
235 |
* @param type the boxed type to which the constant value will be converted |
|
236 |
* @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) |
|
237 |
* @param notPresent if non-null and the field is not present then this value is returned |
|
238 |
* @return the value of the requested field |
|
239 |
* @throws JVMCIError if the field is not static or not present and {@code notPresent} is null |
|
240 |
*/ |
|
241 |
public <T> T getFieldValue(String name, Class<T> type, String cppType, T notPresent) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
242 |
return getFieldValue0(name, type, notPresent, cppType, null); |
43972 | 243 |
} |
244 |
||
245 |
/** |
|
246 |
* Gets the value of a static C++ field. |
|
247 |
* |
|
248 |
* @param name fully qualified name of the field |
|
249 |
* @param type the boxed type to which the constant value will be converted |
|
250 |
* @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) |
|
251 |
* @return the value of the requested field |
|
252 |
* @throws JVMCIError if the field is not static or not present |
|
253 |
*/ |
|
254 |
public <T> T getFieldValue(String name, Class<T> type, String cppType) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
255 |
return getFieldValue0(name, type, null, cppType, null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
256 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
257 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
258 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
259 |
* Gets the value of a static C++ field. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
260 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
261 |
* @param name fully qualified name of the field |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
262 |
* @param type the boxed type to which the constant value will be converted |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
263 |
* @param notPresent if non-null and the field is not present then this value is returned |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
264 |
* @param outCppType if non-null, the C++ type of the field (e.g., {@code "HeapWord*"}) is |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
265 |
* returned in element 0 of this array |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
266 |
* @return the value of the requested field |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
267 |
* @throws JVMCIError if the field is not static or not present and {@code notPresent} is null |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
268 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
269 |
public <T> T getFieldValue(String name, Class<T> type, T notPresent, String[] outCppType) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
270 |
return getFieldValue0(name, type, notPresent, null, outCppType); |
43972 | 271 |
} |
272 |
||
273 |
/** |
|
274 |
* Gets the value of a static C++ field. |
|
275 |
* |
|
276 |
* @param name fully qualified name of the field |
|
277 |
* @param type the boxed type to which the constant value will be converted |
|
278 |
* @return the value of the requested field |
|
279 |
* @throws JVMCIError if the field is not static or not present |
|
280 |
*/ |
|
281 |
public <T> T getFieldValue(String name, Class<T> type) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
282 |
return getFieldValue0(name, type, null, null, null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
283 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
284 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
285 |
private <T> T getFieldValue0(String name, Class<T> type, T notPresent, String inCppType, String[] outCppType) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
286 |
VMField entry = getField(name, inCppType, notPresent == null); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
287 |
if (entry == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
288 |
return notPresent; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
289 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
290 |
if (entry.value == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
291 |
throw new JVMCIError(name + " is not a static field "); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
292 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
293 |
if (outCppType != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
294 |
outCppType[0] = entry.type; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
295 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
296 |
return type.cast(convertValue(name, type, entry.value, inCppType)); |
43972 | 297 |
} |
298 |
||
299 |
/** |
|
300 |
* Gets a C++ field. |
|
301 |
* |
|
302 |
* @param name fully qualified name of the field |
|
303 |
* @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"}) |
|
304 |
* @param required specifies if the field must be present |
|
305 |
* @return the field |
|
306 |
* @throws JVMCIError if the field is not present and {@code required == true} |
|
307 |
*/ |
|
308 |
private VMField getField(String name, String cppType, boolean required) { |
|
309 |
VMField entry = store.vmFields.get(name); |
|
310 |
if (entry == null) { |
|
311 |
if (!required) { |
|
312 |
return null; |
|
313 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
314 |
throw missingEntry("field", name, store.vmFields.keySet()); |
43972 | 315 |
} |
316 |
||
317 |
// Make sure the native type is still the type we expect. |
|
318 |
if (cppType != null && !cppType.equals(entry.type)) { |
|
319 |
throw new JVMCIError("expected type " + cppType + " but VM field " + name + " is of type " + entry.type); |
|
320 |
} |
|
321 |
return entry; |
|
322 |
} |
|
323 |
||
324 |
/** |
|
325 |
* Gets a VM flag value. |
|
326 |
* |
|
327 |
* @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"}) |
|
328 |
* @param type the boxed type to which the flag's value will be converted |
|
329 |
* @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not |
|
330 |
* present |
|
331 |
* @throws JVMCIError if the flag is not present |
|
332 |
*/ |
|
333 |
public <T> T getFlag(String name, Class<T> type) { |
|
334 |
return getFlag(name, type, null); |
|
335 |
} |
|
336 |
||
337 |
/** |
|
338 |
* Gets a VM flag value. |
|
339 |
* |
|
340 |
* @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"}) |
|
341 |
* @param type the boxed type to which the flag's value will be converted |
|
342 |
* @param notPresent if non-null and the flag is not present then this value is returned |
|
343 |
* @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not |
|
344 |
* present |
|
345 |
* @throws JVMCIError if the flag is not present and {@code notPresent == null} |
|
346 |
*/ |
|
347 |
public <T> T getFlag(String name, Class<T> type, T notPresent) { |
|
348 |
VMFlag entry = store.vmFlags.get(name); |
|
349 |
Object value; |
|
350 |
String cppType; |
|
351 |
if (entry == null) { |
|
352 |
// Fall back to VM call |
|
353 |
value = store.compilerToVm.getFlagValue(name); |
|
354 |
if (value == store.compilerToVm) { |
|
355 |
if (notPresent != null) { |
|
356 |
return notPresent; |
|
357 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
358 |
throw missingEntry("flag", name, store.vmFlags.keySet()); |
43972 | 359 |
} else { |
360 |
cppType = null; |
|
361 |
} |
|
362 |
} else { |
|
363 |
value = entry.value; |
|
364 |
cppType = entry.type; |
|
365 |
} |
|
366 |
return type.cast(convertValue(name, type, value, cppType)); |
|
367 |
} |
|
368 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
369 |
private JVMCIError missingEntry(String category, String name, Set<String> keys) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
370 |
throw new JVMCIError("expected VM %s not found in %s: %s%nAvailable values:%n %s", category, store, name, |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
371 |
keys.stream().sorted().collect(Collectors.joining(System.lineSeparator() + " "))); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
372 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52381
diff
changeset
|
373 |
|
43972 | 374 |
private static <T> Object convertValue(String name, Class<T> toType, Object value, String cppType) throws JVMCIError { |
375 |
if (toType == Boolean.class) { |
|
376 |
if (value instanceof String) { |
|
377 |
return Boolean.valueOf((String) value); |
|
378 |
} else if (value instanceof Boolean) { |
|
379 |
return value; |
|
380 |
} else if (value instanceof Long) { |
|
381 |
return ((long) value) != 0; |
|
382 |
} |
|
383 |
} else if (toType == Byte.class) { |
|
384 |
if (value instanceof Long) { |
|
385 |
return (byte) (long) value; |
|
386 |
} |
|
387 |
} else if (toType == Integer.class) { |
|
388 |
if (value instanceof Integer) { |
|
389 |
return value; |
|
390 |
} else if (value instanceof Long) { |
|
391 |
return (int) (long) value; |
|
392 |
} |
|
393 |
} else if (toType == String.class) { |
|
394 |
if (value == null || value instanceof String) { |
|
395 |
return value; |
|
396 |
} |
|
397 |
} else if (toType == Long.class) { |
|
398 |
return value; |
|
399 |
} |
|
400 |
||
401 |
throw new JVMCIError("cannot convert " + name + " of type " + value.getClass().getSimpleName() + (cppType == null ? "" : " [" + cppType + "]") + " to " + toType.getSimpleName()); |
|
402 |
} |
|
403 |
||
404 |
private final HotSpotVMConfigStore store; |
|
405 |
||
406 |
public HotSpotVMConfigAccess(HotSpotVMConfigStore store) { |
|
407 |
this.store = store; |
|
408 |
} |
|
409 |
} |