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


Java GeneratorAdapter类代码示例

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


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

示例1: loadMH

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
@Contract("null, null, _, _ -> fail")
private static void loadMH(GeneratorAdapter adapter, Type reflectorClass, int flags, int mhIndex) {
    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) == 0) return;

    /* Load MethodHandle field */
    adapter.loadThis();
    adapter.getField(notNull(reflectorClass, "Reflector class shouldn't be null!"), MHF, MH_ARRAY);

    /* Load index */
    if(mhIndex >= 0 && mhIndex <= 5)
        /* ICONST_x offset is 3, iow ICONST_0 = 3, ICONST_1 = 4 */
        adapter.visitInsn(ICONST_0 + mhIndex);
    else
        adapter.visitIntInsn(BIPUSH, mhIndex);

    /* Load MethodHandle from array */
    adapter.visitInsn(AALOAD);
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:19,代码来源:MethodGenerator.java

示例2: createClassArray

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
private static void createClassArray(GeneratorAdapter mv, List<Type> args) {
        // create an array of objects capable of containing all the parameters and optionally the "this"

        createLocals(mv, args);
        // we need to maintain the stack index when loading parameters from, as for long and double
        // values, it uses 2 stack elements, all others use only 1 stack element.
        int stackIndex = 0;
        for (int arrayIndex = 0; arrayIndex < args.size(); arrayIndex++) {
            Type arg = args.get(arrayIndex);
            // duplicate the array of objects reference, it will be used to store the value in.
            mv.dup();
            // index in the array of objects to store the boxed parameter.
            mv.push(arrayIndex);
            // Pushes the appropriate local variable on the stack
            redirectLocal(mv, arg);
//			 mv.visitLdcInsn(Type.getType(arg.getDescriptor()));
            // potentially box up intrinsic types.
//			 mv.box(arg);
            mv.arrayStore(Type.getType(Class.class));
            // stack index must progress according to the parameter type we just processed.
//			 stackIndex += arg.getSize();
        }
    }
 
开发者ID:Meituan-Dianping,项目名称:Robust,代码行数:24,代码来源:RobustAsmUtils.java

示例3: visitEnd

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
public void visitEnd() {
	if (! doneAddField) {
		doneAddField = true;
		
		super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_FIELD, Type.getDescriptor(Agent.class), null, null);
	}
	
	if (! doneAddMethod) {
		doneAddMethod = true;

		GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(LOG_CLASS_METHOD, LOG_CLASS_SIGNATURE), LOG_CLASS_SIGNATURE, new Type[] {}, this);

		Label target = mg.newLabel();
		mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
		mg.ifNull(target);
		mg.push(LOG_INTERNAL_TYPE);
		mg.putStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
		mg.mark(target);
		mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
		mg.returnValue();
	}
	
	super.visitEnd();
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:25,代码来源:SystemInstrument.java

示例4: visitEnd

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void visitEnd() {
	if (!done && found) {
		done = true;
		try {
			GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, new Method(LOG_INTERNAL_METHOD, LOG_METHOD_SIGNATURE), LOG_METHOD_SIGNATURE, new Type[] {}, this);

			Label start = mg.mark();
			mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME)));
			mg.returnValue();
			Label end   = mg.mark();
			mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
			mg.returnValue();
			
			mg.endMethod();
		} catch (NoSuchMethodException nsme) {
			System.err.println("Unable to find Agent.rlogCallChain method");
			System.err.println("M:"+nsme);
			nsme.printStackTrace();
		}
	}
	
	super.visitEnd();
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:25,代码来源:CallChainInstrument.java

示例5: visitEnd

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void visitEnd() {
	if (!foundClinit && instrument()) {
		// didn't find <clinit> so lets make one
		try {
			GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(CLINIT_NAME, CLINIT_SIGNATURE), CLINIT_SIGNATURE, new Type[] {}, this);
			
			Label start = mg.mark();
			mg.push(className);
			mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME, String.class)));
			Label end   = mg.mark();
			mg.returnValue();
			
			mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
			mg.returnValue();
			
			mg.endMethod();
		} catch (NoSuchMethodException nsme) {
			System.out.println("Unable to find Agent.reportClass method");
		}
	}
	
	super.visitEnd();
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:25,代码来源:ClinitInstrument.java

