Example usage for org.objectweb.asm Opcodes AALOAD

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

Introduction

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

Prototype

int AALOAD

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

Click Source Link

Usage

From source file:org.jacoco.core.internal.flow.FrameSnapshotTest.java

License:Open Source License

/**
 * Test of <a href="https://gitlab.ow2.org/asm/asm/issues/317793">ASM
 * bug</a>: according to <a href=
 * "https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.10.1.9.aaload">JVMS
 * "4.10.1.9 Type Checking Instructions, AALOAD"</a> resulting type on the
 * operand stack should be null if the input array is null.
 *///from  w  w  w  .j av a 2 s.com
@Test
public void after_aaload_stack_should_contain_null_when_input_array_is_null() {
    analyzer.visitInsn(Opcodes.ACONST_NULL);
    analyzer.visitInsn(Opcodes.ICONST_0);
    analyzer.visitInsn(Opcodes.AALOAD);
    frame = FrameSnapshot.create(analyzer, 0);

    final Object[] stack = arr(Opcodes.NULL);
    expectedVisitor.visitFrame(Opcodes.F_FULL, 1, arr("Foo"), 1, stack);
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    final Object t1, t2, t3, t4;
    switch (opcode) {
    case Opcodes.NOP:
    case Opcodes.RETURN:
        break;/*from   ww w .  ja v a  2  s .co m*/
    case Opcodes.ARETURN:
    case Opcodes.ATHROW:
    case Opcodes.FRETURN:
    case Opcodes.IRETURN:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.POP:
        pop(1);
        break;
    case Opcodes.DRETURN:
    case Opcodes.LRETURN:
    case Opcodes.POP2:
        pop(2);
        break;
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.FASTORE:
    case Opcodes.IASTORE:
    case Opcodes.SASTORE:
        pop(3);
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        pop(4);
        break;
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
        push(Opcodes.INTEGER);
        break;
    case Opcodes.ARRAYLENGTH:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.INEG:
        pop(1);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.D2I:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.IADD:
    case Opcodes.IALOAD:
    case Opcodes.IAND:
    case Opcodes.IDIV:
    case Opcodes.IMUL:
    case Opcodes.IOR:
    case Opcodes.IREM:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.ISUB:
    case Opcodes.IUSHR:
    case Opcodes.IXOR:
    case Opcodes.L2I:
    case Opcodes.SALOAD:
        pop(2);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.LCMP:
        pop(4);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
        push(Opcodes.FLOAT);
        break;
    case Opcodes.FNEG:
    case Opcodes.I2F:
        pop(1);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.D2F:
    case Opcodes.FADD:
    case Opcodes.FALOAD:
    case Opcodes.FDIV:
    case Opcodes.FMUL:
    case Opcodes.FREM:
    case Opcodes.FSUB:
    case Opcodes.L2F:
        pop(2);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2L:
    case Opcodes.I2L:
        pop(1);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.D2L:
    case Opcodes.LALOAD:
    case Opcodes.LNEG:
        pop(2);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
        pop(3);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LDIV:
    case Opcodes.LMUL:
    case Opcodes.LOR:
    case Opcodes.LREM:
    case Opcodes.LSUB:
    case Opcodes.LXOR:
        pop(4);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2D:
    case Opcodes.I2D:
        pop(1);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DALOAD:
    case Opcodes.DNEG:
    case Opcodes.L2D:
        pop(2);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DADD:
    case Opcodes.DDIV:
    case Opcodes.DMUL:
    case Opcodes.DREM:
    case Opcodes.DSUB:
        pop(4);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.ACONST_NULL:
        push(Opcodes.NULL);
        break;
    case Opcodes.AALOAD:
        pop(1);
        t1 = pop();
        push(Type.getType(((String) t1).substring(1)));
        break;
    case Opcodes.DUP:
        t1 = pop();
        push(t1);
        push(t1);
        break;
    case Opcodes.DUP_X1:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2:
        t1 = pop();
        t2 = pop();
        push(t2);
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X1:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t2);
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        t4 = pop();
        push(t2);
        push(t1);
        push(t4);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.SWAP:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitInsn(opcode);
}

From source file:org.jacoco.core.runtime.AbstractRuntimeData.java

License:Open Source License

