Package alt.jiapi.reflect.instruction

Examples of alt.jiapi.reflect.instruction.Invocation


     *
     * @return Name of the hotspot
     */
    public String getName() {
        if (endIns instanceof Invocation) {
            Invocation inv = (Invocation)endIns;
            StringBuffer sb = new StringBuffer();
            if (!"<init>".equals(inv.getMethodName())) {
                sb.append(inv.getReturnType());
                sb.append(' ');
            }

            sb.append(inv.getClassName());
            sb.append('.');
            sb.append(inv.getMethodName());
            sb.append('(');

            String[] params = inv.getParameterTypes();
            for (int i = 0; i < params.length; i++) {
                sb.append(params[i]);
                if (i < params.length - 1) {
                    sb.append(',');
                }
View Full Code Here


            case Opcodes.INVOKEVIRTUAL:
            case Opcodes.INVOKESPECIAL:
            case Opcodes.INVOKESTATIC:
                // BUG: what is the stack consumption
                // cp.getMethodDescriptor(....);
                ins = new Invocation(new byte[] { byteCode[i],
                                                  byteCode[i+1],
                                                  byteCode[i+2] }, cp);
                iMod = 2;//i += 2;
                break;
            case Opcodes.INVOKEINTERFACE:
                byte count = byteCode[i+3];
                ins = new Invocation(new byte[] { byteCode[i],
                                                  byteCode[i+1],
                                                  byteCode[i+2],
                                                  count,
                                                  byteCode[i+4]}, cp);
                iMod = 4;//i += 4;
View Full Code Here

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

        Instruction instruction = new Invocation(bytes, cp);

        return instruction;
    }
View Full Code Here

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

        Instruction instruction = new Invocation(bytes, cp); // new Instruction(bytes);

        return instruction;
    }
View Full Code Here

            InstructionList il = adviceMethod.getInstructionList();
            HotSpotLocator hsl = new HotSpotLocator(il, Opcodes.INVOKEVIRTUAL);

            HotSpot[] dohsCandidates = hsl.getHotSpots();
            for (int i = 0; i < dohsCandidates.length; i++) {
                Invocation inv =
                    (Invocation)dohsCandidates[i].getHotSpotInstruction();

                if (!inv.getClassName().equals(adviceMethod.getDeclaringClass().getName())) {
                    // Process only calls to HotSpotAdvice class
                    continue;
                }

                if ("doHotSpot".equals(inv.getMethodName())) {
//                     if (inv.getAttribute("synthetic") != null) {
//                         // Found it
//                         return il.indexOf(inv);
//                     }
//                     continue;
View Full Code Here

            // advice method.
            HotSpotLocator hsl = new HotSpotLocator(il, Opcodes.INVOKEVIRTUAL);

            HotSpot[] triggerCandidates = hsl.getHotSpots();
            for (int i = 0; i < triggerCandidates.length; i++) {
                Invocation inv =
                    (Invocation)triggerCandidates[i].getHotSpotInstruction();

                if (!inv.getClassName().equals(adviceMethod.getDeclaringClass().getName())) {
                    // Process only calls to HotSpotAdvice class
                    continue;
                }

                // Index of the trigger instruction
                int idx = il.indexOf(inv);

                // Following assumes, that trigger call is
                // void-void method.
                // First, we remove a call to Advice class...
                InstructionList view = il.createView(idx-1, idx + 1);
    view.clear();

                // ...then we replace, that call with trigger action
                // instructions.
                if ("getHotSpotName".equals(inv.getMethodName())) {
                    view.add(factory.pushConstant(hs.getName()));
                }
                else if ("getArguments".equals(inv.getMethodName())) {
                    // NOT IMPLEMENTED
                    // This needs some further thinking before implementing
                }
                else if ("getInstrumentedObject".equals(inv.getMethodName())) {
        JiapiMethod jm = il.getDeclaringMethod();
        int modifiers = jm.getModifiers();
        if (Modifier.isStatic(modifiers)) {
      // Static methods do not have reference to 'this'
      //view.add(factory.pushNull());
View Full Code Here

        // Find invokeXXX instructions
        while ((index = il.indexOf(OpcodeGroups.INVOKE_INSTRUCTIONS,
                                   index)) != -1) {
//              Instruction ins = il.get(index);
//              Operand o = ins.getOperand();
            Invocation ins = (Invocation)il.get(index);
            String targetName = ins.getClassName() + "." + ins.getMethodName();
            // Grep
            //if (match(o.toString())) {
            if (match(targetName)) {
                Instrumentation i = getInstrumentation();
                //i.setTargetName(o.toString());
View Full Code Here

        }


        int idx = -1;
        while ((idx = il.indexOf(OpcodeGroups.INVOKE_INSTRUCTIONS, idx+1)) != -1) {
            Invocation ins = (Invocation)il.get(idx);
            if (!match(ins.getClassName() + "." + ins.getMethodName())) {
                continue;
            }


//             if (System.getProperty("no-lfix") == null) {
//                 // --- bug workaround  for long/doubles in method params
//                 boolean bailOutForLongDoubleSyndrome = false;
//                 String[] i_params = ins.getParameterTypes();
//                 for (int i = 0; i < i_params.length; i++) {
//                     if ("double".equals(i_params[i]) ||
//                         "long".equals(i_params[i])) {
//                         bailOutForLongDoubleSyndrome = true;
//                         break;
//                     }
//                 }
//                 if (bailOutForLongDoubleSyndrome) {
//                     log.warn("Will not instrument invocations to methods with long or double as parameter: In " + jm.getDeclaringClass().getName() + "#" + jm +
//                              ", a call to " + ins + ". This is a workaround for bug in jiapi.");
//                     continue;
//                 }
//                 // --- bug workaround  for long/doubles in method params
//             }

            // We support only these methods at the moment.
            if (ins.getOpcode() != Opcodes.INVOKESTATIC &&
                ins.getOpcode() != Opcodes.INVOKEVIRTUAL) {
                continue;
            }

            JiapiField interceptor = getEventProducerField();
       
//              InstructionList nList = il.createEmptyList();
            InstructionList nList = new InstructionList();


            // each entry in pList holds creation of one argument
            // to method invocation
//             InstructionList[] pLists = createArgumentLists(il, idx);
            ArgumentList al = createArgumentLists(il, idx);
            InstructionList[] pLists = al.arguments;
            int paramIdx = al.paramIndex;

            short opCode = ins.getOpcode();
            if (opCode == Opcodes.INVOKEVIRTUAL ||
                opCode == Opcodes.INVOKESPECIAL) {
                paramIdx--; // Include object ref
            }

            // Generate code, that replaces invocation with a new
            // invocation to InvokeHandler
            switch(opCode) {
            case Opcodes.INVOKEVIRTUAL:
            case Opcodes.INVOKESTATIC:

                nList.add(factory.getField(interceptor)); // Interceptor
                if (opCode == Opcodes.INVOKESTATIC) {
//                     addClassForNameInstructions(jm.getDeclaringClass().getName(), nList);
                    addClassForNameInstructions(ins.getClassName(), nList);
                   
                }
                else {
                    nList.add(il.get(paramIdx)); // objref
                }

                String mName = ins.getMethodName();
                //nList.add(factory.getField(rField));
                nList.add(factory.pushConstant(mName));
                nList.add(factory.newArray("java.lang.Object",
                                           ins.getParameterTypes().length));

                String[] i_params = ins.getParameterTypes();
                // Populate Object array with call parameters
                for (int i = 0; i < pLists.length; i++) {
                    if ("long".equals(i_params[i])) {
                        nList.add(factory.dup());
                    }
                    else if ("double".equals(i_params[i])) {
                        nList.add(factory.dup());
                    }
                    else {
                        nList.add(factory.dup());
                    }
                    nList.add(factory.pushConstant(i));
                    nList.add(pLists[i]);
                    nList.add(factory.aastore());
                }

                // Add Methods signature
//                 nList.add(factory.pushConstant(ins.getDescriptor()));
                // Add cache-key
                nList.add(factory.pushConstant(ins.getClassName() + ins.getMethodName() + ins.getDescriptor()));

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

                handleReturnValue(nList, ins);
View Full Code Here

    /**
     * Create an array of InstructionLists. Each element in array
     * represents one argument of a method invocation.
     */
    private ArgumentList createArgumentLists(InstructionList il, int invocationIndex) {
        Invocation ins = (Invocation)il.get(invocationIndex);

//          System.out.println("Creating arg list for " + ins);

        String[] paramTypes = ins.getParameterTypes();
        InstructionList[] argList =
            new InstructionList[paramTypes.length];

        // First pIdx points to Instruction just before Invocation
        int pIdx = invocationIndex - 1;

//         for (int i = 0; i < argList.length; i++) {
         for (int i = argList.length - 1; i >= 0; i--) {
            int stackUsage = ins.stackConsumption();
            InstructionList pList = il.createEmptyList();

            boolean primitive = SignatureUtil.isPrimitive(paramTypes[i]);
            Instruction pr_ins = null;

            if (primitive) {
                pr_ins = handlePrimitiveType(paramTypes[i], pList);
            }

            int insertIdx = pList.size();
            // When stack usage is 1, we have reached an argument in stack
//             while (stackUsage != 1) {
             while ((stackUsage > 0 && ins.getOpcode() == Opcodes.INVOKESTATIC)||
                    (stackUsage > 1 && ins.getOpcode() == Opcodes.INVOKEVIRTUAL)) {
                Instruction pIns = il.get(pIdx);
//                  System.out.println(">> pIdx: " + pIdx + ": " + pIns +
//                                     ", stackusage: " + stackUsage);
                stackUsage -= pIns.stackUsage();

View Full Code Here

TOP

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

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.