Example usage for org.objectweb.asm MethodVisitor visitLookupSwitchInsn

List of usage examples for org.objectweb.asm MethodVisitor visitLookupSwitchInsn

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitLookupSwitchInsn.

Prototype

public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) 

Source Link

Document

Visits a LOOKUPSWITCH instruction.

Usage

From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java

License:Open Source License

protected void generateWriteStaticGroup(Schema schema, ClassVisitor cv, String genClassInternalName,
        boolean javaClassCodec) {
    // method writeStaticGroupWithId - switch
    MethodVisitor mv = cv.visitMethod(ACC_PROTECTED, "writeStaticGroupWithId",
            "(Lcom/cinnober/msgcodec/io/ByteSink;Ljava/lang/Object;)V", null,
            new String[] { "java/io/IOException" });
    int nextVar = 3;
    mv.visitCode();// w w w .  j a  va 2 s  . co  m

    mv.visitVarInsn(ALOAD, 2);
    if (javaClassCodec) {
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    } else {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, genClassInternalName, "groupTypeAccessor",
                "Lcom/cinnober/msgcodec/GroupTypeAccessor;");
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEINTERFACE, "com/cinnober/msgcodec/GroupTypeAccessor", "getGroupType",
                "(Ljava/lang/Object;)Ljava/lang/Object;", true);
    }
    int groupTypeVar = nextVar++;
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, groupTypeVar);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I", false);

    // switch on class.hashCode()
    Map<Integer, ObjectHashCodeSwitchCase<Object>> casesByHashCode = new TreeMap<>();
    Map<Integer, Label> labelsByGroupId = new TreeMap<>();
    for (GroupDef group : schema.getGroups()) {
        Object groupType = group.getGroupType();
        int groupHash = groupType.hashCode();
        ObjectHashCodeSwitchCase<Object> hashCase = casesByHashCode.get(groupHash);
        if (hashCase == null) {
            hashCase = new ObjectHashCodeSwitchCase<>(groupHash);
            casesByHashCode.put(hashCase.hashCode, hashCase);
        }
        hashCase.add(groupType);
    }

    Label unknownHashLabel = new Label();
    {
        int[] caseValues = new int[casesByHashCode.size()];
        int i = 0;
        for (int hashCode : casesByHashCode.keySet()) {
            caseValues[i++] = hashCode;
        }
        Label[] caseLabels = new Label[casesByHashCode.size()];
        i = 0;
        for (ObjectHashCodeSwitchCase<Object> hashCase : casesByHashCode.values()) {
            caseLabels[i++] = hashCase.label;
        }
        mv.visitLookupSwitchInsn(unknownHashLabel, caseValues, caseLabels);
    }
    for (ObjectHashCodeSwitchCase<Object> hashCase : casesByHashCode.values()) {
        mv.visitLabel(hashCase.label);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        for (ObjectSwitchCase<Object> classCase : hashCase.cases) {
            GroupDef group = schema.getGroup(classCase.object);
            int groupId = schema.getGroup(classCase.object).getId();
            if (groupId != -1) {
                labelsByGroupId.put(groupId, classCase.label);
            }

            mv.visitVarInsn(ALOAD, groupTypeVar);
            if (javaClassCodec) {
                mv.visitLdcInsn(getJavaType(classCase.object));
                mv.visitJumpInsn(IF_ACMPEQ, classCase.label);
            } else {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitFieldInsn(GETFIELD, genClassInternalName, "groupType_" + group.getName(),
                        "Ljava/lang/Object;");
                mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
                mv.visitJumpInsn(IFNE, classCase.label); // IFNE = if not false
            }
        }
    }
    // Default case for class hashcode switch, do lookup using schema.getGroup(Object)
    {
        Label unknownGroupIdLabel = new Label();
        mv.visitLabel(unknownHashLabel);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        Label[] groupIdLabels = new Label[labelsByGroupId.size()];
        int[] groupIds = new int[groupIdLabels.length];

        {
            int i = 0;
            for (Entry<Integer, Label> entry : labelsByGroupId.entrySet()) {
                groupIds[i] = entry.getKey();
                groupIdLabels[i] = new Label();
                i++;
            }
        }

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, genClassInternalName, "schema", "Lcom/cinnober/msgcodec/Schema;");

        mv.visitVarInsn(ALOAD, groupTypeVar);
        mv.visitMethodInsn(INVOKEVIRTUAL, SCHEMA_INAME, "getGroup",
                "(Ljava/lang/Object;)Lcom/cinnober/msgcodec/GroupDef;", false);

        // check for null result from getGroup
        Label noGroupDefLabel = new Label();
        mv.visitInsn(DUP);
        mv.visitJumpInsn(IFNULL, noGroupDefLabel);

        mv.visitMethodInsn(INVOKEVIRTUAL, GROUPDEF_INAME, "getId", "()I", false);

        // Switch on the group id
        mv.visitLookupSwitchInsn(unknownHashLabel, groupIds, groupIdLabels);

        // Cases for the group ids
        for (int i = 0; i < groupIds.length; i++) {
            mv.visitLabel(groupIdLabels[i]);
            mv.visitFrame(F_SAME, 0, null, 0, null);
            mv.visitJumpInsn(GOTO, labelsByGroupId.get(groupIds[i]));
        }

        mv.visitLabel(noGroupDefLabel);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        mv.visitInsn(POP);

        // Throw exception if there is no match on class or group id
        mv.visitLabel(unknownGroupIdLabel);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, groupTypeVar);
        mv.visitMethodInsn(INVOKESTATIC, baseclassIName, "unknownGroupType",
                "(Ljava/lang/Object;)Ljava/lang/IllegalArgumentException;", false);
        mv.visitInsn(ATHROW);
    }

    // Generate the labeled calls to group writer methods
    for (ObjectHashCodeSwitchCase<Object> hashCase : casesByHashCode.values()) {
        for (ObjectSwitchCase<Object> classCase : hashCase.cases) {
            Object groupType = classCase.object;
            GroupDef group = schema.getGroup(groupType);
            String groupDescriptor = getTypeDescriptor(groupType, javaClassCodec);
            mv.visitLabel(classCase.label);
            mv.visitFrame(F_SAME, 0, null, 0, null);
            mv.visitVarInsn(ALOAD, 0); // this
            mv.visitVarInsn(ALOAD, 1); // out
            mv.visitVarInsn(ALOAD, 2); // obj
            if (javaClassCodec) {
                mv.visitTypeInsn(CHECKCAST, getTypeInternalName(groupType, javaClassCodec));
            }
            mv.visitMethodInsn(INVOKEVIRTUAL, genClassInternalName, "writeStaticGroupWithId_" + group.getName(),
                    "(Lcom/cinnober/msgcodec/io/ByteSink;" + groupDescriptor + ")V", false);
            mv.visitInsn(RETURN);
        }
    }

    mv.visitMaxs(4, nextVar);
    mv.visitEnd();
}

