Skip to content

[GR-55581] Check layered image build option compatibility. #11207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -68,8 +68,6 @@ enum ArtifactType {
BUILD_INFO("build_info"),
/* For all debugging-related artifacts. */
DEBUG_INFO("debug_info"),
LAYER_SNAPSHOT("layer_snapshot"),
LAYER_SNAPSHOT_GRAPHS("layer_snapshot_graphs"),

/* For C header files. */
C_HEADER("c_headers"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.jar.Attributes;
Expand Down Expand Up @@ -96,15 +97,15 @@ public Manifest createManifest(String mainClass) {
return mf;
}

public void expandJarToDir(Path inputJarFilePath, Path outputDir, AtomicBoolean outputDirDeleted) {
expandJarToDir(Function.identity(), inputJarFilePath, outputDir, outputDirDeleted);
public void expandJarToDir(Path inputJarFilePath, Path outputDir) {
expandJarToDir(Function.identity(), inputJarFilePath, outputDir, () -> false);
}

public void expandJarToDir(Function<Path, Path> relativizeEntry, Path inputJarFilePath, Path outputDir, AtomicBoolean outputDirDeleted) {
public void expandJarToDir(Function<Path, Path> relativizeEntry, Path inputJarFilePath, Path outputDir, BooleanSupplier outputDirDeleted) {
try {
try (JarFile archive = new JarFile(inputJarFilePath.toFile())) {
Enumeration<JarEntry> jarEntries = archive.entries();
while (jarEntries.hasMoreElements() && !outputDirDeleted.get()) {
while (jarEntries.hasMoreElements() && !outputDirDeleted.getAsBoolean()) {
JarEntry jarEntry = jarEntries.nextElement();
Path originalEntry = outputDir.resolve(jarEntry.getName());
Path targetEntry = relativizeEntry.apply(originalEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private BundleSupport(NativeImage nativeImage, String bundleFilenameArg) {
outputDir = rootDir.resolve("output");

Path bundleFilePath = bundlePath.resolve(bundleName + BUNDLE_FILE_EXTENSION);
nativeImage.archiveSupport().expandJarToDir(e -> relativizeBundleEntry(getOriginalOutputDirName(), e), bundleFilePath, rootDir, deleteBundleRoot);
nativeImage.archiveSupport().expandJarToDir(e -> relativizeBundleEntry(getOriginalOutputDirName(), e), bundleFilePath, rootDir, deleteBundleRoot::get);

if (deleteBundleRoot.get()) {
/* Abort image build request without error message and exit with 0 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,21 +523,23 @@ public void run(Map<Method, CEntryPointData> entryPoints,
setSystemPropertiesForImageLate(k);

var hostedOptionValues = new HostedOptionValues(optionProvider.getHostedValues());
HostedImageLayerBuildingSupport imageLayerSupport = HostedImageLayerBuildingSupport.initialize(hostedOptionValues, loader);
ImageSingletonsSupportImpl.HostedManagement.install(new ImageSingletonsSupportImpl.HostedManagement(imageLayerSupport.buildingImageLayer), imageLayerSupport);

ImageSingletons.add(LayeredImageSingletonSupport.class, (LayeredImageSingletonSupport) ImageSingletonsSupportImpl.get());
ImageSingletons.add(ProgressReporter.class, reporter);
ImageSingletons.add(DeadlockWatchdog.class, loader.watchdog);
ImageSingletons.add(TimerCollection.class, timerCollection);
ImageSingletons.add(ImageBuildStatistics.TimerCollectionPrinter.class, timerCollection);
ImageSingletons.add(AnnotationExtractor.class, loader.classLoaderSupport.annotationExtractor);
ImageSingletons.add(BuildArtifacts.class, new BuildArtifactsImpl());
ImageSingletons.add(HostedOptionValues.class, hostedOptionValues);
ImageSingletons.add(RuntimeOptionValues.class, new RuntimeOptionValues(optionProvider.getRuntimeValues(), allOptionNames));

try (TemporaryBuildDirectoryProviderImpl tempDirectoryProvider = new TemporaryBuildDirectoryProviderImpl()) {
var tempDirectoryOptionValue = NativeImageOptions.TempDirectory.getValue(hostedOptionValues).lastValue().orElse(null);
try (TemporaryBuildDirectoryProviderImpl tempDirectoryProvider = new TemporaryBuildDirectoryProviderImpl(tempDirectoryOptionValue)) {
var builderTempDir = tempDirectoryProvider.getTemporaryBuildDirectory();
HostedImageLayerBuildingSupport imageLayerSupport = HostedImageLayerBuildingSupport.initialize(hostedOptionValues, loader, builderTempDir);
ImageSingletonsSupportImpl.HostedManagement.install(new ImageSingletonsSupportImpl.HostedManagement(imageLayerSupport.buildingImageLayer), imageLayerSupport);

ImageSingletons.add(LayeredImageSingletonSupport.class, (LayeredImageSingletonSupport) ImageSingletonsSupportImpl.get());
ImageSingletons.add(ProgressReporter.class, reporter);
ImageSingletons.add(DeadlockWatchdog.class, loader.watchdog);
ImageSingletons.add(TimerCollection.class, timerCollection);
ImageSingletons.add(ImageBuildStatistics.TimerCollectionPrinter.class, timerCollection);
ImageSingletons.add(AnnotationExtractor.class, loader.classLoaderSupport.annotationExtractor);
ImageSingletons.add(BuildArtifacts.class, new BuildArtifactsImpl());
ImageSingletons.add(HostedOptionValues.class, hostedOptionValues);
ImageSingletons.add(RuntimeOptionValues.class, new RuntimeOptionValues(optionProvider.getRuntimeValues(), allOptionNames));
ImageSingletons.add(TemporaryBuildDirectoryProvider.class, tempDirectoryProvider);

doRun(entryPoints, javaMainSupport, imageName, k, harnessSubstitutions);
} finally {
reporter.ensureCreationStageEndCompleted();
Expand Down Expand Up @@ -571,7 +573,7 @@ protected void doRun(Map<Method, CEntryPointData> entryPoints, JavaMainSupport j

try (DebugContext debug = new Builder(options, new GraalDebugHandlersFactory(GraalAccess.getOriginalSnippetReflection())).build();
DebugCloseable featureCleanup = () -> featureHandler.forEachFeature(Feature::cleanup)) {
setupNativeImage(imageName, options, entryPoints, javaMainSupport, harnessSubstitutions, debug);
setupNativeImage(options, entryPoints, javaMainSupport, harnessSubstitutions, debug);

boolean returnAfterAnalysis = runPointsToAnalysis(imageName, options, debug);
if (returnAfterAnalysis) {
Expand Down Expand Up @@ -766,7 +768,7 @@ protected void doRun(Map<Method, CEntryPointData> entryPoints, JavaMainSupport j
try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.ARCHIVE_LAYER)) {
if (ImageLayerBuildingSupport.buildingSharedLayer()) {
ImageSingletonsSupportImpl.HostedManagement.persist();
HostedImageLayerBuildingSupport.singleton().archiveLayer(imageName);
HostedImageLayerBuildingSupport.singleton().archiveLayer();
}
}
reporter.printCreationEnd(image.getImageFileSize(), heap.getLayerObjectCount(), image.getImageHeapSize(), codeCache.getCodeAreaSize(), numCompilations, image.getDebugInfoSize(),
Expand Down Expand Up @@ -917,7 +919,7 @@ protected boolean verifyAssignableTypes() {
}

@SuppressWarnings("try")
protected void setupNativeImage(String imageName, OptionValues options, Map<Method, CEntryPointData> entryPoints, JavaMainSupport javaMainSupport,
protected void setupNativeImage(OptionValues options, Map<Method, CEntryPointData> entryPoints, JavaMainSupport javaMainSupport,
SubstitutionProcessor harnessSubstitutions, DebugContext debug) {
try (Indent ignored = debug.logAndIndent("setup native-image builder")) {
try (StopTimer ignored1 = TimerCollection.createTimerAndStart(TimerCollection.Registry.SETUP)) {
Expand Down Expand Up @@ -996,7 +998,6 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
if (ImageLayerBuildingSupport.buildingSharedLayer()) {
SVMImageLayerWriter imageLayerWriter = HostedConfiguration.instance().createSVMImageLayerWriter(imageLayerSnapshotUtil, useSharedLayerGraphs, useSharedLayerStrengthenedGraphs);
HostedImageLayerBuildingSupport.singleton().setWriter(imageLayerWriter);
HostedImageLayerBuildingSupport.setupImageLayerArtifacts(imageName);
}

if (ImageLayerBuildingSupport.buildingExtensionLayer()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,30 @@
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Optional;

import com.oracle.svm.core.c.libc.TemporaryBuildDirectoryProvider;
import com.oracle.svm.core.util.TimeUtils;
import com.oracle.svm.core.util.VMError;

public class TemporaryBuildDirectoryProviderImpl implements TemporaryBuildDirectoryProvider, AutoCloseable {

private final Path tempDirectoryOptionValue;
private Path tempDirectory;
private boolean deleteTempDirectory;

public TemporaryBuildDirectoryProviderImpl(Path tempDirectoryOptionValue) {
this.tempDirectoryOptionValue = tempDirectoryOptionValue;
}

@Override
public synchronized Path getTemporaryBuildDirectory() {
if (tempDirectory == null) {
try {
Optional<Path> tempName = NativeImageOptions.TempDirectory.getValue().lastValue();
if (tempName.isEmpty()) {
if (tempDirectoryOptionValue == null) {
tempDirectory = Files.createTempDirectory("SVM-");
deleteTempDirectory = true;
} else {
tempDirectory = tempName.get().resolve("SVM-" + TimeUtils.currentTimeMillis());
tempDirectory = tempDirectoryOptionValue.resolve("SVM-" + TimeUtils.currentTimeMillis());
assert !Files.exists(tempDirectory);
Files.createDirectories(tempDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@

import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;

import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.imagelayer.LayerArchiveSupport;

public class LayerOptionsSupport extends IncludeOptionsSupport {

Expand All @@ -43,8 +45,20 @@ public static LayerOption parse(String layerOptionValue) {

public static LayerOption parse(List<String> options) {
VMError.guarantee(!options.isEmpty());
ExtendedOption[] extendedOptions = options.stream().skip(1).map(ExtendedOption::parse).toArray(ExtendedOption[]::new);
return new LayerOption(Path.of(options.getFirst()), extendedOptions);

Stream<String> optionsStream = options.stream();
String fileName;
String first = options.getFirst();
if (first.isEmpty() || first.endsWith(LayerArchiveSupport.LAYER_FILE_EXTENSION)) {
// First entry is empty or valid filename -> skip from parsing and use as filename
optionsStream = optionsStream.skip(1);
fileName = first;
} else {
// Assume first entry holds ExtendedOption value and use empty string as fileName
fileName = "";
}
ExtendedOption[] extendedOptions = optionsStream.map(ExtendedOption::parse).toArray(ExtendedOption[]::new);
return new LayerOption(Path.of(fileName), extendedOptions);
}
}
}
Loading
Loading