Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import org.graalvm.collections.EconomicMap;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platform.LINUX_AMD64;

import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.util.AnalysisError;
Expand Down Expand Up @@ -133,7 +135,7 @@ public WriteLayerArchiveSupport getWriteLayerArchiveSupport() {

public void archiveLayer() {
writer.dumpFiles();
writeLayerArchiveSupport.write();
writeLayerArchiveSupport.write(imageClassLoader.platform);
}

public SharedLayerSnapshot.Reader getSnapshot() {
Expand Down Expand Up @@ -270,10 +272,26 @@ private static boolean isLayerUseOptionEnabled(OptionValues values) {
return false;
}

private static boolean supportedPlatform(Platform platform) {
boolean supported = platform instanceof LINUX_AMD64;
return supported;
}

public static HostedImageLayerBuildingSupport initialize(HostedOptionValues values, ImageClassLoader imageClassLoader, Path builderTempDir) {
boolean buildingSharedLayer = isLayerCreateOptionEnabled(values);
boolean buildingExtensionLayer = isLayerUseOptionEnabled(values);

if (buildingSharedLayer) {
Platform platform = imageClassLoader.platform;
if (!supportedPlatform(platform)) {
ValueWithOrigin<String> valueWithOrigin = getLayerCreateValueWithOrigin(values);
String layerCreateValue = getLayerCreateValue(valueWithOrigin);
String layerCreateArg = SubstrateOptionsParser.commandArgument(SubstrateOptions.LayerCreate, layerCreateValue);
throw UserError.abort("Layer creation option '%s' from %s is not supported when building for platform %s/%s.",
layerCreateArg, valueWithOrigin.origin(), platform.getOS(), platform.getArchitecture());
}
}

boolean buildingImageLayer = buildingSharedLayer || buildingExtensionLayer;
boolean buildingInitialLayer = buildingImageLayer && !buildingExtensionLayer;
boolean buildingFinalLayer = buildingImageLayer && !buildingSharedLayer;
Expand All @@ -293,7 +311,7 @@ public static HostedImageLayerBuildingSupport initialize(HostedOptionValues valu
List<FileChannel> graphs = List.of();
if (buildingExtensionLayer) {
Path layerFileName = getLayerUseValue(values);
loadLayerArchiveSupport = new LoadLayerArchiveSupport(layerName, layerFileName, builderTempDir, archiveSupport);
loadLayerArchiveSupport = new LoadLayerArchiveSupport(layerName, layerFileName, builderTempDir, archiveSupport, imageClassLoader.platform);
boolean strict = SubstrateOptions.LayerOptionVerification.getValue(values);
boolean verbose = SubstrateOptions.LayerOptionVerificationVerbose.getValue(values);
loadLayerArchiveSupport.verifyCompatibility(imageClassLoader.classLoaderSupport, collectLayerVerifications(imageClassLoader), strict, verbose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import java.util.Objects;
import java.util.Properties;

import com.oracle.svm.core.OS;
import org.graalvm.nativeimage.Platform;

import com.oracle.svm.core.SharedConstants;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.util.ArchiveSupport;
import com.oracle.svm.core.util.UserError;
import com.oracle.svm.core.util.VMError;
Expand Down Expand Up @@ -184,7 +184,7 @@ public String toString() {
}
}

void loadAndVerify() {
void loadAndVerify(Platform current) {
Path layerFileName = layerFile.getFileName();
Path layerPropertiesFile = getLayerPropertiesFile();

Expand All @@ -204,17 +204,18 @@ void loadAndVerify() {
throw UserError.abort(message);
}

String niPlatform = properties.getOrDefault(PROPERTY_KEY_LAYER_BUILDER_VM_PLATFORM, "unknown");
if (!niPlatform.equals(platform())) {
String archivePlatform = properties.getOrDefault(PROPERTY_KEY_LAYER_BUILDER_VM_PLATFORM, "unknown");
String currentPlatform = asString(current);
if (!archivePlatform.equals(currentPlatform)) {
String message = String.format("The given layer file '%s' was created on platform '%s'. The current platform is '%s'." +
" The given layer file can only be used with an image builder running on that same platform.",
layerFileName, niPlatform, platform());
layerFileName, archivePlatform, currentPlatform);
throw UserError.abort(message);
}

String layerCreationTimestamp = properties.getOrDefault(PROPERTY_KEY_LAYER_FILE_CREATION_TIMESTAMP, "");
info("Layer created at '%s'", ArchiveSupport.parseTimestamp(layerCreationTimestamp));
info("Using version: %s on platform: '%s'", layerBuilderVMIdentifier, niPlatform);
info("Using version: %s on platform: '%s'", layerBuilderVMIdentifier, archivePlatform);
}

private void verifyLayerFileVersion(Path layerFileName) {
Expand All @@ -237,9 +238,9 @@ private void verifyLayerFileVersion(Path layerFileName) {
}
}

void write() {
void write(Platform current) {
properties.put(PROPERTY_KEY_LAYER_FILE_CREATION_TIMESTAMP, ArchiveSupport.currentTime());
properties.put(PROPERTY_KEY_LAYER_BUILDER_VM_PLATFORM, platform());
properties.put(PROPERTY_KEY_LAYER_BUILDER_VM_PLATFORM, asString(current));
BuilderVMIdentifier.system().store(properties);
Path layerPropertiesFile = getLayerPropertiesFile();
Path parent = layerPropertiesFile.getParent();
Expand All @@ -261,8 +262,8 @@ public String layerName() {
}
}

private static String platform() {
return (OS.getCurrent().className + "-" + SubstrateUtil.getArchitectureName()).toLowerCase(Locale.ROOT);
private static String asString(Platform val) {
return (val.getOS() + "-" + val.getArchitecture()).toLowerCase(Locale.ROOT);
}

protected static void info(String format, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.graalvm.nativeimage.Platform;

import com.oracle.svm.core.option.LayerVerifiedOption;
import com.oracle.svm.core.option.LayerVerifiedOption.Kind;
import com.oracle.svm.core.option.LayerVerifiedOption.Severity;
Expand All @@ -58,10 +60,10 @@
public class LoadLayerArchiveSupport extends LayerArchiveSupport {

@SuppressWarnings("this-escape")
public LoadLayerArchiveSupport(String layerName, Path layerFile, Path tempDir, ArchiveSupport archiveSupport) {
public LoadLayerArchiveSupport(String layerName, Path layerFile, Path tempDir, ArchiveSupport archiveSupport, Platform current) {
super(layerName, layerFile, tempDir.resolve(LAYER_TEMP_DIR_PREFIX + "load"), archiveSupport);
this.archiveSupport.expandJarToDir(layerFile, layerDir);
layerProperties.loadAndVerify();
layerProperties.loadAndVerify(current);
loadBuilderArgumentsFile();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.nio.file.Path;
import java.util.jar.JarOutputStream;

import org.graalvm.nativeimage.Platform;

import com.oracle.svm.core.BuildArtifacts;
import com.oracle.svm.core.BuildArtifacts.ArtifactType;
import com.oracle.svm.core.SubstrateOptions;
Expand Down Expand Up @@ -86,7 +88,7 @@ private void writeEnvVariablesFile() {
}
}

public void write() {
public void write(Platform current) {
try (JarOutputStream jarOutStream = new JarOutputStream(Files.newOutputStream(layerFile), archiveSupport.createManifest())) {
// disable compression for significant (un)archiving speedup at the cost of file size
jarOutStream.setLevel(0);
Expand All @@ -103,7 +105,7 @@ public void write() {
Path sharedLibFile = BuildArtifacts.singleton().get(BuildArtifacts.ArtifactType.IMAGE_LAYER).getFirst();
archiveSupport.addFileToJar(NativeImageGenerator.getOutputDirectory(), sharedLibFile, layerFile, jarOutStream);
// write properties file and add to jar
layerProperties.write();
layerProperties.write(current);
archiveSupport.addFileToJar(layerDir, getLayerPropertiesFile(), layerFile, jarOutStream);
BuildArtifacts.singleton().add(ArtifactType.IMAGE_LAYER_BUNDLE, layerFile);
} catch (IOException e) {
Expand Down
Loading