changeset 2014:95d4e43f484f

Use a bundled copy of asm for the profiler. Backport of: http://icedtea.classpath.org/hg/thermostat/rev/c0c30665da2c PR3154 Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-August/020733.html
author Jie Kang <jkang@redhat.com>
date Mon, 29 Aug 2016 14:51:15 -0400
parents 189fa2a6b1f5
children 2722ffe3454e
files .hgignore distribution/packaging/shared/man/thermostat.1 main/src/main/java/com/redhat/thermostat/main/impl/FrameworkOptions.java vm-profiler/agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/internal/VmProfiler.java vm-profiler/agent/src/main/resources/com/redhat/thermostat/vm/profiler/agent/internal/settings.properties vm-profiler/agent/src/test/java/com/redhat/thermostat/vm/profiler/agent/internal/VmProfilerTest.java vm-profiler/distribution/pom.xml vm-profiler/jvm-agent/pom.xml vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerAgent.java vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerInstrumentor.java
diffstat 10 files changed, 47 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Aug 29 14:50:28 2016 -0400
+++ b/.hgignore	Mon Aug 29 14:51:15 2016 -0400
@@ -2,6 +2,9 @@
 # standalone integration-test's shade plugin seems to generate this
 # pom. As it's derivable, hgignore it :)
 integration-tests/standalone/dependency-reduced-pom.xml
+# vm-profiler's shade plugin seems to generate this
+# pom. As it's derivable, hgignore it :)
+vm-profiler/jvm-agent/dependency-reduced-pom.xml
 
 # Keyring autogenerated files
 keyring/Makefile.in
--- a/distribution/packaging/shared/man/thermostat.1	Mon Aug 29 14:50:28 2016 -0400
+++ b/distribution/packaging/shared/man/thermostat.1	Mon Aug 29 14:51:15 2016 -0400
@@ -55,7 +55,7 @@
                         available.
   --boot-delegation     Boot delegation string passed on to the OSGi framework.
                         Defaults to
-                        "com.redhat.thermostat.vm.profiler.agent.jvm,org.objectweb.asm,org.objectweb.asm.commons"
+                        "com.redhat.thermostat.vm.profiler.agent.jvm,com.redhat.thermostat.vm.profiler.agent.asm,com.redhat.thermostat.vm.profiler.agent.asm.commons"
 
 .SS "Command Options and Command Arguments"
 Please see 
--- a/main/src/main/java/com/redhat/thermostat/main/impl/FrameworkOptions.java	Mon Aug 29 14:50:28 2016 -0400
+++ b/main/src/main/java/com/redhat/thermostat/main/impl/FrameworkOptions.java	Mon Aug 29 14:51:15 2016 -0400
@@ -122,8 +122,8 @@
         // correctly by default
         globalOptions.put(Option.BOOT_DELEGATION,
                 "com.redhat.thermostat.vm.profiler.agent.jvm," +
-                "org.objectweb.asm," +
-                "org.objectweb.asm.commons");
+                "com.redhat.thermostat.vm.profiler.agent.asm," +
+                "com.redhat.thermostat.vm.profiler.agent.asm.commons");
     }
 
 
--- a/vm-profiler/agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/internal/VmProfiler.java	Mon Aug 29 14:50:28 2016 -0400
+++ b/vm-profiler/agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/internal/VmProfiler.java	Mon Aug 29 14:51:15 2016 -0400
@@ -87,7 +87,6 @@
     private final RemoteProfilerCommunicator remote;
 
     private final String agentJarPath;
