Package org.objectweb.asm

Examples of org.objectweb.asm.ClassReader


    type.write(ctx);

    byte[] bytecode = ctx.getGeneratedBytecode();
   
    if (log.isLogging(LoggerLevelStandard.DEBUG)) {
      ClassReader cr = new ClassReader(bytecode);
      ASMifierClassVisitor asm = new ASMifierClassVisitor(
        new PrintWriter(log.getLoggingWriter(LoggerLevelStandard.DEBUG), true) // log.getLoggingWriter(LoggerLevelStandard.INFO), true)
      );
      cr.accept(asm, 0);
    }
   
    return loader.define(type.getName(), bytecode);
  }
View Full Code Here


    }
    return paramNames;
  }
 
  private ParameterNameDiscoveringVisitor visitMethod(Method method) throws IOException {
    ClassReader classReader = getClassReader(method.getDeclaringClass());
    FindMethodParameterNamesClassVisitor classVisitor = new FindMethodParameterNamesClassVisitor(method);
    classReader.accept(classVisitor, false);
    return classVisitor;
  }
View Full Code Here

    classReader.accept(classVisitor, false);
    return classVisitor;
  }
 
  private ParameterNameDiscoveringVisitor visitConstructor(Constructor ctor) throws IOException {
    ClassReader classReader = getClassReader(ctor.getDeclaringClass());
    FindConstructorParameterNamesClassVisitor classVisitor = new FindConstructorParameterNamesClassVisitor(ctor);
    classReader.accept(classVisitor, false);
    return classVisitor;
  }
