RFR: 8346781: [JVMCI] Limit ServiceLoader to class initializers

Doug Simon dnsimon at openjdk.org
Mon Dec 23 18:06:06 UTC 2024


On Mon, 23 Dec 2024 17:58:23 GMT, Doug Simon <dnsimon at openjdk.org> wrote:

> In the context of libgraal, the current use of ServiceLoader in JVMCI is problematic as libgraal does all class loading at image build time. There are static fields such as `JVMCIServiceLocator.cachedLocators` that need to be initialized [via reflection](https://github.com/oracle/graal/blob/30492c3f7847a13ae7f8dc50663a5a039e49a8e7/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/libgraal/BuildTime.java#L175-L180) when building libgraal.
> 
> This PR removes the need for such reflection by moving all use of ServiceLoader in JVMCI into `<clinit>` methods. These methods are executed when building libgraal.

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/Cleaner.java line 110:

> 108:      * Remove the cleaners whose referents have become weakly reachable.
> 109:      */
> 110:     public static void clean() {

Making this public avoids the need for a [method substitution](https://github.com/oracle/graal/blob/30492c3f7847a13ae7f8dc50663a5a039e49a8e7/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalSubstitutions.java#L112).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22869#discussion_r1896002138


More information about the hotspot-compiler-dev mailing list