Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e3556a4b9018
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a761edbe926e
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 15, 2016

  1. Copy the full SHA
    4da4c16 View commit details
  2. Additional fixes for top-level script protocol.

    * Clear StaticScope's dynscope constructor when variable names are
      altered.
    * Clean up jitted top-level script boot logic.
    headius committed Dec 15, 2016
    Copy the full SHA
    a3ad3fb View commit details
  3. Merge pull request #4388 from headius/protocol-fixes

    Add call protocol to script body and separate non-protocol metas.
    headius authored Dec 15, 2016
    Copy the full SHA
    a761edb View commit details
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ public CompiledIRMethod(MethodHandle variable, MethodHandle specific, int specif
this.method.getStaticScope().determineModule();
this.hasKwargs = hasKwargs;

assert method.hasExplicitCallProtocol();

setHandle(variable);
}

@@ -67,16 +69,6 @@ public InterpreterContext ensureInstrsReady() {
return ic;
}

protected void post(ThreadContext context) {
// update call stacks (pop: ..)
context.postMethodFrameAndScope();
}

protected void pre(ThreadContext context, StaticScope staticScope, RubyModule implementationClass, IRubyObject self, String name, Block block) {
// update call stacks (push: frame, class, scope, etc.)
context.preMethodFrameAndScope(implementationClass, name, self, block, staticScope);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
if (hasKwargs) args = IRRuntimeHelpers.frobnicateKwargsArgument(context, args, getSignature().required());
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.jruby.internal.runtime.methods;

import org.jruby.RubyModule;
import org.jruby.internal.runtime.AbstractIRMethod;
import org.jruby.ir.IRFlags;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Block;
@@ -14,13 +17,15 @@

import java.lang.invoke.MethodHandle;

public class CompiledIRMetaClassBody extends CompiledIRMethod {
public class CompiledIRNoProtocolMethod extends AbstractIRMethod {
private final boolean scope;
private final MethodHandle variable;

public CompiledIRMetaClassBody(MethodHandle handle, IRScope scope, RubyModule implementationClass) {
super(handle, scope, Visibility.PUBLIC, implementationClass, scope.receivesKeywordArgs());
public CompiledIRNoProtocolMethod(MethodHandle handle, IRScope scope, RubyModule implementationClass) {
super(scope, Visibility.PUBLIC, implementationClass);

this.scope = !scope.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED);
this.variable = handle;
}

public ArgumentDescriptor[] getArgumentDescriptors() {
@@ -63,7 +68,6 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
throw new RuntimeException("BUG: this path should never be called");
}

@Override
protected void post(ThreadContext context) {
// update call stacks (pop: ..)
context.popFrame();
@@ -72,7 +76,6 @@ protected void post(ThreadContext context) {
}
}

@Override
protected void pre(ThreadContext context, StaticScope staticScope, RubyModule implementationClass, IRubyObject self, String name, Block block) {
// update call stacks (push: frame, class, scope, etc.)
context.preMethodFrameOnly(implementationClass, name, self, block);
@@ -85,4 +88,16 @@ protected void pre(ThreadContext context, StaticScope staticScope, RubyModule im
context.setCurrentVisibility(getVisibility());
}

@Override
public InterpreterContext ensureInstrsReady() {
// FIXME: duplicated from MixedModeIRMethod
if (method instanceof IRMethod) {
return ((IRMethod) method).lazilyAcquireInterpreterContext();
}

InterpreterContext ic = method.getInterpreterContext();

return ic;
}

}
33 changes: 5 additions & 28 deletions core/src/main/java/org/jruby/ir/Compiler.java
Original file line number Diff line number Diff line change
@@ -63,12 +63,13 @@ protected ScriptAndCode execute(final Ruby runtime, final IRScriptBody scope, Cl
}

final MethodHandle compiledHandle = _compiledHandle;
final StaticScope staticScope = scope.getStaticScope();

Script script = new AbstractScript() {
@Override
public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
try {
return (IRubyObject) compiledHandle.invokeWithArguments(context, scope.getStaticScope(), self, IRubyObject.NULL_ARRAY, block, self.getMetaClass(), Interpreter.ROOT);
return (IRubyObject) compiledHandle.invokeWithArguments(context, staticScope, self, IRubyObject.NULL_ARRAY, block, self.getMetaClass(), Interpreter.ROOT);
} catch (Throwable t) {
Helpers.throwException(t);
return null; // not reached
@@ -78,45 +79,21 @@ public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject
@Override
public IRubyObject load(ThreadContext context, IRubyObject self, boolean wrap) {
// Compiler does not support BEGIN/END yet and should fail to compile above
{
// BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.prepareForInterpretation();

// We get the live object ball rolling here.
// This give a valid value for the top of this lexical tree.
// All new scopes can then retrieve and set based on lexical parent.
// StaticScope scope = ic.getStaticScope();
}
// Copied from Interpreter
StaticScope sscope = scope.getStaticScope();
RubyModule currModule = sscope.getModule();
if (currModule == null) {
// SSS FIXME: Looks like this has to do with Kernel#load
// and the wrap parameter. Figure it out and document it here.
currModule = context.getRuntime().getObject();
}
RubyModule currModule = staticScope.getModule();

sscope.setModule(currModule);
DynamicScope tlbScope = scope.getToplevelScope();
if (tlbScope == null) {
context.preMethodScopeOnly(sscope);
} else {
sscope = tlbScope.getStaticScope();
context.preScopedBody(tlbScope);
tlbScope.growIfNeeded();
}
staticScope.setModule(currModule);
context.setCurrentVisibility(Visibility.PRIVATE);

try {
// runBeginEndBlocks(ic.getBeginBlocks(), context, self, scope, null);
return (IRubyObject) compiledHandle.invokeWithArguments(context, sscope, self, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, currModule, Interpreter.ROOT);
return (IRubyObject) compiledHandle.invokeWithArguments(context, staticScope, self, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, currModule, Interpreter.ROOT);
} catch (IRBreakJump bj) {
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} catch (Throwable t) {
Helpers.throwException(t);
return null; // not reached
} finally {
// runEndBlocks(ic.getEndBlocks(), context, self, scope, null);
context.popScope();
}
}
};
Original file line number Diff line number Diff line change
@@ -22,8 +22,10 @@ public String getLabel() {

private boolean explicitCallProtocolSupported(IRScope scope) {
return scope instanceof IRMethod
|| (scope instanceof IRClosure && !(scope instanceof IREvalScript))
|| (scope instanceof IRModuleBody && !(scope instanceof IRMetaClassBody));
|| (scope instanceof IRClosure && !(scope instanceof IREvalScript))
|| (scope instanceof IRModuleBody && !(scope instanceof IRMetaClassBody)
|| (scope instanceof IRScriptBody)
);
}

/*
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import org.jruby.common.IRubyWarnings;
import org.jruby.exceptions.RaiseException;
import org.jruby.exceptions.Unrescuable;
import org.jruby.internal.runtime.methods.CompiledIRMetaClassBody;
import org.jruby.internal.runtime.methods.CompiledIRNoProtocolMethod;
import org.jruby.internal.runtime.methods.CompiledIRMethod;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.InterpretedIRBodyMethod;
@@ -1240,7 +1240,7 @@ public static DynamicMethod newInterpretedMetaClass(Ruby runtime, IRScope metaCl
public static DynamicMethod newCompiledMetaClass(ThreadContext context, MethodHandle handle, IRScope metaClassBody, IRubyObject obj) {
RubyClass singletonClass = newMetaClassFromIR(context.runtime, metaClassBody, obj);

return new CompiledIRMetaClassBody(handle, metaClassBody, singletonClass);
return new CompiledIRNoProtocolMethod(handle, metaClassBody, singletonClass);
}

private static RubyClass newMetaClassFromIR(Ruby runtime, IRScope metaClassBody, IRubyObject obj) {
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/parser/StaticScope.java
Original file line number Diff line number Diff line change
@@ -244,6 +244,9 @@ public int addVariableThisScope(String name) {

if (slot >= 0) return slot;

// Clear constructor since we are adding a name
constructor = null;

// This is perhaps innefficient timewise? Optimal spacewise
growVariableNames(name);

@@ -277,6 +280,9 @@ public int addVariable(String name) {

if (slot >= 0) return slot;

// Clear constructor since we are adding a name
constructor = null;

// This is perhaps innefficient timewise? Optimal spacewise
growVariableNames(name);

@@ -296,6 +302,9 @@ public void setVariables(String[] names) {
assert names != null : "names is not null";
assert namesAreInterned(names);

// Clear constructor since we are changing names
constructor = null;

variableNames = new String[names.length];
variableNamesLength = names.length;
System.arraycopy(names, 0, variableNames, 0, names.length);
4 changes: 1 addition & 3 deletions core/src/test/java/org/jruby/test/TestRubyBase.java
Original file line number Diff line number Diff line change
@@ -81,9 +81,7 @@ protected final String eval(String script, String fileName) throws Exception {
runtime.getGlobalVariables().set("$>", lStream);
runtime.getGlobalVariables().set("$stderr", lStream);

runtime.runNormally(
runtime.parseFile(new ByteArrayInputStream(script.getBytes()), fileName, runtime.getCurrentContext().getCurrentScope())
);
runtime.runFromMain(new ByteArrayInputStream(script.getBytes()), fileName);
StringBuffer sb = new StringBuffer(new String(result.toByteArray()));
for (int idx = sb.indexOf("\n"); idx != -1; idx = sb.indexOf("\n")) {
sb.deleteCharAt(idx);