Mercurial > hg > graal-jvmci-8
changeset 23392:b3a816d3b844
Backed out changeset: a920338dd4d4
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/jdk.vm.ci.common/src/jdk/vm/ci/common/JVMCIError.java Thu May 12 11:06:49 2016 +0200 @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.vm.ci.common; + +import java.util.ArrayList; +import java.util.Locale; + +/** + * Indicates a condition in JVMCI related code that should never occur during normal operation. + */ +public class JVMCIError extends Error { + + private static final long serialVersionUID = 531632331813456233L; + private final ArrayList<String> context = new ArrayList<>(); + + public static RuntimeException unimplemented() { + throw new JVMCIError("unimplemented"); + } + + public static RuntimeException unimplemented(String msg) { + throw new JVMCIError("unimplemented: %s", msg); + } + + public static RuntimeException shouldNotReachHere() { + throw new JVMCIError("should not reach here"); + } + + public static RuntimeException shouldNotReachHere(String msg) { + throw new JVMCIError("should not reach here: %s", msg); + } + + public static RuntimeException shouldNotReachHere(Throwable cause) { + throw new JVMCIError(cause); + } + + /** + * Checks a given condition and throws a {@link JVMCIError} if it is false. Guarantees are + * stronger than assertions in that they are always checked. Error messages for guarantee + * violations should clearly indicate the nature of the problem as well as a suggested solution + * if possible. + * + * @param condition the condition to check + * @param msg the message that will be associated with the error, in + * {@link String#format(String, Object...)} syntax + * @param args arguments to the format string + */ + public static void guarantee(boolean condition, String msg, Object... args) { + if (!condition) { + throw new JVMCIError("failed guarantee: " + msg, args); + } + } + + /** + * This constructor creates a {@link JVMCIError} with a given message. + * + * @param msg the message that will be associated with the error + */ + public JVMCIError(String msg) { + super(msg); + } + + /** + * This constructor creates a {@link JVMCIError} with a message assembled via + * {@link String#format(String, Object...)}. It always uses the ENGLISH locale in order to + * always generate the same output. + * + * @param msg the message that will be associated with the error, in String.format syntax + * @param args parameters to String.format - parameters that implement {@link Iterable} will be + * expanded into a [x, x, ...] representation. + */ + public JVMCIError(String msg, Object... args) { + super(format(msg, args)); + } + + /** + * This constructor creates a {@link JVMCIError} for a given causing Throwable instance. + * + * @param cause the original exception that contains additional information on this error + */ + public JVMCIError(Throwable cause) { + super(cause); + } + + /** + * This constructor creates a {@link JVMCIError} and adds all the + * {@linkplain #addContext(String) context} of another {@link JVMCIError}. + * + * @param e the original {@link JVMCIError} + */ + public JVMCIError(JVMCIError e) { + super(e); + context.addAll(e.context); + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + str.append(super.toString()); + for (String s : context) { + str.append("\n\tat ").append(s); + } + return str.toString(); + } + + private static String format(String msg, Object... args) { + if (args != null) { + // expand Iterable parameters into a list representation + for (int i = 0; i < args.length; i++) { + if (args[i] instanceof Iterable<?>) { + ArrayList<Object> list = new ArrayList<>(); + for (Object o : (Iterable<?>) args[i]) { + list.add(o); + } + args[i] = list.toString(); + } + } + } + return String.format(Locale.ENGLISH, msg, args); + } + + public JVMCIError addContext(String newContext) { + this.context.add(newContext); + return this; + } + + public JVMCIError addContext(String name, Object obj) { + return addContext(format("%s: %s", name, obj)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jvmci/jdk.vm.ci.common/src/jdk/vm/ci/common/UnsafeUtil.java Thu May 12 11:06:49 2016 +0200 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.vm.ci.common; + +import sun.misc.Unsafe; + +/** + * Utilities for operating on raw memory with {@link Unsafe}. + */ +public class UnsafeUtil { + + /** + * Copies the contents of a {@link String} to a native memory buffer as a {@code '\0'} + * terminated C string. The native memory buffer is allocated via + * {@link Unsafe#allocateMemory(long)}. The caller is responsible for releasing the buffer when + * it is no longer needed via {@link Unsafe#freeMemory(long)}. + * + * @return the native memory pointer of the C string created from {@code s} + */ + public static long createCString(Unsafe unsafe, String s) { + return writeCString(unsafe, s, unsafe.allocateMemory(s.length() + 1)); + } + + /** + * Reads a {@code '\0'} terminated C string from native memory and converts it to a + * {@link String}. + * + * @return a Java string + */ + public 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(); + } + + /** + * Writes the contents of a {@link String} to a native memory buffer as a {@code '\0'} + * terminated C string. The caller is responsible for ensuring the buffer is at least + * {@code s.length() + 1} bytes long. The caller is also responsible for releasing the buffer + * when it is no longer. + * + * @return the value of {@code buf} + */ + public static long writeCString(Unsafe unsafe, String s, long buf) { + int size = s.length(); + for (int i = 0; i < size; i++) { + unsafe.putByte(buf + i, (byte) s.charAt(i)); + } + unsafe.putByte(buf + size, (byte) '\0'); + return buf; + } +}
--- a/jvmci/jdk.vm.ci.hotspot.aarch64/src/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot.aarch64/src/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java Thu May 12 11:06:49 2016 +0200 @@ -64,6 +64,7 @@ import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.StackSlot; import jdk.vm.ci.code.TargetDescription; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.HotSpotCallingConventionType; import jdk.vm.ci.hotspot.HotSpotVMConfig; import jdk.vm.ci.meta.AllocatableValue; @@ -225,7 +226,7 @@ case Double: return simdParameterRegisters; default: - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } } @@ -260,7 +261,7 @@ } break; default: - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } if (locations[i] == null) {
--- a/jvmci/jdk.vm.ci.hotspot.amd64/src/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot.amd64/src/jdk/vm/ci/hotspot/amd64/AMD64HotSpotRegisterConfig.java Thu May 12 11:06:49 2016 +0200 @@ -56,6 +56,7 @@ import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.StackSlot; import jdk.vm.ci.code.TargetDescription; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.HotSpotCallingConventionType; import jdk.vm.ci.hotspot.HotSpotVMConfig; import jdk.vm.ci.meta.AllocatableValue; @@ -222,7 +223,7 @@ case Double: return xmmParameterRegisters; default: - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } } @@ -257,7 +258,7 @@ } break; default: - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } if (locations[i] == null) {
--- a/jvmci/jdk.vm.ci.hotspot.sparc/src/jdk/vm/ci/hotspot/sparc/SPARCHotSpotRegisterConfig.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot.sparc/src/jdk/vm/ci/hotspot/sparc/SPARCHotSpotRegisterConfig.java Thu May 12 11:06:49 2016 +0200 @@ -78,6 +78,7 @@ import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.StackSlot; import jdk.vm.ci.code.TargetDescription; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.HotSpotCallingConventionType; import jdk.vm.ci.hotspot.HotSpotVMConfig; import jdk.vm.ci.meta.AllocatableValue; @@ -210,7 +211,7 @@ if (type == HotSpotCallingConventionType.JavaCallee) { return callingConvention(cpuCalleeParameterRegisters, returnType, parameterTypes, hotspotType, target); } - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } @Override @@ -229,7 +230,7 @@ case Float: return fpuFloatParameterRegisters; default: - throw new InternalError("should not reach here: unknown JavaKind " + kind); + throw JVMCIError.shouldNotReachHere("Unknown JavaKind " + kind); } } @@ -274,7 +275,7 @@ } break; default: - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } if (locations[i] == null) {
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java Thu May 12 11:06:49 2016 +0200 @@ -33,6 +33,7 @@ import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.InvalidInstalledCodeException; import jdk.vm.ci.code.TargetDescription; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspotvmconfig.HotSpotVMField; import jdk.vm.ci.inittimer.InitTimer; import jdk.vm.ci.meta.JavaType; @@ -309,8 +310,8 @@ * {@link HotSpotVMConfig#codeInstallResultCodeTooLarge}, * {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or * {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}. - * @throws InternalError if there is something wrong with the compiled code or the associated - * metadata + * @throws JVMCIError if there is something wrong with the compiled code or the associated + * metadata. */ native int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog);
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java Thu May 12 11:06:49 2016 +0200 @@ -29,6 +29,7 @@ import java.lang.invoke.MethodHandle; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.ConstantPool; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaField; @@ -157,7 +158,7 @@ if (res != null) { return res; } - throw new InternalError("Unknown JVM_CONSTANT tag " + tag); + throw new JVMCIError("Unknown JVM_CONSTANT tag %s", tag); } } @@ -507,7 +508,7 @@ Object obj = compilerToVM().resolveConstantInPool(this, cpi); return HotSpotObjectConstantImpl.forObject(obj); default: - throw new InternalError("Unknown constant pool tag " + tag); + throw new JVMCIError("Unknown constant pool tag %s", tag); } } @@ -654,7 +655,7 @@ break; } default: - throw new InternalError("Unexpected opcode " + opcode); + throw JVMCIError.shouldNotReachHere("Unexpected opcode " + opcode); } final JVM_CONSTANT tag = getTagAt(index);
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java Thu May 12 11:06:49 2016 +0200 @@ -24,6 +24,7 @@ import java.lang.reflect.Array; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaConstant; @@ -197,7 +198,7 @@ if (type instanceof HotSpotResolvedObjectType) { return ((HotSpotResolvedObjectType) type).klass(); } else { - throw new InternalError("should not reach here"); + throw JVMCIError.unimplemented(); } } }
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java Thu May 12 11:06:49 2016 +0200 @@ -24,6 +24,7 @@ import jdk.vm.ci.code.CompilationRequest; import jdk.vm.ci.code.CompilationRequestResult; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; import jdk.vm.ci.runtime.JVMCICompiler; import jdk.vm.ci.runtime.JVMCIRuntime; @@ -35,7 +36,7 @@ private static class DummyCompilerFactory extends JVMCICompilerFactory implements JVMCICompiler { public CompilationRequestResult compileMethod(CompilationRequest request) { - throw new InternalError("no JVMCI compiler selected"); + throw new JVMCIError("no JVMCI compiler selected"); } @Override @@ -71,7 +72,7 @@ } } if (factory == null) { - throw new InternalError("JVMCI compiler '" + compilerName + "' not found"); + throw new JVMCIError("JVMCI compiler '%s' not found", compilerName); } } else { factory = new DummyCompilerFactory();
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java Thu May 12 11:06:49 2016 +0200 @@ -41,6 +41,7 @@ import jdk.vm.ci.code.CompilationRequestResult; import jdk.vm.ci.code.CompiledCode; import jdk.vm.ci.code.InstalledCode; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory; import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; import jdk.vm.ci.inittimer.InitTimer; @@ -138,7 +139,7 @@ } else if (type == String.class) { this.value = propertyValue; } else { - throw new InternalError("Unexpected option type " + type); + throw new JVMCIError("Unexpected option type " + type); } this.isDefault = false; } @@ -188,7 +189,7 @@ } } - throw new InternalError(String.format("No JVMCI runtime available for the %s architecture", architecture)); + throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture); } /**
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntimeProvider.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntimeProvider.java Thu May 12 11:06:49 2016 +0200 @@ -24,6 +24,7 @@ import java.io.OutputStream; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.JVMCIMetaAccessContext; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.JavaType; @@ -97,7 +98,7 @@ case Object: return Unsafe.ARRAY_OBJECT_BASE_OFFSET; default: - throw new InternalError(kind.toString()); + throw new JVMCIError("%s", kind); } } @@ -127,7 +128,7 @@ case Object: return Unsafe.ARRAY_OBJECT_INDEX_SCALE; default: - throw new InternalError(kind.toString()); + throw new JVMCIError("%s", kind); } } }
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java Thu May 12 11:06:49 2016 +0200 @@ -36,6 +36,7 @@ import jdk.vm.ci.code.CodeUtil; import jdk.vm.ci.code.TargetDescription; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.DeoptimizationAction; import jdk.vm.ci.meta.DeoptimizationReason; import jdk.vm.ci.meta.JavaConstant; @@ -93,7 +94,7 @@ field.setAccessible(true); return field; } catch (NoSuchFieldException | SecurityException e) { - throw new InternalError(e); + throw new JVMCIError(e); } } @@ -104,7 +105,7 @@ final int slot = slotField.getInt(reflectionMethod); return runtime.getCompilerToVM().getResolvedJavaMethodAtSlot(holder, slot); } catch (IllegalArgumentException | IllegalAccessException e) { - throw new InternalError(e); + throw new JVMCIError(e); } } @@ -128,7 +129,7 @@ } } - throw new InternalError("unresolved field " + reflectionField); + throw new JVMCIError("unresolved field %s", reflectionField); } private static int intMaskRight(int n) { @@ -181,7 +182,7 @@ case InvalidateStopCompiling: return config.deoptActionMakeNotCompilable; default: - throw new InternalError(action.toString()); + throw new JVMCIError("%s", action); } } @@ -202,7 +203,7 @@ if (action == config.deoptActionMakeNotCompilable) { return DeoptimizationAction.InvalidateStopCompiling; } - throw new InternalError(String.valueOf(action)); + throw new JVMCIError("%d", action); } public int convertDeoptReason(DeoptimizationReason reason) { @@ -241,7 +242,7 @@ case TransferToInterpreter: return config.deoptReasonTransferToInterpreter; default: - throw new InternalError(reason.toString()); + throw new JVMCIError("%s", reason); } } @@ -295,7 +296,7 @@ if (reason == config.deoptReasonTransferToInterpreter) { return DeoptimizationReason.TransferToInterpreter; } - throw new InternalError(String.format("%x", reason)); + throw new JVMCIError("%x", reason); } @Override
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMethodHandleAccessProvider.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMethodHandleAccessProvider.java Thu May 12 11:06:49 2016 +0200 @@ -25,7 +25,7 @@ import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; import static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.fromObjectClass; - +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.MethodHandleAccessProvider; @@ -92,7 +92,7 @@ lambdaFormCompileToBytecodeMethod = findMethodInClass("java.lang.invoke.LambdaForm", "compileToBytecode"); memberNameVmtargetField = (HotSpotResolvedJavaField) findFieldInClass("java.lang.invoke.MemberName", "vmtarget"); } catch (Throwable ex) { - throw new InternalError(ex); + throw new JVMCIError(ex); } } }
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java Thu May 12 11:06:49 2016 +0200 @@ -27,6 +27,8 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import jdk.vm.ci.common.JVMCIError; +import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.ModifiersProvider; import jdk.vm.ci.meta.ResolvedJavaType;
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java Thu May 12 11:06:49 2016 +0200 @@ -36,6 +36,7 @@ import java.util.HashMap; import java.util.Map; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantPool; @@ -614,7 +615,7 @@ */ public int vtableEntryOffset(ResolvedJavaType resolved) { if (!isInVirtualMethodTable(resolved)) { - throw new InternalError(String.format("%s does not have a vtable entry in type %s", this, resolved)); + throw new JVMCIError("%s does not have a vtable entry in type %s", this, resolved); } HotSpotVMConfig config = config(); final int vtableIndex = getVtableIndex((HotSpotResolvedObjectTypeImpl) resolved);
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java Thu May 12 11:06:49 2016 +0200 @@ -38,6 +38,7 @@ import java.util.Arrays; import java.util.HashMap; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.Assumptions.AssumptionResult; import jdk.vm.ci.meta.Assumptions.ConcreteMethod; import jdk.vm.ci.meta.Assumptions.ConcreteSubtype; @@ -278,7 +279,7 @@ @Override public HotSpotResolvedObjectTypeImpl getSingleImplementor() { if (!isInterface()) { - throw new InternalError("Cannot call getSingleImplementor() on a non-interface type: " + this); + throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this); } return compilerToVM().getImplementor(this); }
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java Thu May 12 11:06:49 2016 +0200 @@ -28,6 +28,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Modifier; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.Assumptions.AssumptionResult; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; @@ -94,7 +95,7 @@ @Override public ResolvedJavaType getSingleImplementor() { - throw new InternalError("Cannot call getSingleImplementor() on a non-interface type: " + this); + throw new JVMCIError("Cannot call getSingleImplementor() on a non-interface type: %s", this); } @Override @@ -224,7 +225,7 @@ @Override public String getSourceFileName() { - throw new InternalError("should not reach here"); + throw JVMCIError.unimplemented(); } @Override
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotSignature.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotSignature.java Thu May 12 11:06:49 2016 +0200 @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.ResolvedJavaType; @@ -104,7 +105,7 @@ case 'Z': break; default: - throw new InternalError(String.format("Invalid character at index %d in signature: %s", cur, signature)); + throw new JVMCIError("Invalid character at index %d in signature: %s", cur, signature); } return cur; }
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java Thu May 12 11:06:49 2016 +0200 @@ -22,6 +22,7 @@ */ 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; @@ -30,12 +31,12 @@ import java.util.HashMap; import java.util.Iterator; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspotvmconfig.HotSpotVMConstant; import jdk.vm.ci.hotspotvmconfig.HotSpotVMField; import jdk.vm.ci.hotspotvmconfig.HotSpotVMFlag; import jdk.vm.ci.hotspotvmconfig.HotSpotVMType; import jdk.vm.ci.hotspotvmconfig.HotSpotVMValue; -import sun.misc.Unsafe; //JaCoCo Exclude @@ -115,27 +116,6 @@ } /** - * 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(); - } - - /** * Check that the initialization produces the same result as the values captured through * vmStructs. */ @@ -206,7 +186,7 @@ checkField(f, entry.getValue()); break; default: - throw new InternalError("unknown kind " + annotation.get()); + throw new JVMCIError("unknown kind %s", annotation.get()); } } else if (f.isAnnotationPresent(HotSpotVMType.class)) { HotSpotVMType annotation = f.getAnnotation(HotSpotVMType.class); @@ -220,7 +200,7 @@ checkField(f, entry.getSize()); break; default: - throw new InternalError("unknown kind " + annotation.get()); + throw new JVMCIError("unknown kind %s", annotation.get()); } } else if (f.isAnnotationPresent(HotSpotVMConstant.class)) { HotSpotVMConstant annotation = f.getAnnotation(HotSpotVMConstant.class); @@ -272,7 +252,7 @@ } else if (value instanceof Long) { assert field.getBoolean(this) == (((long) value) != 0) : field + " " + value + " " + field.getBoolean(this); } else { - throw new InternalError(value.getClass().getSimpleName()); + throw new JVMCIError(value.getClass().getSimpleName()); } } else if (fieldType == int.class) { if (value instanceof Integer) { @@ -280,15 +260,15 @@ } else if (value instanceof Long) { assert field.getInt(this) == (int) (long) value : field + " " + value + " " + field.getInt(this); } else { - throw new InternalError(value.getClass().getSimpleName()); + throw new JVMCIError(value.getClass().getSimpleName()); } } else if (fieldType == long.class) { assert field.getLong(this) == (long) value : field + " " + value + " " + field.getLong(this); } else { - throw new InternalError(field.toString()); + throw new JVMCIError(field.toString()); } } catch (IllegalAccessException e) { - throw new InternalError(String.format("%s: %s", field, e)); + throw new JVMCIError("%s: %s", field, e); } } @@ -408,7 +388,7 @@ if (type.endsWith("*")) { return UNSAFE.getAddress(getAddress()); } - throw new InternalError(type); + throw new JVMCIError(type); } } @@ -726,7 +706,7 @@ case "ccstrlist": return readCString(UNSAFE, getAddr()); default: - throw new InternalError(getType()); + throw new JVMCIError(getType()); } } @@ -1232,14 +1212,14 @@ public long cardtableStartAddress() { if (cardtableStartAddress == -1) { - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } return cardtableStartAddress; } public int cardtableShift() { if (cardtableShift == -1) { - throw new InternalError("should not reach here"); + throw JVMCIError.shouldNotReachHere(); } return cardtableShift; }
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigVerifier.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigVerifier.java Thu May 12 11:06:49 2016 +0200 @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.Objects; +import jdk.vm.ci.common.JVMCIError; import jdk.internal.org.objectweb.asm.ClassReader; import jdk.internal.org.objectweb.asm.ClassVisitor; import jdk.internal.org.objectweb.asm.Label; @@ -67,7 +68,7 @@ */ return true; } catch (IOException e) { - throw new InternalError(e); + throw new JVMCIError(e); } } @@ -75,7 +76,7 @@ try { return Class.forName(name.replace('/', '.')); } catch (ClassNotFoundException e) { - throw new InternalError(e); + throw new JVMCIError(e); } } @@ -109,7 +110,7 @@ void error(String message) { String errorMessage = format("%s:%d: %s is not allowed in the context of compilation replay. The unsafe access should be moved into the %s constructor and the result cached in a field", sourceFile, lineNo, message, HotSpotVMConfig.class.getSimpleName()); - throw new InternalError(errorMessage); + throw new JVMCIError(errorMessage); }
--- a/jvmci/jdk.vm.ci.hotspotvmconfig.processor/src/jdk/vm/ci/hotspotvmconfig/processor/HotSpotVMConfigProcessor.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspotvmconfig.processor/src/jdk/vm/ci/hotspotvmconfig/processor/HotSpotVMConfigProcessor.java Thu May 12 11:06:49 2016 +0200 @@ -47,6 +47,7 @@ import javax.tools.FileObject; import javax.tools.StandardLocation; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspotvmconfig.HotSpotVMConstant; import jdk.vm.ci.hotspotvmconfig.HotSpotVMField; import jdk.vm.ci.hotspotvmconfig.HotSpotVMFlag; @@ -278,7 +279,7 @@ setter = String.format("set_%s(\"%s\", (%s) (intptr_t) %s);", type, field.getSimpleName(), type, name); break; default: - throw new InternalError("unexpected type: " + value.get()); + throw new JVMCIError("unexpected type: " + value.get()); } } @@ -341,7 +342,7 @@ case "sparc": return "defined(SPARC)"; default: - throw new InternalError("unexpected arch: " + arch); + throw new JVMCIError("unexpected arch: " + arch); } }
--- a/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java Thu May 12 14:24:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java Thu May 12 11:06:49 2016 +0200 @@ -55,6 +55,7 @@ import org.junit.Test; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.Assumptions.AssumptionResult; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; @@ -428,13 +429,13 @@ assertEquals(aSai2, iSai2.getSingleImplementor()); } - @Test(expected = InternalError.class) + @Test(expected = JVMCIError.class) public void getSingleImplementorTestClassReceiver() { ResolvedJavaType base = metaAccess.lookupJavaType(Base.class); base.getSingleImplementor(); } - @Test(expected = InternalError.class) + @Test(expected = JVMCIError.class) public void getSingleImplementorTestPrimitiveReceiver() { ResolvedJavaType primitive = metaAccess.lookupJavaType(int.class); primitive.getSingleImplementor();
--- a/make/jvmci.make Thu May 12 14:24:15 2016 +0200 +++ b/make/jvmci.make Thu May 12 11:06:49 2016 +0200 @@ -104,6 +104,7 @@ JVMCI_API_SRC += $(shell find jvmci/jdk.vm.ci.meta/src -type f 2> /dev/null) JVMCI_API_SRC += $(shell find jvmci/jdk.vm.ci.code/src -type f 2> /dev/null) JVMCI_API_SRC += $(shell find jvmci/jdk.vm.ci.runtime/src -type f 2> /dev/null) +JVMCI_API_SRC += $(shell find jvmci/jdk.vm.ci.common/src -type f 2> /dev/null) JVMCI_API_SRC += $(shell find jvmci/jdk.vm.ci.aarch64/src -type f 2> /dev/null) JVMCI_API_SRC += $(shell find jvmci/jdk.vm.ci.amd64/src -type f 2> /dev/null) JVMCI_API_SRC += $(shell find jvmci/jdk.vm.ci.sparc/src -type f 2> /dev/null)
--- a/mx.jvmci/suite.py Thu May 12 14:24:15 2016 +0200 +++ b/mx.jvmci/suite.py Thu May 12 11:06:49 2016 +0200 @@ -70,6 +70,14 @@ # ------------- JVMCI:API ------------- + "jdk.vm.ci.common" : { + "subDir" : "jvmci", + "sourceDirs" : ["src"], + "checkstyle" : "jdk.vm.ci.services", + "javaCompliance" : "1.8", + "workingSets" : "API,JVMCI", + }, + "jdk.vm.ci.meta" : { "subDir" : "jvmci", "sourceDirs" : ["src"], @@ -104,6 +112,7 @@ "sourceDirs" : ["src"], "dependencies" : [ "mx:JUNIT", + "jdk.vm.ci.common", "jdk.vm.ci.runtime", ], "checkstyle" : "jdk.vm.ci.services", @@ -153,6 +162,7 @@ "sourceDirs" : ["src"], "dependencies" : [ "jdk.vm.ci.hotspotvmconfig", + "jdk.vm.ci.common", "jdk.vm.ci.inittimer", "jdk.vm.ci.runtime", ], @@ -175,7 +185,7 @@ "jdk.vm.ci.hotspotvmconfig.processor" : { "subDir" : "jvmci", "sourceDirs" : ["src"], - "dependencies" : ["jdk.vm.ci.hotspotvmconfig"], + "dependencies" : ["jdk.vm.ci.hotspotvmconfig", "jdk.vm.ci.common"], "checkstyle" : "jdk.vm.ci.services", "javaCompliance" : "1.8", "workingSets" : "JVMCI,HotSpot,Codegen", @@ -309,6 +319,7 @@ "dependencies" : [ "jdk.vm.ci.inittimer", "jdk.vm.ci.runtime", + "jdk.vm.ci.common", "jdk.vm.ci.aarch64", "jdk.vm.ci.amd64", "jdk.vm.ci.sparc",
--- a/src/share/vm/jvmci/jvmciRuntime.cpp Thu May 12 14:24:15 2016 +0200 +++ b/src/share/vm/jvmci/jvmciRuntime.cpp Thu May 12 11:06:49 2016 +0200 @@ -1043,6 +1043,19 @@ vm_abort(dump_core); } +void JVMCIRuntime::fthrow_error(Thread* thread, const char* file, int line, const char* format, ...) { + const int max_msg_size = 1024; + va_list ap; + va_start(ap, format); + char msg[max_msg_size]; + vsnprintf(msg, max_msg_size, format, ap); + msg[max_msg_size-1] = '\0'; + va_end(ap); + Handle h_loader = Handle(thread, SystemDictionary::jvmci_loader()); + Handle h_protection_domain = Handle(); + Exceptions::_throw_msg(thread, file, line, vmSymbols::jdk_vm_ci_common_JVMCIError(), msg, h_loader, h_protection_domain); +} + Klass* JVMCIRuntime::resolve_or_null(Symbol* name, TRAPS) { assert(!UseJVMCIClassLoader || SystemDictionary::jvmci_loader() != NULL, "JVMCI classloader should have been initialized"); return SystemDictionary::resolve_or_null(name, SystemDictionary::jvmci_loader(), Handle(), CHECK_NULL);
--- a/src/share/vm/jvmci/jvmciRuntime.hpp Thu May 12 14:24:15 2016 +0200 +++ b/src/share/vm/jvmci/jvmciRuntime.hpp Thu May 12 11:06:49 2016 +0200 @@ -32,10 +32,10 @@ #define JVMCI_ERROR(...) \ - { Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_InternalError(), __VA_ARGS__); return; } + { JVMCIRuntime::fthrow_error(THREAD_AND_LOCATION, __VA_ARGS__); return; } #define JVMCI_ERROR_(ret, ...) \ - { Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_InternalError(), __VA_ARGS__); return ret; } + { JVMCIRuntime::fthrow_error(THREAD_AND_LOCATION, __VA_ARGS__); return ret; } #define JVMCI_ERROR_0(...) JVMCI_ERROR_(0, __VA_ARGS__) #define JVMCI_ERROR_NULL(...) JVMCI_ERROR_(NULL, __VA_ARGS__) @@ -172,6 +172,13 @@ static void parse_lines(char* path, ParseClosure* closure, bool warnStatFailure); /** + * Throws a JVMCIError with a formatted error message. Ideally we would use + * a variation of Exceptions::fthrow that takes a class loader argument but alas, + * no such variation exists. + */ + static void fthrow_error(Thread* thread, const char* file, int line, const char* format, ...) ATTRIBUTE_PRINTF(4, 5); + + /** * Aborts the VM due to an unexpected exception. */ static void abort_on_pending_exception(Handle exception, const char* message, bool dump_core = false);
--- a/src/share/vm/jvmci/vmSymbols_jvmci.hpp Thu May 12 14:24:15 2016 +0200 +++ b/src/share/vm/jvmci/vmSymbols_jvmci.hpp Thu May 12 11:06:49 2016 +0200 @@ -84,6 +84,7 @@ template(jdk_vm_ci_code_site_Infopoint, "jdk/vm/ci/code/site/Infopoint") \ template(jdk_vm_ci_code_site_Site, "jdk/vm/ci/code/site/Site") \ template(jdk_vm_ci_code_site_InfopointReason, "jdk/vm/ci/code/site/InfopointReason") \ + template(jdk_vm_ci_common_JVMCIError, "jdk/vm/ci/common/JVMCIError") \ template(adjustCompilationLevel_name, "adjustCompilationLevel") \ template(adjustCompilationLevel_signature, "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;ZI)I") \ template(compileMethod_name, "compileMethod") \