示例6: visitx

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));
        return;
    }
    for (String string : strings) {
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}
 
开发者ID:meili,项目名称:Aceso,代码行数:18,代码来源:IntSwitch.java

示例7: loadVariableArray

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
/**
 * Given an array on the stack, it loads it with the values of the given variables stating at
 * offset.
 */
static void loadVariableArray(
         GeneratorAdapter mv,
         List<LocalVariable> variables, int offset) {
    // we need to maintain the stack index when loading parameters from, as for long and double
    // values, it uses 2 stack elements, all others use only 1 stack element.
    for (int i = offset; i < variables.size(); i++) {
        LocalVariable variable = variables.get(i);
        // duplicate the array of objects reference, it will be used to store the value in.
        mv.dup();
        // index in the array of objects to store the boxed parameter.
        mv.push(i);
        // Pushes the appropriate local variable on the stack
        mv.visitVarInsn(variable.type.getOpcode(Opcodes.ILOAD), variable.var);
        // potentially box up intrinsic types.
        mv.box(variable.type);
        // store it in the array
        mv.arrayStore(Type.getType(Object.class));
    }
}
 
开发者ID:meili,项目名称:Aceso,代码行数:24,代码来源:ByteCodeUtils.java

示例8: redirect

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
/**
 * Adds the instructions to do a generic redirection.
 */
protected void redirect(GeneratorAdapter mv, int change) {
    // code to check if a new implementation of the current class is available.
    Label l0 = new Label();
    mv.loadLocal(change);
    mv.visitJumpInsn(Opcodes.IFNULL, l0);
    doRedirect(mv, change);

    // Return
    if (type == Type.VOID_TYPE) {
        mv.pop();
    } else {
        ByteCodeUtils.unbox(mv, type);
    }
    mv.returnValue();

    // jump label for classes without any new implementation, just invoke the original
    // method implementation.
    mv.visitLabel(l0);
}
 
开发者ID:meili,项目名称:Aceso,代码行数:23,代码来源:Redirection.java

示例9: emitConstants

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
void emitConstants(GeneratorAdapter clinitgen){
	try
		{
		Var.pushThreadBindings(RT.map(RT.PRINT_DUP, RT.T));

		for(int i = 0; i < constants.count(); i++)
			{
               if(usedConstants.contains(i))
                   {
                   emitValue(constants.nth(i), clinitgen);
                   clinitgen.checkCast(constantType(i));
                   clinitgen.putStatic(objtype, constantName(i), constantType(i));
                   }
			}
		}
	finally
		{
		Var.popThreadBindings();
		}
}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:21,代码来源:Compiler.java

示例10: emitAssignLocal

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
public void emitAssignLocal(GeneratorAdapter gen, LocalBinding lb,Expr val){
	if(!isMutable(lb))
		throw new IllegalArgumentException("Cannot assign to non-mutable: " + lb.name);
	Class primc = lb.getPrimitiveType();
	gen.loadThis();
	if(primc != null)
		{
		if(!(val instanceof MaybePrimitiveExpr && ((MaybePrimitiveExpr) val).canEmitPrimitive()))
			throw new IllegalArgumentException("Must assign primitive to primitive mutable: " + lb.name);
		MaybePrimitiveExpr me = (MaybePrimitiveExpr) val;
		me.emitUnboxed(C.EXPRESSION, this, gen);
		gen.putField(objtype, lb.name, Type.getType(primc));
		}
	else
		{
		val.emit(C.EXPRESSION, this, gen);
		gen.putField(objtype, lb.name, OBJECT_TYPE);
		}
}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:20,代码来源:Compiler.java

