Example usage for org.objectweb.asm Opcodes ILOAD

List of usage examples for org.objectweb.asm Opcodes ILOAD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ILOAD.

Prototype

int ILOAD

To view the source code for org.objectweb.asm Opcodes ILOAD.

Click Source Link

Usage

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateSwitchForAccessAdapter.java

License:Open Source License

@Override
protected void addPreSwitchInstructions(MethodNode method) {
    // put "accessId" on the stack
    method.instructions.add(new IntInsnNode(Opcodes.ILOAD, getFirstArgIndex()));
    // put "caller".getClass() on the stack
    method.instructions.add(new IntInsnNode(Opcodes.ALOAD, getFirstArgIndex() + 3));
    method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass",
            "()Ljava/lang/Class;", false));
    // call "getMemberId(accessId, callerClass)
    method.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ClassNames.TEAM_MANAGER_SLASH,
            ConstantMembers.getMemberId.getName(), ConstantMembers.getMemberId.getSignature(), false));
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateSwitchForAccessAdapter.java

License:Open Source License

@Override
protected void addInstructionForDefaultLabel(MethodNode method) {
    if (superClassName.equals("java/lang/Object")) {
        method.instructions.add(new TypeInsnNode(Opcodes.NEW, "org/objectteams/NoSuchMethodError"));
        method.instructions.add(new InsnNode(Opcodes.DUP));
        method.instructions.add(new IntInsnNode(Opcodes.ILOAD, getFirstArgIndex())); // accessId
        method.instructions.add(new LdcInsnNode(clazz.getName())); // current class
        method.instructions.add(new LdcInsnNode("decapsulating access")); // access reason
        method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "org/objectteams/NoSuchMethodError",
                "<init>", "(ILjava/lang/String;Ljava/lang/String;)V", false));
        method.instructions.add(new InsnNode(Opcodes.ATHROW));
    } else {//from  w  w w .  ja va 2s.c  om
        Type[] args = Type.getArgumentTypes(method.desc);
        addInstructionsForLoadArguments(method.instructions, args, getMethod().isStatic());

        int opcode = Opcodes.INVOKESPECIAL;
        if (getMethod().isStatic()) {
            opcode = Opcodes.INVOKESTATIC;
        }
        method.instructions.add(
                new MethodInsnNode(opcode, superClassName, getMethod().getName(), getMethod().getSignature()));
        method.instructions.add(new InsnNode(Opcodes.ARETURN));
    }
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateSwitchForCallAllBindingsNode.java

License:Open Source License

@Override
protected void addPostSwitchInstructions(MethodNode method) {
    method.instructions.add(gotoLabel);//from  w ww.  j av a 2 s .c o  m
    method.instructions.add(new IntInsnNode(Opcodes.ALOAD, 0));

    args = Type.getArgumentTypes(method.desc);
    int length = args.length;
    for (int i = 0; i < length; i++) {
        Type arg = args[i];
        method.instructions.add(new IntInsnNode(arg.getOpcode(Opcodes.ILOAD), i + 1));
    }

    // return callOrig(boundMethodId, args);
    method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, name, ConstantMembers.callOrig.getName(),
            ConstantMembers.callOrig.getSignature()));
    method.instructions.add(new InsnNode(Opcodes.ARETURN));
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.MoveCodeToCallOrigAdapter.java

License:Open Source License

