Skip to content

Commit 91267e3

Browse files
committed
[GR-47665] Adopt internal resources API in Sulong.
PullRequest: graal/15211
2 parents 9fa9d51 + 5cd3ec1 commit 91267e3

File tree

41 files changed

+792
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+792
-269
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,32 @@ final class Target_com_oracle_truffle_polyglot_LanguageCache {
13531353
private String languageHome;
13541354
}
13551355

1356+
@TargetClass(className = "com.oracle.truffle.polyglot.InternalResourceCache", onlyWith = TruffleBaseFeature.IsEnabled.class)
1357+
final class Target_com_oracle_truffle_polyglot_InternalResourceCache {
1358+
1359+
/*
1360+
* The field is also reset explicitly in InternalResourceCache.resetFileSystemNativeImageState.
1361+
* However, the explicit reset comes too late for the String-must-not-contain-the-home-directory
1362+
* verification in DisallowedImageHeapObjectFeature, so we also do the implicit reset using a
1363+
* substitution.
1364+
*/
1365+
@Alias @RecomputeFieldValue(kind = Kind.Reset) //
1366+
private static volatile Pair<Path, Boolean> cacheRoot;
1367+
}
1368+
1369+
@TargetClass(className = "com.oracle.truffle.polyglot.InternalResourceCache$ResettableCachedRoot", onlyWith = TruffleBaseFeature.IsEnabled.class)
1370+
final class Target_com_oracle_truffle_polyglot_InternalResourceCache_ResettableCachedRoot {
1371+
1372+
/*
1373+
* The field is also reset explicitly in InternalResourceCache.resetFileSystemNativeImageState.
1374+
* However, the explicit reset comes too late for the String-must-not-contain-the-home-directory
1375+
* verification in DisallowedImageHeapObjectFeature, so we also do the implicit reset using a
1376+
* substitution.
1377+
*/
1378+
@Alias @RecomputeFieldValue(kind = Kind.Reset) //
1379+
private volatile Path resourceCacheRoot;
1380+
}
1381+
13561382
@TargetClass(className = "com.oracle.truffle.object.CoreLocations$DynamicObjectFieldLocation", onlyWith = TruffleBaseFeature.IsEnabled.class)
13571383
final class Target_com_oracle_truffle_object_CoreLocations_DynamicObjectFieldLocation {
13581384
@Alias @RecomputeFieldValue(kind = Kind.AtomicFieldUpdaterOffset) //

sulong/mx.sulong/mx_sulong.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def _get_jar_dists(self):
516516
license_files=[],
517517
third_party_license_files=[],
518518
dependencies=['Truffle NFI LIBFFI', 'LLVM Runtime Core'],
519-
truffle_jars=['sulong:SULONG_NATIVE'],
519+
truffle_jars=['sulong:SULONG_NATIVE', 'sulong:SULONG_NATIVE_RESOURCES'],
520520
support_distributions=[
521521
'sulong:SULONG_BITCODE_HOME',
522522
'sulong:SULONG_NATIVE_HOME',

sulong/mx.sulong/suite.py

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,21 @@
392392
"jacoco" : "include",
393393
},
394394

395+
"com.oracle.truffle.llvm.nativemode.resources" : {
396+
"subDir" : "projects",
397+
"sourceDirs" : ["src"],
398+
"dependencies" : [
399+
"truffle:TRUFFLE_API",
400+
"sulong:SULONG_API",
401+
],
402+
"checkstyle" : "com.oracle.truffle.llvm.runtime",
403+
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR"],
404+
"javaCompliance" : "17+",
405+
"workingSets" : "Truffle, LLVM",
406+
"license" : "BSD-new",
407+
"jacoco" : "include",
408+
},
409+
395410
"com.oracle.truffle.llvm.runtime" : {
396411
"subDir" : "projects",
397412
"sourceDirs" : ["src"],
@@ -400,6 +415,7 @@
400415
"truffle:TRUFFLE_NFI",
401416
"com.oracle.truffle.llvm.api",
402417
"com.oracle.truffle.llvm.spi",
418+
"com.oracle.truffle.llvm.nativemode.resources",
403419
"truffle:ANTLR4",
404420
],
405421
"requires" : [
@@ -1582,12 +1598,17 @@
15821598
"SULONG_CORE" : {
15831599
"description" : "Sulong core functionality (parser, execution engine, launcher)",
15841600
"moduleInfo" : {
1585-
"name" : "org.graalvm.llvm",
1601+
"name" : "org.graalvm.llvm_community",
15861602
"exports" : [
1587-
"* to org.graalvm.llvm.nativemode,org.graalvm.llvm_enterprise,org.graalvm.llvm.managed,org.graalvm.llvm.nativemode_enterprise,org.graalvm.llvm.mixed",
1603+
"* to org.graalvm.llvm.nativemode,org.graalvm.llvm,org.graalvm.llvm.managed,org.graalvm.llvm.nativemode_community",
1604+
],
1605+
"requires" : [
1606+
# for registration in the language class only
1607+
"static org.graalvm.llvm.nativemode.resources"
15881608
],
15891609
"uses" : [
15901610
"com.oracle.truffle.llvm.runtime.config.ConfigurationFactory",
1611+
"com.oracle.truffle.llvm.spi.internal.LLVMResourceProvider",
15911612
],
15921613
},
15931614
"subDir" : "projects",
@@ -1599,6 +1620,7 @@
15991620
"truffle:TRUFFLE_API",
16001621
"truffle:TRUFFLE_NFI",
16011622
"SULONG_API",
1623+
"SULONG_NATIVE_RESOURCES",
16021624
],
16031625
"exclude" : [
16041626
"truffle:ANTLR4",
@@ -1619,6 +1641,7 @@
16191641
"runtimeDependencies": [
16201642
"SULONG_CORE",
16211643
"SULONG_NATIVE",
1644+
"SULONG_NATIVE_RESOURCES",
16221645
"SULONG_NFI",
16231646
"truffle:TRUFFLE_RUNTIME",
16241647
],
@@ -1651,6 +1674,7 @@
16511674
"exports" : [
16521675
"com.oracle.truffle.llvm.api",
16531676
"com.oracle.truffle.llvm.spi",
1677+
"com.oracle.truffle.llvm.spi.internal to org.graalvm.llvm_community,org.graalvm.llvm.nativemode.resources,org.graalvm.llvm.managed.resources",
16541678
],
16551679
},
16561680
"subDir" : "projects",
@@ -1670,9 +1694,14 @@
16701694
"SULONG_NATIVE" : {
16711695
"description" : "Sulong Native functionality (native memory support, native library support)",
16721696
"moduleInfo" : {
1673-
"name" : "org.graalvm.llvm.nativemode",
1697+
"name" : "org.graalvm.llvm.nativemode_community",
16741698
"exports" : [
1675-
"* to org.graalvm.llvm.nativemode_enterprise,org.graalvm.llvm.mixed",
1699+
"* to org.graalvm.llvm.nativemode",
1700+
],
1701+
"requires" : [
1702+
# static because it's not needed if the language home is there (e.g. in standalones)
1703+
# will be loaded via ServiceLoader if the language home is not there
1704+
"static org.graalvm.llvm.nativemode.resources",
16761705
],
16771706
},
16781707
"subDir" : "projects",
@@ -1688,6 +1717,28 @@
16881717
},
16891718
"license" : "BSD-new",
16901719
},
1720+
"SULONG_NATIVE_RESOURCES" : {
1721+
"description" : "Module that contains resources needed by Sulong Native mode.",
1722+
"moduleInfo" : {
1723+
"name" : "org.graalvm.llvm.nativemode.resources",
1724+
"exports" : [
1725+
"* to org.graalvm.llvm.nativemode_community,org.graalvm.llvm_community",
1726+
],
1727+
},
1728+
"subDir" : "projects",
1729+
"dependencies" : ["com.oracle.truffle.llvm.nativemode.resources"],
1730+
"distDependencies" : [
1731+
"truffle:TRUFFLE_API",
1732+
"SULONG_API",
1733+
"SULONG_NATIVE_LIB_RESOURCES",
1734+
"SULONG_NATIVE_BITCODE_RESOURCES",
1735+
],
1736+
"maven" : {
1737+
"artifactId" : "llvm-language-native-resources",
1738+
"tag": ["default", "public"],
1739+
},
1740+
"license" : "BSD-new",
1741+
},
16911742
"SULONG_NFI" : {
16921743
"description" : "Sulong NFI backend",
16931744
"moduleInfo" : {
@@ -1748,7 +1799,7 @@
17481799
"./native/lib/" : [
17491800
"dependency:com.oracle.truffle.llvm.libraries.pthread/lib/*",
17501801
"dependency:com.oracle.truffle.llvm.libraries.bitcode.libcxx/native/bin/*",
1751-
"dependency:com.oracle.truffle.llvm.libraries.bitcode.libcxx/native/lib/*",
1802+
"dependency:com.oracle.truffle.llvm.libraries.bitcode.libcxx/native/lib/*",
17521803
"dependency:com.oracle.truffle.llvm.libraries.oldnames/<staticlib:oldnames>",
17531804
],
17541805
},
@@ -1817,6 +1868,51 @@
18171868
"license" : "BSD-new",
18181869
},
18191870

1871+
"SULONG_NATIVE_BITCODE_RESOURCES" : {
1872+
"description" : "Contains the runtime dependencies needed by the LLVM runtime in native mode.",
1873+
"type" : "dir",
1874+
"platformDependent" : True,
1875+
"hashEntry" : "META-INF/resources/llvm/native/<os>/<arch>/sha256",
1876+
"fileListEntry" : "META-INF/resources/llvm/native/<os>/<arch>/files",
1877+
"platforms" : [
1878+
"linux-amd64",
1879+
"linux-aarch64",
1880+
"darwin-amd64",
1881+
"darwin-aarch64",
1882+
"windows-amd64",
1883+
],
1884+
"layout" : {
1885+
"META-INF/resources/llvm/native/<os>/<arch>/lib/": [
1886+
"extracted-dependency:SULONG_BITCODE_HOME/native/lib/*",
1887+
"extracted-dependency:SULONG_NATIVE_HOME/native/lib/<libv:*.1>",
1888+
],
1889+
},
1890+
"defaultDereference": "always",
1891+
"maven": False,
1892+
},
1893+
1894+
"SULONG_NATIVE_LIB_RESOURCES" : {
1895+
"description" : "Contains the runtime dependencies needed by the LLVM runtime in native mode.",
1896+
"type" : "dir",
1897+
"platformDependent" : True,
1898+
"hashEntry" : "META-INF/resources/llvm/native-lib/<os>/<arch>/sha256",
1899+
"fileListEntry" : "META-INF/resources/llvm/native-lib/<os>/<arch>/files",
1900+
"platforms" : [
1901+
"linux-amd64",
1902+
"linux-aarch64",
1903+
"darwin-amd64",
1904+
"darwin-aarch64",
1905+
"windows-amd64",
1906+
],
1907+
"layout" : {
1908+
"META-INF/resources/llvm/native-lib/<os>/<arch>/": [
1909+
"dependency:com.oracle.truffle.llvm.libraries.native/bin/*",
1910+
],
1911+
},
1912+
"defaultDereference": "always",
1913+
"maven": False,
1914+
},
1915+
18201916
"SULONG_TOOLCHAIN_LAUNCHERS": {
18211917
"subDir" : "projects",
18221918
"dependencies" : ["com.oracle.truffle.llvm.toolchain.launchers"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.oracle.truffle.llvm.nativemode.resources.NativeResourceProvider
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates.
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification, are
7+
* permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this list of
10+
* conditions and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
* conditions and the following disclaimer in the documentation and/or other materials provided
14+
* with the distribution.
15+
*
16+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
17+
* endorse or promote products derived from this software without specific prior written
18+
* permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
21+
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
* OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.oracle.truffle.llvm.nativemode.resources;
31+
32+
import com.oracle.truffle.api.InternalResource.CPUArchitecture;
33+
import com.oracle.truffle.api.InternalResource.OS;
34+
import com.oracle.truffle.llvm.spi.internal.LLVMResourceProvider;
35+
36+
public class NativeResourceProvider implements LLVMResourceProvider {
37+
38+
@Override
39+
public String getConfiguration() {
40+
return "native";
41+
}
42+
43+
@Override
44+
public String getBasePath(OS os, CPUArchitecture arch) {
45+
return String.format("/META-INF/resources/llvm/native/%s/%s/lib/", os, arch);
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates.
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification, are
7+
* permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this list of
10+
* conditions and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
* conditions and the following disclaimer in the documentation and/or other materials provided
14+
* with the distribution.
15+
*
16+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
17+
* endorse or promote products derived from this software without specific prior written
18+
* permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
21+
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
* OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.oracle.truffle.llvm.nativemode.resources;
31+
32+
import java.io.IOException;
33+
import java.nio.file.Path;
34+
35+
import com.oracle.truffle.api.CompilerDirectives;
36+
import com.oracle.truffle.api.InternalResource;
37+
38+
@InternalResource.Id("libsulong-native")
39+
public class SulongNativeLibResource implements InternalResource {
40+
41+
private static Path basePath(Env env) {
42+
return Path.of("META-INF", "resources", "llvm", "native-lib", env.getOS().toString(), env.getCPUArchitecture().toString());
43+
}
44+
45+
@Override
46+
public void unpackFiles(Env env, Path targetDirectory) throws IOException {
47+
Path base = basePath(env);
48+
env.unpackResourceFiles(base.resolve("files"), targetDirectory, base);
49+
}
50+
51+
@Override
52+
public String versionHash(Env env) {
53+
try {
54+
Path hashResource = basePath(env).resolve("sha256");
55+
return env.readResourceLines(hashResource).get(0);
56+
} catch (IOException ioe) {
57+
throw CompilerDirectives.shouldNotReachHere(ioe);
58+
}
59+
}
60+
}

sulong/projects/com.oracle.truffle.llvm.nativemode/src/com/oracle/truffle/llvm/nativemode/NativeConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -37,6 +37,7 @@
3737
import com.oracle.truffle.llvm.parser.factories.BasicNodeFactory;
3838
import com.oracle.truffle.llvm.parser.factories.BasicPlatformCapability;
3939
import com.oracle.truffle.llvm.runtime.ContextExtension;
40+
import com.oracle.truffle.llvm.runtime.InternalLibraryLocator;
4041
import com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider;
4142
import com.oracle.truffle.llvm.runtime.LLVMLanguage;
4243
import com.oracle.truffle.llvm.runtime.LLVMLanguage.Loader;
@@ -54,12 +55,15 @@ public class NativeConfiguration implements Configuration {
5455
private final Loader loader;
5556
private final LLVMIntrinsicProvider intrinsicProvider;
5657
private final PlatformCapability<?> platformCapability;
58+
private final InternalLibraryLocator internalLocator;
59+
5760
protected final Key languageOptions;
5861

5962
protected NativeConfiguration(LLVMLanguage language, ContextExtension.Registry ctxExtRegistry, Key key) {
6063
loader = new DefaultLoader();
6164
intrinsicProvider = new BasicIntrinsicsProvider(language);
6265
platformCapability = BasicPlatformCapability.create(key.loadCxxLibraries);
66+
internalLocator = InternalLibraryLocator.create("native", language, platformCapability.getOS(), platformCapability.getArch());
6367
this.languageOptions = key;
6468
if (key.enableNFI) {
6569
ctxExtRegistry.register(NativeContextExtension.class, new NFIContextExtension.Factory());
@@ -84,6 +88,8 @@ public <C extends LLVMCapability> C getCapability(Class<C> type) {
8488
return type.cast(intrinsicProvider);
8589
} else if (type == PlatformCapability.class) {
8690
return type.cast(platformCapability);
91+
} else if (type == InternalLibraryLocator.class) {
92+
return type.cast(internalLocator);
8793
}
8894
return null;
8995
}

0 commit comments

Comments
 (0)