Skip to content

Commit

Permalink
- __inline_* methods will inline based if ir.profile is enabled.
Browse files Browse the repository at this point in the history
- interpreter is not capable of deopt
  • Loading branch information
enebo committed Jan 26, 2017
1 parent 86b2dbb commit da8b39a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
22 changes: 21 additions & 1 deletion core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.jruby.runtime.Helpers;
import org.jruby.runtime.callsite.InliningCallSite;
import org.jruby.util.OneShotClassLoader;
import org.jruby.util.collections.IntHashMap;
import org.jruby.util.log.Logger;
Expand Down Expand Up @@ -602,6 +603,23 @@ public synchronized FullInterpreterContext prepareFullBuild(Compilable compilabl

fullInterpreterContext.generateInstructionsForIntepretation();

// Special logic for testing inliner (consider making this a different flag). The special named method
// will get a special callsite which will attempt to inline itself after the threshold marked by the
// inlining callsite caches cacheentry. So if I call a method n times then it will force an inline
// then the next time the parent method is called it should be with the forced inlined method.
if (RubyInstanceConfig.IR_PROFILE) {
Instr[] instructions = fullInterpreterContext.getInstructions();

for (Instr instr: instructions) {
if (instr instanceof CallBase) {
CallBase call = (CallBase) instr;
String name = call.getName();

if (name.startsWith("___inline___")) call.setCallSite(new InliningCallSite(call, this));
}
}
}

return fullInterpreterContext;
}

Expand Down Expand Up @@ -1093,6 +1111,7 @@ private FullInterpreterContext inlineMethodCommon(Compilable method, int classTo

// FIXME: Passing in DynamicMethod is gross here we probably can minimally cast to Compilable
public void inlineMethod(Compilable method, int classToken, BasicBlock basicBlock, CallBase call, boolean cloneHost) {
if (alreadyHasInline) return;
FullInterpreterContext newContext = inlineMethodCommon(method, classToken, basicBlock, call, cloneHost);

newContext.generateInstructionsForIntepretation();
Expand Down Expand Up @@ -1260,12 +1279,13 @@ public boolean needsBinding() {
}

public boolean isDeoptimizable() {
return false; // optimizedInterpreterContext != null;
return optimizedInterpreterContext != null;
}

public void deoptimize() {
optimizedInterpreterContext = null;

compilable.setInterpreterContext(fullInterpreterContext);
// FIXME: full should also delete any data associated with backing off to it.
}
}
Expand Up @@ -151,24 +151,6 @@ public void generateInstructionsForIntepretation() {
instructions = linearizedInstrArray;
temporaryVariablecount = getScope().getTemporaryVariablesCount();

// FIXME: Profiler will end up doing this but we are just hacking with magic name for now.
/*
for (Instr instr: instructions) {
if (instr instanceof CallBase) {
CallBase call = (CallBase) instr;
String name = call.getName();
// Our poor man's inliner will continue to see "else" branch with the original inline.
// we do not want it to happen again.
if (name.startsWith("___inline___")) {
if (call.getCallSite() instanceof InliningCallSite) {
// FIXME: This is some
call.setCallSite(CallBase.getCallSiteFor(call.getCallType(), call.getName(), call.isPotentiallyRefined()));
} else {
call.setCallSite(new InliningCallSite(call, getScope()));
}
}
}
}*/
// System.out.println("SCOPE: " + getScope().getName());
// System.out.println("INSTRS: " + cfg.toStringInstrs());
}
Expand Down
Expand Up @@ -212,6 +212,7 @@ public IRubyObject interpret(ThreadContext context, Compilable compilable, Block
break;
}
} catch (IRDeoptimization e) {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!DEOPTING");
IRScope scope = interpreterContext.getScope();
scope.deoptimize();
instrs = scope.getFullInterpreterContext().getInstructions();
Expand Down

0 comments on commit da8b39a

Please sign in to comment.