Package org.objectweb.asm

Examples of org.objectweb.asm.Type


    }
  }

  public Value merge (final Value v, final Value w) {
    if (!v.equals(w)) {
      Type t = ((BasicValue)v).getType();
      Type u = ((BasicValue)w).getType();
      if (t != null && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY)) {
        if (u != null && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY)) {
          if (t.getDescriptor().equals("Lnull;")) {
            return w;
          }
          if (u.getDescriptor().equals("Lnull;")) {
            return v;
          }
          Class c = getClass(t);
          Class d = getClass(u);
          if (c.isAssignableFrom(d)) {
View Full Code Here


      }
    } else {
      int i = 0;
      int j = 0;
      if (opcode != INVOKESTATIC) {
        Type owner = Type.getType("L" + ((MethodInsnNode)insn).owner + ";");
        if (!isSubTypeOf((Value)values.get(i++), newValue(owner))) {
          throw new AnalyzerException(
            "Method owner", newValue(owner), (Value)values.get(0));
        }
      }
View Full Code Here

    final Object value,
    final Attribute attrs)
  {
    super.visitField(access, name, desc, value, attrs);
    if ((access & ACC_STATIC) == 0) {
      Type t = Type.getType(desc);
      int size = t.getSize();

      // generates getter method
      String gDesc = "()" + desc;
      CodeVisitor gv =
        cv.visitMethod(ACC_PRIVATE, "_get" + name, gDesc, null, null);
      gv.visitFieldInsn(GETSTATIC,
        "java/lang/System", "err", "Ljava/io/PrintStream;");
      gv.visitLdcInsn("_get" + name + " called");
      gv.visitMethodInsn(INVOKEVIRTUAL,
        "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
      gv.visitVarInsn(ALOAD, 0);
      gv.visitFieldInsn(GETFIELD, owner, name, desc);
      gv.visitInsn(t.getOpcode(IRETURN));
      gv.visitMaxs(1 + size, 1);

      // generates setter method
      String sDesc = "(" + desc + ")V";
      CodeVisitor sv =
        cv.visitMethod(ACC_PRIVATE, "_set" + name, sDesc, null, null);
      sv.visitFieldInsn(GETSTATIC,
        "java/lang/System", "err", "Ljava/io/PrintStream;");
      sv.visitLdcInsn("_set" + name + " called");
      sv.visitMethodInsn(INVOKEVIRTUAL,
        "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
      sv.visitVarInsn(ALOAD, 0);
      sv.visitIntInsn(t.getOpcode(ILOAD), 1);
      sv.visitFieldInsn(PUTFIELD, owner, name, desc);
      sv.visitInsn(RETURN);
      sv.visitMaxs(1 + size, 1 + size);
    }
  }
View Full Code Here

    {
        // allocate a slot for the invoke parameters array,
        // construct the array
        // stash it into the slot and return the slot idx

        Type objectType = Type.getType(Object.class);
        Type objectArrayType = Type.getType("[Ljava/lang/Object;");
        Type[] invokeParamTypes = getInvokedTypes();
        int savedValueCount = invokeParamTypes.length;

        // create the array and save it in a local var slot

        int arrayValueSlot = newLocal(objectArrayType);
        push(savedValueCount);
        newArray(objectType);
        storeLocal(arrayValueSlot);

        // pop the arguments off the stack into the invoke parameters array
        // n.b. the top one is the last parameter

        for (int i = savedValueCount - 1; i >= 0; i--) {
            Type type = invokeParamTypes[i];
            if (type != null) {
                // convert value to object if needed
                box(type);
                // load array and  swap under value
                loadLocal(arrayValueSlot);
                swap(objectArrayType, objectType);
                // load index and swap under value
                push(i);
                swap(Type.INT_TYPE, objectType);
            } else {
                // this is a static method and index is 0 so we install null in the array
                // load array index and then null
                loadLocal(arrayValueSlot);
                push(i);
                push((Type)null);
            }
            // store the value in the array as an object
            arrayStore(objectType);
        }

        // now restore the arguments from the array in increasing order

        for (int i = 0; i < savedValueCount; i++) {
            Type type = invokeParamTypes[i];
            if (type != null) {
                // load the array, retrieve the object and unbox if needed
                loadLocal(arrayValueSlot);
                push(i);
                arrayLoad(objectType);
View Full Code Here

        // create the array used to pass the bindings

        int arraySize = callArrayBindings.size();

        push(arraySize);
        Type objectType = Type.getType(Object.class);
        newArray(objectType);

        // check if any of the bindings gets updated. if so we need to stash a copy of the bindings array
        // below the key and owner so we can pull out the updated values and update local var/param slots
        // once the call ahs completed
View Full Code Here

    private void doArgUpdate()
    {
        // at entry the top of the stack contains the object array
        // for an AT EXIT rule the entry below this is the return value

        Type objectType = Type.getType(Object.class);
        int arraySize = callArrayBindings.size();
        int lastUpdated = -1;
        int returnIdx = -1;

View Full Code Here

    }

    @Override
    public void visitMaxs(int maxStack, int maxLocals)
    {
        Type returnType =  Type.getReturnType(descriptor);

        // check whether there are outstanding monitor opens at the start of the trigger
        // block and, if so, insert a handler which unlocks the monitor and then rethrows
        // the exception.
View Full Code Here

    {
        // we need to set this here to avoid recursive re-entry into inject routine

        rule.setTypeInfo(getTriggerClass(), access, name, descriptor, exceptions);
        String key = rule.getKey();
        Type ruleType = Type.getType(TypeHelper.externalizeType("org.jboss.byteman.rule.Rule"));
        Method method = Method.getMethod("void execute(String, Object, Object[])");
        // we are at the relevant line in the method -- so add a trigger call here
        if (Transformer.isVerbose()) {
            System.out.println("RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into " + getTriggerClass() + "." + getMethodName() + " for rule " + rule.getName());
        }
View Full Code Here

    LOGGER.debug("Processing method: {} with descriptor {}", name, desc);

    // identify the target method parameters and return type
    Method currentTransformMethod = new Method(name, desc);
    Type[] targetMethodParameters = currentTransformMethod.getArgumentTypes();
    Type returnType = currentTransformMethod.getReturnType();

    // we create a static field for each method we encounter with a name
    // like method_parm1_parm2...
    StringBuilder methodStaticFieldNameBuilder = new StringBuilder(name);
    // for each a parameter get the name and add it to the field removing
    // the dots first
    for (Type t : targetMethodParameters) {
      methodStaticFieldNameBuilder.append("_");
      methodStaticFieldNameBuilder.append(t.getClassName().replaceAll("\\[\\]", "Array")
          .replaceAll("\\.", ""));
    }
    String methodStaticFieldName = methodStaticFieldNameBuilder.toString();

    // add a private static field for the method
    cv.visitField(ACC_PRIVATE | ACC_STATIC, methodStaticFieldName, METHOD_TYPE.getDescriptor(),
        null, null);

    // visit the method using the class writer, delegated through the method
    // visitor and generator
    // modify the method access so that any native methods aren't
    // described as native
    // since they won't be native in proxy form
    // also stop methods being marked synchronized on the proxy as they will
    // be sync
    // on the real object
    int newAccess = access & (~ACC_NATIVE) & (~ACC_SYNCHRONIZED);
    MethodVisitor mv = cv.visitMethod(newAccess, name, desc, signature, exceptions);
    // use a GeneratorAdapter to build the invoke call directly in byte code
    GeneratorAdapter methodAdapter = new GeneratorAdapter(mv, newAccess, name, desc);

    /*
     * Stage 1 creates the bytecode for adding the reflected method of the
     * superclass to a static field in the subclass: private static Method
     * methodName_parm1_parm2... = null; static{ methodName_parm1_parm2... =
     * superClass.getDeclaredMethod(methodName,new Class[]{method args}; }
     *
     * Stage 2 is to call the ih.invoke(this,methodName_parm1_parm2,args) in
     * the new subclass methods Stage 3 is to cast the return value to the
     * correct type
     */

    /*
     * Stage 1 use superClass.getMethod(methodName,new Class[]{method args}
     * from the Class object on the stack
     */

    // load the static superclass Class onto the stack
    staticAdapter.getStatic(newClassType, currentClassFieldName, CLASS_TYPE);

    // push the method name string arg onto the stack
    staticAdapter.push(name);

    // create an array of the method parm class[] arg
    staticAdapter.push(targetMethodParameters.length);
    staticAdapter.newArray(CLASS_TYPE);
    int index = 0;
    for (Type t : targetMethodParameters) {
      staticAdapter.dup();
      staticAdapter.push(index);
      switch (t.getSort())
      {
        case Type.BOOLEAN:
          staticAdapter.getStatic(Type.getType(java.lang.Boolean.class), "TYPE", CLASS_TYPE);
          break;
        case Type.BYTE:
          staticAdapter.getStatic(Type.getType(java.lang.Byte.class), "TYPE", CLASS_TYPE);
          break;
        case Type.CHAR:
          staticAdapter.getStatic(Type.getType(java.lang.Character.class), "TYPE", CLASS_TYPE);
          break;
        case Type.DOUBLE:
          staticAdapter.getStatic(Type.getType(java.lang.Double.class), "TYPE", CLASS_TYPE);
          break;
        case Type.FLOAT:
          staticAdapter.getStatic(Type.getType(java.lang.Float.class), "TYPE", CLASS_TYPE);
          break;
        case Type.INT:
          staticAdapter.getStatic(Type.getType(java.lang.Integer.class), "TYPE", CLASS_TYPE);
          break;
        case Type.LONG:
          staticAdapter.getStatic(Type.getType(java.lang.Long.class), "TYPE", CLASS_TYPE);
          break;
        case Type.SHORT:
          staticAdapter.getStatic(Type.getType(java.lang.Short.class), "TYPE", CLASS_TYPE);
          break;
        default:
        case Type.OBJECT:
          staticAdapter.push(t);
          break;
      }
      staticAdapter.arrayStore(CLASS_TYPE);
      index++;
    }

    // invoke the getMethod
    staticAdapter.invokeVirtual(CLASS_TYPE, new Method("getDeclaredMethod", METHOD_TYPE,
        new Type[] { STRING_TYPE, Type.getType(java.lang.Class[].class) }));

    // store the reflected method in the static field
    staticAdapter.putStatic(newClassType, methodStaticFieldName, METHOD_TYPE);

    /*
     * Stage 2 call the ih.invoke(this,supermethod,parms)
     */

    // load this to get the ih field
    methodAdapter.loadThis();
    // load the invocation handler from the field (the location of the
    // InvocationHandler.invoke)
    methodAdapter.getField(newClassType, IH_FIELD, IH_TYPE);
    // loadThis (the first arg of the InvocationHandler.invoke)
    methodAdapter.loadThis();
    // load the method to invoke (the second arg of the
    // InvocationHandler.invoke)
    methodAdapter.getStatic(newClassType, methodStaticFieldName, METHOD_TYPE);
    // load all the method arguments onto the stack as an object array (the
    // third arg of the InvocationHandler.invoke)
    methodAdapter.loadArgArray();
    // generate the invoke method
    Method invocationHandlerInvokeMethod = new Method("invoke", OBJECT_TYPE, new Type[] {
        OBJECT_TYPE, METHOD_TYPE, Type.getType(java.lang.Object[].class) });
    // call the invoke method of the invocation handler
    methodAdapter.invokeInterface(IH_TYPE, invocationHandlerInvokeMethod);

    /*
     * Stage 3 the returned object is now on the top of the stack We need to
     * check the type and cast as necessary
     */
    switch (returnType.getSort())
    {
      case Type.BOOLEAN:
        methodAdapter.cast(OBJECT_TYPE, Type.getType(Boolean.class));
        methodAdapter.unbox(Type.BOOLEAN_TYPE);
        break;
View Full Code Here

        if(!!!samePackage)
          throw new RuntimeException(NLS.MESSAGES.getMessage("method.from.superclass.is.hidden", name, superToCopy.getName(), overridingClassType.getClassName()),
                                     new UnableToProxyException(superToCopy));
      }
      //Safe to copy a call to this method!
      Type superType = Type.getType(superToCopy);
     
      // identify the target method parameters and return type
      String methodStaticFieldName = "methodField" + AbstractWovenProxyAdapter.getSanitizedUUIDString();
      transformedMethods.put(methodStaticFieldName, new TypeMethod(
          superType, currentTransformMethod))
View Full Code Here

TOP

Related Classes of org.objectweb.asm.Type

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.