public boolean transform() {
    MethodNode orgMethod = getMethod(method);
    if ((orgMethod.access & Opcodes.ACC_ABSTRACT) != 0)
        return false;

    MethodNode callOrig = getMethod(this.callOrig);

    Type returnType = Type.getReturnType(orgMethod.desc);

    InsnList newInstructions = new InsnList();

    //Unboxing arguments
    Type[] args = Type.getArgumentTypes(orgMethod.desc);

    int boundMethodIdSlot = firstArgIndex;

    if (args.length > 0) {
        // move boundMethodId to a higher slot, to make lower slots available for original locals
        newInstructions.add(new IntInsnNode(Opcodes.ILOAD, boundMethodIdSlot));
        boundMethodIdSlot = callOrig.maxLocals + 1;
        newInstructions.add(new IntInsnNode(Opcodes.ISTORE, boundMethodIdSlot));

        newInstructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + argOffset + 1));

        int slot = firstArgIndex + argOffset;
        for (int i = argOffset; i < args.length; i++) {
            if (i < args.length - 1) {
                newInstructions.add(new InsnNode(Opcodes.DUP));
            }//from   w  ww  .  j a  v  a 2  s.  c  o  m
            newInstructions.add(createLoadIntConstant(i));
            newInstructions.add(new InsnNode(Opcodes.AALOAD));
            Type arg = args[i];
            if (arg.getSort() != Type.ARRAY && arg.getSort() != Type.OBJECT) {
                String objectType = AsmTypeHelper.getObjectType(arg);
                newInstructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType));
                newInstructions.add(AsmTypeHelper.getUnboxingInstructionForType(arg, objectType));
            } else {
                newInstructions.add(new TypeInsnNode(Opcodes.CHECKCAST, arg.getInternalName()));
            }

            newInstructions.add(new IntInsnNode(args[i].getOpcode(Opcodes.ISTORE), slot));
            slot += arg.getSize();
        }
    }

    if (superIsWeavable)
        adjustSuperCalls(orgMethod.instructions, orgMethod.name, args, returnType, boundMethodIdSlot);

    // replace return of the original method with areturn and box the result value if needed
    replaceReturn(orgMethod.instructions, returnType);

    newInstructions.add(orgMethod.instructions);

    addNewLabelToSwitch(callOrig.instructions, newInstructions, boundMethodId);

    // a minimum stacksize of 3 is needed to box the arguments
    callOrig.maxStack = Math.max(Math.max(callOrig.maxStack, orgMethod.maxStack), 3);

    // we have to increment the max. stack size, because we have to put NULL on the stack
    if (returnType.getSort() == Type.VOID) {
        callOrig.maxStack += 1;
    }
    callOrig.maxLocals = Math.max(callOrig.maxLocals, orgMethod.maxLocals);
    return true;
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.MoveCodeToCallOrigAdapter.java

License:Open Source License

/** To avoid infinite recursion, calls super.m(a1, a2) must be translated to super.callOrig(boundMethodId, new Object[] {a1, a2}). */
private void adjustSuperCalls(InsnList instructions, String selector, Type[] args, Type returnType,
        int boundMethodIdSlot) {
    // search://  w  w w  . j  a  v a2 s .c  o  m
    List<MethodInsnNode> toReplace = new ArrayList<MethodInsnNode>();
    ListIterator<AbstractInsnNode> orgMethodIter = instructions.iterator();
    while (orgMethodIter.hasNext()) {
        AbstractInsnNode orgMethodNode = orgMethodIter.next();
        if (orgMethodNode.getOpcode() == Opcodes.INVOKESPECIAL
                && ((MethodInsnNode) orgMethodNode).name.equals(selector))
            toReplace.add((MethodInsnNode) orgMethodNode);
    }
    if (toReplace.isEmpty())
        return;
    // replace:
    for (MethodInsnNode oldNode : toReplace) {
        // we need to insert into the loading sequence before the invocation, find the insertion points:
        AbstractInsnNode[] insertionPoints = StackBalanceAnalyzer.findInsertionPointsBefore(oldNode, args);
        AbstractInsnNode firstInsert = insertionPoints.length > 0 ? insertionPoints[0] : oldNode;

        // push first arg to _OT$callOrig():
        instructions.insertBefore(firstInsert, new IntInsnNode(Opcodes.ILOAD, boundMethodIdSlot));

        // prepare array as second arg to _OT$callOrig():
        instructions.insertBefore(firstInsert, new IntInsnNode(Opcodes.BIPUSH, args.length));
        instructions.insertBefore(firstInsert, new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"));

        for (int i = 0; i < insertionPoints.length; i++) {
            // NB: each iteration has an even stack balance, where the top is the Object[].
            instructions.insertBefore(insertionPoints[i], new InsnNode(Opcodes.DUP));
            instructions.insertBefore(insertionPoints[i], new IntInsnNode(Opcodes.BIPUSH, i));
            // leave the original loading sequence in tact and continue at the next point:
            AbstractInsnNode insertAt = (i + 1 < insertionPoints.length) ? insertionPoints[i + 1] : oldNode;
            instructions.insertBefore(insertAt, AsmTypeHelper.getBoxingInstructionForType(args[i]));
            instructions.insertBefore(insertAt, new InsnNode(Opcodes.AASTORE));
        }

        if (returnType == Type.VOID_TYPE)
            instructions.insert(oldNode, new InsnNode(Opcodes.POP));
        else
            instructions.insert(oldNode, AsmTypeHelper.getUnboxingInstructionForType(returnType));

        instructions.set(oldNode, new MethodInsnNode(Opcodes.INVOKESPECIAL, ((MethodInsnNode) oldNode).owner,
                callOrig.getName(), callOrig.getSignature()));
    }
}

From source file:org.elasticsearch.painless.MethodWriter.java

License:Apache License

public void writeLoopCounter(int slot, int count, Location location) {
    assert slot != -1;
    writeDebugInfo(location);//from  w  ww  .  j a  v  a 2  s. co  m
    final Label end = new Label();

    iinc(slot, -count);
    visitVarInsn(Opcodes.ILOAD, slot);
    push(0);
    ifICmp(GeneratorAdapter.GT, end);
    throwException(PAINLESS_ERROR_TYPE,
            "The maximum number of statements that can be executed in a loop has been reached.");
    mark(end);
}

From source file:org.elasticsearch.painless.node.ECapturingFunctionRef.java

License:Apache License

@Override
void write(MethodWriter writer, Globals globals) {
    writer.writeDebugInfo(location);/*from ww w  .j  a va 2 s  . c o  m*/
    if (defPointer != null) {
        // dynamic interface: push captured parameter on stack
        // TODO: don't do this: its just to cutover :)
        writer.push((String) null);
        writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot());
    } else if (ref == null) {
        // typed interface, dynamic implementation
        writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot());
        Type methodType = Type.getMethodType(expected.type, captured.type.type);
        writer.invokeDefCall(call, methodType, DefBootstrap.REFERENCE, expected.name);
    } else {
        // typed interface, typed implementation
        writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot());
        // convert MethodTypes to asm Type for the constant pool.
        String invokedType = ref.invokedType.toMethodDescriptorString();
        Type samMethodType = Type.getMethodType(ref.samMethodType.toMethodDescriptorString());
        Type interfaceType = Type.getMethodType(ref.interfaceMethodType.toMethodDescriptorString());
        if (ref.needsBridges()) {
            writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType,
                    ref.implMethodASM, samMethodType, LambdaMetafactory.FLAG_BRIDGES, 1, interfaceType);
        } else {
            writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType,
                    ref.implMethodASM, samMethodType, 0);
        }
    }
}

