Package org.objectweb.asm

Examples of org.objectweb.asm.CodeVisitor


        final String methodDesc = "("
            + getJVMType(PersistentObjectItf.class)
            + "[J"
            + getJVMType(Object.class)
            + ")" + getJVMType(StateItf.class);
        CodeVisitor cv = gc.cv.visitMethod(ACC_PUBLIC, "writeIntention",
                methodDesc, null, null);
        //StateItf sa = super.writeIntention(sp, fields, thinLock);
        cv.visitVarInsn(ALOAD, 0);
        cv.visitVarInsn(ALOAD, 1);
        cv.visitVarInsn(ALOAD, 2);
        cv.visitVarInsn(ALOAD, 3);
        cv.visitMethodInsn(INVOKESPECIAL, gc.superClassJCN, "writeIntention", methodDesc);
        cv.visitVarInsn(ASTORE, 4);

        //if (fields == null) {
        cv.visitVarInsn(ALOAD, 2);
        Label labelElse = new Label();
        cv.visitJumpInsn(IFNONNULL, labelElse);
        Label labelEnd = new Label();
        {
            //sa.indexFieldModified(0xffffffff, false);
            cv.visitVarInsn(ALOAD, 4);
            cv.visitLdcInsn(new Integer(0xffffffff));
            cv.visitInsn(ICONST_0);
            cv.visitMethodInsn(INVOKEINTERFACE,
                    getJVMClassName(StateItf.class),
                    "indexFieldModified", "(IZ)V");
            cv.visitJumpInsn(GOTO, labelEnd);
        }
        cv.visitLabel(labelElse);
        {
            for (int ucIdx = 0; ucIdx < gc.userCacheNames.length; ucIdx++) {
                String ucn = gc.userCacheNames[ucIdx];
                List fields = (List) gc.ucn2sfs.get(ucn);
                for(Iterator itf = fields.iterator(); itf.hasNext();) {
                    SpeedoField sf = (SpeedoField) itf.next();
                    //if ((fields[${f.jormFieldIdLongPos}] & ${f.jormFieldId}L) != 0) {
                    cv.visitVarInsn(ALOAD, 2);
                    Util.visitIntConstant(cv, sf.number / 64);
                    cv.visitInsn(LALOAD);
                    Util.visitLongConstant(cv, 1L << (sf.number % 64));
                    cv.visitInsn(LAND);
                    cv.visitInsn(LCONST_0);
                    cv.visitInsn(LCMP);
                    Label labelNext = new Label();
                    cv.visitJumpInsn(IFEQ, labelNext);
                    {
                        //sa.indexFieldModified(${ucn}_USER_CACHE_ID, false);
                        cv.visitVarInsn(ALOAD, 4);
                        Util.visitIntConstant(cv, ucIdx);
                        cv.visitInsn(ICONST_0);
                        cv.visitMethodInsn(INVOKEINTERFACE,
                                getJVMClassName(StateItf.class),
                                "indexFieldModified", "(IZ)V");
                    }
                    cv.visitLabel(labelNext);
                }
            }
        }
        cv.visitLabel(labelEnd);
        //return sa;
        cv.visitVarInsn(ALOAD, 4);
        cv.visitInsn(ARETURN);
        cv.visitMaxs(0, 0);
    }
