use of javassist.bytecode.BadBytecode in project UniverseCore by EB-wilson.
the class Analyzer method analyzeNextEntry.
private void analyzeNextEntry(MethodInfo method, CodeIterator iter, IntQueue queue, Executor executor) throws BadBytecode {
int pos = queue.take();
iter.move(pos);
iter.next();
Frame frame = frames[pos].copy();
Subroutine subroutine = subroutines[pos];
try {
executor.execute(method, pos, iter, frame, subroutine);
} catch (RuntimeException e) {
throw new BadBytecode(e.getMessage() + "[pos = " + pos + "]", e);
}
int opcode = iter.byteAt(pos);
if (opcode == TABLESWITCH) {
mergeTableSwitch(queue, pos, iter, frame);
} else if (opcode == LOOKUPSWITCH) {
mergeLookupSwitch(queue, pos, iter, frame);
} else if (opcode == RET) {
mergeRet(queue, iter, pos, frame, subroutine);
} else if (Util.isJumpInstruction(opcode)) {
int target = Util.getJumpTarget(pos, iter);
if (Util.isJsr(opcode)) {
// Merge the state before the jsr into the next instruction
mergeJsr(queue, frames[pos], subroutines[target], pos, lookAhead(iter, pos));
} else if (!Util.isGoto(opcode)) {
merge(queue, frame, lookAhead(iter, pos));
}
merge(queue, frame, target);
} else if (opcode != ATHROW && !Util.isReturn(opcode)) {
// Can advance to next instruction
merge(queue, frame, lookAhead(iter, pos));
}
// Merge all exceptions that are reachable from this instruction.
// The redundancy is intentional, since the state must be based
// on the current instruction frame.
mergeExceptionHandlers(queue, method, pos, frame);
}
use of javassist.bytecode.BadBytecode in project UniverseCore by EB-wilson.
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 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 UniverseCore by EB-wilson.
the class Reflection method start.
/**
* Initializes the object.
*/
@Override
public void start(ClassPool pool) throws NotFoundException {
classPool = pool;
final String msg = "javassist.tools.reflect.Sample is not found or broken.";
try {
CtClass c = classPool.get("javassist.tools.reflect.Sample");
rebuildClassFile(c.getClassFile());
trapMethod = c.getDeclaredMethod("trap");
trapStaticMethod = c.getDeclaredMethod("trapStatic");
trapRead = c.getDeclaredMethod("trapRead");
trapWrite = c.getDeclaredMethod("trapWrite");
readParam = new CtClass[] { classPool.get("java.lang.Object") };
} catch (NotFoundException e) {
throw new RuntimeException(msg);
} catch (BadBytecode e) {
throw new RuntimeException(msg);
}
}
use of javassist.bytecode.BadBytecode in project UniverseCore by EB-wilson.
the class Instanceof method replace.
/**
* Replaces the instanceof operator with the bytecode derived from
* the given source text.
*
* <p>$0 is available but the value is <code>null</code>.
*
* @param statement a Java statement except try-catch.
*/
@Override
public void replace(String statement) throws CannotCompileException {
// to call checkModify().
thisClass.getClassFile();
@SuppressWarnings("unused") ConstPool constPool = getConstPool();
int pos = currentPos;
int index = iterator.u16bitAt(pos + 1);
Javac jc = new Javac(thisClass);
ClassPool cp = thisClass.getClassPool();
CodeAttribute ca = iterator.get();
try {
CtClass[] params = new CtClass[] { cp.get(javaLangObject) };
CtClass retType = CtClass.booleanType;
int paramVar = ca.getMaxLocals();
jc.recordParams(javaLangObject, params, true, paramVar, withinStatic());
int retVar = jc.recordReturnType(retType, true);
jc.recordProceed(new ProceedForInstanceof(index));
// because $type is not the return type...
jc.recordType(getType());
/* Is $_ included in the source code?
*/
checkResultValue(retType, statement);
Bytecode bytecode = jc.getBytecode();
storeStack(params, true, paramVar, bytecode);
jc.recordLocalVariables(ca, pos);
bytecode.addConstZero(retType);
// initialize $_
bytecode.addStore(retVar, retType);
jc.compileStmnt(statement);
bytecode.addLoad(retVar, retType);
replace0(pos, bytecode, 3);
} catch (CompileError e) {
throw new CannotCompileException(e);
} catch (NotFoundException e) {
throw new CannotCompileException(e);
} catch (BadBytecode e) {
throw new CannotCompileException("broken method");
}
}
Aggregations