javap/src/main/java/org/apidesign/javap/StackMapTableData.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 12 Dec 2012 18:18:07 +0100
branchbenchmarks
changeset 311 84c05018e079
parent 149 32653a09f0db
child 221 3ee23267706c
permissions -rw-r--r--
Copying the test resources next to built classes and js file. Modifying the test to properly use the new bck2brwsr calling scheme.
     1 /*
     2  * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 
    27 package org.apidesign.javap;
    28 
    29 import java.io.*;
    30 
    31 import static org.apidesign.javap.RuntimeConstants.*;
    32 
    33 /* represents one entry of StackMapTable attribute
    34  */
    35 class StackMapTableData {
    36     final int frameType;
    37     int offsetDelta;
    38 
    39     StackMapTableData(int frameType) {
    40         this.frameType = frameType;
    41     }
    42 
    43     static class SameFrame extends StackMapTableData {
    44         SameFrame(int frameType, int offsetDelta) {
    45             super(frameType);
    46             this.offsetDelta = offsetDelta;
    47         }
    48     }
    49 
    50     static class SameLocals1StackItem extends StackMapTableData {
    51         final int[] stack;
    52         SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
    53             super(frameType);
    54             this.offsetDelta = offsetDelta;
    55             this.stack = stack;
    56         }
    57     }
    58 
    59     static class ChopFrame extends StackMapTableData {
    60         ChopFrame(int frameType, int offsetDelta) {
    61             super(frameType);
    62             this.offsetDelta = offsetDelta;
    63         }
    64     }
    65 
    66     static class AppendFrame extends StackMapTableData {
    67         final int[] locals;
    68         AppendFrame(int frameType, int offsetDelta, int[] locals) {
    69             super(frameType);
    70             this.offsetDelta = offsetDelta;
    71             this.locals = locals;
    72         }
    73     }
    74 
    75     static class FullFrame extends StackMapTableData {
    76         final int[] locals;
    77         final int[] stack;
    78         FullFrame(int offsetDelta, int[] locals, int[] stack) {
    79             super(FULL_FRAME);
    80             this.offsetDelta = offsetDelta;
    81             this.locals = locals;
    82             this.stack = stack;
    83         }
    84     }
    85 
    86     static StackMapTableData getInstance(DataInputStream in, MethodData method)
    87                   throws IOException {
    88         int frameType = in.readUnsignedByte();
    89 
    90         if (frameType < SAME_FRAME_BOUND) {
    91             // same_frame
    92             return new SameFrame(frameType, frameType);
    93         } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
    94             // same_locals_1_stack_item_frame
    95             // read additional single stack element
    96             return new SameLocals1StackItem(frameType,
    97                                             (frameType - SAME_FRAME_BOUND),
    98                                             StackMapData.readTypeArray(in, 1, method));
    99         } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
   100             // same_locals_1_stack_item_extended
   101             return new SameLocals1StackItem(frameType,
   102                                             in.readUnsignedShort(),
   103                                             StackMapData.readTypeArray(in, 1, method));
   104         } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType  && frameType < SAME_FRAME_EXTENDED) {
   105             // chop_frame or same_frame_extended
   106             return new ChopFrame(frameType, in.readUnsignedShort());
   107         } else if (frameType == SAME_FRAME_EXTENDED) {
   108             // chop_frame or same_frame_extended
   109             return new SameFrame(frameType, in.readUnsignedShort());
   110         } else if (SAME_FRAME_EXTENDED < frameType  && frameType < FULL_FRAME) {
   111             // append_frame
   112             return new AppendFrame(frameType, in.readUnsignedShort(),
   113                                    StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
   114         } else if (frameType == FULL_FRAME) {
   115             // full_frame
   116             int offsetDelta = in.readUnsignedShort();
   117             int locals_size = in.readUnsignedShort();
   118             int[] locals = StackMapData.readTypeArray(in, locals_size, method);
   119             int stack_size = in.readUnsignedShort();
   120             int[] stack = StackMapData.readTypeArray(in, stack_size, method);
   121             return new FullFrame(offsetDelta, locals, stack);
   122         } else {
   123             throw new ClassFormatError("unrecognized frame_type in StackMapTable");
   124         }
   125     }
   126 }