View Full Code Here

    return classVisitor;
  }
 
  private ClassReader getClassReader(Class clazz) throws IOException {
    synchronized (classReaderCache) {
      ClassReader classReader = (ClassReader) classReaderCache.get(clazz);
      if (classReader == null) {
        InputStream is = clazz.getResourceAsStream(getClassFileName(clazz));
        if (is == null)
          throw new FileNotFoundException("Class file for class [" + clazz.getName() + "] not found");
        try {
          classReader = new ClassReader(is);
          classReaderCache.put(clazz, classReader);
        } finally {
          is.close();
        }
      }
View Full Code Here

        final TestClassVisitor classVisitor = createClassVisitor();

        InputStream classStream = null;
        try {
            classStream = new BufferedInputStream(new FileInputStream(testClassFile));
            final ClassReader classReader = new ClassReader(classStream);
            classReader.accept(classVisitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
        } catch (Throwable e) {
            throw new GradleException("failed to read class file " + testClassFile.getAbsolutePath(), e);
        } finally {
            IOUtils.closeQuietly(classStream);
        }
View Full Code Here

    }

    public static DecompiledClass getDecompiledClass(final InputStream is,
        final String field, final String method, final BitSet modes, final ClassLoader cl)
        throws IOException, UnsupportedClassVersionError {
        ClassReader cr = new ClassReader(is);
        int crFlags = 0;
        if(modes.get(BCOConstants.F_EXPAND_STACKMAP)) {
            crFlags |= ClassReader.EXPAND_FRAMES;
        }
        ClassVisitor cv;
        if (modes.get(BCOConstants.F_SHOW_ASMIFIER_CODE)) {
            cv = new CommentedASMifierClassVisitor(modes);
        } else {
            cv = new CommentedClassVisitor(modes);
        }
        DecompilerClassVisitor dcv = new DecompilerClassVisitor(
            cv, field, method, modes);
        cr.accept(dcv, crFlags);
        return dcv.getResult(cl);
    }
View Full Code Here

        ZipEntry e = (ZipEntry) entries.nextElement();
        String n = e.getName();
        if (n.endsWith(".class")) {
          n = n.substring(0, n.length() - 6).replace('/', '.');
          InputStream is = zip.getInputStream(e);
          ClassReader cr = new ClassReader(is);
          if (cr.readInt(4) != Opcodes.V1_6) {
            try {
              ClassWriter cw = new ClassWriter(
                  ClassWriter.COMPUTE_FRAMES);
              cr.accept(cw, 0);
              cr = new ClassReader(cw.toByteArray());
            } catch (Throwable ignored) {
              continue;
            }
          }
          ClassWriter cw = new ClassWriter(0);
          ClassVisitor cv = getClassAdapter(cw);
          try {
            cr.accept(cv, ClassReader.EXPAND_FRAMES);
          } catch (UnsatisfiedLinkError ignored) {
          } catch (NoClassDefFoundError ignored) {
          }
          byte[] b = cw.toByteArray();
          try {
View Full Code Here

      String s = e.getName();
      if (s.endsWith(".class")) {
        s = s.substring(0, s.length() - 6).replace('/', '.');
        if (clazz == null || s.indexOf(clazz) != -1) {
          InputStream is = zip.getInputStream(e);
          classes.add(new ClassReader(is).b);
        }
      }
    }

    long[] times = new long[15];
    for (int i = 0; i < times.length; ++i) {
      times[i] = Long.MAX_VALUE;
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        new ClassReader(b).accept(new EmptyVisitor(), 0);
      }
      t = System.currentTimeMillis() - t;
      times[0] = Math.min(t, times[0]);
      System.out.println("Time to deserialize " + classes.size()
          + " classes = " + t + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(0);
        new ClassReader(b).accept(cw, 0);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[1] = Math.min(t, times[1]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size() + " classes = " + t + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassReader cr = new ClassReader(b);
        ClassWriter cw = new ClassWriter(cr, 0);
        cr.accept(cw, 0);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[2] = Math.min(t, times[2]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size() + " classes with copyPool = " + t + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(0);
        ClassVisitor cv = new AddTimerAdapter(cw);
        new ClassReader(b).accept(cv, 0);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[3] = Math.min(t, times[3]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size() + " classes with AddTimerAdapter = " + t
          + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassReader cr = new ClassReader(b);
        ClassWriter cw = new ClassWriter(cr, 0);
        ClassVisitor cv = new AddTimerAdapter(cw);
        cr.accept(cv, 0);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[4] = Math.min(t, times[4]);
      System.out
          .println("Time to deserialize and reserialize "
              + classes.size()
              + " classes with AddTimerAdapter and copyPool = " + t
              + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(0);
        ClassVisitor cv = new ClassAdapter(cw) {
          public MethodVisitor visitMethod(int access, String name,
              String desc, String signature, String[] exceptions) {
            return new RemoveGetFieldPutFieldAdapter(cv.visitMethod(
                access, name, desc, signature, exceptions));
          }
        };
        new ClassReader(b).accept(cv, 0);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[5] = Math.min(t, times[5]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size()
          + " classes with RemoveGetFieldPutFieldAdapter = " + t
          + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassReader cr = new ClassReader(b);
        ClassWriter cw = new ClassWriter(cr, 0);
        ClassVisitor cv = new ClassAdapter(cw) {
          public MethodVisitor visitMethod(int access, String name,
              String desc, String signature, String[] exceptions) {
            return new RemoveGetFieldPutFieldAdapter(cv.visitMethod(
                access, name, desc, signature, exceptions));
          }
        };
        cr.accept(cv, 0);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[6] = Math.min(t, times[6]);
      System.out
          .println("Time to deserialize and reserialize "
              + classes.size()
              + " classes with RemoveGetFieldPutFieldAdapter and copyPool = "
              + t + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        new ClassReader(b).accept(cw, 0);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[7] = Math.min(t, times[7]);
      System.out
          .println("Time to deserialize and reserialize "
              + classes.size() + " classes with computeMaxs = " + t
              + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      int errors = 0;
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
        try {
          new ClassReader(b).accept(cw, 0);
        } catch (Throwable e) {
          ++errors;
        }
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[8] = Math.min(t, times[8]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size() + " classes with computeFrames = " + t
          + " ms (" + errors + " errors)");
    }

    System.out.println();

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        new ClassReader(b).accept(new ClassNode(), 0);
      }
      t = System.currentTimeMillis() - t;
      times[9] = Math.min(t, times[9]);
      System.out.println("Time to deserialize " + classes.size()
          + " classes with tree package = " + t + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(0);
        ClassNode cn = new ClassNode();
        new ClassReader(b).accept(cn, 0);
        cn.accept(cw);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[10] = Math.min(t, times[10]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size() + " classes with tree package = " + t
          + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(0);
        ClassNode cn = new ClassNode();
        new ClassReader(b).accept(cn, 0);
        new AddTimerTransformer(null).transform(cn);
        cn.accept(cw);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[11] = Math.min(t, times[11]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size() + " classes with AddTimerTransformer = " + t
          + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size(); ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassWriter cw = new ClassWriter(0);
        ClassNode cn = new ClassNode();
        new ClassReader(b).accept(cn, 0);
        Iterator it = cn.methods.iterator();
        while (it.hasNext()) {
          MethodNode mn = (MethodNode) it.next();
          new RemoveGetFieldPutFieldTransformer(null).transform(mn);
        }
        cn.accept(cw);
        cw.toByteArray();
      }
      t = System.currentTimeMillis() - t;
      times[12] = Math.min(t, times[12]);
      System.out.println("Time to deserialize and reserialize "
          + classes.size()
          + " classes with RemoveGetFieldPutFieldTransformer = " + t
          + " ms");
    }

    for (int i = 0; i < 10; ++i) {
      int errors = 0;
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size() / 10; ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassReader cr = new ClassReader(b);
        ClassNode cn = new ClassNode();
        cr.accept(cn, 0);
        List methods = cn.methods;
        for (int k = 0; k < methods.size(); ++k) {
          MethodNode method = (MethodNode) methods.get(k);
          if (method.instructions.size() > 0) {
            Analyzer a = new Analyzer(new BasicInterpreter());
            try {
              a.analyze(cn.name, method);
            } catch (Throwable th) {
              ++errors;
            }
          }
        }
      }
      t = System.currentTimeMillis() - t;
      times[13] = Math.min(t, times[13]);
      System.out.println("Time to analyze " + classes.size() / 10
          + " classes with BasicInterpreter = " + t + " ms (" + errors
          + " errors)");
    }

    for (int i = 0; i < 10; ++i) {
      int errors = 0;
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size() / 10; ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassReader cr = new ClassReader(b);
        ClassNode cn = new ClassNode();
        cr.accept(cn, 0);
        List methods = cn.methods;
        for (int k = 0; k < methods.size(); ++k) {
          MethodNode method = (MethodNode) methods.get(k);
          if (method.instructions.size() > 0) {
            Analyzer a = new Analyzer(new SimpleVerifier());
View Full Code Here

        return classBytes;
      }
    }

    try {
      ClassReader  cr    = new ClassReader(classBytes);
      ClassWriter  cw    = new BundleClassWriter(ClassWriter.COMPUTE_MAXS,
                                                 classLoader);
      ClassAdapter trans = new ClassAdapterPatcher(cw,
                                                   className.replace('.', '/'),
                                                   classLoader,
                                                   classLoader.archive.getBundleId(),
                                                   this);

      cr.accept(trans, 0);

      byte[] newBytes = cw.toByteArray();

      if(bDumpClasses) {
        dumpClassBytes(className, newBytes);
View Full Code Here

  }

  public synchronized void analyseClass(InputStream clsIn, String fileName)
  {
    try {
      ClassReader cr = new ClassReader(clsIn);
      currentClassFile = new File(fileName);
      cr.accept(this, 0);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

TOP

Related Classes of org.objectweb.asm.ClassReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.