Package alt.jiapi.reflect.instruction

Examples of alt.jiapi.reflect.instruction.FieldAccess


            sb.append(')');

            return sb.toString();
        }
        else if (endIns instanceof FieldAccess) {
            FieldAccess fa = (FieldAccess)endIns;
            return fa.getClassName() + "." + fa.getFieldName();
        }

        return ""; // Should we return null instead?
    }
View Full Code Here


                break;
            case Opcodes.GETSTATIC:
            case Opcodes.PUTSTATIC:
            case Opcodes.GETFIELD:
            case Opcodes.PUTFIELD:
                ins = new FieldAccess(new byte[] { byteCode[i],
                                                   byteCode[i+1],
                                                   byteCode[i+2]}, cp);
                iMod = 2;//i += 2;
                break;
            case Opcodes.INVOKEVIRTUAL:
View Full Code Here

            bytes[0] = Opcodes.GETFIELD;
            bytes[1] = (byte) (index >> 8);
            bytes[2] = (byte) (index & 255);
        }

        Instruction instruction = new FieldAccess(bytes, cp);
        return instruction;
    }
View Full Code Here

            bytes[0] = Opcodes.GETFIELD;
            bytes[1] = (byte) (index >> 8);
            bytes[2] = (byte) (index & 255);
        }

        Instruction instruction = new FieldAccess(bytes, cp);
        return instruction;
    }
View Full Code Here

            bytes[0] = Opcodes.PUTFIELD;
            bytes[1] = (byte) (index >> 8);
            bytes[2] = (byte) (index & 255);
        }

        Instruction instruction = new FieldAccess(bytes, cp);
        return instruction;
    }
