Example usage for org.objectweb.asm Opcodes ANEWARRAY

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

Introduction

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

Prototype

int ANEWARRAY

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

Click Source Link

Usage

From source file:com.codename1.tools.translator.bytecodes.TypeInstruction.java

License:Open Source License

@Override
public void addDependencies(List<String> dependencyList) {
    String t = type.replace('.', '_').replace('/', '_').replace('$', '_');
    t = unarray(t);//from www.j a  va 2  s . c o m
    actualType = t;
    if (t != null && !dependencyList.contains(t)) {
        dependencyList.add(t);
    }
    if (actualType == null) {
        // primitive array
        switch (type.charAt(type.length() - 1)) {
        case 'I':
            actualType = "JAVA_INT";
            break;
        case 'J':
            actualType = "JAVA_LONG";
            break;
        case 'B':
            actualType = "JAVA_BYTE";
            break;
        case 'S':
            actualType = "JAVA_SHORT";
            break;
        case 'F':
            actualType = "JAVA_FLOAT";
            break;
        case 'D':
            actualType = "JAVA_DOUBLE";
            break;
        case 'Z':
            actualType = "JAVA_BOOLEAN";
            break;
        case 'C':
            actualType = "JAVA_CHAR";
            break;
        }
    }
    if (opcode == Opcodes.ANEWARRAY) {
        if (type.startsWith("[")) {
            int dim = 2;
            String tt = type.substring(1);
            while (tt.startsWith("[")) {
                tt = tt.substring(1);
                dim++;
            }
            ByteCodeClass.addArrayType(actualType, dim);
            return;
        }
        ByteCodeClass.addArrayType(actualType, 1);
    }
}

From source file:com.codename1.tools.translator.bytecodes.TypeInstruction.java

License:Open Source License

@Override
public void appendInstruction(StringBuilder b, List<Instruction> l) {
    type = type.replace('.', '_').replace('/', '_').replace('$', '_');
    b.append("    ");
    switch (opcode) {
    case Opcodes.NEW:
        b.append("PUSH_POINTER(__NEW_");
        b.append(type);/*  w w  w.j  a v  a 2 s .  c om*/
        b.append("(threadStateData)); /* NEW */\n");
        break;
    case Opcodes.ANEWARRAY:
        if (type.startsWith("[")) {
            int dim = 2;
            String t = type.substring(1);
            while (t.startsWith("[")) {
                t = t.substring(1);
                dim++;
            }

            b.append(" SP--;\n    PUSH_POINTER(allocArray(threadStateData, (*SP).data.i, &class_array");
            b.append(dim);
            b.append("__");
            b.append(actualType);
            b.append(", sizeof(JAVA_OBJECT), ");
            b.append(dim);
            b.append("));\n    SP[-1].data.o->__codenameOneParentClsReference = &class_array");
            b.append(dim);
            b.append("__");
            b.append(actualType);
            b.append("; /* ANEWARRAY multi */\n");
            break;
        }
        b.append("SP--;\n    PUSH_POINTER(__NEW_ARRAY_");
        b.append(actualType);
        b.append("(threadStateData, SP[0].data.i));\n");
        break;
    case Opcodes.CHECKCAST:
        b.append("BC_CHECKCAST(");
        b.append(type);
        b.append(");\n");
        break;
    case Opcodes.INSTANCEOF:
        int pos = type.indexOf('[');
        if (pos > -1) {
            int count = 1;
            while (type.charAt(pos + 1) == '[') {
                count++;
                pos++;
            }
            b.append("BC_INSTANCEOF(cn1_array_");
            b.append(count);
            b.append("_id_");
            b.append(actualType);
        } else {
            b.append("BC_INSTANCEOF(cn1_class_id_");
            b.append(actualType);
        }
        b.append(");\n");
        break;
    }
}

From source file:com.devexperts.aprof.transformer.AbstractMethodVisitor.java

License:Open Source License

@Override
public void visitTypeInsn(final int opcode, final String desc) {
    switch (opcode) {
    case Opcodes.NEW:
        visitAllocateBefore(desc);/*www.j a va  2s. c  om*/
        mv.visitTypeInsn(opcode, desc);
        visitAllocateAfter(desc);
        break;
    case Opcodes.ANEWARRAY:
        if (!context.isIntrinsicArraysCopyOf()) {
            String arrayDesc = desc.startsWith("[") ? "[" + desc : "[L" + desc + ";";
            visitAllocateArrayBefore(arrayDesc);
            mv.visitTypeInsn(opcode, desc);
            visitAllocateArrayAfter(arrayDesc);
            break;
        }
        // ELSE -- FALLS THROUGH !!!
    default:
        mv.visitTypeInsn(opcode, desc);
    }
}

