本文整理汇总了Java中scouter.javassist.bytecode.CodeAttribute.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java CodeAttribute.iterator方法的具体用法?Java CodeAttribute.iterator怎么用?Java CodeAttribute.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scouter.javassist.bytecode.CodeAttribute
的用法示例。
在下文中一共展示了CodeAttribute.iterator方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isEmpty
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
* Returns true if the constructor (or static initializer)
* is the default one. This method returns true if the constructor
* takes some arguments but it does not perform anything except
* calling <code>super()</code> (the no-argument constructor of
* the super class).
*/
public boolean isEmpty() {
CodeAttribute ca = getMethodInfo2().getCodeAttribute();
if (ca == null)
return false; // native or abstract??
// they are not allowed, though.
ConstPool cp = ca.getConstPool();
CodeIterator it = ca.iterator();
try {
int pos, desc;
int op0 = it.byteAt(it.next());
return op0 == Opcode.RETURN // empty static initializer
|| (op0 == Opcode.ALOAD_0
&& it.byteAt(pos = it.next()) == Opcode.INVOKESPECIAL
&& (desc = cp.isConstructor(getSuperclassName(),
it.u16bitAt(pos + 1))) != 0
&& "()V".equals(cp.getUtf8Info(desc))
&& it.byteAt(it.next()) == Opcode.RETURN
&& !it.hasNext());
}
catch (BadBytecode e) {}
return false;
}
示例2: callsSuper
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
* Returns true if this constructor calls a constructor
* of the super class. This method returns false if it
* calls another constructor of this class by <code>this()</code>.
*/
public boolean callsSuper() throws CannotCompileException {
CodeAttribute codeAttr = methodInfo.getCodeAttribute();
if (codeAttr != null) {
CodeIterator it = codeAttr.iterator();
try {
int index = it.skipSuperConstructor();
return index >= 0;
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
return false;
}
示例3: scan
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
public Subroutine[] scan(MethodInfo method) throws BadBytecode {
CodeAttribute code = method.getCodeAttribute();
CodeIterator iter = code.iterator();
subroutines = new Subroutine[code.getCodeLength()];
subTable.clear();
done.clear();
scan(0, iter, null);
ExceptionTable exceptions = code.getExceptionTable();
for (int i = 0; i < exceptions.size(); i++) {
int handler = exceptions.handlerPc(i);
// If an exception is thrown in subroutine, the handler
// is part of the same subroutine.
scan(handler, iter, subroutines[exceptions.startPc(i)]);
}
return subroutines;
}
示例4: insertAuxInitializer
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
private static void insertAuxInitializer(CodeAttribute codeAttr,
Bytecode initializer,
int stacksize)
throws BadBytecode
{
CodeIterator it = codeAttr.iterator();
int index = it.skipSuperConstructor();
if (index < 0) {
index = it.skipThisConstructor();
if (index >= 0)
return; // this() is called.
// Neither this() or super() is called.
}
int pos = it.insertEx(initializer.get());
it.insert(initializer.getExceptionTable(), pos);
int maxstack = codeAttr.getMaxStack();
if (maxstack < stacksize)
codeAttr.setMaxStack(stacksize);
}
示例5: isEmpty
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
* Returns true if the method body is empty, that is, <code>{}</code>.
* It also returns true if the method is an abstract method.
*/
public boolean isEmpty() {
CodeAttribute ca = getMethodInfo2().getCodeAttribute();
if (ca == null) // abstract or native
return (getModifiers() & Modifier.ABSTRACT) != 0;
CodeIterator it = ca.iterator();
try {
return it.hasNext() && it.byteAt(it.next()) == Opcode.RETURN
&& !it.hasNext();
}
catch (BadBytecode e) {}
return false;
}
示例6: getStartPosOfBody
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
int getStartPosOfBody(CodeAttribute ca) throws CannotCompileException {
CodeIterator ci = ca.iterator();
try {
ci.skipConstructor();
return ci.next();
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
示例7: removeConsCall
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
private static void removeConsCall(CodeAttribute ca)
throws CannotCompileException
{
CodeIterator iterator = ca.iterator();
try {
int pos = iterator.skipConstructor();
if (pos >= 0) {
int mref = iterator.u16bitAt(pos + 1);
String desc = ca.getConstPool().getMethodrefType(mref);
int num = Descriptor.numOfParameters(desc) + 1;
if (num > 3)
pos = iterator.insertGapAt(pos, num - 3, false).position;
iterator.writeByte(Opcode.POP, pos++); // this
iterator.writeByte(Opcode.NOP, pos);
iterator.writeByte(Opcode.NOP, pos + 1);
Descriptor.Iterator it = new Descriptor.Iterator(desc);
while (true) {
it.next();
if (it.isParameter())
iterator.writeByte(it.is2byte() ? Opcode.POP2 : Opcode.POP,
pos++);
else
break;
}
}
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
示例8: analyze
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
* Performs data-flow analysis on a method and returns an array, indexed by
* instruction position, containing the starting frame state of all reachable
* instructions. Non-reachable code, and illegal code offsets are represented
* as a null in the frame state array. This can be used to detect dead code.
*
* If the method does not contain code (it is either native or abstract), null
* is returned.
*
* @param clazz the declaring class of the method
* @param method the method to analyze
* @return an array, indexed by instruction position, of the starting frame state,
* or null if this method doesn't have code
* @throws BadBytecode if the bytecode does not comply with the JVM specification
*/
public Frame[] analyze(CtClass clazz, MethodInfo method) throws BadBytecode {
this.clazz = clazz;
CodeAttribute codeAttribute = method.getCodeAttribute();
// Native or Abstract
if (codeAttribute == null)
return null;
int maxLocals = codeAttribute.getMaxLocals();
int maxStack = codeAttribute.getMaxStack();
int codeLength = codeAttribute.getCodeLength();
CodeIterator iter = codeAttribute.iterator();
IntQueue queue = new IntQueue();
exceptions = buildExceptionInfo(method);
subroutines = scanner.scan(method);
Executor executor = new Executor(clazz.getClassPool(), method.getConstPool());
frames = new Frame[codeLength];
frames[iter.lookAhead()] = firstFrame(method, maxLocals, maxStack);
queue.add(iter.next());
while (!queue.isEmpty()) {
analyzeNextEntry(method, iter, queue, executor);
}
return frames;
}
示例9: make
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
public BasicBlock[] make(MethodInfo minfo) throws BadBytecode {
CodeAttribute ca = minfo.getCodeAttribute();
if (ca == null)
return null;
CodeIterator ci = ca.iterator();
return make(ci, 0, ci.getCodeLength(), ca.getExceptionTable());
}
示例10: doit
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
* Performs code conversion.
*/
protected void doit(CtClass clazz, MethodInfo minfo, ConstPool cp)
throws CannotCompileException
{
Transformer t;
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr == null || transformers == null)
return;
for (t = transformers; t != null; t = t.getNext())
t.initialize(cp, clazz, minfo);
CodeIterator iterator = codeAttr.iterator();
while (iterator.hasNext()) {
try {
int pos = iterator.next();
for (t = transformers; t != null; t = t.getNext())
pos = t.transform(clazz, pos, iterator, cp);
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
int locals = 0;
int stack = 0;
for (t = transformers; t != null; t = t.getNext()) {
int s = t.extraLocals();
if (s > locals)
locals = s;
s = t.extraStack();
if (s > stack)
stack = s;
}
for (t = transformers; t != null; t = t.getNext())
t.clean();
if (locals > 0)
codeAttr.setMaxLocals(codeAttr.getMaxLocals() + locals);
if (stack > 0)
codeAttr.setMaxStack(codeAttr.getMaxStack() + stack);
try {
minfo.rebuildStackMapIf6(clazz.getClassPool(),
clazz.getClassFile2());
}
catch (BadBytecode b) {
throw new CannotCompileException(b.getMessage(), b);
}
}
示例11: doit
import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
* Undocumented method. Do not use; internal-use only.
*/
public boolean doit(CtClass clazz, MethodInfo minfo)
throws CannotCompileException
{
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr == null)
return false;
CodeIterator iterator = codeAttr.iterator();
boolean edited = false;
LoopContext context = new LoopContext(codeAttr.getMaxLocals());
while (iterator.hasNext())
if (loopBody(iterator, clazz, minfo, context))
edited = true;
ExceptionTable et = codeAttr.getExceptionTable();
int n = et.size();
for (int i = 0; i < n; ++i) {
Handler h = new Handler(et, i, iterator, clazz, minfo);
edit(h);
if (h.edited()) {
edited = true;
context.updateMax(h.locals(), h.stack());
}
}
// codeAttr might be modified by other partiess
// so I check the current value of max-locals.
if (codeAttr.getMaxLocals() < context.maxLocals)
codeAttr.setMaxLocals(context.maxLocals);
codeAttr.setMaxStack(codeAttr.getMaxStack() + context.maxStack);
try {
if (edited)
minfo.rebuildStackMapIf6(clazz.getClassPool(),
clazz.getClassFile2());
}
catch (BadBytecode b) {
throw new CannotCompileException(b.getMessage(), b);
}
return edited;
}