Search in sources :

Example 11 with BasicValue

use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.

the class Analysis method createStartFrame.

final Frame<BasicValue> createStartFrame() {
    Frame<BasicValue> frame = new Frame<>(methodNode.maxLocals, methodNode.maxStack);
    Type returnType = Type.getReturnType(methodNode.desc);
    BasicValue returnValue = Type.VOID_TYPE.equals(returnType) ? null : new BasicValue(returnType);
    frame.setReturn(returnValue);
    Type[] args = Type.getArgumentTypes(methodNode.desc);
    int local = 0;
    if ((methodNode.access & Opcodes.ACC_STATIC) == 0) {
        frame.setLocal(local++, new AbstractValues.NotNullValue(Type.getObjectType(controlFlow.className)));
    }
    for (int i = 0; i < args.length; i++) {
        BasicValue value;
        if (direction instanceof InOut && ((InOut) direction).paramIndex == i || direction instanceof In && ((In) direction).paramIndex == i) {
            value = new AbstractValues.ParamValue(args[i]);
        } else {
            value = new BasicValue(args[i]);
        }
        frame.setLocal(local++, value);
        if (args[i].getSize() == 2) {
            frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
        }
    }
    while (local < methodNode.maxLocals) {
        frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
    }
    return frame;
}
Also used : Frame(org.jetbrains.org.objectweb.asm.tree.analysis.Frame) Type(org.jetbrains.org.objectweb.asm.Type) In(com.intellij.codeInspection.bytecodeAnalysis.Direction.In) InOut(com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut) BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)

Example 12 with BasicValue

use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.

the class NegationInterpreter method analyze.

final void analyze() throws AnalyzerException, NegationAnalysisFailure {
    Frame<BasicValue> frame = createStartFrame();
    int insnIndex = 0;
    while (true) {
        AbstractInsnNode insnNode = methodNode.instructions.get(insnIndex);
        switch(insnNode.getType()) {
            case AbstractInsnNode.LABEL:
            case AbstractInsnNode.LINE:
            case AbstractInsnNode.FRAME:
                insnIndex = controlFlow.transitions[insnIndex][0];
                break;
            default:
                switch(insnNode.getOpcode()) {
                    case IFEQ:
                    case IFNE:
                        BasicValue conValue = popValue(frame);
                        checkAssertion(conValue instanceof TrackableCallValue);
                        frame.execute(insnNode, interpreter);
                        conditionValue = (TrackableCallValue) conValue;
                        int jumpIndex = methodNode.instructions.indexOf(((JumpInsnNode) insnNode).label);
                        int nextIndex = insnIndex + 1;
                        proceedBranch(frame, jumpIndex, IFNE == insnNode.getOpcode());
                        proceedBranch(frame, nextIndex, IFEQ == insnNode.getOpcode());
                        checkAssertion(FalseValue == trueBranchValue);
                        checkAssertion(TrueValue == falseBranchValue);
                        return;
                    default:
                        frame.execute(insnNode, interpreter);
                        insnIndex = controlFlow.transitions[insnIndex][0];
                }
        }
    }
}
Also used : BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)

Example 13 with BasicValue

use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.

the class NegationInterpreter method proceedBranch.

private void proceedBranch(Frame<BasicValue> startFrame, int startIndex, boolean branchValue) throws NegationAnalysisFailure, AnalyzerException {
    Frame<BasicValue> frame = new Frame<>(startFrame);
    int insnIndex = startIndex;
    while (true) {
        AbstractInsnNode insnNode = methodNode.instructions.get(insnIndex);
        switch(insnNode.getType()) {
            case AbstractInsnNode.LABEL:
            case AbstractInsnNode.LINE:
            case AbstractInsnNode.FRAME:
                insnIndex = controlFlow.transitions[insnIndex][0];
                break;
            default:
                switch(insnNode.getOpcode()) {
                    case IRETURN:
                        BasicValue returnValue = frame.pop();
                        if (branchValue) {
                            trueBranchValue = returnValue;
                        } else {
                            falseBranchValue = returnValue;
                        }
                        return;
                    default:
                        checkAssertion(controlFlow.transitions[insnIndex].length == 1);
                        frame.execute(insnNode, interpreter);
                        insnIndex = controlFlow.transitions[insnIndex][0];
                }
        }
    }
}
Also used : Frame(org.jetbrains.org.objectweb.asm.tree.analysis.Frame) BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)

