Skip to content

Commit ad3d146

Browse files
christianhaeubllewurm
authored andcommitted
CommittedMemoryProvider cleanups.
1 parent 997f622 commit ad3d146

File tree

3 files changed

+35
-73
lines changed

3 files changed

+35
-73
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCommittedMemoryProvider.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,6 @@ public boolean guaranteesHeapPreferredAddressSpaceAlignment() {
4848
return SubstrateOptions.SpawnIsolates.getValue() && ImageHeapProvider.get().guaranteesHeapPreferredAddressSpaceAlignment();
4949
}
5050

51-
@Override
52-
public Pointer allocateAlignedChunk(UnsignedWord nbytes, UnsignedWord alignment) {
53-
return allocate(nbytes, alignment, false);
54-
}
55-
56-
@Override
57-
public Pointer allocateUnalignedChunk(UnsignedWord nbytes) {
58-
return allocate(nbytes, CommittedMemoryProvider.UNALIGNED, false);
59-
}
60-
61-
@Override
62-
public Pointer allocateExecutableMemory(UnsignedWord nbytes, UnsignedWord alignment) {
63-
return allocate(nbytes, alignment, true);
64-
}
65-
66-
@Override
67-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
68-
public void freeAlignedChunk(PointerBase start, UnsignedWord nbytes, UnsignedWord alignment) {
69-
free(start, nbytes, alignment, false);
70-
}
71-
72-
@Override
73-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
74-
public void freeUnalignedChunk(PointerBase start, UnsignedWord nbytes) {
75-
free(start, nbytes, CommittedMemoryProvider.UNALIGNED, false);
76-
}
77-
78-
@Override
79-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
80-
public void freeExecutableMemory(PointerBase start, UnsignedWord nbytes, UnsignedWord alignment) {
81-
free(start, nbytes, alignment, true);
82-
}
83-
8451
@Uninterruptible(reason = "Still being initialized.")
8552
protected static int protectSingleIsolateImageHeap() {
8653
assert !SubstrateOptions.SpawnIsolates.getValue() : "Must be handled by ImageHeapProvider when SpawnIsolates is enabled";

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/CommittedMemoryProvider.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.util.EnumSet;
2828

29-
import com.oracle.svm.core.util.VMError;
3029
import org.graalvm.compiler.api.replacements.Fold;
3130
import org.graalvm.nativeimage.ImageSingletons;
3231
import org.graalvm.nativeimage.c.type.WordPointer;
@@ -90,22 +89,6 @@ default UnsignedWord getGranularity() {
9089
return VirtualMemoryProvider.get().getGranularity();
9190
}
9291

93-
/**
94-
* Allocate a block of committed memory.
95-
*
96-
* @param nbytes The number of bytes to allocate, which is rounded up to the next multiple of
97-
* the {@linkplain #getGranularity() granularity} if required.
98-
* @param alignment The required alignment of the block start, or {@link #UNALIGNED}.
99-
* @param executable Whether the block must be executable.
100-
* @return The start of the allocated block, or {@link WordFactory#nullPointer()} in case of an
101-
* error.
102-
*/
103-
default Pointer allocate(UnsignedWord nbytes, UnsignedWord alignment, boolean executable) {
104-
// We need this default method temporarily so that we can remove the methods allocate and
105-
// free from all subclasses in GR-34236.
106-
throw VMError.shouldNotReachHere("Subclasses must overwrite this method");
107-
}
108-
10992
Pointer allocateAlignedChunk(UnsignedWord nbytes, UnsignedWord alignment);
11093

11194
Pointer allocateUnalignedChunk(UnsignedWord nbytes);
@@ -118,23 +101,6 @@ default Pointer allocate(UnsignedWord nbytes, UnsignedWord alignment, boolean ex
118101
*/
119102
boolean areUnalignedChunksZeroed();
120103

121-
/**
122-
* Release a block of committed memory that was allocated with {@link #allocate}, requiring the
123-
* exact same parameter values that were originally passed to {@link #allocate}.
124-
*
125-
* @param start The start of the memory block, as returned by {@link #allocate}.
126-
* @param nbytes The originally requested size in bytes.
127-
* @param alignment The originally requested alignment.
128-
* @param executable Whether the block was requested to be executable.
129-
* @return true on success, or false otherwise.
130-
*/
131-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
132-
default boolean free(PointerBase start, UnsignedWord nbytes, UnsignedWord alignment, boolean executable) {
133-
// We need this default method temporarily so that we can remove the methods allocate and
134-
// free from all subclasses in GR-34236.
135-
throw VMError.shouldNotReachHere("Subclasses must overwrite this method");
136-
}
137-
138104
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
139105
void freeAlignedChunk(PointerBase start, UnsignedWord nbytes, UnsignedWord alignment);
140106

@@ -165,8 +131,8 @@ enum Access {
165131
}
166132

167133
/**
168-
* Change access permissions for a block of committed memory that was allocated with
169-
* {@link #allocate}.
134+
* Change access permissions for a block of committed memory that was allocated with one of the
135+
* allocation methods.
170136
*
171137
* @param start The start of the address range to be protected, which must be a multiple of the
172138
* {@linkplain #getGranularity() granularity}.

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/OSCommittedMemoryProvider.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,21 @@ public int tearDown() {
7777
}
7878

7979
@Override
80-
public Pointer allocate(UnsignedWord size, UnsignedWord alignment, boolean executable) {
80+
public Pointer allocateAlignedChunk(UnsignedWord nbytes, UnsignedWord alignment) {
81+
return allocate(nbytes, alignment, false);
82+
}
83+
84+
@Override
85+
public Pointer allocateUnalignedChunk(UnsignedWord nbytes) {
86+
return allocate(nbytes, WordFactory.unsigned(1), false);
87+
}
88+
89+
@Override
90+
public Pointer allocateExecutableMemory(UnsignedWord nbytes, UnsignedWord alignment) {
91+
return allocate(nbytes, alignment, true);
92+
}
93+
94+
private Pointer allocate(UnsignedWord size, UnsignedWord alignment, boolean executable) {
8195
int access = VirtualMemoryProvider.Access.READ | VirtualMemoryProvider.Access.WRITE;
8296
if (executable) {
8397
access |= VirtualMemoryProvider.Access.EXECUTE;
@@ -108,12 +122,27 @@ public boolean areUnalignedChunksZeroed() {
108122

109123
@Override
110124
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
111-
public boolean free(PointerBase start, UnsignedWord nbytes, UnsignedWord alignment, boolean executable) {
125+
public void freeAlignedChunk(PointerBase start, UnsignedWord nbytes, UnsignedWord alignment) {
126+
free(start, nbytes);
127+
}
128+
129+
@Override
130+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
131+
public void freeUnalignedChunk(PointerBase start, UnsignedWord nbytes) {
132+
free(start, nbytes);
133+
}
134+
135+
@Override
136+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
137+
public void freeExecutableMemory(PointerBase start, UnsignedWord nbytes, UnsignedWord alignment) {
138+
free(start, nbytes);
139+
}
140+
141+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
142+
private void free(PointerBase start, UnsignedWord nbytes) {
112143
if (VirtualMemoryProvider.get().free(start, nbytes) == 0) {
113144
tracker.untrack(nbytes);
114-
return true;
115145
}
116-
return false;
117146
}
118147

119148
private final VirtualMemoryTracker tracker = new VirtualMemoryTracker();

0 commit comments

Comments
 (0)