/**
 * Generates the code that calls a {@link ControlFlowRuntimeData} instance through the
 * JRE API method {@link Object#equals(Object)}. The code pops a
 * {@link Object} instance from the stack and pushes the probe array of type
 * <code>boolean[]</code> on the operand stack. The generated code requires
 * a stack size of 6./*from  w w  w.  j av  a2 s .  com*/
 * 
 * @param classid
 *            class identifier
 * @param classname
 *            VM class name
 * @param probecount
 *            probe count for this class
 * @param mv
 *            visitor to emit generated code
 */
public static void generateAccessCall(final long classid, final String classname, final int probecount,
        final MethodVisitor mv) {
    // stack[0]: Ljava/lang/Object;

    generateArgumentArray(classid, classname, probecount, mv);

    // stack[1]: [Ljava/lang/Object;
    // stack[0]: Ljava/lang/Object;

    mv.visitInsn(Opcodes.DUP_X1);

    // stack[2]: [Ljava/lang/Object;
    // stack[1]: Ljava/lang/Object;
    // stack[0]: [Ljava/lang/Object;

    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
    mv.visitInsn(Opcodes.POP);

    // stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.AALOAD);

    // stack[0]: [Z

    mv.visitTypeInsn(Opcodes.CHECKCAST, InstrSupport.DATAFIELD_DESC);
}

From source file:org.jacoco.core.runtime.ExecutionDataAccess.java

License:Open Source License

/**
 * Generates the code that calls the runtime data access through the JRE API
 * method {@link Object#equals(Object)}. The code pops a {@link Object}
 * instance from the stack and pushes the probe array of type
 * <code>boolean[]</code> on the operand stack. The generated code requires
 * a stack size of 6.//from   ww w  . j  ava2s . c o m
 * 
 * @param classid
 * @param classname
 * @param probecount
 * @param mv
 */
public static void generateAccessCall(final long classid, final String classname, final int probecount,
        final MethodVisitor mv) {
    // stack[0]: Ljava/lang/Object;

    generateArgumentArray(classid, classname, probecount, mv);

    // stack[1]: [Ljava/lang/Object;
    // stack[0]: Ljava/lang/Object;

    mv.visitInsn(Opcodes.DUP_X1);

    // stack[2]: [Ljava/lang/Object;
    // stack[1]: Ljava/lang/Object;
    // stack[0]: [Ljava/lang/Object;

    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
    mv.visitInsn(Opcodes.POP);

    // stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.AALOAD);

    // stack[0]: [Z

    mv.visitTypeInsn(Opcodes.CHECKCAST, InstrSupport.DATAFIELD_DESC);
}

From source file:org.jacoco.core.runtime.LoggerRuntime.java

License:Open Source License

public int generateDataAccessor(final long classid, final String classname, final int probecount,
        final MethodVisitor mv) {

    // The data accessor performs the following steps:
    ///*  w w w .  j  a va  2s.  c  om*/
    // final Object[] args = new Object[3];
    // args[0] = Long.valueOf(classid);
    // args[1] = classname;
    // args[2] = Integer.valueOf(probecount);
    // Logger.getLogger(CHANNEL).log(Level.INFO, key, args);
    // final byte[] probedata = (byte[]) args[0];
    //
    // Note that local variable 'args' is used at two places. As were not
    // allowed to allocate local variables we have to keep this value with
    // DUP and SWAP operations on the operand stack.

    // 1. Create parameter array:

    RuntimeData.generateArgumentArray(classid, classname, probecount, mv);

    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.DUP);

    // Stack[1]: [Ljava/lang/Object;
    // Stack[0]: [Ljava/lang/Object;

    // 2. Call Logger:

    mv.visitLdcInsn(CHANNEL);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/logging/Logger", "getLogger",
            "(Ljava/lang/String;)Ljava/util/logging/Logger;");

    // Stack[2]: Ljava/util/logging/Logger;
    // Stack[1]: [Ljava/lang/Object;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.SWAP);

    // Stack[2]: [Ljava/lang/Object;
    // Stack[1]: Ljava/util/logging/Logger;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/util/logging/Level", "INFO", "Ljava/util/logging/Level;");

    // Stack[3]: Ljava/util/logging/Level;
    // Stack[2]: [Ljava/lang/Object;
    // Stack[1]: Ljava/util/logging/Logger;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.SWAP);

    // Stack[3]: [Ljava/lang/Object;
    // Stack[2]: Ljava/util/logging/Level;
    // Stack[1]: Ljava/util/logging/Logger;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitLdcInsn(key);

    // Stack[4]: Ljava/lang/String;
    // Stack[3]: [Ljava/lang/Object;
    // Stack[2]: Ljava/util/logging/Level;
    // Stack[1]: Ljava/util/logging/Logger;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.SWAP);

    // Stack[4]: [Ljava/lang/Object;
    // Stack[3]: Ljava/lang/String;
    // Stack[2]: Ljava/util/logging/Level;
    // Stack[1]: Ljava/util/logging/Logger;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/logging/Logger", "log",
            "(Ljava/util/logging/Level;Ljava/lang/String;[Ljava/lang/Object;)V");

    // Stack[0]: [Ljava/lang/Object;

    // 3. Load data structure from parameter array:

    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.AALOAD);
    mv.visitTypeInsn(Opcodes.CHECKCAST, InstrSupport.DATAFIELD_DESC);

    // Stack[0]: [Z

    return 5; // Maximum local stack size is 5
}

