109 /**
110 * Gets the offset of a non-static C++ field.
111 *
112 * @param name fully qualified name of the field
113 * @param type the boxed type to which the offset value will be converted (must be
114 * {@link Integer} or {@link Long})
115 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
116 * @param notPresent if non-null and the field is not present then this value is returned
117 * @return the offset in bytes of the requested field
118 * @throws JVMCIError if the field is static or not present and {@code notPresent} is null
119 */
120 public <T> T getFieldOffset(String name, Class<T> type, String cppType, T notPresent) {
121 assert type == Integer.class || type == Long.class;
122 VMField entry = getField(name, cppType, notPresent == null);
123 if (entry == null) {
124 return notPresent;
125 }
126 if (entry.address != 0) {
127 throw new JVMCIError("cannot get offset of static field " + name);
128 }
129 return entry == null ? notPresent : type.cast(convertValue(name, type, entry.offset, cppType));
130 }
131
132 /**
133 * Gets the offset of a non-static C++ field.
134 *
135 * @param name fully qualified name of the field
136 * @param type the boxed type to which the offset value will be converted (must be
137 * {@link Integer} or {@link Long})
138 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
139 * @return the offset in bytes of the requested field
140 * @throws JVMCIError if the field is static or not present
141 */
142 public <T> T getFieldOffset(String name, Class<T> type, String cppType) {
143 return getFieldOffset(name, type, cppType, null);
144 }
145
146 /**
147 * Gets the offset of a non-static C++ field.
148 *
149 * @param name fully qualified name of the field
156 return getFieldOffset(name, type, null, null);
157 }
158
159 /**
160 * Gets the address of a static C++ field.
161 *
162 * @param name fully qualified name of the field
163 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
164 * @param notPresent if non-null and the field is not present then this value is returned
165 * @return the address of the requested field
166 * @throws JVMCIError if the field is not static or not present and {@code notPresent} is null
167 */
168 public long getFieldAddress(String name, String cppType, Long notPresent) {
169 VMField entry = getField(name, cppType, notPresent == null);
170 if (entry == null) {
171 return notPresent;
172 }
173 if (entry.address == 0) {
174 throw new JVMCIError(name + " is not a static field");
175 }
176 return entry == null ? notPresent : entry.address;
177 }
178
179 /**
180 * Gets the address of a static C++ field.
181 *
182 * @param name fully qualified name of the field
183 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
184 * @return the address of the requested field
185 * @throws JVMCIError if the field is not static or not present
186 */
187 public long getFieldAddress(String name, String cppType) {
188 return getFieldAddress(name, cppType, null);
189 }
190
191 /**
192 * Gets the value of a static C++ field.
193 *
194 * @param name fully qualified name of the field
195 * @param type the boxed type to which the constant value will be converted
196 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
296 private static <T> Object convertValue(String name, Class<T> toType, Object value, String cppType) throws JVMCIError {
297 if (toType == Boolean.class) {
298 if (value instanceof String) {
299 return Boolean.valueOf((String) value);
300 } else if (value instanceof Boolean) {
301 return value;
302 } else if (value instanceof Long) {
303 return ((long) value) != 0;
304 }
305 } else if (toType == Byte.class) {
306 if (value instanceof Long) {
307 return (byte) (long) value;
308 }
309 } else if (toType == Integer.class) {
310 if (value instanceof Integer) {
311 return value;
312 } else if (value instanceof Long) {
313 return (int) (long) value;
314 }
315 } else if (toType == Long.class) {
316 return (long) value;
317 }
318
319 throw new JVMCIError("cannot convert " + name + " of type " + value.getClass().getSimpleName() + (cppType == null ? "" : " [" + cppType + "]") + " to " + toType.getSimpleName());
320 }
321
322 private final HotSpotVMConfigStore store;
323
324 public HotSpotVMConfigAccess(HotSpotVMConfigStore store) {
325 this.store = store;
326 }
327 }
|
109 /**
110 * Gets the offset of a non-static C++ field.
111 *
112 * @param name fully qualified name of the field
113 * @param type the boxed type to which the offset value will be converted (must be
114 * {@link Integer} or {@link Long})
115 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
116 * @param notPresent if non-null and the field is not present then this value is returned
117 * @return the offset in bytes of the requested field
118 * @throws JVMCIError if the field is static or not present and {@code notPresent} is null
119 */
120 public <T> T getFieldOffset(String name, Class<T> type, String cppType, T notPresent) {
121 assert type == Integer.class || type == Long.class;
122 VMField entry = getField(name, cppType, notPresent == null);
123 if (entry == null) {
124 return notPresent;
125 }
126 if (entry.address != 0) {
127 throw new JVMCIError("cannot get offset of static field " + name);
128 }
129 return type.cast(convertValue(name, type, entry.offset, cppType));
130 }
131
132 /**
133 * Gets the offset of a non-static C++ field.
134 *
135 * @param name fully qualified name of the field
136 * @param type the boxed type to which the offset value will be converted (must be
137 * {@link Integer} or {@link Long})
138 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
139 * @return the offset in bytes of the requested field
140 * @throws JVMCIError if the field is static or not present
141 */
142 public <T> T getFieldOffset(String name, Class<T> type, String cppType) {
143 return getFieldOffset(name, type, cppType, null);
144 }
145
146 /**
147 * Gets the offset of a non-static C++ field.
148 *
149 * @param name fully qualified name of the field
156 return getFieldOffset(name, type, null, null);
157 }
158
159 /**
160 * Gets the address of a static C++ field.
161 *
162 * @param name fully qualified name of the field
163 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
164 * @param notPresent if non-null and the field is not present then this value is returned
165 * @return the address of the requested field
166 * @throws JVMCIError if the field is not static or not present and {@code notPresent} is null
167 */
168 public long getFieldAddress(String name, String cppType, Long notPresent) {
169 VMField entry = getField(name, cppType, notPresent == null);
170 if (entry == null) {
171 return notPresent;
172 }
173 if (entry.address == 0) {
174 throw new JVMCIError(name + " is not a static field");
175 }
176 return entry.address;
177 }
178
179 /**
180 * Gets the address of a static C++ field.
181 *
182 * @param name fully qualified name of the field
183 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
184 * @return the address of the requested field
185 * @throws JVMCIError if the field is not static or not present
186 */
187 public long getFieldAddress(String name, String cppType) {
188 return getFieldAddress(name, cppType, null);
189 }
190
191 /**
192 * Gets the value of a static C++ field.
193 *
194 * @param name fully qualified name of the field
195 * @param type the boxed type to which the constant value will be converted
196 * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
296 private static <T> Object convertValue(String name, Class<T> toType, Object value, String cppType) throws JVMCIError {
297 if (toType == Boolean.class) {
298 if (value instanceof String) {
299 return Boolean.valueOf((String) value);
300 } else if (value instanceof Boolean) {
301 return value;
302 } else if (value instanceof Long) {
303 return ((long) value) != 0;
304 }
305 } else if (toType == Byte.class) {
306 if (value instanceof Long) {
307 return (byte) (long) value;
308 }
309 } else if (toType == Integer.class) {
310 if (value instanceof Integer) {
311 return value;
312 } else if (value instanceof Long) {
313 return (int) (long) value;
314 }
315 } else if (toType == Long.class) {
316 return value;
317 }
318
319 throw new JVMCIError("cannot convert " + name + " of type " + value.getClass().getSimpleName() + (cppType == null ? "" : " [" + cppType + "]") + " to " + toType.getSimpleName());
320 }
321
322 private final HotSpotVMConfigStore store;
323
324 public HotSpotVMConfigAccess(HotSpotVMConfigStore store) {
325 this.store = store;
326 }
327 }
|