当前位置: 首页>>代码示例>>Java>>正文


Java CodeAttribute.getMaxLocals方法代码示例

本文整理汇总了Java中javassist.bytecode.CodeAttribute.getMaxLocals方法的典型用法代码示例。如果您正苦于以下问题:Java CodeAttribute.getMaxLocals方法的具体用法?Java CodeAttribute.getMaxLocals怎么用?Java CodeAttribute.getMaxLocals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javassist.bytecode.CodeAttribute的用法示例。


在下文中一共展示了CodeAttribute.getMaxLocals方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runEditor

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
protected void runEditor(ExprEditor ed, CodeIterator oldIterator)
    throws CannotCompileException
{
    CodeAttribute codeAttr = oldIterator.get();
    int orgLocals = codeAttr.getMaxLocals();
    int orgStack = codeAttr.getMaxStack();
    int newLocals = locals();
    codeAttr.setMaxStack(stack());
    codeAttr.setMaxLocals(newLocals);
    ExprEditor.LoopContext context
        = new ExprEditor.LoopContext(newLocals);
    int size = oldIterator.getCodeLength();
    int endPos = oldIterator.lookAhead();
    oldIterator.move(currentPos);
    if (ed.doit(thisClass, thisMethod, context, oldIterator, endPos))
        edited = true;

    oldIterator.move(endPos + oldIterator.getCodeLength() - size);
    codeAttr.setMaxLocals(orgLocals);
    codeAttr.setMaxStack(orgStack);
    maxLocals = context.maxLocals;
    maxStack += context.maxStack;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:24,代码来源:Expr.java

示例2: getLocalVariableTable

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
@Override
public LocalVariableTable getLocalVariableTable(Signature methodSignature) 
throws MethodNotFoundException, MethodCodeNotFoundException  {
    final CodeAttribute ca = getMethodCodeAttribute(methodSignature);
    final LocalVariableAttribute lvtJA = (LocalVariableAttribute) ca.getAttribute("LocalVariableTable");

    if (lvtJA == null) {
        return this.defaultLocalVariableTable(methodSignature);
    }

    //builds the local variable table from the LocalVariableTable attribute 
    //information; this has always success
    final LocalVariableTable lvt = new LocalVariableTable(ca.getMaxLocals());
    for (int i = 0; i < lvtJA.tableLength(); ++i) {
        lvt.setEntry(lvtJA.index(i), lvtJA.descriptor(i), 
                     lvtJA.variableName(i), lvtJA.startPc(i),  lvtJA.codeLength(i));
    }
    return lvt;
}
 
开发者ID:pietrobraione,项目名称:jbse,代码行数:20,代码来源:ClassFileJavassist.java

示例3: 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;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:43,代码来源:Analyzer.java

示例4: modifyConstructors

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
private void modifyConstructors(ClassFile cf)
    throws CannotCompileException, NotFoundException
{
    if (fieldInitializers == null)
        return;

    ConstPool cp = cf.getConstPool();
    List<MethodInfo> 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);
                }
        }
    }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:32,代码来源:CtClassType.java

示例5: modifyConstructors

import javassist.bytecode.CodeAttribute; //导入方法依赖的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);
                }
        }
    }
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:32,代码来源:CtClassType.java


注:本文中的javassist.bytecode.CodeAttribute.getMaxLocals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。