Java Code Examples for jdk.internal.org.objectweb.asm.Label

The following examples show how to use jdk.internal.org.objectweb.asm.Label. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk8u60   Source File: CheckMethodAdapter.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks a stack frame value.
 *
 * @param value
 *            the value to be checked.
 */
void checkFrameValue(final Object value) {
    if (value == Opcodes.TOP || value == Opcodes.INTEGER
            || value == Opcodes.FLOAT || value == Opcodes.LONG
            || value == Opcodes.DOUBLE || value == Opcodes.NULL
            || value == Opcodes.UNINITIALIZED_THIS) {
        return;
    }
    if (value instanceof String) {
        checkInternalName((String) value, "Invalid stack frame value");
        return;
    }
    if (!(value instanceof Label)) {
        throw new IllegalArgumentException("Invalid stack frame value: "
                + value);
    } else {
        usedLabels.add((Label) value);
    }
}
 
Example 2
@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
    checkStartCode();
    checkEndCode();
    endCode = true;
    for (Label l : usedLabels) {
        if (labels.get(l) == null) {
            throw new IllegalStateException("Undefined label used");
        }
    }
    for (int i = 0; i < handlers.size();) {
        Integer start = labels.get(handlers.get(i++));
        Integer end = labels.get(handlers.get(i++));
        if (start == null || end == null) {
            throw new IllegalStateException(
                    "Undefined try catch block labels");
        }
        if (end.intValue() <= start.intValue()) {
            throw new IllegalStateException(
                    "Emty try catch block handler range");
        }
    }
    checkUnsignedShort(maxStack, "Invalid max stack");
    checkUnsignedShort(maxLocals, "Invalid max locals");
    super.visitMaxs(maxStack, maxLocals);
}
 
Example 3
Source Project: openjdk-jdk9   Source File: CTVMUtilities.java    License: GNU General Public License v2.0 6 votes vote down vote up
public ClassVisitorForLabels(ClassWriter cw, Map<Label, Integer> lines,
                             Executable target) {
    super(Opcodes.ASM5, cw);
    this.lineNumbers = lines;

    StringBuilder builder = new StringBuilder("(");
    for (Parameter parameter : target.getParameters()) {
        builder.append(Utils.toJVMTypeSignature(parameter.getType()));
    }
    builder.append(")");
    if (target instanceof Constructor) {
        targetName = "<init>";
        builder.append("V");
    } else {
        targetName = target.getName();
        builder.append(Utils.toJVMTypeSignature(
                ((Method) target).getReturnType()));
    }
    targetDesc = builder.toString();
}
 
Example 4
@Override
public void visitJumpInsn(final int opcode, final Label label) {
    minSize += 3;
    if (opcode == GOTO || opcode == JSR) {
        maxSize += 5;
    } else {
        maxSize += 8;
    }
    if (mv != null) {
        mv.visitJumpInsn(opcode, label);
    }
}
 
Example 5
Source Project: jdk8u-jdk   Source File: AnalyzerAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitJumpInsn(final int opcode, final Label label) {
    if (mv != null) {
        mv.visitJumpInsn(opcode, label);
    }
    execute(opcode, 0, null);
    if (opcode == Opcodes.GOTO) {
        this.locals = null;
        this.stack = null;
    }
}
 
