]> source.dussan.org Git - aspectj.git/commitdiff
JRockit agent for LTW with 1.3/1.4 + update in doc
authoravasseur <avasseur>
Mon, 4 Jul 2005 14:42:10 +0000 (14:42 +0000)
committeravasseur <avasseur>
Mon, 4 Jul 2005 14:42:10 +0000 (14:42 +0000)
docs/adk15ProgGuideDB/ltw.xml
lib/ext/jrockit/LICENSE.TXT [new file with mode: 0644]
lib/ext/jrockit/managementapi-jrockit81.jar [new file with mode: 0644]
loadtime/.classpath
loadtime/src/org/aspectj/weaver/loadtime/JRockitAgent.java [new file with mode: 0644]

index 8b6f027bb312d77df90e0385866a2154584238f3..e822a5d20561d196bbd5da4037216905d4fff213 100644 (file)
@@ -74,7 +74,7 @@
         
         <sect2>
             <title>Enabling Load-time Weaving</title>
-            <para> AspectJ 5 supports three different ways of enabling load-time weaving for
+            <para> AspectJ 5 supports several different ways of enabling load-time weaving for
             an application: agents, a command-line launch script, and a set of interfaces for
             integration of AspectJ load-time weaving in custom environments. </para>
             <variablelist>
                     <listitem>
                         <para>AspectJ 5 ships with a number of load-time weaving agents that
                             enable load-time weaving. These agents and their configuration
-                            are execution environment dependent.
-                            Using Java 5 for example, you can specify the "-javaagent" option
-                            to the JVM. Configuration for the supported environments is discussed
-                            later in this chapter. AspectJ 5
-                            has several agents including those that use JVMTI, and the 
-                            JRockit MAPI. </para>
-                    </listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>Command line</term>
-                    <listitem>
-                        <!-- FIXME AV - wondering what is the status of this one as per aop.xml etc.. -->
-                        <para> AspectJ includes a script "aj" that allows programs executed at
-                            the command line to take advantage of load-time weaving. 
-                            The script is customized when AspectJ is installed depending on the chosen 
-                            JDK. For example, for JDK 1.4 the script uses the
-                            <literal>-Djava.system.class.loader</literal> system property to replace
-                            the system class loader with a weaving class loader allowing classes 
-                            loaded from the CLASSPATH to be woven. 
-                            For JDK 1.5 the JVMTI weaving agent is used allowing classes loaded by all
-                            class loaders to be woven. Versions of the JDK prior to 1.3 are not
-                            supported by the "aj" mechanism. </para>
+                            are execution environment dependent. Configuration for the supported environments is discussed
+                            later in this chapter.<br/>
+                            Using Java 5 JVMTI you can specify the <code>-javaagent:pathto/aspectjweaver.jar</code> option
+                            to the JVM.<br/>
+                            Using BEA JRockit and Java 1.3/1.4, the very same behavior can be obtained using BEA JRockit JMAPI features with
+                            the <code>-Xmanagement:class=org.aspectj.weaver.loadtime.JRockitAgent</code>
+                        </para>
                     </listitem>
                 </varlistentry>
+                <!-- FIXME: must be made consistent (aop.xml , CL hierarchy etc) -->
+<!--                <varlistentry>-->
+<!--                    <term>Command line</term>-->
+<!--                    <listitem>-->
+<!--                        <para> AspectJ includes a script "aj" that allows programs executed at-->
+<!--                            the command line to take advantage of load-time weaving. -->
+<!--                            The script is customized when AspectJ is installed depending on the chosen -->
+<!--                            JDK. For example, for JDK 1.4 the script uses the-->
+<!--                            <literal>-Djava.system.class.loader</literal> system property to replace-->
+<!--                            the system class loader with a weaving class loader allowing classes -->
+<!--                            loaded from the CLASSPATH to be woven. -->
+<!--                            For JDK 1.5 the JVMTI weaving agent is used allowing classes loaded by all-->
+<!--                            class loaders to be woven. Versions of the JDK prior to 1.3 are not-->
+<!--                            supported by the "aj" mechanism. </para>-->
+<!--                    </listitem>-->
+<!--                </varlistentry>-->
                 <varlistentry>
                     <term>Custom Integration</term>
                     <listitem>
                             to instantiate a weaver and weave classes after loading and before
                             defining them in the JVM. This enables load-time weaving to be supported in
                             environments where no weaving agent is available. It also allows the
-                            user to explicity restrict by class loader which classes can be woven. </para>
+                            user to explicity restrict by class loader which classes can be woven.</para>
                     </listitem>
                 </varlistentry>
             </variablelist>
         <title>Supported Agents</title>
         <sect2>
             <title>JVMTI</title>
-            <para> When using JDK 1.5 the JVMTI agent can be used by starting the JVM with the
+            <para> When using Java 5 the JVMTI agent can be used by starting the JVM with the
                 following option (adapt according to the path to aspectjweaver.jar): </para>
             <programlisting><![CDATA[
-                       -javaagent=aspectjweaver.jar          
+                       -javaagent=pathto/aspectjweaver.jar
                  ]]></programlisting>
         </sect2>
         <sect2>
