Re: [rvm-research] using a java agent

Erik Brangs <[email protected]> Sat, 2 Mar 2019 22:14:28 +0100
Newsgroups gmane.comp.java.jikes.rvm.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------1B5814D8A106BD3737FD22C1
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi,

On 28.02.19 14:36, Johannes Sinsel wrote:
> Hey there,
> 
> I have problems with the classloader using a java agent. On a single class, everything works fine, but on a jar, I get the following exception:
> 
> Failed to run the agent's premain: fullpath.Agent not found in SystemAppCL
> java.lang.ClassNotFoundException: fullpath.Agent not found in SystemAppCL
>     at java.net.URLClassLoader.findClass(URLClassLoader.java:531)
>     at java.lang.ClassLoader.loadClass(ClassLoader.java:341)
>     at java.lang.ClassLoader.loadClass(ClassLoader.java:293)
> 
> 
> after executing:
> 
> ./dist/prototype-opt_x86_64-linux/rvm -javaagent:agent.jar=frames2000 -jar dacapo-2006-10.jar lusearch
> 
> in the terminal (same exception with every other .jar file).
> 
> If anyone got an idea, it will be very helpful.

I think that's a bug.

Does the attached patch fix the problem for you?


Kind regards,

Erik Brangs

--------------1B5814D8A106BD3737FD22C1
Content-Type: text/x-patch;
 name="correctClasspathHandlingForJavaAgent.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="correctClasspathHandlingForJavaAgent.diff"

diff --git a/rvm/src/org/jikesrvm/classloader/RVMClassLoader.java b/rvm/src/org/jikesrvm/classloader/RVMClassLoader.java
index bafd4701f..f5c55c3ab 100644
--- a/rvm/src/org/jikesrvm/classloader/RVMClassLoader.java
+++ b/rvm/src/org/jikesrvm/classloader/RVMClassLoader.java
@@ -13,6 +13,7 @@
 package org.jikesrvm.classloader;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.InputStream;
 
 import org.jikesrvm.Properties;
@@ -138,13 +139,21 @@ public class RVMClassLoader {
    * @param classpath path specification in standard "classpath" format
    */
   public static void setApplicationRepositories(String classpath) {
-    System.setProperty("java.class.path", classpath);
-    stashApplicationRepositories(classpath);
+    String actualClasspath = buildRealClasspath(classpath);
+    System.setProperty("java.class.path", actualClasspath);
+    stashApplicationRepositories(actualClasspath);
     if (DBG_APP_CL) {
       VM.sysWriteln("RVMClassLoader.setApplicationRepositories: applicationRepositories = ", applicationRepositories);
     }
   }
 
+  private static String buildRealClasspath(String classpath) {
+    if (agentRepositories == null) {
+      return classpath;
+    }
+    return classpath + File.pathSeparator + agentRepositories;
+  }
+
   /**
    * Get list of places currently being searched for application
    * classes and resources.
@@ -154,6 +163,25 @@ public class RVMClassLoader {
     return applicationRepositories;
   }
 
+  /**
+   * The classpath entries that are added implicitly by Java Agents for
+   * the jars that contain the agents.
+   */
+  private static String agentRepositories;
+
+  /**
+   * Adds repositories for a Java Agent.
+   *
+   * @param agentClasspath the classpath entry to add
+   */
+  public static void addAgentRepositories(String agentClasspath) {
+    if (agentRepositories == null) {
+      agentRepositories = agentClasspath;
+    } else {
+      agentRepositories = agentRepositories + File.pathSeparator + agentClasspath;
+    }
+  }
+
   /** Are we getting the application CL?  Access is synchronized via the
    *  Class object.  Probably not necessary, but doesn't hurt, or shouldn't.
    *  Used for sanity checks. */
diff --git a/rvm/src/org/jikesrvm/runtime/CommandLineArgs.java b/rvm/src/org/jikesrvm/runtime/CommandLineArgs.java
index 600a9f76c..fd01f222f 100644
--- a/rvm/src/org/jikesrvm/runtime/CommandLineArgs.java
+++ b/rvm/src/org/jikesrvm/runtime/CommandLineArgs.java
@@ -769,8 +769,7 @@ public class CommandLineArgs {
           } else {
             jarPath = arg;
           }
-          String newClassPath = RVMClassLoader.getApplicationRepositories() + File.pathSeparator + jarPath;
-          RVMClassLoader.setApplicationRepositories(newClassPath);
+          RVMClassLoader.addAgentRepositories(jarPath);
           break;
       }
     }

--------------1B5814D8A106BD3737FD22C1
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--------------1B5814D8A106BD3737FD22C1
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Jikesrvm-researchers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jikesrvm-researchers

--------------1B5814D8A106BD3737FD22C1--