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

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


        }
        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_return));

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

        // check oid argument
        final ConstClass keyConstClass = pool.addClass(keyClassName);
        affirm(keyConstClass != null);
        insn = appendCheckVarInstanceOf(insn, 1, keyConstClass,
                                        JAVA_IllegalArgumentException_Path,
                                        "arg1");

        // downcast argument
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_checkcast, keyConstClass));
        insn = insn.append(Insn.create(opc_astore_2));

        // check argument or delegate to superclass
        final boolean isPCRoot = analyzer.isAugmentableAsRoot();
        if (!isPCRoot) {
            // call super.jdoCopyKeyFieldsToObjectId(oid)

            //^olsen: javac uses the truelly declaring class
            //final ConstClass superConstClass = classFile.superName();
            //affirm(superConstClass != null);
            //final String superClassName = superConstClass.asString();
            //affirm(superClassName != null);

            final String superClassName
                = analyzer.getPCSuperKeyOwnerClassName();
            affirm(superClassName != null);
            insn = insn.append(Insn.create(opc_aload_0));
            insn = insn.append(Insn.create(opc_aload_2));
            insn = insn.append(
                Insn.create(opc_invokespecial,
                            pool.addMethodRef(
                                superClassName,
                                methodName,
                                methodSig)));
        }
       
        // get types of and field references of the key fields
        final int keyFieldCount = analyzer.getKeyFieldCount();
        final ConstFieldRef[] keyFieldRefs = getKeyFieldRefs();
        final ConstFieldRef[] keyClassKeyFieldRefs = getKeyClassKeyFieldRefs();
        affirm(keyFieldRefs.length == keyFieldCount);
        affirm(keyClassKeyFieldRefs.length == keyFieldCount);

        // generate the assignment statements
        int maxFieldSize = 0;
        for (int i = 0; i < keyFieldCount; i++) {
            // assign key field
            final ConstFieldRef thisClassKeyRef = keyFieldRefs[i];
            final ConstFieldRef keyClassKeyRef = keyClassKeyFieldRefs[i];
            affirm(thisClassKeyRef != null);
            affirm(keyClassKeyRef != null);
            if (isToOid) {
                insn = insn.append(Insn.create(opc_aload_2));
                insn = insn.append(Insn.create(opc_aload_0));
                insn = insn.append(Insn.create(opc_getfield, thisClassKeyRef));
                insn = insn.append(Insn.create(opc_putfield, keyClassKeyRef));
            } else {
                insn = insn.append(Insn.create(opc_aload_0));
                insn = insn.append(Insn.create(opc_aload_2));
                insn = insn.append(Insn.create(opc_getfield, keyClassKeyRef));
                insn = insn.append(Insn.create(opc_putfield, thisClassKeyRef));
            }

            // compute stack demand
            final String sig
                = thisClassKeyRef.nameAndType().signature().asString();
            affirm(sig != null && sig.length() > 0);
            maxFieldSize = max(maxFieldSize, Descriptor.countFieldWords(sig));
        }

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

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                max(maxFieldSize + 1, 3), // maxStack
                                3, // maxLocals
