--- old/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java 2016-05-12 09:40:47.000000000 +0200 +++ new/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java 2016-05-12 09:40:47.000000000 +0200 @@ -22,7 +22,6 @@ */ 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; @@ -31,15 +30,14 @@ import java.util.HashMap; import java.util.Iterator; +import jdk.internal.misc.Unsafe; 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 @@ -83,7 +81,7 @@ try { f.setLong(this, value); } catch (IllegalAccessException e) { - throw new JVMCIError("index " + index, e); + throw new InternalError("index " + index, e); } } } @@ -110,6 +108,27 @@ } /** + * 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() { @@ -159,13 +178,13 @@ if (!isRequired(osArch, annotation.archs())) { continue; } - throw new JVMCIError(f.getName() + ": expected VM field not found: " + name); + 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 JVMCIError(f.getName() + ": compiler expects type " + type + " but VM field " + name + " is of type " + entry.getTypeString()); + throw new InternalError(f.getName() + ": compiler expects type " + type + " but VM field " + name + " is of type " + entry.getTypeString()); } } @@ -180,14 +199,14 @@ setField(f, entry.getValue()); break; default: - throw new JVMCIError(f.getName() + ": unknown kind: " + annotation.get()); + 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 JVMCIError(f.getName() + ": expected VM type not found: " + name); + throw new InternalError(f.getName() + ": expected VM type not found: " + name); } switch (annotation.get()) { @@ -195,7 +214,7 @@ setField(f, entry.getSize()); break; default: - throw new JVMCIError(f.getName() + ": unknown kind: " + annotation.get()); + throw new InternalError(f.getName() + ": unknown kind: " + annotation.get()); } } else if (f.isAnnotationPresent(HotSpotVMConstant.class)) { HotSpotVMConstant annotation = f.getAnnotation(HotSpotVMConstant.class); @@ -205,7 +224,7 @@ if (!isRequired(osArch, annotation.archs())) { continue; } - throw new JVMCIError(f.getName() + ": expected VM constant not found: " + name); + throw new InternalError(f.getName() + ": expected VM constant not found: " + name); } setField(f, entry.getValue()); } else if (f.isAnnotationPresent(HotSpotVMAddress.class)) { @@ -216,7 +235,7 @@ if (!isRequired(osName, annotation.os())) { continue; } - throw new JVMCIError(f.getName() + ": expected VM address not found: " + name); + throw new InternalError(f.getName() + ": expected VM address not found: " + name); } setField(f, entry.getValue()); } else if (f.isAnnotationPresent(HotSpotVMFlag.class)) { @@ -227,7 +246,7 @@ if (annotation.optional() || !isRequired(osArch, annotation.archs())) { continue; } - throw new JVMCIError(f.getName() + ": expected VM flag not found: " + name); + throw new InternalError(f.getName() + ": expected VM flag not found: " + name); } setField(f, entry.getValue()); @@ -257,13 +276,13 @@ } else if (value instanceof Long) { field.setBoolean(this, ((long) value) != 0); } else { - throw new JVMCIError(value.getClass().getSimpleName()); + throw new InternalError(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()); + throw new InternalError(value.getClass().getSimpleName()); } } else if (fieldType == int.class) { if (value instanceof Integer) { @@ -271,15 +290,15 @@ } else if (value instanceof Long) { field.setInt(this, (int) (long) value); } else { - throw new JVMCIError(value.getClass().getSimpleName()); + throw new InternalError(value.getClass().getSimpleName()); } } else if (fieldType == long.class) { field.setLong(this, (long) value); } else { - throw new JVMCIError(field.toString()); + throw new InternalError(field.toString()); } } catch (IllegalAccessException e) { - throw new JVMCIError("%s: %s", field, e); + throw new InternalError(String.format("%s: %s", field, e)); } } @@ -303,7 +322,7 @@ if (osName.startsWith("Windows")) { osName = "windows"; } else { - throw new JVMCIError("Unexpected OS name: " + osName); + throw new InternalError("Unexpected OS name: " + osName); } } return osName; @@ -450,7 +469,7 @@ if (type.endsWith("*")) { return UNSAFE.getAddress(getAddress()); } - throw new JVMCIError(type); + throw new InternalError(type); } } @@ -827,7 +846,7 @@ case "ccstrlist": return readCString(UNSAFE, getAddr()); default: - throw new JVMCIError(getType()); + throw new InternalError(getType()); } }