Skip to content

Instantly share code, notes, and snippets.

@enebo
Created December 3, 2020 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enebo/2449b111313739bca31041d98f56c8b1 to your computer and use it in GitHub Desktop.
Save enebo/2449b111313739bca31041d98f56c8b1 to your computer and use it in GitHub Desktop.
diff --git a/core/src/main/java/org/jruby/java/proxies/ConcreteJavaProxy.java b/core/src/main/java/org/jruby/java/proxies/ConcreteJavaProxy.java
index 2b9c082672..c793ef996f 100644
--- a/core/src/main/java/org/jruby/java/proxies/ConcreteJavaProxy.java
+++ b/core/src/main/java/org/jruby/java/proxies/ConcreteJavaProxy.java
@@ -380,18 +380,24 @@ public class ConcreteJavaProxy extends JavaProxy {
if ((dm1 != null && !(dm instanceof InitializeMethod)&& !(dm instanceof StaticJCreateMethod))) //jcreate is for nested ruby classes from a java class
{
//TODO: if not defined, then ctors = all valid superctors
-
+
IRMethod irme = ((IRMethod)((AbstractIRMethod)dm).getIRScope());
InterpreterContext ic = irme.builtInterperterContextForJavaConstructor();
if (!(ic instanceof ExitableInterpreterContext))
throw new RuntimeException("Not splittable!!!"); //TODO
ExitableInterpreterContext eic = (ExitableInterpreterContext) ic;
ExitableInterpreterEngineState state = eic.getEngineState();
+ try {
+ getMetaClass().getRuntime().getCurrentContext().pushScope(DynamicScope.newDynamicScope(ic.getStaticScope()));
+
+ IRubyObject tmp = new ExitableInterpreterEngine().interpret(getRuntime().getCurrentContext(), null, this, eic, state, getMetaClass(), "initialize_part1", args, blk);
+ return new Object[]{
+ tmp, //TODO: nils?
+ null, eic, state};
+ } finally {
+ getMetaClass().getRuntime().getCurrentContext().popScope();
+ }
- IRubyObject tmp = new ExitableInterpreterEngine().interpret(getRuntime().getCurrentContext(), null, this, eic, state, getMetaClass(), "initialize_part1", args, blk);
- return new Object[] {
- tmp, //TODO: nils?
- null, eic, state};
}
else
{
java_import java.util.ArrayList
class Foo < ArrayList
def initialize(n)
a = n + 1
puts a
super(n)
end
end
p Foo.new(4)

You can see I added a try/finally where I construct a new dynamic scope for the static scope of the split method. This is not really in the right place since this same dynamicscope needs to be used for both interpret calls.

So you need to make equivalent try/finally in your asm logic where you push a new scope and pop it.

One thing which is a little foggy is that you can probably always push the extra dynamic scope but if it is not actually going to call into the interpreter there is no need to do it. So best solution might be to emit two versions instead of just one which handles the split and non-split case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment