-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36628a3
commit 1a400c0
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
We were trying `javaagent` instead of `jvmti` because we ended | ||
up using the same APIs in JVMTI | ||
1. getAllStackTraces | ||
2. getAnnotations | ||
|
||
However, upon trying to use `javaagent` we realized that we | ||
were not able to get the `Class<?>` instance in the running JVM. | ||
Thus, we can neither get its bytecode nor its annotations. | ||
|
||
Some advantages of using `jvmti` are: | ||
1. It uses `AsyncGetCallTrace` which is immune to [safepoint bias](https://seethawenner.medium.com/java-safepoint-and-async-profiling-cdce0818cd29) and does | ||
not stop the JVM for long periods of time. | ||
2. It gives us the `jclass` instance so we can call `getAnnotations` on it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.chains-project</groupId> | ||
<artifactId>classport</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>classport-introspection</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<configuration> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<manifestEntries> | ||
<Agent-Class>io.github.chains_project.classport.introspector.Agent</Agent-Class> | ||
<Can-Retransform-Classes>false</Can-Retransform-Classes> | ||
</manifestEntries> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>shade</id> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<phase>package</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
24 changes: 24 additions & 0 deletions
24
...rt-introspection/src/main/java/io/github/chains_project/classport/introspector/Agent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.chains_project.classport.introspector; | ||
|
||
import java.lang.instrument.Instrumentation; | ||
import java.util.Arrays; | ||
|
||
public class Agent { | ||
public static void agentmain(String agentArgs, Instrumentation inst) { | ||
Thread.getAllStackTraces().forEach((thread, stackTrace) -> { | ||
System.out.println("Thread: " + thread.getName()); | ||
for (StackTraceElement stackTraceElement : stackTrace) { | ||
String className = stackTraceElement.getClassName(); | ||
System.out.println("Target JVM " + stackTraceElement.getClassLoaderName()); | ||
System.out.println("this " + Agent.class.getClassLoader().getName()); | ||
try { | ||
Class<?> c = Class.forName(className); | ||
c.getAnnotations(); | ||
System.out.println(className + Arrays.toString(c.getAnnotations())); | ||
} catch (ClassNotFoundException e) { | ||
System.out.println("Class not found: " + className); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters