long x = csp.counters.get(s).count;
c += x;
cs.count += x;
}
CallBase call = cs.call;
if (calledScopes.size() == 1 && !call.inliningBlocked()) {
CallSite runtimeCS = call.getCallSite();
if (runtimeCS != null && (runtimeCS instanceof CachingCallSite)) {
CachingCallSite ccs = (CachingCallSite)runtimeCS;
CacheEntry ce = ccs.getCache();
if (!(ce.method instanceof InterpretedIRMethod)) {
// System.out.println("NOT IR-M!");
continue;
} else {
callSites.add(cs);
cs.tgtM = (InterpretedIRMethod)ce.method;
}
}
}
total += cs.count;
}
Collections.sort(callSites, new java.util.Comparator<IRCallSite> () {
@Override
public int compare(IRCallSite a, IRCallSite b) {
if (a.count == b.count) return 0;
return (a.count < b.count) ? 1 : -1;
}
});
// Find top N call sites
double freq = 0.0;
int i = 0;
boolean noInlining = true;
Set<IRScope> inlinedScopes = new HashSet<IRScope>();
for (IRCallSite ircs: callSites) {
double contrib = (ircs.count*100.0)/total;
// 1% is arbitrary
if (contrib < 1.0) break;
i++;
freq += contrib;
// This check is arbitrary
if (i == 100 || freq > 99.0) break;
// System.out.println("Considering: " + ircs.call + " with id: " + ircs.call.callSiteId +
// " in scope " + ircs.s + " with count " + ircs.count + "; contrib " + contrib + "; freq: " + freq);
// Now inline here!
CallBase call = ircs.call;
IRScope hs = ircs.s;
boolean isHotClosure = hs instanceof IRClosure;
IRScope hc = isHotClosure ? hs : null;
hs = isHotClosure ? hs.getLexicalParent() : hs;
IRScope tgtMethod = ircs.tgtM.getIRMethod();
Instr[] instrs = tgtMethod.getInterpreterContext().getInstructions();
// Dont inline large methods -- 500 is arbitrary
// Can be null if a previously inlined method hasn't been rebuilt
if ((instrs == null) || instrs.length > 500) {
// if (instrs == null) System.out.println("no instrs!");
// else System.out.println("large method with " + instrs.length + " instrs. skipping!");
continue;
}
RubyModule implClass = ircs.tgtM.getImplementationClass();
int classToken = implClass.getGeneration();
String n = tgtMethod.getName();
boolean inlineCall = true;
if (isHotClosure) {
Operand clArg = call.getClosureArg(null);
inlineCall = (clArg instanceof WrappedIRClosure) && (((WrappedIRClosure)clArg).getClosure() == hc);
}
if (inlineCall) {
noInlining = false;