From 9d5c3bff371e7c8efdeebc435c367f06c4405f57 Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Wed, 27 Mar 2024 12:02:41 +0100 Subject: [PATCH] Remove ImageHeapProvider.guaranteesHeapPreferredAddressSpaceAlignment() and CommittedMemoryProvider.guaranteesHeapPreferredAddressSpaceAlignment(). --- .../svm/core/genscavenge/AlignedHeapChunk.java | 3 +-- .../com/oracle/svm/core/genscavenge/HeapImpl.java | 12 ++++++++---- .../oracle/svm/core/genscavenge/HeapVerifier.java | 3 +-- .../svm/core/genscavenge/UnalignedHeapChunk.java | 3 +-- .../svm/core/posix/linux/LinuxImageHeapProvider.java | 5 ----- .../src/com/oracle/svm/core/heap/Heap.java | 7 +------ .../svm/core/os/AbstractCommittedMemoryProvider.java | 6 ------ .../core/os/AbstractCopyingImageHeapProvider.java | 5 ----- .../oracle/svm/core/os/CommittedMemoryProvider.java | 9 --------- .../com/oracle/svm/core/os/ImageHeapProvider.java | 8 -------- 10 files changed, 12 insertions(+), 49 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AlignedHeapChunk.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AlignedHeapChunk.java index 54ed7ea421b3..2c60e57f9fb6 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AlignedHeapChunk.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AlignedHeapChunk.java @@ -33,7 +33,6 @@ import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.genscavenge.remset.RememberedSet; import com.oracle.svm.core.heap.ObjectVisitor; -import com.oracle.svm.core.os.CommittedMemoryProvider; import com.oracle.svm.core.util.PointerUtils; import jdk.graal.compiler.api.directives.GraalDirectives; @@ -121,7 +120,7 @@ public static AlignedHeader getEnclosingChunk(Object obj) { @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public static AlignedHeader getEnclosingChunkFromObjectPointer(Pointer ptr) { if (!GraalDirectives.inIntrinsic()) { - assert !HeapImpl.getHeapImpl().isInImageHeap(ptr) || CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment() : "can't be used because the image heap is unaligned"; + assert HeapImpl.isImageHeapAligned() || !HeapImpl.getHeapImpl().isInImageHeap(ptr) : "can't be used because the image heap is unaligned"; } return (AlignedHeader) PointerUtils.roundDown(ptr, HeapParameters.getAlignedHeapChunkAlignment()); } diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java index b9e2598ad365..a8c8e3ab38ee 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java @@ -75,7 +75,6 @@ import com.oracle.svm.core.nodes.CFunctionEpilogueNode; import com.oracle.svm.core.nodes.CFunctionPrologueNode; import com.oracle.svm.core.option.RuntimeOptionKey; -import com.oracle.svm.core.os.CommittedMemoryProvider; import com.oracle.svm.core.snippets.KnownIntrinsics; import com.oracle.svm.core.thread.PlatformThreads; import com.oracle.svm.core.thread.ThreadStatus; @@ -407,9 +406,9 @@ public static boolean usesImageHeapCardMarking() { if (enabled == Boolean.FALSE || enabled == null && !SubstrateOptions.useRememberedSet()) { return false; } else if (enabled == null) { - return CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment(); + return isImageHeapAligned(); } - UserError.guarantee(CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment(), + UserError.guarantee(isImageHeapAligned(), "Enabling option %s requires a custom image heap alignment at runtime, which cannot be ensured with the current configuration (option %s might be disabled)", SerialGCOptions.ImageHeapCardMarking, SubstrateOptions.SpawnIsolates); return true; @@ -424,7 +423,7 @@ public int getPreferredAddressSpaceAlignment() { @Fold @Override public int getImageHeapOffsetInAddressSpace() { - if (SubstrateOptions.SpawnIsolates.getValue() && SubstrateOptions.UseNullRegion.getValue() && CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment()) { + if (SubstrateOptions.SpawnIsolates.getValue() && SubstrateOptions.UseNullRegion.getValue()) { /* * The image heap will be mapped in a way that there is a memory protected gap between * the heap base and the start of the image heap. The gap won't need any memory in the @@ -435,6 +434,11 @@ public int getImageHeapOffsetInAddressSpace() { return 0; } + @Fold + public static boolean isImageHeapAligned() { + return SubstrateOptions.SpawnIsolates.getValue(); + } + @Override public boolean walkImageHeapObjects(ObjectVisitor visitor) { VMOperation.guaranteeInProgressAtSafepoint("Must only be called at a safepoint"); diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapVerifier.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapVerifier.java index c2073f0078f3..d76af06a5c5c 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapVerifier.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapVerifier.java @@ -44,7 +44,6 @@ import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.hub.InteriorObjRefWalker; import com.oracle.svm.core.log.Log; -import com.oracle.svm.core.os.CommittedMemoryProvider; import com.oracle.svm.core.snippets.KnownIntrinsics; import jdk.graal.compiler.word.Word; @@ -265,7 +264,7 @@ private static boolean verifyObject(Object obj, AlignedHeader aChunk, UnalignedH assert aChunk.isNonNull() ^ uChunk.isNonNull(); HeapChunk.Header chunk = aChunk.isNonNull() ? aChunk : uChunk; - if (CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment()) { + if (HeapImpl.isImageHeapAligned() || !HeapImpl.getHeapImpl().isInImageHeap(obj)) { HeapChunk.Header enclosingHeapChunk = HeapChunk.getEnclosingHeapChunk(obj); if (chunk.notEqual(enclosingHeapChunk)) { Log.log().string("Object ").zhex(ptr).string(" should have ").zhex(chunk).string(" as its enclosing chunk but getEnclosingHeapChunk returned ").zhex(enclosingHeapChunk).newline(); diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/UnalignedHeapChunk.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/UnalignedHeapChunk.java index d7d4002e3a9b..fab374bf0604 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/UnalignedHeapChunk.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/UnalignedHeapChunk.java @@ -34,7 +34,6 @@ import com.oracle.svm.core.config.ConfigurationValues; import com.oracle.svm.core.genscavenge.remset.RememberedSet; import com.oracle.svm.core.heap.ObjectVisitor; -import com.oracle.svm.core.os.CommittedMemoryProvider; import com.oracle.svm.core.util.UnsignedUtils; import jdk.graal.compiler.api.directives.GraalDirectives; @@ -131,7 +130,7 @@ public static UnalignedHeader getEnclosingChunk(Object obj) { @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) static UnalignedHeader getEnclosingChunkFromObjectPointer(Pointer ptr) { if (!GraalDirectives.inIntrinsic()) { - assert !HeapImpl.getHeapImpl().isInImageHeap(ptr) || CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment() : "can't be used because the image heap is unaligned"; + assert HeapImpl.isImageHeapAligned() || !HeapImpl.getHeapImpl().isInImageHeap(ptr) : "can't be used for the image heap because the image heap is not aligned to the chunk size"; } Pointer chunkPointer = ptr.subtract(getObjectStartOffset()); return (UnalignedHeader) chunkPointer; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java index 96a9f981fcf7..5915a3a0137d 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java @@ -96,11 +96,6 @@ public class LinuxImageHeapProvider extends AbstractImageHeapProvider { private static final int MAX_PATHLEN = 4096; - @Override - public boolean guaranteesHeapPreferredAddressSpaceAlignment() { - return true; - } - @Override @Uninterruptible(reason = "Called during isolate initialization.") public int initialize(Pointer reservedAddressSpace, UnsignedWord reservedSize, WordPointer basePointer, WordPointer endPointer) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Heap.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Heap.java index be8beb7ad1fc..67e0b9798627 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Heap.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Heap.java @@ -44,7 +44,6 @@ import com.oracle.svm.core.identityhashcode.IdentityHashCodeSupport; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.option.RuntimeOptionKey; -import com.oracle.svm.core.os.CommittedMemoryProvider; import jdk.graal.compiler.api.replacements.Fold; @@ -137,11 +136,7 @@ public void visitLoadedClasses(Consumer> visitor) { /** Reset the heap to the normal execution state. */ public abstract void endSafepoint(); - /** - * Returns a multiple to which the heap address space should be aligned to at runtime. - * - * @see CommittedMemoryProvider#guaranteesHeapPreferredAddressSpaceAlignment() - */ + /** Returns a multiple to which the heap address space should be aligned to at runtime. */ @Fold public abstract int getPreferredAddressSpaceAlignment(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCommittedMemoryProvider.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCommittedMemoryProvider.java index 1ed8a150a708..42ee36657aec 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCommittedMemoryProvider.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCommittedMemoryProvider.java @@ -45,12 +45,6 @@ import jdk.graal.compiler.api.replacements.Fold; public abstract class AbstractCommittedMemoryProvider implements CommittedMemoryProvider { - @Fold - @Override - public boolean guaranteesHeapPreferredAddressSpaceAlignment() { - return SubstrateOptions.SpawnIsolates.getValue() && ImageHeapProvider.get().guaranteesHeapPreferredAddressSpaceAlignment(); - } - @Uninterruptible(reason = "Still being initialized.") protected static int protectSingleIsolateImageHeap() { assert !SubstrateOptions.SpawnIsolates.getValue() : "Must be handled by ImageHeapProvider when SpawnIsolates is enabled"; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCopyingImageHeapProvider.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCopyingImageHeapProvider.java index a5afcd749809..1dd8ca8906b4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCopyingImageHeapProvider.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCopyingImageHeapProvider.java @@ -44,11 +44,6 @@ import com.oracle.svm.core.util.UnsignedUtils; public abstract class AbstractCopyingImageHeapProvider extends AbstractImageHeapProvider { - @Override - public boolean guaranteesHeapPreferredAddressSpaceAlignment() { - return true; - } - @Override @Uninterruptible(reason = "Called during isolate initialization.") public int initialize(Pointer reservedAddressSpace, UnsignedWord reservedSize, WordPointer basePointer, WordPointer endPointer) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/CommittedMemoryProvider.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/CommittedMemoryProvider.java index 47074c1c7f4a..41d3f8cf1ebf 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/CommittedMemoryProvider.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/CommittedMemoryProvider.java @@ -32,7 +32,6 @@ import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.c.function.CEntryPointCreateIsolateParameters; -import com.oracle.svm.core.heap.Heap; import jdk.graal.compiler.api.replacements.Fold; @@ -46,14 +45,6 @@ static CommittedMemoryProvider get() { return ImageSingletons.lookup(CommittedMemoryProvider.class); } - /** - * Returns whether this provider will always guarantee a heap address space alignment of - * {@link Heap#getPreferredAddressSpaceAlignment()} at image runtime, which may also depend on - * {@link ImageHeapProvider#guaranteesHeapPreferredAddressSpaceAlignment()}. - */ - @Fold - boolean guaranteesHeapPreferredAddressSpaceAlignment(); - /** * Performs initializations for the current isolate, before any other methods of this * interface may be called. diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/ImageHeapProvider.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/ImageHeapProvider.java index a20f821b0ec0..118ea194d590 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/ImageHeapProvider.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/ImageHeapProvider.java @@ -56,14 +56,6 @@ static ImageHeapProvider get() { return ImageSingletons.lookup(ImageHeapProvider.class); } - /** - * Returns whether this provider, when not already supplied a reserved address space by - * {@link CommittedMemoryProvider}, will always ensure a heap address space alignment of - * {@link Heap#getPreferredAddressSpaceAlignment()} at image runtime. - */ - @Fold - boolean guaranteesHeapPreferredAddressSpaceAlignment(); - /** * Creates a new instance of the image heap. *