Package org.jboss.byteman.rule.binding

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


        // we expect either (COLON IDENTIFIER TYPE) or IDENTIFIER
        switch (tag) {
            case IDENTIFIER:
            {
                return new Binding(rule, varTree.getText());
            }
            case COLON:
            {
                ParseNode child0 = (ParseNode)varTree.getChild(0);
                ParseNode child1 = (ParseNode)varTree.getChild(1);
                if (child0.getTag() != IDENTIFIER) {
                    throw new TypeException("Event.createBindings : unexpected token type in variable declaration" + child0.getTag() + " for token " + child0.getText() + child0.getPos());
                } else if (child1.getTag() != IDENTIFIER && child1.getTag() != ARRAY) {
                    throw new TypeException("Event.createBindings : unexpected token Type in variable type declaration" + child1.getTag()  + " for token " + child1.getText() + child1.getPos());
                }
                Type type = getBindingType(child1);
                if (type == null) {
                    throw new TypeException("Event.createBindings : incompatible type in declaration of variable " + child1.getText() + child1.getPos());
                }
                return new Binding(rule, child0.getText(), type);
            }
            default:
            {
                throw new TypeException("Event.createBindings : unexpected token type in binding variable declaration" + tag + " for token " + varTree.getText() + varTree.getPos());
            }
View Full Code Here


            throws ExecuteException
    {
        Iterator<Binding> iterator = getBindings().iterator();

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

            binding.interpret(helper);
        }
       
        return null;
    }
View Full Code Here

    {
        int currentStack = compileContext.getStackCount();

        Iterator<Binding> iterator = getBindings().iterator();
        while (iterator.hasNext()) {
            Binding binding = iterator.next();

            binding.compile(mv, compileContext);
        }

        // check stack heights
        if (compileContext.getStackCount() != currentStack) {
            throw new CompileException("Event.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + currentStack);
View Full Code Here

        if (!iter.hasNext()) {
            stringWriter.write("BIND NOTHING");
        } else {
            String prefix = "BIND ";
            while (iter.hasNext()) {
                Binding binding = iter.next();
                stringWriter.write(prefix);
                binding.writeTo(stringWriter);
                prefix = ",\n     ";
            }
        }
        stringWriter.write("\n");
    }
View Full Code Here

            System.out.println(rule.getName() + " execute");
        }
        Bindings bindings = rule.getBindings();
        Iterator<Binding> iterator = bindings.iterator();
        while (iterator.hasNext()) {
            Binding binding = iterator.next();
            String name = binding.getName();
            if (binding.isAlias()) {
                // this is a local var used to refer to a method recipient or parameter
                // so use the value and type associated with the alias
                binding = binding.getAlias();
            }
            if (binding.isHelper()) {
                bindingMap.put(name, this);
            } else if (binding.isRecipient()) {
                bindingMap.put(name, recipient);
            // } else if (!binding.isParam() || binding.isLocalVar() || binding.isReturn() ||
            //         binding.isThrowable() || binding.isParamCount() || binding.isParamArray()) {
            } else if (!binding.isBindVar()) {
                bindingMap.put(name, args[binding.getCallArrayIndex()]);
            }
        }

        // now do the actual execution

        execute0();

        // now restore update bindings

        iterator = bindings.iterator();

        while (iterator.hasNext()) {
            Binding binding = iterator.next();
            String name = binding.getName();
            if (binding.isAlias()) {
                continue;
            }

            if (binding.isUpdated()) {
                // if (binding.isParam() || binding.isLocalVar() || binding.isReturn()) {
                if (!binding.isBindVar() && !binding.isAlias()) {
                    Object value = bindingMap.get(name);
                    int idx = binding.getCallArrayIndex();
                    args[idx] = value;
                }
            }
        }
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 = returnType;
                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()) {
                // at some point we will allow reference to the current return value so we need
                // to be sure that the method has a non-void return type
                if (rule.getTargetLocation().getLocationType() != LocationType.EXIT) {
                    System.out.println("RuleCheckMethodAdapter.checkBindings : found return value binding $! in non-EXIT rule " + 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

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.