View Full Code Here


                "(" + JT_STATE + JT_STATE + ")V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
    private void generateReadObjectMethod(int nbField) {
        CodeVisitor mv;
        mv = cv.visitMethod(ACC_PRIVATE, "readObject",
                "(Ljava/io/ObjectInputStream;)V",
                new String[] { "java/io/IOException", "java/lang/ClassNotFoundException" }, null);
        mv.visitVarInsn(ALOAD, 1); //param
        mv.visitVarInsn(ALOAD, 0); //this
        mv.visitMethodInsn(INVOKESTATIC, getJVMClassName(SpeedoPOSerializer.class),
                "readObject",
                "(Ljava/io/ObjectInputStream;" + JT_PO + ")V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

                "(Ljava/io/ObjectInputStream;" + JT_PO + ")V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
    private void generateWriteObjectMethod(int nbField) {
        CodeVisitor mv;
        mv = cv.visitMethod(ACC_PRIVATE, "writeObject",
                "(Ljava/io/ObjectOutputStream;)V",
                new String[] { "java/io/IOException" }, null);
        mv.visitVarInsn(ALOAD, 1); //param
        mv.visitVarInsn(ALOAD, 0); //this
        // new long[]{0xffffffffffffffffL, ..., 0xffffffffffffffffL}
        generateFieldIdAsLongArray(null, nbField, mv);
        mv.visitMethodInsn(INVOKESTATIC, getJVMClassName(SpeedoPOSerializer.class),
                "writeObject",
                "(Ljava/io/ObjectOutputStream;" + JT_PO + "[J)V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

                "(Ljava/io/ObjectOutputStream;" + JT_PO + "[J)V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
    private void generateSpeedoIsPersistentMethod() {
        CodeVisitor mv;
        mv = cv.visitMethod(ACC_PUBLIC, "speedoIsPersistent", "()Z", null, null);

        //if (!speedoIsActive) {
        //    return false;
        //}
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, classToWrite, ISACTIVE_FIELD_NAME, "Z");
        Label l1 = new Label();
        mv.visitJumpInsn(IFNE, l1);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l1);

        //StateItf sa = speedoGetState();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classToWrite, M_SPEEDO_GET_STATE, "()" + JT_STATE);
        mv.visitVarInsn(ASTORE, 1);

        //return sa == null || LifeCycle.isPersistent(sa.speedoGetStatus());
        mv.visitVarInsn(ALOAD, 1);
        Label l4 = new Label();
        mv.visitJumpInsn(IFNULL, l4);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEINTERFACE, JCN_STATE, M_SPEEDO_GET_STATUS, "()B");
        mv.visitMethodInsn(INVOKESTATIC, JCN_LIFE_CYCLE, "isPersistent", "(B)Z");
        Label l5 = new Label();
        mv.visitJumpInsn(IFEQ, l5);
        mv.visitLabel(l4);
        mv.visitInsn(ICONST_1);
        Label l6 = new Label();
        mv.visitJumpInsn(GOTO, l6);
       
        mv.visitLabel(l5);
        mv.visitInsn(ICONST_0);

        mv.visitLabel(l6);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

    }
    private void generateActiveUserCache(HomeContext gc) {
        if (gc.userCacheNames.length == 0) {
            return;
        }
        CodeVisitor cv = gc.cv.visitMethod(ACC_PUBLIC, "activeUserCache",
                "(Ljava/lang/String;)Z", null, null);

        //if (cacheName == null) {
        cv.visitVarInsn(ALOAD, 1);
        Label l0 = new Label();
        cv.visitJumpInsn(IFNONNULL, l0);
        {
            //return false;
            cv.visitInsn(ICONST_0);
            cv.visitInsn(IRETURN);
        }
        cv.visitLabel(l0);
        //} else if ("*".equals(cacheName)) {
        cv.visitLdcInsn("*");
        cv.visitVarInsn(ALOAD, 1);
        cv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z");
        Label labelElse = new Label();
        cv.visitJumpInsn(IFEQ, labelElse);
        {
            //foreach($ucn in $userCacheNames)
            for (int ucIdx = 0; ucIdx < gc.userCacheNames.length; ucIdx++) {
                //activeUserCache("$ucn");
                cv.visitVarInsn(ALOAD, 0);
                cv.visitLdcInsn(gc.userCacheNames[ucIdx]);
                cv.visitMethodInsn(INVOKEVIRTUAL,
                        gc.classToWriteJCN,
                        "activeUserCache", "(Ljava/lang/String;)Z");
                cv.visitInsn(POP);
            }
            //return true;
            cv.visitInsn(ICONST_1);
            cv.visitInsn(IRETURN);
        }
        cv.visitLabel(labelElse);
        for (int ucIdx = 0; ucIdx < gc.userCacheNames.length; ucIdx++) {
            final String ucn = gc.userCacheNames[ucIdx];
            //} else if ("${ucn}".equals(cacheName)) {
            cv.visitLdcInsn(ucn);
            cv.visitVarInsn(ALOAD, 1);
            cv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z");
            Label labelNext = new Label();
            cv.visitJumpInsn(IFEQ, labelNext);
            {
                //this.addUserCache(cacheName, ${userCacheFieldNames.get($ucn)}, ${ucn}_USER_CACHE_ID);
                cv.visitVarInsn(ALOAD, 0); //this
                cv.visitVarInsn(ALOAD, 1); //cacheName parameter
               
                //parameter ${userCacheFieldNames.get($ucn)}
                // new String[]{"f1", "f2"}
                final List fields = (List) gc.ucn2sfs.get(ucn);
                Util.visitIntConstant(cv, fields.size()); //Array size
                cv.visitTypeInsn(ANEWARRAY, "java/lang/String");
                for (int fieldIdx = 0; fieldIdx < fields.size(); fieldIdx++) {
                    SpeedoField sf = (SpeedoField) fields.get(fieldIdx);
                    cv.visitInsn(DUP);
                    Util.visitIntConstant(cv, fieldIdx); //index
                    cv.visitLdcInsn(sf.name); //value = field name
                    cv.visitInsn(AASTORE);
                }
               
                Util.visitIntConstant(cv, ucIdx); //${ucn}_USER_CACHE_ID
                cv.visitMethodInsn(INVOKEVIRTUAL, gc.classToWriteJCN,
                        "addUserCache", "(Ljava/lang/String;[Ljava/lang/String;I)Lorg/objectweb/speedo/usercache/api/UserCache;");
                cv.visitInsn(POP);
                //return true;
                cv.visitInsn(ICONST_1);
                cv.visitInsn(IRETURN);
            }
            cv.visitLabel(labelNext);
        }
        //return false;
        cv.visitInsn(ICONST_0);
        cv.visitInsn(IRETURN);
        cv.visitMaxs(0, 0);
    }
View Full Code Here

        cv.visitInsn(ICONST_0);
        cv.visitInsn(IRETURN);
        cv.visitMaxs(0, 0);
    }
    private void generateIniSHMethod(HomeContext gc) {
        CodeVisitor cv = gc.cv.visitMethod(ACC_PUBLIC, "initSH", "()V", null, null);
        String sqJCN = getJVMClassName(getQueryClass());
        for (Iterator it = gc.sc.name2query.values().iterator(); it.hasNext();) {
            SpeedoPredefinedQuery q = (SpeedoPredefinedQuery) it.next();
            //sq = new SpeedoQuery();
            cv.visitTypeInsn(NEW, sqJCN);
            cv.visitInsn(DUP);
            cv.visitMethodInsn(INVOKESPECIAL, sqJCN, "<init>", "()V");
            cv.visitVarInsn(ASTORE, 1); //Always use the same variable 1
           
            if (q.query != null) {
                cv.visitVarInsn(ALOAD, 1);
                cv.visitLdcInsn(q.query);
                cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "defineWith", "(Ljava/lang/String;)V");
            }
            if (q.filter != null) {
                cv.visitVarInsn(ALOAD, 1);
                cv.visitLdcInsn(q.filter);
                cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "setFilter", "(Ljava/lang/String;)V");
            }
            if (q.declareImports != null) {
                cv.visitVarInsn(ALOAD, 1);
                cv.visitLdcInsn(q.declareImports);
                cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "declareImports", "(Ljava/lang/String;)V");
            }
            if (q.declareParameters != null) {
                cv.visitVarInsn(ALOAD, 1);
                cv.visitLdcInsn(q.declareParameters);
                cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "declareParameters", "(Ljava/lang/String;)V");
            }
            if (q.declareVariables != null) {
                cv.visitVarInsn(ALOAD, 1);
                cv.visitLdcInsn(q.declareVariables);
                cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "declareVariables", "(Ljava/lang/String;)V");
            }

            cv.visitVarInsn(ALOAD, 1);
            cv.visitInsn(q.ignoreCache ? ICONST_1 : ICONST_0);
            cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "setIgnoreCache", "(Z)V");

            cv.visitVarInsn(ALOAD, 1);
            cv.visitInsn(q.resultUnique ? ICONST_1 : ICONST_0);
            cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "setUnique", "(Z)V");

            cv.visitVarInsn(ALOAD, 1);
            Util.visitLongConstant(cv, q.rangeFirst);
            Util.visitLongConstant(cv, q.rangeLast);
            cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "setRange", "(JJ)V");
           
            if (q.ordering != null) {
                cv.visitVarInsn(ALOAD, 1);
                cv.visitLdcInsn(q.ordering);
                cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "setOrdering", "(Ljava/lang/String;)V");
            }
           
            if (q.resultClass != null) {
                cv.visitVarInsn(ALOAD, 1);
                cv.visitLdcInsn(q.resultClass);
                cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "setResultClass", "(Ljava/lang/String;)V");
            }
           
            cv.visitVarInsn(ALOAD, 1);
            cv.visitInsn(q.includeSubclasses ? ICONST_1 : ICONST_0);
            cv.visitMethodInsn(INVOKEVIRTUAL, sqJCN, "setIncludeSubClasses", "(Z)V");
           
            //addNamedQuery("${nq.name}", sq);
            cv.visitVarInsn(ALOAD, 0);
            cv.visitLdcInsn(q.name);
            cv.visitVarInsn(ALOAD, 1);
            cv.visitMethodInsn(INVOKEVIRTUAL, gc.classToWriteJCN,
                    "addNamedQuery", "(Ljava/lang/String;L" + sqJCN + ";)V");
        }
        cv.visitInsn(RETURN);
        cv.visitMaxs(0, 0);
    }
