Example usage for org.objectweb.asm MethodVisitor visitMaxs

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

Introduction

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

Prototype

public void visitMaxs(final int maxStack, final int maxLocals) 

Source Link

Document

Visits the maximum stack size and the maximum number of local variables of the method.

Usage

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementGetString(final String methodName, final String returnValue) {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, methodName,
            Type.getMethodDescriptor(string, new Type[] {}), null, null);
    mv.visitCode();/*from   w  w w  .  j a  va2 s . c om*/
    mv.visitLdcInsn(returnValue);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementGetObjectCodec() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "getObjectCodec",
            Type.getMethodDescriptor(protobufCodec, new Type[] {}), null, null);
    mv.visitCode();/*from w ww.j a v  a 2  s .c o m*/
    mv.visitFieldInsn(GETSTATIC, implTypeName, F_OBJECT_CODEC, protobufCodec.getDescriptor());
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementGetIndexes() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "getIndexes",
            Type.getMethodDescriptor(Type.getType(IndexFunction[].class), new Type[] {}), null, null);
    mv.visitCode();//from w  w w. j  ava 2 s  .c  o m
    mv.visitFieldInsn(GETSTATIC, implTypeName, F_INDEXES, Type.getType(IndexFunction[].class).getDescriptor());
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementPrimaryKey() {
    final ColumnModel f = key.getField();
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "primaryKey",
            Type.getMethodDescriptor(ormKey, new Type[] { object }), null, null);
    mv.visitCode();/* w w w.j  av a 2  s . c om*/
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(CHECKCAST, entityType.getInternalName());
    mv.visitFieldInsn(GETFIELD, entityType.getInternalName(), f.getFieldName(),
            CodeGenSupport.toType(f).getDescriptor());
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementEncodePrimaryKey() throws OrmException {
    final List<ColumnModel> pCols = Collections.singletonList(key.getField());
    final Type argType = CodeGenSupport.toType(key.getField());
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "encodePrimaryKey",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { indexKeyBuilder, ormKey }), null, null);
    mv.visitCode();/*  w ww .jav a 2  s  .  c o m*/

    mv.visitVarInsn(ALOAD, 2);
    mv.visitTypeInsn(CHECKCAST, argType.getInternalName());
    mv.visitVarInsn(ASTORE, 2);

    final QueryCGS cgs = new QueryCGS(mv, new Type[] { argType }, pCols, new int[] { 2 }, 1);
    for (ColumnModel f : pCols) {
        IndexFunctionGen.encodeField(new QueryModel.OrderBy(f, false), mv, cgs);
    }

    mv.visitInsn(RETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementKeyQuery(KeyModel key) {
    final Type keyType = CodeGenSupport.toType(key.getField());
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, key.getName(),
            Type.getMethodDescriptor(entityType, new Type[] { keyType }), null,
            new String[] { Type.getType(OrmException.class).getInternalName() });
    mv.visitCode();//from w  w w. j a va 2s .com

    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, accessType.getInternalName(), "get",
            Type.getMethodDescriptor(object, new Type[] { ormKey }));
    mv.visitTypeInsn(CHECKCAST, entityType.getInternalName());

    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementQuery(final QueryModel info) throws OrmException {
    final List<ColumnModel> pCols = info.getParameters();
    final boolean hasLimitParam = info.hasLimitParameter();
    final Type[] pTypes = new Type[pCols.size() + (hasLimitParam ? 1 : 0)];
    final int[] pVars = new int[pTypes.length];
    int nextVar = 1;
    for (int i = 0; i < pCols.size(); i++) {
        pTypes[i] = CodeGenSupport.toType(pCols.get(i));
        pVars[i] = nextVar;//from www .j av a2s.c om
        nextVar += pTypes[i].getSize();
    }
    if (hasLimitParam) {
        pTypes[pTypes.length - 1] = Type.INT_TYPE;
        pVars[pTypes.length - 1] = nextVar;
        nextVar += Type.INT_TYPE.getSize();
    }

    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, info.getName(),
            Type.getMethodDescriptor(resultSet, pTypes), null, new String[] { ormException.getInternalName() });
    mv.visitCode();

    final List<Tree> ops = compareOpsOnly(info.getParseTree());

    // Generate fromKey
    //
    final int fromBuf = nextVar++;
    mv.visitTypeInsn(NEW, indexKeyBuilder.getInternalName());
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, indexKeyBuilder.getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
    mv.visitVarInsn(ASTORE, fromBuf);

    QueryCGS cgs = new QueryCGS(mv, pTypes, pCols, pVars, fromBuf);
    encodeFields(info, ops, mv, cgs, true /* fromKey */);

    // Generate toKey
    //
    final int toBuf = nextVar++;
    mv.visitTypeInsn(NEW, indexKeyBuilder.getInternalName());
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, indexKeyBuilder.getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
    mv.visitVarInsn(ASTORE, toBuf);

    cgs = new QueryCGS(mv, pTypes, pCols, pVars, toBuf);
    encodeFields(info, ops, mv, cgs, false /* fromKey */);
    cgs.infinity();

    // Make the scan call
    //
    mv.visitVarInsn(ALOAD, 0);
    if (needsIndexFunction(info)) {
        mv.visitFieldInsn(GETSTATIC, implTypeName, "index_" + info.getName(), indexFunction.getDescriptor());
    }

    mv.visitVarInsn(ALOAD, fromBuf);
    mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), "toByteArray",
            Type.getMethodDescriptor(byteArray, new Type[] {}));

    mv.visitVarInsn(ALOAD, toBuf);
    mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), "toByteArray",
            Type.getMethodDescriptor(byteArray, new Type[] {}));

    // Set the limit on the number of results.
    //
    if (info.hasLimit()) {
        if (hasLimitParam) {
            mv.visitVarInsn(ILOAD, pVars[pTypes.length - 1]);
        } else {
            cgs.push(info.getStaticLimit());
        }
    } else {
        cgs.push(0);
    }

    // Only keep order if there is an order by clause present
    //
    cgs.push(info.hasOrderBy() ? 1 : 0);

    if (needsIndexFunction(info)) {
        mv.visitMethodInsn(INVOKEVIRTUAL, accessType.getInternalName(), "scanIndex",
                Type.getMethodDescriptor(resultSet,
                        new Type[] { indexFunction, byteArray, byteArray, Type.INT_TYPE, Type.BOOLEAN_TYPE }));
    } else {
        // No where and no order by clause? Use the primary key instead.
        //
        mv.visitMethodInsn(INVOKEVIRTUAL, accessType.getInternalName(), "scanPrimaryKey",
                Type.getMethodDescriptor(resultSet,
                        new Type[] { byteArray, byteArray, Type.INT_TYPE, Type.BOOLEAN_TYPE }));
    }

    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.IndexFunctionGen.java