From source file:org.jacoco.core.runtime.URLStreamHandlerRuntime.java

License:Open Source License

public int generateDataAccessor(final long classid, final String classname, final int probecount,
        final MethodVisitor mv) {

    // The data accessor performs the following steps:
    ////from   ww  w  . j a  va2 s. com
    // final URL url = new URL(protocol, null, "");
    // final URLConnection connection = url.openConnection();
    // final Object[] args = new Object[3];
    // args[0] = Long.valueOf(classid);
    // args[1] = classname;
    // args[2] = Integer.valueOf(probecount);
    // connection.equals(args);
    // final byte[] probedata = (byte[]) args[0];

    RuntimeData.generateArgumentArray(classid, classname, probecount, mv);
    mv.visitInsn(Opcodes.DUP);

    // Stack[1]: [Ljava/lang/Object;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitTypeInsn(Opcodes.NEW, "java/net/URL");
    mv.visitInsn(Opcodes.DUP);
    mv.visitLdcInsn(protocol);
    mv.visitInsn(Opcodes.ACONST_NULL);
    mv.visitLdcInsn("");
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/net/URL", "<init>",
            "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");

    // Stack[2]: [Ljava/net/URL;
    // Stack[1]: [Ljava/lang/Object;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/net/URL", "openConnection", "()Ljava/net/URLConnection;");

    // Stack[2]: [Ljava/net/URLConnection;
    // Stack[1]: [Ljava/lang/Object;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.SWAP);

    // Stack[2]: [Ljava/lang/Object;
    // Stack[1]: [Ljava/net/URLConnection;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");

    // Stack[1]: Z;
    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.POP);

    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.AALOAD);
    mv.visitTypeInsn(Opcodes.CHECKCAST, InstrSupport.DATAFIELD_DESC);

    return 7;
}

From source file:org.jboss.arquillian.extension.jacoco.container.ArquillianRuntime.java

License:Apache License

public int generateDataAccessor(long classid, String classname, int probecount, MethodVisitor mv) {
    // 1. Create parameter array:
    generateArgumentArray(classid, classname, probecount, mv);
    // stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.DUP);//from   www . j  a  v  a2 s .  co  m

    // stack[1]: [Ljava/lang/Object;
    // stack[0]: [Ljava/lang/Object;

    // 2. Invoke ArquillianRuntime:
    mv.visitMethodInsn(Opcodes.INVOKESTATIC,
            "org/jboss/arquillian/extension/jacoco/container/ArquillianRuntime", "getInstance",
            "()Lorg/jboss/arquillian/extension/jacoco/container/ArquillianRuntime;");

    // stack[2]: LArquillianRuntime;
    // stack[1]: [Ljava/lang/Object;
    // stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.SWAP);

    // stack[2]: [Ljava/lang/Object;
    // stack[1]: LArquillianRuntime;
    // stack[0]: [Ljava/lang/Object;

    // 3. Invoke ArquillianRuntime swapExecutionData, gets the boolean[] in Object[0]:
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
            "org/jboss/arquillian/extension/jacoco/container/ArquillianRuntime", "swapExecutionData",
            "([Ljava/lang/Object;)V");

    // Stack[0]: [Ljava/lang/Object;

    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.AALOAD);
    mv.visitTypeInsn(Opcodes.CHECKCAST, InstrSupport.DATAFIELD_DESC);

    // Stack[0]: [Z;

    return 5;
}

