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

Commits on Feb 22, 2016

  1. Copy the full SHA
    f98233f View commit details
  2. Copy the full SHA
    6068a5f View commit details
  3. Copy the full SHA
    63694c0 View commit details
  4. Copy the full SHA
    fb895e2 View commit details
  5. Copy the full SHA
    deac0d6 View commit details
  6. Copy the full SHA
    8f0378e View commit details
22 changes: 14 additions & 8 deletions core/src/main/java/org/jruby/compiler/JITCompiler.java
Original file line number Diff line number Diff line change
@@ -236,12 +236,12 @@ public void run() {
}

if ((config.getExcludedMethods().contains(excludeModuleName)
|| config.getExcludedMethods().contains(excludeModuleName + "#" + methodName)
|| config.getExcludedMethods().contains(excludeModuleName + '#' + methodName)
|| config.getExcludedMethods().contains(methodName))) {
method.setCallCount(-1);

if (config.isJitLogging()) {
log(method.getImplementationClass(), method.getFile(), method.getLine(), methodName, "skipping method: " + excludeModuleName + "#" + methodName);
log(method.getImplementationClass(), method.getFile(), method.getLine(), methodName, "skipping method: " + excludeModuleName + '#' + methodName);
}
return;
}
@@ -446,6 +446,14 @@ protected void compile(JVMVisitorMethodContext context) {
// CON FIXME: Really should clone scope before passes in any case
bytecode = visitor.compileToBytecode(method.getIRScope(), context);

// try {
// java.io.FileOutputStream fos = new java.io.FileOutputStream(className + '#' + methodName + ".class");
// fos.write(bytecode);
// fos.close();
// } catch (Exception e) {
// e.printStackTrace();
// }

compileTime = System.nanoTime() - start;
}

