< prev index next >

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

Print this page




  33      * Gets the available configuration data.
  34      */
  35     public HotSpotVMConfigStore getStore() {
  36         return store;
  37     }
  38 
  39     /**
  40      * Gets the address of a C++ symbol.
  41      *
  42      * @param name name of C++ symbol
  43      * @param notPresent if non-null and the symbol is not present then this value is returned
  44      * @return the address of the symbol
  45      * @throws JVMCIError if the symbol is not present and {@code notPresent == null}
  46      */
  47     public long getAddress(String name, Long notPresent) {
  48         Long entry = store.vmAddresses.get(name);
  49         if (entry == null) {
  50             if (notPresent != null) {
  51                 return notPresent;
  52             }
  53             throw new JVMCIError("expected VM symbol not found: " + name);

  54         }
  55         return entry;
  56     }
  57 
  58     /**
  59      * Gets the address of a C++ symbol.
  60      *
  61      * @param name name of C++ symbol
  62      * @return the address of the symbol
  63      * @throws JVMCIError if the symbol is not present
  64      */
  65     public long getAddress(String name) {
  66         return getAddress(name, null);
  67     }
  68 
  69     /**
  70      * Gets the value of a C++ constant.
  71      *
  72      * @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"})
  73      * @param type the boxed type to which the constant value will be converted
  74      * @param notPresent if non-null and the constant is not present then this value is returned
  75      * @return the constant value converted to {@code type}
  76      * @throws JVMCIError if the constant is not present and {@code notPresent == null}
  77      */
  78     public <T> T getConstant(String name, Class<T> type, T notPresent) {
  79         Long c = store.vmConstants.get(name);
  80         if (c == null) {
  81             if (notPresent != null) {
  82                 return notPresent;
  83             }
  84             throw new JVMCIError("expected VM constant not found: " + name);

  85         }
  86         return type.cast(convertValue(name, type, c, null));
  87     }
  88 
  89     /**
  90      * Gets the value of a C++ constant.
  91      *
  92      * @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"})
  93      * @param type the boxed type to which the constant value will be converted
  94      * @return the constant value converted to {@code type}
  95      * @throws JVMCIError if the constant is not present
  96      */
  97     public <T> T getConstant(String name, Class<T> type) {
  98         return getConstant(name, type, null);
  99     }
 100 
 101     /**
 102      * Gets the offset of a non-static C++ field.
 103      *
 104      * @param name fully qualified name of the field


 224      */
 225     public <T> T getFieldValue(String name, Class<T> type) {
 226         return getFieldValue(name, type, null, null);
 227     }
 228 
 229     /**
 230      * Gets a C++ field.
 231      *
 232      * @param name fully qualified name of the field
 233      * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
 234      * @param required specifies if the field must be present
 235      * @return the field
 236      * @throws JVMCIError if the field is not present and {@code required == true}
 237      */
 238     private VMField getField(String name, String cppType, boolean required) {
 239         VMField entry = store.vmFields.get(name);
 240         if (entry == null) {
 241             if (!required) {
 242                 return null;
 243             }
 244             throw new JVMCIError("expected VM field not found: " + name);

 245         }
 246 
 247         // Make sure the native type is still the type we expect.
 248         if (cppType != null && !cppType.equals(entry.type)) {
 249             throw new JVMCIError("expected type " + cppType + " but VM field " + name + " is of type " + entry.type);
 250         }
 251         return entry;
 252     }
 253 
 254     /**
 255      * Gets a VM flag value.
 256      *
 257      * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"})
 258      * @param type the boxed type to which the flag's value will be converted
 259      * @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not
 260      *         present
 261      * @throws JVMCIError if the flag is not present
 262      */
 263     public <T> T getFlag(String name, Class<T> type) {
 264         return getFlag(name, type, null);


 268      * Gets a VM flag value.
 269      *
 270      * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"})
 271      * @param type the boxed type to which the flag's value will be converted
 272      * @param notPresent if non-null and the flag is not present then this value is returned
 273      * @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not
 274      *         present
 275      * @throws JVMCIError if the flag is not present and {@code notPresent == null}
 276      */
 277     public <T> T getFlag(String name, Class<T> type, T notPresent) {
 278         VMFlag entry = store.vmFlags.get(name);
 279         Object value;
 280         String cppType;
 281         if (entry == null) {
 282             // Fall back to VM call
 283             value = store.compilerToVm.getFlagValue(name);
 284             if (value == store.compilerToVm) {
 285                 if (notPresent != null) {
 286                     return notPresent;
 287                 }
 288                 throw new JVMCIError("expected VM flag not found: " + name);

 289             } else {
 290                 cppType = null;
 291             }
 292         } else {
 293             value = entry.value;
 294             cppType = entry.type;
 295         }
 296         return type.cast(convertValue(name, type, value, cppType));
 297     }
 298 
 299     private static <T> Object convertValue(String name, Class<T> toType, Object value, String cppType) throws JVMCIError {
 300         if (toType == Boolean.class) {
 301             if (value instanceof String) {
 302                 return Boolean.valueOf((String) value);
 303             } else if (value instanceof Boolean) {
 304                 return value;
 305             } else if (value instanceof Long) {
 306                 return ((long) value) != 0;
 307             }
 308         } else if (toType == Byte.class) {




  33      * Gets the available configuration data.
  34      */
  35     public HotSpotVMConfigStore getStore() {
  36         return store;
  37     }
  38 
  39     /**
  40      * Gets the address of a C++ symbol.
  41      *
  42      * @param name name of C++ symbol
  43      * @param notPresent if non-null and the symbol is not present then this value is returned
  44      * @return the address of the symbol
  45      * @throws JVMCIError if the symbol is not present and {@code notPresent == null}
  46      */
  47     public long getAddress(String name, Long notPresent) {
  48         Long entry = store.vmAddresses.get(name);
  49         if (entry == null) {
  50             if (notPresent != null) {
  51                 return notPresent;
  52             }
  53             store.printConfig();
  54             throw new JVMCIError("expected VM symbol not found in " + store + ": " + name);
  55         }
  56         return entry;
  57     }
  58 
  59     /**
  60      * Gets the address of a C++ symbol.
  61      *
  62      * @param name name of C++ symbol
  63      * @return the address of the symbol
  64      * @throws JVMCIError if the symbol is not present
  65      */
  66     public long getAddress(String name) {
  67         return getAddress(name, null);
  68     }
  69 
  70     /**
  71      * Gets the value of a C++ constant.
  72      *
  73      * @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"})
  74      * @param type the boxed type to which the constant value will be converted
  75      * @param notPresent if non-null and the constant is not present then this value is returned
  76      * @return the constant value converted to {@code type}
  77      * @throws JVMCIError if the constant is not present and {@code notPresent == null}
  78      */
  79     public <T> T getConstant(String name, Class<T> type, T notPresent) {
  80         Long c = store.vmConstants.get(name);
  81         if (c == null) {
  82             if (notPresent != null) {
  83                 return notPresent;
  84             }
  85             store.printConfig();
  86             throw new JVMCIError("expected VM constant not found in " + store + ": " + name);
  87         }
  88         return type.cast(convertValue(name, type, c, null));
  89     }
  90 
  91     /**
  92      * Gets the value of a C++ constant.
  93      *
  94      * @param name name of the constant (e.g., {@code "frame::arg_reg_save_area_bytes"})
  95      * @param type the boxed type to which the constant value will be converted
  96      * @return the constant value converted to {@code type}
  97      * @throws JVMCIError if the constant is not present
  98      */
  99     public <T> T getConstant(String name, Class<T> type) {
 100         return getConstant(name, type, null);
 101     }
 102 
 103     /**
 104      * Gets the offset of a non-static C++ field.
 105      *
 106      * @param name fully qualified name of the field


 226      */
 227     public <T> T getFieldValue(String name, Class<T> type) {
 228         return getFieldValue(name, type, null, null);
 229     }
 230 
 231     /**
 232      * Gets a C++ field.
 233      *
 234      * @param name fully qualified name of the field
 235      * @param cppType if non-null, the expected C++ type of the field (e.g., {@code "HeapWord*"})
 236      * @param required specifies if the field must be present
 237      * @return the field
 238      * @throws JVMCIError if the field is not present and {@code required == true}
 239      */
 240     private VMField getField(String name, String cppType, boolean required) {
 241         VMField entry = store.vmFields.get(name);
 242         if (entry == null) {
 243             if (!required) {
 244                 return null;
 245             }
 246             store.printConfig();
 247             throw new JVMCIError("expected VM field not found in " + store + ": " + name);
 248         }
 249 
 250         // Make sure the native type is still the type we expect.
 251         if (cppType != null && !cppType.equals(entry.type)) {
 252             throw new JVMCIError("expected type " + cppType + " but VM field " + name + " is of type " + entry.type);
 253         }
 254         return entry;
 255     }
 256 
 257     /**
 258      * Gets a VM flag value.
 259      *
 260      * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"})
 261      * @param type the boxed type to which the flag's value will be converted
 262      * @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not
 263      *         present
 264      * @throws JVMCIError if the flag is not present
 265      */
 266     public <T> T getFlag(String name, Class<T> type) {
 267         return getFlag(name, type, null);


 271      * Gets a VM flag value.
 272      *
 273      * @param name name of the flag (e.g., {@code "CompileTheWorldStartAt"})
 274      * @param type the boxed type to which the flag's value will be converted
 275      * @param notPresent if non-null and the flag is not present then this value is returned
 276      * @return the flag's value converted to {@code type} or {@code notPresent} if the flag is not
 277      *         present
 278      * @throws JVMCIError if the flag is not present and {@code notPresent == null}
 279      */
 280     public <T> T getFlag(String name, Class<T> type, T notPresent) {
 281         VMFlag entry = store.vmFlags.get(name);
 282         Object value;
 283         String cppType;
 284         if (entry == null) {
 285             // Fall back to VM call
 286             value = store.compilerToVm.getFlagValue(name);
 287             if (value == store.compilerToVm) {
 288                 if (notPresent != null) {
 289                     return notPresent;
 290                 }
 291                 store.printConfig();
 292                 throw new JVMCIError("expected VM flag not found in " + store + ": " + name);
 293             } else {
 294                 cppType = null;
 295             }
 296         } else {
 297             value = entry.value;
 298             cppType = entry.type;
 299         }
 300         return type.cast(convertValue(name, type, value, cppType));
 301     }
 302 
 303     private static <T> Object convertValue(String name, Class<T> toType, Object value, String cppType) throws JVMCIError {
 304         if (toType == Boolean.class) {
 305             if (value instanceof String) {
 306                 return Boolean.valueOf((String) value);
 307             } else if (value instanceof Boolean) {
 308                 return value;
 309             } else if (value instanceof Long) {
 310                 return ((long) value) != 0;
 311             }
 312         } else if (toType == Byte.class) {


< prev index next >