License:Apache License

private void implementConstructor() {
    final String consName = "<init>";
    final String consDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {});
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, consName, consDesc, null, null);
    mv.visitCode();//from   ww  w  .  ja  v a 2 s.c o m

    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, superTypeName, consName, consDesc);

    mv.visitInsn(RETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.IndexFunctionGen.java

License:Apache License

private void implementGetName() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "getName",
            Type.getMethodDescriptor(Type.getType(String.class), new Type[] {}), null, null);
    mv.visitCode();//from   ww w. ja  va 2 s.c  o m
    mv.visitLdcInsn(query.getName());
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.IndexFunctionGen.java

License:Apache License

private void implementIncludes() throws OrmException {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "includes",
            Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { object }), null, null);
    mv.visitCode();//from  w  w  w .  j  av  a2 s  .  c  o  m
    final IncludeCGS cgs = new IncludeCGS(mv);
    cgs.setEntityType(pojoType);

    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(CHECKCAST, pojoType.getInternalName());
    mv.visitVarInsn(ASTORE, 1);

    Set<ColumnModel> checked = new HashSet<ColumnModel>();
    for (QueryModel.OrderBy orderby : myFields) {
        checkNotNullFields(Collections.singleton(orderby.column), checked, mv, cgs);
    }

    final Tree parseTree = query.getParseTree();
    if (parseTree != null) {
        checkConstants(parseTree, mv, cgs);
    }

    cgs.push(1);
    mv.visitInsn(IRETURN);

    mv.visitLabel(cgs.no);
    cgs.push(0);
    mv.visitInsn(IRETURN);

    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}