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


Java CodeAttribute.iterator方法代码示例

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


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

示例1: transformInvokevirtualsIntoPutAndGetfields

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile) throws CannotCompileException, BadBytecode {
	for ( Object o : classfile.getMethods() ) {
		final MethodInfo methodInfo = (MethodInfo) o;
		final String methodName = methodInfo.getName();
		if ( methodName.startsWith( EACH_READ_METHOD_PREFIX )
				|| methodName.startsWith( EACH_WRITE_METHOD_PREFIX )
				|| methodName.equals( GETFIELDHANDLER_METHOD_NAME )
				|| methodName.equals( SETFIELDHANDLER_METHOD_NAME ) ) {
			continue;
		}

		final CodeAttribute codeAttr = methodInfo.getCodeAttribute();
		if ( codeAttr == null ) {
			continue;
		}

		final CodeIterator iter = codeAttr.iterator();
		while ( iter.hasNext() ) {
			int pos = iter.next();
			pos = transformInvokevirtualsIntoGetfields( classfile, iter, pos );
			transformInvokevirtualsIntoPutfields( classfile, iter, pos );
		}
		final StackMapTable smt = MapMaker.make( classPool, methodInfo );
		codeAttr.setAttribute( smt );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:FieldTransformer.java

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

示例3: insertAuxInitializer

import 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);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:22,代码来源:CtClassType.java

示例4: getBehaviourBytecode

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
 * This is basically the InstructionPrinter.getMethodBytecode but with a
 * CtBehaviour parameter instead of a CtMethod
 * 
 * @param behavior
 * @return
 */
public static String getBehaviourBytecode(CtBehavior behavior) {
    MethodInfo info = behavior.getMethodInfo2();
    CodeAttribute code = info.getCodeAttribute();
    if (code == null) {
        return "";
    }

    ConstPool pool = info.getConstPool();
    StringBuilder sb = new StringBuilder(1024);

    CodeIterator iterator = code.iterator();
    while (iterator.hasNext()) {
        int pos;
        try {
            pos = iterator.next();
        } catch (BadBytecode e) {
            throw new JVoidIntrumentationException("BadBytecoode", e);
        }

        sb.append(pos + ": " + InstructionPrinter.instructionString(iterator, pos, pool) + "\n");
    }
    return sb.toString();
}
 
开发者ID:jVoid,项目名称:jVoid,代码行数:31,代码来源:JavassistUtils.java

示例5: 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

示例6: transformInvokevirtualsIntoPutAndGetfields

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
		throws CannotCompileException {
	List methods = classfile.getMethods();
	for (Iterator method_iter = methods.iterator(); method_iter.hasNext();) {
		MethodInfo minfo = (MethodInfo) method_iter.next();
		String methodName = minfo.getName();
		if (methodName.startsWith(EACH_READ_METHOD_PREFIX)
		    || methodName.startsWith(EACH_WRITE_METHOD_PREFIX)
		    || methodName.equals(GETFIELDHANDLER_METHOD_NAME)
		    || methodName.equals(SETFIELDHANDLER_METHOD_NAME)) {
			continue;
		}
		CodeAttribute codeAttr = minfo.getCodeAttribute();
		if (codeAttr == null) {
			return;
		}
		CodeIterator iter = codeAttr.iterator();
		while (iter.hasNext()) {
			try {
				int pos = iter.next();
				pos = transformInvokevirtualsIntoGetfields(classfile, iter,
				                                           pos);
				pos = transformInvokevirtualsIntoPutfields(classfile, iter,
				                                           pos);

			} catch (BadBytecode e) {
				throw new CannotCompileException(e);
			}
		}
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:32,代码来源:FieldTransformer.java

示例7: 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;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:15,代码来源:ByteCodeTransformationQuery.java

示例8: opCodeIndexList

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
protected List<Integer> opCodeIndexList(CodeAttribute ca) throws BadBytecode {
    List<Integer> list = new ArrayList<Integer>();
    CodeIterator i = ca.iterator();

    while (i.hasNext()) {
        list.add(i.next());
    }
    return list;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:10,代码来源:ByteCodeTransformationQuery.java

示例9: addOpcode

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
protected void addOpcode(CodeAttribute ca, int index, byte[] bytecode) throws BadBytecode {
    CodeIterator i = ca.iterator();

    i.insert(index, bytecode);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:6,代码来源:BytecodeAdd.java

示例10: deleteOpcode

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
protected void deleteOpcode(CodeAttribute ca, int index, int size) {
    CodeIterator i = ca.iterator();
    byte[] NOPByte = new byte[size];
    i.write(NOPByte,index);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:6,代码来源:BytecodeReplace.java

示例11: addOpcode

import javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
protected void addOpcode(CodeAttribute ca, int index, byte[] bytecode) throws BadBytecode {
    CodeIterator i = ca.iterator();
    i.insert(index, bytecode);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:5,代码来源:BytecodeReplace.java


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