List of usage examples for org.objectweb.asm Opcodes NEWARRAY
int NEWARRAY
To view the source code for org.objectweb.asm Opcodes NEWARRAY.
Click Source Link
From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java
License:BSD License
@Override public void visitIntInsn(final int opcode, final int operand) { this.mv.visitIntInsn(opcode, operand); if (opcode != Opcodes.NEWARRAY) this.stackFrame.push(OTHER); }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void interpret(IntInsnNode insn, FrameState frame, BBInfo block) { int operand = insn.operand; switch (insn.getOpcode()) { case Opcodes.BIPUSH: case Opcodes.SIPUSH: frame.stack.push(module.constants().getSmallestIntConstant(insn.operand)); break;//from w w w. java 2s . com case Opcodes.NEWARRAY: ArrayType t; switch (operand) { case Opcodes.T_BOOLEAN: t = module.types().getArrayType(boolean[].class); break; case Opcodes.T_BYTE: t = module.types().getArrayType(byte[].class); break; case Opcodes.T_CHAR: t = module.types().getArrayType(char[].class); break; case Opcodes.T_SHORT: t = module.types().getArrayType(short[].class); break; case Opcodes.T_INT: t = module.types().getArrayType(int[].class); break; case Opcodes.T_LONG: t = module.types().getArrayType(long[].class); break; case Opcodes.T_FLOAT: t = module.types().getArrayType(float[].class); break; case Opcodes.T_DOUBLE: t = module.types().getArrayType(double[].class); break; default: throw new AssertionError(operand); } NewArrayInst i = new NewArrayInst(t, frame.stack.pop()); block.block.instructions().add(i); frame.stack.push(i); break; default: throw new UnsupportedOperationException("" + insn.getOpcode()); } }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
private void emit(NewArrayInst i, InsnList insns) { ArrayType t = i.getType();/* w w w . ja v a 2 s . c om*/ if (t.getDimensions() == 1) { load(i.getOperand(0), insns); RegularType ct = t.getComponentType(); if (ct instanceof PrimitiveType) { if (ct.equals(booleanType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_BOOLEAN)); else if (ct.equals(byteType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_BYTE)); else if (ct.equals(charType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_CHAR)); else if (ct.equals(shortType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_SHORT)); else if (ct.equals(intType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT)); else if (ct.equals(longType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_LONG)); else if (ct.equals(floatType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_FLOAT)); else if (ct.equals(doubleType)) insns.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_DOUBLE)); } else { insns.add(new TypeInsnNode(Opcodes.ANEWARRAY, internalName(ct.getKlass()))); } } else { for (Value v : i.operands()) load(v, insns); insns.add(new MultiANewArrayInsnNode(t.getDescriptor(), i.getNumOperands())); } store(i, insns); }
From source file:edu.ubc.mirrors.holograms.HologramMethodGenerator.java
License:Open Source License
@Override public void visitIntInsn(int opcode, int operand) { if (opcode == Opcodes.NEWARRAY) { // Wrap with an ArrayMirror Type elementType;/*from w w w.ja va 2 s . c o m*/ switch (operand) { case Opcodes.T_BOOLEAN: elementType = Type.BOOLEAN_TYPE; break; case Opcodes.T_BYTE: elementType = Type.BYTE_TYPE; break; case Opcodes.T_CHAR: elementType = Type.CHAR_TYPE; break; case Opcodes.T_SHORT: elementType = Type.SHORT_TYPE; break; case Opcodes.T_INT: elementType = Type.INT_TYPE; break; case Opcodes.T_LONG: elementType = Type.LONG_TYPE; break; case Opcodes.T_FLOAT: elementType = Type.FLOAT_TYPE; break; case Opcodes.T_DOUBLE: elementType = Type.DOUBLE_TYPE; break; default: throw new IllegalArgumentException("Unknown type number: " + operand); } getClassMirror(elementType); swap(); invokeinterface(classMirrorType.getInternalName(), "newArray", Type.getMethodDescriptor(Type.getType(ArrayMirror.class), Type.INT_TYPE)); String arrayHologramType = "edu/ubc/mirrors/holograms/" + getSortName(elementType.getSort()) + "ArrayHologram"; invokestatic(objectHologramType.getInternalName(), "make", Type.getMethodDescriptor(hologramType, objectMirrorType)); checkcast(Type.getObjectType(arrayHologramType)); return; } super.visitIntInsn(opcode, operand); }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
private void classMapContent(ClassVisitor cv, int nr, List<TouchPointDescriptor> touchPointDescriptors) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_CLASSMAP_METHOD_NAME + "_" + nr, "(" + Type.getType(LightClassmapListener.class).toString() + ")V", null, null); mv.visitCode();//from ww w. ja v a 2s.c om mv.visitVarInsn(Opcodes.ALOAD, 0); for (TouchPointDescriptor tpd : touchPointDescriptors) { mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(tpd.getLineNumber()); if (tpd instanceof LineTouchPointDescriptor) { mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getCounterId()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodName()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodSignature()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putLineTouchPoint", "(IILjava/lang/String;Ljava/lang/String;)V"); } else if (tpd instanceof JumpTouchPointDescriptor) { mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForTrue()); mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForFalse()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putJumpTouchPoint", "(III)V"); } else if (tpd instanceof SwitchTouchPointDescriptor) { SwitchTouchPointDescriptor stpd = (SwitchTouchPointDescriptor) tpd; final String enum_sign = ((SwitchTouchPointDescriptor) tpd).getEnumType(); if (enum_sign == null) { mv.visitLdcInsn(Integer.MAX_VALUE); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, enum_sign, "values", "()[L" + enum_sign + ";"); mv.visitInsn(Opcodes.ARRAYLENGTH); } Collection<Integer> ci = stpd.getCountersForLabels(); mv.visitLdcInsn(ci.size());//Size of a new table mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); int i = 0; for (Integer counterId : ci) { mv.visitInsn(Opcodes.DUP); //First for addition of items, second ad putSwitchTouchPoint parameter (or next loop iteration) mv.visitLdcInsn(i); mv.visitLdcInsn(counterId); mv.visitInsn(Opcodes.IASTORE); i++; } mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putSwitchTouchPoint", "(II[I)V"); } } mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.AtomicArrayCodeProvider.java
License:GNU General Public License
/** * <pre>/*from w w w . ja va2 s. c o m*/ * int[] __cobertura_get_and_reset_counters() { * int[] res = new int[counters.length()]; * for(int i=0; i<counters.length(); i++){ * res[i]=counters.getAndSet(i, 0); * } * return res; * } * </pre> */ public void generateCoberturaGetAndResetCountersMethod(ClassVisitor cv, String className) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_GET_AND_RESET_COUNTERS_METHOD_NAME, "()[I", null, null); mv.visitCode(); mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicIntegerArray", "length", "()I"); mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); mv.visitVarInsn(Opcodes.ASTORE, 0); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, 1); Label l3 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l3); Label l4 = new Label(); mv.visitLabel(l4); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitInsn(Opcodes.ICONST_0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicIntegerArray", "getAndSet", "(II)I"); mv.visitInsn(Opcodes.IASTORE); mv.visitIincInsn(1, 1); mv.visitLabel(l3); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicIntegerArray", "length", "()I"); mv.visitJumpInsn(Opcodes.IF_ICMPLT, l4); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.FastArrayCodeProvider.java
License:GNU General Public License
public void generateCINITmethod(MethodVisitor mv, String className, int counters_cnt) { mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, l1); mv.visitLdcInsn(counters_cnt);//from w w w . j a v a 2s . c o m mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); generateRegisterClass(mv, className); mv.visitLabel(l1); }
From source file:net.sourceforge.cobertura.instrument.pass3.FastArrayCodeProvider.java
License:GNU General Public License
public void generateCoberturaGetAndResetCountersMethod(ClassVisitor cv, String className) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_GET_AND_RESET_COUNTERS_METHOD_NAME, "()[I", null, null); mv.visitCode();// ww w . j a v a2s . c o m /*cobertura_counters.*/ mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(Opcodes.ASTORE, 0); /*cobertura_counters.*/ mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.yrom.tools.RSymbols.java
License:Apache License
private void drainSymbols(Path file) { final String filename = file.getFileName().toString(); String typeName = filename.substring(0, filename.length() - ".class".length()); byte[] bytes; try {//ww w. j a va2 s .c om bytes = Files.readAllBytes(file); } catch (IOException e) { throw new UncheckedIOException(e); } ClassVisitor visitor = new ClassVisitor(Opcodes.ASM5) { @Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { // read constant value if (value instanceof Integer) { String key = typeName + '.' + name; Integer old = symbols.get(key); if (old != null && !old.equals(value)) { throw new IllegalStateException("Value of " + key + " mismatched! " + "Excepted 0x" + Integer.toHexString(old) + " but was 0x" + Integer.toHexString((Integer) value)); } else { symbols.put(key, (Integer) value); } } return null; } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (access == Opcodes.ACC_STATIC && "<clinit>".equals(name)) { return new MethodVisitor(Opcodes.ASM5) { int[] current = null; LinkedList<Integer> intStack = new LinkedList<>(); @Override public void visitIntInsn(int opcode, int operand) { if (opcode == Opcodes.NEWARRAY && operand == Opcodes.T_INT) { current = new int[intStack.pop()]; } else if (opcode == Opcodes.BIPUSH) { intStack.push(operand); } } @Override public void visitLdcInsn(Object cst) { if (cst instanceof Integer) { intStack.push((Integer) cst); } } @Override public void visitInsn(int opcode) { if (opcode >= Opcodes.ICONST_0 && opcode <= Opcodes.ICONST_5) { intStack.push(opcode - Opcodes.ICONST_0); } else if (opcode == Opcodes.IASTORE) { int value = intStack.pop(); int index = intStack.pop(); current[index] = value; } } @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { if (opcode == Opcodes.PUTSTATIC) { int[] old = styleables.get(name); if (old != null && old.length != current.length && !Arrays.equals(old, current)) { throw new IllegalStateException("Value of styleable." + name + " mismatched! " + "Excepted " + Arrays.toString(old) + " but was " + Arrays.toString(current)); } else { styleables.put(name, current); } current = null; intStack.clear(); } } }; } return null; } }; new ClassReader(bytes).accept(visitor, SKIP_DEBUG | SKIP_FRAMES); }
From source file:net.yrom.tools.WriteStyleablesProcessor.java
License:Apache License
private void writeClinit(ClassWriter writer) { Map<String, int[]> styleables = symbols.getStyleables(); MethodVisitor clinit = writer.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); clinit.visitCode();// w w w . j a v a 2 s . c o m for (Map.Entry<String, int[]> entry : styleables.entrySet()) { final String field = entry.getKey(); final int[] value = entry.getValue(); final int length = value.length; pushInt(clinit, length); clinit.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); for (int i = 0; i < length; i++) { clinit.visitInsn(Opcodes.DUP); // dup pushInt(clinit, i); pushInt(clinit, value[i]); clinit.visitInsn(Opcodes.IASTORE); // iastore } clinit.visitFieldInsn(Opcodes.PUTSTATIC, RSymbols.R_STYLEABLES_CLASS_NAME, field, "[I"); } clinit.visitInsn(Opcodes.RETURN); clinit.visitMaxs(0, 0); // auto compute clinit.visitEnd(); }