Package com.google.gwt.dev.asm.commons

Examples of com.google.gwt.dev.asm.commons.Method


      /*
       * The local descriptor is the same as the descriptor from the abstract
       * method in the interface.
       */
      String localDescriptor = interfaceMethod.getDescriptor();
      Method localMethod = new Method(mangledName, localDescriptor);

      /*
       * We also use the first argument to know which type to statically
       * dispatch to.
       */
      Type implementingType = Type.getType("L"
          + implementingMethod.getArgumentTypes()[0].getInternalName() + "$;");

      // Maybe create the method. This is marked final as a sanity check
      MethodVisitor mv = visitMethodNoRewrite(Opcodes.ACC_PUBLIC
          | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, localMethod.getName(),
          localMethod.getDescriptor(), null, null);

      if (mv != null) {
        mv.visitCode();

        /*
         * It just so happens that the stack and local variable sizes are the
         * same, but they're kept distinct to aid in clarity should the dispatch
         * logic change.
         */
        int var = 0;
        int size = 0;

        for (Type t : implementingMethod.getArgumentTypes()) {
          size += t.getSize();
          mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
          var += t.getSize();
        }

        // Make sure there's enough room for the return value
        size = Math.max(size, implementingMethod.getReturnType().getSize());

        mv.visitMethodInsn(Opcodes.INVOKESTATIC,
            implementingType.getInternalName(), implementingMethod.getName(),
            implementingMethod.getDescriptor());
        mv.visitInsn(localMethod.getReturnType().getOpcode(Opcodes.IRETURN));
        mv.visitMaxs(size, var);
        mv.visitEnd();
      }
    }
View Full Code Here


     * more awkward than the duplication of code.
     */
    for (String mangledName : toImplement(stubIntr)) {
      for (Method method : jsoData.getDeclarations(mangledName)) {

        Method toCall = new Method(method.getName(), method.getDescriptor());

        // Must not be final
        MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC
            | Opcodes.ACC_SYNTHETIC, mangledName, method.getDescriptor(), null, null);
        if (mv != null) {
          mv.visitCode();

          /*
           * It just so happens that the stack and local variable sizes are the
           * same, but they're kept distinct to aid in clarity should the
           * dispatch logic change.
           *
           * These start at 1 because we need to load "this" onto the stack
           */
          int var = 1;
          int size = 1;

          // load this
          mv.visitVarInsn(Opcodes.ALOAD, 0);

          // then the rest of the arguments
          for (Type t : toCall.getArgumentTypes()) {
            size += t.getSize();
            mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
            var += t.getSize();
          }

          // Make sure there's enough room for the return value
          size = Math.max(size, toCall.getReturnType().getSize());

          mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName,
              toCall.getName(), toCall.getDescriptor());
          mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN));
          mv.visitMaxs(size, var);
          mv.visitEnd();
        }
      }
    }
View Full Code Here

    }

    private JavaScriptHostInfo(Type returnType, String methodName,
        boolean requiresCast) {
      this.requiresCast = requiresCast;
      this.method = new Method(methodName, returnType,
          INVOKE_NATIVE_PARAM_TYPES);
      assert matchesRealMethod(methodName, returnType) : "JavaScriptHostInfo for '"
          + this + "' does not match real method";
    }
View Full Code Here

     * for example, {@code new Boolean} instead of using
     * {@link Boolean#valueOf(boolean)}.
     */
    @Override
    public void box(Type type) {
      Method method = Boxing.getBoxMethod(type);
      if (method != null) {
        invokeStatic(method.getReturnType(), method);
      }
    }
View Full Code Here

      OperationData toReturn = d;
      d = null;

      if (toReturn.clientMethodDescriptor != null) {
        // Strip return types
        Method noReturn =
            new Method(toReturn.methodName, Type.VOID_TYPE, Type
                .getArgumentTypes(toReturn.clientMethodDescriptor));
        toReturn.clientMethodDescriptor = noReturn.getDescriptor();
      }
      if (toReturn.domainMethodDescriptor != null) {
        Method noReturn =
            new Method(toReturn.methodName, Type.VOID_TYPE, Type
                .getArgumentTypes(toReturn.domainMethodDescriptor));
        toReturn.domainMethodDescriptor = noReturn.getDescriptor();
      }

      return toReturn;
    }
