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


Java CodeIterator.byteAt方法代码示例

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


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

示例1: transformInvokevirtualsIntoGetfields

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private int transformInvokevirtualsIntoGetfields(ClassFile classfile, CodeIterator iter, int pos) {
	final ConstPool constPool = classfile.getConstPool();
	final int c = iter.byteAt( pos );
	if ( c != Opcode.GETFIELD ) {
		return pos;
	}

	final int index = iter.u16bitAt( pos + 1 );
	final String fieldName = constPool.getFieldrefName( index );
	final String className = constPool.getFieldrefClassName( index );
	if ( !filter.handleReadAccess( className, fieldName ) ) {
		return pos;
	}

	final String fieldReaderMethodDescriptor = "()" + constPool.getFieldrefType( index );
	final int fieldReaderMethodIndex = constPool.addMethodrefInfo(
			constPool.getThisClassInfo(),
			EACH_READ_METHOD_PREFIX + fieldName,
			fieldReaderMethodDescriptor
	);
	iter.writeByte( Opcode.INVOKEVIRTUAL, pos );
	iter.write16bit( fieldReaderMethodIndex, pos + 1 );
	return pos;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:FieldTransformer.java

示例2: transformInvokevirtualsIntoPutfields

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private int transformInvokevirtualsIntoPutfields(ClassFile classfile, CodeIterator iter, int pos) {
	final ConstPool constPool = classfile.getConstPool();
	final int c = iter.byteAt( pos );
	if ( c != Opcode.PUTFIELD ) {
		return pos;
	}

	final int index = iter.u16bitAt( pos + 1 );
	final String fieldName = constPool.getFieldrefName( index );
	final String className = constPool.getFieldrefClassName( index );
	if ( !filter.handleWriteAccess( className, fieldName ) ) {
		return pos;
	}

	final String fieldWriterMethodDescriptor = "(" + constPool.getFieldrefType( index ) + ")V";
	final int fieldWriterMethodIndex = constPool.addMethodrefInfo(
			constPool.getThisClassInfo(),
			EACH_WRITE_METHOD_PREFIX + fieldName,
			fieldWriterMethodDescriptor
	);
	iter.writeByte( Opcode.INVOKEVIRTUAL, pos );
	iter.write16bit( fieldWriterMethodIndex, pos + 1 );
	return pos;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:FieldTransformer.java

示例3: evalNewObjectArray

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void evalNewObjectArray(int pos, CodeIterator iter, Frame frame) throws BadBytecode {
    // Convert to x[] format
    Type type = resolveClassInfo(constPool.getClassInfo(iter.u16bitAt(pos + 1)));
    String name = type.getCtClass().getName();
    int opcode = iter.byteAt(pos);
    int dimensions;

    if (opcode == MULTIANEWARRAY) {
        dimensions = iter.byteAt(pos + 3);
    } else {
        name = name + "[]";
        dimensions = 1;
    }

    while (dimensions-- > 0) {
        verifyAssignable(Type.INTEGER, simplePop(frame));
    }

    simplePush(getType(name), frame);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:21,代码来源:Executor.java

示例4: transformInvokevirtualsIntoGetfields

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private int transformInvokevirtualsIntoGetfields(ClassFile classfile,
                                                 CodeIterator iter, int pos) {
	ConstPool cp = classfile.getConstPool();
	int c = iter.byteAt(pos);
	if (c != Opcode.GETFIELD) {
		return pos;
	}
	int index = iter.u16bitAt(pos + 1);
	String fieldName = cp.getFieldrefName(index);
	String className = cp.getFieldrefClassName(index);
	if ((!classfile.getName().equals(className))
	    || (!readableFields.containsKey(fieldName))) {
		return pos;
	}
	String desc = "()" + (String) readableFields.get(fieldName);
	int read_method_index = cp.addMethodrefInfo(cp.getThisClassInfo(),
	                                            EACH_READ_METHOD_PREFIX + fieldName, desc);
	iter.writeByte(Opcode.INVOKEVIRTUAL, pos);
	iter.write16bit(read_method_index, pos + 1);
	return pos;
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:22,代码来源:FieldTransformer.java

示例5: transformInvokevirtualsIntoPutfields

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private int transformInvokevirtualsIntoPutfields(ClassFile classfile,
                                                 CodeIterator iter, int pos) {
	ConstPool cp = classfile.getConstPool();
	int c = iter.byteAt(pos);
	if (c != Opcode.PUTFIELD) {
		return pos;
	}
	int index = iter.u16bitAt(pos + 1);
	String fieldName = cp.getFieldrefName(index);
	String className = cp.getFieldrefClassName(index);
	if ((!classfile.getName().equals(className))
	    || (!writableFields.containsKey(fieldName))) {
		return pos;
	}
	String desc = "(" + (String) writableFields.get(fieldName) + ")V";
	int write_method_index = cp.addMethodrefInfo(cp.getThisClassInfo(),
	                                             EACH_WRITE_METHOD_PREFIX + fieldName, desc);
	iter.writeByte(Opcode.INVOKEVIRTUAL, pos);
	iter.write16bit(write_method_index, pos + 1);
	return pos;
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:22,代码来源:FieldTransformer.java

示例6: initialize

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
public void initialize(ConstPool cp, CtClass clazz, MethodInfo minfo) throws CannotCompileException {
    /*
     * This transformer must be isolated from other transformers, since some
     * of them affect the local variable and stack maximums without updating
     * the code attribute to reflect the changes. This screws up the
     * data-flow analyzer, since it relies on consistent code state. Even
     * if the attribute values were updated correctly, we would have to
     * detect it, and redo analysis, which is not cheap. Instead, we are
     * better off doing all changes in initialize() before everyone else has
     * a chance to muck things up.
     */
    CodeIterator iterator = minfo.getCodeAttribute().iterator();
    while (iterator.hasNext()) {
        try {
            int pos = iterator.next();
            int c = iterator.byteAt(pos);

            if (c == AALOAD)
                initFrames(clazz, minfo);

            if (c == AALOAD || c == BALOAD || c == CALOAD || c == DALOAD
                    || c == FALOAD || c == IALOAD || c == LALOAD
                    || c == SALOAD) {
                pos = replace(cp, iterator, pos, c, getLoadReplacementSignature(c));
            } else if (c == AASTORE || c == BASTORE || c == CASTORE
                    || c == DASTORE || c == FASTORE || c == IASTORE
                    || c == LASTORE || c == SASTORE) {
                pos = replace(cp, iterator, pos, c, getStoreReplacementSignature(c));
            }

        } catch (Exception e) {
            throw new CannotCompileException(e);
        }
    }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:36,代码来源:TransformAccessArrayField.java

示例7: evalNewArray

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void evalNewArray(int pos, CodeIterator iter, Frame frame) throws BadBytecode {
    verifyAssignable(Type.INTEGER, simplePop(frame));
    Type type = null;
    int typeInfo = iter.byteAt(pos + 1);
    switch (typeInfo) {
        case T_BOOLEAN:
            type = getType("boolean[]");
            break;
        case T_CHAR:
            type = getType("char[]");
            break;
        case T_BYTE:
            type = getType("byte[]");
            break;
        case T_SHORT:
            type = getType("short[]");
            break;
        case T_INT:
            type = getType("int[]");
            break;
        case T_LONG:
            type = getType("long[]");
            break;
        case T_FLOAT:
            type = getType("float[]");
            break;
        case T_DOUBLE:
            type = getType("double[]");
            break;
        default:
            throw new BadBytecode("Invalid array type [pos = " + pos + "]: " + typeInfo);

    }

    frame.push(type);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:37,代码来源:Executor.java

示例8: equals

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
public boolean equals(String methodName) throws NotFoundException, BadBytecode {
    CtMethod mth1 = class1.getDeclaredMethod(methodName);
    CtMethod mth2 = class2.getDeclaredMethod(methodName);
    CodeIterator i1 = mth1.getMethodInfo().getCodeAttribute().iterator();
    CodeIterator i2 = mth2.getMethodInfo().getCodeAttribute().iterator();


    while (i1.hasNext() && i2.hasNext()) {
        if(i1.byteAt(i1.next()) != i2.byteAt(i2.next())) {
            return false;
        }
    }
    return i1.hasNext() == i2.hasNext();
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:15,代码来源:CompareBytecode.java

示例9: byteCodeAt

import javassist.bytecode.CodeIterator; //导入方法依赖的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

示例10: scanOp

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private boolean scanOp(int pos, CodeIterator iter, Subroutine sub) throws BadBytecode {
    subroutines[pos] = sub;

    int opcode = iter.byteAt(pos);

    if (opcode == TABLESWITCH) {
        scanTableSwitch(pos, iter, sub);

        return false;
    }

    if (opcode == LOOKUPSWITCH) {
        scanLookupSwitch(pos, iter, sub);

        return false;
    }

    // All forms of return and throw end current code flow
    if (Util.isReturn(opcode) || opcode == RET || opcode == ATHROW)
        return false;

    if (Util.isJumpInstruction(opcode)) {
        int target = Util.getJumpTarget(pos, iter);
        if (opcode == JSR || opcode == JSR_W) {
            Subroutine s = (Subroutine) subTable.get(Integer.valueOf(target));
            if (s == null) {
                s = new Subroutine(target, pos);
                subTable.put(Integer.valueOf(target), s);
                scan(target, iter, s);
            } else {
                s.addCaller(pos);
            }
        } else {
            scan(target, iter, sub);

            // GOTO ends current code flow
            if (Util.isGoto(opcode))
                return false;
        }
    }

    return true;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:44,代码来源:SubroutineScanner.java

示例11: getJumpTarget

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
public static int getJumpTarget(int pos, CodeIterator iter) {
    int opcode = iter.byteAt(pos);
    pos += (opcode == JSR_W || opcode == GOTO_W) ? iter.s32bitAt(pos + 1) : iter.s16bitAt(pos + 1);
    return pos;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:6,代码来源:Util.java

示例12: analyzeNextEntry

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void analyzeNextEntry(MethodInfo method, CodeIterator iter,
        IntQueue queue, Executor executor) throws BadBytecode {
    int pos = queue.take();
    iter.move(pos);
    iter.next();

    Frame frame = frames[pos].copy();
    Subroutine subroutine = subroutines[pos];

    try {
        executor.execute(method, pos, iter, frame, subroutine);
    } catch (RuntimeException e) {
        throw new BadBytecode(e.getMessage() + "[pos = " + pos + "]", e);
    }

    int opcode = iter.byteAt(pos);

    if (opcode == TABLESWITCH) {
        mergeTableSwitch(queue, pos, iter, frame);
    } else if (opcode == LOOKUPSWITCH) {
        mergeLookupSwitch(queue, pos, iter, frame);
    } else if (opcode == RET) {
        mergeRet(queue, iter, pos, frame, subroutine);
    } else if (Util.isJumpInstruction(opcode)) {
        int target = Util.getJumpTarget(pos, iter);

        if (Util.isJsr(opcode)) {
            // Merge the state before the jsr into the next instruction
            mergeJsr(queue, frames[pos], subroutines[target], pos, lookAhead(iter, pos));
        } else if (! Util.isGoto(opcode)) {
            merge(queue, frame, lookAhead(iter, pos));
        }

        merge(queue, frame, target);
    } else if (opcode != ATHROW && ! Util.isReturn(opcode)) {
        // Can advance to next instruction
        merge(queue, frame, lookAhead(iter, pos));
    }

    // Merge all exceptions that are reachable from this instruction.
    // The redundancy is intentional, since the state must be based
    // on the current instruction frame.
    mergeExceptionHandlers(queue, method, pos, frame);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:45,代码来源:Analyzer.java

示例13: evalWide

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void evalWide(int pos, CodeIterator iter, Frame frame, Subroutine subroutine) throws BadBytecode {
    int opcode = iter.byteAt(pos + 1);
    int index = iter.u16bitAt(pos + 2);
    switch (opcode) {
        case ILOAD:
            evalLoad(Type.INTEGER, index, frame, subroutine);
            break;
        case LLOAD:
            evalLoad(Type.LONG, index, frame, subroutine);
            break;
        case FLOAD:
            evalLoad(Type.FLOAT, index, frame, subroutine);
            break;
        case DLOAD:
            evalLoad(Type.DOUBLE, index, frame, subroutine);
            break;
        case ALOAD:
            evalLoad(Type.OBJECT, index, frame, subroutine);
            break;
        case ISTORE:
            evalStore(Type.INTEGER, index, frame, subroutine);
            break;
        case LSTORE:
            evalStore(Type.LONG, index, frame, subroutine);
            break;
        case FSTORE:
            evalStore(Type.FLOAT, index, frame, subroutine);
            break;
        case DSTORE:
            evalStore(Type.DOUBLE, index, frame, subroutine);
            break;
        case ASTORE:
            evalStore(Type.OBJECT, index, frame, subroutine);
            break;
        case IINC:
            verifyAssignable(Type.INTEGER, frame.getLocal(index));
            break;
        case RET:
            verifyAssignable(Type.RETURN_ADDRESS, frame.getLocal(index));
            break;
        default:
            throw new BadBytecode("Invalid WIDE operand [pos = " + pos + "]: " + opcode);
    }

}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:46,代码来源:Executor.java

示例14: BytecodeInstruction

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
public BytecodeInstruction(CodeIterator cit, int idx) {
    this.cit = cit;
    this.idx = idx;
    this.opcode = cit.byteAt(idx);
}
 
开发者ID:korat-jenkins,项目名称:korat,代码行数:6,代码来源:BytecodeInstruction.java

示例15: scanOp

import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private boolean scanOp(int pos, CodeIterator iter, Subroutine sub) throws BadBytecode {
    subroutines[pos] = sub;

    int opcode = iter.byteAt(pos);

    if (opcode == TABLESWITCH) {
        scanTableSwitch(pos, iter, sub);

        return false;
    }

    if (opcode == LOOKUPSWITCH) {
        scanLookupSwitch(pos, iter, sub);

        return false;
    }

    // All forms of return and throw end current code flow
    if (Util.isReturn(opcode) || opcode == RET || opcode == ATHROW)
        return false;

    if (Util.isJumpInstruction(opcode)) {
        int target = Util.getJumpTarget(pos, iter);
        if (opcode == JSR || opcode == JSR_W) {
            Subroutine s = (Subroutine) subTable.get(new Integer(target));
            if (s == null) {
                s = new Subroutine(target, pos);
                subTable.put(new Integer(target), s);
                scan(target, iter, s);
            } else {
                s.addCaller(pos);
            }
        } else {
            scan(target, iter, sub);

            // GOTO ends current code flow
            if (Util.isGoto(opcode))
                return false;
        }
    }

    return true;
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:44,代码来源:SubroutineScanner.java


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