Skip to content

Commit

Permalink
Showing 4 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -261,7 +261,7 @@ public static MethodHandle finishAdapting(final SmartBinder binder, final RubyMo
SmartHandle smartTarget = targetBinder.invoke(method);
if (frame) {
smartTarget = SmartHandle
.from(smartTarget.signature(), InvocationLinker.wrapWithFrameOnly(binder.baseSignature(), implementationClass, rubyName, smartTarget.handle(), null));
.from(smartTarget.signature(), InvocationLinker.wrapWithFrameOnly(binder.baseSignature(), implementationClass, rubyName, smartTarget.handle()));
}

MethodHandle target = smartTarget.handle();
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jruby.*;
import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings;
import org.jruby.internal.runtime.GlobalVariable;
import org.jruby.internal.runtime.methods.*;
@@ -19,10 +20,10 @@
import org.jruby.runtime.CompiledIRBlockBody;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.Frame;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.invokedynamic.GlobalSite;
import org.jruby.runtime.invokedynamic.InvocationLinker;
import org.jruby.runtime.invokedynamic.MathLinker;
import org.jruby.runtime.invokedynamic.VariableSite;
import org.jruby.runtime.ivars.FieldVariableAccessor;
@@ -589,6 +590,11 @@ static MethodHandle buildNativeHandle(InvokeSite site, DynamicMethod method, boo
.handle();
}
}

JRubyMethod anno = nativeCall.getMethod().getAnnotation(JRubyMethod.class);
if (anno != null && anno.frame()) {
mh = InvocationLinker.wrapWithFrameOnly(site.signature, method.getImplementationClass(), site.name(), mh);
}
}
}

4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
@@ -835,6 +835,10 @@ public void preMethodFrameOnly(RubyModule clazz, String name, IRubyObject self,
pushCallFrame(clazz, name, self, block);
}

public void preMethodFrameOnly(RubyModule clazz, String name, IRubyObject self) {
pushCallFrame(clazz, name, self, Block.NULL_BLOCK);
}

public void postMethodFrameOnly() {
popFrame();
}
Original file line number Diff line number Diff line change
@@ -82,8 +82,8 @@ public static MethodHandle wrapWithFraming(Signature signature, CallConfiguratio
return nativeTarget;
}

public static MethodHandle wrapWithFrameOnly(Signature signature, RubyModule implClass, String name, MethodHandle nativeTarget, StaticScope scope) {
MethodHandle framePre = getFramePre(signature, CallConfiguration.FrameFullScopeNone, implClass, name, scope);
public static MethodHandle wrapWithFrameOnly(Signature signature, RubyModule implClass, String name, MethodHandle nativeTarget) {
MethodHandle framePre = getFrameOnlyPre(signature, CallConfiguration.FrameFullScopeNone, implClass, name);

MethodHandle framePost = getFramePost(signature, CallConfiguration.FrameFullScopeNone);

@@ -141,14 +141,6 @@ public static MethodHandle getFramePre(Signature signature, CallConfiguration ca
.invokeVirtualQuiet(lookup(), "preMethodFrameOnly")
.handle();

case FrameNoneScopeFull:
// before logic
return binder
.permute("context")
.insert(1, arrayOf("selfClass", "scope"), arrayOf(RubyModule.class, StaticScope.class), implClass, scope)
.invokeVirtualQuiet(lookup(), "preMethodScopeOnly")
.handle();

case FrameNoneScopeDummy:
// before logic
return binder
@@ -157,11 +149,34 @@ public static MethodHandle getFramePre(Signature signature, CallConfiguration ca
.invokeVirtualQuiet(lookup(), "preMethodNoFrameAndDummyScope")
.handle();

case FrameNoneScopeFull:
return getFrameOnlyPre(signature, callConfig, implClass, name);

}

return null;
}

public static MethodHandle getFrameOnlyPre(Signature signature, CallConfiguration callConfig, RubyModule implClass, String name) {
Signature inbound = signature.asFold(void.class);
SmartBinder binder = SmartBinder
.from(inbound);

switch (callConfig) {
case FrameFullScopeNone:
// before logic
return binder
.permute("context", "self", "block")
.insert(1, arrayOf("selfClass", "name"), arrayOf(RubyModule.class, String.class), implClass, name)
.invokeVirtualQuiet(lookup(), "preMethodFrameOnly")
.handle();

default:
throw new RuntimeException("invalid input: " + callConfig);

}
}

public static MethodHandle getFramePost(Signature signature, CallConfiguration callConfig) {
Signature inbound = signature.asFold(void.class);
SmartBinder binder = SmartBinder

0 comments on commit b0db8d9

Please sign in to comment.