From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java

License:Open Source License

public void anewarray(Type type) {
    methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, type.internalName());
    stack.newarray(type);
}

From source file:com.github.malamut2.low.AllocationMethodAdapter.java

License:Apache License

/**
 * new and anewarray bytecodes take a String operand for the type of
 * the object or array element so we hook them here.  Note that new doesn't
 * actually result in any instrumentation here; we just do a bit of
 * book-keeping and do the instrumentation following the constructor call
 * (because we're not allowed to touch the object until it is initialized).
 *///from  w  w w . ja  v  a  2 s. c o  m
@Override
public void visitTypeInsn(int opcode, String typeName) {
    if (opcode == Opcodes.NEW) {
        // We can't actually tag this object right after allocation because it
        // must be initialized with a ctor before we can touch it (Verifier
        // enforces this).  Instead, we just note it and tag following
        // initialization.
        super.visitTypeInsn(opcode, typeName);
        ++outstandingAllocs;
    } else if (opcode == Opcodes.ANEWARRAY) {
        super.visitInsn(Opcodes.DUP);
        super.visitTypeInsn(opcode, typeName);
        invokeRecordAllocation(typeName);
    } else {
        super.visitTypeInsn(opcode, typeName);
    }
}

From source file:com.github.wreulicke.bean.validation.ASMMethodParameterValidationInjector.java

License:Open Source License

private void inject(MethodNode node, ClassNode clazzNode) {
    if (Modifier.isStatic(node.access) || Modifier.isAbstract(node.access) || Modifier.isAbstract(node.access)
            || "<init>".equals(node.name) || "<clinit>".equals(node.name)) {
        return;//from www.j  a  v a  2  s . c  o m
    }

    InsnList list = new InsnList();
    int index = node.localVariables.size();
    list.add(new MethodInsnNode(INVOKESTATIC, "javax/validation/Validation", "buildDefaultValidatorFactory",
            "()Ljavax/validation/ValidatorFactory;", false));
    list.add(new MethodInsnNode(INVOKEINTERFACE, "javax/validation/ValidatorFactory", "getValidator",
            "()Ljavax/validation/Validator;", true));
    list.add(new MethodInsnNode(INVOKEINTERFACE, "javax/validation/Validator", "forExecutables",
            "()Ljavax/validation/executable/ExecutableValidator;", true));

    list.add(new VarInsnNode(Opcodes.ASTORE, index));
    list.add(new VarInsnNode(Opcodes.ALOAD, index));
    list.add(new VarInsnNode(Opcodes.ALOAD, 0));

    list.add(new LdcInsnNode(Type.getType("L" + clazzNode.name + ";")));
    list.add(new LdcInsnNode(node.name));

    @SuppressWarnings("unchecked")
    List<LocalVariableNode> variables = node.localVariables;
    Type[] args = Type.getArgumentTypes(node.desc);

    list.add(new LdcInsnNode(args.length));
    list.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Class"));

    for (int i = 0; i < args.length; i++) {
        int paramIndex = 1 + i;
        list.add(new InsnNode(Opcodes.DUP));
        list.add(new LdcInsnNode(i));
        list.add(new LdcInsnNode(Type.getType(variables.get(paramIndex).desc)));
        list.add(new InsnNode(Opcodes.AASTORE));
    }

    list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getMethod",
            "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false));

    list.add(new LdcInsnNode(args.length));
    list.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"));
    for (int i = 0; i < args.length; i++) {
        int paramIndex = i + 1;
        list.add(new InsnNode(Opcodes.DUP));
        list.add(new LdcInsnNode(i));
        list.add(new VarInsnNode(Opcodes.ALOAD, paramIndex));
        list.add(new InsnNode(Opcodes.AASTORE));
    }
    list.add(new InsnNode(Opcodes.ICONST_0));
    list.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Class"));
    list.add(new MethodInsnNode(INVOKEINTERFACE, "javax/validation/executable/ExecutableValidator",
            "validateParameters",
            "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/util/Set;",
            true));
    list.add(new MethodInsnNode(INVOKESTATIC, "com/github/wreulicke/bean/validation/Constraints",
            "throwIfNeeded", "(Ljava/util/Set;)V", false));
    node.instructions.insert(list);
}