From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java

License:Open Source License

protected void generateReadStaticGroup(Schema schema, ClassVisitor cv, String genClassInternalName,
        boolean javaClassCodec) {
    MethodVisitor mv = cv.visitMethod(ACC_PROTECTED, "readStaticGroup",
            "(ILcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Object;", null,
            new String[] { "java/io/IOException" });
    int nextVar = 3;
    mv.visitCode();//from  w  w  w .j ava 2  s .c  om

    Map<Integer, Label> labelsByGroupId = new TreeMap<>();
    for (GroupDef group : schema.getGroups()) {
        if (group.getId() != -1) {
            labelsByGroupId.put(group.getId(), new Label());
        }
    }
    mv.visitVarInsn(ILOAD, 1); // group id
    Label unknownGroupIdLabel = new Label();
    {
        int[] caseValues = new int[labelsByGroupId.size()];
        int i = 0;
        for (int groupId : labelsByGroupId.keySet()) {
            caseValues[i++] = groupId;
        }
        Label[] caseLabels = labelsByGroupId.values().toArray(new Label[labelsByGroupId.size()]);
        mv.visitLookupSwitchInsn(unknownGroupIdLabel, caseValues, caseLabels);
    }

    for (Map.Entry<Integer, Label> caseEntry : labelsByGroupId.entrySet()) {
        GroupDef group = schema.getGroup(caseEntry.getKey().intValue());
        Object groupType = group.getGroupType();
        String groupDescriptor = getTypeDescriptor(groupType, javaClassCodec);

        mv.visitLabel(caseEntry.getValue());
        mv.visitFrame(F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, genClassInternalName, "readStaticGroup_" + group.getName(),
                "(Lcom/cinnober/msgcodec/io/ByteSource;)" + groupDescriptor, false);
        mv.visitInsn(ARETURN);
    }
    // default case
    mv.visitLabel(unknownGroupIdLabel);
    mv.visitFrame(F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitMethodInsn(INVOKESTATIC, baseclassIName, "unknownGroupId",
            "(I)Lcom/cinnober/msgcodec/DecodeException;", false);
    mv.visitInsn(ATHROW);
    mv.visitMaxs(2, nextVar);
    mv.visitEnd();
}

From source file:com.facebook.presto.byteCode.control.LookupSwitch.java

License:Apache License

@Override
public void accept(MethodVisitor visitor) {
    int[] keys = new int[cases.size()];
    Label[] labels = new Label[cases.size()];

    int index = 0;
    for (CaseStatement caseStatement : cases) {
        keys[index] = caseStatement.getKey();
        labels[index] = caseStatement.getLabel().getLabel();
        index++;/*from w  w  w .  j av  a2  s. c  o m*/
    }
    visitor.visitLookupSwitchInsn(defaultCase.getLabel(), keys, labels);
}

From source file:com.facebook.presto.bytecode.control.SwitchStatement.java

License:Apache License

@Override
public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) {
    // build switch table
    int[] keys = new int[cases.size()];
    Label[] labels = new Label[cases.size()];

    int index = 0;
    for (CaseStatement caseStatement : cases) {
        keys[index] = caseStatement.getKey();
        labels[index] = caseStatement.getLabel().getLabel();
        index++;//  w ww. j  a v a 2 s.  c o m
    }

    // build case blocks
    BytecodeBlock block = new BytecodeBlock();

    for (CaseStatement caseStatement : cases) {
        block.visitLabel(caseStatement.getLabel()).append(caseStatement.getBody()).gotoLabel(endLabel);
    }

    // build default block
    block.visitLabel(defaultLabel);

    if (defaultBody != null) {
        block.append(defaultBody);
    }

    block.visitLabel(endLabel);

    // emit code
    expression.accept(visitor, generationContext);
    visitor.visitLookupSwitchInsn(defaultLabel.getLabel(), keys, labels);
    block.accept(visitor, generationContext);
}

