8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
Reviewed-by: redestad
--- a/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java Fri Oct 28 11:18:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java Tue Nov 01 17:20:45 2016 -0700
@@ -80,7 +80,7 @@
default : throw newInternalError("unexpected xtype: " + xtype);
}
} catch (Throwable t) {
- throw newInternalError(t);
+ throw uncaughtException(t);
}
}
@@ -188,7 +188,7 @@
case D_TYPE: return (double) speciesData().getters[i].invokeBasic(this);
}
} catch (Throwable ex) {
- throw newInternalError(ex);
+ throw uncaughtException(ex);
}
throw new InternalError("unexpected type: " + speciesData().typeChars+"."+i);
}
@@ -408,18 +408,14 @@
*/
static boolean speciesDataCachePopulated() {
Class<BoundMethodHandle> rootCls = BoundMethodHandle.class;
- try {
- for (Class<?> c : rootCls.getDeclaredClasses()) {
- if (rootCls.isAssignableFrom(c)) {
- final Class<? extends BoundMethodHandle> cbmh = c.asSubclass(BoundMethodHandle.class);
- SpeciesData d = Factory.getSpeciesDataFromConcreteBMHClass(cbmh);
- assert(d != null) : cbmh.getName();
- assert(d.clazz == cbmh);
- assert(CACHE.get(d.typeChars) == d);
- }
+ for (Class<?> c : rootCls.getDeclaredClasses()) {
+ if (rootCls.isAssignableFrom(c)) {
+ final Class<? extends BoundMethodHandle> cbmh = c.asSubclass(BoundMethodHandle.class);
+ SpeciesData d = Factory.getSpeciesDataFromConcreteBMHClass(cbmh);
+ assert(d != null) : cbmh.getName();
+ assert(d.clazz == cbmh);
+ assert(CACHE.get(d.typeChars) == d);
}
- } catch (Throwable e) {
- throw newInternalError(e);
}
return true;
}
--- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Fri Oct 28 11:18:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Tue Nov 01 17:20:45 2016 -0700
@@ -1021,7 +1021,7 @@
try {
emptyArray = name.function.resolvedHandle().invoke();
} catch (Throwable ex) {
- throw newInternalError(ex);
+ throw uncaughtException(ex);
}
assert(java.lang.reflect.Array.getLength(emptyArray) == 0);
assert(emptyArray.getClass() == rtype); // exact typing
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Fri Oct 28 11:18:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Tue Nov 01 17:20:45 2016 -0700
@@ -855,7 +855,11 @@
System.out.println("LambdaForm compilation failed: " + this);
bge.printStackTrace(System.out);
}
- } catch (Error | Exception e) {
+ } catch (Error e) {
+ // Pass through any error
+ throw e;
+ } catch (Exception e) {
+ // Wrap any exception
throw newInternalError(this.toString(), e);
}
}
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Fri Oct 28 11:18:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Tue Nov 01 17:20:45 2016 -0700
@@ -957,7 +957,7 @@
if (!fail) return needType;
// elicit an error:
this.asType(needType);
- throw newInternalError("should not return", null);
+ throw newInternalError("should not return");
}
private void spreadArrayChecks(Class<?> arrayType, int arrayLength) {
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java Fri Oct 28 11:18:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java Tue Nov 01 17:20:45 2016 -0700
@@ -379,11 +379,13 @@
name, fixMethodType(callerClass, type), appendixResult);
}
}
+ } catch (Error e) {
+ // Pass through an Error, including say StackOverflowError or
+ // OutOfMemoryError
+ throw e;
} catch (Throwable ex) {
- if (ex instanceof LinkageError)
- throw (LinkageError) ex;
- else
- throw new LinkageError(ex.getMessage(), ex);
+ // Wrap anything else in LinkageError
+ throw new LinkageError(ex.getMessage(), ex);
}
throw new LinkageError("no such method "+defc.getName()+"."+name+type);
}
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Fri Oct 28 11:18:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Tue Nov 01 17:20:45 2016 -0700
@@ -107,10 +107,10 @@
/*non-public*/ static InternalError newInternalError(String message) {
return new InternalError(message);
}
- /*non-public*/ static InternalError newInternalError(String message, Throwable cause) {
+ /*non-public*/ static InternalError newInternalError(String message, Exception cause) {
return new InternalError(message, cause);
}
- /*non-public*/ static InternalError newInternalError(Throwable cause) {
+ /*non-public*/ static InternalError newInternalError(Exception cause) {
return new InternalError(cause);
}
/*non-public*/ static RuntimeException newIllegalStateException(String message) {
@@ -132,7 +132,7 @@
/*non-public*/ static Error uncaughtException(Throwable ex) {
if (ex instanceof Error) throw (Error) ex;
if (ex instanceof RuntimeException) throw (RuntimeException) ex;
- throw newInternalError("uncaught exception", ex);
+ throw new InternalError("uncaught exception", ex);
}
private static String message(String message, Object obj) {
if (obj != null) message = message + ": " + obj;
--- a/jdk/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java Fri Oct 28 11:18:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java Tue Nov 01 17:20:45 2016 -0700
@@ -723,6 +723,9 @@
default:
throw new StringConcatException("Concatenation strategy " + STRATEGY + " is not implemented");
}
+ } catch (Error | StringConcatException e) {
+ // Pass through any error or existing StringConcatException
+ throw e;
} catch (Throwable t) {
throw new StringConcatException("Generator failed", t);
}
@@ -1092,9 +1095,9 @@
UNSAFE.ensureClassInitialized(innerClass);
dumpIfEnabled(innerClass.getName(), classBytes);
return Lookup.IMPL_LOOKUP.findStatic(innerClass, METHOD_NAME, args);
- } catch (Throwable e) {
+ } catch (Exception e) {
dumpIfEnabled(className + "$$FAILED", classBytes);
- throw new StringConcatException("Error while spinning the class", e);
+ throw new StringConcatException("Exception while spinning the class", e);
}
}