View Full Code Here


        }
        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_return));

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

        // check fm argument
        insn = appendCheckVarNonNull(insn, 1,
                                     JAVA_IllegalArgumentException_Path,
                                     "arg1");
       
        // check oid argument
        final ConstClass keyConstClass = pool.addClass(keyClassName);
        affirm(keyConstClass != null);
        insn = appendCheckVarInstanceOf(insn, 2, keyConstClass,
                                        JAVA_IllegalArgumentException_Path,
                                        "arg2");

        // downcast argument
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(Insn.create(opc_checkcast, keyConstClass));
        insn = insn.append(Insn.create(opc_astore_3));

        // call super.jdoCopyKeyFieldsToObjectId(oid)
        final boolean isPCRoot = analyzer.isAugmentableAsRoot();
        if (!isPCRoot) {
            // call super.jdoCopyKeyFieldsToObjectId(oid)

            //^olsen: javac uses the truelly declaring class
            //final ConstClass superConstClass = classFile.superName();
            //affirm(superConstClass != null);
            //final String superClassName = superConstClass.asString();
            //affirm(superClassName != null);

            final String superClassName
                = analyzer.getPCSuperKeyOwnerClassName();
            insn = insn.append(Insn.create(opc_aload_0));
            insn = insn.append(Insn.create(opc_aload_1));
            insn = insn.append(Insn.create(opc_aload_3));
            insn = insn.append(
                Insn.create(opc_invokespecial,
                            pool.addMethodRef(
                                superClassName,
                                methodName,
                                methodSig)));
        }
       
        // get types of and field references of the key fields
        final int keyFieldCount = analyzer.getKeyFieldCount();
        final ConstFieldRef[] keyFieldRefs = getKeyFieldRefs();
        final ConstFieldRef[] keyClassKeyFieldRefs = getKeyClassKeyFieldRefs();
        affirm(keyFieldRefs.length == keyFieldCount);
        affirm(keyClassKeyFieldRefs.length == keyFieldCount);

        // generate the case-targets for the method calls
        final SizeHolder sizeHolder = new SizeHolder();
        if (isToOid) {
            insn = appendStatementsForCopyKeyFieldsToOid(insn, sizeHolder);
        } else {
            insn = appendStatementsForCopyKeyFieldsFromOid(insn, sizeHolder);
        }

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

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                max(sizeHolder.size
                                    + (isToOid ? 3 : 2), 3), // maxStack
View Full Code Here

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
        affirm(sig != null && sig.length() > 0);
View Full Code Here

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        // get field's sig and compute first non-parameter slot
        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
View Full Code Here

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        // get field's sig and compute first non-parameter slot
        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
        affirm(sig != null && sig.length() > 0);
        final int fieldSize = ((sig.equals("J") || sig.equals("D")) ? 2 : 1);
        final int varStart = 1;

        // directly return field if flags are <= LOAD_REQUIRED
        final InsnTarget mediate = new InsnTarget();
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_getfield,
                        getjdoFlagsFieldRef()));
        insn = insn.append(Insn.create(opc_ifgt, mediate));
        insn = appendDirectReadReturn(insn, fieldRef);

        // mediate access
        insn = insn.append(mediate);
        insn = appendMediatedReadAccess(insn, fieldIndex, fieldRef, varStart);

        // end of method body

        final CodeAttribute codeAttr
View Full Code Here

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);

        // write argument to field and return
View Full Code Here

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        // get field's sig and compute first non-parameter slot
        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
View Full Code Here

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        // get field's sig and compute first non-parameter slot
        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
        affirm(sig != null && sig.length() > 0);
        final int fieldSize = ((sig.equals("J") || sig.equals("D")) ? 2 : 1);
        final int varStart = fieldSize + 1;

        // directly write argument and retrurn if flags are != READ_WRITE_OK
        final InsnTarget mediate = new InsnTarget();
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_getfield,
                        getjdoFlagsFieldRef()));
        insn = insn.append(Insn.create(opc_ifne, mediate));
        insn = appendDirectWriteReturn(insn, fieldRef);

        // mediate access
        insn = insn.append(mediate);
        insn = appendMediatedWriteAccess(insn, fieldIndex, fieldRef, varStart);

        // end of method body

        final CodeAttribute codeAttr