示例11: emit

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
	boolean allKeysConstant = true;
	boolean allConstantKeysUnique = true;
	IPersistentSet constantKeys = PersistentHashSet.EMPTY;
	for(int i = 0; i < keyvals.count(); i+=2)
		{
		Expr k = (Expr) keyvals.nth(i);
		if(k instanceof LiteralExpr)
			{
			Object kval = k.eval();
			if (constantKeys.contains(kval))
				allConstantKeysUnique = false;
			else
				constantKeys = (IPersistentSet)constantKeys.cons(kval);
			}
		else
			allKeysConstant = false;
		}
	MethodExpr.emitArgsAsArray(keyvals, objx, gen);
	if((allKeysConstant && allConstantKeysUnique) || (keyvals.count() <= 2))
		gen.invokeStatic(RT_TYPE, mapUniqueKeysMethod);
	else
		gen.invokeStatic(RT_TYPE, mapMethod);
	if(context == C.STATEMENT)
		gen.pop();
}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:27,代码来源:Compiler.java

示例12: emitLetFnInits

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
public void emitLetFnInits(GeneratorAdapter gen, ObjExpr objx, IPersistentSet letFnLocals){
	//objx arg is enclosing objx, not this
	gen.checkCast(objtype);

	for(ISeq s = RT.keys(closes); s != null; s = s.next())
		{
		LocalBinding lb = (LocalBinding) s.first();
		if(letFnLocals.contains(lb))
			{
			Class primc = lb.getPrimitiveType();
			gen.dup();
			if(primc != null)
				{
				objx.emitUnboxedLocal(gen, lb);
				gen.putField(objtype, lb.name, Type.getType(primc));
				}
			else
				{
				objx.emitLocal(gen, lb, false);
				gen.putField(objtype, lb.name, OBJECT_TYPE);
				}
			}
		}
	gen.pop();

}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:27,代码来源:Compiler.java

示例13: emitAssign

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
public void emitAssign(C context, ObjExpr objx, GeneratorAdapter gen,
                       Expr val){
	if(targetClass != null && field != null)
		{
		target.emit(C.EXPRESSION, objx, gen);
		gen.checkCast(getType(targetClass));
		val.emit(C.EXPRESSION, objx, gen);
		gen.visitLineNumber(line, gen.mark());
		gen.dupX1();
		HostExpr.emitUnboxArg(objx, gen, field.getType());
		gen.putField(getType(targetClass), fieldName, Type.getType(field.getType()));
		}
	else
		{
		target.emit(C.EXPRESSION, objx, gen);
		gen.push(fieldName);
		val.emit(C.EXPRESSION, objx, gen);
		gen.visitLineNumber(line, gen.mark());
		gen.invokeStatic(REFLECTOR_TYPE, setInstanceFieldMethod);
		}
	if(context == C.STATEMENT)
		gen.pop();
}
 
开发者ID:mrange,项目名称:fsharpadvent2016,代码行数:24,代码来源:Compiler.java

示例14: emitMethods

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
protected void emitMethods(ClassVisitor cv){
	//override of invoke/doInvoke for each method
	for(ISeq s = RT.seq(methods); s != null; s = s.next())
		{
		ObjMethod method = (ObjMethod) s.first();
		method.emit(this, cv);
		}

	if(isVariadic())
		{
		GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
		                                            Method.getMethod("int getRequiredArity()"),
		                                            null,
		                                            null,
		                                            cv);
		gen.visitCode();
		gen.push(variadicMethod.reqParms.count());
		gen.returnValue();
		gen.endMethod();
		}
}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:22,代码来源:Compiler.java

示例15: emitClearLocals

import org.objectweb.asm.commons.GeneratorAdapter; //导入依赖的package包/类
void emitClearLocals(GeneratorAdapter gen){
//		for(int i = 1; i < numParams() + 1; i++)
//			{
//			if(!localsUsedInCatchFinally.contains(i))
//				{
//				gen.visitInsn(Opcodes.ACONST_NULL);
//				gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i);
//				}
//			}
//		for(int i = numParams() + 1; i < maxLocal + 1; i++)
//			{
//			if(!localsUsedInCatchFinally.contains(i))
//				{
//				LocalBinding b = (LocalBinding) RT.get(indexlocals, i);
//				if(b == null || maybePrimitiveType(b.init) == null)
//					{
//					gen.visitInsn(Opcodes.ACONST_NULL);
//					gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i);
//					}
//				}
//			}
//		if(((FnExpr)objx).onceOnly)
//			{
//			objx.emitClearCloses(gen);
//			}
	}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:27,代码来源:Compiler.java


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