View Full Code Here

        //System.out.println("Instrumenting " + il.getDeclaringMethod());

        int idx = -1;
        while ((idx = il.indexOf(OpcodeGroups.FIELD_ACCESS_INSTRUCTIONS, idx+1)) != -1) {
            FieldAccess ins = (FieldAccess)il.get(idx);
            // Do not instrument on __jiapi_fields
            if (ins.getName().startsWith("__jiapi_field")) {
                continue;
            }

            //System.out.println("  found " + ins);
            InstructionList invokeList = il.createEmptyList();

            switch(ins.getOpcode()) {
            case Opcodes.PUTFIELD:
            case Opcodes.GETFIELD:
                invokeList.add(factory.getField(jiapiField));
                invokeList.add(factory.pushThis());
                invokeList.add(factory.pushConstant(ins.getFieldName()));
                if (ins.getOpcode() == Opcodes.GETFIELD) {
                    invokeList.add(factory.invoke(fieldGet));
                }
                else {
                    invokeList.add(factory.invoke(fieldSet));
                }
                break;
            case Opcodes.PUTSTATIC:
            case Opcodes.GETSTATIC:
                invokeList.add(factory.getField(jiapiField));
                invokeList.add(factory.getField(jiapiField)); // BUG: Class
                invokeList.add(factory.pushConstant(ins.getFieldName()));
                if (ins.getOpcode() == Opcodes.GETSTATIC) {
                    invokeList.add(factory.invoke(fieldGet));
                }
                else {
                    invokeList.add(factory.invoke(fieldSet));
                }
View Full Code Here

    // Find event producer initialization on <clinit>
    private int findFieldInitIndex(InstructionList il, JiapiField jiapiField) {
        int idx = -1;
       
        while ((idx = il.indexOf(Opcodes.PUTSTATIC, idx+1)) != -1) {
            FieldAccess fa = (FieldAccess)il.get(idx);
            if (fa.getFieldName().equals(jiapiField.getName())) {
                break;
            }
        }

        return idx;
View Full Code Here

        int index = 0;
       
        // Find getXXX or putXXX instructions
        while ((index = il.indexOf(OpcodeGroups.FIELD_ACCESS_INSTRUCTIONS,
                                   index)) != -1) {
            FieldAccess fa = (FieldAccess)il.get(index);
            int opcode = fa.getOpcode();
//              Operand o = i.getOperand();
            String targetName = fa.getFieldName();

            //            if (match(o.toString())) { // Resolution
            if (match(targetName)) { // Resolution
                if ((accessPolicy & READ_ACCESS) == READ_ACCESS) {
                    if ((opcode == Opcodes.GETFIELD) ||
View Full Code Here

            new HotSpotLocator(il, new byte[]{Opcodes.GETSTATIC,
                                              Opcodes.GETFIELD});
        HotSpot[] hotSpots = hsl.getHotSpots();

        for (int i = 0; i < hotSpots.length; i++) {
            FieldAccess fa = (FieldAccess)hotSpots[i].getHotSpotInstruction();
            short opCode = fa.getOpcode();

            if (!match(fa.getClassName() + "." + fa.getFieldName())) {
                continue;
            }

            InstructionList hsList = hotSpots[i].getInstructionList();
            InstructionList nList = il.createEmptyList();

            boolean primitive = SignatureUtil.isPrimitive(fa.getTypeName());


            if (opCode == Opcodes.GETSTATIC ||
                opCode == Opcodes.GETFIELD) {
                nList.add(factory.getField(interceptor)); // Interceptor

                // NOTE: We could store Class into variable,
                //       and use getField() instead of Class.forName() call
                // Class or objref; 1st parameter to interceptor
                if (opCode == Opcodes.GETSTATIC) {
                    short lvIdx =
                        addClassForNameInstructions(fa.getClassName(), jm);
                    nList.add(factory.aload(lvIdx));
//                     addClassForNameInstructions(fa.getClassName(), nList);
//                     nList.add(factory.pushNull());
                }
                else {
                    //addClassForNameInstructions(fa.getClassName(), nList);
                    nList.add(hsList.get(0)); // objref
                }

                // Name of the field; 2nd parameter to interceptor
                nList.add(factory.pushConstant(fa.getFieldName()));

                // 3rd parameter; field value
                Instruction pIns = null;
                if (primitive) {
                    // Provide wrapper for primitive types
                    pIns = handlePrimitiveType(fa.getTypeName(), nList);
                }
                //nList.add(fa);
                //nList.add(hsList);
                nList.add(hotSpots[i].getInstructionList());

                if (pIns != null) {
                    nList.add(pIns);
                }

                // call Interceptor
                nList.add(factory.invoke(getMethod));

                handleReturnValue(nList, fa.getTypeName());
                //nList.add(factory.cast(fa.getTypeName()));

                hotSpots[i].getInstructionList()/* hsList*/.replace(nList);
            }
        }
View Full Code Here

            new HotSpotLocator(il,
                               new byte[]{Opcodes.GETSTATIC/*,Opcodes.PUTSTATIC*/});
        HotSpot[] hotSpots = hsl.getHotSpots();

        for (int i = 0; i < hotSpots.length; i++) {
            FieldAccess fa = (FieldAccess)hotSpots[i].getHotSpotInstruction();
           
            if (fa.getName().startsWith("__jiapi")) {
                continue;
            }

            if (!match(fa.getClassName() + "." + fa.getFieldName())) {
                continue;
            }

            // BUG: We cannot use reflection in this interceptor, since it
            // is allowed only for public fields.
            if (!isPublicField(fa)) {
                continue;
            }

            InstructionList hsList = hotSpots[i].getInstructionList();
            InstructionList nList = il.createEmptyList();

            nList.add(factory.getField(interceptor)); // Interceptor

            // Class or objref; 1st parameter to interceptor
            if ((fa.getOpcode() == Opcodes.GETSTATIC) ||
                (fa.getOpcode() == Opcodes.PUTSTATIC)) {
                addClassForNameInstructions(fa.getClassName(), nList);
            }
            else {
                nList.add(il.get(0)); // objref
            }

            // Name of the field; 2nd parameter to interceptor
            nList.add(factory.pushConstant(fa.getClassName() + "." +
                                           fa.getFieldName()));

            // call Interceptor
            if ((fa.getOpcode() == Opcodes.GETSTATIC) ||
                (fa.getOpcode() == Opcodes.GETFIELD)) {
                nList.add(factory.invoke(getMethod));
            }
            else {
                nList.add(il.get(1)); // value ???
                nList.add(factory.invoke(setMethod));
            }
           
            handleReturnValue(nList, fa.getTypeName());

            //nList.add(factory.cast(fa.getTypeName()));

            hsList.replace(nList);
        }
View Full Code Here

TOP

Related Classes of alt.jiapi.reflect.instruction.FieldAccess

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.