-    private final String asmJarPath;
 
     public VmProfiler(String agentId, Properties configuration, ProfileDAO dao, MXBeanConnectionPool pool) {
         this(agentId, configuration, dao, new SystemClock(), new ProfileUploaderCreator(), new RemoteProfilerCommunicator(pool));
@@ -104,7 +103,6 @@
 
         // requireNonNull protects against bad config with missing values
         agentJarPath = Objects.requireNonNull(configuration.getProperty("AGENT_JAR"));
-        asmJarPath = Objects.requireNonNull(configuration.getProperty("ASM_JAR"));
     }
 
     public synchronized void vmStarted(String vmId, int pid) {
@@ -142,7 +140,7 @@
         }
 
         if (!vmsWithAgentLoaded.contains((Integer)pid)) {
-            String jarsToLoad = asmJarPath + ":" + agentJarPath;
+            String jarsToLoad = agentJarPath;
             logger.info("Asking " + pid + " to load agent '" + agentJarPath + "' with arguments '" + jarsToLoad + "'");
 
             remote.loadAgentIntoPid(pid, agentJarPath, jarsToLoad);
--- a/vm-profiler/agent/src/main/resources/com/redhat/thermostat/vm/profiler/agent/internal/settings.properties	Mon Aug 29 14:50:28 2016 -0400
+++ b/vm-profiler/agent/src/main/resources/com/redhat/thermostat/vm/profiler/agent/internal/settings.properties	Mon Aug 29 14:51:15 2016 -0400
@@ -1,3 +1,2 @@
 # These values are prefixed with thermostat home at run-time
 AGENT_JAR = plugins/vm-profiler/thermostat-vm-profiler-jvm-agent-${project.version}.jar
-ASM_JAR = plugins/vm-profiler/asm-all-${asm.version}.jar
--- a/vm-profiler/agent/src/test/java/com/redhat/thermostat/vm/profiler/agent/internal/VmProfilerTest.java	Mon Aug 29 14:50:28 2016 -0400
+++ b/vm-profiler/agent/src/test/java/com/redhat/thermostat/vm/profiler/agent/internal/VmProfilerTest.java	Mon Aug 29 14:51:15 2016 -0400
@@ -66,7 +66,7 @@
 
     private static final String AGENT_JAR = "foo";
     private static final String ASM_JAR = "bar";
-    private static final String AGENT_OPTIONS = ASM_JAR + ":" + AGENT_JAR;
+    private static final String AGENT_OPTIONS = AGENT_JAR;
     private static final long TIMESTAMP = 1_000_000_000;
 
     private VmProfiler profiler;
--- a/vm-profiler/distribution/pom.xml	Mon Aug 29 14:50:28 2016 -0400
+++ b/vm-profiler/distribution/pom.xml	Mon Aug 29 14:51:15 2016 -0400
@@ -117,11 +117,6 @@
       <artifactId>thermostat-vm-profiler-jvm-agent</artifactId>
       <version>${project.version}</version>
     </dependency>
-    <dependency>
-      <groupId>org.ow2.asm</groupId>
-      <artifactId>asm-all</artifactId>
-      <version>${asm.version}</version>
-    </dependency>
   </dependencies>
 
 </project>
--- a/vm-profiler/jvm-agent/pom.xml	Mon Aug 29 14:50:28 2016 -0400
+++ b/vm-profiler/jvm-agent/pom.xml	Mon Aug 29 14:51:15 2016 -0400
@@ -74,6 +74,31 @@
           <target>1.6</target>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <configuration>
+          <artifactSet>
+            <includes>
+              <include>*:asm-all</include>
+            </includes>
+          </artifactSet>
+          <relocations>
+            <relocation>
+              <pattern>org.objectweb.asm</pattern>
+              <shadedPattern>com.redhat.thermostat.vm.profiler.agent.asm</shadedPattern>
+            </relocation>
+          </relocations>
+        </configuration>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 
@@ -89,15 +114,15 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.ow2.asm</groupId>
-      <artifactId>asm-all</artifactId>
-      <version>${asm.version}</version>
-    </dependency>
-    <dependency>
       <groupId>com.redhat.thermostat</groupId>
       <artifactId>thermostat-annotations</artifactId>
       <version>${project.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm-all</artifactId>
+      <version>${asm.version}</version>
+    </dependency>
   </dependencies>
 </project>
--- a/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerAgent.java	Mon Aug 29 14:50:28 2016 -0400
+++ b/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerAgent.java	Mon Aug 29 14:51:15 2016 -0400
@@ -75,6 +75,7 @@
     }
 
     private static void addJarsToClassPath(String jars, Instrumentation instrumentation) throws AssertionError {
+        Debug.println("Boot-Classpath: " + System.getProperty("sun.boot.class.path"));
         Debug.println("Classpath: " + System.getProperty("java.class.path"));
         boolean addToBoot = true;
         String[] jarPaths = jars.split(":");
--- a/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerInstrumentor.java	Mon Aug 29 14:50:28 2016 -0400
+++ b/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerInstrumentor.java	Mon Aug 29 14:51:15 2016 -0400
@@ -57,9 +57,8 @@
 
         // this class
         ignorePackageRegexps.add(Pattern.compile("com\\.redhat\\.thermostat\\.vm\\.profiler\\.agent\\.jvm\\..*"));
-
-        // our dependencies
-        ignorePackageRegexps.add(Pattern.compile("org\\.objectweb\\.asm\\..*"));
+        // our dependencies: shaded asm
+        ignorePackageRegexps.add(Pattern.compile("com\\.redhat\\.thermostat\\.vm\\.profiler\\.agent\\.asm\\..*"));
     }
 
     @Override
@@ -68,6 +67,12 @@
             ProtectionDomain protectionDomain, byte[] classfileBuffer)
             throws IllegalClassFormatException {
 
+        if (!loader.equals(classBeingRedefined.getClassLoader())) {
+            String message = "ERROR: classloader " + loader + " didn't load " + className;
+            Debug.println(message);
+            throw new AssertionError(message);
+        }
+
         className = className.replace('/', '.');
         if (!shouldInstrument(className)) {
             return null;