From source file:com.google.gwtorm.protobuf.CodecGen.java

License:Apache License

private static void decodeMessage(final JavaColumnModel[] myFields, final MethodVisitor mv, final DecodeCGS cgs)
        throws OrmException {
    final Label nextField = new Label();
    final Label end = new Label();
    mv.visitLabel(nextField);//from w w  w. j  a  v  a 2 s . c o m

    // while (!ci.isAtEnd) { ...
    cgs.call("readTag", Type.INT_TYPE);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ISTORE, cgs.tagVar);

    cgs.push(3);
    mv.visitInsn(IUSHR);

    final Label badField = new Label();
    final int[] caseTags = new int[1 + myFields.length];
    final Label[] caseLabels = new Label[caseTags.length];

    caseTags[0] = 0;
    caseLabels[0] = new Label();

    int gaps = 0;
    for (int i = 1; i < caseTags.length; i++) {
        caseTags[i] = myFields[i - 1].getColumnID();
        caseLabels[i] = new Label();
        gaps += caseTags[i] - (caseTags[i - 1] + 1);
    }

    if (2 * gaps / 3 <= myFields.length) {
        final int min = 0;
        final int max = caseTags[caseTags.length - 1];
        final Label[] table = new Label[max + 1];
        Arrays.fill(table, badField);
        for (int idx = 0; idx < caseTags.length; idx++) {
            table[caseTags[idx]] = caseLabels[idx];
        }
        mv.visitTableSwitchInsn(min, max, badField, table);
    } else {
        mv.visitLookupSwitchInsn(badField, caseTags, caseLabels);
    }

    mv.visitLabel(caseLabels[0]);
    mv.visitJumpInsn(GOTO, end);

    for (int idx = 1; idx < caseTags.length; idx++) {
        final JavaColumnModel f = myFields[idx - 1];
        mv.visitLabel(caseLabels[idx]);
        if (f.isNested()) {
            final Label load = new Label();
            cgs.setFieldReference(f);
            cgs.pushFieldValue();
            mv.visitJumpInsn(IFNONNULL, load);
            cgs.fieldSetBegin();
            mv.visitTypeInsn(NEW, Type.getType(f.getNestedClass()).getInternalName());
            mv.visitInsn(DUP);
            mv.visitMethodInsn(INVOKESPECIAL, Type.getType(f.getNestedClass()).getInternalName(), "<init>",
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
            cgs.fieldSetEnd();

            // read the length, set a new limit, decode the message, validate
            // we stopped at the end of it as expected.
            //
            mv.visitLabel(load);
            final int limitVar = cgs.newLocal();
            cgs.pushCodedInputStream();
            cgs.call("readRawVarint32", Type.INT_TYPE);
            cgs.ncallInt("pushLimit", Type.INT_TYPE);
            mv.visitVarInsn(ISTORE, limitVar);

            decodeMessage(sort(f.getNestedColumns()), mv, cgs);

            cgs.pushCodedInputStream();
            mv.visitVarInsn(ILOAD, limitVar);
            cgs.ncallInt("popLimit", Type.VOID_TYPE);
            cgs.freeLocal(limitVar);

        } else {
            decodeScalar(mv, cgs, f);
        }
        mv.visitJumpInsn(GOTO, nextField);
    }

    // default:
    mv.visitLabel(badField);
    cgs.pushCodedInputStream();
    mv.visitVarInsn(ILOAD, cgs.tagVar);
    cgs.ncallInt("skipField", Type.BOOLEAN_TYPE);
    mv.visitInsn(POP);
    mv.visitJumpInsn(GOTO, nextField);

    mv.visitLabel(end);
    cgs.pushCodedInputStream();
    cgs.push(0);
    cgs.ncallInt("checkLastTagWas", Type.VOID_TYPE);
}

