Skip to content

Commit

Permalink
Fix alias dispatch via indy; was using new name instead of old.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 28, 2012
1 parent f79f151 commit 36cee21
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/org/jruby/runtime/invokedynamic/InvocationLinker.java
Expand Up @@ -426,7 +426,10 @@ public IndirectBindingException(String reason) {

private static MethodHandle tryDispatchDirect(JRubyCallSite site, String name, RubyClass cls, DynamicMethod method) {
// get the "real" method in a few ways
while (method instanceof AliasMethod) method = method.getRealMethod();
while (method instanceof AliasMethod) {
name = ((AliasMethod)method).getOldName(); // need to use original name, not aliased name
method = method.getRealMethod();
}
while (method instanceof WrapperMethod) method = method.getRealMethod();

if (method instanceof DefaultMethod) {
Expand Down Expand Up @@ -574,11 +577,11 @@ private static MethodHandle handleForMethod(JRubyCallSite site, String name, Rub
} else if (method instanceof CompiledMethod || method instanceof JittedMethod) {
// Ruby to Ruby
if (RubyInstanceConfig.LOG_INDY_BINDINGS) LOG.info(name + "\tbound to Ruby method " + logMethod(method) + ": " + nativeCall);
nativeTarget = createRubyHandle(site, method);
nativeTarget = createRubyHandle(site, method, name);
} else {
// Ruby to Core
if (RubyInstanceConfig.LOG_INDY_BINDINGS) LOG.info(name + "\tbound to native method " + logMethod(method) + ": " + nativeCall);
nativeTarget = createNativeHandle(site, method);
nativeTarget = createNativeHandle(site, method, name);
}
}

Expand Down Expand Up @@ -1222,7 +1225,7 @@ public static IRubyObject stringOrNil(Ruby runtime, CharSequence cs) {
// Dispatch via direct handle to native core method
////////////////////////////////////////////////////////////////////////////

private static MethodHandle createNativeHandle(JRubyCallSite site, DynamicMethod method) {
private static MethodHandle createNativeHandle(JRubyCallSite site, DynamicMethod method, String name) {
MethodHandle nativeTarget = (MethodHandle)method.getHandle();
if (nativeTarget != null) return nativeTarget;

Expand Down Expand Up @@ -1274,7 +1277,7 @@ private static MethodHandle createNativeHandle(JRubyCallSite site, DynamicMethod
nativeTarget = explicitCastArguments(nativeTarget, convert);
nativeTarget = permuteArguments(nativeTarget, inboundType, permute);

nativeTarget = wrapWithFraming(site, method, nativeTarget, null, argCount);
nativeTarget = wrapWithFraming(method, name, nativeTarget, null, argCount);

method.setHandle(nativeTarget);

Expand Down Expand Up @@ -1372,7 +1375,7 @@ private static MethodHandle createAttrWriterHandle(JRubyCallSite site, RubyClass
// Dispatch via direct handle to Ruby method
////////////////////////////////////////////////////////////////////////////

private static MethodHandle createRubyHandle(JRubyCallSite site, DynamicMethod method) {
private static MethodHandle createRubyHandle(JRubyCallSite site, DynamicMethod method, String name) {
MethodHandle nativeTarget = (MethodHandle)method.getHandle();
if (nativeTarget != null) return nativeTarget;

Expand All @@ -1399,7 +1402,7 @@ private static MethodHandle createRubyHandle(JRubyCallSite site, DynamicMethod m
.insert(0, scriptObject)
.invokeStaticQuiet(site.lookup(), nativeCall.getNativeTarget(), nativeCall.getNativeName());

nativeTarget = wrapWithFraming(site, method, nativeTarget, scope, argCount);
nativeTarget = wrapWithFraming(method, name, nativeTarget, scope, argCount);

method.setHandle(nativeTarget);
return nativeTarget;
Expand All @@ -1408,8 +1411,8 @@ private static MethodHandle createRubyHandle(JRubyCallSite site, DynamicMethod m
}
}

private static MethodHandle wrapWithFraming(JRubyCallSite site, DynamicMethod method, MethodHandle nativeTarget, StaticScope scope, int argCount) {
MethodHandle framePre = getFramePre(site, method, argCount, scope);
private static MethodHandle wrapWithFraming(DynamicMethod method, String name, MethodHandle nativeTarget, StaticScope scope, int argCount) {
MethodHandle framePre = getFramePre(method, name, argCount, scope);

if (framePre != null) {
MethodHandle framePost = getFramePost(method, argCount);
Expand Down Expand Up @@ -1475,7 +1478,7 @@ public static IRubyObject handleRedo(JumpException.RedoJump rj, ThreadContext co
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.REDO, context.runtime.getNil(), "unexpected redo");
}

private static MethodHandle getFramePre(JRubyCallSite site, DynamicMethod method, int argCount, StaticScope scope) {
private static MethodHandle getFramePre(DynamicMethod method, String name, int argCount, StaticScope scope) {
MethodHandle framePre = null;

switch (method.getCallConfig()) {
Expand All @@ -1484,7 +1487,7 @@ private static MethodHandle getFramePre(JRubyCallSite site, DynamicMethod method
framePre = Binder
.from(STANDARD_NATIVE_TYPES_BLOCK[Math.abs(argCount)].changeReturnType(void.class))
.permute(TC_SELF_BLOCK_PERMUTES[Math.abs(argCount)])
.insert(1, new Class[]{RubyModule.class, String.class}, method.getImplementationClass(), site.name())
.insert(1, new Class[]{RubyModule.class, String.class}, method.getImplementationClass(), name)
.insert(5, new Class[]{StaticScope.class}, scope)
.invokeVirtualQuiet(lookup(), "preMethodFrameAndScope");

Expand All @@ -1495,7 +1498,7 @@ private static MethodHandle getFramePre(JRubyCallSite site, DynamicMethod method
framePre = Binder
.from(STANDARD_NATIVE_TYPES_BLOCK[Math.abs(argCount)].changeReturnType(void.class))
.permute(TC_SELF_BLOCK_PERMUTES[Math.abs(argCount)])
.insert(1, new Class[]{RubyModule.class, String.class}, method.getImplementationClass(), site.name())
.insert(1, new Class[]{RubyModule.class, String.class}, method.getImplementationClass(), name)
.insert(5, new Class[]{StaticScope.class}, scope)
.invokeVirtualQuiet(lookup(), "preMethodFrameAndDummyScope");

Expand All @@ -1506,7 +1509,7 @@ private static MethodHandle getFramePre(JRubyCallSite site, DynamicMethod method
framePre = Binder
.from(STANDARD_NATIVE_TYPES_BLOCK[Math.abs(argCount)].changeReturnType(void.class))
.permute(TC_SELF_BLOCK_PERMUTES[Math.abs(argCount)])
.insert(1, new Class[]{RubyModule.class, String.class}, method.getImplementationClass(), site.name())
.insert(1, new Class[]{RubyModule.class, String.class}, method.getImplementationClass(), name)
.invokeVirtualQuiet(lookup(), "preMethodFrameOnly");

break;
Expand Down

0 comments on commit 36cee21

Please sign in to comment.