Package org.jboss.byteman.rule.binding

Examples of org.jboss.byteman.rule.binding.Binding


        // identify which is the last index we will need to update. n.b. if we find a return value we will
        // update that last

        for (int i = 0; i < arraySize; i++) {
            Binding binding = callArrayBindings.get(i);
            if (binding.isUpdated()) {
                lastUpdated = i;
                if (binding.isReturn()) {
                    returnIdx = i;
                }
            }
        }
       
        // if the return value is updated it gets done last
        if (returnIdx >= 0) {
            lastUpdated = returnIdx;
        }

        // write back all other args then stack new return value and drop old one
        for (int i = 0; i < arraySize; i++) {
            Binding binding = callArrayBindings.get(i);
            if (binding.isUpdated() && !binding.isReturn()) {
                // if this is the last update then we consume the arguments array
                // otherwise we need to copy it
                if (i != lastUpdated) {
                    dup();
                }
                push(i);
                arrayLoad(objectType);
                if (binding.isParam()) {
                    int idx = binding.getIndex() - 1;
                    unbox(argumentTypes[idx]);
                    storeArg(idx);
                } else if (binding.isLocalVar()) {
                    int idx = binding.getLocalIndex();
                    Type t = getLocalType(idx);
                    // cannot always trust locals flagged as Object type because we sometimes
                    // insert that when we see an ALOAD for a local var we do not know about.
                    // but we can rely on the descriptor in the binding which we derived during
                    // rule check processing
                    if (t.getClassName().equals("java.lang.Object")) {
                        String descriptor = binding.getDescriptor();
                        t = Type.getType("L" + descriptor.replace('.', '/') + ";");
                    }
                    unbox(t);
                    storeLocal(idx);
                }
View Full Code Here


        Bindings bindings = rule.getBindings();
        Iterator<Binding> iterator = bindings.iterator();

        while (iterator.hasNext()) {
            Binding binding = iterator.next();

            if (binding.getType() == Type.UNDEFINED) {
                if (binding.isRecipient()) {
                    binding.setDescriptor(targetClassName);
                } else if (binding.isParam()) {
                    int idx = binding.getIndex();
                    // n.b. param indices are 1-based so use > here not >=
                    if (idx > paramCount) {
                        errorCount++;
                        System.err.println("ERROR : Invalid method parameter reference $" + idx  + " in rule \"" + rule.getName() + "\"");
                    } else {
                        binding.setDescriptor(paramTypes.get(idx - 1));
                    }
                } else if (binding.isReturn()) {
                    if (rule.getTargetLocation().getLocationType() != LocationType.INVOKE_COMPLETED) {
                        // return type is on end of list
                        String returnType = paramTypes.get(paramCount);
                        if ("void".equals(returnType)) {
                            errorCount++;
                            System.err.println("ERROR : Invalid return value reference $! in rule \"" + rule.getName() + "\"");
                        } else {
                            binding.setDescriptor(returnType);
                        }
                    } else {
                        warningCount++;
                        System.err.println("WARNING : cannot infer type for $! in AFTER INVOKE rule \"" + rule.getName() + "\"");
                        binding.setDescriptor("void");
                    }
                } else if (binding.isLocalVar()) {
                    warningCount++;
                    System.err.println("WARNING : Cannot typecheck local variable " + binding.getName()  + " in rule \"" + rule.getName() + "\"");
                    binding.setDescriptor("void");
                }
            }
        }

        return errorCount;
View Full Code Here

        // check the local var bindings and, if any of them are actually refereces to method params
        // alias them to the corresponding param binding

        while (iterator.hasNext()) {
            Binding binding = iterator.next();
            if  (binding.isLocalVar()){
                int localIdx = binding.getLocalIndex();
                if (localIdx < argLocalIndex) {
                    binding = alias(binding, bindings, localIdx);
                    if (binding != null) {
                        // the aliased param binding was not present so ensure it gets added to the
                        // binding set once we have finished iterating. there is no need to add it
                        // to the call bindings since we pass the aliased method param instead
                        aliasBindings.add(binding);
                    }
                } else {
                    callArrayBindings.add(binding);
                }
            }
        }

        bindings.addBindings(aliasBindings);
       
        // now iterate over the param vars and ensure they go into the call bindings list

        iterator = bindings.iterator();
       
        while (iterator.hasNext()) {
            Binding binding = iterator.next();
            if (binding.isParam()) {
                callArrayBindings.add(binding);
            } else if (binding.isReturn()) {
                // in order to be able to add the return value to the args array
                // we have to add a local var to store the value so track that requirement
                bindReturnOrThrowableValue = true;
                saveValueType = getReturnBindingType();
                binding.setDescriptor(saveValueType.getClassName());
                callArrayBindings.add(binding);
            } else if (binding.isThrowable()) {
                // in order to be able to add the return value or throwable value to the args array
                // we have to add a local var to store the value so track that requirement
                bindReturnOrThrowableValue = true;
                // TODO -- allow type to be more accurately identified than this
                saveValueType = Type.getType("Ljava/lang/Throwable;");
                callArrayBindings.add(binding);
            } else if (binding.isParamCount() || binding.isParamArray()) {
                callArrayBindings.add(binding);
            } else if (binding.isInvokeParamArray()) {
                // in order to be able to ad th einvoke parameters to the args array we
                // have to add a local var to store the value so track that requirement
                callArrayBindings.add(binding);
                bindInvokeParams = true;
            }
View Full Code Here

    private Binding alias(Binding binding, Bindings bindings, int localIdx)
    {
        if (((access & Opcodes.ACC_STATIC) == 0) && (localIdx == 0)) {
            String name = "$0";
            Binding alias = bindings.lookup(name);
            if (alias == null) {
                alias = new Binding(rule, name);
                alias.setDescriptor(binding.getDescriptor());
                alias.setLocalIndex(binding.getLocalIndex());
                binding.aliasTo(alias);
                // alias var was new so return it for addition to the binding set
                return alias;
            } else {
                // just alias the binding
                binding.aliasTo(alias);
                return null;
            }
        }

        for (int i = 0; i < argLocalIndices.length; i++) {
            if (argLocalIndices[i] == localIdx) {
                String name = "$" + (i + 1);
                Binding alias = bindings.lookup(name);
                if (alias == null) {
                    alias = new Binding(rule, name);
                    alias.setDescriptor(binding.getDescriptor());
                    alias.setLocalIndex(binding.getLocalIndex());
                    binding.aliasTo(alias);
                    // alias var was new so return it for addition to the binding set
                    return alias;
                } else {
                    // just alias the binding
View Full Code Here

        // once the call ahs completed

        boolean doUpdates = false;

        for (int i = 0; i < arraySize; i++) {
            Binding binding = callArrayBindings.get(i);
            if (binding.isUpdated()) {
                doUpdates = true;
                break;
            }
        }

        if (doUpdates) {
            // insert copy of array below first two call arguments
            // [.. key owner bindings ] ==> [.. bindings key owner bindings ]
            mv.visitInsn(Opcodes.DUP_X2);
        }

        // now install required values into bindings array
        for (int i = 0; i < arraySize; i++) {
            Binding binding = callArrayBindings.get(i);
            dup();
            push(i);
            if (binding.isParam()) {
                int idx = binding.getIndex() - 1;
                loadArg(idx);
                box(argumentTypes[idx]);
            } else if (binding.isLocalVar()){
                int idx = binding.getLocalIndex();
                loadLocal(idx);
                box(getLocalType(idx));
            } else if (binding.isParamCount()){
                int count = argumentTypes.length;
                push(count);
                box(Type.INT_TYPE);
            } else if (binding.isParamArray()){
                int count = argumentTypes.length;
                push(count + 1);
                newArray(objectType);
                dup();
                push(0);
                if ((access & Opcodes.ACC_STATIC) == 0) {
                    loadThis();
                } else {
                    push((Type)null);
                }
                arrayStore(objectType);
                for (int idx = 0; idx < count; idx++) {
                    dup();
                    push(idx + 1);
                    loadArg(idx);
                    box(argumentTypes[idx]);
                    arrayStore(objectType);
                }
            } else if (binding.isInvokeParamArray()){
                loadLocal(saveSlot);
            } else if (binding.isThrowable() | binding.isReturn()){
                loadLocal(saveSlot);
                box(saveValueType);
            }
            arrayStore(objectType);
        }
View Full Code Here

        // identify which is the last index we will need to update. n.b. if we find a return value we will
        // update that last

        for (int i = 0; i < arraySize; i++) {
            Binding binding = callArrayBindings.get(i);
            if (binding.isUpdated()) {
                lastUpdated = i;
                if (binding.isReturn()) {
                    returnIdx = i;
                }
            }
        }
       
        // if the return value is updated it gets done last
        if (returnIdx >= 0) {
            lastUpdated = returnIdx;
        }

        // write back all other args then stack new return value and drop old one
        for (int i = 0; i < arraySize; i++) {
            Binding binding = callArrayBindings.get(i);
            if (binding.isUpdated() && !binding.isReturn()) {
                // if this is the last update then we consume the arguments array
                // otherwise we need to copy it
                if (i != lastUpdated) {
                    dup();
                }
                push(i);
                arrayLoad(objectType);
                if (binding.isParam()) {
                    int idx = binding.getIndex() - 1;
                    unbox(argumentTypes[idx]);
                    storeArg(idx);
                } else if (binding.isLocalVar()) {
                    int idx = binding.getLocalIndex();
                    unbox(getLocalType(idx));
                    storeLocal(idx);
                }
            }
        }
View Full Code Here

        List<String> parameterTypenames = Type.parseMethodDescriptor(descriptor, true);
        int parameterCount = parameterTypenames.size() - 1; // allows for return type

        // make sure all entries are valid
        while (bindingIter.hasNext()) {
            Binding binding = bindingIter.next();
            if (binding.isRecipient()) {
                if ((access & Opcodes.ACC_STATIC) != 0) {
                    if (Transformer.isVerbose()) {
                        System.out.println("RuleCheckMethodAdapter.checkBindings : found invalid recipient binding " + binding + " checking static method " + name + descriptor);
                    }
                    return false;
                }
            } else if (binding.isParam()) {
                int idx = binding.getIndex();
                if (idx > parameterCount) {
                    // parameter out of range
                    if (Transformer.isVerbose()) {
                        System.out.println("RuleCheckMethodAdapter.checkBindings : found out of range parameter binding " + binding + " checking method " + name + descriptor);
                    }
                    return false;
                } else {
                    binding.setDescriptor(parameterTypenames.get(idx - 1));
                }
            } else if (binding.isReturn()) {
                // this is a valid reference in an AT EXIT rule and in an AFTER INVOKE
                LocationType locationType = rule.getTargetLocation().getLocationType();
                if (locationType != LocationType.EXIT && locationType != LocationType.INVOKE_COMPLETED) {
                    System.out.println("RuleCheckMethodAdapter.checkBindings : found return value binding $! in rule which is neither AT EXIT nor AFTER INVOKE " + rule.getName());
                    return false;
                }
            } else if (binding.isThrowable()) {
                // we can only allow reference to the current throwable in an AT THROW rule
                if (rule.getTargetLocation().getLocationType() != LocationType.THROW) {
                    System.out.println("RuleCheckMethodAdapter.checkBindings : found throwable value binding $^ in non-THROW rule " + rule.getName());
                    return false;
                }
                // we will need to set the descriptor at some point
            } else if (binding.isParamArray()) {
                // this is ok
            } else if (binding.isParamCount()) {
                // this is ok
            } else if (binding.isInvokeParamArray()) {
                // we can only allow reference to the invoked method parameters in an AT INVOKE rule
                if (rule.getTargetLocation().getLocationType() != LocationType.INVOKE) {
                    System.out.println("RuleCheckMethodAdapter.checkBindings : found invoke parameter array binding $@ in non-AT INVOKE rule " + rule.getName());
                    return false;
                }
            } else if (binding.isLocalVar()){
                // make sure we have a local variable with the correct name
                String localVarName = binding.getName().substring(1);
                List<LocalVar> localVars = lookup(localVarName);

                if (localVars == null || localVars.isEmpty()) {
                    if (Transformer.isVerbose()) {
                        System.out.println("RuleCheckMethodAdapter.checkBindings : unknown local variable binding " + binding + " checking method " + name + descriptor);
                    }
                    return false;
                } else {
                    String descriptor = null;
                    int index = -1;
                    Iterator<Label> labelIter = triggerPoints.iterator();
                    while (labelIter.hasNext()) {
                        int triggerPos = labelIter.next().getOffset();
                        boolean found = false;
                        Iterator<LocalVar> localVarIter = localVars.iterator();
                        while (localVarIter.hasNext()) {
                            LocalVar localVar = localVarIter.next();
                            int start = localVar.start.getOffset();
                            int end = localVar.end.getOffset();
                            if (start <= triggerPos && triggerPos < end) {
                                // only accept if the descriptor and index are the same or are not yet set
                                if (descriptor == null && index == -1) {
                                    descriptor = localVar.desc;
                                    index = localVar.index;
                                    found = true;
                                } else if (descriptor.equals(localVar.desc) && index == localVar.index) {
                                    found = true;
                                }
                                // terminate the loop here
                                break;
                            }
                        }
                        // if there was no variable for this trigger point then fail
                        if (!found) {
                            if (Transformer.isVerbose()) {
                                System.out.println("RuleCheckMethodAdapter.checkBindings : invalid local variable binding " + binding + " checking method " + name + descriptor);
                            }
                            return false;
                        }
                    }
                    // if we got here then we have a unique local var descriptor and index for
                    // all trigger points so update the binding

                    binding.setDescriptor(Type.parseFieldDescriptor(descriptor));
                    binding.setLocalIndex(index);
                }
            }
        }
        // ok all local vars and params are accounted for so return true
View Full Code Here

        Bindings bindings = rule.getBindings();
        Iterator<Binding> iterator = bindings.iterator();

        while (iterator.hasNext()) {
            Binding binding = iterator.next();

            if (binding.getType() == Type.UNDEFINED) {
                if (binding.isRecipient()) {
                    binding.setDescriptor(targetClassName);
                } else if (binding.isParam()) {
                    int idx = binding.getIndex();
                    // n.b. param indices are 1-based so use > here not >=
                    if (idx > paramCount) {
                        errorCount++;
                        System.err.println("ERROR : Invalid method parameter reference $" + idx  + " in rule \"" + rule.getName() + "\"");
                    } else {
                        binding.setDescriptor(paramTypes.get(idx - 1));
                    }
                } else if (binding.isLocalVar()) {
                    warningCount++;
                    System.err.println("WARNING : Cannot typecheck local variable " + binding.getName()  + " in rule \"" + rule.getName() + "\"");
                }
            }
        }

        return errorCount;
View Full Code Here

    public Type typeCheck(Type expected) throws TypeException {
        // expected must be Type.VOID
        Iterator<Binding> iterator = getBindings().iterator();
        while (iterator.hasNext()) {
            Binding binding = iterator.next();

            typeCheck(binding);
        }
        return Type.VOID;
    }
View Full Code Here

            throw new TypeException(message);
        }

        ParseNode varTree = (ParseNode)bindingTree.getChild(0);
        ParseNode exprTree = (ParseNode)bindingTree.getChild(1);
        Binding binding;

        binding = createBinding(varTree);

        // don't allow current binding to be used when parsing the expression
        // but do use any type supplied for the binding

        Expression expr;

        expr = ExpressionHelper.createExpression(rule, bindings, exprTree, binding.getType());

        // check bindings
        expr.bind();

        String name = binding.getName();

        if (bindings.lookup(name) != null) {
            // oops rebinding not allowed
            String message = "Event.createBindings : rebinding disallowed for variable " + name + varTree.getPos();
            throw new TypeException(message);
        }
        // if the binding type is undefined and the expression type is defined propagate the
        // expression type to the binding
        if (binding.getType() == Type.UNDEFINED && expr.getType() != Type.UNDEFINED) {
            binding.setType(expr.getType());
        }
        binding.setValue(expr);
        bindings.append(binding);
    }
View Full Code Here

TOP

Related Classes of org.jboss.byteman.rule.binding.Binding

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.