2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
27 package sun.tools.javap;
32 import static sun.tools.javap.RuntimeConstants.*;
34 /* represents one entry of StackMapTable attribute
36 class StackMapTableData {
40 StackMapTableData(int frameType) {
41 this.frameType = frameType;
44 void print(JavapPrinter p) {
45 p.out.print(" frame_type = " + frameType);
48 static class SameFrame extends StackMapTableData {
49 SameFrame(int frameType, int offsetDelta) {
51 this.offsetDelta = offsetDelta;
53 void print(JavapPrinter p) {
55 if (frameType < SAME_FRAME_BOUND) {
56 p.out.println(" /* same */");
58 p.out.println(" /* same_frame_extended */");
59 p.out.println(" offset_delta = " + offsetDelta);
64 static class SameLocals1StackItem extends StackMapTableData {
66 SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
68 this.offsetDelta = offsetDelta;
71 void print(JavapPrinter p) {
73 if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
74 p.out.println(" /* same_locals_1_stack_item_frame_extended */");
75 p.out.println(" offset_delta = " + offsetDelta);
77 p.out.println(" /* same_locals_1_stack_item */");
79 p.printMap(" stack = [", stack);
83 static class ChopFrame extends StackMapTableData {
84 ChopFrame(int frameType, int offsetDelta) {
86 this.offsetDelta = offsetDelta;
88 void print(JavapPrinter p) {
90 p.out.println(" /* chop */");
91 p.out.println(" offset_delta = " + offsetDelta);
95 static class AppendFrame extends StackMapTableData {
97 AppendFrame(int frameType, int offsetDelta, int[] locals) {
99 this.offsetDelta = offsetDelta;
100 this.locals = locals;
102 void print(JavapPrinter p) {
104 p.out.println(" /* append */");
105 p.out.println(" offset_delta = " + offsetDelta);
106 p.printMap(" locals = [", locals);
110 static class FullFrame extends StackMapTableData {
113 FullFrame(int offsetDelta, int[] locals, int[] stack) {
115 this.offsetDelta = offsetDelta;
116 this.locals = locals;
119 void print(JavapPrinter p) {
121 p.out.println(" /* full_frame */");
122 p.out.println(" offset_delta = " + offsetDelta);
123 p.printMap(" locals = [", locals);
124 p.printMap(" stack = [", stack);
128 static StackMapTableData getInstance(DataInputStream in, MethodData method)
130 int frameType = in.readUnsignedByte();
132 if (frameType < SAME_FRAME_BOUND) {
134 return new SameFrame(frameType, frameType);
135 } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
136 // same_locals_1_stack_item_frame
137 // read additional single stack element
138 return new SameLocals1StackItem(frameType,
139 (frameType - SAME_FRAME_BOUND),
140 StackMapData.readTypeArray(in, 1, method));
141 } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
142 // same_locals_1_stack_item_extended
143 return new SameLocals1StackItem(frameType,
144 in.readUnsignedShort(),
145 StackMapData.readTypeArray(in, 1, method));
146 } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType && frameType < SAME_FRAME_EXTENDED) {
147 // chop_frame or same_frame_extended
148 return new ChopFrame(frameType, in.readUnsignedShort());
149 } else if (frameType == SAME_FRAME_EXTENDED) {
150 // chop_frame or same_frame_extended
151 return new SameFrame(frameType, in.readUnsignedShort());
152 } else if (SAME_FRAME_EXTENDED < frameType && frameType < FULL_FRAME) {
154 return new AppendFrame(frameType, in.readUnsignedShort(),
155 StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
156 } else if (frameType == FULL_FRAME) {
158 int offsetDelta = in.readUnsignedShort();
159 int locals_size = in.readUnsignedShort();
160 int[] locals = StackMapData.readTypeArray(in, locals_size, method);
161 int stack_size = in.readUnsignedShort();
162 int[] stack = StackMapData.readTypeArray(in, stack_size, method);
163 return new FullFrame(offsetDelta, locals, stack);
165 throw new ClassFormatError("unrecognized frame_type in StackMapTable");