From source file:com.googlecode.d2j.converter.IR2JConverter.java

License:Apache License

private void reBuildInstructions(IrMethod ir, MethodVisitor asm) {
    asm = new LdcOptimizeAdapter(asm);
    int maxLocalIndex = 0;
    for (Local local : ir.locals) {
        maxLocalIndex = Math.max(maxLocalIndex, local._ls_index);
    }/*from   w w  w.  j a  va  2s .co m*/
    Map<String, Integer> lockMap = new HashMap<String, Integer>();
    for (Stmt st : ir.stmts) {
        switch (st.st) {
        case LABEL:
            LabelStmt labelStmt = (LabelStmt) st;
            Label label = (Label) labelStmt.tag;
            asm.visitLabel(label);
            if (labelStmt.lineNumber >= 0) {
                asm.visitLineNumber(labelStmt.lineNumber, label);
            }
            break;
        case ASSIGN: {
            E2Stmt e2 = (E2Stmt) st;
            Value v1 = e2.op1;
            Value v2 = e2.op2;
            switch (v1.vt) {
            case LOCAL:

                Local local = ((Local) v1);
                int i = local._ls_index;

                if (v2.vt == VT.LOCAL && (i == ((Local) v2)._ls_index)) {//
                    continue;
                }

                boolean skipOrg = false;
                if (v1.valueType.charAt(0) == 'I') {// check for IINC
                    if (v2.vt == VT.ADD) {
                        E2Expr e = (E2Expr) v2;
                        if ((e.op1 == local && e.op2.vt == VT.CONSTANT)
                                || (e.op2 == local && e.op1.vt == VT.CONSTANT)) {
                            int increment = (Integer) ((Constant) (e.op1 == local ? e.op2 : e.op1)).value;
                            if (increment >= Short.MIN_VALUE && increment <= Short.MAX_VALUE) {
                                asm.visitIincInsn(i, increment);
                                skipOrg = true;
                            }
                        }
                    } else if (v2.vt == VT.SUB) {
                        E2Expr e = (E2Expr) v2;
                        if (e.op1 == local && e.op2.vt == VT.CONSTANT) {
                            int increment = -(Integer) ((Constant) e.op2).value;
                            if (increment >= Short.MIN_VALUE && increment <= Short.MAX_VALUE) {
                                asm.visitIincInsn(i, increment);
                                skipOrg = true;
                            }
                        }
                    }
                }
                if (!skipOrg) {
                    accept(v2, asm);
                    if (i >= 0) {
                        asm.visitVarInsn(getOpcode(v1, ISTORE), i);
                    } else if (!v1.valueType.equals("V")) { // skip void type locals
                        switch (v1.valueType.charAt(0)) {
                        case 'J':
                        case 'D':
                            asm.visitInsn(POP2);
                            break;
                        default:
                            asm.visitInsn(POP);
                            break;
                        }
                    }
                }
                break;
            case STATIC_FIELD: {
                StaticFieldExpr fe = (StaticFieldExpr) v1;
                accept(v2, asm);
                insertI2x(v2.valueType, fe.type, asm);
                asm.visitFieldInsn(PUTSTATIC, toInternal(fe.owner), fe.name, fe.type);
                break;
            }
            case FIELD: {
                FieldExpr fe = (FieldExpr) v1;
                accept(fe.op, asm);
                accept(v2, asm);
                insertI2x(v2.valueType, fe.type, asm);
                asm.visitFieldInsn(PUTFIELD, toInternal(fe.owner), fe.name, fe.type);
                break;
            }
            case ARRAY:
                ArrayExpr ae = (ArrayExpr) v1;
                accept(ae.op1, asm);
                accept(ae.op2, asm);
                accept(v2, asm);
                String tp1 = ae.op1.valueType;
                String tp2 = ae.valueType;
                if (tp1.charAt(0) == '[') {
                    String arrayElementType = tp1.substring(1);
                    insertI2x(v2.valueType, arrayElementType, asm);
                    asm.visitInsn(getOpcode(arrayElementType, IASTORE));
                } else {
                    asm.visitInsn(getOpcode(tp2, IASTORE));
                }
                break;
            }
        }
            break;
        case IDENTITY: {
            E2Stmt e2 = (E2Stmt) st;
            if (e2.op2.vt == VT.EXCEPTION_REF) {
                int index = ((Local) e2.op1)._ls_index;
                if (index >= 0) {
                    asm.visitVarInsn(ASTORE, index);
                } else {
                    asm.visitInsn(POP);
                }
            }
        }
            break;

        case FILL_ARRAY_DATA: {
            E2Stmt e2 = (E2Stmt) st;
            Object arrayData = ((Constant) e2.getOp2()).value;
            int arraySize = Array.getLength(arrayData);
            String arrayValueType = e2.getOp1().valueType;
            String elementType;
            if (arrayValueType.charAt(0) == '[') {
                elementType = arrayValueType.substring(1);
            } else {
                elementType = "I";
            }
            int iastoreOP = getOpcode(elementType, IASTORE);
            accept(e2.getOp1(), asm);
            for (int i = 0; i < arraySize; i++) {
                asm.visitInsn(DUP);
                asm.visitLdcInsn(i);
                asm.visitLdcInsn(Array.get(arrayData, i));
                asm.visitInsn(iastoreOP);
            }
            asm.visitInsn(POP);
        }
            break;
        case GOTO:
            asm.visitJumpInsn(GOTO, (Label) ((GotoStmt) st).target.tag);
            break;
        case IF:
            reBuildJumpInstructions((IfStmt) st, asm);
            break;
        case LOCK: {
            Value v = ((UnopStmt) st).op;
            accept(v, asm);
            if (optimizeSynchronized) {
                switch (v.vt) {
                case LOCAL:
                    // FIXME do we have to disable local due to OptSyncTest ?
                    // break;
                case CONSTANT: {
                    String key;
                    if (v.vt == VT.LOCAL) {
                        key = "L" + ((Local) v)._ls_index;
                    } else {
                        key = "C" + ((Constant) v).value;
                    }
                    Integer integer = lockMap.get(key);
                    int nIndex = integer != null ? integer : ++maxLocalIndex;
                    asm.visitInsn(DUP);
                    asm.visitVarInsn(getOpcode(v, ISTORE), nIndex);
                    lockMap.put(key, nIndex);
                }
                    break;
                default:
                    throw new RuntimeException();
                }
            }
            asm.visitInsn(MONITORENTER);
        }
            break;
        case UNLOCK: {
            Value v = ((UnopStmt) st).op;
            if (optimizeSynchronized) {
                switch (v.vt) {
                case LOCAL:
                case CONSTANT: {
                    String key;
                    if (v.vt == VT.LOCAL) {
                        key = "L" + ((Local) v)._ls_index;
                    } else {
                        key = "C" + ((Constant) v).value;
                    }
                    Integer integer = lockMap.get(key);
                    if (integer != null) {
                        asm.visitVarInsn(getOpcode(v, ILOAD), integer);
                    } else {
                        accept(v, asm);
                    }
                }
                    break;
                // TODO other
                default: {
                    accept(v, asm);
                    break;
                }
                }
            } else {
                accept(v, asm);
            }
            asm.visitInsn(MONITOREXIT);
        }
            break;
        case NOP:
            break;
        case RETURN: {
            Value v = ((UnopStmt) st).op;
            accept(v, asm);
            insertI2x(v.valueType, ir.ret, asm);
            asm.visitInsn(getOpcode(v, IRETURN));
        }
            break;
        case RETURN_VOID:
            asm.visitInsn(RETURN);
            break;
        case LOOKUP_SWITCH: {
            LookupSwitchStmt lss = (LookupSwitchStmt) st;
            accept(lss.op, asm);
            Label targets[] = new Label[lss.targets.length];
            for (int i = 0; i < targets.length; i++) {
                targets[i] = (Label) lss.targets[i].tag;
            }
            asm.visitLookupSwitchInsn((Label) lss.defaultTarget.tag, lss.lookupValues, targets);
        }
            break;
        case TABLE_SWITCH: {
            TableSwitchStmt tss = (TableSwitchStmt) st;
            accept(tss.op, asm);
            Label targets[] = new Label[tss.targets.length];
            for (int i = 0; i < targets.length; i++) {
                targets[i] = (Label) tss.targets[i].tag;
            }
            asm.visitTableSwitchInsn(tss.lowIndex, tss.lowIndex + targets.length - 1,
                    (Label) tss.defaultTarget.tag, targets);
        }
            break;
        case THROW:
            accept(((UnopStmt) st).op, asm);
            asm.visitInsn(ATHROW);
            break;
        case VOID_INVOKE:
            InvokeExpr invokeExpr = (InvokeExpr) st.getOp();
            accept(invokeExpr, asm);
            String ret = invokeExpr.ret;
            if (invokeExpr.vt == VT.INVOKE_NEW) {
                asm.visitInsn(POP);
            } else if (!"V".equals(ret)) {
                switch (ret.charAt(0)) {
                case 'J':
                case 'D':
                    asm.visitInsn(POP2);
                    break;
                default:
                    asm.visitInsn(POP);
                    break;
                }
            }
            break;
        default:
            throw new RuntimeException("not support st: " + st.st);
        }

    }
}

