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


Java ClassWriter.COMPUTE_FRAMES属性代码示例

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


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

示例1: transform

public byte[] transform(String name, byte[] basicClass) {
	int i = 0;
	while (i < transformers.size()) {
		if (transformers.get(i).is(name)) {
			ClassNode classNode = new ClassNode();
			ClassReader classReader = new ClassReader(basicClass);
			classReader.accept(classNode, 0);

			transformers.get(i).transform(classNode);

			ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
			classNode.accept(writer);
			basicClass = writer.toByteArray();

			System.out.println("[" + MineCamera.MODID + "] Patched " + transformers.get(i).className + " ...");
			transformers.get(i).done();
			i++;
			// transformers.remove(i);
		} else
			i++;
	}
	return basicClass;
}
 
开发者ID:PorPit,项目名称:MineCamera,代码行数:23,代码来源:CamTransformer.java

示例2: convert

@NotNull
@SuppressWarnings("unchecked")
static <T extends IClassTransformer> Class<T> convert(@NotNull Class<? extends OrionTransformer> transformer) {
    if(Arrays.asList(transformer.getInterfaces()).contains(IClassTransformer.class))
        return (Class<T>) transformer; /* no-op */

    // Orion transformer name
    String rawTransformerName = transformer.getName().replace('.', '/');

    // New wrapper class name
    String newWrapperName = getNewName(transformer);

    // Start generating new TransformerWrapper
    ClassReader cr = new ClassReader(TW_DATA);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);

    cn.accept(new WrapperGenerator(cw, TW_TYPE.getInternalName(), newWrapperName.replace('.', '/'), rawTransformerName));

    return requireNonNull((Class<T>) ClassLoaderTools.defineClass(Launch.classLoader, newWrapperName, cw.toByteArray()));
}
 
开发者ID:OrionMinecraft,项目名称:Orion,代码行数:22,代码来源:ClassTransformerConverter.java

示例3: generateTests

private void generateTests() throws IOException {
  ClassReader cr = new ClassReader(new FileInputStream(classNamePath.toFile()));
  ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  cr.accept(
      new ClassVisitor(Opcodes.ASM5, cw) {
        @Override
        public void visitEnd() {
          generateMethodTest1(cw);
          generateMethodTest2(cw);
          generateMethodTest3(cw);
          generateMethodTest4(cw);
          generateMethodTest5(cw);
          generateMethodTest6(cw);
          generateMethodTest7(cw);
          generateMethodTest8(cw);
          generateMethodTest9(cw);
          generateMethodTest10(cw);
          generateMethodTest11(cw);
          generateMethodTest12(cw);
          generateMethodTest13(cw);
          generateMethodMain(cw);
          super.visitEnd();
        }
      }, 0);
  new FileOutputStream(classNamePath.toFile()).write(cw.toByteArray());
}
 
开发者ID:inferjay,项目名称:r8,代码行数:26,代码来源:TestGenerator.java

示例4: generate

public byte[] generate(){
    String className = "eu.mikroskeem.test.shuriken.common.classtools.gen.GeneratedClass";
    String classNameInternal = className.replaceAll("\\.", "/");

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(
            V1_8,
            ACC_PUBLIC + ACC_SUPER,
            classNameInternal,
            null,
            Type.getInternalName(Object.class),
            null);
    FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "test", Type.getDescriptor(String.class), null, "hey");
    fv.visitEnd();
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:23,代码来源:ValidatorTester.java

示例5: modify

/**
 * 类修改器
 * 修改方法
 * @param className 类名
 * @param originalClass 原始类字节数组
 * @param interceptorId 注册的拦截器id
 * @return modified类字节数组
 */
@SuppressWarnings("unchecked")
public static byte[] modify(String className, byte[] originalClass,String interceptorId) {
    Interceptor interceptor = Interceptor.getInterceptor(interceptorId);
    if (!interceptor.matchBeforeReadClass(className, originalClass)) {
        return originalClass;
    }
    ClassReader cr = new ClassReader(originalClass);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);

    if (!interceptor.matchAfterReadClass(cn)) {
        return originalClass;
    }

    List<MethodNode> methods = cn.methods;
    boolean transformed = false;
    for (MethodNode node : methods) {
        if (MethodModifier.modifyMethod(interceptor,cn,node)) {
            transformed = true;
        }
    }
    if (!transformed) {
        return originalClass;
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

    cn.accept(cw);

    return cw.toByteArray();

}
 
