use of javassist.bytecode.BadBytecode in project javassist by jboss-javassist.
the class Analyzer method mergeJsr.
private void mergeJsr(IntQueue queue, Frame frame, Subroutine sub, int pos, int next) throws BadBytecode {
if (sub == null)
throw new BadBytecode("No subroutine at jsr target! [pos = " + pos + "]");
Frame old = frames[next];
boolean changed = false;
if (old == null) {
old = frames[next] = frame.copy();
changed = true;
} else {
for (int i = 0; i < frame.localsLength(); i++) {
// Skip everything accessed by a subroutine, mergeRet must handle this
if (!sub.isAccessed(i)) {
Type oldType = old.getLocal(i);
Type newType = frame.getLocal(i);
if (oldType == null) {
old.setLocal(i, newType);
changed = true;
continue;
}
newType = oldType.merge(newType);
// Always set the type, in case a multi-type switched to a standard type.
old.setLocal(i, newType);
if (!newType.equals(oldType) || newType.popChanged())
changed = true;
}
}
}
if (!old.isJsrMerged()) {
old.setJsrMerged(true);
changed = true;
}
if (changed && old.isRetMerged())
queue.add(next);
}
use of javassist.bytecode.BadBytecode in project javassist by jboss-javassist.
the class Analyzer method mergeRet.
private void mergeRet(IntQueue queue, CodeIterator iter, int pos, Frame frame, Subroutine subroutine) throws BadBytecode {
if (subroutine == null)
throw new BadBytecode("Ret on no subroutine! [pos = " + pos + "]");
for (int caller : subroutine.callers()) {
int returnLoc = getNext(iter, caller, pos);
boolean changed = false;
Frame old = frames[returnLoc];
if (old == null) {
old = frames[returnLoc] = frame.copyStack();
changed = true;
} else {
changed = old.mergeStack(frame);
}
for (int index : subroutine.accessed()) {
Type oldType = old.getLocal(index);
Type newType = frame.getLocal(index);
if (oldType != newType) {
old.setLocal(index, newType);
changed = true;
}
}
if (!old.isRetMerged()) {
old.setRetMerged(true);
changed = true;
}
if (changed && old.isJsrMerged())
queue.add(returnLoc);
}
}
use of javassist.bytecode.BadBytecode in project javassist by jboss-javassist.
the class Executor method paramTypesFromDesc.
private Type[] paramTypesFromDesc(String desc) throws BadBytecode {
CtClass[] classes = null;
try {
classes = Descriptor.getParameterTypes(desc, classPool);
} catch (NotFoundException e) {
throw new BadBytecode("Could not find class in descriptor [pos = " + lastPos + "]: " + e.getMessage());
}
if (classes == null)
throw new BadBytecode("Could not obtain parameters for descriptor [pos = " + lastPos + "]: " + desc);
Type[] types = new Type[classes.length];
for (int i = 0; i < types.length; i++) types[i] = Type.get(classes[i]);
return types;
}
use of javassist.bytecode.BadBytecode in project javassist by jboss-javassist.
the class MapMaker method make.
/*
public static void main(String[] args) throws Exception {
boolean useMain2 = args[0].equals("0");
if (useMain2 && args.length > 1) {
main2(args);
return;
}
for (int i = 0; i < args.length; i++)
main1(args[i]);
}
public static void main1(String className) throws Exception {
ClassPool cp = ClassPool.getDefault();
//javassist.CtClass cc = cp.get(className);
javassist.CtClass cc = cp.makeClass(new java.io.FileInputStream(className));
System.out.println(className);
ClassFile cf = cc.getClassFile();
java.util.List minfos = cf.getMethods();
for (int i = 0; i < minfos.size(); i++) {
MethodInfo minfo = (MethodInfo)minfos.get(i);
CodeAttribute ca = minfo.getCodeAttribute();
if (ca != null)
ca.setAttribute(make(cp, minfo));
}
cc.writeFile("tmp");
}
public static void main2(String[] args) throws Exception {
ClassPool cp = ClassPool.getDefault();
//javassist.CtClass cc = cp.get(args[1]);
javassist.CtClass cc = cp.makeClass(new java.io.FileInputStream(args[1]));
MethodInfo minfo;
if (args[2].equals("_init_"))
minfo = cc.getDeclaredConstructors()[0].getMethodInfo();
// minfo = cc.getClassInitializer().getMethodInfo();
else
minfo = cc.getDeclaredMethod(args[2]).getMethodInfo();
CodeAttribute ca = minfo.getCodeAttribute();
if (ca == null) {
System.out.println("abstarct method");
return;
}
TypedBlock[] blocks = TypedBlock.makeBlocks(minfo, ca, false);
MapMaker mm = new MapMaker(cp, minfo, ca);
mm.make(blocks, ca.getCode());
for (int i = 0; i < blocks.length; i++)
System.out.println(blocks[i]);
}
*/
/**
* Computes the stack map table of the given method and returns it.
* It returns null if the given method does not have to have a
* stack map table or it includes JSR.
*/
public static StackMapTable make(ClassPool classes, MethodInfo minfo) throws BadBytecode {
CodeAttribute ca = minfo.getCodeAttribute();
if (ca == null)
return null;
TypedBlock[] blocks;
try {
blocks = TypedBlock.makeBlocks(minfo, ca, true);
} catch (BasicBlock.JsrBytecode e) {
return null;
}
if (blocks == null)
return null;
MapMaker mm = new MapMaker(classes, minfo, ca);
try {
mm.make(blocks, ca.getCode());
} catch (BadBytecode bb) {
throw new BadBytecode(minfo, bb);
}
return mm.toStackMap(blocks);
}
use of javassist.bytecode.BadBytecode in project javassist by jboss-javassist.
the class TypeData method aastore.
public static void aastore(TypeData array, TypeData value, ClassPool cp) throws BadBytecode {
if (array instanceof AbsTypeVar)
if (!value.isNullType())
((AbsTypeVar) array).merge(ArrayType.make(value));
if (value instanceof AbsTypeVar)
if (array instanceof AbsTypeVar)
// should call value.setType() later.
ArrayElement.make(array);
else if (array instanceof ClassName) {
if (!array.isNullType()) {
String type = ArrayElement.typeName(array.getName());
value.setType(type, cp);
}
} else
throw new BadBytecode("bad AASTORE: " + array);
}
Aggregations