Skip to content

Commit

Permalink
Workaround for defining classes during LTW
Browse files Browse the repository at this point in the history
Overhaul ClassLoaderWeavingAdaptor to use statically initialised Unsafe
instances and method handles pointing to their 'defineClass' methods.
Those now work universally on JDKs 8-21. In older JDKs, the method used
to be in sun.misc.Unsafe, in more recent ones on jdk.internal.misc.Unsafe.
It is challenging to fetch instances, especially as reflection
protection and module boundaries have been increased in the JDK
progressively. But finally, a solution was adapted from Byte Buddy (BB).
Kudos to BB author Rafael Winterhalter. The previous solution to use
ClassLoader::defineClass and require '--add-opens' is no longer
necessary for the first time since it became necessary in AspectJ 1.9.7
with Java 16 support.

Add org.ow2.asm:asm-common as a dependency everywhere org.ow2.asm:asm
was used before. Maybe that is too many places, but no worse than before.

Add missing dependency to loadtime to aspectjweaver. This kept a build
like "mvn install -am -pl aspectjweaver" from picking up changed
loadtime classes.

Fixes #117.

Signed-off-by: Alexander Kriegisch <[email protected]>
  • Loading branch information
kriegaex committed Jan 28, 2024
1 parent 8b3a50e commit 413ffaa
Show file tree
Hide file tree
Showing 29 changed files with 395 additions and 223 deletions.
4 changes: 4 additions & 0 deletions ajde.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>testing-util</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions ajde/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>org.aspectj.ajdt.core</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions ajdoc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>testing-util</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions aspectjtools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>runtime</artifactId>
Expand Down
1 change: 1 addition & 0 deletions aspectjweaver/aspectjweaver-assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>org.ow2.asm:asm</include>
<include>org.ow2.asm:asm-commons</include>
</includes>
</dependencySet>
</dependencySets>
Expand Down
9 changes: 9 additions & 0 deletions aspectjweaver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,19 @@
<artifactId>weaver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>loadtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</dependency>
</dependencies>

</project>
4 changes: 4 additions & 0 deletions loadtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>testing-util</artifactId>
Expand Down
Loading

0 comments on commit 413ffaa

Please sign in to comment.