View Full Code Here

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

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

        //@olsen: disabled code
        if (false) {
            // reset jdoFlags = LOAD_REQUIRED
            insn = insn.append(Insn.create(opc_aload_0));
            insn = insn.append(Insn.create(opc_iconst_1));
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             JDO_PC_jdoFlags_Name,
                                             JDO_PC_jdoFlags_Sig)));
        }

        // iterate over all declared fields of the class
        final ClassField[] managedFields = null; //analyzer.annotatedFields();
        final int managedFieldCount = managedFields.length;
        for (int i = 0; i < managedFieldCount; i++) {
            final ClassField field = managedFields[i];
            final String fieldName = field.name().asString();
            final String fieldSig = field.signature().asString();

/*
            // ignore primary managed fields
            if (field.isManaged())
                continue;
*/

/*
            //@olsen: disconnect mutable SCOs before clear
            if (field.isMutableSCO()) {
                // fetch field
                insn = insn.append(Insn.create(opc_aload_0));
                insn = insn.append(
                    Insn.create(opc_getfield,
                                pool.addFieldRef(
                                    className,
                                    fieldName,
                                    fieldSig)));

                // test whether instanceof SCO base type
                // skip disconnecting if == 0
                final ConstClass cc
                    = pool.addClass(JDO_SecondClassObjectBase_Path);
                InsnTarget disconnect = new InsnTarget();
                InsnTarget afterDisconnect = new InsnTarget();
                insn = insn.append(
                    Insn.create(opc_dup));
                insn = insn.append(
                    Insn.create(opc_instanceof,
                                cc));
                insn = insn.append(
                    Insn.create(opc_ifne,
                                disconnect));

                // pop field and skip disconnecting
                insn = insn.append(
                    Insn.create(opc_pop));
                insn = insn.append(
                    Insn.create(opc_goto, afterDisconnect));

                // disconnect SCO field's object
                insn = insn.append(disconnect);

                // cast to SCO base type
                insn = insn.append(
                    Insn.create(opc_checkcast,
                                cc));

                // call method: void unsetOwner();
                final int requiredStack = 1;
                insn = insn.append(
                    new InsnInterfaceInvoke(
                        pool.addInterfaceMethodRef(
                            JDO_SecondClassObjectBase_Path,
                            "unsetOwner",
                            "()V"),
                        requiredStack));

                insn = insn.append(afterDisconnect);
            }
*/

            // get this
            insn = insn.append(Insn.create(opc_aload_0));

            // use the getMethodReturn type to decide how to clear field
            switch (fieldSig.charAt(0)) {
            case 'D':
                insn = insn.append(Insn.create(opc_dconst_0));
                break;
            case 'F':
                insn = insn.append(Insn.create(opc_fconst_0));
                break;
            case 'J':
                insn = insn.append(Insn.create(opc_lconst_0));
                break;
            case 'Z':
            case 'C':
            case 'B':
            case 'S':
            case 'I':
                insn = insn.append(Insn.create(opc_iconst_0));
                break;
            case 'L':
            case '[':
                insn = insn.append(Insn.create(opc_aconst_null));
                break;
            default:
                throw new InternalError("Illegal field type: " + fieldSig);
            }

            // put default value to field
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             fieldName,
                                             fieldSig)));
        }

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

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

                pool.addUtf8(ExceptionsAttribute.expectedAttrName),
                pool.addClass("java/lang/CloneNotSupportedException"));

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

        // THISCLASS newObject = (THISCLASS) super.clone();
        final ConstClass superConstClass = classFile.superName();
        final ConstClass thisConstClass = classFile.className();
        affirm(thisConstClass != null);
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_invokespecial,
                        pool.addMethodRef(superConstClass.asString(),
                                          methodName,
                                          methodSig)));
        insn = insn.append(Insn.create(opc_checkcast, thisConstClass));

        // newObject.jdoStateManager = null;
        if (false)
        {
            insn = insn.append(Insn.create(opc_dup));
            insn = insn.append(Insn.create(opc_aconst_null));
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             JDO_PC_jdoStateManager_Name,
                                             JDO_PC_jdoStateManager_Sig)));
        }

        // newObject.jdoFlags = 0;
        if (false)
        {
            insn = insn.append(Insn.create(opc_dup));
            insn = insn.append(Insn.create(opc_iconst_0));
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             JDO_PC_jdoFlags_Name,
                                             JDO_PC_jdoFlags_Sig)));
        }

        // return newObject;

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

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                1, //3, //3, // maxStack
                                1, //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.