use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method printSizeResult.
public void printSizeResult(DFATool program) {
for (InstructionHandle instr : sizes.keySet()) {
ContextMap<CallString, Interval[]> r = sizes.get(instr);
Context c = r.getContext();
LineNumberTable lines = c.getMethodInfo().getCode().getLineNumberTable();
int sourceLine = lines.getSourceLine(instr.getPosition());
for (CallString callString : r.keySet()) {
Interval[] bounds = r.get(callString);
System.out.println(c.method() + ":" + sourceLine + ":\t" + callString.toStringList() + ": ");
System.out.println(Arrays.asList(bounds));
}
}
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method doInvoke.
private void doInvoke(String methodName, InstructionHandle stmt, Context context, Map<CallString, Map<Location, ValueMapping>> input, Interpreter<CallString, Map<Location, ValueMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Map<Location, ValueMapping>>> state, Map<CallString, Map<Location, ValueMapping>> result) {
DFATool p = interpreter.getDFATool();
MethodInfo method = p.getMethod(methodName);
if (method.isNative()) {
handleNative(method, context, input, result);
} else {
// set up new context
int varPtr = context.stackPtr - MethodHelper.getArgSize(method);
Context c = new Context(context);
c.stackPtr = method.getCode().getMaxLocals();
if (method.isSynchronized()) {
c.syncLevel = context.syncLevel + 1;
}
c.setMethodInfo(method);
c.callString = c.callString.push(method, stmt, callStringLength);
// carry only minimal information with call
Map<Location, ValueMapping> in = input.get(context.callString);
Map<Location, ValueMapping> out = new LinkedHashMap<Location, ValueMapping>();
for (Location l : in.keySet()) {
if (l.stackLoc < 0) {
out.put(l, in.get(l));
}
if (l.stackLoc >= varPtr) {
out.put(new Location(l.stackLoc - varPtr), new ValueMapping(in.get(l), false));
}
}
ContextMap<CallString, Map<Location, ValueMapping>> tmpresult = new ContextMap<CallString, Map<Location, ValueMapping>>(c, new LinkedHashMap<CallString, Map<Location, ValueMapping>>());
tmpresult.put(c.callString, out);
InstructionHandle entry = p.getEntryHandle(method);
state.put(entry, join(state.get(entry), tmpresult));
// interpret method
Map<InstructionHandle, ContextMap<CallString, Map<Location, ValueMapping>>> r = interpreter.interpret(c, entry, state, false);
//System.out.println(">>>>>>>>");
// pull out relevant information from call
InstructionHandle exit = p.getExitHandle(method);
if (r.get(exit) != null) {
Map<Location, ValueMapping> returned = r.get(exit).get(c.callString);
if (returned != null) {
for (Location l : returned.keySet()) {
if (l.stackLoc < 0) {
ValueMapping m = new ValueMapping(returned.get(l), true);
m.join(result.get(context.callString).get(l));
result.get(context.callString).put(l, m);
}
if (l.stackLoc >= 0) {
ValueMapping m = new ValueMapping(returned.get(l), false);
Location loc = new Location(l.stackLoc + varPtr);
m.join(result.get(context.callString).get(loc));
result.get(context.callString).put(loc, m);
}
}
}
}
// add relevant information to result
for (Location l : in.keySet()) {
if (l.stackLoc >= 0 && l.stackLoc < context.stackPtr - MethodHelper.getArgSize(method)) {
result.get(context.callString).put(l, new ValueMapping(in.get(l), true));
}
}
}
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method getArrayIndices.
public Interval getArrayIndices(InstructionHandle stmt, CallString cs) {
ContextMap<CallString, Interval> map = arrayIndices.get(stmt);
Interval retval = null;
if (map == null) {
return retval;
}
for (CallString c : map.keySet()) {
if (c.hasSuffix(cs)) {
if (retval == null) {
retval = new Interval(map.get(c));
} else {
retval.join(map.get(c));
}
}
}
return retval;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class SimpleInliner method optimizeMethod.
@Override
public void optimizeMethod(MethodInfo method) {
InlineData inlineData = new InlineData();
List<InvokeSite> invokes = new ArrayList<InvokeSite>(method.getCode().getInvokeSites());
// we iterate over the invoke sites in a sorted order for the single reason that the DFA cache hack works
// (else the order of the entries in the constantpool can differ)
Collections.sort(invokes, new Comparator<InvokeSite>() {
@Override
public int compare(InvokeSite o1, InvokeSite o2) {
return o1.getInstructionHandle().getPosition() - o2.getInstructionHandle().getPosition();
}
});
for (InvokeSite invoke : invokes) {
// The callstring contains 'original' invokesites from the unmodified callgraph,
// 'invoke' refers to the new invokesite in the modified code
CallString cs = new CallString(invoke);
while (invoke != null) {
countInvokeSites++;
MethodInfo invokee = helper.devirtualize(cs);
if (invokee == null)
break;
countDevirtualized++;
// Preliminary checks
if (checkInvoke(invoke, cs, invokee, inlineData)) {
invoke = performSimpleInline(invoke, invokee, inlineData);
inlineCounter++;
if (inlineData.getInvokeSite() != null) {
cs.push(inlineData.getInvokeSite());
} else {
break;
}
} else {
break;
}
}
}
// update callgraph (?) If we update the callgraph, the callstrings become invalid!
// -> update callgraph only after we finished inlining of a toplevel invokesite;
// collect all invokesites to collapse into toplevel invokesite;
// replace old invokesite with invokesites from inlined code, add edges to not inlined methods
// We could collect all nodes to merge and call callgraph.merge(), but this is not yet implemented.
// Instead we simply rebuild the whole callgraph and all results which use callstrings.
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class ExecFrequencyProvider method getExecCount.
public long getExecCount(ExecutionContext context) {
CallString cs = context.getCallString();
if (cs.isEmpty()) {
return getExecCount(context.getMethodInfo());
}
// if we have a callstring, we need to start at the beginning of the callstring, then multiply the
// frequencies up to the invoked method along the callstring
long count = getExecCount(cs.first().getInvoker());
for (int i = 0; i < cs.length(); i++) {
InvokeSite is = cs.get(i);
MethodInfo invokee = i + 1 < cs.length() ? cs.get(i + 1).getInvoker() : context.getMethodInfo();
count *= getExecFrequency(is, invokee);
}
return count;
}
Aggregations