use of org.hotswap.agent.javassist.CtClass 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.CtClass in project HotswapAgent by HotswapProjects.
the class Javac method compileMethod.
private CtBehavior compileMethod(Parser p, MethodDecl md) throws CompileError {
int mod = MemberResolver.getModifiers(md.getModifiers());
CtClass[] plist = gen.makeParamList(md);
CtClass[] tlist = gen.makeThrowsList(md);
recordParams(plist, Modifier.isStatic(mod));
md = p.parseMethod2(stable, md);
try {
if (md.isConstructor()) {
CtConstructor cons = new CtConstructor(plist, gen.getThisClass());
cons.setModifiers(mod);
md.accept(gen);
cons.getMethodInfo().setCodeAttribute(bytecode.toCodeAttribute());
cons.setExceptionTypes(tlist);
return cons;
} else {
Declarator r = md.getReturn();
CtClass rtype = gen.resolver.lookupClass(r);
recordReturnType(rtype, false);
CtMethod method = new CtMethod(rtype, r.getVariable().get(), plist, gen.getThisClass());
method.setModifiers(mod);
gen.setThisMethod(method);
md.accept(gen);
if (md.getBody() != null)
method.getMethodInfo().setCodeAttribute(bytecode.toCodeAttribute());
else
method.setModifiers(mod | Modifier.ABSTRACT);
method.setExceptionTypes(tlist);
return method;
}
} catch (NotFoundException e) {
throw new CompileError(e.toString());
}
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class Bytecode method setMaxLocals.
/**
* Sets <code>max_locals</code>.
*
* <p>This computes the number of local variables
* used to pass method parameters and sets <code>max_locals</code>
* to that number plus <code>locals</code>.
*
* @param isStatic true if <code>params</code> must be
* interpreted as parameters to a static method.
* @param params parameter types.
* @param locals the number of local variables excluding
* ones used to pass parameters.
*/
public void setMaxLocals(boolean isStatic, CtClass[] params, int locals) {
if (!isStatic)
++locals;
if (params != null) {
CtClass doubleType = CtClass.doubleType;
CtClass longType = CtClass.longType;
int n = params.length;
for (int i = 0; i < n; ++i) {
CtClass type = params[i];
if (type == doubleType || type == longType)
locals += 2;
else
++locals;
}
}
maxLocals = locals;
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class TypeData method commonSuperClass.
/**
* Finds the most specific common super class of the given classes.
* This method is a copy from javassist.bytecode.analysis.Type.
*/
public static CtClass commonSuperClass(CtClass one, CtClass two) throws NotFoundException {
CtClass deep = one;
CtClass shallow = two;
CtClass backupShallow = shallow;
CtClass backupDeep = deep;
// Phase 1 - Find the deepest hierarchy, set deep and shallow correctly
for (; ; ) {
// In case we get lucky, and find a match early
if (eq(deep, shallow) && deep.getSuperclass() != null)
return deep;
CtClass deepSuper = deep.getSuperclass();
CtClass shallowSuper = shallow.getSuperclass();
if (shallowSuper == null) {
// right, now reset shallow
shallow = backupShallow;
break;
}
if (deepSuper == null) {
// wrong, swap them, since deep is now useless, its our tmp before we swap it
deep = backupDeep;
backupDeep = backupShallow;
backupShallow = deep;
deep = shallow;
shallow = backupShallow;
break;
}
deep = deepSuper;
shallow = shallowSuper;
}
// Phase 2 - Move deepBackup up by (deep end - deep)
for (; ; ) {
deep = deep.getSuperclass();
if (deep == null)
break;
backupDeep = backupDeep.getSuperclass();
}
deep = backupDeep;
// The common super class is easy to find now
while (!eq(deep, shallow)) {
deep = deep.getSuperclass();
shallow = shallow.getSuperclass();
}
return deep;
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class HotSwapperJpda method swapClasses.
/**
* Swap class definition from another class file.
* <p/>
* This is mainly useful for unit testing - declare multiple version of a class and then
* hotswap definition and do the tests.
*
* @param original original class currently in use
* @param swap fully qualified class name of class to swap
* @throws Exception swap exception
*/
public void swapClasses(Class original, String swap) throws Exception {
// need to recreate classpool on each swap to avoid stale class definition
ClassPool classPool = new ClassPool();
classPool.appendClassPath(new LoaderClassPath(original.getClassLoader()));
CtClass ctClass = classPool.getAndRename(swap, original.getName());
reload(original.getName(), ctClass.toBytecode());
}
Aggregations