Skip to content

Commit

Permalink
using implclass for generation number was wrong. We should use self to
Browse files Browse the repository at this point in the history
figure this out since we want most specific type.  Fixes errant guard
trigger.
enebo committed Jan 25, 2017
1 parent 8c93786 commit a82d673
Showing 5 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -614,7 +614,6 @@ public boolean isFullBuildComplete() {
/** Run any necessary passes to get the IR ready for compilation */
public synchronized BasicBlock[] prepareForCompilation() {
if (optimizedInterpreterContext != null) {
System.out.println("OIC BBLISTY: " + optimizedInterpreterContext.getLinearizedBBList());
return optimizedInterpreterContext.getLinearizedBBList();
}

Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ public IRubyObject interpret(ThreadContext context, Compilable compilable, Block
receiveArg(context, instr, operation, args, acceptsKeywordArgument, currDynScope, temp, exception, blockArg);
break;
case CALL_OP:
if (profile) Profiler.markCallAboutToBeCalled((CallBase) instr, interpreterContext);
if (profile) Profiler.markCallAboutToBeCalled((CallBase) instr, interpreterContext, self);
processCall(context, instr, operation, currDynScope, currScope, temp, self);
break;
case RET_OP:
21 changes: 13 additions & 8 deletions core/src/main/java/org/jruby/ir/interpreter/Profiler.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.representations.BasicBlock;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CachingCallSite;

import java.util.*;
@@ -62,6 +63,7 @@ public static class IRCallSite {
private CallBase call = null; // which instr is at this callsite
long count; // how many times callsite has been executed
Compilable liveMethod; // winner winner chicken dinner we think we have monomorphic target method to inline.
int generation = -1;

public IRCallSite() {}

@@ -70,6 +72,7 @@ public IRCallSite(IRCallSite cs) {
id = cs.id;
call = cs.call;
count = 0;
generation = cs.generation;
}

/**
@@ -95,15 +98,17 @@ public int hashCode() {
return (int) call.getSiteId();
}

public void update(long callSiteId, IRScope scope) {
public void update(long callSiteId, IRScope scope, int generation) {
this.scope = scope;
this.id = callSiteId;
this.generation = generation;
}

public void update(CallBase call, IRScope scope) {
public void update(CallBase call, IRScope scope, int generation) {
this.scope = scope;
this.id = call.getSiteId();
this.call = call;
this.generation = generation;
}
}

@@ -330,7 +335,7 @@ private static void analyzeProfile() {
}
RubyModule implClass = methodToInline.getImplementationClass();
long start = new java.util.Date().getTime();
parentIC.getScope().inlineMethodJIT(methodToInline, implClass, implClass.getGeneration(), null, call, false);//!inlinedScopes.contains(ic));
parentIC.getScope().inlineMethodJIT(methodToInline, implClass, callSite.generation, null, call, false);//!inlinedScopes.contains(ic));
inlinedScopes.add(parentIC.getScope());
long end = new java.util.Date().getTime();
if (Options.IR_PROFILE_DEBUG.load()) LOG.info("Inlined " + methodToInline.getName() + " into " + parentIC.getName() + " @ instr " + callSite.getCall() +
@@ -341,7 +346,7 @@ private static void analyzeProfile() {
if (shouldInline(scope, callSite.getCall(), parentIC, isClosure)) {
RubyModule implClass = methodToInline.getImplementationClass();
long start = new java.util.Date().getTime();
parentIC.getScope().inlineMethod(methodToInline, implClass, implClass.getGeneration(), null, callSite.getCall(), false);//!inlinedScopes.contains(ic));
parentIC.getScope().inlineMethod(methodToInline, implClass, callSite.generation, null, callSite.getCall(), false);//!inlinedScopes.contains(ic));
inlinedScopes.add(parentIC.getScope());
long end = new java.util.Date().getTime();
if (Options.IR_PROFILE_DEBUG.load()) LOG.info("Inlined " + methodToInline.getName() + " into " + parentIC.getName() + " @ instr " + callSite.getCall() +
@@ -413,15 +418,15 @@ public static void initProfiling(IRScope scope) {
}

@JIT
public static void markCallAboutToBeCalled(long callsiteId, IRScope scope) {
public static void markCallAboutToBeCalled(long callsiteId, IRScope scope, IRubyObject self) {
callerSite.call = null;
callerSite.update(callsiteId, scope);
callerSite.update(callsiteId, scope, self.getMetaClass().getGeneration());
}

// We do not pass profiling instructions through call so we temporarily tuck away last IR executed
// call in Profiler.
public static void markCallAboutToBeCalled(CallBase call, InterpreterContext ic) {
callerSite.update(call, ic.getScope());
public static void markCallAboutToBeCalled(CallBase call, InterpreterContext ic, IRubyObject self) {
callerSite.update(call, ic.getScope(), self.getMetaClass().getGeneration());
}

public static void clockTick() {
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -1079,7 +1079,8 @@ public void CallInstr(CallInstr callInstr) {
if (Options.IR_PROFILE.load()) {
jvmAdapter().ldc(callInstr.getSiteId());
jvmAdapter().getstatic(jvm.clsData().clsName, jvm.clsData().methodData().method.adapter.getName() + "_IRScope", ci(IRScope.class));
jvmAdapter().invokestatic(p(Profiler.class), "markCallAboutToBeCalled", sig(void.class, long.class, IRScope.class));
m.loadSelf();
jvmAdapter().invokestatic(p(Profiler.class), "markCallAboutToBeCalled", sig(void.class, long.class, IRScope.class, IRubyObject.class));
}

compileCallCommon(m, name, args, receiver, numArgs, closure, hasClosure, callType, result, callInstr.isPotentiallyRefined());
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -2194,7 +2194,7 @@ public static boolean isGenerationEqual(IRubyObject object, int generation) {
@JIT
public static void checkGeneration(IRubyObject object, int generation, int ipc) {
if (!isGenerationEqual(object, generation)) {
// throw new IRDeoptimization(ipc);
throw new IRDeoptimization(ipc);
}
}

0 comments on commit a82d673

Please sign in to comment.