Example usage for org.objectweb.asm Opcodes ISTORE

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

Introduction

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

Prototype

int ISTORE

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

Click Source Link

Usage

From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java

License:Open Source License

@Override
public void visitVarInsn(final int opcode, final int var) {
    T t = null;//from   w  w  w  .j a  v  a  2  s .  co  m

    switch (opcode) {
    /********
     * LOAD *
     ********/
    case Opcodes.ALOAD:
        t = T.REF;
        // fall through
    case Opcodes.DLOAD:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FLOAD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ILOAD:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LLOAD:
        if (t == null) {
            t = T.LONG;
        }
        add(new LOAD(this.ops.size(), opcode, this.line, t, var));
        break;
    /*********
     * STORE *
     *********/
    case Opcodes.ASTORE:
        t = T.AREF; // RET allowed too
        // fall through
    case Opcodes.DSTORE:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FSTORE:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ISTORE:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LSTORE:
        if (t == null) {
            t = T.LONG;
        }
        add(new STORE(this.ops.size(), opcode, this.line, t, var));
        break;
    /*******
     * RET *
     *******/
    case Opcodes.RET: {
        add(new RET(this.ops.size(), opcode, this.line, var));
        break;
    }
    default:
        log.warn(getM() + ": Unknown var insn opcode '" + opcode + "'!");
    }
}

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

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String methodName, String desc, String signature,
        String[] exceptions) {//from  www .j a  va 2 s.  co  m
    if (INIT.equals(methodName)) {
        // into each constructor ...
        final MethodVisitor methodVisitor = cv.visitMethod(access, methodName, desc, null, null);
        return new AdviceAdapter(this.api, methodVisitor, access, methodName, desc) {
            @Override
            public void invokeConstructor(Type type, Method method) {
                super.invokeConstructor(type, method);
                // ... that contains a super(..) call (rather than this(..)):
                if (type.getInternalName().equals(clazz.getInternalSuperClassName())) {
                    // insert:
                    // this._OT$creationThread = Thread.currentThread();
                    methodVisitor.visitIntInsn(Opcodes.ALOAD, 0);
                    methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.THREAD_SLASH, CURRENT_THREAD,
                            CURRENT_THREAD_DESC, false);
                    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, clazz.getInternalName(), CREATION_THREAD,
                            THREAD_DESC);
                }
            }
        };
    } else if (RUN.equals(methodName) && RUN_DESC.equals(desc)) {
        final MethodVisitor methodVisitor = cv.visitMethod(access, methodName, desc, null, null);
        return new AdviceAdapter(this.api, methodVisitor, access, methodName, desc) {

            Label start = new Label(); // start of method (scope of new local)
            Label end = new Label(); // end of method
            int isThreadStartIdx; // new local: boolean _OT$isThreadStart

            @Override
            protected void onMethodEnter() {
                methodVisitor.visitLabel(start);
                isThreadStartIdx = newLocal(Type.BOOLEAN_TYPE);
                methodVisitor.visitLocalVariable("_OT$isThreadStart", "Z", null, start, end, isThreadStartIdx);
                // TeamThreadManager.newThreadStarted(false, this._OT$creationThread)
                methodVisitor.visitInsn(Opcodes.ICONST_0);
                methodVisitor.visitIntInsn(Opcodes.ALOAD, 0);
                methodVisitor.visitFieldInsn(Opcodes.GETFIELD, clazz.getInternalName(), CREATION_THREAD,
                        THREAD_DESC);
                methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.TEAM_THREAD_MANAGER_SLASH,
                        NEW_THREAD_STARTED, NEW_THREAD_STARTED_DESC, false);
                methodVisitor.visitIntInsn(Opcodes.ISTORE, isThreadStartIdx);
                // this._OT$creationThread = null; // avoid leak
                methodVisitor.visitIntInsn(Opcodes.ALOAD, 0);
                methodVisitor.visitInsn(Opcodes.ACONST_NULL);
                methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, clazz.getInternalName(), CREATION_THREAD,
                        THREAD_DESC);
            }

            @Override
            protected void onMethodExit(int opcode) {
                insertThreadEndedNotification();
            }

            @Override
            public void endMethod() {
                methodVisitor.visitLabel(end);

                // insert another threadEnded notification as a handler for Throwable
                Label handler = new Label();
                methodVisitor.visitLabel(handler);
                insertThreadEndedNotification();
                methodVisitor.visitInsn(Opcodes.ATHROW); // rethrow caught exception

                methodVisitor.visitTryCatchBlock(start, end, handler, ClassNames.THROWABLE_SLASH);
                methodVisitor.visitMaxs(0, 0);
            }

            void insertThreadEndedNotification() {
                Label skip = new Label();
                // insert:
                // if (_OT$isThreadStart) TeamThreadManager.threadEnded();
                methodVisitor.visitIntInsn(Opcodes.ILOAD, isThreadStartIdx);
                methodVisitor.visitJumpInsn(Opcodes.IFEQ, skip);
                methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ClassNames.TEAM_THREAD_MANAGER_SLASH,
                        THREAD_ENDED, THREAD_ENDED_DESC, false);
                methodVisitor.visitLabel(skip);
            }
        };
    }
    return null;
}

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 w w  .j  a  v a2  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.elasticsearch.painless.node.EVariable.java

