Example usage for org.objectweb.asm.tree.analysis BasicValue equals

List of usage examples for org.objectweb.asm.tree.analysis BasicValue equals

Introduction

In this page you can find the example usage for org.objectweb.asm.tree.analysis BasicValue equals.

Prototype

@Override
    public boolean equals(final Object value) 

Source Link

Usage

From source file:edu.ubc.mirrors.holograms.BetterVerifier.java

License:Open Source License

@Override
public BasicValue merge(final BasicValue v, final BasicValue w) {
    if (!v.equals(w)) {
        Type t = v.getType();/*w ww .j a  v a2s.c o m*/
        Type u = w.getType();
        if (t != null && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY)) {
            if (u != null && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY)) {
                if ("Lnull;".equals(t.getDescriptor())) {
                    return w;
                }
                if ("Lnull;".equals(u.getDescriptor())) {
                    return v;
                }
                if (isAssignableFrom(t, u)) {
                    return v;
                }
                if (isAssignableFrom(u, t)) {
                    return w;
                }

                if (t.getSort() == Type.ARRAY && u.getSort() == Type.ARRAY) {
                    BasicValue vComp = new BasicValue(
                            Reflection.makeArrayType(t.getDimensions() - 1, t.getElementType()));
                    BasicValue wComp = new BasicValue(
                            Reflection.makeArrayType(u.getDimensions() - 1, u.getElementType()));
                    BasicValue mergedComp = merge(vComp, wComp);
                    if (!mergedComp.equals(BasicValue.UNINITIALIZED_VALUE)) {
                        Type mergedCompType = mergedComp.getType();
                        return new BasicValue(Reflection.makeArrayType(1, mergedCompType));
                    }
                }

                do {
                    if (t == null || isInterface(t)) {
                        return BasicValue.REFERENCE_VALUE;
                    }
                    t = getSuperClass(t);
                    if (isAssignableFrom(t, u)) {
                        return newValue(t);
                    }
                } while (true);
            }
        }
        return BasicValue.UNINITIALIZED_VALUE;
    }
    return v;
}

From source file:jaspex.speculation.newspec.FlowFrame.java

License:Open Source License

/** Converte lista de BasicValues no formato usado no visitFrame **/
private static Object[] convertToFrame(UtilList<BasicValue> values, boolean locals) {
    UtilList<Object> outList = new UtilArrayList<Object>();
    int top = 0;/*from  www  .j  ava2s . c  om*/

    for (int i = 0; i < values.size(); i++) {
        BasicValue v = values.get(i);

        if (v.equals(BasicValue.UNINITIALIZED_VALUE) && locals) {
            // Os locals so criados logo com o tamanho do MAXLOCALS, mas com
            // UNINITIALIZED_VALUE at serem usados
            // Mesmo assim, podem existir outros locals usados, e temos
            // que introduzir algo na lista para as posies no mudarem

            // Por vezes um UninitializedValue est no lugar de um top
            if (i > 0 && (values.get(i - 1).equals(BasicValue.LONG_VALUE)
                    || values.get(i - 1).equals(BasicValue.DOUBLE_VALUE))) {
                top++;
                continue;
            }
            outList.add("jaspex/HACK/UninitializedValue");
            continue;
        }
        if (v instanceof MergedUninitializedValue) {
            // Normalmente no devia ser deixado um MergedUninitializedValue
            // na stack/locals, mas tal pode acontecer quando no faz diferena
            // nenhuma no bloco (por exemplo porque vai fazer return)
            outList.add("jaspex/HACK/MergedUninitializedValue");
            continue;
        }
        if (v.getType() == null || v.equals(BasicValue.RETURNADDRESS_VALUE)) {
            throw new AssertionError("FIXME");
        }
        Type type = v.getType();
        Object convertedType;
        switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.BYTE:
        case Type.CHAR:
        case Type.SHORT:
        case Type.INT:
            convertedType = Opcodes.INTEGER;
            break;
        case Type.FLOAT:
            convertedType = Opcodes.FLOAT;
            break;
        case Type.LONG:
            convertedType = Opcodes.LONG;
            break;
        case Type.DOUBLE:
            convertedType = Opcodes.DOUBLE;
            break;
        case Type.ARRAY:
        case Type.OBJECT:
            convertedType = type.getInternalName();
            break;
        default:
            throw new AssertionError();
        }
        outList.add(convertedType);
    }

    assert ((outList.size() + top) == values.size());
    return outList.toArray();
}

