• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Bytecode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: addDefaultConstructor

import javassist.bytecode.Bytecode; //导入依赖的package包/类
/**
 * Declares a constructor that takes no parameter.
 *
 * @param classfile The class descriptor
 *
 * @throws CannotCompileException Indicates trouble with the underlying Javassist calls
 */
private void addDefaultConstructor(ClassFile classfile) throws CannotCompileException {
	final ConstPool constPool = classfile.getConstPool();
	final String constructorSignature = "()V";
	final MethodInfo constructorMethodInfo = new MethodInfo( constPool, MethodInfo.nameInit, constructorSignature );

	final Bytecode code = new Bytecode( constPool, 0, 1 );
	// aload_0
	code.addAload( 0 );
	// invokespecial
	code.addInvokespecial( BulkAccessor.class.getName(), MethodInfo.nameInit, constructorSignature );
	// return
	code.addOpcode( Opcode.RETURN );

	constructorMethodInfo.setCodeAttribute( code.toCodeAttribute() );
	constructorMethodInfo.setAccessFlags( AccessFlag.PUBLIC );
	classfile.addMethod( constructorMethodInfo );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:BulkAccessorFactory.java


示例2: modifyClassConstructor

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private void modifyClassConstructor(ClassFile cf)
    throws CannotCompileException, NotFoundException
{
    if (fieldInitializers == null)
        return;

    Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
    Javac jv = new Javac(code, this);
    int stacksize = 0;
    boolean doInit = false;
    for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) {
        CtField f = fi.field;
        if (Modifier.isStatic(f.getModifiers())) {
            doInit = true;
            int s = fi.init.compileIfStatic(f.getType(), f.getName(),
                                            code, jv);
            if (stacksize < s)
                stacksize = s;
        }
    }

    if (doInit)    // need an initializer for static fileds.
        modifyClassConstructor(cf, code, stacksize, 0);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:25,代码来源:CtClassType.java


示例3: insertAuxInitializer

import javassist.bytecode.Bytecode; //导入依赖的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: makeFieldInitializer

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private int makeFieldInitializer(Bytecode code, CtClass[] parameters)
    throws CannotCompileException, NotFoundException
{
    int stacksize = 0;
    Javac jv = new Javac(code, this);
    try {
        jv.recordParams(parameters, false);
    }
    catch (CompileError e) {
        throw new CannotCompileException(e);
    }

    for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) {
        CtField f = fi.field;
        if (!Modifier.isStatic(f.getModifiers())) {
            int s = fi.init.compile(f.getType(), f.getName(), code,
                                    parameters, jv);
            if (stacksize < s)
                stacksize = s;
        }
    }

    return stacksize;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:25,代码来源:CtClassType.java


示例5: storeStack0

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void storeStack0(int i, int n, CtClass[] params, int regno,
        Bytecode bytecode) {
    if (i >= n)
        return;
    else {
        CtClass c = params[i];
        int size;
        if (c instanceof CtPrimitiveType)
            size = ((CtPrimitiveType)c).getDataSize();
        else
            size = 1;

        storeStack0(i + 1, n, params, regno + size, bytecode);
        bytecode.addStore(regno, c);
    }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:17,代码来源:Expr.java


示例6: replace0

import javassist.bytecode.Bytecode; //导入依赖的package包/类
protected void replace0(int pos, Bytecode bytecode, int size)
        throws BadBytecode {
    byte[] code = bytecode.get();
    edited = true;
    int gap = code.length - size;
    for (int i = 0; i < size; ++i)
        iterator.writeByte(NOP, pos + i);

    if (gap > 0)
        pos = iterator.insertGapAt(pos, gap, false).position;

    iterator.write(code, pos);
    iterator.insert(bytecode.getExceptionTable(), pos);
    maxLocals = bytecode.getMaxLocals();
    maxStack = bytecode.getMaxStack();
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:17,代码来源:Expr.java


示例7: addDefaultConstructor

import javassist.bytecode.Bytecode; //导入依赖的package包/类
/**
 * Declares a constructor that takes no parameter.
 *
 * @param classfile
 * @throws CannotCompileException
 */
private void addDefaultConstructor(ClassFile classfile) throws CannotCompileException {
	ConstPool cp = classfile.getConstPool();
	String cons_desc = "()V";
	MethodInfo mi = new MethodInfo( cp, MethodInfo.nameInit, cons_desc );

	Bytecode code = new Bytecode( cp, 0, 1 );
	// aload_0
	code.addAload( 0 );
	// invokespecial
	code.addInvokespecial( BulkAccessor.class.getName(), MethodInfo.nameInit, cons_desc );
	// return
	code.addOpcode( Opcode.RETURN );

	mi.setCodeAttribute( code.toCodeAttribute() );
	mi.setAccessFlags( AccessFlag.PUBLIC );
	classfile.addMethod( mi );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:BulkAccessorFactory.java


示例8: addGetFieldHandlerMethod

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private void addGetFieldHandlerMethod(ClassFile classfile)
		throws CannotCompileException {
	ConstPool cp = classfile.getConstPool();
	int this_class_index = cp.getThisClassInfo();
	MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
	                                  GETFIELDHANDLER_METHOD_DESCRIPTOR);
	/* local variable | this | */
	Bytecode code = new Bytecode(cp, 2, 1);
	// aload_0 // load this
	code.addAload(0);
	// getfield // get field "$JAVASSIST_CALLBACK" defined already
	code.addOpcode(Opcode.GETFIELD);
	int field_index = cp.addFieldrefInfo(this_class_index,
	                                     HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
	code.addIndex(field_index);
	// areturn // return the value of the field
	code.addOpcode(Opcode.ARETURN);
	minfo.setCodeAttribute(code.toCodeAttribute());
	minfo.setAccessFlags(AccessFlag.PUBLIC);
	classfile.addMethod(minfo);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:22,代码来源:FieldTransformer.java


示例9: addSetFieldHandlerMethod

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private void addSetFieldHandlerMethod(ClassFile classfile)
		throws CannotCompileException {
	ConstPool cp = classfile.getConstPool();
	int this_class_index = cp.getThisClassInfo();
	MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
	                                  SETFIELDHANDLER_METHOD_DESCRIPTOR);
	/* local variables | this | callback | */
	Bytecode code = new Bytecode(cp, 3, 3);
	// aload_0 // load this
	code.addAload(0);
	// aload_1 // load callback
	code.addAload(1);
	// putfield // put field "$JAVASSIST_CALLBACK" defined already
	code.addOpcode(Opcode.PUTFIELD);
	int field_index = cp.addFieldrefInfo(this_class_index,
	                                     HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
	code.addIndex(field_index);
	// return
	code.addOpcode(Opcode.RETURN);
	minfo.setCodeAttribute(code.toCodeAttribute());
	minfo.setAccessFlags(AccessFlag.PUBLIC);
	classfile.addMethod(minfo);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:FieldTransformer.java


示例10: addTypeDependDataLoad

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void addTypeDependDataLoad(Bytecode code, String typeName,
                                          int i) {
	if ((typeName.charAt(0) == 'L')
	    && (typeName.charAt(typeName.length() - 1) == ';')
	    || (typeName.charAt(0) == '[')) {
		// reference type
		code.addAload(i);
	} else if (typeName.equals("Z") || typeName.equals("B")
	           || typeName.equals("C") || typeName.equals("I")
	           || typeName.equals("S")) {
		// boolean, byte, char, int, short
		code.addIload(i);
	} else if (typeName.equals("D")) {
		// double
		code.addDload(i);
	} else if (typeName.equals("F")) {
		// float
		code.addFload(i);
	} else if (typeName.equals("J")) {
		// long
		code.addLload(i);
	} else {
		// bad type
		throw new RuntimeException("bad type: " + typeName);
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:FieldTransformer.java


示例11: addTypeDependDataStore

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void addTypeDependDataStore(Bytecode code, String typeName,
                                           int i) {
	if ((typeName.charAt(0) == 'L')
	    && (typeName.charAt(typeName.length() - 1) == ';')
	    || (typeName.charAt(0) == '[')) {
		// reference type
		code.addAstore(i);
	} else if (typeName.equals("Z") || typeName.equals("B")
	           || typeName.equals("C") || typeName.equals("I")
	           || typeName.equals("S")) {
		// boolean, byte, char, int, short
		code.addIstore(i);
	} else if (typeName.equals("D")) {
		// double
		code.addDstore(i);
	} else if (typeName.equals("F")) {
		// float
		code.addFstore(i);
	} else if (typeName.equals("J")) {
		// long
		code.addLstore(i);
	} else {
		// bad type
		throw new RuntimeException("bad type: " + typeName);
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:FieldTransformer.java


示例12: addTypeDependDataReturn

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void addTypeDependDataReturn(Bytecode code, String typeName) {
	if ((typeName.charAt(0) == 'L')
	    && (typeName.charAt(typeName.length() - 1) == ';')
	    || (typeName.charAt(0) == '[')) {
		// reference type
		code.addOpcode(Opcode.ARETURN);
	} else if (typeName.equals("Z") || typeName.equals("B")
	           || typeName.equals("C") || typeName.equals("I")
	           || typeName.equals("S")) {
		// boolean, byte, char, int, short
		code.addOpcode(Opcode.IRETURN);
	} else if (typeName.equals("D")) {
		// double
		code.addOpcode(Opcode.DRETURN);
	} else if (typeName.equals("F")) {
		// float
		code.addOpcode(Opcode.FRETURN);
	} else if (typeName.equals("J")) {
		// long
		code.addOpcode(Opcode.LRETURN);
	} else {
		// bad type
		throw new RuntimeException("bad type: " + typeName);
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:FieldTransformer.java


示例13: addUnwrapper

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private void addUnwrapper(Bytecode code, Class type) {
	final int index = FactoryHelper.typeIndex( type );
	final String wrapperType = FactoryHelper.wrapperTypes[index];
	// checkcast
	code.addCheckcast( wrapperType );
	// invokevirtual
	code.addInvokevirtual( wrapperType, FactoryHelper.unwarpMethods[index], FactoryHelper.unwrapDesc[index] );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:BulkAccessorFactory.java


示例14: addGetFieldHandlerMethod

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private void addGetFieldHandlerMethod(ClassFile classfile) throws CannotCompileException, BadBytecode {
	final ConstPool constPool = classfile.getConstPool();
	final int thisClassInfo = constPool.getThisClassInfo();
	final MethodInfo getterMethodInfo = new MethodInfo(
			constPool,
			GETFIELDHANDLER_METHOD_NAME,
			GETFIELDHANDLER_METHOD_DESCRIPTOR
	);

	/* local variable | this | */
	final Bytecode code = new Bytecode( constPool, 2, 1 );
	// aload_0 // load this
	code.addAload( 0 );
	// getfield // get field "$JAVASSIST_CALLBACK" defined already
	code.addOpcode( Opcode.GETFIELD );
	final int fieldIndex = constPool.addFieldrefInfo( thisClassInfo, HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR );
	code.addIndex( fieldIndex );
	// areturn // return the value of the field
	code.addOpcode( Opcode.ARETURN );
	getterMethodInfo.setCodeAttribute( code.toCodeAttribute() );
	getterMethodInfo.setAccessFlags( AccessFlag.PUBLIC );
	final CodeAttribute codeAttribute = getterMethodInfo.getCodeAttribute();
	if ( codeAttribute != null ) {
		final StackMapTable smt = MapMaker.make( classPool, getterMethodInfo );
		codeAttribute.setAttribute( smt );
	}
	classfile.addMethod( getterMethodInfo );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:FieldTransformer.java


示例15: addSetFieldHandlerMethod

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private void addSetFieldHandlerMethod(ClassFile classfile) throws CannotCompileException, BadBytecode {
	final ConstPool constPool = classfile.getConstPool();
	final int thisClassInfo = constPool.getThisClassInfo();
	final MethodInfo methodInfo = new MethodInfo(
			constPool,
			SETFIELDHANDLER_METHOD_NAME,
			SETFIELDHANDLER_METHOD_DESCRIPTOR
	);

	/* local variables | this | callback | */
	final Bytecode code = new Bytecode(constPool, 3, 3);
	// aload_0 : load this
	code.addAload( 0 );
	// aload_1 : load callback
	code.addAload( 1 );
	// putfield // put field "$JAVASSIST_CALLBACK" defined already
	code.addOpcode( Opcode.PUTFIELD );
	final int fieldIndex = constPool.addFieldrefInfo( thisClassInfo, HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR );
	code.addIndex( fieldIndex );
	// return
	code.addOpcode( Opcode.RETURN );
	methodInfo.setCodeAttribute( code.toCodeAttribute() );
	methodInfo.setAccessFlags( AccessFlag.PUBLIC );
	final CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
	if ( codeAttribute != null ) {
		final StackMapTable smt = MapMaker.make( classPool, methodInfo );
		codeAttribute.setAttribute( smt );
	}
	classfile.addMethod( methodInfo );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:FieldTransformer.java


示例16: addTypeDependDataLoad

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void addTypeDependDataLoad(Bytecode code, String typeName, int i) {
	if ( typeName.charAt( 0 ) == 'L'
			&& typeName.charAt( typeName.length() - 1 ) == ';'
			|| typeName.charAt( 0 ) == '[' ) {
		// reference type
		code.addAload( i );
	}
	else if ( typeName.equals( "Z" )
			|| typeName.equals( "B" )
			|| typeName.equals( "C" )
			|| typeName.equals( "I" )
			|| typeName.equals( "S" ) ) {
		// boolean, byte, char, int, short
		code.addIload( i );
	}
	else if ( typeName.equals( "D" ) ) {
		// double
		code.addDload( i );
	}
	else if ( typeName.equals( "F" ) ) {
		// float
		code.addFload( i );
	}
	else if ( typeName.equals( "J" ) ) {
		// long
		code.addLload( i );
	}
	else {
		// bad type
		throw new RuntimeException( "bad type: " + typeName );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:FieldTransformer.java


示例17: addTypeDependDataStore

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void addTypeDependDataStore(Bytecode code, String typeName, int i) {
	if ( typeName.charAt( 0 ) == 'L'
			&& typeName.charAt( typeName.length() - 1 ) == ';'
			|| typeName.charAt( 0 ) == '[' ) {
		// reference type
		code.addAstore( i );
	}
	else if ( typeName.equals( "Z" )
			|| typeName.equals( "B" )
			|| typeName.equals( "C" )
			|| typeName.equals( "I" )
			|| typeName.equals( "S" ) ) {
		// boolean, byte, char, int, short
		code.addIstore( i );
	}
	else if ( typeName.equals( "D" ) ) {
		// double
		code.addDstore( i );
	}
	else if ( typeName.equals( "F" ) ) {
		// float
		code.addFstore( i );
	}
	else if ( typeName.equals( "J" ) ) {
		// long
		code.addLstore( i );
	}
	else {
		// bad type
		throw new RuntimeException( "bad type: " + typeName );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:FieldTransformer.java


示例18: addTypeDependDataReturn

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private static void addTypeDependDataReturn(Bytecode code, String typeName) {
	if ( typeName.charAt( 0 ) == 'L'
			&& typeName.charAt( typeName.length() - 1 ) == ';'
			|| typeName.charAt( 0 ) == '[') {
		// reference type
		code.addOpcode( Opcode.ARETURN );
	}
	else if ( typeName.equals( "Z" )
			|| typeName.equals( "B" )
			|| typeName.equals( "C" )
			|| typeName.equals( "I" )
			|| typeName.equals( "S" ) ) {
		// boolean, byte, char, int, short
		code.addOpcode( Opcode.IRETURN );
	}
	else if ( typeName.equals( "D" ) ) {
		// double
		code.addOpcode( Opcode.DRETURN );
	}
	else if ( typeName.equals( "F" ) ) {
		// float
		code.addOpcode( Opcode.FRETURN );
	}
	else if ( typeName.equals( "J" ) ) {
		// long
		code.addOpcode( Opcode.LRETURN );
	}
	else {
		// bad type
		throw new RuntimeException( "bad type: " + typeName );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:FieldTransformer.java


示例19: makeClassInitializer

import javassist.bytecode.Bytecode; //导入依赖的package包/类
public CtConstructor makeClassInitializer()
    throws CannotCompileException
{
    CtConstructor clinit = getClassInitializer();
    if (clinit != null)
        return clinit;

    checkModify();
    ClassFile cf = getClassFile2();
    Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
    modifyClassConstructor(cf, code, 0, 0);
    return getClassInitializer();
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:14,代码来源:CtClassType.java


示例20: modifyConstructors

import javassist.bytecode.Bytecode; //导入依赖的package包/类
private void modifyConstructors(ClassFile cf)
    throws CannotCompileException, NotFoundException
{
    if (fieldInitializers == null)
        return;

    ConstPool cp = cf.getConstPool();
    List<MethodInfo> list = cf.getMethods();
    int n = list.size();
    for (int i = 0; i < n; ++i) {
        MethodInfo minfo = (MethodInfo)list.get(i);
        if (minfo.isConstructor()) {
            CodeAttribute codeAttr = minfo.getCodeAttribute();
            if (codeAttr != null)
                try {
                    Bytecode init = new Bytecode(cp, 0,
                                            codeAttr.getMaxLocals());
                    CtClass[] params
                        = Descriptor.getParameterTypes(
                                            minfo.getDescriptor(),
                                            classPool);
                    int stacksize = makeFieldInitializer(init, params);
                    insertAuxInitializer(codeAttr, init, stacksize);
                    minfo.rebuildStackMapIf6(classPool, cf);
                }
                catch (BadBytecode e) {
                    throw new CannotCompileException(e);
                }
        }
    }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:32,代码来源:CtClassType.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BasicVisualLexicon类代码示例发布时间:2022-05-22
下一篇:
Java Nullable类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap