List of usage examples for org.objectweb.asm MethodVisitor visitVarInsn
public void visitVarInsn(final int opcode, final int var)
From source file:com.google.gwtorm.nosql.IndexFunctionGen.java
License:Apache License
private void implementEncode() throws OrmException { final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "encode", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { indexKeyBuilder, object }), null, null); mv.visitCode();//from ww w . j a v a2s .c o m final EncodeCGS cgs = new EncodeCGS(mv); cgs.setEntityType(pojoType); mv.visitVarInsn(ALOAD, 2); mv.visitTypeInsn(CHECKCAST, pojoType.getInternalName()); mv.visitVarInsn(ASTORE, 2); encodeFields(myFields, mv, cgs); mv.visitInsn(RETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
From source file:com.google.gwtorm.protobuf.CodecGen.java
License:Apache License
private void implementSizeof() throws OrmException { final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "sizeof", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { object }), null, new String[] {}); mv.visitCode();//from w w w . j a v a 2 s . c om final SizeofCGS cgs = new SizeofCGS(mv); cgs.setEntityType(pojoType); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, pojoType.getInternalName()); mv.visitVarInsn(ASTORE, 1); cgs.push(0); mv.visitVarInsn(ISTORE, cgs.sizeVar); sizeofMessage(myFields, mv, cgs); mv.visitVarInsn(ILOAD, cgs.sizeVar); mv.visitInsn(IRETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
From source file:com.google.gwtorm.protobuf.CodecGen.java
License:Apache License
private static void sizeofMessage(final JavaColumnModel[] myFields, final MethodVisitor mv, final SizeofCGS cgs) throws OrmException { for (final JavaColumnModel f : myFields) { if (f.isNested()) { final Label end = new Label(); cgs.setFieldReference(f);// w w w .j av a 2s . com cgs.pushFieldValue(); mv.visitJumpInsn(IFNULL, end); final int oldVar = cgs.sizeVar; final int msgVar = cgs.newLocal(); cgs.sizeVar = msgVar; cgs.push(0); mv.visitVarInsn(ISTORE, cgs.sizeVar); sizeofMessage(sort(f.getNestedColumns()), mv, cgs); cgs.sizeVar = oldVar; cgs.push(f.getColumnID()); cgs.inc("computeTagSize", Type.INT_TYPE); mv.visitVarInsn(ILOAD, msgVar); cgs.inc("computeRawVarint32Size", Type.INT_TYPE); mv.visitVarInsn(ILOAD, msgVar); cgs.inc(); cgs.freeLocal(msgVar); mv.visitLabel(end); } else { sizeofScalar(mv, cgs, f); } } }
From source file:com.google.gwtorm.protobuf.CodecGen.java
License:Apache License
private void implementEncode() throws OrmException { final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "encode", Type.getMethodDescriptor(byteString, new Type[] { object }), null, new String[] {}); mv.visitCode();/*from w w w . j a v a 2 s . com*/ final EncodeCGS cgs = new EncodeCGS(mv); cgs.setEntityType(pojoType); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, pojoType.getInternalName()); mv.visitVarInsn(ASTORE, 1); encodeMessage(myFields, mv, cgs); mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
From source file:com.google.gwtorm.protobuf.CodecGen.java
License:Apache License
private static void encodeMessage(final JavaColumnModel[] myFields, final MethodVisitor mv, final EncodeCGS cgs) throws OrmException { final int oldVar = cgs.codedOutputStreamVar; cgs.codedOutputStreamVar = cgs.newLocal(); final int strVar = cgs.newLocal(); mv.visitMethodInsn(INVOKESTATIC, byteString.getInternalName(), "newOutput", Type.getMethodDescriptor(byteStringOutput, new Type[] {})); mv.visitVarInsn(ASTORE, strVar); mv.visitVarInsn(ALOAD, strVar);/*from www . j a v a 2 s .c o m*/ mv.visitMethodInsn(INVOKESTATIC, codedOutputStream.getInternalName(), "newInstance", Type.getMethodDescriptor(codedOutputStream, new Type[] { Type.getType(OutputStream.class) })); mv.visitVarInsn(ASTORE, cgs.codedOutputStreamVar); for (final JavaColumnModel f : myFields) { if (f.isNested()) { final Label end = new Label(); cgs.setFieldReference(f); cgs.pushFieldValue(); mv.visitJumpInsn(IFNULL, end); final int v = cgs.newLocal(); encodeMessage(sort(f.getNestedColumns()), mv, cgs); mv.visitVarInsn(ASTORE, v); mv.visitVarInsn(ALOAD, v); mv.visitMethodInsn(INVOKEVIRTUAL, byteString.getInternalName(), "size", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] {})); mv.visitJumpInsn(IFEQ, end); cgs.pushCodedOutputStream(); cgs.push(f.getColumnID()); mv.visitVarInsn(ALOAD, v); cgs.write("writeBytes", byteString); cgs.freeLocal(v); mv.visitLabel(end); } else { encodeScalar(mv, cgs, f); } } cgs.pushCodedOutputStream(); mv.visitMethodInsn(INVOKEVIRTUAL, codedOutputStream.getInternalName(), "flush", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {})); cgs.freeLocal(cgs.codedOutputStreamVar); cgs.codedOutputStreamVar = oldVar; mv.visitVarInsn(ALOAD, strVar); mv.visitMethodInsn(INVOKEVIRTUAL, byteStringOutput.getInternalName(), "toByteString", Type.getMethodDescriptor(byteString, new Type[] {})); cgs.freeLocal(strVar); }
From source file:com.google.gwtorm.protobuf.CodecGen.java
License:Apache License
private void implementDecode() throws OrmException { final Type retType = object; final MethodVisitor mv = cw.visitMethod(ACC_PROTECTED, "decode", Type.getMethodDescriptor(retType, new Type[] { codedInputStream }), null, new String[] {}); mv.visitCode();/*from w w w . j ava 2s .co m*/ final DecodeCGS cgs = new DecodeCGS(mv); cgs.setEntityType(pojoType); mv.visitTypeInsn(NEW, pojoType.getInternalName()); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, pojoType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {})); mv.visitVarInsn(ASTORE, cgs.objVar); final int tagVar = cgs.newLocal(); decodeMessage(myFields, mv, cgs); cgs.pushEntity(); mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
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);/*www. j a v a 2s. 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.google.gwtorm.server.SchemaConstructorGen.java
License:Apache License
private void implementConstructor() { final Type ft = Type.getType(schemaArg.getClass()); final String consName = "<init>"; final String consDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { ft }); final MethodVisitor mv; mv = cw.visitMethod(ACC_PUBLIC, consName, consDesc, null, null); mv.visitCode();//from ww w . j a v a2 s . c o m mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), consName, Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {})); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, implTypeName, CTX, ft.getDescriptor()); mv.visitInsn(RETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
From source file:com.google.gwtorm.server.SchemaConstructorGen.java
License:Apache License
private void implementNewInstance() { final Type ft = Type.getType(schemaArg.getClass()); final String typeName = Type.getType(schemaImpl).getInternalName(); final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "open", Type.getMethodDescriptor(Type.getType(Schema.class), new Type[] {}), null, null); mv.visitCode();/*from ww w . ja v a 2 s.co m*/ Constructor<?> c = schemaImpl.getDeclaredConstructors()[0]; Type argType = Type.getType(c.getParameterTypes()[0]); mv.visitTypeInsn(NEW, typeName); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, implTypeName, CTX, ft.getDescriptor()); mv.visitMethodInsn(INVOKESPECIAL, typeName, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { argType })); mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
From source file:com.google.gwtorm.server.SchemaGen.java
License:Apache License
private void implementConstructor() { final String consName = "<init>"; final Type superType = Type.getType(schemaSuperClass); final Type dbType = Type.getType(databaseClass); final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, consName, Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { dbType }), null, null); mv.visitCode();// w w w . ja va 2 s .com mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, superType.getInternalName(), consName, Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.getType(schemaSuperClass.getDeclaredConstructors()[0].getParameterTypes()[0]) })); for (final RelationGen info : relations) { mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, info.accessType.getInternalName()); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, info.accessType.getInternalName(), consName, Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { superType })); mv.visitFieldInsn(PUTFIELD, implTypeName, info.getAccessInstanceFieldName(), info.accessType.getDescriptor()); } mv.visitInsn(RETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }