src/share/classes/com/sun/tools/classfile/StackMapTable_attribute.java

Tue, 24 Feb 2009 17:48:53 -0800

author
darcy
date
Tue, 24 Feb 2009 17:48:53 -0800
changeset 232
1fbc1cc6e260
parent 198
b4b1f7732289
child 229
03bcd66bd8e7
permissions
-rw-r--r--

6498938: Faulty comparison of TypeMirror objects in getElementsAnnotatedWith implementation
Reviewed-by: jjg

jjg@46 1 /*
xdono@54 2 * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
jjg@46 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@46 4 *
jjg@46 5 * This code is free software; you can redistribute it and/or modify it
jjg@46 6 * under the terms of the GNU General Public License version 2 only, as
jjg@46 7 * published by the Free Software Foundation. Sun designates this
jjg@46 8 * particular file as subject to the "Classpath" exception as provided
jjg@46 9 * by Sun in the LICENSE file that accompanied this code.
jjg@46 10 *
jjg@46 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@46 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@46 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@46 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@46 15 * accompanied this code).
jjg@46 16 *
jjg@46 17 * You should have received a copy of the GNU General Public License version
jjg@46 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@46 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@46 20 *
jjg@46 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@46 22 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@46 23 * have any questions.
jjg@46 24 */
jjg@46 25
jjg@46 26 package com.sun.tools.classfile;
jjg@46 27
jjg@46 28 import java.io.IOException;
jjg@46 29
jjg@46 30 /**
jjg@46 31 * See JVMS3, section 4.8.4.
jjg@46 32 *
jjg@46 33 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
jjg@46 34 * you write code that depends on this, you do so at your own risk.
jjg@46 35 * This code and its internal interfaces are subject to change or
jjg@46 36 * deletion without notice.</b>
jjg@46 37 */
jjg@46 38 public class StackMapTable_attribute extends Attribute {
jjg@46 39 static class InvalidStackMap extends AttributeException {
jjg@198 40 private static final long serialVersionUID = -5659038410855089780L;
jjg@46 41 InvalidStackMap(String msg) {
jjg@46 42 super(msg);
jjg@46 43 }
jjg@46 44 }
jjg@46 45
jjg@46 46 StackMapTable_attribute(ClassReader cr, int name_index, int length)
jjg@46 47 throws IOException, InvalidStackMap {
jjg@46 48 super(name_index, length);
jjg@46 49 number_of_entries = cr.readUnsignedShort();
jjg@46 50 entries = new stack_map_frame[number_of_entries];
jjg@46 51 for (int i = 0; i < number_of_entries; i++)
jjg@46 52 entries[i] = stack_map_frame.read(cr);
jjg@46 53 }
jjg@46 54
jjg@46 55 public StackMapTable_attribute(ConstantPool constant_pool, stack_map_frame[] entries)
jjg@46 56 throws ConstantPoolException {
jjg@46 57 this(constant_pool.getUTF8Index(Attribute.StackMapTable), entries);
jjg@46 58 }
jjg@46 59
jjg@46 60 public StackMapTable_attribute(int name_index, stack_map_frame[] entries) {
jjg@46 61 super(name_index, length(entries));
jjg@46 62 this.number_of_entries = entries.length;
jjg@46 63 this.entries = entries;
jjg@46 64 }
jjg@46 65
jjg@46 66 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 67 return visitor.visitStackMapTable(this, data);
jjg@46 68 }
jjg@46 69
jjg@46 70 static int length(stack_map_frame[] entries) {
jjg@46 71 int n = 2;
jjg@46 72 for (stack_map_frame entry: entries)
jjg@46 73 n += entry.length();
jjg@46 74 return n;
jjg@46 75 }
jjg@46 76
jjg@46 77 public final int number_of_entries;
jjg@46 78 public final stack_map_frame entries[];
jjg@46 79
jjg@46 80 public static abstract class stack_map_frame {
jjg@46 81 static stack_map_frame read(ClassReader cr)
jjg@46 82 throws IOException, InvalidStackMap {
jjg@46 83 int frame_type = cr.readUnsignedByte();
jjg@46 84 if (frame_type <= 63)
jjg@46 85 return new same_frame(frame_type);
jjg@46 86 else if (frame_type <= 127)
jjg@46 87 return new same_locals_1_stack_item_frame(frame_type, cr);
jjg@46 88 else if (frame_type <= 246)
jjg@46 89 throw new Error("unknown frame_type " + frame_type);
jjg@46 90 else if (frame_type == 247)
jjg@46 91 return new same_locals_1_stack_item_frame_extended(frame_type, cr);
jjg@46 92 else if (frame_type <= 250)
jjg@46 93 return new chop_frame(frame_type, cr);
jjg@46 94 else if (frame_type == 251)
jjg@46 95 return new same_frame_extended(frame_type, cr);
jjg@46 96 else if (frame_type <= 254)
jjg@46 97 return new append_frame(frame_type, cr);
jjg@46 98 else
jjg@46 99 return new full_frame(frame_type, cr);
jjg@46 100 }
jjg@46 101
jjg@46 102 protected stack_map_frame(int frame_type) {
jjg@46 103 this.frame_type = frame_type;
jjg@46 104 }
jjg@46 105
jjg@46 106 public int length() {
jjg@46 107 return 1;
jjg@46 108 }
jjg@46 109
jjg@46 110 public abstract <R,D> R accept(Visitor<R,D> visitor, D data);
jjg@46 111
jjg@46 112 public final int frame_type;
jjg@46 113
jjg@46 114 public static interface Visitor<R,P> {
jjg@46 115 R visit_same_frame(same_frame frame, P p);
jjg@46 116 R visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, P p);
jjg@46 117 R visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, P p);
jjg@46 118 R visit_chop_frame(chop_frame frame, P p);
jjg@46 119 R visit_same_frame_extended(same_frame_extended frame, P p);
jjg@46 120 R visit_append_frame(append_frame frame, P p);
jjg@46 121 R visit_full_frame(full_frame frame, P p);
jjg@46 122 }
jjg@46 123 }
jjg@46 124
jjg@46 125 public static class same_frame extends stack_map_frame {
jjg@46 126 same_frame(int frame_type) {
jjg@46 127 super(frame_type);
jjg@46 128 }
jjg@46 129
jjg@46 130 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 131 return visitor.visit_same_frame(this, data);
jjg@46 132 }
jjg@46 133 }
jjg@46 134
jjg@46 135 public static class same_locals_1_stack_item_frame extends stack_map_frame {
jjg@46 136 same_locals_1_stack_item_frame(int frame_type, ClassReader cr)
jjg@46 137 throws IOException, InvalidStackMap {
jjg@46 138 super(frame_type);
jjg@46 139 stack = new verification_type_info[1];
jjg@46 140 stack[0] = verification_type_info.read(cr);
jjg@46 141 }
jjg@46 142
jjg@46 143 @Override
jjg@46 144 public int length() {
jjg@46 145 return super.length() + stack[0].length();
jjg@46 146 }
jjg@46 147
jjg@46 148 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 149 return visitor.visit_same_locals_1_stack_item_frame(this, data);
jjg@46 150 }
jjg@46 151
jjg@46 152 public final verification_type_info[] stack;
jjg@46 153 }
jjg@46 154
jjg@46 155 public static class same_locals_1_stack_item_frame_extended extends stack_map_frame {
jjg@46 156 same_locals_1_stack_item_frame_extended(int frame_type, ClassReader cr)
jjg@46 157 throws IOException, InvalidStackMap {
jjg@46 158 super(frame_type);
jjg@46 159 offset_delta = cr.readUnsignedShort();
jjg@46 160 stack = new verification_type_info[1];
jjg@46 161 stack[0] = verification_type_info.read(cr);
jjg@46 162 }
jjg@46 163
jjg@46 164 @Override
jjg@46 165 public int length() {
jjg@46 166 return super.length() + 2 + stack[0].length();
jjg@46 167 }
jjg@46 168
jjg@46 169 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 170 return visitor.visit_same_locals_1_stack_item_frame_extended(this, data);
jjg@46 171 }
jjg@46 172
jjg@46 173 public final int offset_delta;
jjg@46 174 public final verification_type_info[] stack;
jjg@46 175 }
jjg@46 176
jjg@46 177 public static class chop_frame extends stack_map_frame {
jjg@46 178 chop_frame(int frame_type, ClassReader cr) throws IOException {
jjg@46 179 super(frame_type);
jjg@46 180 offset_delta = cr.readUnsignedShort();
jjg@46 181 }
jjg@46 182
jjg@46 183 @Override
jjg@46 184 public int length() {
jjg@46 185 return super.length() + 2;
jjg@46 186 }
jjg@46 187
jjg@46 188 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 189 return visitor.visit_chop_frame(this, data);
jjg@46 190 }
jjg@46 191
jjg@46 192 public final int offset_delta;
jjg@46 193 }
jjg@46 194
jjg@46 195 public static class same_frame_extended extends stack_map_frame {
jjg@46 196 same_frame_extended(int frame_type, ClassReader cr) throws IOException {
jjg@46 197 super(frame_type);
jjg@46 198 offset_delta = cr.readUnsignedShort();
jjg@46 199 }
jjg@46 200
jjg@46 201 @Override
jjg@46 202 public int length() {
jjg@46 203 return super.length() + 2;
jjg@46 204 }
jjg@46 205
jjg@46 206 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 207 return visitor.visit_same_frame_extended(this, data);
jjg@46 208 }
jjg@46 209
jjg@46 210 public final int offset_delta;
jjg@46 211 }
jjg@46 212
jjg@46 213 public static class append_frame extends stack_map_frame {
jjg@46 214 append_frame(int frame_type, ClassReader cr)
jjg@46 215 throws IOException, InvalidStackMap {
jjg@46 216 super(frame_type);
jjg@46 217 offset_delta = cr.readUnsignedShort();
jjg@46 218 locals = new verification_type_info[frame_type - 251];
jjg@46 219 for (int i = 0; i < locals.length; i++)
jjg@46 220 locals[i] = verification_type_info.read(cr);
jjg@46 221 }
jjg@46 222
jjg@46 223 @Override
jjg@46 224 public int length() {
jjg@46 225 int n = super.length() + 2;
jjg@46 226 for (verification_type_info local: locals)
jjg@46 227 n += local.length();
jjg@46 228 return n;
jjg@46 229 }
jjg@46 230
jjg@46 231 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 232 return visitor.visit_append_frame(this, data);
jjg@46 233 }
jjg@46 234
jjg@46 235 public final int offset_delta;
jjg@46 236 public final verification_type_info[] locals;
jjg@46 237 }
jjg@46 238
jjg@46 239 public static class full_frame extends stack_map_frame {
jjg@46 240 full_frame(int frame_type, ClassReader cr)
jjg@46 241 throws IOException, InvalidStackMap {
jjg@46 242 super(frame_type);
jjg@46 243 offset_delta = cr.readUnsignedShort();
jjg@46 244 number_of_locals = cr.readUnsignedShort();
jjg@46 245 locals = new verification_type_info[number_of_locals];
jjg@46 246 for (int i = 0; i < locals.length; i++)
jjg@46 247 locals[i] = verification_type_info.read(cr);
jjg@46 248 number_of_stack_items = cr.readUnsignedShort();
jjg@46 249 stack = new verification_type_info[number_of_stack_items];
jjg@46 250 for (int i = 0; i < stack.length; i++)
jjg@46 251 stack[i] = verification_type_info.read(cr);
jjg@46 252 }
jjg@46 253
jjg@46 254 @Override
jjg@46 255 public int length() {
jjg@46 256 int n = super.length() + 2;
jjg@46 257 for (verification_type_info local: locals)
jjg@46 258 n += local.length();
jjg@46 259 n += 2;
jjg@46 260 for (verification_type_info item: stack)
jjg@46 261 n += item.length();
jjg@46 262 return n;
jjg@46 263 }
jjg@46 264
jjg@46 265 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 266 return visitor.visit_full_frame(this, data);
jjg@46 267 }
jjg@46 268
jjg@46 269 public final int offset_delta;
jjg@46 270 public final int number_of_locals;
jjg@46 271 public final verification_type_info[] locals;
jjg@46 272 public final int number_of_stack_items;
jjg@46 273 public final verification_type_info[] stack;
jjg@46 274 }
jjg@46 275
jjg@46 276 public static class verification_type_info {
jjg@46 277 public static final int ITEM_Top = 0;
jjg@46 278 public static final int ITEM_Integer = 1;
jjg@46 279 public static final int ITEM_Float = 2;
jjg@46 280 public static final int ITEM_Long = 4;
jjg@46 281 public static final int ITEM_Double = 3;
jjg@46 282 public static final int ITEM_Null = 5;
jjg@46 283 public static final int ITEM_UninitializedThis = 6;
jjg@46 284 public static final int ITEM_Object = 7;
jjg@46 285 public static final int ITEM_Uninitialized = 8;
jjg@46 286
jjg@46 287 static verification_type_info read(ClassReader cr)
jjg@46 288 throws IOException, InvalidStackMap {
jjg@46 289 int tag = cr.readUnsignedByte();
jjg@46 290 switch (tag) {
jjg@46 291 case ITEM_Top:
jjg@46 292 case ITEM_Integer:
jjg@46 293 case ITEM_Float:
jjg@46 294 case ITEM_Long:
jjg@46 295 case ITEM_Double:
jjg@46 296 case ITEM_Null:
jjg@46 297 case ITEM_UninitializedThis:
jjg@46 298 return new verification_type_info(tag);
jjg@46 299
jjg@46 300 case ITEM_Object:
jjg@46 301 return new Object_variable_info(cr);
jjg@46 302
jjg@46 303 case ITEM_Uninitialized:
jjg@46 304 return new Uninitialized_variable_info(cr);
jjg@46 305
jjg@46 306 default:
jjg@46 307 throw new InvalidStackMap("unrecognized verification_type_info tag");
jjg@46 308 }
jjg@46 309 }
jjg@46 310
jjg@46 311 verification_type_info(int tag) {
jjg@46 312 this.tag = tag;
jjg@46 313 }
jjg@46 314
jjg@46 315 public int length() {
jjg@46 316 return 1;
jjg@46 317 }
jjg@46 318
jjg@46 319 public final int tag;
jjg@46 320 }
jjg@46 321
jjg@46 322 public static class Object_variable_info extends verification_type_info {
jjg@46 323 Object_variable_info(ClassReader cr) throws IOException {
jjg@46 324 super(ITEM_Object);
jjg@46 325 cpool_index = cr.readUnsignedShort();
jjg@46 326 }
jjg@46 327
jjg@46 328 @Override
jjg@46 329 public int length() {
jjg@46 330 return super.length() + 2;
jjg@46 331 }
jjg@46 332
jjg@46 333 public final int cpool_index;
jjg@46 334 }
jjg@46 335
jjg@46 336 public static class Uninitialized_variable_info extends verification_type_info {
jjg@46 337 Uninitialized_variable_info(ClassReader cr) throws IOException {
jjg@46 338 super(ITEM_Uninitialized);
jjg@46 339 offset = cr.readUnsignedShort();
jjg@46 340 }
jjg@46 341
jjg@46 342 @Override
jjg@46 343 public int length() {
jjg@46 344 return super.length() + 2;
jjg@46 345 }
jjg@46 346
jjg@46 347 public final int offset;
jjg@46 348
jjg@46 349 }
jjg@46 350 }

mercurial