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.

ltw.xml 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <chapter id="ltw" xreflabel="Load-Time Weaving">
  2. <title>Load-Time Weaving</title>
  3. <sect1 id="ltw-introduction">
  4. <title>Introduction</title>
  5. <para> The AspectJ weaver takes class files as input and produces class files as output.
  6. The weaving process itself can take place at one of three different times: compile-time,
  7. post-compile time, and load-time. The class files produced by the weaving process (and
  8. hence the run-time behaviour of an application) are the same regardless of the approach
  9. chosen. </para>
  10. <itemizedlist>
  11. <listitem> <para>Compile-time weaving is the simplest approach. When you have the source code
  12. for an application, ajc will compile from source and produce woven class files as
  13. output. The invocation of the weaver is integral to the ajc compilation process. The
  14. aspects themselves may be in source or binary form.
  15. If the aspects are required for the affected classes to compile, then
  16. you must weave at compile-time. Aspects are required, e.g., when they
  17. add members to a class and other classes being compiled reference the
  18. added members.
  19. </para></listitem>
  20. <listitem> <para>Post-compile weaving (also sometimes called binary weaving) is used to weave
  21. existing class files and JAR files. As with compile-time weaving,
  22. the aspects used for weaving may be in source or binary form,
  23. and may themselves be woven by aspects.</para></listitem>
  24. <listitem> <para>Load-time weaving (LTW) is simply binary weaving defered until the point that
  25. a class loader loads a class file and defines the class to the JVM. To support this,
  26. one or more "weaving class loaders", either provided explicitly by the run-time
  27. environment or enabled through a "weaving agent" are required. </para></listitem>
  28. </itemizedlist>
  29. <para> You may also hear the term "run-time weaving". We define this as the weaving of
  30. classes that have already been defined to the JVM (without reloading those
  31. classes). AspectJ 5 does not provide explicit support for run-time weaving although
  32. simple coding patterns can support dynamically enabling and disabling advice in aspects. </para>
  33. <sect2 id="weaving-class-files-more-than-once" xreflabel="weaving-class-files-more-than-once">
  34. <title>Weaving class files more than once</title>
  35. <para> As of AspectJ 5 aspects (code style or annotation style) and woven classes are
  36. reweavable by default. If you are developing AspectJ applications that are to be used
  37. in a load-time weaving environment with an older version of the compiler you
  38. need to specify the <literal>-Xreweavable</literal> compiler option when building
  39. them. This causes AspectJ to save additional state in the class files that is used
  40. to support subsequent reweaving. </para>
  41. </sect2>
  42. </sect1>
  43. <sect1 id="ltw-rules">
  44. <title>Load-time Weaving Requirements</title>
  45. <para> All load-time weaving is done in the context of a class loader, and hence the set of
  46. aspects used for weaving and the types that can be woven are affected by the class
  47. loader delegation model. This ensures that LTW complies with the Java 2 security model.
  48. The following rules govern the interaction of load-time weaving with class loading: </para>
  49. <orderedlist>
  50. <listitem> <para>All aspects to be used for weaving must be defined to the weaver before any
  51. types to be woven are loaded. This avoids types being "missed" by aspects added
  52. later, with the result that invariants across types fail.</para></listitem>
  53. <listitem> <para>All aspects visible to the weaver are usable.
  54. A visible aspect is one defined by the
  55. weaving class loader or one of its parent class loaders.
  56. All concrete visible aspects are woven and all abstract visible aspects
  57. may be extended.
  58. </para></listitem>
  59. <listitem><para>A class loader may only weave classes that it defines. It may not weave
  60. classes loaded by a delegate or parent class loader.</para></listitem>
  61. </orderedlist>
  62. </sect1>
  63. <sect1 id="ltw-configuration">
  64. <title>Configuration</title>
  65. <para>New in AspectJ 5 are a number of mechanisms to make load-time weaving
  66. easy to use. The load-time weaving mechanism is chosen through JVM startup options.
  67. Configuration files determine the set of aspects to be used for weaving and which
  68. types will be woven. Additional diagnostic options allow the user to debug the configuration and
  69. weaving process. </para>
  70. <sect2 id="enabling-load-time-weaving" xreflabel="enabling-load-time-weaving">
  71. <title>Enabling Load-time Weaving</title>
  72. <para> AspectJ 5 supports several ways of enabling load-time weaving for
  73. an application: agents, a command-line launch script, and a set of interfaces for
  74. integration of AspectJ load-time weaving in custom environments. </para>
  75. <variablelist>
  76. <varlistentry>
  77. <term>Agents</term>
  78. <listitem>
  79. <para>AspectJ 5 ships with a load-time weaving agent that
  80. enables load-time weaving. This agent and its configuration
  81. is execution environment dependent. Configuration for the supported environments is discussed
  82. later in this chapter.</para>
  83. <para>
  84. Using Java 5 JVMTI you can specify the <literal>-javaagent:pathto/aspectjweaver.jar</literal> option
  85. to the JVM.</para><para>
  86. Since AspectJ 1.9.7, the obsolete Oracle/BEA JRockit agent is no longer part of AspectJ.
  87. JRockit JDK never supported Java versions higher than 1.6. Several JRockit JVM features are
  88. now part of HotSpot and tools like Mission Control available for OpenJDK and Oracle JDK.
  89. </para>
  90. </listitem>
  91. </varlistentry>
  92. <varlistentry>
  93. <term>Command-line wrapper scripts <literal>aj</literal></term>
  94. <listitem>
  95. <para>The <command>aj</command> command runs Java programs in Java 1.4 or
  96. later by setting up <literal>WeavingURLClassLoader</literal> as the
  97. system class loader.
  98. For more information, see <xref linkend="aj"/>.
  99. </para>
  100. <para>The <command>aj5</command> command runs Java programs in Java 5
  101. by using the <literal>-javaagent:pathto/aspectjweaver.jar</literal> option
  102. described above.
  103. For more information, see <xref linkend="aj"/>.
  104. </para>
  105. </listitem>
  106. </varlistentry>
  107. <varlistentry>
  108. <term>Custom class loader</term>
  109. <listitem>
  110. <para> A public interface is provided to allow a user written class loader
  111. to instantiate a weaver and weave classes after loading and before
  112. defining them in the JVM. This enables load-time weaving to be supported in
  113. environments where no weaving agent is available. It also allows the
  114. user to explicitly restrict by class loader which classes can be woven.
  115. For more information, see <xref linkend="aj"/> and the
  116. API documentation and source for
  117. <literal>WeavingURLClassLoader</literal> and
  118. <literal>WeavingAdapter</literal>.
  119. </para>
  120. </listitem>
  121. </varlistentry>
  122. </variablelist>
  123. </sect2>
  124. <sect2 id="configuring-load-time-weaving-with-aopxml-files" xreflabel="configuring-load-time-weaving-with-aopxml-files">
  125. <title>Configuring Load-time Weaving with aop.xml files</title>
  126. <para>The weaver is configured using one or more <literal>META-INF/aop.xml</literal>
  127. files located on the class loader search path. Each file may declare a list of
  128. aspects to be used for weaving, type patterns describing which types
  129. should woven, and a set of options to be passed to the weaver. In addition AspectJ 5
  130. supports the definition of concrete aspects in XML. Aspects defined in this way
  131. must extend an abstract aspect visible to the weaver. The abstract aspect
  132. may define abstract pointcuts (but not abstract
  133. methods). The following example shows a simple aop.xml file: </para>
  134. <programlisting><![CDATA[
  135. <aspectj>
  136. <aspects>
  137. <!-- declare two existing aspects to the weaver -->
  138. <aspect name="com.MyAspect"/>
  139. <aspect name="com.MyAspect.Inner"/>
  140. <!-- define a concrete aspect inline -->
  141. <concrete-aspect name="com.xyz.tracing.MyTracing"
  142. extends="tracing.AbstractTracing"
  143. precedence="com.xyz.first, *">
  144. <pointcut name="tracingScope" expression="within(org.maw.*)"/>
  145. </concrete-aspect>
  146. <!-- Of the set of aspects declared to the weaver
  147. use aspects matching the type pattern "com..*" for weaving. -->
  148. <include within="com..*"/>
  149. <!-- Of the set of aspects declared to the weaver
  150. do not use any aspects with the @CoolAspect annotation for weaving -->
  151. <exclude within="@CoolAspect *"/>
  152. </aspects>
  153. <weaver options="-verbose">
  154. <!-- Weave types that are within the javax.* or org.aspectj.*
  155. packages. Also weave all types in the foo package that do
  156. not have the @NoWeave annotation. -->
  157. <include within="javax.*"/>
  158. <include within="org.aspectj.*"/>
  159. <include within="(!@NoWeave foo.*) AND foo.*"/>
  160. <!-- Do not weave types within the "bar" pakage -->
  161. <exclude within="bar.*"/>
  162. <!-- Dump all types within the "com.foo.bar" package
  163. to the "./_ajdump" folder on disk (for diagnostic purposes) -->
  164. <dump within="com.foo.bar.*"/>
  165. <!-- Dump all types within the "com.foo.bar" package and sub-packages,
  166. both before are after they are woven,
  167. which can be used for byte-code generated at runtime
  168. <dump within="com.foo.bar..*" beforeandafter="true"/>
  169. </weaver>
  170. </aspectj>
  171. ]]></programlisting>
  172. <para>
  173. The DTD defining the format of this file is available here:
  174. http://www.eclipse.org/aspectj/dtd/aspectj.dtd.
  175. </para>
  176. <para>
  177. An aop.xml file contains two key sections: <literal>aspects</literal> defines one
  178. or more aspects to the weaver and controls which aspects are to be
  179. used in the weaving process; <literal>weaver</literal> defines weaver options and which
  180. types should be woven.
  181. </para>
  182. <para>
  183. The simplest way to define an aspect to the weaver is to
  184. specify the fully-qualified name of the aspect type in an aspect element.
  185. You can also
  186. declare (and define to the weaver) aspects inline in the aop.xml file.
  187. This is done using the <literal>concrete-aspect</literal> element. A concrete-aspect
  188. declaration must provide a pointcut definition for every abstract
  189. pointcut in the abstract aspect it extends. This mechanism is a
  190. useful way of externalizing configuration for infrastructure and
  191. auxiliary aspects where the pointcut definitions themselves can be
  192. considered part of the configuration of the service.
  193. Refer to the next section for more details.
  194. </para>
  195. <para>
  196. The <literal>aspects</literal> element may optionally contain one or more <literal>include</literal> and
  197. <literal>exclude</literal> elements (by default, all defined aspects are used for weaving).
  198. Specifying include or exclude elements restricts the set of defined
  199. aspects to be used for weaving to those that are matched by an include
  200. pattern, but not by an exclude pattern. The <literal>within</literal> attribute accepts
  201. a type pattern of the same form as a within pcd, except that &amp;&amp;
  202. and || are replaced by 'AND' and 'OR'.
  203. </para>
  204. <para>
  205. Note that <literal>include</literal> and <literal>exclude</literal> elements affect all aspects
  206. declared to the weaver including those in other aop.xml files. To help avoid unexpected
  207. behaviour a lint warning is issued
  208. if an aspect is not declared as a result of of applying these filters.
  209. Also note <literal>aspect</literal> and <literal>concrete-aspect</literal> elements
  210. must be used to declare aspects to the weaver i.e. <literal>include</literal> and <literal>exclude</literal>
  211. elements cannot be used find aspects on the class loader search path.
  212. </para>
  213. <para>
  214. The <literal>weaver</literal> element is used to pass options to the weaver and to specify
  215. the set of types that should be woven. If no include elements are specified
  216. then all types visible to the weaver will be woven. In addition the <literal>dump</literal>
  217. element can be used capture on disk byte-code of woven classes for diagnostic purposes both before,
  218. in the case of those generated at runtime, and after the weaving process.
  219. </para>
  220. <para> When several configuration files are visible from a given weaving class loader
  221. their contents are conceptually merged.
  222. The files are merged in the order they are
  223. found on the search path (with a regular <literal>getResourceAsStream</literal> lookup)
  224. according to the following rules: </para>
  225. <itemizedlist>
  226. <!-- FIXME AV - looks like we can refine conf in a child CL - not good -->
  227. <listitem> <para>The set of available aspects is the set of all
  228. declared and defined aspects (<literal>aspect</literal> and
  229. <literal>concrete-aspect</literal> elements of the <literal>aspects</literal>
  230. section).</para></listitem>
  231. <listitem> <para>The set of aspects used for weaving is the subset of the available
  232. aspects that are matched by at least one include statement and are not matched
  233. by any exclude statements. If there are no include statements then all non-excluded
  234. aspects are included.</para></listitem>
  235. <listitem> <para> The set of types to be woven are those types matched by at
  236. least one weaver <literal>include</literal> element and not matched by any
  237. weaver <literal>exclude</literal> element. If there are no weaver include
  238. statements then all non-excluded types are included.</para></listitem>
  239. <listitem> <para> The weaver options are derived by taking the union of the
  240. options specified in each of the weaver options attribute specifications. Where an
  241. option takes a value e.g. <literal>-warn:none</literal> the most recently defined value
  242. will be used.</para></listitem>
  243. </itemizedlist>
  244. <para>It is not an error for the same aspect to be defined to the weaver in
  245. more than one visible <literal>META-INF/aop.xml</literal> file.
  246. However, if the same concrete aspect
  247. is defined in more than one aop.xml file then an error will be issued.
  248. A concrete aspect
  249. defined in this way will be used to weave types loaded by the
  250. class loader that loaded the aop.xml file in which it was defined.
  251. </para>
  252. <para> A <literal>META-INF/aop.xml</literal> can be generated by
  253. using either the <literal>-outxml</literal> or <literal>-outxmlfile</literal> options of the AspectJ compiler.
  254. It will simply contain a (possibly empty) set of aspect elements; one for
  255. each abstract or concrete aspect defined.
  256. When used in conjuction with the <literal>-outjar</literal> option
  257. a JAR is produced that can be used
  258. with the <command>aj5</command> command or a load-time weaving environment.</para>
  259. </sect2>
  260. <sect2 id="concrete-aspect" xreflabel="concrete-aspect">
  261. <title>Using Concrete Aspects</title>
  262. <para>
  263. It is possible to make an abstract aspect concrete by means of the <literal>META-INF/aop.xml</literal>
  264. file. This is useful way to implement abstract pointcuts at deployment time, and also gives control
  265. over precedence through the <literal>precedence</literal> attribute of the
  266. <literal>concrete-aspect</literal> XML element.
  267. Consider the following:
  268. </para>
  269. <programlisting><![CDATA[
  270. package mypack;
  271. @Aspect
  272. public abstract class AbstractAspect {
  273. // abstract pointcut: no expression is defined
  274. @Pointcut
  275. abstract void scope();
  276. @Before("scope() && execution(* *..doSome(..))")
  277. public void before(JoinPoint jp) {
  278. ....
  279. }
  280. }
  281. ]]></programlisting>
  282. <para>
  283. This aspect is equivalent to the following in code style:
  284. </para>
  285. <programlisting><![CDATA[
  286. package mypack;
  287. public abstract aspect AbstractAspect {
  288. // abstract pointcut: no expression is defined
  289. abstract pointcut scope();
  290. before() : scope() && execution(* *..doSome(..)) {
  291. ....
  292. }
  293. }
  294. ]]></programlisting>
  295. <para>
  296. This aspect (in either style) can be made concrete using <literal>META-INF/aop.xml</literal>.
  297. It defines the abstract pointcut <literal>scope()</literal>. When using this mechanism the
  298. following rules apply:
  299. <itemizedlist>
  300. <listitem><para>The parent aspect must be abstract. It can be an @AspectJ or a
  301. regular code style aspect.</para></listitem>
  302. <listitem><para>Only a simple abstract pointcut can be implemented i.e. a pointcut that doesn't expose
  303. state (through <literal>args(), this(), target(), if()</literal>). In @AspectJ syntax
  304. as illustrated in this sample, this means the method that hosts the pointcut must be abstract,
  305. have no arguments, and return void.</para></listitem>
  306. <listitem><para>The concrete aspect must implement all inherited abstract pointcuts.</para></listitem>
  307. <listitem><para>The concrete aspect may not implement methods so the abstract aspect it
  308. extends may not contain any abstract methods.</para></listitem>
  309. </itemizedlist>
  310. </para>
  311. <para>
  312. <emphasis>A limitation of the implementation of this feature in AspectJ 1.5.0 is that aspects defined using
  313. aop.xml are not exposed to the weaver. This means that they are not affected by advice and ITDs defined in
  314. other aspects. Support for this capability will be considered in a future release.</emphasis>
  315. </para>
  316. <para>
  317. If more complex aspect inheritance is required use regular aspect
  318. inheritance instead of XML.
  319. The following XML definition shows a valid concrete sub-aspect for the abstract aspects above:
  320. </para>
  321. <programlisting><![CDATA[
  322. <aspectj>
  323. <aspects>
  324. <concrete-aspect name="mypack.__My__AbstractAspect" extends="mypack.AbstractAspect">
  325. <pointcut name="scope" expression="within(yourpackage..*)"/>
  326. </concrete-aspect>
  327. <aspects>
  328. </aspectj>
  329. ]]></programlisting>
  330. <para>
  331. It is important to remember that the <literal>name</literal> attribute in the
  332. <literal>concrete-aspect</literal> directive defines the fully qualified name that will be given to the
  333. concrete aspect. It must a valid class name because the aspect will be generated on the fly by the weaver.
  334. You must
  335. also ensure that there are no name collisions. Note that the concrete aspect will be
  336. defined at the classloader level for which the aop.xml is visible. This implies that if you need
  337. to use the <literal>aspectof</literal> methods to access the aspect instance(s) (depending on the perclause
  338. of the aspect it extends) you have to use the helper API <literal>org.aspectj.lang.Aspects.aspectOf(..)</literal>
  339. as in:
  340. </para>
  341. <programlisting><![CDATA[
  342. // exception handling omitted
  343. Class myConcreteAspectClass = Class.forName("mypack.__My__AbstractAspect");
  344. // here we are using a singleton aspect
  345. AbstractAspect concreteInstance = Aspects.aspectOf(myConcreteAspectClass);
  346. ]]></programlisting>
  347. </sect2>
  348. <sect2 id="concrete-aspect-precedence" xreflabel="concrete-aspect-precedence">
  349. <title>Using Concrete Aspects to define precedence</title>
  350. <para>
  351. As described in the previous section, the <literal>concrete-aspect</literal> element in
  352. <literal>META-INF/aop.xml</literal> gives the option to declare the precedence, just as
  353. <literal>@DeclarePrecedence</literal> or <literal>declare precedence</literal> do in
  354. aspect source code.
  355. </para>
  356. <para>
  357. Sometimes it is necessary to declare precedence without extending any abstract aspect.
  358. It is therefore possible to use the <literal>concrete-aspect</literal>
  359. element without the <literal>extends</literal> attribute and without any
  360. <literal>pointcut</literal> nested elements, just a <literal>precedence</literal>
  361. attribute.
  362. Consider the following:
  363. </para>
  364. <programlisting><![CDATA[
  365. <aspectj>
  366. <aspects>
  367. <concrete-aspect name="mypack.__MyDeclarePrecedence"
  368. precedence="*..*Security*, Logging+, *"/>
  369. </aspects>
  370. </aspectj>
  371. ]]></programlisting>
  372. <para>
  373. This deployment time definitions is only declaring a precedence rule. You have to remember
  374. that the <literal>name</literal> attribute must be a valid fully qualified class name
  375. that will be then reserved for this concrete-aspect and must not conflict with other classes
  376. you deploy.
  377. </para>
  378. </sect2>
  379. <!-- TODO someone implement that -->
  380. <!--
  381. <sect2 id="configuring-load-time-weaving-with-properties-files" xreflabel="configuring-load-time-weaving-with-properties-files">
  382. <title>Configuring Load-time Weaving with Properties Files</title>
  383. <para> For memory constrained environments or those without support for XML a simple
  384. Java Properties file can be used to configure LTW. Just like XML files,
  385. <literal>META-INF/aop.properties</literal> files are loaded from the class loader
  386. search path. Everything that can be configured through XML can be configured using a
  387. Properties file, with the exception of declarative concrete aspects. For example: </para>
  388. <programlisting><![CDATA[
  389. aspects.names=com.MyAspect,com.MyAspect.Inner
  390. aspects.include=com..*
  391. aspects.exclude=@CoolAspect
  392. weaver.options=-verbose
  393. weaver.include=javax.* OR org.aspectj.*
  394. ]]></programlisting>
  395. </sect2>
  396. -->
  397. <sect2 id="weaver-options" xreflabel="weaver-options">
  398. <title>Weaver Options</title>
  399. <para> The table below lists the AspectJ options supported by LTW. All other options
  400. will be ignored and a warning issued. </para>
  401. <informaltable>
  402. <tgroup cols="2">
  403. <thead>
  404. <row>
  405. <entry>Option</entry>
  406. <entry>Purpose</entry>
  407. </row>
  408. </thead>
  409. <tbody>
  410. <row>
  411. <entry>
  412. <literal>-verbose</literal>
  413. </entry>
  414. <entry>Issue informational messages about the weaving process. Messages issued while the weaver is being
  415. bootstrapped are accumulated until all options are parsed. If the messages are required to be output
  416. immediately you can use the option <literal>-Daj.weaving.verbose=true</literal> on the JVM startup command line.
  417. </entry>
  418. </row>
  419. <row>
  420. <entry>
  421. <literal>-debug</literal>
  422. </entry>
  423. <entry>
  424. Issue a messages for each class passed to the weaver
  425. indicating whether it was woven, excluded or ignored.
  426. Also issue messages for classes
  427. defined during the weaving process such as around advice
  428. closures and concrete aspects defined in
  429. <literal>META-INF/aop.xml</literal>.
  430. </entry>
  431. </row>
  432. <row>
  433. <entry>
  434. <literal>-showWeaveInfo</literal>
  435. </entry>
  436. <entry>
  437. Issue informational messages whenever the weaver touches a class file.
  438. This option may also be enabled using the System property
  439. <literal>-Dorg.aspectj.weaver.showWeaveInfo=true</literal>.
  440. </entry>
  441. </row>
  442. <!-- TODO option parsed but not used -->
  443. <!--
  444. <row>
  445. <entry>
  446. <literal>-1.5</literal>
  447. </entry>
  448. <entry>Run the weaver in 1.5 mode (supports autoboxing in
  449. join point matching)</entry>
  450. </row>
  451. -->
  452. <row>
  453. <entry>
  454. <literal>-Xlintfile:pathToAResource</literal>
  455. </entry>
  456. <entry>Configure lint messages as specified in the given resource (visible from this aop.xml file' classloader)</entry>
  457. </row>
  458. <row>
  459. <entry>
  460. <literal>-Xlint:default, -Xlint:ignore, ...</literal>
  461. </entry>
  462. <entry>Configure lint messages, refer to documentation for meaningfull values</entry>
  463. </row>
  464. <row>
  465. <entry>
  466. <literal>-nowarn, -warn:none</literal>
  467. </entry>
  468. <entry>Suppress warning messages</entry>
  469. </row>
  470. <!-- TODO option parsed but not used -->
  471. <!--
  472. <row>
  473. <entry>
  474. <literal>-proceedOnError</literal>
  475. </entry>
  476. <entry>Continue weaving even if errors occur (for example,
  477. "... already woven" errors)</entry>
  478. </row>
  479. -->
  480. <row>
  481. <entry>
  482. <literal>-Xreweavable</literal>
  483. </entry>
  484. <entry>Produce class files that can subsequently be rewoven</entry>
  485. </row>
  486. <row>
  487. <entry>
  488. <literal>-XnoInline</literal>
  489. </entry>
  490. <entry>Don't inline around advice.</entry>
  491. </row>
  492. <row>
  493. <entry>
  494. <literal>-XmessageHandlerClass:...</literal>
  495. </entry>
  496. <entry>Provide alternative output destination to stdout/stderr for all weaver messages.
  497. The given value must be the full qualified class name of a class that implements the
  498. <literal>org.aspectj.bridge.IMessageHandler</literal> interface
  499. and is visible to the classloader with which the weaver being configured is associated.
  500. Exercise caution when packaging a custom message handler with an application that is to
  501. be woven. The handler (as well as classes on which it depends) cannot itself be woven
  502. by the aspects that are declared to the same weaver.
  503. </entry>
  504. </row>
  505. </tbody>
  506. </tgroup>
  507. </informaltable>
  508. </sect2>
  509. </sect1>
  510. <sect1 id="ltw-specialcases">
  511. <title>Special cases</title>
  512. <para>
  513. The following classes are not exposed to the LTW infrastructure regardless of
  514. the <literal>aop.xml</literal> file(s) used:
  515. <itemizedlist>
  516. <listitem> <para>All <literal>org.aspectj.*</literal> classes (and subpackages) - as those are needed by the infrastructure itself</para></listitem>
  517. <listitem> <para>All <literal>java.*</literal> and <literal>javax.*</literal> classes (and subpackages)</para></listitem>
  518. <listitem> <para>All <literal>sun.reflect.*</literal> classes - as those are JDK specific classes used when reflective calls occurs</para></listitem>
  519. </itemizedlist>
  520. </para>
  521. <para>
  522. Despite these restrictions, it is perfectly possible to match call join points for calls to these types providing the calling
  523. class is exposed to the weaver. Subtypes of these excluded types that are exposed to the weaver may of course be woven.
  524. </para>
  525. <para>
  526. Note that dynamic proxy representations are exposed to the LTW infrastructure and are not considered
  527. a special case.
  528. </para>
  529. <para>
  530. Some lint options behave differently when used under load-time weaving. The <literal>adviceDidNotMatch</literal>
  531. won't be handled as a warn (as during compile time) but as an info message.
  532. </para>
  533. </sect1>
  534. <sect1 id="ltw-packaging">
  535. <title>Runtime Requirements for Load-time Weaving</title>
  536. <para> To use LTW the <literal>aspectjweaver.jar</literal> library must be added to the
  537. classpath. This contains the AspectJ 5 runtime, weaver, weaving class loader and
  538. weaving agents. It also contains the DTD for parsing XML weaving configuration files. </para>
  539. </sect1>
  540. <sect1 id="ltw-agents">
  541. <title>Supported Agents</title>
  542. <sect2 id="jvmti" xreflabel="jvmti">
  543. <title>JVMTI</title>
  544. <para> When using Java 5 the JVMTI agent can be used by starting the JVM with the
  545. following option (adapt according to the path to aspectjweaver.jar): </para>
  546. <programlisting><![CDATA[
  547. -javaagent:pathto/aspectjweaver.jar
  548. ]]></programlisting>
  549. </sect2>
  550. <sect2 id="jrockit" xreflabel="jrockit">
  551. <title>JRockit with Java 1.3/1.4 (use JVMTI on Java 5)</title>
  552. <para>
  553. Since AspectJ 1.9.7, the obsolete Oracle/BEA JRockit agent is no longer part of AspectJ.
  554. JRockit JDK never supported Java versions higher than 1.6. Several JRockit JVM features are
  555. now part of HotSpot and tools like Mission Control available for OpenJDK and Oracle JDK.
  556. </para>
  557. </sect2>
  558. </sect1>
  559. </chapter>