use of javassist.bytecode.BadBytecode in project blaze-persistence by Blazebit.
the class ProxyFactory method compileUnsafe.
private void compileUnsafe(CtConstructor ctConstructor, String src) throws CannotCompileException {
// This is essentially what javassist.compiler.Javac.compileBody does, except for an unsafe part
CtClass cc = ctConstructor.getDeclaringClass();
MethodInfo methodInfo = ctConstructor.getMethodInfo();
try {
Bytecode b = new Bytecode(cc.getClassFile2().getConstPool(), 0, 0);
JvstCodeGen gen = new JvstCodeGen(b, cc, cc.getClassPool());
SymbolTable stable = new SymbolTable();
int mod = ctConstructor.getModifiers();
gen.recordParams(ctConstructor.getParameterTypes(), Modifier.isStatic(mod), "$", "$args", "$$", stable);
gen.recordType(CtClass.voidType);
gen.recordReturnType(CtClass.voidType, "$r", null, stable);
Parser p = new Parser(new Lex(src));
SymbolTable stb = new SymbolTable(stable);
Stmnt s = p.parseStatement(stb);
if (p.hasMore()) {
throw new CompileError("the method/constructor body must be surrounded by {}");
}
// setting callSuper to false is the unsafe part...
boolean callSuper = false;
gen.atMethodBody(s, callSuper, true);
methodInfo.setCodeAttribute(b.toCodeAttribute());
methodInfo.setAccessFlags(methodInfo.getAccessFlags() & ~AccessFlag.ABSTRACT);
methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
cc.rebuildClassFile();
} catch (CompileError e) {
throw new CannotCompileException(e);
} catch (BadBytecode e) {
throw new CannotCompileException(e);
} catch (NotFoundException e) {
throw new CannotCompileException(e);
}
}
use of javassist.bytecode.BadBytecode in project JavaAgentTools by ethushiroha.
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);
}
}
}
}
use of javassist.bytecode.BadBytecode in project JavaAgentTools by ethushiroha.
the class Executor method evalArrayStore.
private void evalArrayStore(Type expectedComponent, Frame frame) throws BadBytecode {
Type value = simplePop(frame);
Type index = frame.pop();
Type array = frame.pop();
if (array == Type.UNINIT) {
verifyAssignable(Type.INTEGER, index);
return;
}
Type component = array.getComponent();
if (component == null)
throw new BadBytecode("Not an array! [pos = " + lastPos + "]: " + component);
component = zeroExtend(component);
verifyAssignable(expectedComponent, component);
verifyAssignable(Type.INTEGER, index);
// // but will throw arraystoreexception
if (expectedComponent == Type.OBJECT) {
verifyAssignable(expectedComponent, value);
} else {
verifyAssignable(component, value);
}
}
use of javassist.bytecode.BadBytecode in project JavaAgentTools by ethushiroha.
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 UniverseCore by EB-wilson.
the class CtConstructor method insertBeforeBody.
/**
* Inserts bytecode just after another constructor in the super class
* or this class is called.
* It does not work if this object represents a class initializer.
*
* @param src the source code representing the inserted bytecode.
* It must be a single statement or block.
*/
public void insertBeforeBody(String src) throws CannotCompileException {
CtClass cc = declaringClass;
cc.checkModify();
if (isClassInitializer())
throw new CannotCompileException("class initializer");
CodeAttribute ca = methodInfo.getCodeAttribute();
CodeIterator iterator = ca.iterator();
Bytecode b = new Bytecode(methodInfo.getConstPool(), ca.getMaxStack(), ca.getMaxLocals());
b.setStackDepth(ca.getMaxStack());
Javac jv = new Javac(b, cc);
try {
jv.recordParams(getParameterTypes(), false);
jv.compileStmnt(src);
ca.setMaxStack(b.getMaxStack());
ca.setMaxLocals(b.getMaxLocals());
iterator.skipConstructor();
int pos = iterator.insertEx(b.get());
iterator.insert(b.getExceptionTable(), pos);
methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
} catch (NotFoundException e) {
throw new CannotCompileException(e);
} catch (CompileError e) {
throw new CannotCompileException(e);
} catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
Aggregations