當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodInfo.getConstPool方法代碼示例

本文整理匯總了Java中scouter.javassist.bytecode.MethodInfo.getConstPool方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodInfo.getConstPool方法的具體用法?Java MethodInfo.getConstPool怎麽用?Java MethodInfo.getConstPool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scouter.javassist.bytecode.MethodInfo的用法示例。


在下文中一共展示了MethodInfo.getConstPool方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildExceptionInfo

import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
    ConstPool constPool = method.getConstPool();
    ClassPool classes = clazz.getClassPool();

    ExceptionTable table = method.getCodeAttribute().getExceptionTable();
    ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
    for (int i = 0; i < table.size(); i++) {
        int index = table.catchType(i);
        Type type;
        try {
            type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
        } catch (NotFoundException e) {
            throw new IllegalStateException(e.getMessage());
        }

        exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
    }

    return exceptions;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:21,代碼來源:Analyzer.java

示例2: makeBlocks

import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
/**
 * Divides the method body into basic blocks.
 * The type information of the first block is initialized.
 *
 * @param optimize       if it is true and the method does not include
 *                      branches, this method returns null.
 */
public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca,
                                      boolean optimize)
    throws BadBytecode
{
    TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo);
    if (optimize && blocks.length < 2)
        if (blocks.length == 0 || blocks[0].incoming == 0)
            return null;

    ConstPool pool = minfo.getConstPool();
    boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0;
    blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(),
                             pool.getClassName(), minfo.getDescriptor(),
                             isStatic, minfo.isConstructor());
    return blocks;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:24,代碼來源:TypedBlock.java

示例3: 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;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:43,代碼來源:Analyzer.java

示例4: 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();
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:29,代碼來源:CtBehavior.java

示例5: MapMaker

import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public MapMaker(ClassPool classes, MethodInfo minfo, CodeAttribute ca) {
    super(classes, minfo.getConstPool(),
          ca.getMaxStack(), ca.getMaxLocals(),
          TypedBlock.getRetType(minfo.getDescriptor()));
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:6,代碼來源:MapMaker.java

示例6: make

import scouter.javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
/**
 * Creates a method from a <code>MethodInfo</code> object.
 *
 * @param declaring     the class declaring the method.
 * @throws CannotCompileException       if the the <code>MethodInfo</code>
 *          object and the declaring class have different
 *          <code>ConstPool</code> objects
 * @since 3.6
 */
public static CtMethod make(MethodInfo minfo, CtClass declaring)
    throws CannotCompileException
{
    if (declaring.getClassFile2().getConstPool() != minfo.getConstPool())
        throw new CannotCompileException("bad declaring class");

    return new CtMethod(minfo, declaring);
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:18,代碼來源:CtMethod.java


注:本文中的scouter.javassist.bytecode.MethodInfo.getConstPool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。