1 19 20 package org.netbeans.modules.classfile; 21 22 import java.io.DataInputStream ; 23 import java.io.IOException ; 24 25 35 public abstract class StackMapFrame { 36 int frameType; 37 38 static StackMapFrame[] loadStackMapTable(DataInputStream in, ConstantPool pool) 39 throws IOException { 40 int n = in.readUnsignedShort(); 41 StackMapFrame[] entries = new StackMapFrame[n]; 42 for (int i = 0; i < n; i++) { 43 int tag = in.readUnsignedByte(); 44 StackMapFrame frame; 45 if (tag >= 0 && tag <= 63) 46 frame = new SameFrame(tag); 47 else if (tag >= 64 && tag <= 127) { 48 VerificationTypeInfo typeInfo = 49 VerificationTypeInfo.loadVerificationTypeInfo(in, pool); 50 frame = new SameLocals1StackItemFrame(tag, typeInfo); 51 } 52 else if (tag >= 128 && tag <= 246) 53 throw new InvalidClassFormatException("reserved stack map frame tag used: " + tag); 54 else if (tag == 247) { 55 int offset = in.readUnsignedShort(); 56 VerificationTypeInfo typeInfo = 57 VerificationTypeInfo.loadVerificationTypeInfo(in, pool); 58 frame = new SameLocals1StackItemFrameExtended(tag, offset, typeInfo); 59 } 60 else if (tag >= 248 && tag <= 250) { 61 int offset = in.readUnsignedShort(); 62 frame = new ChopFrame(tag, offset); 63 } 64 else if (tag == 251) { 65 int offset = in.readUnsignedShort(); 66 frame = new SameFrameExtended(tag, offset); 67 } 68 else if (tag >= 252 && tag <= 254) 69 frame = makeAppendFrame(tag, in, pool); 70 else 71 frame = makeFullFrame(in, pool); 72 entries[i] = frame; 73 } 74 return entries; 75 } 76 77 private static AppendFrame makeAppendFrame(int tag, DataInputStream in, ConstantPool pool) 78 throws IOException { 79 int offset = in.readUnsignedShort(); 80 VerificationTypeInfo[] locals = new VerificationTypeInfo[tag - 251]; 81 for (int i = 0; i < locals.length; i++) 82 locals[i] = VerificationTypeInfo.loadVerificationTypeInfo(in, pool); 83 return new AppendFrame(tag, offset, locals); 84 } 85 86 private static FullFrame makeFullFrame(DataInputStream in, ConstantPool pool) 87 throws IOException { 88 int offset = in.readUnsignedShort(); 89 int n = in.readUnsignedShort(); 90 VerificationTypeInfo[] locals = new VerificationTypeInfo[n]; 91 for (int i = 0; i < locals.length; i++) 92 locals[i] = VerificationTypeInfo.loadVerificationTypeInfo(in, pool); 93 n = in.readUnsignedShort(); 94 VerificationTypeInfo[] stackItems = new VerificationTypeInfo[n]; 95 for (int i = 0; i < stackItems.length; i++) 96 stackItems[i] = VerificationTypeInfo.loadVerificationTypeInfo(in, pool); 97 return new FullFrame(255, offset, locals, stackItems); 98 } 99 100 101 StackMapFrame(int tag) { 102 frameType = tag; 103 } 104 105 109 public final int getFrameType() { 110 return frameType; 111 } 112 113 125 public abstract int getOffsetDelta(); 126 127 132 public static final class SameFrame extends StackMapFrame { 133 SameFrame(int tag) { 134 super(tag); 135 } 136 137 141 public int getOffsetDelta() { 142 return frameType; 143 } 144 } 145 146 151 public static final class SameLocals1StackItemFrame extends StackMapFrame { 152 VerificationTypeInfo typeInfo; 153 SameLocals1StackItemFrame(int tag, VerificationTypeInfo typeInfo) { 154 super(tag); 155 this.typeInfo = typeInfo; 156 } 157 158 162 public int getOffsetDelta() { 163 return frameType - 64; 164 } 165 166 170 public VerificationTypeInfo getVerificationTypeInfo() { 171 return typeInfo; 172 } 173 } 174 175 180 public static final class SameLocals1StackItemFrameExtended extends StackMapFrame { 181 int offset; 182 VerificationTypeInfo typeInfo; 183 SameLocals1StackItemFrameExtended(int tag, int offset, VerificationTypeInfo typeInfo) { 184 super(tag); 185 this.offset = offset; 186 this.typeInfo = typeInfo; 187 } 188 189 192 public int getOffsetDelta() { 193 return offset; 194 } 195 196 200 public VerificationTypeInfo getVerificationTypeInfo() { 201 return typeInfo; 202 } 203 } 204 205 211 public static final class ChopFrame extends StackMapFrame { 212 int offset; 213 ChopFrame(int tag, int offset) { 214 super(tag); 215 this.offset = offset; 216 } 217 218 221 public int getOffsetDelta() { 222 return offset; 223 } 224 } 225 226 231 public static final class SameFrameExtended extends StackMapFrame { 232 int offset; 233 SameFrameExtended(int tag, int offset) { 234 super(tag); 235 this.offset = offset; 236 } 237 238 241 public int getOffsetDelta() { 242 return offset; 243 } 244 } 245 246 252 public static final class AppendFrame extends StackMapFrame { 253 int offset; 254 VerificationTypeInfo[] locals; 255 AppendFrame(int tag, int offset, VerificationTypeInfo[] locals) { 256 super(tag); 257 this.offset = offset; 258 this.locals = locals; 259 } 260 261 264 public int getOffsetDelta() { 265 return offset; 266 } 267 268 272 public VerificationTypeInfo[] getLocals() { 273 return locals.clone(); 274 } 275 } 276 277 281 public static final class FullFrame extends StackMapFrame { 282 int offset; 283 VerificationTypeInfo[] locals; 284 VerificationTypeInfo[] stackItems; 285 FullFrame(int tag, int offset, VerificationTypeInfo[] locals, 286 VerificationTypeInfo[] stackItems) { 287 super(tag); 288 this.offset = offset; 289 this.locals = locals; 290 this.stackItems = stackItems; 291 } 292 293 296 public int getOffsetDelta() { 297 return offset; 298 } 299 300 304 public VerificationTypeInfo[] getLocals() { 305 return locals.clone(); 306 } 307 308 312 public VerificationTypeInfo[] getStackItems() { 313 return stackItems.clone(); 314 } 315 } 316 } 317 | Popular Tags |