From source file:jaspex.speculation.newspec.FlowFrame.java

License:Open Source License

@Override
/** Implementao do merge que mantm informao dos dois tipos que originaram o merge
  * num MergedUninitializedValue.//w w  w.j av a  2s.c om
  **/
public BasicValue merge(BasicValue v, BasicValue w) {
    BasicValue value = super.merge(v, w);
    if (!v.equals(w)) {
        boolean isFutureV = isFuture(v);
        boolean isFutureW = isFuture(w);
        if ((value.equals(BasicValue.UNINITIALIZED_VALUE) && (isFutureV || isFutureW
                || v instanceof MergedUninitializedValue || w instanceof MergedUninitializedValue)) ||
        // Nota: REFERENCE_VALUE parece ocorrer quando ASM est a tomar atalhos
        // e no lhe "apetece" ver quais os verdadeiros tipos
                (value.equals(BasicValue.REFERENCE_VALUE) && (isFutureV || isFutureW)) ||
                // ASM considera merge(null, T) = T, mas quando T  um Futuro, no podemos
                // assumir isso, pois por exemplo podem existir dois caminhos: um que coloca
                // null na pilha, e outro um futuro, como exemplificado no NewSpecExample28
                (isFutureV && "null".equals(w.getType().getInternalName()))
                || (isFutureW && "null".equals(v.getType().getInternalName()))) {
            BasicValue muv = new MergedUninitializedValue(v, w);
            return muv.equals(v) ? v : muv.equals(w) ? w : muv;
        }
    }
    if (value.equals(BasicValue.REFERENCE_VALUE) && !value.equals(v) && !value.equals(w)) {
        // Ou os dois tipos s tem Object em comum, ou s tm uma interface em comum e
        // o ASM no faz o trabalho de a descobrir
        Type tv = v.getType();
        Type tw = w.getType();
        if (tv != null && tw != null) {
            Type commonInterface = ClassHierarchy.getBestCommonInterface(tv, tw);
            if (commonInterface != null)
                return newValue(commonInterface);
        }
    }
    return value;
}

From source file:org.apache.flink.api.java.sca.NestedMethodAnalyzer.java

License:Apache License

@Override
public BasicValue merge(BasicValue v, BasicValue w) {
    // values are not equal
    // BasicValue's equals method is too general
    if ((!isTagged(v) && !w.equals(v)) || (isTagged(v) && !v.equals(w))) {
        // w is a BasicValue
        if (isTagged(v) && !isTagged(w)) {
            return new TaggedValue(w.getType());
        }/*from   ww w .ja v  a2 s  .  c  om*/
        // v is a BasicValue or uninteresting and w is a interesting TaggedValue
        else if ((!isTagged(v) || tagged(v).canNotContainInput()) && isTagged(w)
                && tagged(w).canContainInput()) {
            final TaggedValue taggedW = tagged(w);
            if (hasImportantDependencies(taggedW) && rightMergePriority) {
                // w has a merge priority, its grouped inputs will be returned
                final TaggedValue returnValue = removeUngroupedInputs(taggedW.copy());
                if (returnValue != null) {
                    return returnValue;
                } else {
                    return new TaggedValue(v.getType());
                }
            }
            return new TaggedValue(v.getType());
        }
        // v is a BasicValue and w is a uninteresting TaggedValue
        else if (!isTagged(v) && isTagged(w) && tagged(w).canNotContainInput()) {
            return v;
        }
        // merge v and w (both TaggedValues), v is interesting
        else if (isTagged(v) && isTagged(w) && tagged(v).canContainInput()) {
            final List<TaggedValue> list = Arrays.asList(tagged(v), tagged(w));
            final TaggedValue returnValue = mergeReturnValues(list);
            if (returnValue != null) {
                return returnValue;
            }
        }
        // v is a TaggedValue and uninteresting
        else if (isTagged(v) && tagged(v).canNotContainInput()) {
            return v;
        }
        // v and w are BasicValues and not equal
        return BasicValue.UNINITIALIZED_VALUE;
    }
    // v and w are equal, return one of them
    return v;
}