From source file:com.googlecode.ddom.weaver.asm.MethodVisitorTee.java

License:Apache License

public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
    for (MethodVisitor visitor : visitors) {
        visitor.visitLookupSwitchInsn(dflt, keys, labels);
    }/*from   w  w  w .ja  v a  2  s  .  c  o m*/
}

From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java

License:Apache License

public void addSupportMethod() {
    int access = Opcodes.ACC_PUBLIC;
    Method m = new Method("isSupport", "(I)Z");
    MethodVisitor mv = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null);

    mv.visitCode();/* www.  j  av  a 2s  .co  m*/
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    //        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);

    int[] hashArray = new int[fixMtds.size()];
    Label[] labelArray = new Label[fixMtds.size()];
    Label l0 = new Label();
    Label l1 = new Label();
    for (int i = 0; i < fixMtds.size(); i++) {
        hashArray[i] = AcesoProguardMap.instance().getClassData(visitedClassName).getMtdIndex(fixMtds.get(i));
        labelArray[i] = l0;
    }

    mv.visitLookupSwitchInsn(l1, hashArray, labelArray);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(1, 2);
    mv.visitEnd();

    mv.visitMaxs(0, 0);
    mv.visitEnd();

}

From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.LookupSwitchInsn.java

License:Open Source License

public void toAsm(MethodVisitor mv) {
    mv.visitLookupSwitchInsn(dflt, keys, labels);
}

From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java

License:Open Source License

private static void getRawHelper(MethodVisitor mv, String className, Relation<String, Integer> hashCodeRelation,
        EnvironmentClass environmentClass, List<Integer> sortedCodes, Label returnNull) {
    int[] codes = new int[sortedCodes.size()];
    Label[] labels = new Label[sortedCodes.size()];
    for (int i = 0; i < codes.length; i++) {
        codes[i] = sortedCodes.get(i);//from w  ww.  j  a va 2s.  c  om
        Label label = new Label();
        labels[i] = label;
    }
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitLookupSwitchInsn(returnNull, codes, labels);
    for (int i = 0; i < codes.length; i++) {
        mv.visitLabel(labels[i]);
        getRawBaseCase(mv, className, hashCodeRelation, environmentClass, codes[i], returnNull);
    }
}