From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java

License:Open Source License

@Override
public void visitTypeInsn(int opcode, String type) {
    String descriptor = convertToDescriptor(type);
    switch (opcode) {
    case Opcodes.NEW:
        pushDescriptor(descriptor); // This should be UNINITIALIZED(label). Okay for type inference.
        break;/*from  www.  j a va 2  s .  c o  m*/
    case Opcodes.ANEWARRAY:
        pop();
        pushDescriptor('[' + descriptor);
        break;
    case Opcodes.CHECKCAST:
        pop();
        pushDescriptor(descriptor);
        break;
    case Opcodes.INSTANCEOF:
        pop();
        push(InferredType.INT);
        break;
    default:
        throw new RuntimeException("Unhandled opcode " + opcode);
    }
    super.visitTypeInsn(opcode, type);
}

From source file:com.google.monitoring.runtime.instrumentation.adapters.AllocationMethodAdapter.java

License:Apache License

/**
 * new and anewarray bytecodes take a String operand for the type of
 * the object or array element so we hook them here.  Note that new doesn't
 * actually result in any instrumentation here; we just do a bit of
 * book-keeping and do the instrumentation following the constructor call
 * (because we're not allowed to touch the object until it is initialized).
 *///from  w ww  .  ja va  2  s. c o m
@Override
public void visitTypeInsn(final int opcode, final String typeName) {
    if (opcode == Opcodes.NEW) {
        // We can't actually tag this object right after allocation because it
        // must be initialized with a ctor before we can touch it (Verifier
        // enforces this).  Instead, we just note it and tag following
        // initialization.
        super.visitTypeInsn(opcode, typeName);
        ++outstandingAllocs;
    } else if (opcode == Opcodes.ANEWARRAY) {
        super.visitInsn(Opcodes.DUP);
        super.visitTypeInsn(opcode, typeName);
        invokeRecordAllocation(typeName);
    } else {
        super.visitTypeInsn(opcode, typeName);
    }
}

From source file:com.google.monitoring.runtime.instrumentation.adapters.EscapeMethodAdapter.java

License:Apache License

/**
 * new and anewarray bytecodes take a String operand for the type of
 * the object or array element so we hook them here.  Note that new doesn't
 * actually result in any instrumentation here; we just do a bit of
 * book-keeping and do the instrumentation following the constructor call
 * (because we're not allowed to touch the object until it is initialized).
 *///from w  ww  .j a v a  2 s. co  m
@Override
public void visitTypeInsn(int opcode, String typeName) {
    if (opcode == Opcodes.NEW) {
        // We can't actually tag this object right after allocation because it
        // must be initialized with a ctor before we can touch it (Verifier
        // enforces this).  Instead, we just note it and tag following
        // initialization.
        invokeStart();
        super.visitTypeInsn(opcode, typeName);
        ++outstandingAllocs;
    } else if (opcode == Opcodes.ANEWARRAY) {
        invokeStart();
        super.visitInsn(Opcodes.DUP);
        super.visitTypeInsn(opcode, typeName);
        invokeRecordAllocation(typeName);
    } else {
        super.visitTypeInsn(opcode, typeName);
    }
}

From source file:com.google.test.metric.asm.MethodVisitorBuilder.java

License:Apache License

public void visitTypeInsn(final int opcode, final String desc) {
    if (desc.length() == 1) {
        throw new IllegalStateException("WARNING! I don't expect primitive types:" + desc);
    }/*ww  w .  j ava2  s  .  c  o  m*/
    final Type type = desc.contains(";") ? JavaType.fromDesc(desc) : JavaType.fromJava(desc);
    recorder.add(new Runnable() {
        public void run() {
            switch (opcode) {
            case Opcodes.NEW:
                Constant constant = new Constant("new", type);
                block.addOp(new Load(lineNumber, constant));
                break;
            case Opcodes.NEWARRAY:
            case Opcodes.ANEWARRAY:
                block.addOp(new Transform(lineNumber, "newarray", JavaType.INT, null, type.toArray()));
                break;
            case Opcodes.INSTANCEOF:
                block.addOp(new Transform(lineNumber, "instanceof", JavaType.OBJECT, null, JavaType.INT));
                break;
            case Opcodes.CHECKCAST:
                block.addOp(new Transform(lineNumber, "checkcast", type, null, type));
                break;
            default:
                throw new UnsupportedOperationException("" + opcode);
            }
        }
    });
}