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: 31842aea476f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 243de08b6fb0
Choose a head ref
  • 3 commits
  • 11 files changed
  • 1 contributor

Commits on Aug 12, 2017

  1. Copy the full SHA
    5ff2b3e View commit details
  2. Copy the full SHA
    baa1ab2 View commit details
  3. Copy the full SHA
    243de08 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/compiler/BlockJITTask.java
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ public BlockJITTask(JITCompiler jitCompiler, MixedModeIRBlockBody body, String c
public void run() {
try {
String key = SexpMaker.sha1(body.getIRScope());
JVMVisitor visitor = new JVMVisitor();
JVMVisitor visitor = new JVMVisitor(jitCompiler.runtime);
BlockJITClassGenerator generator = new BlockJITClassGenerator(className, methodName, key, jitCompiler.runtime, body, visitor);

JVMVisitorMethodContext context = new JVMVisitorMethodContext();
8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/compiler/MethodJITTask.java
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
package org.jruby.compiler;

import org.jruby.MetaClass;
import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.ast.util.SexpMaker;
import org.jruby.internal.runtime.methods.CompiledIRMethod;
@@ -77,8 +78,9 @@ public void run() {
}

String key = SexpMaker.sha1(method.getIRScope());
JVMVisitor visitor = new JVMVisitor();
MethodJITClassGenerator generator = new MethodJITClassGenerator(className, methodName, key, jitCompiler.runtime, method, visitor);
Ruby runtime = jitCompiler.runtime;
JVMVisitor visitor = new JVMVisitor(runtime);
MethodJITClassGenerator generator = new MethodJITClassGenerator(className, methodName, key, runtime, method, visitor);

JVMVisitorMethodContext context = new JVMVisitorMethodContext();
generator.compile(context);
@@ -88,7 +90,7 @@ public void run() {
// that's so big that JVMs won't even try to compile it. Removed the check because with the new IR JIT
// bytecode counts often include all nested scopes, even if they'd be different methods. We need a new
// mechanism of getting all method sizes.
Class sourceClass = visitor.defineFromBytecode(method.getIRScope(), generator.bytecode(), new OneShotClassLoader(jitCompiler.runtime.getJRubyClassLoader()));
Class sourceClass = visitor.defineFromBytecode(method.getIRScope(), generator.bytecode(), new OneShotClassLoader(runtime.getJRubyClassLoader()));

if (sourceClass == null) {
// class could not be found nor generated; give up on JIT and bail out
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/Compiler.java
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ protected ScriptAndCode execute(final Ruby runtime, final IRScriptBody scope, Cl
}

try {
JVMVisitor visitor = new JVMVisitor();
JVMVisitor visitor = new JVMVisitor(runtime);
JVMVisitorMethodContext context = new JVMVisitorMethodContext();
bytecode = visitor.compileToBytecode(scope, context);
Class compiled = visitor.defineFromBytecode(scope, bytecode, classLoader);
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -2495,7 +2495,8 @@ public Operand buildDStr(Variable result, DStrNode node) {
}

if (result == null) result = createTemporaryVariable();
addInstr(new BuildCompoundStringInstr(result, pieces, node.getEncoding(), node.isFrozen(), getFileName(), node.getLine()));
boolean debuggingFrozenStringLiteral = manager.getInstanceConfig().isDebuggingFrozenStringLiteral();
addInstr(new BuildCompoundStringInstr(result, pieces, node.getEncoding(), node.isFrozen(), debuggingFrozenStringLiteral, getFileName(), node.getLine()));
return result;
}

@@ -2507,7 +2508,8 @@ public Operand buildDSymbol(Variable result, DSymbolNode node) {
}

if (result == null) result = createTemporaryVariable();
addInstr(new BuildCompoundStringInstr(result, pieces, node.getEncoding(), false, getFileName(), node.getLine()));
boolean debuggingFrozenStringLiteral = manager.getInstanceConfig().isDebuggingFrozenStringLiteral();
addInstr(new BuildCompoundStringInstr(result, pieces, node.getEncoding(), false, debuggingFrozenStringLiteral, getFileName(), node.getLine()));
return copyAndReturnValue(new DynamicSymbol(result));
}

Original file line number Diff line number Diff line change
@@ -24,14 +24,16 @@
public class BuildCompoundStringInstr extends NOperandResultBaseInstr {
final private Encoding encoding;
final private boolean frozen;
final private boolean debug;
final private String file;
final private int line;

public BuildCompoundStringInstr(Variable result, Operand[] pieces, Encoding encoding, boolean frozen, String file, int line) {
public BuildCompoundStringInstr(Variable result, Operand[] pieces, Encoding encoding, boolean frozen, boolean debug, String file, int line) {
super(Operation.BUILD_COMPOUND_STRING, result, pieces);

this.encoding = encoding;
this.frozen = frozen;
this.debug = debug;
this.file = file;
this.line = line;
}
@@ -46,7 +48,7 @@ public Encoding getEncoding() {

@Override
public Instr clone(CloneInfo ii) {
return new BuildCompoundStringInstr(ii.getRenamedVariable(result), cloneOperands(ii), encoding, frozen, file, line);
return new BuildCompoundStringInstr(ii.getRenamedVariable(result), cloneOperands(ii), encoding, frozen, debug, file, line);
}

public boolean isSameEncodingAndCodeRange(RubyString str, StringLiteral newStr) {
@@ -64,7 +66,8 @@ public void encode(IRWriterEncoder e) {
}

public static BuildCompoundStringInstr decode(IRReaderDecoder d) {
return new BuildCompoundStringInstr(d.decodeVariable(), d.decodeOperandArray(), d.decodeEncoding(), d.decodeBoolean(), d.decodeString(), d.decodeInt());
boolean debuggingFrozenStringLiteral = d.getCurrentScope().getManager().getInstanceConfig().isDebuggingFrozenStringLiteral();
return new BuildCompoundStringInstr(d.decodeVariable(), d.decodeOperandArray(), d.decodeEncoding(), d.decodeBoolean(), debuggingFrozenStringLiteral, d.decodeString(), d.decodeInt());
}

@Override
@@ -82,7 +85,13 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
}
}

return frozen ? IRRuntimeHelpers.freezeLiteralString(context, str, file, line) : str;
if (frozen) {
if (debug) {
return IRRuntimeHelpers.freezeLiteralString(str, context, file, line);
}
return IRRuntimeHelpers.freezeLiteralString(str);
}
return str;
}

@Override
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/operands/Filename.java
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import org.jruby.ir.IRVisitor;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
@@ -47,7 +48,7 @@ public void visit(IRVisitor visitor) {

@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
return context.runtime.newString(currScope.getIRScope().getFileName());
return IRRuntimeHelpers.getFileNameStringFromScope(context, currScope);
}

@Override
10 changes: 3 additions & 7 deletions core/src/main/java/org/jruby/ir/operands/FrozenString.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jruby.ir.operands;

import org.jruby.RubyString;
import org.jruby.ir.IRVisitor;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
@@ -16,7 +17,7 @@
/**
* Represents a frozen string value.
*/
public class FrozenString extends ImmutableLiteral implements Stringable {
public class FrozenString extends ImmutableLiteral<RubyString> implements Stringable {
// SSS FIXME: Pick one of bytelist or string, or add internal conversion methods to convert to the default representation

public final ByteList bytelist;
@@ -79,11 +80,6 @@ public boolean hasKnownValue() {
return true;
}

@Override
public void addUsedVariables(List<Variable> l) {
/* Do nothing */
}

@Override
public int hashCode() {
return bytelist.hashCode();
@@ -105,7 +101,7 @@ public Operand cloneForInlining(CloneInfo ii) {
}

@Override
public Object createCacheObject(ThreadContext context) {
public RubyString createCacheObject(ThreadContext context) {
return IRRuntimeHelpers.newFrozenString(context, bytelist, coderange, file, line);
}

10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/ir/operands/ImmutableLiteral.java
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@
* side-effect free as well, but this is difficult without adding a level of
* indirection or pre-caching each value we encounter during construction.
*/
public abstract class ImmutableLiteral extends Operand {
private Object cachedObject = null;
public abstract class ImmutableLiteral<T> extends Operand {
private T cachedObject = null;

public ImmutableLiteral() {
super();
@@ -53,13 +53,13 @@ public Operand cloneForInlining(CloneInfo ii) {
/**
* Implementing class is responsible for constructing the cached value.
*/
public abstract Object createCacheObject(ThreadContext context);
public abstract T createCacheObject(ThreadContext context);

/**
* Returns the cached object. If not then it asks class to create an
* object to cache.
*/
public Object cachedObject(ThreadContext context) {
public T cachedObject(ThreadContext context) {
if (!isCached()) cachedObject = createCacheObject(context);

return cachedObject;
@@ -80,7 +80,7 @@ public boolean isCached() {
* assume the cost of constructing literals which may never be used.
*/
@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
public T retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
return cachedObject(context);
}
}
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ir/operands/StringLiteral.java
Original file line number Diff line number Diff line change
@@ -83,8 +83,7 @@ public Operand cloneForInlining(CloneInfo ii) {

@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
RubyString string = (RubyString) frozenString.retrieve(context, self, currScope, currDynScope, temp);
return string.strDup(context.runtime);
return frozenString.retrieve(context, self, currScope, currDynScope, temp).strDup(context.runtime);
}

@Override
16 changes: 14 additions & 2 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jruby.ir.runtime;

import com.headius.invokebinder.Signature;
import jnr.ffi.annotations.In;
import org.jcodings.Encoding;
import org.jruby.*;
import org.jruby.common.IRubyWarnings;
@@ -1898,7 +1899,15 @@ public static RubyString newFrozenString(ThreadContext context, ByteList bytelis
return string;
}

public static RubyString freezeLiteralString(ThreadContext context, RubyString string, String file, int line) {
@JIT @Interp
public static RubyString freezeLiteralString(RubyString string) {
string.setFrozen(true);

return string;
}

@JIT @Interp
public static RubyString freezeLiteralString(RubyString string, ThreadContext context, String file, int line) {
Ruby runtime = context.runtime;

if (runtime.getInstanceConfig().isDebuggingFrozenStringLiteral()) {
@@ -1975,7 +1984,10 @@ public static RubyArray newArray(ThreadContext context, IRubyObject obj0, IRubyO
}

@JIT @Interp

public static RubyString getFileNameStringFromScope(ThreadContext context, StaticScope currScope) {
// FIXME: Not very efficient to do all this every time
return context.runtime.newString(currScope.getIRScope().getFileName());
}

private static IRRuntimeHelpersSites sites(ThreadContext context) {
return context.sites.IRRuntimeHelpers;
27 changes: 14 additions & 13 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -73,10 +73,11 @@ public class JVMVisitor extends IRVisitor {
.returning(IRubyObject.class)
.appendArgs(new String[]{"context", SELF_BLOCK_NAME, "scope", "self", "args", BLOCK_ARG_NAME, "superName", "type"}, ThreadContext.class, Block.class, StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, String.class, Block.Type.class);

public JVMVisitor() {
public JVMVisitor(Ruby runtime) {
this.jvm = Options.COMPILE_INVOKEDYNAMIC.load() ? new JVM7() : new JVM6();
this.methodIndex = 0;
this.scopeMap = new HashMap();
this.runtime = runtime;
}

public Class compile(IRScope scope, ClassDefiningClassLoader jrubyClassLoader) {
@@ -982,11 +983,14 @@ public void BuildCompoundStringInstr(BuildCompoundStringInstr compoundstring) {
}
}
if (compoundstring.isFrozen()) {
jvmMethod().loadContext();
jvmAdapter().swap();
jvmAdapter().ldc(compoundstring.getFile());
jvmAdapter().ldc(compoundstring.getLine());
jvmMethod().invokeIRHelper("freezeLiteralString", sig(RubyString.class, ThreadContext.class, RubyString.class, String.class, int.class));
if (runtime.getInstanceConfig().isDebuggingFrozenStringLiteral()) {
jvmMethod().loadContext();
jvmAdapter().ldc(compoundstring.getFile());
jvmAdapter().ldc(compoundstring.getLine());
jvmMethod().invokeIRHelper("freezeLiteralString", sig(RubyString.class, RubyString.class, ThreadContext.class, String.class, int.class));
} else {
jvmMethod().invokeIRHelper("freezeLiteralString", sig(RubyString.class, RubyString.class));
}
}
jvmStoreLocal(compoundstring.getResult());
}
@@ -2342,15 +2346,11 @@ public void DynamicSymbol(DynamicSymbol dynamicsymbol) {

@Override
public void Filename(Filename filename) {
// Fixme: Not very efficient to do all this every time
jvmMethod().loadRuntime();
jvmMethod().loadContext();
jvmMethod().loadStaticScope();
jvmAdapter().invokevirtual(p(StaticScope.class), "getIRScope", sig(IRScope.class));
jvmAdapter().invokevirtual(p(IRScope.class), "getFileName", sig(String.class));
jvmAdapter().invokevirtual(p(Ruby.class), "newString", sig(RubyString.class, String.class));
jvmMethod().invokeIRHelper("getFileNameStringFromScope", sig(RubyString.class, ThreadContext.class, StaticScope.class));
}


@Override
public void Fixnum(Fixnum fixnum) {
jvmMethod().pushFixnum(fixnum.getValue());
@@ -2601,7 +2601,8 @@ private IRBytecodeAdapter jvmMethod() {
return jvm.method();
}

private JVM jvm;
private final JVM jvm;
private final Ruby runtime;
private int methodIndex;
private Map<String, IRScope> scopeMap;
private String file;