From source file:org.spongepowered.asm.util.Locals.java

License:MIT License

/**
 * Use ASM Analyzer to generate the local variable table for the specified
 * method/*from   www.  j a  v a2 s.  co  m*/
 * 
 * @param classNode Containing class
 * @param method Method
 * @return generated local variable table
 */
public static List<LocalVariableNode> generateLocalVariableTable(ClassNode classNode, MethodNode method) {
    List<Type> interfaces = null;
    if (classNode.interfaces != null) {
        interfaces = new ArrayList<Type>();
        for (String iface : classNode.interfaces) {
            interfaces.add(Type.getObjectType(iface));
        }
    }

    Type objectType = null;
    if (classNode.superName != null) {
        objectType = Type.getObjectType(classNode.superName);
    }

    // Use Analyzer to generate the bytecode frames
    Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(
            new SimpleVerifier(Type.getObjectType(classNode.name), objectType, interfaces, false));
    try {
        analyzer.analyze(classNode.name, method);
    } catch (AnalyzerException ex) {
        ex.printStackTrace();
    }

    // Get frames from the Analyzer
    Frame<BasicValue>[] frames = analyzer.getFrames();

    // Record the original size of hte method
    int methodSize = method.instructions.size();

    // List of LocalVariableNodes to return
    List<LocalVariableNode> localVariables = new ArrayList<LocalVariableNode>();

    LocalVariableNode[] localNodes = new LocalVariableNode[method.maxLocals]; // LocalVariableNodes for current frame
    BasicValue[] locals = new BasicValue[method.maxLocals]; // locals in previous frame, used to work out what changes between frames
    LabelNode[] labels = new LabelNode[methodSize]; // Labels to add to the method, for the markers

    // Traverse the frames and work out when locals begin and end
    for (int i = 0; i < methodSize; i++) {
        Frame<BasicValue> f = frames[i];
        if (f == null) {
            continue;
        }
        LabelNode label = null;

        for (int j = 0; j < f.getLocals(); j++) {
            BasicValue local = f.getLocal(j);
            if (local == null && locals[j] == null) {
                continue;
            }
            if (local != null && local.equals(locals[j])) {
                continue;
            }

            if (label == null) {
                label = new LabelNode();
                labels[i] = label;
            }

            if (local == null && locals[j] != null) {
                localVariables.add(localNodes[j]);
                localNodes[j].end = label;
                localNodes[j] = null;
            } else if (local != null) {
                if (locals[j] != null) {
                    localVariables.add(localNodes[j]);
                    localNodes[j].end = label;
                    localNodes[j] = null;
                }

                String desc = (local.getType() != null) ? local.getType().getDescriptor() : null;
                localNodes[j] = new LocalVariableNode("var" + j, desc, null, label, null, j);
            }

            locals[j] = local;
        }
    }

    // Reached the end of the method so flush all current locals and mark the end
    LabelNode label = null;
    for (int k = 0; k < localNodes.length; k++) {
        if (localNodes[k] != null) {
            if (label == null) {
                label = new LabelNode();
                method.instructions.add(label);
            }

            localNodes[k].end = label;
            localVariables.add(localNodes[k]);
        }
    }

    // Insert generated labels into the method body
    for (int n = methodSize - 1; n >= 0; n--) {
        if (labels[n] != null) {
            method.instructions.insert(method.instructions.get(n), labels[n]);
        }
    }

    return localVariables;
}