Package org.apache.jdo.impl.enhancer.classfile

Examples of org.apache.jdo.impl.enhancer.classfile.Insn


            "annotating: " + userClassName
            + "." + method.name().asString()
            + Descriptor.userMethodArgs(method.signature().asString()));
       
        // first instruction is a target
        final Insn firstInsn = codeAttr.theCode();
        affirm(firstInsn.opcode() == Insn.opc_target);
        Insn insn = firstInsn.next();
        while (insn != null) {
            switch(insn.opcode()) {
            case opc_getfield:
            case opc_putfield:
                final Insn newInsn = insnAnnotation(insn);
                if (insn != newInsn) {
                    annotated = true;
                }
                insn = newInsn;
                break;
View Full Code Here


                               + declClassName + "." + methodName
                               + " : " + methodSig);
        }

        // call the PC's static accessor/mutator
        final Insn frag = Insn.create(opc_invokestatic,
                                      pool.addMethodRef(declClassName,
                                                        methodName,
                                                        methodSig));

        //insn.prev().insert(Insn.create(opc_nop));
        // replace instruction
        final Insn prev = insn.prev();
        insn.remove();

        // replace current instruction with new fragment
        final Insn last = prev.insert(frag);
        return last;
    }
View Full Code Here

            }

            // check whether next instruction already is a downcast to a
            // class implementing PersistenceCapable
            final String thisClass = classFile.classNameString();
            final Insn checkCastInsn = insn.next();
            final boolean needCheckcast;
            if (checkCastInsn.opcode() != opc_checkcast) {
                needCheckcast = true;
            } else {
                ConstClass target =
                    (ConstClass) ((InsnConstOp)checkCastInsn).value();
                if (target.asString().equals(thisClass)) {
                    insn = checkCastInsn;
                    needCheckcast = false;
                } else {
                    needCheckcast = true;
                }
            }

            // clear jdo fields of clone
            {
                // duplicate downcasted reference
                final Insn newInsn = Insn.create(opc_dup);
                if (needCheckcast) {
                    newInsn.append(Insn.create(opc_checkcast,
                                               pool.addClass(thisClass)));
                }
                newInsn.append(Insn.create(opc_dup));

                // clear jdo fields
                newInsn.append(Insn.create(opc_aconst_null));
                newInsn.append(Insn.create(
                    opc_putfield,
                    pool.addFieldRef(
                        thisClass,
                        JDOConstants.JDO_PC_jdoStateManager_Name,
                        JDOConstants.JDO_PC_jdoStateManager_Sig)));
                newInsn.append(Insn.create(opc_iconst_0));
                newInsn.append(Insn.create(
                    opc_putfield,
                    pool.addFieldRef(
                        thisClass,
                        JDOConstants.JDO_PC_jdoFlags_Name,
                        JDOConstants.JDO_PC_jdoFlags_Sig)));
View Full Code Here

        final int accessFlags = JDO_PC_jdoNewInstance_Object_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // push a newly created an instance of this class
        final ConstClass thisConstClass = classFile.className();
        affirm(thisConstClass != null);
        insn = insn.append(Insn.create(opc_new, thisConstClass));
        insn = insn.append(Insn.create(opc_dup));
        insn = insn.append(
            Insn.create(opc_invokespecial,
                        pool.addMethodRef(
                            className,
                            NameHelper.constructorName(),
                            NameHelper.constructorSig())));
        insn = insn.append(Insn.create(opc_astore_3));

        // class on instance pc.jdoCopyKeyFieldsFromObjectId(oid)
        //^olsen: javac uses the truelly declaring class
        final String pcKeyOwnerClassName = analyzer.getPCKeyOwnerClassName();
        affirm(pcKeyOwnerClassName != null);
        insn = insn.append(Insn.create(opc_aload_3));
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(
            Insn.create(opc_invokevirtual,
                        pool.addMethodRef(
                            pcKeyOwnerClassName,
                            JDO_PC_jdoCopyKeyFieldsFromObjectId_Name,
                            JDO_PC_jdoCopyKeyFieldsFromObjectId_Sig)));

        // init jdo flags and assign argument to sm
        insn = insn.append(Insn.create(opc_aload_3));
        insn = insn.append(Insn.create(opc_iconst_1));
        insn = insn.append(
            Insn.create(opc_putfield,
                        getjdoFlagsFieldRef()));
        insn = insn.append(Insn.create(opc_aload_3));
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(
            Insn.create(opc_putfield,
                        getjdoStateManagerFieldRef()));

        // end of method body
        insn = insn.append(Insn.create(opc_aload_3));
        insn = insn.append(Insn.create(opc_areturn));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                2, // maxStack
                                4, // maxLocals
View Full Code Here

        final int accessFlags = JDO_PC_jdoProvideField_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // generate the begin code
        insn = appendBeginProvideReplaceField(insn);
       
        // generate the switch code
        final SizeHolder sizeHolder = new SizeHolder();
        insn = appendSwitchForProvideField(insn, sizeHolder);
       
        // generate the default-branch code with throw/return
        insn = appendEndProvideReplaceField(insn,
                                            JDO_PC_jdoProvideField_Name,
                                            JDO_PC_jdoProvideField_Sig);

        // end of method body
        affirm(insn.opcode() == opc_athrow || insn.opcode() == opc_return);
       
        affirm(0 <= sizeHolder.size && sizeHolder.size <= 2);
        //System.out.println("sizeHolder.size = " + sizeHolder.size);
        final int maxStack = (sizeHolder.size == 0
                              ? 3 : (sizeHolder.size == 1 ? 4 : 5));
View Full Code Here

        final int accessFlags = JDO_PC_jdoReplaceField_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // generate the begin code
        insn = appendBeginProvideReplaceField(insn);
       
        // generate the switch code
        final SizeHolder sizeHolder = new SizeHolder();
        insn = appendSwitchForReplaceField(insn, sizeHolder);
       
        // generate the default-branch code with throw/return
        insn = appendEndProvideReplaceField(insn,
                                            JDO_PC_jdoReplaceField_Name,
                                            JDO_PC_jdoReplaceField_Sig);

        // end of method body
        affirm(insn.opcode() == opc_athrow || insn.opcode() == opc_return);

        affirm(0 <= sizeHolder.size && sizeHolder.size <= 2);
        //System.out.println("sizeHolder.size = " + sizeHolder.size);
        final int maxStack = (sizeHolder.size == 0 ? 3 : 4);
        final CodeAttribute codeAttr
View Full Code Here

        final int accessFlags = JDO_PC_jdoCopyField_Mods;
        final ExceptionsAttribute exceptAttr = null;
       
        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // generate the begin code
        insn = appendBeginCopyField(insn);
       
        // generate the switch code
        insn = appendSwitchForCopyField(insn);
       
        // generate the default-branch code with throw/return
        insn = appendEndCopyField(insn);

        // end of method body
        affirm(insn.opcode() == opc_athrow || insn.opcode() == opc_return);
       
        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                3, // maxStack
                                3, // maxLocals
View Full Code Here

        final int accessFlags = JDO_PC_jdoCopyFields_Mods;       
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // check sm
        insn = appendCheckStateManager(insn, 0,
                                       JAVA_IllegalStateException_Path,
                                       "arg0." + JDO_PC_jdoStateManager_Name);

        // check pc argument
        final ConstClass thisConstClass = classFile.className();
        affirm(thisConstClass != null);
        insn = appendCheckVarInstanceOf(insn, 1, thisConstClass,
                                        JAVA_IllegalArgumentException_Path,
                                        "arg1");

        // check fieldnumbers argument
        insn = appendCheckVarNonNull(insn, 2,
                                     JAVA_IllegalArgumentException_Path,
                                     "arg2");

        // downcast argument
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_checkcast, thisConstClass));
        insn = insn.append(Insn.create(opc_astore_3));

        // check this and argument's sm for equality
        final InsnTarget endcheck = new InsnTarget();
        insn = insn.append(Insn.create(opc_aload_3));
        insn = insn.append(
            Insn.create(
                opc_getfield,
                getjdoStateManagerFieldRef()));
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(
                opc_getfield,
                getjdoStateManagerFieldRef()));
        insn = insn.append(Insn.create(opc_if_acmpeq, endcheck));
        insn = appendThrowJavaException(insn,
                                        JAVA_IllegalArgumentException_Path,
                                        "arg1." + JDO_PC_jdoStateManager_Name);

        // store the array argument length into local var
        insn = insn.append(endcheck);
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(Insn.create(opc_arraylength));
        insn = insn.append(Insn.create(opc_istore, 4));

        // init loop counter and goto loop check
        final InsnTarget loopcheck = new InsnTarget();
        insn = insn.append(Insn.create(opc_iconst_0));
        insn = insn.append(Insn.create(opc_istore, 5));
        insn = insn.append(Insn.create(opc_goto, loopcheck));

        // loop body: call self-delegating method with arguments
        final InsnTarget loopbody = new InsnTarget();
        insn = insn.append(loopbody);
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(Insn.create(opc_aload_3));

        // select element from array argument at loop counter
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(Insn.create(opc_iload, 5));
        insn = insn.append(Insn.create(opc_iaload));

        // call self-delegating method
        final String delegateName = JDO_PC_jdoCopyField_Name;
        final String delegateSig
            = JDONameHelper.getJDO_PC_jdoCopyField_Sig(className);
        insn = insn.append(
            Insn.create(opc_invokevirtual,
                        pool.addMethodRef(
                            className,
                            delegateName,
                            delegateSig)));

        // loop counter increment
        insn = insn.append(new InsnIInc(5, 1));

        // loop termination check
        insn = insn.append(loopcheck);
        insn = insn.append(Insn.create(opc_iload, 5));
        insn = insn.append(Insn.create(opc_iload, 4));
        insn = insn.append(Insn.create(opc_if_icmplt, loopbody));

        // end of method body
        insn = insn.append(Insn.create(opc_return));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                4, // maxStack
                                6, // maxLocals
