indy: fix guardWithCatch bug on argc > 10
authorjrose
Sat Jul 04 14:35:42 2009 -0700 (4 months ago)
changeset 52c9eda12bdd9e
parent 51e1f9d04b190c
child 534d81aaaa12c1
indy: fix guardWithCatch bug on argc > 10
indy.patch
--- a/indy.patch Thu Jul 02 03:34:06 2009 -0700
+++ b/indy.patch Sat Jul 04 14:35:42 2009 -0700
@@ -8072,7 +8072,7 @@ diff --git a/src/share/classes/sun/dyn/M
MethodHandle res = AdapterMethodHandle.makePairwiseConvert(token, newType, target);
if (res != null)
return res;
-@@ -274,81 +487,343 @@
+@@ -274,81 +487,384 @@
ptypes[spreadArg + i] = VerifyType.spreadArgElementType(spreadType, i);
MethodType midType = MethodType.make(newType.returnType(), ptypes);
// after spreading, some arguments may need further conversion
@@ -8171,7 +8171,11 @@ diff --git a/src/share/classes/sun/dyn/M
+ private static class GuardWithTest extends JavaMethodHandle {
+ private final MethodHandle test, target, fallback;
+ public GuardWithTest(MethodHandle test, MethodHandle target, MethodHandle fallback) {
-+ super(INVOKES[target.type().parameterCount()]);
++ this(INVOKES[target.type().parameterCount()], test, target, fallback);
++ }
++ public GuardWithTest(MethodHandle invoker,
++ MethodHandle test, MethodHandle target, MethodHandle fallback) {
++ super(invoker);
+ this.test = test;
+ this.target = target;
+ this.fallback = fallback;
@@ -8179,6 +8183,11 @@ diff --git a/src/share/classes/sun/dyn/M
+ @Override
+ public String toString() {
+ return target.toString();
++ }
++ private Object invoke_V(Object... av) throws Throwable {
++ if (test.<boolean>invoke(av))
++ return target.<Object>invoke(av);
++ return fallback.<Object>invoke(av);
+ }
+ private Object invoke_L0() throws Throwable {
+ if (test.<boolean>invoke())
@@ -8243,6 +8252,16 @@ diff --git a/src/share/classes/sun/dyn/M
+ return invokes.toArray(new MethodHandle[0]);
+ };
+ static final MethodHandle[] INVOKES = makeInvokes();
++ // For testing use this:
++ //static final MethodHandle[] INVOKES = Arrays.copyOf(makeInvokes(), 2);
++ static final MethodHandle VARARGS_INVOKE;
++ static {
++ try {
++ VARARGS_INVOKE = IMPL_LOOKUP.findVirtual(GuardWithTest.class, "invoke_V", MethodType.makeGeneric(0, true));
++ } catch (NoAccessException ex) {
++ throw new InternalError("");
++ }
++ }
+ }
+
public static
@@ -8276,11 +8295,11 @@ diff --git a/src/share/classes/sun/dyn/M
+ MethodHandle gguard = new GuardWithTest(gtest, gtarget, gfallback);
+ return convertArguments(token, gguard, type, gtype, null);
+ } else {
-+ MethodType gtype = MethodType.makeGeneric(1);
++ MethodType gtype = MethodType.makeGeneric(0, true);
+ MethodHandle gtest = spreadArguments(token, test, gtype.changeReturnType(boolean.class), 0);
+ MethodHandle gtarget = spreadArguments(token, target, gtype, 0);
+ MethodHandle gfallback = spreadArguments(token, fallback, gtype, 0);
-+ MethodHandle gguard = new GuardWithTest(gtest, gtarget, gfallback);
++ MethodHandle gguard = new GuardWithTest(GuardWithTest.VARARGS_INVOKE, gtest, gtarget, gfallback);
+ if (gtest == null || gtarget == null || gfallback == null) return null;
+ return collectArguments(token, gguard, type, 0, null);
}
@@ -8298,10 +8317,7 @@ diff --git a/src/share/classes/sun/dyn/M
+ private final Class<? extends Throwable> exType;
+ private final MethodHandle catcher;
+ public GuardWithCatch(MethodHandle target, Class<? extends Throwable> exType, MethodHandle catcher) {
-+ super(INVOKES[target.type().parameterCount()]);
-+ this.target = target;
-+ this.exType = exType;
-+ this.catcher = catcher;
++ this(INVOKES[target.type().parameterCount()], target, exType, catcher);
}
- // Got here? Reduced calling sequence to Object(Object).
- class Guarder {
@@ -8317,19 +8333,34 @@ diff --git a/src/share/classes/sun/dyn/M
- MethodType invokeType = MethodType.makeGeneric(0, true);
- MethodHandle vh = IMPL_LOOKUP.bind(this, "invoke", invokeType);
- return MethodHandles.collectArguments(vh, target.type());
++ public GuardWithCatch(MethodHandle invoker,
++ MethodHandle target, Class<? extends Throwable> exType, MethodHandle catcher) {
++ super(invoker);
++ this.target = target;
++ this.exType = exType;
++ this.catcher = catcher;
++ }
+ @Override
+ public String toString() {
+ return target.toString();
+ }
++ private Object invoke_V(Object... av) throws Throwable {
++ try {
++ return target.<Object>invoke(av);
++ } catch (Throwable t) {
++ if (!exType.isInstance(t)) throw t;
++ return catcher.<Object>invoke(t, av);
+ }
+ }
+- return new Guarder().handle();
+ private Object invoke_L0() throws Throwable {
+ try {
+ return target.<Object>invoke();
+ } catch (Throwable t) {
+ if (!exType.isInstance(t)) throw t;
+ return catcher.<Object>invoke(t);
- }
- }
-- return new Guarder().handle();
++ }
++ }
+ private Object invoke_L1(Object a0) throws Throwable {
+ try {
+ return target.<Object>invoke(a0);
@@ -8412,6 +8443,16 @@ diff --git a/src/share/classes/sun/dyn/M
+ return invokes.toArray(new MethodHandle[0]);
+ };
+ static final MethodHandle[] INVOKES = makeInvokes();
++ // For testing use this:
++ //static final MethodHandle[] INVOKES = Arrays.copyOf(makeInvokes(), 2);
++ static final MethodHandle VARARGS_INVOKE;
++ static {
++ try {
++ VARARGS_INVOKE = IMPL_LOOKUP.findVirtual(GuardWithCatch.class, "invoke_V", MethodType.makeGeneric(0, true));
++ } catch (NoAccessException ex) {
++ throw new InternalError("");
++ }
++ }
+ }
+
+
@@ -8433,11 +8474,11 @@ diff --git a/src/share/classes/sun/dyn/M
+ if (gtarget == null || gcatcher == null || gguard == null) return null;
+ return convertArguments(token, gguard, type, gtype, null);
+ } else {
-+ MethodType gtype = MethodType.makeGeneric(1);
++ MethodType gtype = MethodType.makeGeneric(0, true);
+ MethodType gcatchType = gtype.insertParameterType(0, Throwable.class);
+ MethodHandle gtarget = spreadArguments(token, target, gtype, 0);
+ MethodHandle gcatcher = spreadArguments(token, catcher, gcatchType, 1);
-+ MethodHandle gguard = new GuardWithCatch(gtarget, exType, gcatcher);
++ MethodHandle gguard = new GuardWithCatch(GuardWithCatch.VARARGS_INVOKE, gtarget, exType, gcatcher);
+ if (gtarget == null || gcatcher == null || gguard == null) return null;
+ return collectArguments(token, gguard, type, 0, null);
+ }
@@ -8462,7 +8503,7 @@ diff --git a/src/share/classes/sun/dyn/M
MemberName name = null;
if (target != null)
name = MethodHandleNatives.getMethodName(target);
-@@ -357,17 +832,13 @@
+@@ -357,17 +873,13 @@
return name.getName();
}