-            <title>JRockit</title>
+            <title>JRockit with Java 1.3/1.4 (use JVMTI on Java 5)</title>
             <para> The JRockit agent is configured with the following JVM option: </para>
             <programlisting><![CDATA[
-                       -Xmanagement:class=org.aspectj.weaver.tools.JRockitWeavingAgent
+                       -Xmanagement:class=org.aspectj.weaver.loadtime.JRockitAgent
                  ]]></programlisting>
         </sect2>
     </sect1>
diff --git a/lib/ext/jrockit/LICENSE.TXT b/lib/ext/jrockit/LICENSE.TXT
new file mode 100644 (file)
index 0000000..6bbc97c
--- /dev/null
@@ -0,0 +1,8 @@
+The managementapi-jrockit81.jar jar file in this folder is an excerpt of the BEA JRockit Management API
+as per JRockit 8.1 (Java 1.4) (supports also for JRockit 7 ie Java 1.3).
+
+It contains only the class file needed at build time for AspectJ
+and must not be used by the end-user.
+
+http://www.jrockit.com
+http://www.bea.com
\ No newline at end of file
diff --git a/lib/ext/jrockit/managementapi-jrockit81.jar b/lib/ext/jrockit/managementapi-jrockit81.jar
new file mode 100644 (file)
index 0000000..f951295
Binary files /dev/null and b/lib/ext/jrockit/managementapi-jrockit81.jar differ
index fa9d3237171812a440e05ea99b70a7c129ac7e38..47982eb80a24d91a5e4a4c3e7a78e6a6be2d2dc5 100644 (file)
                <attributes>
                </attributes>
        </classpathentry>
+       <classpathentry kind="lib" path="/lib/ext/jrockit/managementapi-jrockit81.jar">
+               <attributes>
+               </attributes>
+       </classpathentry>
        <classpathentry sourcepath="/lib/junit/junit-src.jar" kind="lib" path="/lib/junit/junit.jar">
                <attributes>
                </attributes>
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/JRockitAgent.java b/loadtime/src/org/aspectj/weaver/loadtime/JRockitAgent.java
new file mode 100644 (file)
index 0000000..9b5191f
--- /dev/null
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors:
+ *   Alexandre Vasseur         initial implementation (derivative from AspectWerkz)
+ *******************************************************************************/
+package org.aspectj.weaver.loadtime;
+
+import com.bea.jvm.JVMFactory;
+import com.jrockit.management.rmp.RmpSocketListener;
+
+/**
+ * JRockit (tested with 7SP4 and 8.1) preprocessor Adapter based on JMAPI <p/>JRockit has a low
+ * level API for hooking ClassPreProcessor, allowing the use of online weaving at full speed.
+ * Moreover, JRockit does not allow java.lang.ClassLoader overriding thru -Xbootclasspath/p option.
+ * <p/>The ClassPreProcessor
+ * implementation and all third party jars CAN reside in the standard classpath. <p/>The command
+ * line will look like:
+ * <code>"%JAVA_COMMAND%" -Xmanagement:class=org.aspectj.weaver.loadtime.JRockitAgent -cp ...</code>
+ * Note: there can be some NoClassDefFoundError due to classpath limitation - as described in
+ * http://edocs.bea.com/wls/docs81/adminguide/winservice.html <p/>In order to use the BEA JRockit
+ * management server (for further connection of management console or runtime analyzer), the regular
+ * option -Xmanagement will not have any effect prior to JRockit 8.1 SP2. Instead, use <code>-Dmanagement</code>.
+ *
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class JRockitAgent implements com.bea.jvm.ClassPreProcessor {
+
+    /**
+     * Concrete preprocessor
+     */
+    private final static ClassPreProcessor s_preProcessor;
+
+    private static boolean START_RMP_SERVER = false;
+
+    static {
+        START_RMP_SERVER = System.getProperties().containsKey("management");
+        try {
+            s_preProcessor = new Aj();
+            s_preProcessor.initialize();
+        } catch (Exception e) {
+            throw new ExceptionInInitializerError("could not initialize JRockitAgent preprocessor due to: " + e.toString());
+        }
+    }
+
+    /**
+     * The JMAPI ClassPreProcessor must be self registrating
+     */
+    public JRockitAgent() {
+        if (START_RMP_SERVER) {
+            // the management server will be spawned in a new thread
+            RmpSocketListener management = new RmpSocketListener();
+        }
+        JVMFactory.getJVM().getClassLibrary().setClassPreProcessor(this);
+    }
+
+    /**
+     * Weave a class
+     *
+     * @param caller   classloader
+     * @param name     of the class to weave
+     * @param bytecode original
+     * @return bytecode weaved
+     */
+    public byte[] preProcess(ClassLoader caller, String name, byte[] bytecode) {
+        if (caller == null || caller.getParent() == null) {
+            return bytecode;
+        } else {
+            return s_preProcessor.preProcess(name, bytecode, caller);
+        }
+    }
+}
\ No newline at end of file