From source file:org.elasticsearch.painless.node.ELambda.java

License:Apache License

@Override
void write(MethodWriter writer, Globals globals) {
    writer.writeDebugInfo(location);/*www .  j a  v  a  2s.c  o  m*/

    if (ref != null) {
        writer.writeDebugInfo(location);
        // load captures
        for (Variable capture : captures) {
            writer.visitVarInsn(capture.type.type.getOpcode(Opcodes.ILOAD), capture.getSlot());
        }
        // convert MethodTypes to asm Type for the constant pool.
        String invokedType = ref.invokedType.toMethodDescriptorString();
        org.objectweb.asm.Type samMethodType = org.objectweb.asm.Type
                .getMethodType(ref.samMethodType.toMethodDescriptorString());
        org.objectweb.asm.Type interfaceType = org.objectweb.asm.Type
                .getMethodType(ref.interfaceMethodType.toMethodDescriptorString());
        if (ref.needsBridges()) {
            writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType,
                    ref.implMethodASM, samMethodType, LambdaMetafactory.FLAG_BRIDGES, 1, interfaceType);
        } else {
            writer.invokeDynamic(ref.invokedName, invokedType, LAMBDA_BOOTSTRAP_HANDLE, samMethodType,
                    ref.implMethodASM, samMethodType, 0);
        }
    } else {
        // placeholder
        writer.push((String) null);
        // load captures
        for (Variable capture : captures) {
            writer.visitVarInsn(capture.type.type.getOpcode(Opcodes.ILOAD), capture.getSlot());
        }
    }

    // add synthetic method to the queue to be written
    globals.addSyntheticMethod(desugared);
}

From source file:org.elasticsearch.painless.node.EVariable.java

License:Apache License

@Override
void write(MethodWriter writer, Globals globals) {
    writer.visitVarInsn(actual.type.getOpcode(Opcodes.ILOAD), variable.getSlot());
}

From source file:org.elasticsearch.painless.node.EVariable.java

License:Apache License

@Override
void load(MethodWriter writer, Globals globals) {
    writer.visitVarInsn(actual.type.getOpcode(Opcodes.ILOAD), variable.getSlot());
}