use of org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.
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 org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.
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 + "]");
Iterator callerIter = subroutine.callers().iterator();
while (callerIter.hasNext()) {
int caller = ((Integer) callerIter.next()).intValue();
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 (Iterator i = subroutine.accessed().iterator(); i.hasNext(); ) {
int index = ((Integer) i.next()).intValue();
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 org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.
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 org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.
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);
}
use of org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.
the class FieldInitLink method modifyConstructors.
private void modifyConstructors(ClassFile cf) throws CannotCompileException, NotFoundException {
if (fieldInitializers == null)
return;
ConstPool cp = cf.getConstPool();
List list = cf.getMethods();
int n = list.size();
for (int i = 0; i < n; ++i) {
MethodInfo minfo = (MethodInfo) list.get(i);
if (minfo.isConstructor()) {
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr != null)
try {
Bytecode init = new Bytecode(cp, 0, codeAttr.getMaxLocals());
CtClass[] params = Descriptor.getParameterTypes(minfo.getDescriptor(), classPool);
int stacksize = makeFieldInitializer(init, params);
insertAuxInitializer(codeAttr, init, stacksize);
minfo.rebuildStackMapIf6(classPool, cf);
} catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
}
}
Aggregations