Skip to content

Instantly share code, notes, and snippets.

Created May 24, 2011 00:43
Show Gist options
  • Save anonymous/987939 to your computer and use it in GitHub Desktop.
Save anonymous/987939 to your computer and use it in GitHub Desktop.
diff --git a/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java b/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
index dc18326..1c40745 100644
--- a/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
+++ b/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
@@ -183,7 +183,23 @@ public class InvokeDynamicSupport {
MethodHandle myTest = MethodHandles.insertArguments(test, 0, entry.token);
MethodHandle myTarget = MethodHandles.insertArguments(target, 0, entry);
MethodHandle myFallback = curryFallback ? MethodHandles.insertArguments(fallback, 0, site) : fallback;
- MethodHandle guardWithTest = MethodHandles.guardWithTest(myTest, myTarget, myFallback);
+
+ MethodHandle guardWithTest;
+ if (test == TEST_1) {
+ guardWithTest = findStatic(InvokeDynamicSupport.class, "gwt", MethodType.methodType(
+ IRubyObject.class,
+ MethodHandle.class,
+ MethodHandle.class,
+ MethodHandle.class,
+ ThreadContext.class,
+ IRubyObject.class,
+ IRubyObject.class,
+ String.class,
+ IRubyObject.class));
+ guardWithTest = MethodHandles.insertArguments(guardWithTest, 0, myTest, myTarget, myFallback);
+ } else {
+ guardWithTest = MethodHandles.guardWithTest(myTest, myTarget, myFallback);
+ }
return MethodHandles.convertArguments(guardWithTest, site.type());
}
@@ -912,6 +928,15 @@ public class InvokeDynamicSupport {
return entry.method.call(context, self, selfClass, name, arg0);
}
+ public static IRubyObject gwt(MethodHandle test, MethodHandle target, MethodHandle fallback, ThreadContext context, IRubyObject caller, IRubyObject self, String name, IRubyObject arg0) throws Throwable {
+// System.out.println(test);
+// if ((boolean)test.invokeExact(context, caller, self, name, arg0)) {
+ return (IRubyObject)target.invokeExact(context, caller, self, name, arg0);
+// } else {
+// return fallback.invokeExact(context, caller, self, name, arg0);
+// }
+ }
+
public static IRubyObject fallback(JRubyCallSite site, ThreadContext context, IRubyObject caller, IRubyObject self, String name, IRubyObject arg0, IRubyObject arg1) {
RubyClass selfClass = pollAndGetClass(context, self);
CacheEntry entry = selfClass.searchWithCache(name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment