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


Java Bytecode.addGetstatic方法代码示例

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


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

示例1: getter

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
 * Creates a public getter method.  The getter method returns the value
 * of the specified field in the class to which this method is added.
 * The created method is initially not static even if the field is
 * static.  Change the modifiers if the method should be static.
 *
 * @param methodName        the name of the getter
 * @param field             the field accessed.
 */
public static CtMethod getter(String methodName, CtField field)
    throws CannotCompileException
{
    FieldInfo finfo = field.getFieldInfo2();
    String fieldType = finfo.getDescriptor();
    String desc = "()" + fieldType;
    ConstPool cp = finfo.getConstPool();
    MethodInfo minfo = new MethodInfo(cp, methodName, desc);
    minfo.setAccessFlags(AccessFlag.PUBLIC);

    Bytecode code = new Bytecode(cp, 2, 1);
    try {
        String fieldName = finfo.getName();
        if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0) {
            code.addAload(0);
            code.addGetfield(Bytecode.THIS, fieldName, fieldType);
        }
        else
            code.addGetstatic(Bytecode.THIS, fieldName, fieldType);

        code.addReturn(field.getType());
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }

    minfo.setCodeAttribute(code.toCodeAttribute());
    CtClass cc = field.getDeclaringClass();
    // a stack map is not needed.
    return new CtMethod(minfo, cc);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:41,代码来源:CtNewMethod.java

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

示例3: makeForwarder

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
 * @param delegatorName     null if the original method is abstract.
 */
private static MethodInfo makeForwarder(String thisClassName,
                Method meth, String desc, ConstPool cp,
                Class declClass, String delegatorName, int index,
                ArrayList forwarders) {
    MethodInfo forwarder = new MethodInfo(cp, meth.getName(), desc);
    forwarder.setAccessFlags(Modifier.FINAL
                | (meth.getModifiers() & ~(Modifier.ABSTRACT
                                           | Modifier.NATIVE
                                           | Modifier.SYNCHRONIZED)));
    setThrows(forwarder, cp, meth);
    int args = Descriptor.paramSize(desc);
    Bytecode code = new Bytecode(cp, 0, args + 2);
    /*
     * static {
     *   methods[index * 2]
     *     = RuntimeSupport.findSuperMethod(this, <overridden name>, <desc>);
     *   methods[index * 2 + 1]
     *     = RuntimeSupport.findMethod(this, <delegator name>, <desc>);
     *     or = null // the original method is abstract.
     * }
     *     :
     * return ($r)handler.invoke(this, methods[index * 2],
     *                methods[index * 2 + 1], $args);
     */
    int origIndex = index * 2;
    int delIndex = index * 2 + 1;
    int arrayVar = args + 1;
    code.addGetstatic(thisClassName, HOLDER, HOLDER_TYPE);
    code.addAstore(arrayVar);

    forwarders.add(new Find2MethodsArgs(meth.getName(), delegatorName, desc, origIndex));

    code.addAload(0);
    code.addGetfield(thisClassName, HANDLER, HANDLER_TYPE);
    code.addAload(0);

    code.addAload(arrayVar);
    code.addIconst(origIndex);
    code.addOpcode(Opcode.AALOAD);

    code.addAload(arrayVar);
    code.addIconst(delIndex);
    code.addOpcode(Opcode.AALOAD);

    makeParameterList(code, meth.getParameterTypes());
    code.addInvokeinterface(MethodHandler.class.getName(), "invoke",
        "(Ljava/lang/Object;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;",
        5);
    Class retType = meth.getReturnType();
    addUnwrapper(code, retType);
    addReturn(code, retType);

    CodeAttribute ca = code.toCodeAttribute();
    forwarder.setCodeAttribute(ca);
    return forwarder;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:60,代码来源:ProxyFactory.java


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