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

Doug Simon dnsimon at openjdk.org
Mon Dec 23 18:09:36 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. It also removes a few other public methods and fields that are no longer used by Graal. Given that JVMCI is still experimental and only has qualified exports to Graal, I don't think this needs a CSR.

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java line 52:

> 50:      * statement on this field - the guard cannot be behind a method call.
> 51:      */
> 52:     public static final boolean IS_BUILDING_NATIVE_IMAGE = Boolean.parseBoolean(VM.getSavedProperty("jdk.vm.ci.services.aot"));

This field is no longer used in JVMCI and I will remove its usages in Graal.

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java line 184:

> 182:      *             {@link RuntimePermission}("jvmci")</tt>
> 183:      */
> 184:     public static <S> Iterable<S> load(Class<S> service) {

There are no usages of this method in JVMCI or Graal.

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java line 202:

> 200:      *             {@link RuntimePermission}("jvmci")</tt>
> 201:      */
> 202:     public static <S> S loadSingle(Class<S> service, boolean required) {

There are no usages of this method in JVMCI or Graal.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22869#discussion_r1896005238
PR Review Comment: https://git.openjdk.org/jdk/pull/22869#discussion_r1896005660
PR Review Comment: https://git.openjdk.org/jdk/pull/22869#discussion_r1896005730


More information about the hotspot-compiler-dev mailing list