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

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


        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
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here


        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
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

        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
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

        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
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

        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
                                4, // maxLocals
                                begin,
                                new ExceptionTable(),
View Full Code Here

        // return direct read
        insn = appendDirectReadReturn(insn, fieldRef);

        // end of method body

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                fieldSize, // maxStack
                                1, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

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

        // end of method body

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                fieldSize + 3, // maxStack
                                2, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

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

        // end of method body

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                fieldSize + 3, // maxStack
                                2, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

        affirm(fieldRef != null);

        // write argument to field and return
        insn = appendDirectWriteReturn(insn, fieldRef);

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                3, // maxStack: allow for long/double
                                3, // maxLocals: allow for long/double
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

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

        // end of method body

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                (2 * fieldSize) + 3, // maxStack
                                fieldSize + 2, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

TOP

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

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.