License:Apache License

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

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

License:Apache License

@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
    adapter.visitVarInsn(after.type.getOpcode(Opcodes.ISTORE), slot);
}

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

License:Apache License

@Override
void write(MethodWriter writer, Globals globals) {
    writer.writeStatementOffset(location);

    Label jump = new Label();

    writer.mark(jump);//  ww w. j  a  va 2 s . com
    writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot());

    if (block != null) {
        block.continu = continu;
        block.brake = brake;
        block.write(writer, globals);
    }

    writer.visitTryCatchBlock(begin, end, jump, variable.type.type.getInternalName());

    if (exception != null && !block.allEscape) {
        writer.goTo(exception);
    }
}

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

License:Apache License

@Override
void write(MethodWriter writer, Globals globals) {
    writer.writeStatementOffset(location);

    if (expression == null) {
        switch (variable.type.sort) {
        case VOID:
            throw createError(new IllegalStateException("Illegal tree structure."));
        case BOOL:
        case BYTE:
        case SHORT:
        case CHAR:
        case INT:
            writer.push(0);// w  w  w.  j  a  v a  2  s .  c om
            break;
        case LONG:
            writer.push(0L);
            break;
        case FLOAT:
            writer.push(0.0F);
            break;
        case DOUBLE:
            writer.push(0.0);
            break;
        default:
            writer.visitInsn(Opcodes.ACONST_NULL);
        }
    } else {
        expression.write(writer, globals);
    }

    writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot());
}

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

License:Apache License

void writeArray(MethodWriter writer, Globals globals) {
    expression.write(writer, globals);/*from  w ww  .  j  a va  2s.  co  m*/
    writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ISTORE), array.getSlot());
    writer.push(-1);
    writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ISTORE), index.getSlot());

    Label begin = new Label();
    Label end = new Label();

    writer.mark(begin);

    writer.visitIincInsn(index.getSlot(), 1);
    writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.getSlot());
    writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.getSlot());
    writer.arrayLength();
    writer.ifICmp(MethodWriter.GE, end);

    writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.getSlot());
    writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.getSlot());
    writer.arrayLoad(indexed.type);
    writer.writeCast(cast);
    writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot());

    block.write(writer, globals);

    writer.goTo(begin);
    writer.mark(end);
}

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

License:Apache License

void writeIterable(MethodWriter writer, Globals globals) {
    expression.write(writer, globals);//w ww .  j  a v  a2s.co  m

    if (method == null) {
        Type itr = Definition.getType("Iterator");
        org.objectweb.asm.Type methodType = org.objectweb.asm.Type.getMethodType(itr.type,
                Definition.DEF_TYPE.type);
        writer.invokeDefCall("iterator", methodType, DefBootstrap.ITERATOR);
    } else {
        method.write(writer);
    }

    writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ISTORE), iterator.getSlot());

    Label begin = new Label();
    Label end = new Label();

    writer.mark(begin);

    writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ILOAD), iterator.getSlot());
    writer.invokeInterface(ITERATOR_TYPE, ITERATOR_HASNEXT);
    writer.ifZCmp(MethodWriter.EQ, end);

    writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ILOAD), iterator.getSlot());
    writer.invokeInterface(ITERATOR_TYPE, ITERATOR_NEXT);
    writer.writeCast(cast);
    writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot());

    block.write(writer, globals);

    writer.goTo(begin);
    writer.mark(end);
}

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

License:Apache License

@Override
void write(MethodWriter function, Globals globals) {
    if (reserved.getMaxLoopCounter() > 0) {
        // if there is infinite loop protection, we do this once:
        // int #loop = settings.getMaxLoopCounter()
        function.push(reserved.getMaxLoopCounter());
        function.visitVarInsn(Opcodes.ISTORE, loop.getSlot());
    }/*from   w w w.  j  ava2  s.c o  m*/

    for (AStatement statement : statements) {
        statement.write(function, globals);
    }

    if (!methodEscape) {
        if (rtnType.sort == Sort.VOID) {
            function.returnValue();
        } else {
            throw createError(new IllegalStateException("Illegal tree structure."));
        }
    }

    String staticHandleFieldName = Def.getUserFunctionHandleFieldName(name, parameters.size());
    globals.addConstantInitializer(new Constant(location, WriterConstants.METHOD_HANDLE_TYPE,
            staticHandleFieldName, this::initializeConstant));
}