开发者ID:yutian-tianpl,项目名称:byte-cobweb,代码行数:40,代码来源:ClassModifier.java

示例6: modify

/**
 * Modifies the class and returns the result as a byte array
 *
 * @return byte array
 *
 * @throws IOException rethrown from the {@link ClassReader} constructor
 */
public byte[] modify() throws IOException
{
    if (this.output == null)
    {
        final ClassReader classReader = new ClassReader(this.inputStream);
        final ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
        this.cv = classWriter;
        classReader.accept(this, ClassReader.EXPAND_FRAMES);
        this.output = classWriter.toByteArray();
    }

    return this.output;
}
 
开发者ID:MrGregorix,项目名称:Gasket,代码行数:20,代码来源:ClassModifier.java

示例7: transform

@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES);
    ClassVisitor cv = new ClassAdapter(cw);
    cr.accept(cv, ClassReader.SKIP_FRAMES);
    return cw.toByteArray();
}
 
开发者ID:RuntimeTools,项目名称:javametrics,代码行数:10,代码来源:ClassTransformer.java

示例8: transform

@Override
public byte[] transform(String name, String realName, byte[] bytes) {
    if (transformingClasses.containsKey(realName)) {
        ClassTransformer transformer = transformingClasses.get(realName);
        try {
            LOGGER.info("Transforming class " + realName);

            ClassNode classNode = new ClassNode();
            ClassReader classReader = new ClassReader(bytes);
            classReader.accept(classNode, 0);

            transformer.transform(classNode);

            ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
            classNode.accept(classWriter);

            // let gc clean this up
            transformingClasses.remove(realName);

            return classWriter.toByteArray();
        } catch (Exception e) {
            LOGGER.error(e.getClass().getSimpleName() + " thrown from transforming class " + realName + ": " + e.getMessage());
            ASMStackLogger.printStackTrace(e);
        }
    }
    return bytes;
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:27,代码来源:ForgeHaxTransformer.java

示例9: transform

private static byte[] transform(byte[] serverClass, boolean isObfuscated, transformType type)
{
    System.out.println("MALMO: Attempting to transform MinecraftServer");
    try
    {
        ClassNode cnode = new ClassNode();
        ClassReader creader = new ClassReader(serverClass);
        creader.accept(cnode, 0);
        
        switch (type)
        {
        case SERVER:
            overclockServer(cnode, isObfuscated);
            break;
        case RENDERER:
            overclockRenderer(cnode, isObfuscated);
            break;
        }
        
        ClassWriter cwriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
        cnode.accept(cwriter);
        return cwriter.toByteArray();
    }
    catch (Exception e)
    {
        System.out.println("MALMO FAILED to transform MinecraftServer - overclocking not available!");
    }
    return serverClass;
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:29,代码来源:OverclockingClassTransformer.java

示例10: transformClassLoader

private byte[] transformClassLoader(byte[] bytes) {
    ClassReader cr = new ClassReader(bytes);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES);
    ClassVisitor cv = new CV(cw);
    cr.accept(cv, 0);
    return cw.toByteArray();
}
 
开发者ID:SpongePowered,项目名称:Metronome,代码行数:7,代码来源:Agent.java

示例11: visit

@Override
public Object visit(ASTStreamSignature node, Object data) throws CompileException {

  LangUnitNode stream_hdr = node.getChildren(0);
  Debug.assertion(stream_hdr.isNodeId(JJTSTREAMHEADER),
      "first child should be Stream Type, but(" + stream_hdr.getNodeName() + ")");

  switch (stream_hdr.getStreamForm()) {
  case LangUnitNode.STREAMFORM_CLASS: {
    TContextClass class_context = (TContextClass) this.getTopContext();
    Debug.assertion(class_context != null, "top context should not be null");
    Debug.assertion(class_context.isForm(AbsType.FORM_CLASS), "top context should be class");

    String class_name = class_context.getName();

    String super_class_name = null;
    AbsClassType super_class = class_context.getSuperClass();

    if (super_class != null) {
      super_class_name = ((AbsType) super_class).getName();
      Debug.assertion(super_class_name != null, "Super Class Name should not be invalid");
    }

    String[] interfaces = check_interface_impl_and_get(class_context);

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    class_context.setClassWriter(cw);

    LOG.info("Creating Public Class...({}) super({})", class_name, super_class_name);

    //// Writing Byte Code
    cw.visit(Compiler.java_version, Opcodes.ACC_PUBLIC, class_name, null, super_class_name, interfaces);

    if (class_context.isGenDfltConstructor()) {
      // if it does not have any constructor, add a dummy constructor
      // default constructor
      MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();

      // super class default constructor call
      if (super_class != null) {
        LOG.info("ALOAD 0");
        LOG.info("INVOKESPECIAL " + super_class_name + " <init> ()V");

        mv.visitVarInsn(Opcodes.ALOAD, 0); // this
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, super_class_name, "<init>", "()V", false);
      }

      if (Debug.enable_compile_debug_print) {
        // LOG.info("GETSTATIC java/lang/System.out");
        // LOG.info("LDC "+class_name+" was instantiated");
        // LOG.info("INVOKEVIRTUAL java/io/PrintStream.println");
        mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn(class_name + " was instantiated");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
      }
      mv.visitInsn(Opcodes.RETURN);
      mv.visitMaxs(0, 0);
      mv.visitEnd();
      //// end Byte Code
    }

  }
    break;

  default:
    // do nothing for other stream form ...
  }

  return null;
}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:71,代码来源:ASTCompileVisitor.java

