Example usage for org.objectweb.asm Opcodes ALOAD

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

Introduction

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

Prototype

int ALOAD

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

Click Source Link

Usage

From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java

License:Open Source License

private void emitStoreState(MethodVisitor mv, int idx, FrameInfo fi, int numArgsToPreserve) {
    Frame f = frames[fi.endInstruction];

    if (fi.lBefore != null)
        fi.lBefore.accept(mv);/*from ww  w.j  a va  2  s .c  o  m*/

    mv.visitVarInsn(Opcodes.ALOAD, lvarStack);
    emitConst(mv, idx);
    emitConst(mv, fi.numSlots);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "pushMethod", "(II)V");

    // store operand stack
    for (int i = f.getStackSize(); i-- > 0;) {
        BasicValue v = (BasicValue) f.getStack(i);
        if (!isOmitted(v)) {
            if (!isNullType(v)) {
                int slotIdx = fi.stackSlotIndices[i];
                assert slotIdx >= 0 && slotIdx < fi.numSlots;
                emitStoreValue(mv, v, lvarStack, slotIdx, -1);
            } else {
                db.log(LogLevel.DEBUG, "NULL stack entry: type=%s size=%d", v.getType(), v.getSize());
                mv.visitInsn(Opcodes.POP);
            }
        }
    }

    // store local vars
    for (int i = firstLocal; i < f.getLocals(); i++) {
        BasicValue v = (BasicValue) f.getLocal(i);
        if (!isNullType(v)) {
            mv.visitVarInsn(v.getType().getOpcode(Opcodes.ILOAD), i);
            int slotIdx = fi.localSlotIndices[i];
            assert slotIdx >= 0 && slotIdx < fi.numSlots;
            emitStoreValue(mv, v, lvarStack, slotIdx, i);
        }
    }

    // restore last numArgsToPreserve operands
    for (int i = f.getStackSize() - numArgsToPreserve; i < f.getStackSize(); i++) {
        BasicValue v = (BasicValue) f.getStack(i);
        if (!isOmitted(v)) {
            if (!isNullType(v)) {
                int slotIdx = fi.stackSlotIndices[i];
                assert slotIdx >= 0 && slotIdx < fi.numSlots;
                emitRestoreValue(mv, v, lvarStack, slotIdx, -1);
            } else {
                mv.visitInsn(Opcodes.ACONST_NULL);
            }
        }
    }
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java

License:Open Source License

private void emitPostRestore(MethodVisitor mv) {
    mv.visitVarInsn(Opcodes.ALOAD, lvarStack);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "postRestore", "()V");
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java

License:Open Source License

private void emitPreemptionPoint(MethodVisitor mv, int type) {
    mv.visitVarInsn(Opcodes.ALOAD, lvarStack);
    switch (type) {
    case 0:/* ww w  .j  a v a2s.  co m*/
        mv.visitInsn(Opcodes.ICONST_0);
        break;
    case 1:
        mv.visitInsn(Opcodes.ICONST_1);
        break;
    case 2:
        mv.visitInsn(Opcodes.ICONST_2);
        break;
    case 3:
        mv.visitInsn(Opcodes.ICONST_3);
        break;
    default:
        throw new AssertionError("Unsupported type: " + type);
    }
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "preemptionPoint", "(I)V");
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java

License:Open Source License

private void emitStoreValue(MethodVisitor mv, BasicValue v, int lvarStack, int idx, int lvar)
        throws InternalError, IndexOutOfBoundsException {
    String desc;//from  w  w w  .j a  v a 2 s  . c  o m

    switch (v.getType().getSort()) {
    case Type.OBJECT:
    case Type.ARRAY:
        desc = "(Ljava/lang/Object;L" + STACK_NAME + ";I)V";
        break;
    case Type.BOOLEAN:
    case Type.BYTE:
    case Type.SHORT:
    case Type.CHAR:
    case Type.INT:
        desc = "(IL" + STACK_NAME + ";I)V";
        break;
    case Type.FLOAT:
        desc = "(FL" + STACK_NAME + ";I)V";
        break;
    case Type.LONG:
        desc = "(JL" + STACK_NAME + ";I)V";
        break;
    case Type.DOUBLE:
        desc = "(DL" + STACK_NAME + ";I)V";
        break;
    default:
        throw new InternalError("Unexpected type: " + v.getType());
    }

    mv.visitVarInsn(Opcodes.ALOAD, lvarStack);
    //        if (v.getType().getSort() == Type.OBJECT || v.getType().getSort() == Type.ARRAY)
    //            println(mv, "STORE " + (lvar >= 0 ? ("VAR " + lvar + ": ") : "OPRND: "));
    emitConst(mv, idx);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, STACK_NAME, "push", desc);
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java

License:Open Source License