Example 6
Source Project: jdk8u-dev-jdk   Source File: ASMifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Appends a declaration of the given label to {@link #buf buf}. This
 * declaration is of the form "Label lXXX = new Label();". Does nothing if
 * the given label has already been declared.
 *
 * @param l
 *            a label.
 */
protected void declareLabel(final Label l) {
    if (labelNames == null) {
        labelNames = new HashMap<Label, String>();
    }
    String name = labelNames.get(l);
    if (name == null) {
        name = "l" + labelNames.size();
        labelNames.put(l, name);
        buf.append("Label ").append(name).append(" = new Label();\n");
    }
}
 
Example 7
Source Project: jdk8u_jdk   Source File: CheckMethodAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLineNumber(final int line, final Label start) {
    checkStartCode();
    checkEndCode();
    checkUnsignedShort(line, "Invalid line number");
    checkLabel(start, true, "start label");
    super.visitLineNumber(line, start);
}
 
Example 8
@Override
public void visitLocalVariable(final String name, final String desc,
        final String signature, final Label start, final Label end,
        final int index) {
    int newIndex = remap(index, Type.getType(desc));
    mv.visitLocalVariable(name, desc, signature, start, end, newIndex);
}
 
Example 9
/**
 * Returns the field of the Label class whose name is given.
 *
 * @param name
 *            a field name.
 * @return the field of the Label class whose name is given, or null.
 */
private static Field getLabelField(final String name) {
    try {
        Field f = Label.class.getDeclaredField(name);
        f.setAccessible(true);
        return f;
    } catch (NoSuchFieldException e) {
        return null;
    }
}
 
Example 10
Source Project: nashorn   Source File: Textifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLineNumber(final int line, final Label start) {
    buf.setLength(0);
    buf.append(tab2).append("LINENUMBER ").append(line).append(' ');
    appendLabel(start);
    buf.append('\n');
    text.add(buf.toString());
}
 
Example 11
Source Project: hottub   Source File: ASMifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLabel(final Label label) {
    buf.setLength(0);
    declareLabel(label);
    buf.append(name).append(".visitLabel(");
    appendLabel(label);
    buf.append(");\n");
    text.add(buf.toString());
}
 
Example 12
Source Project: jdk8u-jdk   Source File: ASMifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void appendFrameTypes(final int n, final Object[] o) {
    for (int i = 0; i < n; ++i) {
        if (i > 0) {
            buf.append(", ");
        }
        if (o[i] instanceof String) {
            appendConstant(o[i]);
        } else if (o[i] instanceof Integer) {
            switch (((Integer) o[i]).intValue()) {
            case 0:
                buf.append("Opcodes.TOP");
                break;
            case 1:
                buf.append("Opcodes.INTEGER");
                break;
            case 2:
                buf.append("Opcodes.FLOAT");
                break;
            case 3:
                buf.append("Opcodes.DOUBLE");
                break;
            case 4:
                buf.append("Opcodes.LONG");
                break;
            case 5:
                buf.append("Opcodes.NULL");
                break;
            case 6:
                buf.append("Opcodes.UNINITIALIZED_THIS");
                break;
            }
        } else {
            appendLabel((Label) o[i]);
        }
    }
}
 
Example 13
Source Project: jdk8u_jdk   Source File: ASMifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLabel(final Label label) {
    buf.setLength(0);
    declareLabel(label);
    buf.append(name).append(".visitLabel(");
    appendLabel(label);
    buf.append(");\n");
    text.add(buf.toString());
}
 
Example 14
Source Project: openjdk-jdk9   Source File: Textifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitTableSwitchInsn(final int min, final int max,
        final Label dflt, final Label... labels) {
    buf.setLength(0);
    buf.append(tab2).append("TABLESWITCH\n");
    for (int i = 0; i < labels.length; ++i) {
        buf.append(tab3).append(min + i).append(": ");
        appendLabel(labels[i]);
        buf.append('\n');
    }
    buf.append(tab3).append("default: ");
    appendLabel(dflt);
    buf.append('\n');
    text.add(buf.toString());
}
 
Example 15
@Override
public void accept(final MethodVisitor mv) {
    int[] keys = new int[this.keys.size()];
    for (int i = 0; i < keys.length; ++i) {
        keys[i] = this.keys.get(i).intValue();
    }
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitLookupSwitchInsn(dflt.getLabel(), keys, labels);
    acceptAnnotations(mv);
}
 
Example 16
Source Project: Bytecoder   Source File: TableSwitchInsnNode.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
    Label[] labelsArray = new Label[this.labels.size()];
    for (int i = 0, n = labelsArray.length; i < n; ++i) {
        labelsArray[i] = this.labels.get(i).getLabel();
    }
    methodVisitor.visitTableSwitchInsn(min, max, dflt.getLabel(), labelsArray);
    acceptAnnotations(methodVisitor);
}
 
Example 17
/**
 * Makes the given visitor visit this type annotation.
 *
 * @param mv
 *            the visitor that must visit this annotation.
 * @param visible
 *            <tt>true</tt> if the annotation is visible at runtime.
 */
public void accept(final MethodVisitor mv, boolean visible) {
    Label[] start = new Label[this.start.size()];
    Label[] end = new Label[this.end.size()];
    int[] index = new int[this.index.size()];
    for (int i = 0; i < start.length; ++i) {
        start[i] = this.start.get(i).getLabel();
        end[i] = this.end.get(i).getLabel();
        index[i] = this.index.get(i);
    }
    accept(mv.visitLocalVariableAnnotation(typeRef, typePath, start, end,
            index, desc, true));
}
 
Example 18
Source Project: hottub   Source File: AdviceAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitTableSwitchInsn(final int min, final int max,
        final Label dflt, final Label... labels) {
    mv.visitTableSwitchInsn(min, max, dflt, labels);
    if (constructor) {
        popValue();
        addBranches(dflt, labels);
    }
}
 
