本文整理汇总了Java中javassist.bytecode.CodeAttribute.getCodeLength方法的典型用法代码示例。如果您正苦于以下问题:Java CodeAttribute.getCodeLength方法的具体用法?Java CodeAttribute.getCodeLength怎么用?Java CodeAttribute.getCodeLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.CodeAttribute
的用法示例。
在下文中一共展示了CodeAttribute.getCodeLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scan
import 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;
}
示例2: analyze
import 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;
}
示例3: byteCodeAt
import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
protected byte[] byteCodeAt(CodeAttribute ca, List<Integer> opCodeIndexList, int index) {
int borne;
int byteCodeIndex = opCodeIndexList.get(index);
if(index + 1 == opCodeIndexList.size())
borne = ca.getCodeLength();
else
borne = opCodeIndexList.get(index+1);
CodeIterator iter = ca.iterator();
byte[] bytecode = new byte[borne - byteCodeIndex];
for(int i = 0; i < borne - byteCodeIndex; i++) {
bytecode[i] = (byte) iter.byteAt(i);
}
return bytecode;
}