From source file:org.jboss.byteman.rule.expression.ArrayExpression.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    Type valueType = arrayRef.getType().getBaseType();
    int currentStack = compileContext.getStackCount();
    int expected = 0;

    // compile load of array reference -- adds 1 to stack height
    arrayRef.compile(mv, compileContext);
    // for each index expression compile the expression and the do an array load
    Iterator<Expression> iterator = idxList.iterator();

    while (iterator.hasNext()) {
        Expression idxExpr = iterator.next();
        // compile expression index -- adds 1 to height
        idxExpr.compile(mv, compileContext);
        // make sure the index is an integer
        compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext);

        if (valueType.isObject() || valueType.isArray()) {
            // compile load object - pops 2 and adds 1
            mv.visitInsn(Opcodes.AALOAD);
            expected = 1;/*from www  . j a v a2s.  c  om*/
        } else if (valueType == Type.Z || valueType == Type.B) {
            // compile load byte - pops 2 and adds 1
            mv.visitInsn(Opcodes.BALOAD);
            expected = 1;
        } else if (valueType == Type.S) {
            // compile load short - pops 2 and adds 1
            mv.visitInsn(Opcodes.SALOAD);
            expected = 1;
        } else if (valueType == Type.C) {
            // compile load char - pops 2 and adds 1
            mv.visitInsn(Opcodes.CALOAD);
            expected = 1;
        } else if (valueType == Type.I) {
            // compile load int - pops 2 and adds 1
            mv.visitInsn(Opcodes.IALOAD);
            expected = 1;
        } else if (valueType == Type.J) {
            // compile load long - pops 2 and adds 2
            mv.visitInsn(Opcodes.LALOAD);
            expected = 2;
        } else if (valueType == Type.F) {
            // compile load float - pops 2 and adds 1
            mv.visitInsn(Opcodes.FALOAD);
            expected = 1;
        } else if (valueType == Type.D) {
            // compile load double - pops 2 and adds 2
            mv.visitInsn(Opcodes.DALOAD);
            expected = 2;
        }
        compileContext.addStackCount(expected - 2);
        if (iterator.hasNext()) {
            assert valueType.isArray();
            valueType = valueType.getBaseType();
        }
    }

    // check stack height
    if (compileContext.getStackCount() != currentStack + expected) {
        throw new CompileException("ArrayExpression.compile : invalid stack height "
                + compileContext.getStackCount() + " expecting " + (currentStack + expected));
    }

    // we needed room for an aray and an index or for a one or two word result
    // but the recursive evaluations will have made sure the max stack is big enough
    // so there is no need to update the maximum stack height
}

From source file:org.jboss.byteman.rule.expression.ArrayExpression.java

License:Open Source License

