You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WeaverStateInfo.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /* *******************************************************************
  2. * Copyright (c) 2002-2019 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.ByteArrayInputStream;
  14. import java.io.ByteArrayOutputStream;
  15. import java.io.DataInputStream;
  16. import java.io.DataOutputStream;
  17. import java.io.IOException;
  18. import java.util.ArrayList;
  19. import java.util.Collection;
  20. import java.util.Collections;
  21. import java.util.HashSet;
  22. import java.util.List;
  23. import java.util.Set;
  24. import java.util.zip.ZipEntry;
  25. import java.util.zip.ZipInputStream;
  26. import org.aspectj.bridge.IMessage;
  27. import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
  28. /**
  29. * WeaverStateInfo represents how a type was processed. It is used by the weaver to determine how a type was previously treated and
  30. * whether reweaving is allowed. The format in the data stream is:
  31. *
  32. * Byte: Kind. UNTOUCHED|WOVEN|EXTENDED - If extended it can have two extra bits set 'REWEAVABLE' and 'REWEAVABLE_COMPRESSION_BIT'
  33. * Short: typeMungerCount - how many type mungers have affected this type <UnresolvedType & ResolvedTypeMunger>: The type mungers
  34. * themselves If we are reweavable then we also have: Short: Number of aspects that touched this type in some way when it was
  35. * previously woven <String> The fully qualified name of each type Int: Length of class file data (i.e. the unwovenclassfile)
  36. * Byte[]: The class file data, compressed if REWEAVABLE_COMPRESSION_BIT set.
  37. *
  38. * @author Andy Clement
  39. */
  40. public class WeaverStateInfo {
  41. private List<Entry> typeMungers;
  42. private boolean oldStyle;
  43. private boolean reweavable;
  44. private boolean reweavableCompressedMode; // If true, unwovenClassFile is uncompressed on read
  45. private boolean reweavableDiffMode; // if true, unwovenClassFile is written and read as a diff
  46. // These must exist in the world for reweaving to be valid.
  47. // It is a set of signatures 'La/b/c/D;'
  48. private Set<String> aspectsAffectingType;
  49. private byte[] unwovenClassFile; // Original 'untouched' class file
  50. private static boolean reweavableDefault = true; // ajh02: changed from false;
  51. private static boolean reweavableCompressedModeDefault = false;
  52. private static boolean reweavableDiffModeDefault = true;
  53. // when serializing the WeaverStateInfo we come to adding the reweavable data,
  54. // we'd like to add a diff of the unwovenClassFile and the wovenClassFile,
  55. // but we don't have the wovenClassFile yet as we're still in the process of making it.
  56. // so we put this key there instead as a stub.
  57. // Then when the wovenClassFile has been made, replaceKeyWithDiff is called.
  58. private static byte[] key = { -51, 34, 105, 56, -34, 65, 45, 78, -26, 125, 114, 97, 98, 1, -1, -42 };
  59. private boolean unwovenClassFileIsADiff = false;
  60. int compressionEnabled = 0; // 0=dont know, 1=no, 2=yes
  61. private void checkCompressionEnabled() {
  62. if (compressionEnabled == 0) {
  63. // work it out!
  64. compressionEnabled = 1;
  65. try {
  66. String value = System.getProperty("aspectj.compression.weaverstateinfo", "false");
  67. if (value.equalsIgnoreCase("true")) {
  68. System.out.println("ASPECTJ: aspectj.compression.weaverstateinfo=true: compressing weaverstateinfo");
  69. compressionEnabled = 2;
  70. }
  71. } catch (Throwable t) {
  72. // nop
  73. }
  74. }
  75. }
  76. private WeaverStateInfo() {
  77. // this(new ArrayList(), false,reweavableDefault,reweavableCompressedModeDefault,reweavableDiffModeDefault);
  78. }
  79. public WeaverStateInfo(boolean reweavable) {
  80. this(new ArrayList<Entry>(), false, reweavable, reweavableCompressedModeDefault, reweavableDiffModeDefault);
  81. }
  82. private WeaverStateInfo(List<Entry> typeMungers, boolean oldStyle, boolean reweavableMode, boolean reweavableCompressedMode,
  83. boolean reweavableDiffMode) {
  84. this.typeMungers = typeMungers;
  85. this.oldStyle = oldStyle;
  86. this.reweavable = reweavableMode;
  87. this.reweavableCompressedMode = reweavableCompressedMode;
  88. this.reweavableDiffMode = reweavableMode ? reweavableDiffMode : false;
  89. this.aspectsAffectingType = new HashSet<String>();
  90. this.unwovenClassFile = null;
  91. }
  92. public static void setReweavableModeDefaults(boolean mode, boolean compress, boolean diff) {
  93. reweavableDefault = mode;
  94. reweavableCompressedModeDefault = compress;
  95. reweavableDiffModeDefault = diff;
  96. }
  97. private static final int UNTOUCHED = 0, WOVEN = 2, EXTENDED = 3;
  98. // Use 'bits' for these capabilities - only valid in EXTENDED mode
  99. private static final byte REWEAVABLE_BIT = 1 << 4;
  100. private static final byte REWEAVABLE_COMPRESSION_BIT = 1 << 5;
  101. private static final byte REWEAVABLE_DIFF_BIT = 1 << 6;
  102. /** See comments on write() */
  103. public static final WeaverStateInfo read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  104. byte b = s.readByte();
  105. boolean isReweavable = ((b & REWEAVABLE_BIT) != 0);
  106. if (isReweavable) {
  107. b = (byte) (b - REWEAVABLE_BIT);
  108. }
  109. boolean isReweavableCompressed = ((b & REWEAVABLE_COMPRESSION_BIT) != 0);
  110. if (isReweavableCompressed) {
  111. b = (byte) (b - REWEAVABLE_COMPRESSION_BIT);
  112. }
  113. boolean isReweavableDiff = ((b & REWEAVABLE_DIFF_BIT) != 0);
  114. if (isReweavableDiff) {
  115. b = (byte) (b - REWEAVABLE_DIFF_BIT);
  116. }
  117. switch (b) {
  118. case UNTOUCHED:
  119. throw new RuntimeException("unexpected UNWOVEN");
  120. case WOVEN:
  121. return new WeaverStateInfo(Collections.<Entry>emptyList(), true, isReweavable, isReweavableCompressed, isReweavableDiff);
  122. case EXTENDED:
  123. boolean isCompressed = false;
  124. if (s.isAtLeast169()) {
  125. isCompressed = s.readBoolean();
  126. }
  127. int n = s.readShort();
  128. List<Entry> l = new ArrayList<Entry>();
  129. for (int i = 0; i < n; i++) {
  130. // conditional on version
  131. UnresolvedType aspectType = null;
  132. if (isCompressed) {
  133. int cpIndex = s.readShort();
  134. String signature = s.readUtf8(cpIndex);
  135. if (signature.charAt(0) == '@') { // '@missing@'
  136. aspectType = ResolvedType.MISSING;
  137. } else {
  138. aspectType = UnresolvedType.forSignature(signature);
  139. }
  140. } else {
  141. aspectType = UnresolvedType.read(s);
  142. }
  143. ResolvedTypeMunger typeMunger = ResolvedTypeMunger.read(s, context);
  144. l.add(new Entry(aspectType, typeMunger));
  145. }
  146. WeaverStateInfo wsi = new WeaverStateInfo(l, false, isReweavable, isReweavableCompressed, isReweavableDiff);
  147. readAnyReweavableData(wsi, s, isCompressed);
  148. return wsi;
  149. }
  150. throw new RuntimeException("bad WeaverState.Kind: " + b + ". File was :"
  151. + (context == null ? "unknown" : context.makeSourceLocation(0, 0).toString()));
  152. }
  153. private static class Entry {
  154. public UnresolvedType aspectType;
  155. public ResolvedTypeMunger typeMunger;
  156. public Entry(UnresolvedType aspectType, ResolvedTypeMunger typeMunger) {
  157. this.aspectType = aspectType;
  158. this.typeMunger = typeMunger;
  159. }
  160. public String toString() {
  161. return "<" + aspectType + ", " + typeMunger + ">";
  162. }
  163. }
  164. /**
  165. * Serialize the WeaverStateInfo. Various bits are set within the 'kind' flag to indicate the structure of the attribute. In
  166. * reweavable diff mode a 'marker' is inserted at the start of the attribute to indicate where the final calculated diff should
  167. * be inserted. When the key is replaced with the diff, the 'kind' byte moves to the front of the attribute - thats why in the
  168. * read logic you'll see it expecting the kind as the first byte.
  169. */
  170. public void write(CompressingDataOutputStream s) throws IOException {
  171. checkCompressionEnabled();
  172. if (oldStyle || reweavableCompressedMode) {
  173. throw new RuntimeException("shouldn't be writing this");
  174. }
  175. byte weaverStateInfoKind = EXTENDED;
  176. if (reweavable) {
  177. weaverStateInfoKind |= REWEAVABLE_BIT;
  178. }
  179. if (reweavableDiffMode) {
  180. s.write(key); // put key in so we can replace it with the diff later
  181. weaverStateInfoKind |= REWEAVABLE_DIFF_BIT;
  182. }
  183. s.writeByte(weaverStateInfoKind);
  184. // Tag whether the remainder of the data is subject to cp compression
  185. try {
  186. s.compressionEnabled = compressionEnabled == 2;
  187. s.writeBoolean(s.canCompress());
  188. int n = typeMungers.size();
  189. s.writeShort(n);
  190. for (Entry e : typeMungers) {
  191. if (s.canCompress()) {
  192. s.writeCompressedSignature(e.aspectType.getSignature());
  193. } else {
  194. e.aspectType.write(s);
  195. }
  196. e.typeMunger.write(s);
  197. }
  198. writeAnyReweavableData(this, s, s.canCompress());
  199. } finally {
  200. s.compressionEnabled = true;
  201. }
  202. }
  203. private final static byte[] NO_BYTES = new byte[0];
  204. /**
  205. * If the weaver is ever invoked in over weaving mode, we should
  206. * not include the key when writing out, it won't be replaced later.
  207. * If we turn off the reweaving flag that unfortunately removes
  208. * the 'what aspects have been woven into this type' list which we
  209. * want to keep as it helps overweaving avoid weaving an aspect in
  210. * twice.
  211. */
  212. public void markOverweavingInUse() {
  213. reweavableDiffMode = false;
  214. unwovenClassFile = NO_BYTES;
  215. }
  216. public void addConcreteMunger(ConcreteTypeMunger munger) {
  217. typeMungers.add(new Entry(munger.getAspectType(), munger.getMunger()));
  218. }
  219. public String toString() {
  220. return "WeaverStateInfo(aspectsAffectingType=" + aspectsAffectingType + "," + typeMungers + ", " + oldStyle + ")";
  221. }
  222. public List<ConcreteTypeMunger> getTypeMungers(ResolvedType onType) {
  223. World world = onType.getWorld();
  224. List<ConcreteTypeMunger> ret = new ArrayList<ConcreteTypeMunger>();
  225. for (Entry entry : typeMungers) {
  226. ResolvedType aspectType = world.resolve(entry.aspectType, true);
  227. if (aspectType.isMissing()) {
  228. world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ASPECT_NEEDED, entry.aspectType, onType),
  229. onType.getSourceLocation(), null);
  230. continue;
  231. }
  232. ret.add(new TemporaryTypeMunger(entry.typeMunger, aspectType));
  233. }
  234. return ret;
  235. }
  236. public boolean isOldStyle() {
  237. return oldStyle;
  238. }
  239. public byte[] getUnwovenClassFileData() {
  240. return unwovenClassFile;
  241. }
  242. public byte[] getUnwovenClassFileData(byte wovenClassFile[]) {
  243. if (unwovenClassFileIsADiff) {
  244. unwovenClassFile = applyDiff(wovenClassFile, unwovenClassFile);
  245. unwovenClassFileIsADiff = false;
  246. }
  247. return unwovenClassFile;
  248. }
  249. public void setUnwovenClassFileData(byte[] data) {
  250. unwovenClassFile = data;
  251. }
  252. public boolean isReweavable() {
  253. return reweavable;
  254. }
  255. public void setReweavable(boolean rw) {
  256. reweavable = rw;
  257. }
  258. public void addAspectsAffectingType(Collection<String> aspects) {
  259. aspectsAffectingType.addAll(aspects);
  260. }
  261. public void addAspectAffectingType(String aspectSignature) {
  262. aspectsAffectingType.add(aspectSignature);
  263. }
  264. public Set<String> getAspectsAffectingType() {
  265. return this.aspectsAffectingType;
  266. }
  267. private static void readAnyReweavableData(WeaverStateInfo wsi, VersionedDataInputStream s, boolean compressed)
  268. throws IOException {
  269. if (wsi.isReweavable()) {
  270. // Load list of aspects that need to exist in the world for reweaving to be 'legal'
  271. int numberAspectsAffectingType = s.readShort();
  272. for (int i = 0; i < numberAspectsAffectingType; i++) {
  273. String str = null;
  274. if (compressed) {
  275. str = s.readSignature();
  276. } else {
  277. str = s.readUTF();
  278. // Prior to 1.6.9 we were writing out names (com.foo.Bar) rather than signatures (Lcom/foo/Bar;)
  279. // From 1.6.9 onwards we write out signatures (pr319431)
  280. if (s.getMajorVersion() < WeaverVersionInfo.WEAVER_VERSION_AJ169) {
  281. // It is a name, make it a signature
  282. StringBuilder sb = new StringBuilder();
  283. sb.append("L").append(str.replace('.', '/')).append(";");
  284. str = sb.toString();
  285. }
  286. }
  287. wsi.addAspectAffectingType(str);
  288. }
  289. int unwovenClassFileSize = s.readInt();
  290. byte[] classData = null;
  291. // the unwovenClassFile may have been compressed:
  292. if (wsi.reweavableCompressedMode) {
  293. classData = new byte[unwovenClassFileSize];
  294. ZipInputStream zis = new ZipInputStream(s);
  295. ZipEntry zen = zis.getNextEntry();
  296. int current = 0;
  297. int bytesToGo = unwovenClassFileSize;
  298. while (bytesToGo > 0) {
  299. int amount = zis.read(classData, current, bytesToGo);
  300. current += amount;
  301. bytesToGo -= amount;
  302. }
  303. zis.closeEntry();
  304. if (bytesToGo != 0) {
  305. throw new IOException("ERROR whilst reading compressed reweavable data, expected " + unwovenClassFileSize
  306. + " bytes, only found " + current);
  307. }
  308. } else {
  309. classData = new byte[unwovenClassFileSize];
  310. if (unwovenClassFileSize != 0) {
  311. int bytesread = s.read(classData);
  312. if (bytesread != unwovenClassFileSize) {
  313. throw new IOException("ERROR whilst reading reweavable data, expected " + unwovenClassFileSize
  314. + " bytes, only found " + bytesread);
  315. }
  316. }
  317. }
  318. // if it was diffMode we'll have to remember to apply the diff if someone
  319. // asks for the unwovenClassFile
  320. wsi.unwovenClassFileIsADiff = wsi.reweavableDiffMode;
  321. wsi.setUnwovenClassFileData(classData);
  322. }
  323. }
  324. /**
  325. * Here is the cleverness for reweavable diff mode. The class file on disk contains, inside the weaverstateinfo attribute, a
  326. * diff that can be applied to 'itself' to recover the original class - which can then be rewoven.
  327. */
  328. public byte[] replaceKeyWithDiff(byte wovenClassFile[]) {
  329. // we couldn't have made the diff earlier
  330. // as we didn't have the wovenClassFile
  331. // so we left a key there as a marker to come back to
  332. if (reweavableDiffMode) {
  333. ByteArrayOutputStream arrayStream = new ByteArrayOutputStream();
  334. DataOutputStream s = new DataOutputStream(arrayStream);
  335. int endOfKey = findEndOfKey(wovenClassFile);
  336. int startOfKey = endOfKey - key.length;
  337. // the length of the wsi attribute is written infront of it in the classFile,
  338. // swapping the diff for the key will probably change the length of the wsi,
  339. // so we'll have to fiddle with the four 'int length' bytes
  340. int oldLengthLocation = startOfKey - 4;
  341. int oldLength = readInt(wovenClassFile, oldLengthLocation);
  342. wovenClassFile = deleteInArray(wovenClassFile, startOfKey, endOfKey); // delete the key
  343. byte[] wovenClassFileUpToWSI = new byte[oldLengthLocation];
  344. System.arraycopy(wovenClassFile, 0, wovenClassFileUpToWSI, 0, oldLengthLocation);
  345. byte[] diff = generateDiff(wovenClassFileUpToWSI, unwovenClassFile);
  346. try { // put the length of the diff infront of the diff
  347. s.writeInt(diff.length);
  348. s.write(diff);
  349. } catch (IOException e) {
  350. }
  351. diff = arrayStream.toByteArray();
  352. // we have to swap the oldLength for the new one,
  353. // and add the diff, using the oldLength to work out where it should go :)
  354. int newLength = oldLength - key.length + diff.length;
  355. byte newLengthBytes[] = serializeInt(newLength);
  356. // swap in the serialized newLength for the oldOne:
  357. wovenClassFile[oldLengthLocation] = newLengthBytes[0];
  358. wovenClassFile[oldLengthLocation + 1] = newLengthBytes[1];
  359. wovenClassFile[oldLengthLocation + 2] = newLengthBytes[2];
  360. wovenClassFile[oldLengthLocation + 3] = newLengthBytes[3];
  361. // add the diff
  362. wovenClassFile = insertArray(diff, wovenClassFile, oldLengthLocation + 4 + oldLength - key.length);
  363. }
  364. return wovenClassFile;
  365. }
  366. private static final int findEndOfKey(byte[] wovenClassFile) {
  367. // looks through the classfile backwards (as the attributes are all near the end)
  368. for (int i = wovenClassFile.length - 1; i > 0; i--) {
  369. if (endOfKeyHere(wovenClassFile, i)) {
  370. return i + 1;
  371. }
  372. }
  373. throw new RuntimeException("key not found in wovenClassFile"); // should never happen
  374. }
  375. private static final boolean endOfKeyHere(byte lookIn[], int i) {
  376. for (int j = 0; j < key.length; j++) {
  377. if (key[key.length - 1 - j] != lookIn[i - j]) {
  378. return false;
  379. }
  380. }
  381. return true;
  382. }
  383. private static final byte[] insertArray(byte toInsert[], byte original[], int offset) {
  384. byte result[] = new byte[original.length + toInsert.length];
  385. System.arraycopy(original, 0, result, 0, offset);
  386. System.arraycopy(toInsert, 0, result, offset, toInsert.length);
  387. System.arraycopy(original, offset, result, offset + toInsert.length, original.length - offset);
  388. return result;
  389. }
  390. private static final int readInt(byte[] a, int offset) {
  391. ByteArrayInputStream b = new ByteArrayInputStream(a, offset, 4);
  392. DataInputStream d = new DataInputStream(b);
  393. int length = -1;
  394. try {
  395. length = d.readInt();
  396. } catch (IOException e) {
  397. throw (new RuntimeException("readInt called with a bad array or offset")); // should never happen
  398. }
  399. return length;
  400. }
  401. private static final byte[] deleteInArray(byte a[], int start, int end) {
  402. int lengthToDelete = end - start;
  403. byte result[] = new byte[a.length - lengthToDelete]; // make a new array
  404. System.arraycopy(a, 0, result, 0, start); // copy in the bit before the deleted bit
  405. System.arraycopy(a, end, result, start, a.length - end); // copy in the bit after the deleted bit
  406. return result;
  407. }
  408. // ajh02: a quick note about the diff format...
  409. //
  410. // classfiles consist of:
  411. // 8 bytes: magic number and minor and major versions,
  412. // 2 bytes: its constant pool count
  413. // n bytes: the rest of the class file
  414. //
  415. // weaving a classfile never changes the classfile's first 8 bytes,
  416. // and after the constant pool count there's usually a run of bytes that weaving didn't change
  417. // hereafter referred to as the run
  418. //
  419. // so the diff consists of:
  420. // 2 bytes: its constant pool count
  421. // 4 bytes: length of the run
  422. // n bytes: the rest of the unwovenClassFile
  423. byte[] generateDiff(byte[] wovenClassFile, byte[] unWovenClassFile) {
  424. // find how long the run is
  425. int lookingAt = 10;
  426. int shorterLength = (wovenClassFile.length < unWovenClassFile.length) ? wovenClassFile.length : unWovenClassFile.length;
  427. while (lookingAt < shorterLength && (wovenClassFile[lookingAt] == unWovenClassFile[lookingAt])) {
  428. lookingAt++;
  429. }
  430. int lengthInCommon = lookingAt - 10;
  431. byte[] diff = new byte[unWovenClassFile.length - 4 - lengthInCommon];
  432. // first 2 bytes of the diff are the constant pool count
  433. diff[0] = unWovenClassFile[8];
  434. diff[1] = unWovenClassFile[9];
  435. // then 4 bytes saying how long the run is
  436. byte[] lengthInCommonBytes = serializeInt(lengthInCommon);
  437. diff[2] = lengthInCommonBytes[0];
  438. diff[3] = lengthInCommonBytes[1];
  439. diff[4] = lengthInCommonBytes[2];
  440. diff[5] = lengthInCommonBytes[3];
  441. // then we just dump the rest of the unWovenClassFile verbatim
  442. System.arraycopy(unWovenClassFile, 10 + lengthInCommon, diff, 6, diff.length - 6);
  443. return diff;
  444. }
  445. byte[] applyDiff(byte[] wovenClassFile, byte[] diff) {
  446. int lengthInCommon = readInt(diff, 2);
  447. byte[] unWovenClassFile = new byte[4 + diff.length + lengthInCommon];
  448. // copy the first 8 bytes from the wovenClassFile
  449. System.arraycopy(wovenClassFile, 0, unWovenClassFile, 0, 8);
  450. // copy the constant pool count from the diff
  451. unWovenClassFile[8] = diff[0];
  452. unWovenClassFile[9] = diff[1];
  453. // copy the run from the wovenClassFile
  454. System.arraycopy(wovenClassFile, 10, unWovenClassFile, 10, lengthInCommon);
  455. // copy the stuff after the run from the diff
  456. System.arraycopy(diff, 6, unWovenClassFile, 10 + lengthInCommon, diff.length - 6);
  457. return unWovenClassFile;
  458. }
  459. private byte[] serializeInt(int i) {
  460. ByteArrayOutputStream bos = new ByteArrayOutputStream(4);
  461. DataOutputStream dos = new DataOutputStream(bos);
  462. try {
  463. dos.writeInt(i);
  464. } catch (IOException e) {
  465. }
  466. return bos.toByteArray();
  467. }
  468. private static void writeAnyReweavableData(WeaverStateInfo wsi, CompressingDataOutputStream s, boolean compress)
  469. throws IOException {
  470. if (wsi.isReweavable()) {
  471. // Write out list of aspects that must exist next time we try and weave this class
  472. s.writeShort(wsi.aspectsAffectingType.size());
  473. for (String type : wsi.aspectsAffectingType) {
  474. if (compress) {
  475. s.writeCompressedSignature(type);
  476. } else {
  477. s.writeUTF(type);
  478. }
  479. }
  480. byte[] data = wsi.unwovenClassFile;
  481. // if we're not in diffMode, write the unwovenClassFile now,
  482. // otherwise we'll insert it as a diff later
  483. if (!wsi.reweavableDiffMode) {
  484. s.writeInt(data.length);
  485. s.write(wsi.unwovenClassFile);
  486. }
  487. }
  488. }
  489. /**
  490. * @return true if the supplied aspect is already in the list of those affecting this type
  491. */
  492. public boolean isAspectAlreadyApplied(ResolvedType someAspect) {
  493. String someAspectSignature = someAspect.getSignature();
  494. for (String aspectSignature : aspectsAffectingType) {
  495. if (aspectSignature.equals(someAspectSignature)) {
  496. return true;
  497. }
  498. }
  499. return false;
  500. }
  501. }