Package alt.jiapi.reflect

Examples of alt.jiapi.reflect.InstructionList


    }

    public void instrument(JiapiMethod jm) {
        JiapiClass clazz = jm.getDeclaringClass();
        JiapiField interceptor = getEventProducerField();
        InstructionList il = jm.getInstructionList();
        InstructionFactory factory = il.getInstructionFactory();

        HotSpotLocator hsl =
            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


     * values in <clinit>
     *
     * @return index of the local variable, where Class is stored
     */
    private short addClassForNameInstructions(String name, JiapiMethod jm) {
        InstructionList il = jm.getInstructionList();
        InstructionFactory f = il.getInstructionFactory();

        InstructionList nl = il.createEmptyList();
        short maxLocals = (short)jm.getMaxLocals();
       
        // NOTE: We do not create exception handlers for
        //       Class.forName(...) invocation.
        //       However, we use this to get Class of the running object,
        //       so its Class is allways found.
        try {
            nl.add(f.pushConstant(name));
            nl.add(f.invoke(Modifier.STATIC, "java.lang.Class",
                            "forName", new Signature("java.lang.Class",
                                                     new String[] {"java.lang.String"})));
            nl.add(f.astore(maxLocals));
        }
        catch(Exception e) {
            e.printStackTrace();
            il.add(f.pushNull());
        }
View Full Code Here

        }
    }

    public void instrument(JiapiMethod jm) {
        JiapiField interceptor = getEventProducerField();
        InstructionList il = jm.getInstructionList();
        InstructionFactory factory = il.getInstructionFactory();

        HotSpotLocator hsl =
            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()));
View Full Code Here


    private void addClassForNameInstructions(String name, InstructionList il) {
        InstructionFactory f = il.getInstructionFactory();

        InstructionList nl = il.createEmptyList();
       
        // NOTE: We do not create exception handlers for
        //       Class.forName(...) invocation.
        //       However, we use this to get Class of the running object,
        //       so its Class is allways found.
        try {
            nl.add(f.pushConstant(name));
            nl.add(f.invoke(Modifier.STATIC, "java.lang.Class",
                            "forName", new Signature("java.lang.Class",
                                                     new String[] {"java.lang.String"})));
        }
        catch(Exception e) {
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of alt.jiapi.reflect.InstructionList

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.