@Override
public void compileAssign(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    Type valueType = arrayRef.getType().getBaseType();
    int currentStack = compileContext.getStackCount();
    boolean isTwoWords = (valueType.getNBytes() > 4);
    int toPop = 0;
    int size = (isTwoWords ? 2 : 1);

    // value to be assigned is TOS and will already be coerced to the correct value type
    // copy it so we can install the copy and leave the original as a a return value on the stack
    if (isTwoWords) {
        // [... val1 val2 ==> ... val1 val2 val1 val2]
        mv.visitInsn(Opcodes.DUP2);//  w ww  . ja v a2  s  .  c o  m
    } else {
        // [... val ==> ... val val]
        mv.visitInsn(Opcodes.DUP);
    }
    compileContext.addStackCount(size);

    // compile load of array reference -- adds 1 to stack height
    arrayRef.compile(mv, compileContext);
    // for each index expression compile the expression and the do an array load
    Iterator<Expression> iterator = idxList.iterator();

    while (iterator.hasNext()) {
        Expression idxExpr = iterator.next();
        if (iterator.hasNext()) {
            // dereference the array to get an embedded array
            // compile expression index -- adds 1 to height
            idxExpr.compile(mv, compileContext);
            // make sure the index is an integer
            compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext);
            // fetch embedded array pop 2 and add 1
            mv.visitInsn(Opcodes.AALOAD);
            compileContext.addStackCount(-1);
            valueType = valueType.getBaseType();
        } else {
            if (isTwoWords) {
                // stack is [..., val1, val2, val1, val2, aref ] and we want [..., val1, val2, aref, val1, val2 ]
                mv.visitInsn(Opcodes.DUP_X2); // ==>  [..., val1, val2, aref. val1, val2, aref ]
                compileContext.addStackCount(1);
                mv.visitInsn(Opcodes.POP); // ==> [..., val1, val2, aref. val1, val2 ]
                compileContext.addStackCount(-1);
            } else {
                // stack is [..., val, val, aref ] and we want [..., val, aref, val ]
                mv.visitInsn(Opcodes.SWAP);
            }
            // compile expression index -- adds 1 to height
            idxExpr.compile(mv, compileContext);
            // make sure the index is an integer
            compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext);
            if (isTwoWords) {
                // stack is [..., val1, val2, aref, val1, val2, idx] and we want [..., val1, val2, aref, idx, val1, val2 ]
                mv.visitInsn(Opcodes.DUP_X2); // ==> [..., val1, val2, aref, idx, val1, val2, idx]
                compileContext.addStackCount(1);
                mv.visitInsn(Opcodes.POP); // ==> [..., val1, val2, aref, idx, val1, val2 ]
                compileContext.addStackCount(-1);
            } else {
                // stack is [..., val, aref, val, idx] and we want [..., val, aref, idx, val ]
                mv.visitInsn(Opcodes.SWAP);
            }
            // now we can do the array store
            if (valueType.isObject() || valueType.isArray()) {
                // compile load object - pops 3
                mv.visitInsn(Opcodes.AASTORE);
                toPop = -3;
            } else if (valueType == Type.Z || valueType == Type.B) {
                // compile load byte - pops 3
                mv.visitInsn(Opcodes.BASTORE);
                toPop = -3;
            } else if (valueType == Type.S) {
                // compile load short - pops 3
                mv.visitInsn(Opcodes.SASTORE);
                toPop = -3;
            } else if (valueType == Type.C) {
                // compile load char - pops 3
                mv.visitInsn(Opcodes.CASTORE);
                toPop = -3;
            } else if (valueType == Type.I) {
                // compile load int - pops 3
                mv.visitInsn(Opcodes.IASTORE);
                toPop = -3;
            } else if (valueType == Type.J) {
                // compile load long - pops 4
                mv.visitInsn(Opcodes.LASTORE);
                toPop = -4;
            } else if (valueType == Type.F) {
                // compile load float - pops 3
                mv.visitInsn(Opcodes.FASTORE);
                toPop = -3;
            } else if (valueType == Type.D) {
                // compile load double - pops 4
                mv.visitInsn(Opcodes.DASTORE);
                toPop = -4;
            }
            compileContext.addStackCount(toPop);
            if (iterator.hasNext()) {
                assert valueType.isArray();
                valueType = valueType.getBaseType();
            }
        }
    }

    // check stack height
    if (compileContext.getStackCount() != currentStack) {
        throw new CompileException("ArrayExpression.compile : invalid stack height "
                + compileContext.getStackCount() + " expecting " + currentStack);
    }

    // we needed room for an aray and an index or for a one or two word result
    // but the recursive evaluations will have made sure the max stack is big enough
    // so there is no need to update the maximum stack height
}

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

/**
 * @param elemType element type of the array.
 * @return java op-code to use for loading arrays with elements of the specified type.
 *///from  w  w  w  .  j a v a  2s.  c o m
private static int getArrayLoadOpCode(JavaTypeName elemType) {

    switch (elemType.getTag()) {

    case JavaTypeName.VOID_TAG:
        throw new IllegalArgumentException();

    case JavaTypeName.BOOLEAN_TAG:
    case JavaTypeName.BYTE_TAG:
        return Opcodes.BALOAD;

    case JavaTypeName.SHORT_TAG:
        return Opcodes.SALOAD;

    case JavaTypeName.CHAR_TAG:
        return Opcodes.CALOAD;

    case JavaTypeName.INT_TAG:
        return Opcodes.IALOAD;

    case JavaTypeName.LONG_TAG:
        return Opcodes.LALOAD;

    case JavaTypeName.DOUBLE_TAG:
        return Opcodes.DALOAD;

    case JavaTypeName.FLOAT_TAG:
        return Opcodes.FALOAD;

    case JavaTypeName.ARRAY_TAG:
    case JavaTypeName.OBJECT_TAG:
        return Opcodes.AALOAD;

    default: {
        throw new IllegalArgumentException();
    }
    }
}