1 30 package org.objectweb.asm; 31 32 38 public class Label { 39 40 43 int line; 44 45 48 boolean resolved; 49 50 53 int position; 54 55 58 boolean resized; 59 60 63 private int referenceCount; 64 65 74 private int[] srcAndRefPositions; 75 76 89 int beginStackSize; 90 91 97 int maxStackSize; 98 99 104 Edge successors; 105 106 110 Label next; 111 112 116 boolean pushed; 117 118 122 125 public Label() { 126 } 127 128 132 141 public int getOffset() { 142 if (!resolved) { 143 throw new IllegalStateException ("Label offset position has not been resolved yet"); 144 } 145 return position; 146 } 147 148 163 void put( 164 final MethodWriter owner, 165 final ByteVector out, 166 final int source, 167 final boolean wideOffset) 168 { 169 if (resolved) { 170 if (wideOffset) { 171 out.putInt(position - source); 172 } else { 173 out.putShort(position - source); 174 } 175 } else { 176 if (wideOffset) { 177 addReference(-1 - source, out.length); 178 out.putInt(-1); 179 } else { 180 addReference(source, out.length); 181 out.putShort(-1); 182 } 183 } 184 } 185 186 198 private void addReference( 199 final int sourcePosition, 200 final int referencePosition) 201 { 202 if (srcAndRefPositions == null) { 203 srcAndRefPositions = new int[6]; 204 } 205 if (referenceCount >= srcAndRefPositions.length) { 206 int[] a = new int[srcAndRefPositions.length + 6]; 207 System.arraycopy(srcAndRefPositions, 208 0, 209 a, 210 0, 211 srcAndRefPositions.length); 212 srcAndRefPositions = a; 213 } 214 srcAndRefPositions[referenceCount++] = sourcePosition; 215 srcAndRefPositions[referenceCount++] = referencePosition; 216 } 217 218 237 boolean resolve( 238 final MethodWriter owner, 239 final int position, 240 final byte[] data) 241 { 242 boolean needUpdate = false; 243 this.resolved = true; 244 this.position = position; 245 int i = 0; 246 while (i < referenceCount) { 247 int source = srcAndRefPositions[i++]; 248 int reference = srcAndRefPositions[i++]; 249 int offset; 250 if (source >= 0) { 251 offset = position - source; 252 if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) { 253 262 int opcode = data[reference - 1] & 0xFF; 263 if (opcode <= Opcodes.JSR) { 264 data[reference - 1] = (byte) (opcode + 49); 266 } else { 267 data[reference - 1] = (byte) (opcode + 20); 269 } 270 needUpdate = true; 271 } 272 data[reference++] = (byte) (offset >>> 8); 273 data[reference] = (byte) offset; 274 } else { 275 offset = position + source + 1; 276 data[reference++] = (byte) (offset >>> 24); 277 data[reference++] = (byte) (offset >>> 16); 278 data[reference++] = (byte) (offset >>> 8); 279 data[reference] = (byte) offset; 280 } 281 } 282 return needUpdate; 283 } 284 285 289 294 public String toString() { 295 return "L" + System.identityHashCode(this); 296 } 297 } 298 | Popular Tags |