1 34 35 package org.logicalcobwebs.asm; 36 37 41 42 public class Label { 43 44 47 48 CodeWriter owner; 49 50 53 54 boolean resolved; 55 56 59 60 int position; 61 62 65 66 private int referenceCount; 67 68 77 78 private int[] srcAndRefPositions; 79 80 90 95 96 int beginStackSize; 97 98 104 105 int maxStackSize; 106 107 112 113 Edge successors; 114 115 119 120 Label next; 121 122 126 127 boolean pushed; 128 129 133 136 137 public Label () { 138 } 139 140 144 159 160 void put ( 161 final CodeWriter owner, 162 final ByteVector out, 163 final int source, 164 final boolean wideOffset) 165 { 166 if (CodeWriter.CHECK) { 167 if (this.owner == null) { 168 this.owner = owner; 169 } else if (this.owner != owner) { 170 throw new IllegalArgumentException (); 171 } 172 } 173 if (resolved) { 174 if (wideOffset) { 175 out.put4(position - source); 176 } else { 177 out.put2(position - source); 178 } 179 } else { 180 if (wideOffset) { 181 addReference(-1 - source, out.length); 182 out.put4(-1); 183 } else { 184 addReference(source, out.length); 185 out.put2(-1); 186 } 187 } 188 } 189 190 201 202 private void addReference ( 203 final int sourcePosition, 204 final int referencePosition) 205 { 206 if (srcAndRefPositions == null) { 207 srcAndRefPositions = new int[6]; 208 } 209 if (referenceCount >= srcAndRefPositions.length) { 210 int[] a = new int[srcAndRefPositions.length + 6]; 211 System.arraycopy(srcAndRefPositions, 0, a, 0, srcAndRefPositions.length); 212 srcAndRefPositions = a; 213 } 214 srcAndRefPositions[referenceCount++] = sourcePosition; 215 srcAndRefPositions[referenceCount++] = referencePosition; 216 } 217 218 236 237 boolean resolve ( 238 final CodeWriter owner, 239 final int position, 240 final byte[] data) 241 { 242 if (CodeWriter.CHECK) { 243 if (this.owner == null) { 244 this.owner = owner; 245 } 246 if (resolved || this.owner != owner) { 247 throw new IllegalArgumentException (); 248 } 249 } 250 boolean needUpdate = false; 251 this.resolved = true; 252 this.position = position; 253 int i = 0; 254 while (i < referenceCount) { 255 int source = srcAndRefPositions[i++]; 256 int reference = srcAndRefPositions[i++]; 257 int offset; 258 if (source >= 0) { 259 offset = position - source; 260 if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) { 261 int opcode = data[reference - 1] & 0xFF; 268 if (opcode <= Constants.JSR) { 269 data[reference - 1] = (byte)(opcode + 49); 271 } else { 272 data[reference - 1] = (byte)(opcode + 20); 274 } 275 needUpdate = true; 276 } 277 data[reference++] = (byte)(offset >>> 8); 278 data[reference] = (byte)offset; 279 } else { 280 offset = position + source + 1; 281 data[reference++] = (byte)(offset >>> 24); 282 data[reference++] = (byte)(offset >>> 16); 283 data[reference++] = (byte)(offset >>> 8); 284 data[reference] = (byte)offset; 285 } 286 } 287 return needUpdate; 288 } 289 } 290 | Popular Tags |