1 30 31 package oracle.toplink.libraries.asm; 32 33 39 40 public class Label { 41 42 45 46 CodeWriter owner; 47 48 51 52 int line; 53 54 57 58 boolean resolved; 59 60 63 64 int position; 65 66 69 70 boolean resized; 71 72 75 76 private int referenceCount; 77 78 87 88 private int[] srcAndRefPositions; 89 90 100 105 106 int beginStackSize; 107 108 114 115 int maxStackSize; 116 117 122 123 Edge successors; 124 125 129 130 Label next; 131 132 136 137 boolean pushed; 138 139 143 146 147 public Label () { 148 } 149 150 154 163 164 public int getOffset () { 165 if (!resolved) { 166 throw new IllegalStateException ( 167 "Label offset position has not been resolved yet"); 168 } 169 return position; 170 } 171 172 187 188 void put ( 189 final CodeWriter owner, 190 final ByteVector out, 191 final int source, 192 final boolean wideOffset) 193 { 194 if (CodeWriter.CHECK) { 195 if (this.owner == null) { 196 this.owner = owner; 197 } else if (this.owner != owner) { 198 throw new IllegalArgumentException (); 199 } 200 } 201 if (resolved) { 202 if (wideOffset) { 203 out.putInt(position - source); 204 } else { 205 out.putShort(position - source); 206 } 207 } else { 208 if (wideOffset) { 209 addReference(-1 - source, out.length); 210 out.putInt(-1); 211 } else { 212 addReference(source, out.length); 213 out.putShort(-1); 214 } 215 } 216 } 217 218 229 230 private void addReference ( 231 final int sourcePosition, 232 final int referencePosition) 233 { 234 if (srcAndRefPositions == null) { 235 srcAndRefPositions = new int[6]; 236 } 237 if (referenceCount >= srcAndRefPositions.length) { 238 int[] a = new int[srcAndRefPositions.length + 6]; 239 System.arraycopy(srcAndRefPositions, 0, a, 0, srcAndRefPositions.length); 240 srcAndRefPositions = a; 241 } 242 srcAndRefPositions[referenceCount++] = sourcePosition; 243 srcAndRefPositions[referenceCount++] = referencePosition; 244 } 245 246 264 265 boolean resolve ( 266 final CodeWriter owner, 267 final int position, 268 final byte[] data) 269 { 270 if (CodeWriter.CHECK) { 271 if (this.owner == null) { 272 this.owner = owner; 273 } 274 if (resolved || this.owner != owner) { 275 throw new IllegalArgumentException (); 276 } 277 } 278 boolean needUpdate = false; 279 this.resolved = true; 280 this.position = position; 281 int i = 0; 282 while (i < referenceCount) { 283 int source = srcAndRefPositions[i++]; 284 int reference = srcAndRefPositions[i++]; 285 int offset; 286 if (source >= 0) { 287 offset = position - source; 288 if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) { 289 int opcode = data[reference - 1] & 0xFF; 296 if (opcode <= Constants.JSR) { 297 data[reference - 1] = (byte)(opcode + 49); 299 } else { 300 data[reference - 1] = (byte)(opcode + 20); 302 } 303 needUpdate = true; 304 } 305 data[reference++] = (byte)(offset >>> 8); 306 data[reference] = (byte)offset; 307 } else { 308 offset = position + source + 1; 309 data[reference++] = (byte)(offset >>> 24); 310 data[reference++] = (byte)(offset >>> 16); 311 data[reference++] = (byte)(offset >>> 8); 312 data[reference] = (byte)offset; 313 } 314 } 315 return needUpdate; 316 } 317 318 322 327 328 public String toString () { 329 return "L" + System.identityHashCode(this); 330 } 331 } 332 | Popular Tags |