示例12: buildClosureClass

private void buildClosureClass(TContext closure_ctx) throws CompileException {
  Debug.assertion(closure_ctx instanceof TContextClosure, "closure_ctx should be closure ctx");

  ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
  ((TContextClosure) closure_ctx).setClassWriter(cw);

  cw.visit(Compiler.java_version, Opcodes.ACC_PUBLIC, closure_ctx.getName(), null, "java/lang/Object", null);

  // default constructor
  MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
  mv.visitCode();

  LOG.info("ALOAD 0 for this");
  LOG.info("INVOKESPECIAL java/lang/Object");

  mv.visitVarInsn(Opcodes.ALOAD, 0); // this
  mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
  if (Debug.enable_compile_debug_print) {
    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitLdcInsn(closure_ctx.getName() + " was instantiated");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
  }
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(0, 0);
  mv.visitEnd();
  // end default constructor

  TContext parent_ctx = (TContext) closure_ctx.getOwnerType();
  Debug.assertion(parent_ctx != null, "parent_ctx should be valid");

  // add closure class member field
  Container var_cont = null;
  AbsType var_type = null;

  LinkedList<Container> var_list = closure_ctx.get_childvar_list();
  int var_size = var_list.size();
  Container closure_member_var = null;

  for (int i = 0; i < var_size; i++) {
    closure_member_var = var_list.get(i);
    var_cont = closure_member_var.getClosureOrgFuncvarContainer();

    Debug.assertion(var_cont != null, "var_cont should be valid");
    // Debug.assertion(var_cont.isForm(Container.FORM_FUNSTACK_VAR), "var_cont
    // should be stack variable");
    Debug.assertion(var_cont.isTypeInitialized(), "var_cont type should be initialized");

    if (var_cont.isForm(Container.FORM_FUNSTACK_VAR)) {
      // only assigned stack variable will be copied
      if (var_cont.isAssigned()) {
        LOG.debug("  (" + var_cont.getContextVarIdx() + ") " + var_cont);
        var_type = var_cont.getType();
        cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
      }
    } else if (var_cont.isForm(Container.FORM_OBJMEMBER_VAR)) {
      LOG.debug("  (" + var_cont.getContextVarIdx() + ") " + var_cont);
      var_type = var_cont.getType();
      cw.visitField(Opcodes.ACC_PUBLIC, var_cont.getName(), var_type.getMthdDscStr(), null, null).visitEnd();
    } else {
      throw new CompileException("Invalid var_cont form(" + var_cont + ")");
    }

  }

}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:65,代码来源:ASTCompileVisitor.java

示例13: getMergedClass

