< prev index next >

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigAccess.java

Print this page

  1 /*
  2  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  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  */

279      * @throws JVMCIError if the field is not static or not present
280      */
281     public <T> T getFieldValue(String name, Class<T> type) {
282         return getFieldValue0(name, type, null, null, null);
283     }
284 
285     private <T> T getFieldValue0(String name, Class<T> type, T notPresent, String inCppType, String[] outCppType) {
286         VMField entry = getField(name, inCppType, notPresent == null);
287         if (entry == null) {
288             return notPresent;
289         }
290         if (entry.value == null) {
291             throw new JVMCIError(name + " is not a static field ");
292         }
293         if (outCppType != null) {
294             outCppType[0] = entry.type;
295         }
296         return type.cast(convertValue(name, type, entry.value, inCppType));
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             }
314             throw missingEntry("field", name, store.vmFields.keySet());
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.

  1 /*
  2  * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
  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  */

279      * @throws JVMCIError if the field is not static or not present
280      */
281     public <T> T getFieldValue(String name, Class<T> type) {
282         return getFieldValue0(name, type, null, null, null);
283     }
284 
285     private <T> T getFieldValue0(String name, Class<T> type, T notPresent, String inCppType, String[] outCppType) {
286         VMField entry = getField(name, inCppType, notPresent == null);
287         if (entry == null) {
288             return notPresent;
289         }
290         if (entry.value == null) {
291             throw new JVMCIError(name + " is not a static field ");
292         }
293         if (outCppType != null) {
294             outCppType[0] = entry.type;
295         }
296         return type.cast(convertValue(name, type, entry.value, inCppType));
297     }
298 
299     private boolean typeEquals(String t1, String t2) {
300         if (t1.equals("int64_t") && t2.equals("intx")) {
301             return true;
302         }
303         return t1.equals(t2);
304     }
305 
306     /**
307      * Gets a C++ field.
308      *
309      * @param name fully qualified name of the field
310      * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
311      * @param required specifies if the field must be present
312      * @return the field
313      * @throws JVMCIError if the field is not present and {@code required == true}
314      */
315     private VMField getField(String name, String cppType, boolean required) {
316         VMField entry = store.vmFields.get(name);
317         if (entry == null) {
318             if (!required) {
319                 return null;
320             }
321             throw missingEntry("field", name, store.vmFields.keySet());
322         }
323 
324         // Make sure the native type is still the type we expect.
325         if (cppType != null && !typeEquals(cppType, entry.type)) {
326             throw new JVMCIError("expected type " + cppType + " but VM field " + name + " is of type " + entry.type);
327         }
328         return entry;
329     }
330 
331     /**
332      * Gets a VM flag value.
333      *
334      * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"})
335      * @param type the boxed type to which the flag's value will be converted
336      * @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not
337      *         present
338      * @throws JVMCIError if the flag is not present
339      */
340     public <T> T getFlag(String name, Class<T> type) {
341         return getFlag(name, type, null);
342     }
343 
344     /**
345      * Gets a VM flag value.
< prev index next >