< prev index next >

src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java

Print this page

        

*** 20,47 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.vm.ci.hotspot; - import static jdk.vm.ci.common.UnsafeUtil.readCString; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Iterator; import jdk.internal.vm.annotation.Stable; - import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspotvmconfig.HotSpotVMAddress; import jdk.vm.ci.hotspotvmconfig.HotSpotVMConstant; import jdk.vm.ci.hotspotvmconfig.HotSpotVMData; import jdk.vm.ci.hotspotvmconfig.HotSpotVMField; import jdk.vm.ci.hotspotvmconfig.HotSpotVMFlag; import jdk.vm.ci.hotspotvmconfig.HotSpotVMType; - import jdk.internal.misc.Unsafe; //JaCoCo Exclude /** * Used to access native configuration details. --- 20,45 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.vm.ci.hotspot; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Iterator; + import jdk.internal.misc.Unsafe; import jdk.internal.vm.annotation.Stable; import jdk.vm.ci.hotspotvmconfig.HotSpotVMAddress; import jdk.vm.ci.hotspotvmconfig.HotSpotVMConstant; import jdk.vm.ci.hotspotvmconfig.HotSpotVMData; import jdk.vm.ci.hotspotvmconfig.HotSpotVMField; import jdk.vm.ci.hotspotvmconfig.HotSpotVMFlag; import jdk.vm.ci.hotspotvmconfig.HotSpotVMType; //JaCoCo Exclude /** * Used to access native configuration details.
*** 81,91 **** final int index = annotation.index(); final long value = UNSAFE.getAddress(gHotSpotVMData + Unsafe.ADDRESS_SIZE * index); try { f.setLong(this, value); } catch (IllegalAccessException e) { ! throw new JVMCIError("index " + index, e); } } } // Quick sanity check. --- 79,89 ---- final int index = annotation.index(); final long value = UNSAFE.getAddress(gHotSpotVMData + Unsafe.ADDRESS_SIZE * index); try { f.setLong(this, value); } catch (IllegalAccessException e) { ! throw new InternalError("index " + index, e); } } } // Quick sanity check.
*** 108,117 **** --- 106,136 ---- public String toString() { return getClass().getSimpleName(); } /** + * Reads a {@code '\0'} terminated C string from native memory and converts it to a + * {@link String}. + * + * @return a Java string + */ + static String readCString(Unsafe unsafe, long address) { + if (address == 0) { + return null; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0;; i++) { + char c = (char) unsafe.getByte(address + i); + if (c == 0) { + break; + } + sb.append(c); + } + return sb.toString(); + } + + /** * Initialize fields by reading their values from vmStructs. */ private void initialize() { // Fill the VM fields hash map. HashMap<String, VMFields.Field> vmFields = new HashMap<>();
*** 157,173 **** VMFields.Field entry = vmFields.get(name); if (entry == null) { if (!isRequired(osArch, annotation.archs())) { continue; } ! throw new JVMCIError(f.getName() + ": expected VM field not found: " + name); } // Make sure the native type is still the type we expect. if (!type.isEmpty()) { if (!type.equals(entry.getTypeString())) { ! throw new JVMCIError(f.getName() + ": compiler expects type " + type + " but VM field " + name + " is of type " + entry.getTypeString()); } } switch (annotation.get()) { case OFFSET: --- 176,192 ---- VMFields.Field entry = vmFields.get(name); if (entry == null) { if (!isRequired(osArch, annotation.archs())) { continue; } ! throw new InternalError(f.getName() + ": expected VM field not found: " + name); } // Make sure the native type is still the type we expect. if (!type.isEmpty()) { if (!type.equals(entry.getTypeString())) { ! throw new InternalError(f.getName() + ": compiler expects type " + type + " but VM field " + name + " is of type " + entry.getTypeString()); } } switch (annotation.get()) { case OFFSET:
*** 178,235 **** break; case VALUE: setField(f, entry.getValue()); break; default: ! throw new JVMCIError(f.getName() + ": unknown kind: " + annotation.get()); } } else if (f.isAnnotationPresent(HotSpotVMType.class)) { HotSpotVMType annotation = f.getAnnotation(HotSpotVMType.class); String name = annotation.name(); VMTypes.Type entry = vmTypes.get(name); if (entry == null) { ! throw new JVMCIError(f.getName() + ": expected VM type not found: " + name); } switch (annotation.get()) { case SIZE: setField(f, entry.getSize()); break; default: ! throw new JVMCIError(f.getName() + ": unknown kind: " + annotation.get()); } } else if (f.isAnnotationPresent(HotSpotVMConstant.class)) { HotSpotVMConstant annotation = f.getAnnotation(HotSpotVMConstant.class); String name = annotation.name(); AbstractConstant entry = vmConstants.get(name); if (entry == null) { if (!isRequired(osArch, annotation.archs())) { continue; } ! throw new JVMCIError(f.getName() + ": expected VM constant not found: " + name); } setField(f, entry.getValue()); } else if (f.isAnnotationPresent(HotSpotVMAddress.class)) { HotSpotVMAddress annotation = f.getAnnotation(HotSpotVMAddress.class); String name = annotation.name(); VMAddresses.Address entry = vmAddresses.get(name); if (entry == null) { if (!isRequired(osName, annotation.os())) { continue; } ! throw new JVMCIError(f.getName() + ": expected VM address not found: " + name); } setField(f, entry.getValue()); } else if (f.isAnnotationPresent(HotSpotVMFlag.class)) { HotSpotVMFlag annotation = f.getAnnotation(HotSpotVMFlag.class); String name = annotation.name(); Flags.Flag entry = flags.get(name); if (entry == null) { if (annotation.optional() || !isRequired(osArch, annotation.archs())) { continue; } ! throw new JVMCIError(f.getName() + ": expected VM flag not found: " + name); } setField(f, entry.getValue()); } } --- 197,254 ---- break; case VALUE: setField(f, entry.getValue()); break; default: ! throw new InternalError(f.getName() + ": unknown kind: " + annotation.get()); } } else if (f.isAnnotationPresent(HotSpotVMType.class)) { HotSpotVMType annotation = f.getAnnotation(HotSpotVMType.class); String name = annotation.name(); VMTypes.Type entry = vmTypes.get(name); if (entry == null) { ! throw new InternalError(f.getName() + ": expected VM type not found: " + name); } switch (annotation.get()) { case SIZE: setField(f, entry.getSize()); break; default: ! throw new InternalError(f.getName() + ": unknown kind: " + annotation.get()); } } else if (f.isAnnotationPresent(HotSpotVMConstant.class)) { HotSpotVMConstant annotation = f.getAnnotation(HotSpotVMConstant.class); String name = annotation.name(); AbstractConstant entry = vmConstants.get(name); if (entry == null) { if (!isRequired(osArch, annotation.archs())) { continue; } ! throw new InternalError(f.getName() + ": expected VM constant not found: " + name); } setField(f, entry.getValue()); } else if (f.isAnnotationPresent(HotSpotVMAddress.class)) { HotSpotVMAddress annotation = f.getAnnotation(HotSpotVMAddress.class); String name = annotation.name(); VMAddresses.Address entry = vmAddresses.get(name); if (entry == null) { if (!isRequired(osName, annotation.os())) { continue; } ! throw new InternalError(f.getName() + ": expected VM address not found: " + name); } setField(f, entry.getValue()); } else if (f.isAnnotationPresent(HotSpotVMFlag.class)) { HotSpotVMFlag annotation = f.getAnnotation(HotSpotVMFlag.class); String name = annotation.name(); Flags.Flag entry = flags.get(name); if (entry == null) { if (annotation.optional() || !isRequired(osArch, annotation.archs())) { continue; } ! throw new InternalError(f.getName() + ": expected VM flag not found: " + name); } setField(f, entry.getValue()); } }
*** 255,287 **** } else if (value instanceof Boolean) { field.setBoolean(this, (boolean) value); } else if (value instanceof Long) { field.setBoolean(this, ((long) value) != 0); } else { ! throw new JVMCIError(value.getClass().getSimpleName()); } } else if (fieldType == byte.class) { if (value instanceof Long) { field.setByte(this, (byte) (long) value); } else { ! throw new JVMCIError(value.getClass().getSimpleName()); } } else if (fieldType == int.class) { if (value instanceof Integer) { field.setInt(this, (int) value); } else if (value instanceof Long) { field.setInt(this, (int) (long) value); } else { ! throw new JVMCIError(value.getClass().getSimpleName()); } } else if (fieldType == long.class) { field.setLong(this, (long) value); } else { ! throw new JVMCIError(field.toString()); } } catch (IllegalAccessException e) { ! throw new JVMCIError("%s: %s", field, e); } } /** * Gets the host operating system name. --- 274,306 ---- } else if (value instanceof Boolean) { field.setBoolean(this, (boolean) value); } else if (value instanceof Long) { field.setBoolean(this, ((long) value) != 0); } else { ! throw new InternalError(value.getClass().getSimpleName()); } } else if (fieldType == byte.class) { if (value instanceof Long) { field.setByte(this, (byte) (long) value); } else { ! throw new InternalError(value.getClass().getSimpleName()); } } else if (fieldType == int.class) { if (value instanceof Integer) { field.setInt(this, (int) value); } else if (value instanceof Long) { field.setInt(this, (int) (long) value); } else { ! throw new InternalError(value.getClass().getSimpleName()); } } else if (fieldType == long.class) { field.setLong(this, (long) value); } else { ! throw new InternalError(field.toString()); } } catch (IllegalAccessException e) { ! throw new InternalError(String.format("%s: %s", field, e)); } } /** * Gets the host operating system name.
*** 301,311 **** default: // Of course Windows is different... if (osName.startsWith("Windows")) { osName = "windows"; } else { ! throw new JVMCIError("Unexpected OS name: " + osName); } } return osName; } --- 320,330 ---- default: // Of course Windows is different... if (osName.startsWith("Windows")) { osName = "windows"; } else { ! throw new InternalError("Unexpected OS name: " + osName); } } return osName; }
*** 448,458 **** default: // All foo* types are addresses. if (type.endsWith("*")) { return UNSAFE.getAddress(getAddress()); } ! throw new JVMCIError(type); } } @Override public String toString() { --- 467,477 ---- default: // All foo* types are addresses. if (type.endsWith("*")) { return UNSAFE.getAddress(getAddress()); } ! throw new InternalError(type); } } @Override public String toString() {
*** 825,835 **** return Double.valueOf(UNSAFE.getDouble(getAddr())); case "ccstr": case "ccstrlist": return readCString(UNSAFE, getAddr()); default: ! throw new JVMCIError(getType()); } } @Override public String toString() { --- 844,854 ---- return Double.valueOf(UNSAFE.getDouble(getAddr())); case "ccstr": case "ccstrlist": return readCString(UNSAFE, getAddr()); default: ! throw new InternalError(getType()); } } @Override public String toString() {
< prev index next >