private void emitRestoreValue(MethodVisitor mv, BasicValue v, int lvarStack, int idx, int lvar) {
    mv.visitVarInsn(Opcodes.ALOAD, lvarStack);
    emitConst(mv, idx);//from   w w  w .j  a  va  2s .c  om

    switch (v.getType().getSort()) {
    case Type.OBJECT:
        String internalName = v.getType().getInternalName();
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getObject", "(I)Ljava/lang/Object;");
        if (!internalName.equals("java/lang/Object")) // don't cast to Object ;)
            mv.visitTypeInsn(Opcodes.CHECKCAST, internalName);
        //                println(mv, "RESTORE " + (lvar >= 0 ? ("VAR " + lvar + ": ") : "OPRND: "));
        break;
    case Type.ARRAY:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getObject", "(I)Ljava/lang/Object;");
        mv.visitTypeInsn(Opcodes.CHECKCAST, v.getType().getDescriptor());
        break;
    case Type.BYTE:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getInt", "(I)I");
        mv.visitInsn(Opcodes.I2B);
        break;
    case Type.SHORT:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getInt", "(I)I");
        mv.visitInsn(Opcodes.I2S);
        break;
    case Type.CHAR:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getInt", "(I)I");
        mv.visitInsn(Opcodes.I2C);
        break;
    case Type.BOOLEAN:
    case Type.INT:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getInt", "(I)I");
        break;
    case Type.FLOAT:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getFloat", "(I)F");
        break;
    case Type.LONG:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getLong", "(I)J");
        break;
    case Type.DOUBLE:
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "getDouble", "(I)D");
        break;
    default:
        throw new InternalError("Unexpected type: " + v.getType());
    }
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java

License:Open Source License

private void println(MethodVisitor mv, String prefix, int refVar) {
    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;");
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder");
    mv.visitInsn(Opcodes.DUP);/*from   www  . jav  a  2s .  com*/
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V");
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Thread", "currentThread", "()Ljava/lang/Thread;");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Thread", "getName", "()Ljava/lang/String;");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(Ljava/lang/String;)Ljava/lang/StringBuilder;");
    mv.visitLdcInsn(" " + prefix);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(Ljava/lang/String;)Ljava/lang/StringBuilder;");
    mv.visitLdcInsn(" var " + refVar + ":");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(Ljava/lang/String;)Ljava/lang/StringBuilder;");

    mv.visitVarInsn(Opcodes.ALOAD, refVar);

    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(Ljava/lang/Object;)Ljava/lang/StringBuilder;");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
}

From source file:com.alibaba.hotswap.processor.constructor.modifier.FieldHolderInitModifier.java

License:Open Source License

@Override
public void visitCode() {
    super.visitCode();

    // this.__$$hotswap_field_holder$$__ = new ConcurrentHashMap();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, HotswapConstants.FIELD_HOLDER,
            "Ljava/util/concurrent/ConcurrentHashMap;");
    Label end = newLabel();// w w  w  .  j  av  a 2s  .co  m
    ifNonNull(end);

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/concurrent/ConcurrentHashMap");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/concurrent/ConcurrentHashMap", "<init>", "()V");
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, HotswapConstants.FIELD_HOLDER,
            "Ljava/util/concurrent/ConcurrentHashMap;");
    mark(end);
}

From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.DefineClassMethodModifier.java

License:Open Source License

@Override
public void visitCode() {
    super.visitCode();

    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapConfiguration.class),
            "getClassPathInWorkspace", "(Ljava/lang/String;)Ljava/lang/String;");
    mv.visitInsn(Opcodes.DUP);/*  w  ww .  j a v a2  s  . c o m*/
    Label old = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, old);

    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "updateClassMeta",
            "(Ljava/lang/String;Ljava/lang/ClassLoader;)V");

    mv.visitVarInsn(Opcodes.ALOAD, 1); // className
    mv.visitInsn(Opcodes.SWAP);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(CustomerLoadClassBytes.class),
            "loadBytesFromPath", "(Ljava/lang/String;Ljava/lang/String;)[B");
    mv.visitVarInsn(Opcodes.ASTORE, 2);// store class bytes into 2
    mv.visitVarInsn(Opcodes.ALOAD, 2);// load class bytes
    mv.visitInsn(Opcodes.ARRAYLENGTH); // length of the class bytes
    mv.visitVarInsn(Opcodes.ISTORE, 4);// store length into 4

    Label end = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, end);

    mv.visitLabel(old);
    mv.visitInsn(Opcodes.POP);

    mv.visitLabel(end);
}

From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.DefineClassMethodModifier.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    if (opcode == Opcodes.ARETURN) {
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta",
                "(Ljava/lang/String;)Z");
        Label end = new Label();
        mv.visitJumpInsn(Opcodes.IFEQ, end);

        mv.visitInsn(Opcodes.DUP);//from  w  w w  .  ja  v  a2s  .c o m
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitInsn(Opcodes.SWAP);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class),
                "updateClassMetaClass", "(Ljava/lang/String;Ljava/lang/Class;)V");

        mv.visitLabel(end);
    }

    super.visitInsn(opcode);
}

From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.FindClassMethodModifier.java

License:Open Source License

@Override
public void visitCode() {
    super.visitCode();

    Label normal = new Label();

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);/*from   w ww  .  j a  v a 2  s . c  om*/
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ClassLoaderHelper.class), "tryLoadVClass",
            "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;");
    mv.visitInsn(Opcodes.DUP);
    mv.visitJumpInsn(Opcodes.IFNULL, normal);
    mv.visitInsn(Opcodes.ARETURN);

    mv.visitLabel(normal);
    mv.visitInsn(Opcodes.POP);
}