Skip to content

Commit

Permalink
Use RuntimeResourceAccess to inject resources in TruffleBaseFeature; …
Browse files Browse the repository at this point in the history
…use reachability-metadata.json config instead of feature API to add Truffle jcodings resources.
  • Loading branch information
jchalou committed Dec 10, 2024
1 parent 137fd0b commit 9b48f0c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.truffle;

/**
* When this class is reachable for native image, the resources of the module
* <code>org.graalvm.shadowed.jcodings</code> are included in the image in case the module is on
* module path or class path and {@link TruffleBaseFeature} is enabled.
*/
public class NeedsAllEncodings {
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import java.util.function.Consumer;
import java.util.stream.Stream;

import com.oracle.svm.core.log.Log;
import org.graalvm.collections.Pair;
import org.graalvm.home.HomeFinder;
import org.graalvm.home.Version;
Expand All @@ -72,8 +71,7 @@
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
import org.graalvm.nativeimage.hosted.RuntimeClassInitialization;
import org.graalvm.nativeimage.hosted.RuntimeReflection;
import org.graalvm.nativeimage.impl.ConfigurationCondition;
import org.graalvm.nativeimage.impl.RuntimeResourceSupport;
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess;
import org.graalvm.polyglot.Engine;

import com.oracle.graal.pointsto.ObjectScanner;
Expand All @@ -99,6 +97,7 @@
import com.oracle.svm.core.fieldvaluetransformer.FieldValueTransformerWithAvailability;
import com.oracle.svm.core.graal.word.SubstrateWordTypes;
import com.oracle.svm.core.heap.Pod;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.option.HostedOptionKey;
import com.oracle.svm.core.option.HostedOptionValues;
import com.oracle.svm.core.reflect.target.ReflectionSubstitutionSupport;
Expand Down Expand Up @@ -554,10 +553,6 @@ public void duringSetup(DuringSetupAccess a) {
access.registerObjectReachableCallback(TruffleFile.class, (a1, file, reason) -> checkTruffleFile(classInitializationSupport, file));
}

if (needsAllEncodings) {
RuntimeResourceSupport.singleton().addResources(ConfigurationCondition.alwaysTrue(), "org/graalvm/shadowed/org/jcodings/tables/.*bin$", "Truffle needsAllEncodings flag is set");
}

if (includeLanguageResources) {
Path resourcesForNativeImageTempDir;
try {
Expand All @@ -570,7 +565,7 @@ public void duringSetup(DuringSetupAccess a) {
new BiConsumer<Module, Pair<String, byte[]>>() {
@Override
public void accept(Module module, Pair<String, byte[]> resource) {
RuntimeResourceSupport.singleton().injectResource(module, resource.getLeft(), resource.getRight(), "Truffle Language Internal Resources");
RuntimeResourceAccess.addResource(module, resource.getLeft(), resource.getRight());
}
});
} catch (Exception e) {
Expand Down Expand Up @@ -608,6 +603,9 @@ void setGraalGraphObjectReplacer(GraalGraphObjectReplacer graalGraphObjectReplac

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
if (needsAllEncodings) {
access.registerAsUsed(NeedsAllEncodings.class);
}
if (graalGraphObjectReplacer == null) {
BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) access;
SubstrateWordTypes wordTypes = new SubstrateWordTypes(config.getMetaAccess(), ConfigurationValues.getWordKind());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private Path installResource(Function<InternalResource, InternalResource.Env> re
Objects.requireNonNull(resourceEnvProvider, "ResourceEnvProvider must be non-null.");
assert Thread.holdsLock(this) : "Unpacking must be called under lock";
assert owningRoot.kind() == InternalResourceRoots.Root.Kind.VERSIONED;
assert !ImageInfo.inImageRuntimeCode() : "Must not be called in the image execution time.";
assert !ImageInfo.inImageRuntimeCode() || aggregatedFileListHash != null : "InternalResource#unpackFiles must not be called in the image execution time.";
InternalResource resource = resourceFactory.get();
InternalResource.Env env = resourceEnvProvider.apply(resource);
String versionHash = aggregatedFileListHash == null || env.inNativeImageBuild() ? resource.versionHash(env)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"resources": [
{
"condition": {
"typeReached": "com.oracle.svm.truffle.NeedsAllEncodings"
},
"module": "org.graalvm.shadowed.jcodings",
"glob": "org/graalvm/shadowed/org/jcodings/tables/*.bin"
},
{
"condition": {
"typeReached": "com.oracle.svm.truffle.NeedsAllEncodings"
},
"glob": "org/graalvm/shadowed/org/jcodings/tables/*.bin"
}
]
}

0 comments on commit 9b48f0c

Please sign in to comment.