use of com.jopdesign.common.MethodCode in project jop by jop-devel.
the class SourceLineStorage method applySourceInfos.
private void applySourceInfos(MethodInfo method, List<SourceLineEntry> entries) {
MethodCode code = method.getCode();
InstructionHandle[] il = code.getInstructionList(true, false).getInstructionHandles();
for (SourceLineEntry sle : entries) {
sle.applyEntry(code, il);
}
}
use of com.jopdesign.common.MethodCode in project jop by jop-devel.
the class MethodCacheAnalysis method checkCache.
/**
* Check that cache is big enough to hold any method possibly invoked
* Return largest method
*/
public static MethodInfo checkCache(WCETTool wcetTool, Iterable<MethodInfo> methods) throws AppInfoException {
MethodCache methodCache = wcetTool.getWCETProcessorModel().getMethodCache();
int maxWords = 0;
MethodInfo largestMethod = null;
// for (ClassInfo ci : project.getAppInfo().getClassInfos()) {
for (MethodInfo mi : methods) {
MethodCode code = mi.getCode();
if (code == null)
continue;
// FIXME: using getNumberOfBytes(false) here to be compatible to old behaviour.
// should probably be getNumberOfBytes()
int size = code.getNumberOfBytes(false);
int words = MiscUtils.bytesToWords(size);
if (!methodCache.fitsInCache(words)) {
throw new AppInfoException("Cache to small for target method: " + mi.getFQMethodName() + " / " + words + " words");
}
if (words >= maxWords) {
largestMethod = mi;
maxWords = words;
}
}
return largestMethod;
}
use of com.jopdesign.common.MethodCode in project jop by jop-devel.
the class InsertSynchronized method synchronize.
private void synchronize(MethodInfo method) {
MethodCode mc = method.getCode();
InstructionList il = mc.getInstructionList();
InstructionFinder f;
// prepend monitorenter (reversed order of opcodes)
il.insert(new MONITORENTER());
if (method.isStatic()) {
// il.insert(new GET_CURRENT_CLASS());
throw new JavaClassFormatError("synchronized on static methods not yet supported");
} else {
il.insert(new ALOAD(0));
}
il.setPositions();
f = new InstructionFinder(il);
// find return instructions and insert monitorexit
String retInstr = "ReturnInstruction";
for (Iterator iterator = f.search(retInstr); iterator.hasNext(); ) {
InstructionHandle[] match = (InstructionHandle[]) iterator.next();
InstructionHandle ih = match[0];
// handle for inserted sequence
InstructionHandle newh;
if (method.isStatic()) {
// il.insert(ih, new GET_CURRENT_CLASS());
throw new JavaClassFormatError("synchronized on static methods not yet supported");
} else {
// TODO this could become a bug if JCopter ever reassigns local variable slots, then
// we could not be sure that slot 0 holds the this reference anymore.. To be on the safe side
// we should check if there is an xSTORE_0 somewhere in the code
newh = il.insert(ih, new ALOAD(0));
}
il.insert(ih, new MONITOREXIT());
// correct jumps
method.getCode().retarget(ih, newh);
}
il.setPositions();
method.compile();
}
use of com.jopdesign.common.MethodCode in project jop by jop-devel.
the class ReplaceIinc method replace.
private void replace(MethodInfo method) {
MethodCode mc = method.getCode();
InstructionList il = mc.getInstructionList();
InstructionFinder f = new InstructionFinder(il);
for (Iterator i = f.search("IINC"); i.hasNext(); ) {
InstructionHandle[] match = (InstructionHandle[]) i.next();
InstructionHandle ih = match[0];
IINC ii = (IINC) ih.getInstruction();
int idx = ii.getIndex();
int inc = ii.getIncrement();
// IINC rep = new IINC(idx, inc);
ih.setInstruction(new ILOAD(idx));
if (inc >= -1 && inc <= 5) {
ih = il.append(ih, new ICONST(inc));
} else if (inc >= -128 && inc < 127) {
ih = il.append(ih, new BIPUSH((byte) inc));
} else if (inc >= -32768 && inc < 32767) {
ih = il.append(ih, new SIPUSH((short) inc));
} else {
System.out.println("IINC constant too big");
System.exit(-1);
}
ih = il.append(ih, new IADD());
ih = il.append(ih, new ISTORE(idx));
}
method.compile();
}
use of com.jopdesign.common.MethodCode in project jop by jop-devel.
the class DescendingClassTraverser method visitMethodCode.
public void visitMethodCode(MethodInfo methodInfo) {
if (methodInfo.hasCode()) {
bcelVisitor.setCode(true);
MethodCode code = methodInfo.getCode();
visitor.visitMethodCode(code);
for (CodeExceptionGen ex : code.getExceptionHandlers()) {
visitor.visitCodeException(methodInfo, ex);
}
for (LineNumberGen lng : code.getLineNumbers()) {
visitor.visitLineNumber(methodInfo, lng);
}
for (LocalVariableGen lvg : code.getLocalVariables()) {
visitor.visitLocalVariable(methodInfo, lvg);
}
visitAttributes(code.getAttributes());
bcelVisitor.setCode(false);
}
}
Aggregations