src/share/classes/sun/tools/javap/StackMapTableData.java

Wed, 02 Jul 2008 12:56:02 -0700

author
xdono
date
Wed, 02 Jul 2008 12:56:02 -0700
changeset 54
eaf608c64fec
parent 1
9a66ca7c79fa
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
duke@1 2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26
duke@1 27 package sun.tools.javap;
duke@1 28
duke@1 29 import java.util.*;
duke@1 30 import java.io.*;
duke@1 31
duke@1 32 import static sun.tools.javap.RuntimeConstants.*;
duke@1 33
duke@1 34 /* represents one entry of StackMapTable attribute
duke@1 35 */
duke@1 36 class StackMapTableData {
duke@1 37 final int frameType;
duke@1 38 int offsetDelta;
duke@1 39
duke@1 40 StackMapTableData(int frameType) {
duke@1 41 this.frameType = frameType;
duke@1 42 }
duke@1 43
duke@1 44 void print(JavapPrinter p) {
duke@1 45 p.out.print(" frame_type = " + frameType);
duke@1 46 }
duke@1 47
duke@1 48 static class SameFrame extends StackMapTableData {
duke@1 49 SameFrame(int frameType, int offsetDelta) {
duke@1 50 super(frameType);
duke@1 51 this.offsetDelta = offsetDelta;
duke@1 52 }
duke@1 53 void print(JavapPrinter p) {
duke@1 54 super.print(p);
duke@1 55 if (frameType < SAME_FRAME_BOUND) {
duke@1 56 p.out.println(" /* same */");
duke@1 57 } else {
duke@1 58 p.out.println(" /* same_frame_extended */");
duke@1 59 p.out.println(" offset_delta = " + offsetDelta);
duke@1 60 }
duke@1 61 }
duke@1 62 }
duke@1 63
duke@1 64 static class SameLocals1StackItem extends StackMapTableData {
duke@1 65 final int[] stack;
duke@1 66 SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
duke@1 67 super(frameType);
duke@1 68 this.offsetDelta = offsetDelta;
duke@1 69 this.stack = stack;
duke@1 70 }
duke@1 71 void print(JavapPrinter p) {
duke@1 72 super.print(p);
duke@1 73 if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
duke@1 74 p.out.println(" /* same_locals_1_stack_item_frame_extended */");
duke@1 75 p.out.println(" offset_delta = " + offsetDelta);
duke@1 76 } else {
duke@1 77 p.out.println(" /* same_locals_1_stack_item */");
duke@1 78 }
duke@1 79 p.printMap(" stack = [", stack);
duke@1 80 }
duke@1 81 }
duke@1 82
duke@1 83 static class ChopFrame extends StackMapTableData {
duke@1 84 ChopFrame(int frameType, int offsetDelta) {
duke@1 85 super(frameType);
duke@1 86 this.offsetDelta = offsetDelta;
duke@1 87 }
duke@1 88 void print(JavapPrinter p) {
duke@1 89 super.print(p);
duke@1 90 p.out.println(" /* chop */");
duke@1 91 p.out.println(" offset_delta = " + offsetDelta);
duke@1 92 }
duke@1 93 }
duke@1 94
duke@1 95 static class AppendFrame extends StackMapTableData {
duke@1 96 final int[] locals;
duke@1 97 AppendFrame(int frameType, int offsetDelta, int[] locals) {
duke@1 98 super(frameType);
duke@1 99 this.offsetDelta = offsetDelta;
duke@1 100 this.locals = locals;
duke@1 101 }
duke@1 102 void print(JavapPrinter p) {
duke@1 103 super.print(p);
duke@1 104 p.out.println(" /* append */");
duke@1 105 p.out.println(" offset_delta = " + offsetDelta);
duke@1 106 p.printMap(" locals = [", locals);
duke@1 107 }
duke@1 108 }
duke@1 109
duke@1 110 static class FullFrame extends StackMapTableData {
duke@1 111 final int[] locals;
duke@1 112 final int[] stack;
duke@1 113 FullFrame(int offsetDelta, int[] locals, int[] stack) {
duke@1 114 super(FULL_FRAME);
duke@1 115 this.offsetDelta = offsetDelta;
duke@1 116 this.locals = locals;
duke@1 117 this.stack = stack;
duke@1 118 }
duke@1 119 void print(JavapPrinter p) {
duke@1 120 super.print(p);
duke@1 121 p.out.println(" /* full_frame */");
duke@1 122 p.out.println(" offset_delta = " + offsetDelta);
duke@1 123 p.printMap(" locals = [", locals);
duke@1 124 p.printMap(" stack = [", stack);
duke@1 125 }
duke@1 126 }
duke@1 127
duke@1 128 static StackMapTableData getInstance(DataInputStream in, MethodData method)
duke@1 129 throws IOException {
duke@1 130 int frameType = in.readUnsignedByte();
duke@1 131
duke@1 132 if (frameType < SAME_FRAME_BOUND) {
duke@1 133 // same_frame
duke@1 134 return new SameFrame(frameType, frameType);
duke@1 135 } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
duke@1 136 // same_locals_1_stack_item_frame
duke@1 137 // read additional single stack element
duke@1 138 return new SameLocals1StackItem(frameType,
duke@1 139 (frameType - SAME_FRAME_BOUND),
duke@1 140 StackMapData.readTypeArray(in, 1, method));
duke@1 141 } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
duke@1 142 // same_locals_1_stack_item_extended
duke@1 143 return new SameLocals1StackItem(frameType,
duke@1 144 in.readUnsignedShort(),
duke@1 145 StackMapData.readTypeArray(in, 1, method));
duke@1 146 } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType && frameType < SAME_FRAME_EXTENDED) {
duke@1 147 // chop_frame or same_frame_extended
duke@1 148 return new ChopFrame(frameType, in.readUnsignedShort());
duke@1 149 } else if (frameType == SAME_FRAME_EXTENDED) {
duke@1 150 // chop_frame or same_frame_extended
duke@1 151 return new SameFrame(frameType, in.readUnsignedShort());
duke@1 152 } else if (SAME_FRAME_EXTENDED < frameType && frameType < FULL_FRAME) {
duke@1 153 // append_frame
duke@1 154 return new AppendFrame(frameType, in.readUnsignedShort(),
duke@1 155 StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
duke@1 156 } else if (frameType == FULL_FRAME) {
duke@1 157 // full_frame
duke@1 158 int offsetDelta = in.readUnsignedShort();
duke@1 159 int locals_size = in.readUnsignedShort();
duke@1 160 int[] locals = StackMapData.readTypeArray(in, locals_size, method);
duke@1 161 int stack_size = in.readUnsignedShort();
duke@1 162 int[] stack = StackMapData.readTypeArray(in, stack_size, method);
duke@1 163 return new FullFrame(offsetDelta, locals, stack);
duke@1 164 } else {
duke@1 165 throw new ClassFormatError("unrecognized frame_type in StackMapTable");
duke@1 166 }
duke@1 167 }
duke@1 168 }

mercurial