List of usage examples for org.objectweb.asm MethodVisitor visitLdcInsn
public void visitLdcInsn(final Object value)
From source file:com.cinnober.msgcodec.blink.NativeByteCodeGenerator.java
License:Open Source License
/** * Generate value decoding using the blink input. * * <p>Defaults to <code>readBinary[Null].</code> * * @param required true if the field is required, otherwise false. * @param mv the method visitor, not null. * @see #generateDecodeValue/*w w w. ja va 2s.c o m*/ */ @Override protected void generateDecodeBinaryValue(TypeDef.Binary type, MethodVisitor mv, boolean required) { if (Integer.compareUnsigned(type.getMaxSize(), 255) <= 0) { // inline mv.visitLdcInsn(type.getMaxSize()); if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readBinary", "(Lcom/cinnober/msgcodec/io/ByteSource;I)[B", false); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readBinaryNull", "(Lcom/cinnober/msgcodec/io/ByteSource;I)[B", false); } } else { // data area throw new UnsupportedOperationException("Not implemented yet"); // TODO: add support for data area } }
From source file:com.cinnober.msgcodec.blink.NativeByteCodeGenerator.java
License:Open Source License
/** * Generate value decoding using the blink input. * * <p>Defaults to <code>readStringUTF8[Null].</code> * * @param required true if the field is required, otherwise false. * @param mv the method visitor, not null. * @see #generateDecodeValue// w ww. ja v a 2s. c o m */ @Override protected void generateDecodeStringValue(TypeDef.StringUnicode type, MethodVisitor mv, boolean required) { if (Integer.compareUnsigned(type.getMaxSize(), 255) <= 0) { // inline mv.visitLdcInsn(type.getMaxSize()); if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readInlineStringUTF8", "(Lcom/cinnober/msgcodec/io/ByteSource;I)Ljava/lang/String;", false); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readInlineStringUTF8Null", "(Lcom/cinnober/msgcodec/io/ByteSource;I)Ljava/lang/String;", false); } } else { // data area throw new UnsupportedOperationException("Not implemented yet"); // TODO: add support for data area } }
From source file:com.e2info.helloasm.HelloAsmApp.java
License:Open Source License
public static void main(String[] args) throws IOException { String name = "HelloAsm"; int flag = ClassWriter.COMPUTE_MAXS; ClassWriter cw = new ClassWriter(flag); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null); cw.visitSource(name + ".java", null); {// w w w . j av a2 s. c o m MethodVisitor mv; mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); // we need this call to take effect ClassWriter.COMPUTE_MAXS flag. mv.visitMaxs(0, 0); mv.visitEnd(); } { MethodVisitor mv; mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); mv.visitCode(); mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("hello ASM"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.RETURN); // we need this call to take effect ClassWriter.COMPUTE_MAXS flag. mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); // build binary byte[] bin = cw.toByteArray(); // save asm trace for human readable { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); new ClassReader(bin).accept(new TraceClassVisitor(pw), 0); File f = new File(name + ".txt"); FileUtils.writeStringToFile(f, sw.toString()); } // save as calss file { File f = new File(name + ".class"); FileUtils.writeByteArrayToFile(f, bin); } }
From source file:com.enea.jcarder.agent.instrument.InstrumentationUtilities.java
License:GNU General Public License
public static void pushClassReferenceToStack(MethodVisitor mv, String className) { /*/*from w ww . java2 s . c o m*/ * It is not possible to use: * * mv.visitLdcInsn(RuleType.getType(mClassName)); * * for class versions before 49.0 (introduced with java 1.5). Therefore * we use Class.forName instead. * * TODO It might be possible to do this more efficiently by caching the * result from Class.forName. But note that adding a new field (where * the cached class object can be stored) is only possible if the class * has not already been loaded by the JVM. */ mv.visitLdcInsn(className); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); }
From source file:com.gargoylesoftware.js.nashorn.internal.codegen.types.BooleanType.java
License:Open Source License
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_INT); return BOOLEAN; }
From source file:com.gargoylesoftware.js.nashorn.internal.codegen.types.IntType.java
License:Open Source License
@Override public Type ldc(final MethodVisitor method, final Object c) { assert c instanceof Integer; final int value = ((Integer) c); switch (value) { case -1://www. jav a2s.co m method.visitInsn(ICONST_M1); break; case 0: method.visitInsn(ICONST_0); break; case 1: method.visitInsn(ICONST_1); break; case 2: method.visitInsn(ICONST_2); break; case 3: method.visitInsn(ICONST_3); break; case 4: method.visitInsn(ICONST_4); break; case 5: method.visitInsn(ICONST_5); break; default: if (value == (byte) value) { method.visitIntInsn(BIPUSH, value); } else if (value == (short) value) { method.visitIntInsn(SIPUSH, value); } else { method.visitLdcInsn(c); } break; } return Type.INT; }
From source file:com.gargoylesoftware.js.nashorn.internal.codegen.types.IntType.java
License:Open Source License
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_INT); return INT; }
From source file:com.gargoylesoftware.js.nashorn.internal.codegen.types.LongType.java
License:Open Source License
@Override public Type ldc(final MethodVisitor method, final Object c) { assert c instanceof Long; final long value = (Long) c; if (value == 0L) { method.visitInsn(LCONST_0);/* w w w . j a va2s . c o m*/ } else if (value == 1L) { method.visitInsn(LCONST_1); } else { method.visitLdcInsn(c); } return Type.LONG; }
From source file:com.gargoylesoftware.js.nashorn.internal.codegen.types.LongType.java
License:Open Source License
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_LONG); return LONG; }
From source file:com.gargoylesoftware.js.nashorn.internal.codegen.types.NumberType.java
License:Open Source License
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_DOUBLE); return NUMBER; }