本文整理匯總了Java中scouter.javassist.bytecode.MethodInfo.getCodeAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodInfo.getCodeAttribute方法的具體用法?Java MethodInfo.getCodeAttribute怎麽用?Java MethodInfo.getCodeAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scouter.javassist.bytecode.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.getCodeAttribute方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: scan
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的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 scouter.javassist.bytecode.MethodInfo; //導入方法依賴的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: make
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
/**
* Computes the stack map table of the given method and returns it.
* It returns null if the given method does not have to have a
* stack map table or it includes JSR.
*/
public static StackMapTable make(ClassPool classes, MethodInfo minfo)
throws BadBytecode
{
CodeAttribute ca = minfo.getCodeAttribute();
if (ca == null)
return null;
TypedBlock[] blocks;
try {
blocks = TypedBlock.makeBlocks(minfo, ca, true);
}
catch (BasicBlock.JsrBytecode e) {
return null;
}
if (blocks == null)
return null;
MapMaker mm = new MapMaker(classes, minfo, ca);
try {
mm.make(blocks, ca.getCode());
}
catch (BadBytecode bb) {
throw new BadBytecode(minfo, bb);
}
return mm.toStackMap(blocks);
}
示例4: make2
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
/**
* Computes the stack map table for J2ME.
* It returns null if the given method does not have to have a
* stack map table or it includes JSR.
*/
public static StackMap make2(ClassPool classes, MethodInfo minfo)
throws BadBytecode
{
CodeAttribute ca = minfo.getCodeAttribute();
if (ca == null)
return null;
TypedBlock[] blocks;
try {
blocks = TypedBlock.makeBlocks(minfo, ca, true);
}
catch (BasicBlock.JsrBytecode e) {
return null;
}
if (blocks == null)
return null;
MapMaker mm = new MapMaker(classes, minfo, ca);
try {
mm.make(blocks, ca.getCode());
}
catch (BadBytecode bb) {
throw new BadBytecode(minfo, bb);
}
return mm.toStackMap2(minfo.getConstPool(), blocks);
}
示例5: make
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的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());
}
示例6: setBody0
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
static void setBody0(CtClass srcClass, MethodInfo srcInfo,
CtClass destClass, MethodInfo destInfo,
ClassMap map)
throws CannotCompileException
{
destClass.checkModify();
map = new ClassMap(map);
map.put(srcClass.getName(), destClass.getName());
try {
CodeAttribute cattr = srcInfo.getCodeAttribute();
if (cattr != null) {
ConstPool cp = destInfo.getConstPool();
CodeAttribute ca = (CodeAttribute)cattr.copy(cp, map);
destInfo.setCodeAttribute(ca);
// a stack map table is copied to destInfo.
}
}
catch (CodeAttribute.RuntimeCopyException e) {
/* the exception may be thrown by copy() in CodeAttribute.
*/
throw new CannotCompileException(e);
}
destInfo.setAccessFlags(destInfo.getAccessFlags()
& ~AccessFlag.ABSTRACT);
destClass.rebuildClassFile();
}
示例7: modifyConstructors
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
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);
}
}
}
}
示例8: doit
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的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);
}
}
示例9: toMethod
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
/**
* Makes a copy of this constructor and converts it into a method.
* The signature of the method is the same as the that of this constructor.
* The return type is <code>void</code>. The resulting method must be
* appended to the class specified by <code>declaring</code>.
* If this constructor is a static initializer, the resulting method takes
* no parameter.
*
* <p>An occurrence of another constructor call <code>this()</code>
* or a super constructor call <code>super()</code> is
* eliminated from the resulting method.
*
* <p>The immediate super class of the class declaring this constructor
* must be also a super class of the class declaring the resulting method
* (this is obviously true if the second parameter <code>declaring</code> is
* the same as the class declaring this constructor).
* If the constructor accesses a field, the class declaring the resulting method
* must also declare a field with the same name and type.
*
* @param name the name of the resulting method.
* @param declaring the class declaring the resulting method.
* It is normally the same as the class declaring this
* constructor.
* @param map the hash table associating original class names
* with substituted names. The original class names will be
* replaced while making a copy.
* <code>map</code> can be <code>null</code>.
*/
public CtMethod toMethod(String name, CtClass declaring, ClassMap map)
throws CannotCompileException
{
CtMethod method = new CtMethod(null, declaring);
method.copy(this, false, map);
if (isConstructor()) {
MethodInfo minfo = method.getMethodInfo2();
CodeAttribute ca = minfo.getCodeAttribute();
if (ca != null) {
removeConsCall(ca);
try {
methodInfo.rebuildStackMapIf6(declaring.getClassPool(),
declaring.getClassFile2());
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
}
method.setName(name);
return method;
}
示例10: doit
import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的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;
}