< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/util/CheckMethodAdapter.java

Print this page
rev 47452 : imported patch jdk-new-asmv6.patch


 409     public CheckMethodAdapter(final MethodVisitor mv) {
 410         this(mv, new HashMap<Label, Integer>());
 411     }
 412 
 413     /**
 414      * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 415      * will not perform any data flow check (see
 416      * {@link #CheckMethodAdapter(int,String,String,MethodVisitor,Map)}).
 417      * <i>Subclasses must not use this constructor</i>. Instead, they must use
 418      * the {@link #CheckMethodAdapter(int, MethodVisitor, Map)} version.
 419      *
 420      * @param mv
 421      *            the method visitor to which this adapter must delegate calls.
 422      * @param labels
 423      *            a map of already visited labels (in other methods).
 424      * @throws IllegalStateException
 425      *             If a subclass calls this constructor.
 426      */
 427     public CheckMethodAdapter(final MethodVisitor mv,
 428             final Map<Label, Integer> labels) {
 429         this(Opcodes.ASM5, mv, labels);
 430         if (getClass() != CheckMethodAdapter.class) {
 431             throw new IllegalStateException();
 432         }
 433     }
 434 
 435     /**
 436      * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 437      * will not perform any data flow check (see
 438      * {@link #CheckMethodAdapter(int,String,String,MethodVisitor,Map)}).
 439      *
 440      * @param api
 441      *            the ASM API version implemented by this CheckMethodAdapter.
 442      *            Must be one of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.

 443      * @param mv
 444      *            the method visitor to which this adapter must delegate calls.
 445      * @param labels
 446      *            a map of already visited labels (in other methods).
 447      */
 448     protected CheckMethodAdapter(final int api, final MethodVisitor mv,
 449             final Map<Label, Integer> labels) {
 450         super(api, mv);
 451         this.labels = labels;
 452         this.usedLabels = new HashSet<Label>();
 453         this.handlers = new ArrayList<Label>();
 454     }
 455 
 456     /**
 457      * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 458      * will perform basic data flow checks. For instance in a method whose
 459      * signature is <tt>void m ()</tt>, the invalid instruction IRETURN, or the
 460      * invalid sequence IADD L2I will be detected.
 461      *
 462      * @param access


 739     }
 740 
 741     private void doVisitMethodInsn(int opcode, final String owner,
 742             final String name, final String desc, final boolean itf) {
 743         checkStartCode();
 744         checkEndCode();
 745         checkOpcode(opcode, 5);
 746         if (opcode != Opcodes.INVOKESPECIAL || !"<init>".equals(name)) {
 747             checkMethodIdentifier(version, name, "name");
 748         }
 749         checkInternalName(owner, "owner");
 750         checkMethodDesc(desc);
 751         if (opcode == Opcodes.INVOKEVIRTUAL && itf) {
 752             throw new IllegalArgumentException(
 753                     "INVOKEVIRTUAL can't be used with interfaces");
 754         }
 755         if (opcode == Opcodes.INVOKEINTERFACE && !itf) {
 756             throw new IllegalArgumentException(
 757                     "INVOKEINTERFACE can't be used with classes");
 758         }






 759         // Calling super.visitMethodInsn requires to call the correct version
 760         // depending on this.api (otherwise infinite loops can occur). To
 761         // simplify and to make it easier to automatically remove the backward
 762         // compatibility code, we inline the code of the overridden method here.
 763         if (mv != null) {
 764             mv.visitMethodInsn(opcode, owner, name, desc, itf);
 765         }
 766         ++insnCount;
 767     }
 768 
 769     @Override
 770     public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
 771             Object... bsmArgs) {
 772         checkStartCode();
 773         checkEndCode();
 774         checkMethodIdentifier(version, name, "name");
 775         checkMethodDesc(desc);
 776         if (bsm.getTag() != Opcodes.H_INVOKESTATIC
 777                 && bsm.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
 778             throw new IllegalArgumentException("invalid handle tag "




 409     public CheckMethodAdapter(final MethodVisitor mv) {
 410         this(mv, new HashMap<Label, Integer>());
 411     }
 412 
 413     /**
 414      * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 415      * will not perform any data flow check (see
 416      * {@link #CheckMethodAdapter(int,String,String,MethodVisitor,Map)}).
 417      * <i>Subclasses must not use this constructor</i>. Instead, they must use
 418      * the {@link #CheckMethodAdapter(int, MethodVisitor, Map)} version.
 419      *
 420      * @param mv
 421      *            the method visitor to which this adapter must delegate calls.
 422      * @param labels
 423      *            a map of already visited labels (in other methods).
 424      * @throws IllegalStateException
 425      *             If a subclass calls this constructor.
 426      */
 427     public CheckMethodAdapter(final MethodVisitor mv,
 428             final Map<Label, Integer> labels) {
 429         this(Opcodes.ASM6, mv, labels);
 430         if (getClass() != CheckMethodAdapter.class) {
 431             throw new IllegalStateException();
 432         }
 433     }
 434 
 435     /**
 436      * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 437      * will not perform any data flow check (see
 438      * {@link #CheckMethodAdapter(int,String,String,MethodVisitor,Map)}).
 439      *
 440      * @param api
 441      *            the ASM API version implemented by this CheckMethodAdapter.
 442      *            Must be one of {@link Opcodes#ASM4}, {@link Opcodes#ASM5}
 443      *            or {@link Opcodes#ASM6}.
 444      * @param mv
 445      *            the method visitor to which this adapter must delegate calls.
 446      * @param labels
 447      *            a map of already visited labels (in other methods).
 448      */
 449     protected CheckMethodAdapter(final int api, final MethodVisitor mv,
 450             final Map<Label, Integer> labels) {
 451         super(api, mv);
 452         this.labels = labels;
 453         this.usedLabels = new HashSet<Label>();
 454         this.handlers = new ArrayList<Label>();
 455     }
 456 
 457     /**
 458      * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 459      * will perform basic data flow checks. For instance in a method whose
 460      * signature is <tt>void m ()</tt>, the invalid instruction IRETURN, or the
 461      * invalid sequence IADD L2I will be detected.
 462      *
 463      * @param access


 740     }
 741 
 742     private void doVisitMethodInsn(int opcode, final String owner,
 743             final String name, final String desc, final boolean itf) {
 744         checkStartCode();
 745         checkEndCode();
 746         checkOpcode(opcode, 5);
 747         if (opcode != Opcodes.INVOKESPECIAL || !"<init>".equals(name)) {
 748             checkMethodIdentifier(version, name, "name");
 749         }
 750         checkInternalName(owner, "owner");
 751         checkMethodDesc(desc);
 752         if (opcode == Opcodes.INVOKEVIRTUAL && itf) {
 753             throw new IllegalArgumentException(
 754                     "INVOKEVIRTUAL can't be used with interfaces");
 755         }
 756         if (opcode == Opcodes.INVOKEINTERFACE && !itf) {
 757             throw new IllegalArgumentException(
 758                     "INVOKEINTERFACE can't be used with classes");
 759         }
 760         if (opcode == Opcodes.INVOKESPECIAL && itf
 761                 && (version & 0xFFFF) < Opcodes.V1_8) {
 762             throw new IllegalArgumentException(
 763                     "INVOKESPECIAL can't be used with interfaces prior to Java 8");
 764         }
 765 
 766         // Calling super.visitMethodInsn requires to call the correct version
 767         // depending on this.api (otherwise infinite loops can occur). To
 768         // simplify and to make it easier to automatically remove the backward
 769         // compatibility code, we inline the code of the overridden method here.
 770         if (mv != null) {
 771             mv.visitMethodInsn(opcode, owner, name, desc, itf);
 772         }
 773         ++insnCount;
 774     }
 775 
 776     @Override
 777     public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
 778             Object... bsmArgs) {
 779         checkStartCode();
 780         checkEndCode();
 781         checkMethodIdentifier(version, name, "name");
 782         checkMethodDesc(desc);
 783         if (bsm.getTag() != Opcodes.H_INVOKESTATIC
 784                 && bsm.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
 785             throw new IllegalArgumentException("invalid handle tag "


< prev index next >