View Full Code Here

        final int accessFlags = JDO_PC_jdoNewObjectIdInstance_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // generate empty method in case of datastore identity
        final String keyClassName = analyzer.getKeyClassName();
        if (keyClassName == null){
            // end of method body
            insn = insn.append(Insn.create(opc_aconst_null));
            insn = insn.append(Insn.create(opc_areturn));

            final CodeAttribute codeAttr
                = new CodeAttribute(getCodeAttributeUtf8(),
                                    1, // maxStack
                                    1, // maxLocals
                                    begin,
                                    new ExceptionTable(),
                                    new AttributeVector());
            augmenter.addMethod(methodName, methodSig, accessFlags,
                                codeAttr, exceptAttr);
            return;
        }
        affirm(keyClassName != null);

        // push a newly created an instance of this class
        insn = insn.append(
            Insn.create(opc_new,
                        pool.addClass(keyClassName)));
        insn = insn.append(Insn.create(opc_dup));
        insn = insn.append(
            Insn.create(opc_invokespecial,
                        pool.addMethodRef(
                            keyClassName,
                            NameHelper.constructorName(),
                            NameHelper.constructorSig())));

        // end of method body
        insn = insn.append(Insn.create(opc_areturn));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                2, // maxStack
                                1, // maxLocals
View Full Code Here

        final int accessFlags = JDO_PC_jdoNewObjectIdInstance_Object_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // generate empty method in case of datastore identity
        final String keyClassName = analyzer.getKeyClassName();
        if (keyClassName == null){
            // end of method body
            insn = insn.append(Insn.create(opc_aconst_null));
            insn = insn.append(Insn.create(opc_areturn));

            final CodeAttribute codeAttr
                = new CodeAttribute(getCodeAttributeUtf8(),
                                    1, // maxStack
                                    2, // maxLocals
                                    begin,
                                    new ExceptionTable(),
                                    new AttributeVector());
            augmenter.addMethod(methodName, methodSig, accessFlags,
                                codeAttr, exceptAttr);
            return;
        }
        affirm(keyClassName != null);

        // TODO: support for single field identity

        // push a newly created an instance of this class
        insn = insn.append(
            Insn.create(opc_new,
                        pool.addClass(keyClassName)));
        insn = insn.append(Insn.create(opc_dup));
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_checkcast,
                                       pool.addClass(JAVA_String_Path)));
        insn = insn.append(
            Insn.create(opc_invokespecial,
                        pool.addMethodRef(
                            keyClassName,
                            NameHelper.constructorName(),
                            NameHelper.constructorSig(JAVA_String_Sig))));

        // end of method body
        insn = insn.append(Insn.create(opc_areturn));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                3, // maxStack
                                2, // maxLocals
View Full Code Here

TOP

Related Classes of org.apache.jdo.impl.enhancer.classfile.Insn

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.