Package com.caucho.bytecode

Examples of com.caucho.bytecode.JavaClass


      switch (visitor.getOpcode()) {
      case CodeVisitor.INVOKESPECIAL:
        int index = visitor.getShortArg();

        JavaClass jClass = visitor.getJavaClass();
        ConstantPool cp = jClass.getConstantPool();
        MethodRefConstant ref;
        ref = cp.getMethodRef(index);

        if (ref.getName().endsWith("__super")) {
          return;
        }
        else if (ref.getName().equals("<init>")
                 && (! ref.getClassName().equals(jClass.getSuperClassName())
                     || ! _method.getName().equals("<init>"))) {
          return;
        }
        else if (! ref.getName().equals("<init>")) {
          // private methods are called with invokespecial, but shouldn't
View Full Code Here


      }

      log.fine("merging .smap for " + classPath.getTail());

      ByteCodeParser parser = new ByteCodeParser();
      JavaClass javaClass;

      ReadStream is = classPath.openRead();
      try {
        javaClass = parser.parse(is);
      } finally {
        is.close();
      }

      CharBuffer smap = new CharBuffer();

      is = smapPath.openRead();
      try {
        int ch;

        while ((ch = is.read()) >= 0) {
          smap.append((char) ch);
        }
      } finally {
        is.close();
      }

      SourceDebugExtensionAttribute attr;

      attr = new SourceDebugExtensionAttribute(smap.toString());

      javaClass.addAttribute(attr);

      WriteStream os = classPath.openWrite();
      try {
        javaClass.write(os);
      } finally {
        os.close();
      }
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
View Full Code Here

      }
     
      if (_proxyClass == null) {
        JavaClassLoader jLoader = new JavaClassLoader(cl.getClassLoader());

        JavaClass jClass = new JavaClass(jLoader);
        jClass.setAccessFlags(Modifier.PUBLIC);

        jClass.setWrite(true);

        jClass.setMajor(49);
        jClass.setMinor(0);

        String superClassName;

        if (! cl.isInterface())
          superClassName = typeClassName;
        else
          superClassName = "java/lang/Object";

        jClass.setSuperClass(superClassName);
        jClass.setThisClass(thisClassName);

        for (Class<?> iface : types) {
          if (iface.isInterface())
            jClass.addInterface(iface.getName().replace('.', '/'));
        }
       
        jClass.addInterface(ScopeProxy.class.getName().replace('.', '/'));

        JavaField factoryField =
          jClass.createField("_factory",
                             "Lcom/caucho/config/inject/InjectManager$ReferenceFactory;");
        factoryField.setAccessFlags(Modifier.PRIVATE);

        JavaMethod ctor =
          jClass.createMethod("<init>",
                              "(Lcom/caucho/config/inject/InjectManager$ReferenceFactory;)V");
        ctor.setAccessFlags(Modifier.PUBLIC);

        CodeWriterAttribute code = ctor.createCodeWriter();
        code.setMaxLocals(3);
        code.setMaxStack(4);

        code.pushObjectVar(0);
        code.pushObjectVar(1);
        code.putField(thisClassName, factoryField.getName(),
                      factoryField.getDescriptor());
       
        code.pushObjectVar(0);
        code.invokespecial(superClassName, "<init>", "()V", 1, 0);
        code.addReturn();
        code.close();

        createGetDelegateMethod(jClass);
        createSerialize(jClass);

        for (Method method : getMethods(_types)) {
          if (Modifier.isStatic(method.getModifiers()))
            continue;
          if (Modifier.isFinal(method.getModifiers()))
            continue;

          if (isRemoveMethod(_beanClass, method))
            createRemoveProxyMethod(jClass, method, method.getDeclaringClass().isInterface());
          else
            createProxyMethod(jClass, method, method.getDeclaringClass().isInterface());
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        WriteStream out = Vfs.openWrite(bos);

        jClass.write(out);

        out.close();

        byte[] buffer = bos.toByteArray();
View Full Code Here

  private Class generateProxy()
  {
    try {
      JavaClassLoader jLoader = new JavaClassLoader(_cl.getClassLoader());
     
      JavaClass jClass = new JavaClass(jLoader);
      jClass.setAccessFlags(Modifier.PUBLIC);
      ConstantPool cp = jClass.getConstantPool();

      jClass.setWrite(true);
     
      jClass.setMajor(49);
      jClass.setMinor(0);

      String superClassName = _cl.getName().replace('.', '/');
      String thisClassName = superClassName + "$BeanProxy";

      jClass.setSuperClass(superClassName);
      jClass.setThisClass(thisClassName);

      jClass.addInterface("java/io/Serializable");
      jClass.addInterface("com/caucho/config/inject/HandleAware");

      generateConstructors(jClass, superClassName);
     
      generateWriteReplace(jClass);
      generateSetHandle(jClass);

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      WriteStream out = Vfs.openWrite(bos);

      jClass.write(out);
   
      out.close();

      byte []buffer = bos.toByteArray();
View Full Code Here

      if (_proxyClass != null)
        return;
     
      JavaClassLoader jLoader = new JavaClassLoader(cl.getClassLoader());

      JavaClass jClass = new JavaClass(jLoader);
      jClass.setAccessFlags(Modifier.PUBLIC);

      jClass.setWrite(true);

      jClass.setMajor(49);
      jClass.setMinor(0);

      String superClassName;

      if (! cl.isInterface())
        superClassName = typeClassName;
      else
        superClassName = "java/lang/Object";

      jClass.setSuperClass(superClassName);
      jClass.setThisClass(thisClassName);

      JavaMethod ctor =
        jClass.createMethod("<init>", "()V");
      ctor.setAccessFlags(Modifier.PUBLIC);

      CodeWriterAttribute code = ctor.createCodeWriter();
      code.setMaxLocals(3);
      code.setMaxStack(4);

      code.pushObjectVar(0);
      code.invokespecial(superClassName, "<init>", "()V", 1, 0);
      code.addReturn();
      code.close();

      for (Method method : _cl.getMethods()) {
        if (Modifier.isStatic(method.getModifiers()))
          continue;
        if (Modifier.isFinal(method.getModifiers()))
          continue;
        if (! Modifier.isAbstract(method.getModifiers()))
          continue;

        createStubMethod(jClass, method);
      }

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      WriteStream out = Vfs.openWrite(bos);

      jClass.write(out);

      out.close();

      byte[] buffer = bos.toByteArray();
View Full Code Here

  protected void renameSubClass(String className,
                                Path targetPath,
                                Path extPath)
    throws Exception
  {
    JavaClass extClass = null;

    ByteCodeParser parser = new ByteCodeParser();

    parser = new ByteCodeParser();
    parser.setClassLoader(new JavaClassLoader());

    ReadStream is = extPath.openRead();
    try {
      extClass = parser.parse(is);
    } finally {
      if (is != null)
        is.close();
    }

    cleanExtConstantPool(className, extClass);

    WriteStream os = targetPath.openWrite();
    try {
      extClass.write(os);
    } finally {
      os.close();
    }
  }
View Full Code Here

                              Path targetPath,
                              Path sourcePath,
                              Path extPath)
    throws Exception
  {
    JavaClass baseClass = null;
    JavaClass extClass = null;

    ByteCodeParser parser = new ByteCodeParser();
    parser.setClassLoader(getJavaClassLoader());

    ReadStream is = sourcePath.openRead();
View Full Code Here

  protected void mergeClasses(String className,
                              Path targetPath,
                              Path extPath)
    throws Exception
  {
    JavaClass baseClass = null;
    JavaClass extClass = null;

    ByteCodeParser parser = new ByteCodeParser();
    parser.setClassLoader(getJavaClassLoader());

    ReadStream is = extPath.openRead();
    try {
      extClass = parser.parse(is);
    } finally {
      if (is != null)
        is.close();
    }

    cleanExtConstantPool(className, extClass);

    postEnhance(baseClass);

    WriteStream os = targetPath.openWrite();
    try {
      extClass.write(os);
    } finally {
      os.close();
    }
  }
View Full Code Here

      if (_offset >= 0)
        return;

      switch (visitor.getOpcode()) {
      case CodeVisitor.INVOKESPECIAL:
        JavaClass javaClass = visitor.getJavaClass();
        ConstantPool cp = javaClass.getConstantPool();
        MethodRefConstant ref = cp.getMethodRef(visitor.getShortArg());

        // ejb/0l00
        // handler "super()" and "this()"
        if (ref.getName().equals("<init>")
            && (ref.getClassName().equals(javaClass.getThisClass())
                || ref.getClassName().equals(javaClass.getSuperClassName()))) {
          _offset = visitor.getOffset() + 3;
        }
        break;
      }
    }
View Full Code Here

        parser.setClassLoader(_jClassLoader);

        ByteArrayInputStream is;
        is = new ByteArrayInputStream(buffer, 0, buffer.length);
     
        JavaClass jClass = parser.parse(is);

        return enhance(jClass);
      } catch (RuntimeException e) {
        throw e;
      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.caucho.bytecode.JavaClass

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.