Example 19
@Override
public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
        final Label[] labels) {
    mv.visitLookupSwitchInsn(dflt, keys, labels);
    if (constructor) {
        popValue();
        addBranches(dflt, labels);
    }
}
 
Example 20
Source Project: Bytecoder   Source File: AdviceAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) {
    super.visitLookupSwitchInsn(dflt, keys, labels);
    if (isConstructor && !superClassConstructorCalled) {
        popValue();
        addForwardJumps(dflt, labels);
    }
}
 
Example 21
Source Project: jdk8u_jdk   Source File: AdviceAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitTryCatchBlock(Label start, Label end, Label handler,
        String type) {
    super.visitTryCatchBlock(start, end, handler, type);
    if (constructor && !branches.containsKey(handler)) {
        List<Object> stackFrame = new ArrayList<Object>();
        stackFrame.add(OTHER);
        branches.put(handler, stackFrame);
    }
}
 
Example 22
Source Project: nashorn   Source File: LookupSwitchInsnNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    int[] keys = new int[this.keys.size()];
    for (int i = 0; i < keys.length; ++i) {
        keys[i] = this.keys.get(i).intValue();
    }
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitLookupSwitchInsn(dflt.getLabel(), keys, labels);
}
 
Example 23
/**
 * Checks that the given label is not null. This method can also check that
 * the label has been visited.
 *
 * @param label
 *            the label to be checked.
 * @param checkVisited
 *            <tt>true</tt> to check that the label has been visited.
 * @param msg
 *            a message to be used in case of error.
 */
void checkLabel(final Label label, final boolean checkVisited,
        final String msg) {
    if (label == null) {
        throw new IllegalArgumentException("Invalid " + msg
                + " (must not be null)");
    }
    if (checkVisited && labels.get(label) == null) {
        throw new IllegalArgumentException("Invalid " + msg
                + " (must be visited first)");
    }
}
 
Example 24
Source Project: nashorn   Source File: ASMifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLabel(final Label label) {
    buf.setLength(0);
    declareLabel(label);
    buf.append(name).append(".visitLabel(");
    appendLabel(label);
    buf.append(");\n");
    text.add(buf.toString());
}
 
Example 25
public JIMethodInliningAdapter(LocalVariablesSorter mv, Label end, int acc, String desc, Remapper remapper) {
    super(acc, desc, mv, remapper);
    this.lvs = mv;
    this.end = end;
    int offset = isStatic(acc) ? 0 : 1;
    Type[] args = Type.getArgumentTypes(desc);
    for (int i = args.length - 1; i >= 0; i--) {
        super.visitVarInsn(args[i].getOpcode(Opcodes.ISTORE), i + offset);
    }
    if (offset > 0) {
        super.visitVarInsn(Opcodes.ASTORE, 0);
    }
}
 
Example 26
Source Project: jdk8u_jdk   Source File: AdviceAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLabel(final Label label) {
    mv.visitLabel(label);
    if (constructor && branches != null) {
        List<Object> frame = branches.get(label);
        if (frame != null) {
            stackFrame = frame;
            branches.remove(label);
        }
    }
}
 
Example 27
Source Project: jdk8u-jdk   Source File: Textifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Appends the name of the given label to {@link #buf buf}. Creates a new
 * label name if the given label does not yet have one.
 *
 * @param l
 *            a label.
 */
protected void appendLabel(final Label l) {
    if (labelNames == null) {
        labelNames = new HashMap<Label, String>();
    }
    String name = labelNames.get(l);
    if (name == null) {
        name = "L" + labelNames.size();
        labelNames.put(l, name);
    }
    buf.append(name);
}
 
Example 28
@Override
public void accept(final MethodVisitor mv) {
    int[] keys = new int[this.keys.size()];
    for (int i = 0; i < keys.length; ++i) {
        keys[i] = this.keys.get(i).intValue();
    }
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitLookupSwitchInsn(dflt.getLabel(), keys, labels);
    acceptAnnotations(mv);
}
 
Example 29
Source Project: jdk8u_jdk   Source File: TraceMethodVisitor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLocalVariable(final String name, final String desc,
        final String signature, final Label start, final Label end,
        final int index) {
    p.visitLocalVariable(name, desc, signature, start, end, index);
    super.visitLocalVariable(name, desc, signature, start, end, index);
}
 
Example 30
@Override
public void accept(final MethodVisitor mv) {
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitTableSwitchInsn(min, max, dflt.getLabel(), labels);
    acceptAnnotations(mv);
}