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.

README-190.html 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  2. <html> <head>
  3. <title>AspectJ 1.9.0 Readme</title>
  4. <style type="text/css">
  5. <!--
  6. P { margin-left: 20px; }
  7. PRE { margin-left: 20px; }
  8. LI { margin-left: 20px; }
  9. H4 { margin-left: 20px; }
  10. H3 { margin-left: 10px; }
  11. -->
  12. </style>
  13. </head>
  14. <body>
  15. <div align="right"><small>
  16. &copy; Copyright 2018 Contributors.
  17. All rights reserved.
  18. </small></div>
  19. <p>The full list of resolved issues in 1.9.0 is available
  20. <a href="https://bugs.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&f0=OP&f1=OP&f3=CP&f4=CP&j1=OR&list_id=16866879&product=AspectJ&query_format=advanced&target_milestone=1.9.0">here</a></h2>.</p>
  21. <h1>AspectJ 1.9.0</h1>
  22. <h4>Improved runtime interface</h4>
  23. <p>New factory methods have been added to the AspectJ runtime. This is an attempt to more optimally create <tt>thisJoinPoint</tt> and
  24. <tt>thisEnclosingJoinPoint</tt> objects. The generated code that invokes these now also uses the ability
  25. for the LDC bytecode instruction to load class constants directly (this replaces what was happening
  26. previously where generated code referenced string classnames and classloading was being done from the
  27. aspectj runtime as the woven application was starting).</p>
  28. <p>This is turned on by using <tt>-Xajruntimetarget:1.9</tt>. This option was used previously to enable
  29. users to target an old runtime if they knew that old runtime is all that was available at some deployed target.
  30. The new generation mechanism is not the default, not until it has had a bit more testing out in the wild.</p>
  31. <p>The changes to generated code have a couple of potential side effects:
  32. <ul>
  33. <li><b>overall size</b>: the woven code may be smaller due to the use of smaller string constant pieces in the generated
  34. code (previously strings were smashed together in the generated code and then taken apart by AspectJ at runtime).
  35. Since the pieces are smaller, they can be shared across other uses in the class file.
  36. <li><b>method size</b>: although the overall class may be smaller there are more instructions involved in preparing the
  37. data for invocation of the new joinpoint factory methods. It is possible if you have a lot of joinpoints that we might
  38. blow the 64k instruction limit for the <tt>ajc$preClinit</tt> method (where the factory invocation code is generated).
  39. Please provide feedback if this happens to you!
  40. </ul>
  41. <p>In anticipation of not all build plugins supporting that <tt>-Xajruntimetarget</tt> option, you can now specify
  42. these kinds of option in the <tt>ASPECTJ_OPTS</tt> environment variable. Set that in your environment:</p>
  43. <pre><code>
  44. export ASPECTJ_OPTS="-Xajruntimetarget:1.9"
  45. </code></pre>
  46. <p>And it should get picked up by AspectJ when it runs.</p>
  47. <ul>
  48. <li>1.9.0 available 2-Apr-2018
  49. </ul>
  50. <h1>AspectJ 1.9.0.RC4</h1>
  51. <p>Primary changes in RC4 are to add support for &lt;compilerArg&gt; in the Ant task. This enables users of the Ant task to
  52. pass in options supported by the underlying AspectJ but not yet surfaced elsewhere. Particularly useful with Java9 which includes
  53. a number of module related commands. For example, here is an iajc usage with compilerArg that is passing <tt>--add-modules java.xml.bind</tt>:
  54. <pre><code>
  55. &lt;iajc destdir="bin" failonerror="true"
  56. showWeaveInfo="true" source="1.9" target="1.9"
  57. debug="true" fork="true" maxmem="256m"&gt;
  58. &lt;compilerArg value="--add-modules"/&gt;
  59. &lt;compilerArg value="java.xml.bind"/&gt;
  60. &lt;src path="src" /&gt;
  61. &lt;classpath&gt;
  62. &lt;pathelement location="${aspectj.home}/lib/aspectjrt.jar"/&gt;
  63. &lt;/classpath&gt;
  64. &lt;/iajc&gt;
  65. </code></pre>
  66. <li>1.9.0.RC4 available 21-Feb-2018</li>
  67. <h1>AspectJ 1.9.0.RC3</h1>
  68. <p>Primary changes in RC3 are to upgrade JDT and pickup all the fixes for Java9 that have gone into it over the last few months.</p>
  69. <li>1.9.0.RC3 available 5-Feb-2018</li>
  70. <h1>AspectJ 1.9.0.RC2</h1>
  71. <ul>
  72. <li>1.9.0.RC2 available 9-Nov-2017
  73. </ul>
  74. <p>Key change in 1.9.0.RC2 is actually to be more tolerant of JDK10. The version handling has been somewhat overhauled so AspectJ 9 will
  75. behave better on Java 10 and future JDKs. This should put AspectJ in a better place if new JDK versions are going
  76. to arrive thick and fast.
  77. <h1>AspectJ 1.9.0.RC1</h1>
  78. <ul>
  79. <li>1.9.0.RC1 available 20-Oct-2017
  80. </ul>
  81. <p>This is the first release candidate of AspectJ 1.9.0 - the version of AspectJ to be based on Java9. It includes
  82. a recent version of the Eclipse Java9 compiler (from jdt core, commit #062ac5d7a6bf9).</p>
  83. <h4>Automatic Modules</h4>
  84. <p>AspectJ can now be used with the new module system available in Java9. The key jars in AspectJ have been given automatic module names.
  85. The automatic module name is <tt>org.aspectj.runtime</tt> for the <tt>aspectjrt</tt> module:</p>
  86. <pre><code>
  87. $ java --module-path &lt;pathto&gt;/lib/aspectjrt.jar --list-modules | grep aspectj
  88. org.aspectj.runtime file:///&lt;pathto&gt;/lib/aspectjrt.jar automatic
  89. </code></pre>
  90. <p>And similarly <tt>org.aspectj.weaver</tt> and <tt>org.aspectj.tools</tt> for <tt>aspectjweaver</tt> and <tt>aspectjtools</tt> respectively:</p>
  91. <pre><code>
  92. $ java --module-path &lt;pathto&gt;/lib/aspectjweaver.jar --describe-module org.aspectj.weaver
  93. org.aspectj.weaver file:///&lt;pathto&gt;/lib/aspectjweaver.jar automatic
  94. requires java.base mandated
  95. contains aj.org.objectweb.asm
  96. contains aj.org.objectweb.asm.signature
  97. contains org.aspectj.apache.bcel
  98. contains org.aspectj.apache.bcel.classfile
  99. contains org.aspectj.apache.bcel.classfile.annotation
  100. contains org.aspectj.apache.bcel.generic
  101. contains org.aspectj.apache.bcel.util
  102. contains org.aspectj.asm
  103. contains org.aspectj.asm.internal
  104. ...
  105. </code></pre>
  106. </p>
  107. <br><br>
  108. <h4>Building woven modules</h4>
  109. <p>AspectJ understands module-info.java source files and building modules that include aspects. Here is an example:</p>
  110. <pre><code>
  111. <b>module-info.java</b>
  112. module demo {
  113. exports pkg;
  114. requires org.aspectj.runtime;
  115. }
  116. <b>pkg/Demo.java</b>
  117. package pkg;
  118. public class Demo {
  119. public static void main(String[] argv) {
  120. System.out.println("Demo running");
  121. }
  122. }
  123. <b>otherpkg/Azpect.java</b>
  124. package otherpkg;
  125. public aspect Azpect {
  126. before(): execution(* *(..)) && !within(Azpect) {
  127. System.out.println("Azpect running");
  128. }
  129. }
  130. </code></pre>
  131. <p>We can now build those into a module:</p>
  132. <pre><code>
  133. $ ajc -1.9 module-info.java otherpkg/Azpect.java pkg/Demo.java -outjar demo.jar
  134. ...
  135. module-info.java:3 [error] org.aspectj.runtime cannot be resolved to a module
  136. ...
  137. </code></pre>
  138. <p>Wait, that failed! Yes, <tt>aspectjrt.jar</tt> (which includes the required <tt>org.aspectj.weaver</tt> module) wasn't supplied.
  139. We need to pass it on the module-path:</p>
  140. <pre><code>
  141. $ ajc -1.9 --module-path &lt;pathto&gt;/aspectjrt.jar module-info.java otherpkg/Azpect.java pkg/Demo.java -outjar demo.jar
  142. </code></pre>
  143. <p>Now we have a demo module we can run:</p>
  144. <pre><code>
  145. $ java --module-path &lt;pathto&gt;/aspectjrt.jar:demo.jar --module demo/pkg.Demo
  146. Azpect running
  147. Demo running
  148. </code></pre>
  149. <p>That's it!</p>
  150. <br><br>
  151. <h4>Binary weaving with modules</h4>
  152. <p>A module is really just a jar with a module-info descriptor. As such you can simply pass a module on the <tt>inpath</tt>
  153. and binary weave it with other aspects. Take the module we built above, let's weave into it again:</p>
  154. <pre><code>extra/AnotherAzpect.java
  155. package extra;
  156. public aspect AnotherAzpect {
  157. before(): execution(* *(..)) && !within(*Azpect) {
  158. System.out.println("AnotherAzpect running");
  159. }
  160. }
  161. </code></pre>
  162. <pre><code>
  163. $ ajc -inpath demo.jar AnotherAzpect.java -outjar newdemo.jar</code></pre>
  164. <p>Notice how there was no complaint here that the <tt>org.aspectj.runtime</tt> module hadn't been passed in. That is because <tt>inpath</tt>
  165. was being used which doesn't treat specified jars as modules (and so does not check dependencies). There is no <tt>module-inpath</tt> right now.
  166. <p>Because the new jar produced includes the compiled aspect, the module-info specification inside is still correct, so we can run it
  167. exactly as before:</p>
  168. <pre><code>$ java --module-path ~/installs/aspectj190rc1/lib/aspectjrt.jar:newdemo.jar --module demo/pkg.Demo
  169. Azpect running
  170. AnotherAzpect running
  171. Demo running
  172. </code></pre>
  173. <br><br>
  174. <h4>Faster Spring AOP</h4>
  175. <p>Dave Syer recently created a series of benchmarks for checking the speed of Spring-AspectJ:
  176. <tt><a href="https://github.com/dsyer/spring-boot-aspectj">https://github.com/dsyer/spring-boot-aspectj</a></tt>
  177. <p>Here we can see the numbers for AspectJ 1.8.11 (on an older Macbook Pro):
  178. <pre><code>
  179. Benchmark (scale) Mode Cnt Score Error Units
  180. StartupBenchmark.ltw N/A avgt 10 2.553 ~ 0.030 s/op
  181. StartupBenchmark.ltw_100 N/A avgt 10 2.608 ~ 0.046 s/op
  182. StartupBenchmark.spring v0_10 avgt 10 2.120 ~ 0.148 s/op
  183. StartupBenchmark.spring v1_10 avgt 10 2.219 ~ 0.066 s/op
  184. StartupBenchmark.spring v1_100 avgt 10 2.244 ~ 0.030 s/op
  185. StartupBenchmark.spring v10_50 avgt 10 2.950 ~ 0.026 s/op
  186. StartupBenchmark.spring v20_50 avgt 10 3.854 ~ 0.090 s/op
  187. StartupBenchmark.spring v20_100 avgt 10 4.003 ~ 0.038 s/op
  188. StartupBenchmark.spring a0_10 avgt 10 2.067 ~ 0.019 s/op
  189. StartupBenchmark.spring a1_10 avgt 10 2.724 ~ 0.023 s/op
  190. StartupBenchmark.spring a1_100 avgt 10 2.778 ~ 0.057 s/op
  191. StartupBenchmark.spring a10_50 avgt 10 7.191 ~ 0.134 s/op
  192. StartupBenchmark.spring a10_100 avgt 10 7.191 ~ 0.168 s/op
  193. StartupBenchmark.spring a20_50 avgt 10 11.541 ~ 0.158 s/op
  194. StartupBenchmark.spring a20_100 avgt 10 11.464 ~ 0.157 s/op
  195. </code></pre>
  196. <p>So this is the average startup of an app affected by aspects applying to the beans involved.
  197. Where numbers are referenced the first is the number of aspects/pointcuts and the second
  198. is the number of beans. The 'a' indicates an annotation based pointcut vs a non-annotation
  199. based pointcut ('v'). Notice things are much worse for annotation based pointcuts. At 20
  200. pointcuts and 50 beans the app is 9 seconds slower to startup.
  201. <br>
  202. <p>In AspectJ 1.8.12 and 1.9.0.RC1 some work has been done here. The key change is to recognize that the use
  203. of annotations with runtime retention is much more likely than annotations with class level
  204. retention. Retrieving annotations with class retention is costly because we must open the
  205. bytes for the class file and dig around in there (vs runtime retention which are immediately
  206. accessible by reflection on the types). In 1.8.11 the actual type of the annotation involved
  207. in the matching is ignored and the code will fetch *all* the annotations on the type/method/field
  208. being matched against. So even if the match is looking for a runtime retention annotation, we
  209. were doing the costly thing of fetching any class retention annotations. In 1.8.12/1.9.0.RC1
  210. we take the type of the match annotation into account - allowing us to skip opening the classfiles
  211. in many cases. There is also some deeper work on activating caches that were not previously
  212. being used correctly but the primary change is factoring in the annotation type.
  213. <p>What difference does that make?
  214. AspectJ 1.9.0.RC1:
  215. <pre><code>
  216. Benchmark (scale) Mode Cnt Score Error Units
  217. StartupBenchmark.ltw N/A avgt 10 2.568 ~ 0.035 s/op
  218. StartupBenchmark.ltw_100 N/A avgt 10 2.622 ~ 0.075 s/op
  219. StartupBenchmark.spring v0_10 avgt 10 2.096 ~ 0.054 s/op
  220. StartupBenchmark.spring v1_10 avgt 10 2.206 ~ 0.031 s/op
  221. StartupBenchmark.spring v1_100 avgt 10 2.252 ~ 0.025 s/op
  222. StartupBenchmark.spring v10_50 avgt 10 2.979 ~ 0.071 s/op
  223. StartupBenchmark.spring v20_50 avgt 10 3.851 ~ 0.058 s/op
  224. StartupBenchmark.spring v20_100 avgt 10 4.000 ~ 0.046 s/op
  225. StartupBenchmark.spring a0_10 avgt 10 2.071 ~ 0.026 s/op
  226. StartupBenchmark.spring a1_10 avgt 10 2.182 ~ 0.032 s/op
  227. StartupBenchmark.spring a1_100 avgt 10 2.272 ~ 0.024 s/op
  228. StartupBenchmark.spring a10_50 avgt 10 2.557 ~ 0.027 s/op
  229. StartupBenchmark.spring a10_100 avgt 10 2.598 ~ 0.040 s/op
  230. StartupBenchmark.spring a20_50 avgt 10 2.961 ~ 0.043 s/op
  231. StartupBenchmark.spring a20_100 avgt 10 3.093 ~ 0.098 s/op
  232. </code></pre>
  233. <p>Look at the a20_100 case - instead of impacting start time by 9 seconds, it impacts it by 1 second.
  234. <h3>More to come...</h3>
  235. <ul>
  236. <li><p>Eclipse JDT Java 9 support is still being actively worked on and lots of fixes will be coming through over the next few months
  237. and included in AspectJ 1.9.X revisions.</p>
  238. <li><p>AspectJ does not currently modify <tt>module-info.java</tt> files. An aspect from one module applying to code in
  239. another module clearly introduces a dependency between those two modules. There is no reason - other than time! - that
  240. this can't be done. (<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=526244">Issue 526244</a>)</p>
  241. <li><p>Related to that AspectJ, on detection of aspects should be able to automatically introduce the <tt>requires org.aspectj.runtime</tt> to
  242. the <tt>module-info</tt>. (<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=526242">Issue 526242</a>)</p>
  243. <li><p>Module aware variants of AspectJ paths: <tt>--module-inpath</tt>, <tt>--module-aspectpath</tt>. (<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=526243">Issue 526243</a>)</p>
  244. </ul>
  245. <br><br>
  246. <!-- ============================== -->
  247. </body>
  248. </html>