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


Java Bytecode类代码示例

本文整理汇总了Java中scouter.javassist.bytecode.Bytecode的典型用法代码示例。如果您正苦于以下问题:Java Bytecode类的具体用法?Java Bytecode怎么用?Java Bytecode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: wrapped

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
public static CtConstructor wrapped(CtClass[] parameterTypes,
                                    CtClass[] exceptionTypes,
                                    int howToCallSuper,
                                    CtMethod body,
                                    ConstParameter constParam,
                                    CtClass declaring)
    throws CannotCompileException
{
    try {
        CtConstructor cons = new CtConstructor(parameterTypes, declaring);
        cons.setExceptionTypes(exceptionTypes);
        Bytecode code = makeBody(declaring, declaring.getClassFile2(),
                                 howToCallSuper, body,
                                 parameterTypes, constParam);
        cons.getMethodInfo2().setCodeAttribute(code.toCodeAttribute());
        // a stack map table is not needed.
        return cons;
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:23,代码来源:CtNewWrappedConstructor.java

示例2: defaultConstructor

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
/**
 * Creates a default (public) constructor.
 *
 * <p>The created constructor takes no parameter.  It calls
 * <code>super()</code>.
 */
public static CtConstructor defaultConstructor(CtClass declaring)
    throws CannotCompileException
{
    CtConstructor cons = new CtConstructor((CtClass[])null, declaring);

    ConstPool cp = declaring.getClassFile2().getConstPool();
    Bytecode code = new Bytecode(cp, 1, 1);
    code.addAload(0);
    try {
        code.addInvokespecial(declaring.getSuperclass(),
                              "<init>", "()V");
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }

    code.add(Bytecode.RETURN);

    // no need to construct a stack map table.
    cons.getMethodInfo2().setCodeAttribute(code.toCodeAttribute());
    return cons;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:29,代码来源:CtNewConstructor.java

示例3: atAssignParamList

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
protected void atAssignParamList(CtClass[] params, Bytecode code)
    throws CompileError
{
    if (params == null)
        return;

    int varNo = indexOfParam1();
    int n = params.length;
    for (int i = 0; i < n; ++i) {
        code.addOpcode(DUP);
        code.addIconst(i);
        code.addOpcode(AALOAD);
        compileUnwrapValue(params[i], code);
        code.addStore(varNo, params[i]);
        varNo += is2word(exprType, arrayDim) ? 2 : 1;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:18,代码来源:JvstCodeGen.java

示例4: compileUnwrapValue

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
protected void compileUnwrapValue(CtClass type, Bytecode code)
    throws CompileError
{
    if (type == CtClass.voidType) {
        addNullIfVoid();
        return;
    }

    if (exprType == VOID)
        throw new CompileError("invalid type for " + returnCastName);

    if (type instanceof CtPrimitiveType) {
        CtPrimitiveType pt = (CtPrimitiveType)type;
        // pt is not voidType.
        String wrapper = pt.getWrapperName();
        code.addCheckcast(wrapper);
        code.addInvokevirtual(wrapper, pt.getGetMethodName(),
                              pt.getGetMethodDescriptor());
        setType(type);
    }
    else {
        code.addCheckcast(type);
        setType(type);
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:26,代码来源:JvstCodeGen.java

示例5: wrapped

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
public static CtMethod wrapped(CtClass returnType, String mname,
                               CtClass[] parameterTypes,
                               CtClass[] exceptionTypes,
                               CtMethod body, ConstParameter constParam,
                               CtClass declaring)
    throws CannotCompileException
{
    CtMethod mt = new CtMethod(returnType, mname, parameterTypes,
                               declaring);
    mt.setModifiers(body.getModifiers());
    try {
        mt.setExceptionTypes(exceptionTypes);
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }

    Bytecode code = makeBody(declaring, declaring.getClassFile2(), body,
                             parameterTypes, returnType, constParam);
    MethodInfo minfo = mt.getMethodInfo2();
    minfo.setCodeAttribute(code.toCodeAttribute());
    // a stack map has been already created. 
    return mt;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:25,代码来源:CtNewWrappedMethod.java

示例6: compileReturn

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void compileReturn(Bytecode code, CtClass type) {
    if (type.isPrimitive()) {
        CtPrimitiveType pt = (CtPrimitiveType)type;
        if (pt != CtClass.voidType) {
            String wrapper = pt.getWrapperName();
            code.addCheckcast(wrapper);
            code.addInvokevirtual(wrapper, pt.getGetMethodName(),
                                  pt.getGetMethodDescriptor());
        }

        code.addOpcode(pt.getReturnOp());
    }
    else {
        code.addCheckcast(type);
        code.addOpcode(Bytecode.ARETURN);
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:18,代码来源:CtNewWrappedMethod.java

示例7: wrapped

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
public static CtConstructor wrapped(CtClass[] parameterTypes,
                                    CtClass[] exceptionTypes,
                                    int howToCallSuper,
                                    CtMethod body,
                                    CtMethod.ConstParameter constParam,
                                    CtClass declaring)
    throws CannotCompileException
{
    try {
        CtConstructor cons = new CtConstructor(parameterTypes, declaring);
        cons.setExceptionTypes(exceptionTypes);
        Bytecode code = makeBody(declaring, declaring.getClassFile2(),
                                 howToCallSuper, body,
                                 parameterTypes, constParam);
        cons.getMethodInfo2().setCodeAttribute(code.toCodeAttribute());
        // a stack map table is not needed.
        return cons;
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:23,代码来源:CtNewWrappedConstructor.java

示例8: compile

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
/**
 * Produces codes in which a new object is created and assigned to
 * the field as the initial value.
 */
int compile(CtClass type, String name, Bytecode code,
            CtClass[] parameters, Javac drv)
    throws CannotCompileException
{
    int stacksize;

    code.addAload(0);
    code.addNew(objectType);
    code.add(Bytecode.DUP);
    code.addAload(0);

    if (stringParams == null)
        stacksize = 4;
    else
        stacksize = compileStringParameter(code) + 4;

    if (withConstructorParams)
        stacksize += CtNewWrappedMethod.compileParameterList(code,
                                                    parameters, 1);

    code.addInvokespecial(objectType, "<init>", getDescriptor());
    code.addPutfield(Bytecode.THIS, name, Descriptor.of(type));
    return stacksize;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:29,代码来源:CtField.java

示例9: compileIfStatic

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
/**
 * Produces codes for a static field.
 */
int compileIfStatic(CtClass type, String name, Bytecode code,
                    Javac drv) throws CannotCompileException
{
    String desc;

    code.addNew(objectType);
    code.add(Bytecode.DUP);

    int stacksize = 2;
    if (stringParams == null)
        desc = "()V";
    else {
        desc = "([Ljava/lang/String;)V";
        stacksize += compileStringParameter(code);
    }

    code.addInvokespecial(objectType, "<init>", desc);
    code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type));
    return stacksize;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:24,代码来源:CtField.java

示例10: fixDeadcode

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
private void fixDeadcode(byte[] code, TypedBlock block) throws BadBytecode {
    int pos = block.position;
    int len = block.length - 3;
    if (len < 0) {
        // if the dead-code length is shorter than 3 bytes.
        if (len == -1)
            code[pos] = Bytecode.NOP;

        code[pos + block.length - 1] = (byte)Bytecode.ATHROW;
        block.incoming = 1;
        recordStackMap(block, 0);
        return;
    }

    // if block.incomping > 0, all the incoming edges are from
    // other dead code blocks.  So set block.incoming to 0.
    block.incoming = 0;

    for (int k = 0; k < len; k++) 
        code[pos + k] = Bytecode.NOP;

    code[pos + len] = (byte)Bytecode.GOTO;
    ByteArray.write16bit(-len, code, pos + len + 1);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:25,代码来源:MapMaker.java

示例11: insertAfterAdvice

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
private int insertAfterAdvice(Bytecode code, Javac jv, String src,
                              ConstPool cp, CtClass rtype, int varNo)
    throws CompileError
{
    int pc = code.currentPc();
    if (rtype == CtClass.voidType) {
        code.addOpcode(Opcode.ACONST_NULL);
        code.addAstore(varNo);
        jv.compileStmnt(src);
        code.addOpcode(Opcode.RETURN);
        if (code.getMaxLocals() < 1)
            code.setMaxLocals(1);
    }
    else {
        code.addStore(varNo, rtype);
        jv.compileStmnt(src);
        code.addLoad(varNo, rtype);
        if (rtype.isPrimitive())
            code.addOpcode(((CtPrimitiveType)rtype).getReturnOp());
        else
            code.addOpcode(Opcode.ARETURN);
    }

    return code.currentPc() - pc;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:26,代码来源:CtBehavior.java

示例12: callFind2Methods

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
/**
 * @param thisMethod        might be null.
 */
private static void callFind2Methods(Bytecode code, String superMethod, String thisMethod,
                                     int index, String desc, int classVar, int arrayVar) {
    String findClass = RuntimeSupport.class.getName();
    String findDesc
        = "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/reflect/Method;)V";

    code.addAload(classVar);
    code.addLdc(superMethod);
    if (thisMethod == null)
        code.addOpcode(Opcode.ACONST_NULL);
    else
        code.addLdc(thisMethod);

    code.addIconst(index);
    code.addLdc(desc);
    code.addAload(arrayVar);
    code.addInvokestatic(findClass, "find2Methods", findDesc);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:22,代码来源:ProxyFactory.java

示例13: makeDelegator

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
private MethodInfo makeDelegator(Method meth, String desc,
            ConstPool cp, Class declClass, String delegatorName) {
    MethodInfo delegator = new MethodInfo(cp, delegatorName, desc);
    delegator.setAccessFlags(Modifier.FINAL | Modifier.PUBLIC
            | (meth.getModifiers() & ~(Modifier.PRIVATE
                                       | Modifier.PROTECTED
                                       | Modifier.ABSTRACT
                                       | Modifier.NATIVE
                                       | Modifier.SYNCHRONIZED)));
    setThrows(delegator, cp, meth);
    Bytecode code = new Bytecode(cp, 0, 0);
    code.addAload(0);
    int s = addLoadParameters(code, meth.getParameterTypes(), 1);
    Class targetClass = invokespecialTarget(declClass);
    code.addInvokespecial(targetClass.isInterface(), cp.addClassInfo(targetClass.getName()),
                          meth.getName(), desc);
    addReturn(code, meth.getReturnType());
    code.setMaxLocals(++s);
    delegator.setCodeAttribute(code.toCodeAttribute());
    return delegator;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:22,代码来源:ProxyFactory.java

示例14: addLoad

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
private static int addLoad(Bytecode code, int n, Class type) {
    if (type.isPrimitive()) {
        if (type == Long.TYPE) {
            code.addLload(n);
            return 2;
        }
        else if (type == Float.TYPE)
            code.addFload(n);
        else if (type == Double.TYPE) {
            code.addDload(n);
            return 2;
        }
        else
            code.addIload(n);
    }
    else
        code.addAload(n);

    return 1;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:21,代码来源:ProxyFactory.java

示例15: addReturn

import scouter.javassist.bytecode.Bytecode; //导入依赖的package包/类
private static int addReturn(Bytecode code, Class type) {
    if (type.isPrimitive()) {
        if (type == Long.TYPE) {
            code.addOpcode(Opcode.LRETURN);
            return 2;
        }
        else if (type == Float.TYPE)
            code.addOpcode(Opcode.FRETURN);
        else if (type == Double.TYPE) {
            code.addOpcode(Opcode.DRETURN);
            return 2;
        }
        else if (type == Void.TYPE) {
            code.addOpcode(Opcode.RETURN);
            return 0;
        }
        else
            code.addOpcode(Opcode.IRETURN);
    }
    else
        code.addOpcode(Opcode.ARETURN);

    return 1;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:25,代码来源:ProxyFactory.java


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