Skip to content

Commit e3d74d9

Browse files
[GR-62769] Disable libgraal-specific API if it isn't needed.
PullRequest: graal/20229
2 parents 22da969 + 4d1c860 commit e3d74d9

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.libgraal;
26+
27+
import java.util.function.BooleanSupplier;
28+
29+
import com.oracle.svm.core.SubstrateOptions;
30+
31+
public class LibGraalBuild implements BooleanSupplier {
32+
@Override
33+
public boolean getAsBoolean() {
34+
return !SubstrateOptions.LibGraalClassLoader.getValue().isBlank();
35+
}
36+
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/libgraal/LibGraalRuntimeSupportImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
*/
2525
package com.oracle.svm.core.libgraal;
2626

27-
import com.oracle.svm.core.Isolates;
27+
import org.graalvm.nativeimage.libgraal.impl.LibGraalRuntimeSupport;
2828

29+
import com.oracle.svm.core.Isolates;
2930
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
3031
import com.oracle.svm.core.heap.Heap;
3132
import com.oracle.svm.core.util.VMError;
3233

33-
import org.graalvm.nativeimage.libgraal.impl.LibGraalRuntimeSupport;
34-
35-
@AutomaticallyRegisteredImageSingleton({LibGraalRuntimeSupport.class})
34+
@AutomaticallyRegisteredImageSingleton(value = LibGraalRuntimeSupport.class, onlyWith = LibGraalBuild.class)
3635
public final class LibGraalRuntimeSupportImpl implements LibGraalRuntimeSupport {
3736

3837
@Override

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/GraalCompilerFeature.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@
2828
import java.util.List;
2929
import java.util.function.BooleanSupplier;
3030

31-
import com.oracle.svm.util.ReflectionUtil;
32-
import jdk.graal.compiler.serviceprovider.GlobalAtomicLong;
33-
import org.graalvm.nativeimage.libgraal.hosted.GlobalData;
3431
import org.graalvm.nativeimage.ImageSingletons;
3532
import org.graalvm.nativeimage.hosted.Feature;
3633
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
3734
import org.graalvm.nativeimage.hosted.RuntimeReflection;
3835

36+
import com.oracle.svm.core.c.GlobalLongSupplier;
3937
import com.oracle.svm.core.feature.InternalFeature;
4038
import com.oracle.svm.core.graal.GraalConfiguration;
39+
import com.oracle.svm.core.graal.RuntimeCompilation;
4140
import com.oracle.svm.graal.GraalCompilerSupport;
4241
import com.oracle.svm.hosted.FeatureImpl;
42+
import com.oracle.svm.util.ReflectionUtil;
4343

4444
import jdk.graal.compiler.debug.DebugContext;
45+
import jdk.graal.compiler.serviceprovider.GlobalAtomicLong;
4546
import jdk.vm.ci.meta.JavaKind;
4647

4748
/**
@@ -64,8 +65,11 @@ public List<Class<? extends Feature>> getRequiredFeatures() {
6465

6566
@Override
6667
public void duringSetup(DuringSetupAccess c) {
67-
ImageSingletons.add(GraalCompilerSupport.class, new GraalCompilerSupport());
68+
if (!RuntimeCompilation.isEnabled()) {
69+
return;
70+
}
6871

72+
ImageSingletons.add(GraalCompilerSupport.class, new GraalCompilerSupport());
6973
((FeatureImpl.DuringSetupAccessImpl) c).registerClassReachabilityListener(GraalCompilerSupport::registerPhaseStatistics);
7074
}
7175

@@ -76,12 +80,17 @@ void register(BeforeAnalysisAccess access) {
7680

7781
@Override
7882
public Object transform(Object receiver, Object originalValue) {
79-
return GlobalData.createGlobal(((GlobalAtomicLong) receiver).getInitialValue());
83+
long initialValue = ((GlobalAtomicLong) receiver).getInitialValue();
84+
return new GlobalLongSupplier(initialValue);
8085
}
8186
}
8287

8388
@Override
8489
public void beforeAnalysis(BeforeAnalysisAccess c) {
90+
if (!RuntimeCompilation.isEnabled()) {
91+
return;
92+
}
93+
8594
DebugContext debug = DebugContext.forCurrentThread();
8695

8796
new GlobalAtomicLongTransformer().register(c);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/GlobalDataSupportImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626

2727
import java.util.function.Supplier;
2828

29+
import org.graalvm.nativeimage.libgraal.impl.GlobalDataSupport;
30+
2931
import com.oracle.svm.core.c.GlobalLongSupplier;
3032
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
33+
import com.oracle.svm.core.libgraal.LibGraalBuild;
3134

32-
import org.graalvm.nativeimage.libgraal.impl.GlobalDataSupport;
33-
34-
@AutomaticallyRegisteredImageSingleton(GlobalDataSupport.class)
35+
@AutomaticallyRegisteredImageSingleton(value = GlobalDataSupport.class, onlyWith = LibGraalBuild.class)
3536
public final class GlobalDataSupportImpl implements GlobalDataSupport {
3637
@Override
3738
public Supplier<Long> createGlobal(long initialValue) {

0 commit comments

Comments
 (0)