Skip to content

Commit a53eb3b

Browse files
committed
Use RuntimeResourceAccess to inject resources in TruffleBaseFeature; use reachability-metadata.json config instead of feature API to add Truffle jcodings resources.
1 parent 7467673 commit a53eb3b

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2024, 2024, 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.truffle;
26+
27+
/**
28+
* When this class is reachable for native image, the resources of the module
29+
* <code>org.graalvm.shadowed.jcodings</code> are included in the image in case the module is on
30+
* module path or class path and {@link TruffleBaseFeature} is enabled.
31+
*/
32+
public class NeedsAllEncodings {
33+
}

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import java.util.function.Consumer;
6363
import java.util.stream.Stream;
6464

65-
import com.oracle.svm.core.log.Log;
6665
import org.graalvm.collections.Pair;
6766
import org.graalvm.home.HomeFinder;
6867
import org.graalvm.home.Version;
@@ -72,8 +71,7 @@
7271
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
7372
import org.graalvm.nativeimage.hosted.RuntimeClassInitialization;
7473
import org.graalvm.nativeimage.hosted.RuntimeReflection;
75-
import org.graalvm.nativeimage.impl.ConfigurationCondition;
76-
import org.graalvm.nativeimage.impl.RuntimeResourceSupport;
74+
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess;
7775
import org.graalvm.polyglot.Engine;
7876

7977
import com.oracle.graal.pointsto.ObjectScanner;
@@ -99,6 +97,7 @@
9997
import com.oracle.svm.core.fieldvaluetransformer.FieldValueTransformerWithAvailability;
10098
import com.oracle.svm.core.graal.word.SubstrateWordTypes;
10199
import com.oracle.svm.core.heap.Pod;
100+
import com.oracle.svm.core.log.Log;
102101
import com.oracle.svm.core.option.HostedOptionKey;
103102
import com.oracle.svm.core.option.HostedOptionValues;
104103
import com.oracle.svm.core.reflect.target.ReflectionSubstitutionSupport;
@@ -554,10 +553,6 @@ public void duringSetup(DuringSetupAccess a) {
554553
access.registerObjectReachableCallback(TruffleFile.class, (a1, file, reason) -> checkTruffleFile(classInitializationSupport, file));
555554
}
556555

557-
if (needsAllEncodings) {
558-
RuntimeResourceSupport.singleton().addResources(ConfigurationCondition.alwaysTrue(), "org/graalvm/shadowed/org/jcodings/tables/.*bin$", "Truffle needsAllEncodings flag is set");
559-
}
560-
561556
if (includeLanguageResources) {
562557
Path resourcesForNativeImageTempDir;
563558
try {
@@ -570,7 +565,7 @@ public void duringSetup(DuringSetupAccess a) {
570565
new BiConsumer<Module, Pair<String, byte[]>>() {
571566
@Override
572567
public void accept(Module module, Pair<String, byte[]> resource) {
573-
RuntimeResourceSupport.singleton().injectResource(module, resource.getLeft(), resource.getRight(), "Truffle Language Internal Resources");
568+
RuntimeResourceAccess.addResource(module, resource.getLeft(), resource.getRight());
574569
}
575570
});
576571
} catch (Exception e) {
@@ -608,6 +603,9 @@ void setGraalGraphObjectReplacer(GraalGraphObjectReplacer graalGraphObjectReplac
608603

609604
@Override
610605
public void beforeAnalysis(BeforeAnalysisAccess access) {
606+
if (needsAllEncodings) {
607+
access.registerAsUsed(NeedsAllEncodings.class);
608+
}
611609
if (graalGraphObjectReplacer == null) {
612610
BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) access;
613611
SubstrateWordTypes wordTypes = new SubstrateWordTypes(config.getMetaAccess(), ConfigurationValues.getWordKind());

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/InternalResourceCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private Path installResource(Function<InternalResource, InternalResource.Env> re
227227
Objects.requireNonNull(resourceEnvProvider, "ResourceEnvProvider must be non-null.");
228228
assert Thread.holdsLock(this) : "Unpacking must be called under lock";
229229
assert owningRoot.kind() == InternalResourceRoots.Root.Kind.VERSIONED;
230-
assert !ImageInfo.inImageRuntimeCode() : "Must not be called in the image execution time.";
230+
assert !ImageInfo.inImageRuntimeCode() || aggregatedFileListHash != null : "InternalResource#unpackFiles must not be called in the image execution time.";
231231
InternalResource resource = resourceFactory.get();
232232
InternalResource.Env env = resourceEnvProvider.apply(resource);
233233
String versionHash = aggregatedFileListHash == null || env.inNativeImageBuild() ? resource.versionHash(env)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"resources": [
3+
{
4+
"condition": {
5+
"typeReached": "com.oracle.svm.truffle.NeedsAllEncodings"
6+
},
7+
"module": "org.graalvm.shadowed.jcodings",
8+
"glob": "org/graalvm/shadowed/org/jcodings/tables/*.bin"
9+
},
10+
{
11+
"condition": {
12+
"typeReached": "com.oracle.svm.truffle.NeedsAllEncodings"
13+
},
14+
"glob": "org/graalvm/shadowed/org/jcodings/tables/*.bin"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)