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


Java Bytecode.addInvokespecial方法代码示例

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


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

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

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

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

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

示例5: compileParameterList

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
public static int compileParameterList(Bytecode code,
                            CtClass[] params, int regno) {
    if (params == null) {
        code.addIconst(0);                          // iconst_0
        code.addAnewarray(javaLangObject);          // anewarray Object
        return 1;
    }
    else {
        CtClass[] args = new CtClass[1];
        int n = params.length;
        code.addIconst(n);                          // iconst_<n>
        code.addAnewarray(javaLangObject);          // anewarray Object
        for (int i = 0; i < n; ++i) {
            code.addOpcode(Bytecode.DUP);           // dup
            code.addIconst(i);                      // iconst_<i>
            if (params[i].isPrimitive()) {
                CtPrimitiveType pt = (CtPrimitiveType)params[i];
                String wrapper = pt.getWrapperName();
                code.addNew(wrapper);               // new <wrapper>
                code.addOpcode(Bytecode.DUP);       // dup
                int s = code.addLoad(regno, pt);    // ?load <regno>
                regno += s;
                args[0] = pt;
                code.addInvokespecial(wrapper, "<init>",
                            Descriptor.ofMethod(CtClass.voidType, args));
                                                    // invokespecial
            }
            else {
                code.addAload(regno);               // aload <regno>
                ++regno;
            }

            code.addOpcode(Bytecode.AASTORE);       // aastore
        }

        return 8;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:39,代码来源:JvstCodeGen.java

示例6: delegator0

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static CtMethod delegator0(CtMethod delegate, CtClass declaring)
    throws CannotCompileException, NotFoundException
{
    MethodInfo deleInfo = delegate.getMethodInfo2();
    String methodName = deleInfo.getName();
    String desc = deleInfo.getDescriptor();
    ConstPool cp = declaring.getClassFile2().getConstPool();
    MethodInfo minfo = new MethodInfo(cp, methodName, desc);
    minfo.setAccessFlags(deleInfo.getAccessFlags());

    ExceptionsAttribute eattr = deleInfo.getExceptionsAttribute();
    if (eattr != null)
        minfo.setExceptionsAttribute(
                            (ExceptionsAttribute)eattr.copy(cp, null));

    Bytecode code = new Bytecode(cp, 0, 0);
    boolean isStatic = Modifier.isStatic(delegate.getModifiers());
    CtClass deleClass = delegate.getDeclaringClass();
    CtClass[] params = delegate.getParameterTypes();
    int s;
    if (isStatic) {
        s = code.addLoadParameters(params, 0);
        code.addInvokestatic(deleClass, methodName, desc);
    }
    else {
        code.addLoad(0, deleClass);
        s = code.addLoadParameters(params, 1);
        code.addInvokespecial(deleClass, methodName, desc);
    }

    code.addReturn(delegate.getReturnType());
    code.setMaxLocals(++s);
    code.setMaxStack(s < 2 ? 2 : s); // for a 2-word return value
    minfo.setCodeAttribute(code.toCodeAttribute());
    // a stack map is not needed. 
    return new CtMethod(minfo, declaring);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:38,代码来源:CtNewMethod.java

示例7: makeConstructor

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static MethodInfo makeConstructor(String thisClassName, Constructor cons,
                                          ConstPool cp, Class superClass, boolean doHandlerInit) {
    String desc = RuntimeSupport.makeDescriptor(cons.getParameterTypes(),
                                                Void.TYPE);
    MethodInfo minfo = new MethodInfo(cp, "<init>", desc);
    minfo.setAccessFlags(Modifier.PUBLIC);      // cons.getModifiers() & ~Modifier.NATIVE
    setThrows(minfo, cp, cons.getExceptionTypes());
    Bytecode code = new Bytecode(cp, 0, 0);

    // legacy: if we are not using caching then we initialise the instance's handler
    // from the class's static default interceptor and skip the next few instructions if
    // it is non-null
    if (doHandlerInit) {
        code.addAload(0);
        code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
        code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
        code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
        code.addOpcode(Opcode.IFNONNULL);
        code.addIndex(10);
    }
    // if caching is enabled then we don't have a handler to initialise so this else branch will install
    // the handler located in the static field of class RuntimeSupport.
    code.addAload(0);
    code.addGetstatic(NULL_INTERCEPTOR_HOLDER, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
    code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
    int pc = code.currentPc();

    code.addAload(0);
    int s = addLoadParameters(code, cons.getParameterTypes(), 1);
    code.addInvokespecial(superClass.getName(), "<init>", desc);
    code.addOpcode(Opcode.RETURN);
    code.setMaxLocals(s + 1);
    CodeAttribute ca = code.toCodeAttribute();
    minfo.setCodeAttribute(ca);

    StackMapTable.Writer writer = new StackMapTable.Writer(32);
    writer.sameFrame(pc);
    ca.setAttribute(writer.toStackMapTable(cp));
    return minfo;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:41,代码来源:ProxyFactory.java

示例8: makeWrapper

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static int makeWrapper(Bytecode code, Class type, int regno) {
    int index = FactoryHelper.typeIndex(type);
    String wrapper = FactoryHelper.wrapperTypes[index]; 
    code.addNew(wrapper);
    code.addOpcode(Opcode.DUP);
    addLoad(code, regno, type);
    code.addInvokespecial(wrapper, "<init>",
                          FactoryHelper.wrapperDesc[index]);
    return regno + FactoryHelper.dataSize[index];
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:11,代码来源:ProxyFactory.java

示例9: makeBody

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected static Bytecode makeBody(CtClass declaring, ClassFile classfile,
                                   int howToCallSuper,
                                   CtMethod wrappedBody,
                                   CtClass[] parameters,
                                   ConstParameter cparam)
    throws CannotCompileException
{
    int stacksize, stacksize2;

    int superclazz = classfile.getSuperclassId();
    Bytecode code = new Bytecode(classfile.getConstPool(), 0, 0);
    code.setMaxLocals(false, parameters, 0);
    code.addAload(0);
    if (howToCallSuper == PASS_NONE) {
        stacksize = 1;
        code.addInvokespecial(superclazz, "<init>", "()V");
    }
    else if (howToCallSuper == PASS_PARAMS) {
        stacksize = code.addLoadParameters(parameters, 1) + 1;
        code.addInvokespecial(superclazz, "<init>",
                              Descriptor.ofConstructor(parameters));
    }
    else {
        stacksize = compileParameterList(code, parameters, 1);
        String desc;
        if (cparam == null) {
            stacksize2 = 2;
            desc = ConstParameter.defaultConstDescriptor();
        }
        else {
            stacksize2 = cparam.compile(code) + 2;
            desc = cparam.constDescriptor();
        }

        if (stacksize < stacksize2)
            stacksize = stacksize2;

        code.addInvokespecial(superclazz, "<init>", desc);
    }

    if (wrappedBody == null)
        code.add(Bytecode.RETURN);
    else {
        stacksize2 = makeBody0(declaring, classfile, wrappedBody,
                               false, parameters, CtClass.voidType,
                               cparam, code);
        if (stacksize < stacksize2)
            stacksize = stacksize2;
    }

    code.setMaxStack(stacksize);
    return code;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:54,代码来源:CtNewWrappedConstructor.java

示例10: makeBody0

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected static int makeBody0(CtClass clazz, ClassFile classfile,
                               CtMethod wrappedBody,
                               boolean isStatic, CtClass[] parameters,
                               CtClass returnType, ConstParameter cparam,
                               Bytecode code)
    throws CannotCompileException
{
    if (!(clazz instanceof CtClassType))
        throw new CannotCompileException("bad declaring class"
                                         + clazz.getName());

    if (!isStatic)
        code.addAload(0);

    int stacksize = compileParameterList(code, parameters,
                                         (isStatic ? 0 : 1));
    int stacksize2;
    String desc;
    if (cparam == null) {
        stacksize2 = 0;
        desc = ConstParameter.defaultDescriptor();
    }
    else {
        stacksize2 = cparam.compile(code);
        desc = cparam.descriptor();
    }

    checkSignature(wrappedBody, desc);

    String bodyname;
    try {
        bodyname = addBodyMethod((CtClassType)clazz, classfile,
                                 wrappedBody);
        /* if an exception is thrown below, the method added above
         * should be removed. (future work :<)
         */
    }
    catch (BadBytecode e) {
        throw new CannotCompileException(e);
    }

    if (isStatic)
        code.addInvokestatic(Bytecode.THIS, bodyname, desc);
    else
        code.addInvokespecial(Bytecode.THIS, bodyname, desc);

    compileReturn(code, returnType);        // consumes 2 stack entries

    if (stacksize < stacksize2 + 2)
        stacksize = stacksize2 + 2;

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

示例11: makeBody

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected static Bytecode makeBody(CtClass declaring, ClassFile classfile,
                                   int howToCallSuper,
                                   CtMethod wrappedBody,
                                   CtClass[] parameters,
                                   CtMethod.ConstParameter cparam)
    throws CannotCompileException
{
    int stacksize, stacksize2;

    int superclazz = classfile.getSuperclassId();
    Bytecode code = new Bytecode(classfile.getConstPool(), 0, 0);
    code.setMaxLocals(false, parameters, 0);
    code.addAload(0);
    if (howToCallSuper == PASS_NONE) {
        stacksize = 1;
        code.addInvokespecial(superclazz, "<init>", "()V");
    }
    else if (howToCallSuper == PASS_PARAMS) {
        stacksize = code.addLoadParameters(parameters, 1) + 1;
        code.addInvokespecial(superclazz, "<init>",
                              Descriptor.ofConstructor(parameters));
    }
    else {
        stacksize = compileParameterList(code, parameters, 1);
        String desc;
        if (cparam == null) {
            stacksize2 = 2;
            desc = CtMethod.ConstParameter.defaultConstDescriptor();
        }
        else {
            stacksize2 = cparam.compile(code) + 2;
            desc = cparam.constDescriptor();
        }

        if (stacksize < stacksize2)
            stacksize = stacksize2;

        code.addInvokespecial(superclazz, "<init>", desc);
    }

    if (wrappedBody == null)
        code.add(Bytecode.RETURN);
    else {
        stacksize2 = makeBody0(declaring, classfile, wrappedBody,
                               false, parameters, CtClass.voidType,
                               cparam, code);
        if (stacksize < stacksize2)
            stacksize = stacksize2;
    }

    code.setMaxStack(stacksize);
    return code;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:54,代码来源:CtNewWrappedConstructor.java


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