use of org.hotswap.agent.javassist.bytecode.Bytecode 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);
}
}
}
}
use of org.hotswap.agent.javassist.bytecode.Bytecode in project HotswapAgent by HotswapProjects.
the class Javac method recordStaticProceed.
/**
* Prepares to use $proceed() representing a static method.
* If the return type of $proceed() is void, null is pushed on the
* stack.
*
* @param targetClass the fully-qualified dot-separated name
* of the class declaring the method.
* @param method the method name.
*/
public void recordStaticProceed(String targetClass, String method) throws CompileError {
final String c = targetClass;
final String m = method;
ProceedHandler h = new ProceedHandler() {
public void doit(JvstCodeGen gen, Bytecode b, ASTList args) throws CompileError {
Expr expr = Expr.make(TokenId.MEMBER, new Symbol(c), new Member(m));
expr = CallExpr.makeCall(expr, args);
gen.compileExpr(expr);
gen.addNullIfVoid();
}
public void setReturnType(JvstTypeChecker check, ASTList args) throws CompileError {
Expr expr = Expr.make(TokenId.MEMBER, new Symbol(c), new Member(m));
expr = CallExpr.makeCall(expr, args);
expr.accept(check);
check.addNullIfVoid();
}
};
gen.setProceedHandler(h, proceedName);
}
use of org.hotswap.agent.javassist.bytecode.Bytecode in project HotswapAgent by HotswapProjects.
the class FieldInitLink method modifyClassConstructor.
private void modifyClassConstructor(ClassFile cf) throws CannotCompileException, NotFoundException {
if (fieldInitializers == null)
return;
Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
Javac jv = new Javac(code, this);
int stacksize = 0;
boolean doInit = false;
for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) {
CtField f = fi.field;
if (Modifier.isStatic(f.getModifiers())) {
doInit = true;
int s = fi.init.compileIfStatic(f.getType(), f.getName(), code, jv);
if (stacksize < s)
stacksize = s;
}
}
if (// need an initializer for static fileds.
doInit)
modifyClassConstructor(cf, code, stacksize, 0);
}
use of org.hotswap.agent.javassist.bytecode.Bytecode in project HotswapAgent by HotswapProjects.
the class FieldInitLink method makeClassInitializer.
public CtConstructor makeClassInitializer() throws CannotCompileException {
CtConstructor clinit = getClassInitializer();
if (clinit != null)
return clinit;
checkModify();
ClassFile cf = getClassFile2();
Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
modifyClassConstructor(cf, code, 0, 0);
return getClassInitializer();
}
Aggregations