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: 25ec188d9eba
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dbc430f07bff
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Mar 3, 2015

  1. Copy the full SHA
    e321dfe View commit details
  2. Some code still expected a StringLiteral here, so accommodate.

    Note that this reduces the effectiveness of frozen string caching
    in the interpreter, since the operand now hits the dedup cache
    every time. JIT should still be caching at site.
    headius committed Mar 3, 2015
    Copy the full SHA
    dbc430f View commit details
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.variable.invokeExact(context, method.getStaticScope(), self, args, block, implementationClass);
return (IRubyObject)this.variable.invokeExact(context, method.getStaticScope(), self, args, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
@@ -119,7 +119,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
@@ -135,7 +135,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
@@ -151,7 +151,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
@@ -167,7 +167,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, arg2, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, arg2, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/ir/Compiler.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import org.jruby.ast.executable.ScriptAndCode;
import org.jruby.compiler.NotCompilableException;
import org.jruby.ir.interpreter.BeginEndInterpreterContext;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.operands.IRException;
import org.jruby.ir.runtime.IRBreakJump;
import org.jruby.ir.targets.JVMVisitor;
@@ -55,7 +56,7 @@ protected ScriptAndCode execute(final Ruby runtime, final IRScriptBody scope, Cl
compiled = visitor.defineFromBytecode(scope, bytecode, classLoader);

Method compiledMethod = compiled.getMethod("__script__", ThreadContext.class,
StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, RubyModule.class);
StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, RubyModule.class, String.class);
_compiledHandle = MethodHandles.publicLookup().unreflect(compiledMethod);
} catch (NotCompilableException nce) {
throw nce;
@@ -69,7 +70,7 @@ protected ScriptAndCode execute(final Ruby runtime, final IRScriptBody scope, Cl
@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());
return (IRubyObject) compiledHandle.invokeWithArguments(context, scope.getStaticScope(), self, IRubyObject.NULL_ARRAY, block, self.getMetaClass(), Interpreter.ROOT);
} catch (Throwable t) {
Helpers.throwException(t);
return null; // not reached
@@ -109,7 +110,7 @@ public IRubyObject load(ThreadContext context, IRubyObject self, boolean wrap) {

try {
// runBeginEndBlocks(ic.getBeginBlocks(), context, self, scope, null);
return (IRubyObject) compiledHandle.invokeWithArguments(context, sscope, self, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, currModule);
return (IRubyObject) compiledHandle.invokeWithArguments(context, sscope, self, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, currModule, Interpreter.ROOT);
} catch (IRBreakJump bj) {
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} catch (Throwable t) {
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ public IRubyObject callHelper(ThreadContext context, StaticScope currScope, Dyna
return IRRuntimeHelpers.isDefinedCall(context, self, (IRubyObject) arg1, ((StringLiteral) operands[1]).getString());
case IS_DEFINED_CONSTANT_OR_METHOD:
return IRRuntimeHelpers.isDefinedConstantOrMethod(context, (IRubyObject) arg1,
((StringLiteral) operands[1]).getString());
((FrozenString) operands[1]).getString());
case IS_DEFINED_INSTANCE_VAR:
return IRRuntimeHelpers.isDefinedInstanceVar(context, (IRubyObject) arg1, ((StringLiteral) operands[1]).getString());
case IS_DEFINED_CLASS_VAR:
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
public class Interpreter extends IRTranslator<IRubyObject, IRubyObject> {
public static final Logger LOG = LoggerFactory.getLogger("Interpreter");
private static final IRubyObject[] EMPTY_ARGS = new IRubyObject[]{};
public static final String ROOT = "(root)";
static int interpInstrsCount = 0;

// we do not need instances of Interpreter
@@ -76,7 +77,7 @@ public static void runBeginBlocks(List<IRClosure> beBlocks, ThreadContext contex
protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject self) {
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.prepareForInterpretation();
ThreadContext context = runtime.getCurrentContext();
String name = "(root)";
String name = ROOT;

if (IRRuntimeHelpers.isDebug()) LOG.info("Executing " + ic);

22 changes: 4 additions & 18 deletions core/src/main/java/org/jruby/ir/operands/FrozenString.java
Original file line number Diff line number Diff line change
@@ -20,30 +20,20 @@
* for example, and modify the contents of the string.
* This is not like a Java string.
*/
public class FrozenString extends ImmutableLiteral {
final private ByteList bytelist;
private RubyString cached;

public class FrozenString extends StringLiteral {
public FrozenString(ByteList byteList) {
super(OperandType.STRING_LITERAL);

this.bytelist = byteList;
super(byteList);
}

public FrozenString(String s) {
this(ByteList.create(s));
super(s);
}

@Override
public Object createCacheObject(ThreadContext context) {
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
return context.runtime.freezeAndDedupString(RubyString.newString(context.runtime, bytelist));
}

@Override
public int hashCode() {
return bytelist.hashCode();
}

@Override
public boolean equals(Object other) {
return other instanceof FrozenString && bytelist.equals(((FrozenString) other).bytelist);
@@ -58,8 +48,4 @@ public String toString() {
public void visit(IRVisitor visitor) {
visitor.FrozenString(this);
}

public ByteList getByteList() {
return bytelist;
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -344,7 +344,8 @@ static MethodHandle buildJittedHandle(InvokeSite site, DynamicMethod method, boo

binder = binder
.insert(1, "scope", StaticScope.class, compiledIRMethod.getStaticScope())
.append("class", RubyModule.class, compiledIRMethod.getImplementationClass());
.append("class", RubyModule.class, compiledIRMethod.getImplementationClass())
.append("frameName", String.class, site.name());

mh = binder.invoke(mh).handle();
}
Original file line number Diff line number Diff line change
@@ -88,7 +88,12 @@ public void loadBlock() {
}

public void loadFrameClass() {
// when present, should be last element in signature
// when present, should be second-to-last element in signature
adapter.aload(signature.argCount() - 2);
}

public void loadFrameName() {
// when present, should be second-to-last element in signature
adapter.aload(signature.argCount() - 1);
}

4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -205,7 +205,7 @@ public void emitScope(IRScope scope, String name, Signature signature, boolean s

private static final Signature METHOD_SIGNATURE_BASE = Signature
.returning(IRubyObject.class)
.appendArgs(new String[]{"context", "scope", "self", "block", "class"}, ThreadContext.class, StaticScope.class, IRubyObject.class, Block.class, RubyModule.class);
.appendArgs(new String[]{"context", "scope", "self", "block", "class", "callName"}, ThreadContext.class, StaticScope.class, IRubyObject.class, Block.class, RubyModule.class, String.class);

public static final Signature signatureFor(IRScope method, boolean aritySplit) {
if (aritySplit) {
@@ -1435,7 +1435,7 @@ public void RaiseRequiredKeywordArgumentErrorInstr(RaiseRequiredKeywordArgumentE
public void PushFrameInstr(PushFrameInstr pushframeinstr) {
jvmMethod().loadContext();
jvmMethod().loadFrameClass();
jvmAdapter().ldc(pushframeinstr.getFrameName());
jvmMethod().loadFrameName();
jvmMethod().loadSelf();
jvmMethod().loadBlock();
jvmMethod().invokeVirtual(Type.getType(ThreadContext.class), Method.getMethod("void preMethodFrameOnly(org.jruby.RubyModule, String, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.Block)"));
13 changes: 12 additions & 1 deletion spec/compiler/general_spec.rb
Original file line number Diff line number Diff line change
@@ -60,7 +60,8 @@ def compile_to_method(src, filename, lineno)
oj.runtime.builtin.IRubyObject.java_class,
oj.runtime.builtin.IRubyObject[].java_class,
oj.runtime.Block.java_class,
oj.RubyModule.java_class);
oj.RubyModule.java_class,
java.lang.String.java_class);
handle = java.lang.invoke.MethodHandles.publicLookup().unreflect(scriptMethod);

return oj.internal.runtime.methods.CompiledIRMethod.new(
@@ -998,5 +999,15 @@ def a; true; end
x.should == [true, false, false]
end
end

it "pushes call name into frame" do
run('obj = Class.new do
def a; __callee__; end
define_method :b, instance_method(:a)
end.new
[obj.a, obj.b]') do |x|
x.should == [:a, :b]
end
end
end
end