@@ -584,16 +592,14 @@ static void log(RubyModule implementationClass, String file, int line, String na
String className = isBlock ? "<block>" : implementationClass.getBaseName();
if (className == null) className = "<anon class>";

name = isBlock ? "" : "." + name;

StringBuilder builder = new StringBuilder(32);
builder.append(message).append(':').append(className).append(name).append(" at ").append(file).append(':').append(line);
builder.append(message).append(": ").append(className)
.append(' ').append(name == null ? "" : name)
.append(" at ").append(file).append(':').append(line);

if (reason.length > 0) {
builder.append(" because of: \"");
for (String aReason : reason) {
builder.append(aReason);
}
for (String aReason : reason) builder.append(aReason);
builder.append('"');
}

Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ protected void pre(ThreadContext context, StaticScope staticScope, RubyModule im
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
if (!hasExplicitCallProtocol) return callNoProtocol(context, self, name, args, block);

if (hasKwargs) IRRuntimeHelpers.frobnicateKwargsArgument(context, getSignature().required(), args);
if (hasKwargs) IRRuntimeHelpers.frobnicateKwargsArgument(context, args, getSignature().required());

return invokeExact(this.variable, context, staticScope, self, args, block, implementationClass, name);
}
@@ -133,7 +133,7 @@ private IRubyObject callNoProtocol(ThreadContext context, IRubyObject self, Stri
RubyModule implementationClass = this.implementationClass;
pre(context, staticScope, implementationClass, self, name, block);

if (hasKwargs) IRRuntimeHelpers.frobnicateKwargsArgument(context, getSignature().required(), args);
if (hasKwargs) IRRuntimeHelpers.frobnicateKwargsArgument(context, args, getSignature().required());

try {
return invokeExact(this.variable, context, staticScope, self, args, block, implementationClass, name);
@@ -206,6 +206,11 @@ public int getLine() {
return method.getLineNumber();
}

@Override
public String toString() {
return getClass().getName() + '@' + Integer.toHexString(hashCode()) + ' ' + method + ' ' + getSignature();
}

private static IRubyObject invokeExact(MethodHandle method,
ThreadContext context, StaticScope staticScope, IRubyObject self,
IRubyObject[] args, Block block,
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -713,7 +713,7 @@ public void computeScopeFlags() {

@Override
public String toString() {
return getScopeType() + " " + getName() + "[" + getFileName() + ":" + getLineNumber() + "]";
return String.valueOf(getScopeType()) + ' ' + getName() + '[' + getFileName() + ':' + getLineNumber() + ']';
}

public String debugOutput() {
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel

// Blocks with explicit call protocol shouldn't do this before args are prepared
if (acceptsKeywordArgument && (block == null || !interpreterContext.hasExplicitCallProtocol())) {
IRRuntimeHelpers.frobnicateKwargsArgument(context, interpreterContext.getRequiredArgsCount(), args);
IRRuntimeHelpers.frobnicateKwargsArgument(context, args, interpreterContext.getRequiredArgsCount());
}

StaticScope currScope = interpreterContext.getStaticScope();
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
int ipc = 0;
Object exception = null;

if (interpreterContext.receivesKeywordArguments()) IRRuntimeHelpers.frobnicateKwargsArgument(context, interpreterContext.getRequiredArgsCount(), args);
if (interpreterContext.receivesKeywordArguments()) IRRuntimeHelpers.frobnicateKwargsArgument(context, args, interpreterContext.getRequiredArgsCount());

StaticScope currScope = interpreterContext.getStaticScope();
DynamicScope currDynScope = context.getCurrentScope();
27 changes: 16 additions & 11 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -554,8 +554,10 @@ public static void checkArity(ThreadContext context, Object[] args, int required
// Due to our current strategy of destructively processing the kwargs hash we need to dup
// and make sure the copy is not frozen. This has a poor name as encouragement to rewrite
// how we handle kwargs internally :)
public static void frobnicateKwargsArgument(ThreadContext context, int requiredArguments, IRubyObject[] args) {
RubyHash kwargs = IRRuntimeHelpers.extractKwargsHash(args, requiredArguments, true);
public static void frobnicateKwargsArgument(ThreadContext context, IRubyObject[] args, int requiredArgsCount) {
if (args.length <= requiredArgsCount) return; // No kwarg because required args slurp them up.

RubyHash kwargs = toHash(args[args.length - 1], context);

if (kwargs != null) {
kwargs = (RubyHash) kwargs.dup(context);
@@ -564,20 +566,23 @@ public static void frobnicateKwargsArgument(ThreadContext context, int requiredA
}
}

private static RubyHash toHash(IRubyObject lastArg, ThreadContext context) {
if (lastArg instanceof RubyHash) return (RubyHash) lastArg;
if (lastArg.respondsTo("to_hash")) {
if ( context == null ) context = lastArg.getRuntime().getCurrentContext();
lastArg = lastArg.callMethod(context, "to_hash");
if (lastArg instanceof RubyHash) return (RubyHash) lastArg;
}
return null;
}

public static RubyHash extractKwargsHash(Object[] args, int requiredArgsCount, boolean receivesKwargs) {
if (!receivesKwargs) return null;
if (args.length <= requiredArgsCount) return null; // No kwarg because required args slurp them up.

Object lastArg = args[args.length - 1];

if (lastArg instanceof RubyHash) return (RubyHash) lastArg;

if (((IRubyObject) lastArg).respondsTo("to_hash")) {
lastArg = ((IRubyObject) lastArg).callMethod(((IRubyObject) lastArg).getRuntime().getCurrentContext(), "to_hash");

if (lastArg instanceof RubyHash) return (RubyHash) lastArg;
}

if (lastArg instanceof IRubyObject) return toHash((IRubyObject) lastArg, null);
return null;
}

@@ -1666,7 +1671,7 @@ public static IRubyObject[] prepareFixedBlockArgs(ThreadContext context, Block b
public static IRubyObject[] prepareBlockArgs(ThreadContext context, Block block, IRubyObject[] args, boolean usesKwArgs) {
args = prepareBlockArgsInternal(context, block, args);
if (usesKwArgs) {
frobnicateKwargsArgument(context, block.getBody().getSignature().required(), args);
frobnicateKwargsArgument(context, args, block.getBody().getSignature().required());
}
return args;
}
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/ir/targets/ClassData.java
Original file line number Diff line number Diff line change
@@ -81,10 +81,10 @@ public void popmethod() {

public ClassVisitor cls;
public final String clsName;
Stack<MethodData> methodStack = new Stack();
public AtomicInteger callSiteCount = new AtomicInteger(0);
public Set<Integer> arrayMethodsDefined = new HashSet();
public Set<Integer> hashMethodsDefined = new HashSet();
public Set<Integer> kwargsHashMethodsDefined = new HashSet();
public Set<Integer> dregexpMethodsDefined = new HashSet();
final Stack<MethodData> methodStack = new Stack();
public final AtomicInteger callSiteCount = new AtomicInteger(0);
public final Set<Integer> arrayMethodsDefined = new HashSet(4, 1);
public final Set<Integer> hashMethodsDefined = new HashSet(4, 1);
public final Set<Integer> kwargsHashMethodsDefined = new HashSet(4, 1);
public final Set<Integer> dregexpMethodsDefined = new HashSet(4, 1);
}
Original file line number Diff line number Diff line change
@@ -785,7 +785,7 @@ public void kwargsHash(int length) {
adapter2.areturn();
adapter2.end();

getClassData().hashMethodsDefined.add(length);
getClassData().kwargsHashMethodsDefined.add(length);
}

// now call it
11 changes: 1 addition & 10 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -85,15 +85,6 @@ public Class compile(IRScope scope, ClassDefiningClassLoader jrubyClassLoader) {

public byte[] compileToBytecode(IRScope scope, JVMVisitorMethodContext context) {
codegenScope(scope, context);

// try {
// FileOutputStream fos = new FileOutputStream("tmp.class");
// fos.write(target.code());
// fos.close();
// } catch (Exception e) {
// e.printStackTrace();
// }

return code();
}

@@ -142,7 +133,7 @@ public void emitScope(IRScope scope, String name, Signature signature, boolean s
LOG.info("Printing JIT IR for " + scope.getName(), "\n" + new String(baos.toByteArray()));
}

Map <BasicBlock, Label> exceptionTable = scope.buildJVMExceptionTable();
Map<BasicBlock, Label> exceptionTable = scope.buildJVMExceptionTable();

emitClosures(scope, print);