Search in sources :

Example 11 with BasicValue

use of org.objectweb.asm.tree.analysis.BasicValue in project drill by apache.

the class InstructionModifier method getFunctionReturn.

/**
   * Get the value of a function return if it is a ReplacingBasicValue.
   *
   * <p>Assumes that we're in the middle of processing an INVOKExxx instruction.
   *
   * @return the value that will be on the top of the stack after the function returns
   */
private ReplacingBasicValue getFunctionReturn() {
    final Frame<BasicValue> nextFrame = list.nextFrame;
    final BasicValue basicValue = nextFrame.getStack(nextFrame.getStackSize() - 1);
    return filterReplacement(basicValue);
}
Also used : BasicValue(org.objectweb.asm.tree.analysis.BasicValue)

Example 12 with BasicValue

use of org.objectweb.asm.tree.analysis.BasicValue in project drill by apache.

the class ReplacingInterpreter method naryOperation.

@Override
public BasicValue naryOperation(final AbstractInsnNode insn, final List<? extends BasicValue> values) throws AnalyzerException {
    if (insn instanceof MethodInsnNode) {
        boolean skipOne = insn.getOpcode() != Opcodes.INVOKESTATIC;
        // Note if the argument is a holder, and is used as a function argument
        for (BasicValue value : values) {
            // if non-static method, skip over the receiver
            if (skipOne) {
                skipOne = false;
                continue;
            }
            if (value instanceof ReplacingBasicValue) {
                final ReplacingBasicValue argument = (ReplacingBasicValue) value;
                argument.setFunctionArgument();
            }
        }
    }
    return super.naryOperation(insn, values);
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) BasicValue(org.objectweb.asm.tree.analysis.BasicValue)

Example 13 with BasicValue

use of org.objectweb.asm.tree.analysis.BasicValue in project drill by apache.

the class ScalarReplacementNode method visitEnd.

@Override
public void visitEnd() {
    /*
     * Note this is a MethodNode, not a MethodVisitor. As a result, calls to the various visitX()
     * methods will be building up a method. Then, once we analyze it, we use accept() to visit that
     * method and transform it with the InstructionModifier at the bottom.
     */
    super.visitEnd();
    final LinkedList<ReplacingBasicValue> valueList = new LinkedList<>();
    final MethodAnalyzer<BasicValue> analyzer = new MethodAnalyzer<BasicValue>(new ReplacingInterpreter(className, valueList));
    Frame<BasicValue>[] frames;
    try {
        frames = analyzer.analyze(className, this);
    } catch (final AnalyzerException e) {
        throw new IllegalStateException(e);
    }
    if (logger.isTraceEnabled()) {
        final StringBuilder sb = new StringBuilder();
        sb.append("ReplacingBasicValues for " + className + "\n");
        for (final ReplacingBasicValue value : valueList) {
            value.dump(sb, 2);
            sb.append('\n');
        }
        logger.debug(sb.toString());
    }
    // wrap the instruction handler so that we can do additional things
    final TrackingInstructionList list = new TrackingInstructionList(frames, this.instructions);
    this.instructions = list;
    MethodVisitor methodVisitor = inner;
    if (verifyBytecode) {
        methodVisitor = new CheckMethodVisitorFsm(CompilationConfig.ASM_API_VERSION, methodVisitor);
    }
    final InstructionModifier holderV = new InstructionModifier(this.access, this.name, this.desc, this.signature, this.exceptionsArr, list, methodVisitor);
    accept(holderV);
}
Also used : Frame(org.objectweb.asm.tree.analysis.Frame) AnalyzerException(org.objectweb.asm.tree.analysis.AnalyzerException) LinkedList(java.util.LinkedList) BasicValue(org.objectweb.asm.tree.analysis.BasicValue) MethodVisitor(org.objectweb.asm.MethodVisitor) CheckMethodVisitorFsm(org.apache.drill.exec.compile.CheckMethodVisitorFsm)

Aggregations

BasicValue (org.objectweb.asm.tree.analysis.BasicValue)13 Type (org.objectweb.asm.Type)3 Frame (org.objectweb.asm.tree.analysis.Frame)3 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)2 MethodNode (org.objectweb.asm.tree.MethodNode)2 AnalyzerException (org.objectweb.asm.tree.analysis.AnalyzerException)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CheckMethodVisitorFsm (org.apache.drill.exec.compile.CheckMethodVisitorFsm)1 UdfAnalyzerUtils.findMethodNode (org.apache.flink.api.java.sca.UdfAnalyzerUtils.findMethodNode)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1 ClassNode (org.objectweb.asm.tree.ClassNode)1 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)1 Analyzer (org.objectweb.asm.tree.analysis.Analyzer)1 SimpleVerifier (org.objectweb.asm.tree.analysis.SimpleVerifier)1