1 30 package com.tc.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 85 86 91 int beginStackSize; 92 93 99 int maxStackSize; 100 101 106 Edge successors; 107 108 112 Label next; 113 114 118 boolean pushed; 119 120 124 127 public Label() { 128 } 129 130 134 143 public int getOffset() { 144 if (!resolved) { 145 throw new IllegalStateException ("Label offset position has not been resolved yet"); 146 } 147 return position; 148 } 149 150 165 void put( 166 final MethodWriter owner, 167 final ByteVector out, 168 final int source, 169 final boolean wideOffset) 170 { 171 if (resolved) { 172 if (wideOffset) { 173 out.putInt(position - source); 174 } else { 175 out.putShort(position - source); 176 } 177 } else { 178 if (wideOffset) { 179 addReference(-1 - source, out.length); 180 out.putInt(-1); 181 } else { 182 addReference(source, out.length); 183 out.putShort(-1); 184 } 185 } 186 } 187 188 200 private void addReference( 201 final int sourcePosition, 202 final int referencePosition) 203 { 204 if (srcAndRefPositions == null) { 205 srcAndRefPositions = new int[6]; 206 } 207 if (referenceCount >= srcAndRefPositions.length) { 208 int[] a = new int[srcAndRefPositions.length + 6]; 209 System.arraycopy(srcAndRefPositions, 210 0, 211 a, 212 0, 213 srcAndRefPositions.length); 214 srcAndRefPositions = a; 215 } 216 srcAndRefPositions[referenceCount++] = sourcePosition; 217 srcAndRefPositions[referenceCount++] = referencePosition; 218 } 219 220 239 boolean resolve( 240 final MethodWriter owner, 241 final int position, 242 final byte[] data) 243 { 244 boolean needUpdate = false; 245 this.resolved = true; 246 this.position = position; 247 int i = 0; 248 while (i < referenceCount) { 249 int source = srcAndRefPositions[i++]; 250 int reference = srcAndRefPositions[i++]; 251 int offset; 252 if (source >= 0) { 253 offset = position - source; 254 if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) { 255 264 int opcode = data[reference - 1] & 0xFF; 265 if (opcode <= Opcodes.JSR) { 266 data[reference - 1] = (byte) (opcode + 49); 268 } else { 269 data[reference - 1] = (byte) (opcode + 20); 271 } 272 needUpdate = true; 273 } 274 data[reference++] = (byte) (offset >>> 8); 275 data[reference] = (byte) offset; 276 } else { 277 offset = position + source + 1; 278 data[reference++] = (byte) (offset >>> 24); 279 data[reference++] = (byte) (offset >>> 16); 280 data[reference++] = (byte) (offset >>> 8); 281 data[reference] = (byte) offset; 282 } 283 } 284 return needUpdate; 285 } 286 287 291 296 public String toString() { 297 return "L" + System.identityHashCode(this); 298 } 299 } 300 | Popular Tags |