View Full Code Here

                "javax/jdo/JDOUnsupportedOptionException", "<init>", "()V");
        mv.visitInsn(ATHROW);
    }
   
    private void generateJdoGetPersistenceManagerMethod() {
        CodeVisitor mv = cv.visitMethod(ACC_PUBLIC, "jdoGetPersistenceManager",
                "()Ljavax/jdo/PersistenceManager;", null, null);
        //return (speedoIsActive
                //? speedoGetHome().getPOManagerFactory().lookup()
                //: null);
       
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, classToWrite, ISACTIVE_FIELD_NAME, "Z");
        Label l1 = new Label();
        mv.visitJumpInsn(IFEQ, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classToWrite, "speedoGetHome",
                "()" + JT_HOME);
        mv.visitMethodInsn(INVOKEINTERFACE, JCN_HOME, "getPOManagerFactory",
                "()" + JT_POMF);
        mv.visitMethodInsn(INVOKEINTERFACE, JCN_POMF, "lookup", "()" + JT_POM);
        Label l2 = new Label();
        mv.visitJumpInsn(GOTO, l2);
        mv.visitLabel(l1);
        mv.visitInsn(ACONST_NULL);
        mv.visitLabel(l2);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

        cv.visitField(ACC_PROTECTED, ENCODEDPNAME_FIELD_NAME,
                "Ljava/lang/Object;", null, null);
    }
   
    private void generateSpeedoIsActiveMethod() {
        CodeVisitor mv;
        mv = cv.visitMethod(ACC_PUBLIC, ISACTIVE_FIELD_NAME, "()Z", null, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, classToWrite, ISACTIVE_FIELD_NAME, "Z");
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

        mv.visitFieldInsn(GETFIELD, classToWrite, ISACTIVE_FIELD_NAME, "Z");
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
    }
    private void generateSpeedoIsActiveZMethod() {
        CodeVisitor mv;
        mv = cv.visitMethod(ACC_PUBLIC, ISACTIVE_FIELD_NAME, "(Z)V", null, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitFieldInsn(PUTFIELD, classToWrite, ISACTIVE_FIELD_NAME, "Z");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

        mv.visitFieldInsn(PUTFIELD, classToWrite, ISACTIVE_FIELD_NAME, "Z");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
    }
    private void generateSpeedoGetHomeMethod() {
        CodeVisitor mv;
        mv = cv.visitMethod(ACC_PUBLIC, M_SPEEDO_GET_HOME, "()" + JT_HOME, null, null);
        mv.visitVarInsn(ALOAD, 0);
        //return (HomeItf) getPClassMapping();
        mv.visitMethodInsn(INVOKEVIRTUAL, classToWrite, "getPClassMapping",
                "()Lorg/objectweb/jorm/api/PClassMapping;");
        mv.visitTypeInsn(CHECKCAST, JCN_HOME);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(0, 0);
    }
View Full Code Here

TOP

Related Classes of org.objectweb.asm.CodeVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.