public static MergedClassResult getMergedClass(final ClassSet set, final byte[] precompiledClass,
      ClassNode generatedClass, final boolean scalarReplace) {
    if (verifyBytecode) {
      if (!AsmUtil.isClassBytesOk(logger, "precompiledClass", precompiledClass)) {
        throw new IllegalStateException("Problem found in precompiledClass");
      }
      if ((generatedClass != null) && !AsmUtil.isClassOk(logger, "generatedClass", generatedClass)) {
        throw new IllegalStateException("Problem found in generatedClass");
      }
    }

    /*
     * Setup adapters for merging, remapping class names and class writing. This is done in
     * reverse order of how they will be evaluated.
     */
    final RemapClasses re = new RemapClasses(set);
    try {
      if (scalarReplace && generatedClass != null) {
        if (logger.isDebugEnabled()) {
          AsmUtil.logClass(logger, "generated " + set.generated.dot, generatedClass);
        }

        final ClassNode generatedMerged = new ClassNode();
        ClassVisitor mergeGenerator = generatedMerged;
        if (verifyBytecode) {
          mergeGenerator = new DrillCheckClassAdapter(CompilationConfig.ASM_API_VERSION,
              new CheckClassVisitorFsm(CompilationConfig.ASM_API_VERSION, generatedMerged), true);
        }

        /*
         * Even though we're effectively transforming-creating a new class in mergeGenerator,
         * there's no way to pass in ClassWriter.COMPUTE_MAXS, which would save us from having
         * to figure out stack size increases on our own. That gets handled by the
         * InstructionModifier (from inside ValueHolderReplacement > ScalarReplacementNode).
         */
        generatedClass.accept(new ValueHolderReplacementVisitor(mergeGenerator, verifyBytecode));
        if (verifyBytecode) {
          if (!AsmUtil.isClassOk(logger, "generatedMerged", generatedMerged)) {
            throw new IllegalStateException("Problem found with generatedMerged");
          }
        }
        generatedClass = generatedMerged;
      }

      final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
      ClassVisitor writerVisitor = writer;
      if (verifyBytecode) {
        writerVisitor = new DrillCheckClassAdapter(CompilationConfig.ASM_API_VERSION,
            new CheckClassVisitorFsm(CompilationConfig.ASM_API_VERSION, writerVisitor), true);
      }
      ClassVisitor remappingAdapter = new RemappingClassAdapter(writerVisitor, re);
      if (verifyBytecode) {
        remappingAdapter = new DrillCheckClassAdapter(CompilationConfig.ASM_API_VERSION,
            new CheckClassVisitorFsm(CompilationConfig.ASM_API_VERSION, remappingAdapter), true);
      }

      ClassVisitor visitor = remappingAdapter;
      if (generatedClass != null) {
        visitor = new MergeAdapter(set, remappingAdapter, generatedClass);
      }
      ClassReader tReader = new ClassReader(precompiledClass);
      tReader.accept(visitor, ClassReader.SKIP_FRAMES);
      byte[] outputClass = writer.toByteArray();
      if (logger.isDebugEnabled()) {
        AsmUtil.logClassFromBytes(logger, "merged " + set.generated.dot, outputClass);
      }

      // enable when you want all the generated merged class files to also be written to disk.
//      Files.write(outputClass, new File(String.format("/src/scratch/drill-generated-classes/%s-output.class", set.generated.dot)));

      return new MergedClassResult(outputClass, re.getInnerClasses());
    } catch (Error | RuntimeException e) {
      logger.error("Failure while merging classes.", e);
      AsmUtil.logClass(logger, "generatedClass", generatedClass);
      throw e;
    }
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:77,代码来源:MergeAdapter.java

示例14: traceBytecode

private void traceBytecode(byte[] bytecode) {
    ClassReader cr = new ClassReader(bytecode);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cr.accept(new TraceClassVisitor(cw, new PrintWriter(System.out)), 0);
}
 
开发者ID:willfleury,项目名称:prometheus-metrics-agent,代码行数:5,代码来源:BaseMetricTest.java

示例15: verifyBytecode

private void verifyBytecode(byte[] bytecode) {
    ClassReader cr = new ClassReader(bytecode);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cr.accept(new CheckClassAdapter(cw), 0);
}
 
开发者ID:willfleury,项目名称:prometheus-metrics-agent,代码行数:5,代码来源:BaseMetricTest.java


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