View Full Code Here

      throw new RuntimeException("No UTF-8", e);
    }
  }

  private static String key(String requestContextBinaryName, String methodName, String descriptor) {
    Method m = new Method(methodName, Type.VOID_TYPE, Type.getArgumentTypes(descriptor));
    String raw = requestContextBinaryName + "::" + methodName + m.getDescriptor();
    return raw.length() >= HASH_LENGTH ? hash(raw) : raw;
  }
View Full Code Here

       */
      assert implementingMethod.getArgumentTypes().length > 0;
      String localDescriptor = "("
          + implementingMethod.getDescriptor().substring(
              1 + implementingMethod.getArgumentTypes()[0].getDescriptor().length());
      Method localMethod = new Method(mangledName, localDescriptor);

      /*
       * We also use the first argument to know which type to statically
       * dispatch to.
       */
      Type implementingType = Type.getType("L"
          + implementingMethod.getArgumentTypes()[0].getInternalName() + "$;");

      // Maybe create the method. This is marked final as a sanity check
      MethodVisitor mv = visitMethodNoRewrite(Opcodes.ACC_PUBLIC
          | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, localMethod.getName(),
          localMethod.getDescriptor(), null, null);

      if (mv != null) {
        mv.visitCode();

        /*
         * It just so happens that the stack and local variable sizes are the
         * same, but they're kept distinct to aid in clarity should the dispatch
         * logic change.
         */
        int var = 0;
        int size = 0;

        for (Type t : implementingMethod.getArgumentTypes()) {
          size += t.getSize();
          mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
          var += t.getSize();
        }

        // Make sure there's enough room for the return value
        size = Math.max(size, implementingMethod.getReturnType().getSize());

        mv.visitMethodInsn(Opcodes.INVOKESTATIC,
            implementingType.getInternalName(), implementingMethod.getName(),
            implementingMethod.getDescriptor());
        mv.visitInsn(localMethod.getReturnType().getOpcode(Opcodes.IRETURN));
        mv.visitMaxs(size, var);
        mv.visitEnd();
      }
    }
View Full Code Here

     * semantics of the dispatches that would make a common implementation far
     * more awkward than the duplication of code.
     */
    for (Map.Entry<String, Method> entry : toImplement(stubIntr).entrySet()) {
      String mangledName = entry.getKey();
      Method method = entry.getValue();

      String descriptor = "("
          + method.getDescriptor().substring(
              1 + method.getArgumentTypes()[0].getDescriptor().length());
      String localName = method.getName().substring(0,
          method.getName().length() - 1);
      Method toCall = new Method(localName, descriptor);

      // Must not be final
      MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC
          | Opcodes.ACC_SYNTHETIC, mangledName, descriptor, null, null);
      if (mv != null) {
        mv.visitCode();

        /*
         * It just so happens that the stack and local variable sizes are the
         * same, but they're kept distinct to aid in clarity should the dispatch
         * logic change.
         *
         * These start at 1 because we need to load "this" onto the stack
         */
        int var = 1;
        int size = 1;

        // load this
        mv.visitVarInsn(Opcodes.ALOAD, 0);

        // then the rest of the arguments
        for (Type t : toCall.getArgumentTypes()) {
          size += t.getSize();
          mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
          var += t.getSize();
        }

        // Make sure there's enough room for the return value
        size = Math.max(size, toCall.getReturnType().getSize());

        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName,
            toCall.getName(), toCall.getDescriptor());
        mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN));
        mv.visitMaxs(size, var);
        mv.visitEnd();
      }
    }
  }
View Full Code Here

               * there are two super-interfaces that define methods with
               * identical names and descriptors, the choice of implementation
               * is undefined.
               */
              String maybeMangled = intf.replace('/', '_') + "_" + name;
              Method method = mangledNamesToImplementations.get(maybeMangled);
              if (method != null) {
                /*
                 * Found a method with the right name, but we need to check the
                 * parameters and the return type. In order to do this, we'll
                 * look at the arguments and return type of the target method,
                 * removing the first argument, which is the instance.
                 */
                assert method.getArgumentTypes().length >= 1;
                Type[] argumentTypes = new Type[method.getArgumentTypes().length - 1];
                System.arraycopy(method.getArgumentTypes(), 1, argumentTypes,
                    0, argumentTypes.length);
                String maybeDescriptor = Type.getMethodDescriptor(
                    method.getReturnType(), argumentTypes);
                if (maybeDescriptor.equals(desc)) {
                  name = maybeMangled;
                  break;
                }
              }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.asm.commons.Method

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.