Package org.jboss.byteman.rule.binding

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


        // 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

            recipient.bind();
        } else if (pathList != null) {
            // see if the path starts with a bound variable and, if so, treat the path as a series
            // of field references and construct a owner expression from it.
            String leading = pathList[0];
            Binding binding = getBindings().lookup(leading);
            if (binding != null) {
                // create a sequence of field expressions and make it the recipient

                int l = pathList.length;
                Expression recipient =  new Variable(rule, binding.getType(), token, binding.getName());
                for (int idx = 1; idx < l; idx++) {
                    recipient = new FieldExpression(rule, Type.UNDEFINED, token, pathList[idx], recipient, null);
                }
                this.recipient = recipient;
                this.pathList = null;
View Full Code Here

    private boolean bind(boolean isUpdateable)throws TypeException
    {
        // ensure that there is a binding with this name

        Binding binding = getBindings().lookup(name);

        if (binding == null) {
            throw new TypeException("Variable.bind : unbound variable " + name + getPos());
        }

        // if necessary tag it as updateable
        if (isUpdateable) {
            binding.setUpdated();
        }
       
        // adopt the binding type

        this.type = binding.getType();

        return true;
    }
View Full Code Here

    }

    public Type typeCheck(Type expected) throws TypeException {
        // type must be defined by now or we are in trouble

        Binding binding = getBindings().lookup(name);

        type = Type.dereference(binding.getType());

        if (type.isUndefined()) {
            throw new TypeException("Variable.typeCheck : unable to derive type for variable " + name +  getPos());
        }
        if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
View Full Code Here

        } else {
            // see if the path starts with a bound variable and, if so, treat the path as a series
            // of field references and construct a owner expression from it. if not we will have to
            // wait until runtime in order to resolve this as a static field reference
            String leading = pathList[0];
            Binding binding = getBindings().lookup(leading);
            if (binding != null) {
                // create a sequence of field expressions and make it the owner

                int l = pathList.length;
                Expression owner =  new Variable(rule, binding.getType(), token, binding.getName());
                for (int idx = 1; idx < l; idx++) {
                    owner = new FieldExpression(rule, Type.UNDEFINED, token, pathList[idx], owner, null);
                }
                this.owner = owner;
                this.pathList = null;
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

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.