Example 14 with BasicValue

use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.

the class NegationInterpreter method createStartFrame.

final Frame<BasicValue> createStartFrame() {
    Frame<BasicValue> frame = new Frame<>(methodNode.maxLocals, methodNode.maxStack);
    Type returnType = Type.getReturnType(methodNode.desc);
    BasicValue returnValue = Type.VOID_TYPE.equals(returnType) ? null : new BasicValue(returnType);
    frame.setReturn(returnValue);
    Type[] args = Type.getArgumentTypes(methodNode.desc);
    int local = 0;
    if ((methodNode.access & ACC_STATIC) == 0) {
        frame.setLocal(local++, ThisValue);
    }
    for (int i = 0; i < args.length; i++) {
        BasicValue value = new NthParamValue(args[i], i);
        frame.setLocal(local++, value);
        if (args[i].getSize() == 2) {
            frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
        }
    }
    while (local < methodNode.maxLocals) {
        frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
    }
    return frame;
}
Also used : Frame(org.jetbrains.org.objectweb.asm.tree.analysis.Frame) Type(org.jetbrains.org.objectweb.asm.Type) BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)

Example 15 with BasicValue

use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.

the class NegationInterpreter method contractEquation.

final Equation contractEquation(int i, Value inValue, boolean stable) {
    final Key key = new Key(method, new InOut(i, inValue), stable);
    final Result result;
    if (exception || (inValue == Value.Null && interpreter.dereferencedParams[i])) {
        result = new Final(Value.Bot);
    } else if (FalseValue == returnValue) {
        result = new Final(Value.False);
    } else if (TrueValue == returnValue) {
        result = new Final(Value.True);
    } else if (returnValue instanceof TrackableNullValue) {
        result = new Final(Value.Null);
    } else if (returnValue instanceof NotNullValue || ThisValue == returnValue) {
        result = new Final(Value.NotNull);
    } else if (returnValue instanceof NthParamValue && ((NthParamValue) returnValue).n == i) {
        result = new Final(inValue);
    } else if (returnValue instanceof TrackableCallValue) {
        TrackableCallValue call = (TrackableCallValue) returnValue;
        HashSet<Key> keys = new HashSet<>();
        for (int argI = 0; argI < call.args.size(); argI++) {
            BasicValue arg = call.args.get(argI);
            if (arg instanceof NthParamValue) {
                NthParamValue npv = (NthParamValue) arg;
                if (npv.n == i) {
                    keys.add(new Key(call.method, new InOut(argI, inValue), call.stableCall));
                }
            }
        }
        if (ASMUtils.isReferenceType(call.getType())) {
            keys.add(new Key(call.method, Out, call.stableCall));
        }
        if (keys.isEmpty()) {
            result = new Final(Value.Top);
        } else {
            result = new Pending(new SingletonSet<>(new Product(Value.Top, keys)));
        }
    } else {
        result = new Final(Value.Top);
    }
    return new Equation(key, result);
}
Also used : SingletonSet(com.intellij.util.SingletonSet) BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue) HashSet(com.intellij.util.containers.HashSet)

Aggregations

BasicValue (org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)17 Frame (org.jetbrains.org.objectweb.asm.tree.analysis.Frame)5 StrictBasicValue (org.jetbrains.kotlin.codegen.optimization.common.StrictBasicValue)4 Type (org.jetbrains.org.objectweb.asm.Type)3 In (com.intellij.codeInspection.bytecodeAnalysis.Direction.In)2 Edge (com.intellij.codeInspection.bytecodeAnalysis.asm.ControlFlowGraph.Edge)2 HashSet (java.util.HashSet)2 InOut (com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut)1 AnalyzerExt (com.intellij.codeInspection.bytecodeAnalysis.asm.AnalyzerExt)1 LiteAnalyzerExt (com.intellij.codeInspection.bytecodeAnalysis.asm.LiteAnalyzerExt)1 SingletonSet (com.intellij.util.SingletonSet)1 HashSet (com.intellij.util.containers.HashSet)1 PrintWriter (java.io.PrintWriter)1 Set (java.util.Set)1 NotNull (org.jetbrains.annotations.NotNull)1 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)1 AbstractInsnNode (org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)1 ClassNode (org.jetbrains.org.objectweb.asm.tree.ClassNode)1 MethodInsnNode (org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)1 MethodNode (org.jetbrains.org.objectweb.asm.tree.MethodNode)1