5454import com .oracle .svm .core .c .CGlobalDataFactory ;
5555import com .oracle .svm .core .feature .AutomaticallyRegisteredFeature ;
5656import com .oracle .svm .core .feature .InternalFeature ;
57- import com .oracle .svm .core .nmt .NativeMemoryTracking ;
58- import com .oracle .svm .core .nmt .NmtFlag ;
59- import com .oracle .svm .core .nmt .NmtVirtualMemoryData ;
6057import com .oracle .svm .core .os .VirtualMemoryProvider ;
6158import com .oracle .svm .core .posix .headers .Unistd ;
6259import com .oracle .svm .core .util .PointerUtils ;
@@ -113,23 +110,6 @@ public UnsignedWord getGranularity() {
113110 @ Override
114111 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
115112 public Pointer reserve (UnsignedWord nbytes , UnsignedWord alignment , boolean executable ) {
116- return reserve (nbytes , alignment , executable , WordFactory .nullPointer ());
117- }
118-
119- @ Override
120- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
121- public Pointer reserve (UnsignedWord nbytes , UnsignedWord alignment , boolean executable , NmtVirtualMemoryData nmtData ) {
122- return reserve0 (nbytes , alignment , executable , nmtData , NmtFlag .mtNone .ordinal ());
123- }
124-
125- @ Override
126- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
127- public Pointer reserve (UnsignedWord nbytes , UnsignedWord alignment , boolean executable , int flag ) {
128- return reserve0 (nbytes , alignment , executable , WordFactory .nullPointer (), flag );
129- }
130-
131- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
132- private Pointer reserve0 (UnsignedWord nbytes , UnsignedWord alignment , boolean executable , NmtVirtualMemoryData nmtData , int flag ) {
133113 if (nbytes .equal (0 )) {
134114 return WordFactory .nullPointer ();
135115 }
@@ -148,56 +128,25 @@ private Pointer reserve0(UnsignedWord nbytes, UnsignedWord alignment, boolean ex
148128 return nullPointer ();
149129 }
150130 if (!customAlignment ) {
151- if (nmtData .isNull ()) {
152- NativeMemoryTracking .recordReserve (mappingSize , flag );
153- } else {
154- nmtData .setReserved (nmtData .getReserved ().add (mappingSize ));
155- }
156131 return mappingBegin ;
157132 }
158- UnsignedWord unmappedSize = WordFactory .zero ();
159133 Pointer begin = PointerUtils .roundUp (mappingBegin , alignment );
160134 UnsignedWord clippedBegin = begin .subtract (mappingBegin );
161135 if (clippedBegin .aboveOrEqual (granularity )) {
162- UnsignedWord unmapSize = UnsignedUtils .roundDown (clippedBegin , granularity );
163- munmap (mappingBegin , unmapSize );
164- unmappedSize .add (unmapSize );
136+ munmap (mappingBegin , UnsignedUtils .roundDown (clippedBegin , granularity ));
165137 }
166138 Pointer mappingEnd = mappingBegin .add (mappingSize );
167139 UnsignedWord clippedEnd = mappingEnd .subtract (begin .add (nbytes ));
168140 if (clippedEnd .aboveOrEqual (granularity )) {
169141 UnsignedWord rounded = UnsignedUtils .roundDown (clippedEnd , granularity );
170142 munmap (mappingEnd .subtract (rounded ), rounded );
171- unmappedSize .add (rounded );
172- }
173- if (nmtData .isNull ()) {
174- NativeMemoryTracking .recordReserve (mappingSize .subtract (unmappedSize ), flag );
175- } else {
176- nmtData .setReserved (nmtData .getReserved ().add (mappingSize .subtract (unmappedSize )));
177143 }
178144 return begin ;
179145 }
180146
181147 @ Override
182148 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
183149 public Pointer mapFile (PointerBase start , UnsignedWord nbytes , WordBase fileHandle , UnsignedWord offset , int access ) {
184- return mapFile (start , nbytes , fileHandle , offset , access , WordFactory .nullPointer ());
185- }
186-
187- @ Override
188- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
189- public Pointer mapFile (PointerBase start , UnsignedWord nbytes , WordBase fileHandle , UnsignedWord offset , int access , NmtVirtualMemoryData nmtData ) {
190- return mapFile0 (start , nbytes , fileHandle , offset , access , nmtData , NmtFlag .mtNone .ordinal ());
191- }
192-
193- @ Override
194- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
195- public Pointer mapFile (PointerBase start , UnsignedWord nbytes , WordBase fileHandle , UnsignedWord offset , int access , int flag ) {
196- return mapFile0 (start , nbytes , fileHandle , offset , access , WordFactory .nullPointer (), flag );
197- }
198-
199- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
200- private Pointer mapFile0 (PointerBase start , UnsignedWord nbytes , WordBase fileHandle , UnsignedWord offset , int access , NmtVirtualMemoryData nmtData , int flag ) {
201150 if ((start .isNonNull () && !isAligned (start )) || nbytes .equal (0 )) {
202151 return WordFactory .nullPointer ();
203152 }
@@ -208,33 +157,12 @@ private Pointer mapFile0(PointerBase start, UnsignedWord nbytes, WordBase fileHa
208157 }
209158 int fd = (int ) fileHandle .rawValue ();
210159 Pointer result = mmap (start , nbytes , accessAsProt (access ), flags , fd , offset .rawValue ());
211- if (result .notEqual (MAP_FAILED ())) {
212- commitAndMaybeReserve (start , nbytes , nmtData , flag );
213- return result ;
214- }
215- return WordFactory .nullPointer ();
160+ return result .notEqual (MAP_FAILED ()) ? result : WordFactory .nullPointer ();
216161 }
217162
218163 @ Override
219164 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
220165 public Pointer commit (PointerBase start , UnsignedWord nbytes , int access ) {
221- return commit (start , nbytes , access , WordFactory .nullPointer ());
222- }
223-
224- @ Override
225- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
226- public Pointer commit (PointerBase start , UnsignedWord nbytes , int access , NmtVirtualMemoryData nmtData ) {
227- return commit0 (start , nbytes , access , nmtData , NmtFlag .mtNone .ordinal ());
228- }
229-
230- @ Override
231- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
232- public Pointer commit (PointerBase start , UnsignedWord nbytes , int access , int flag ) {
233- return commit0 (start , nbytes , access , WordFactory .nullPointer (), flag );
234- }
235-
236- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
237- private Pointer commit0 (PointerBase start , UnsignedWord nbytes , int access , NmtVirtualMemoryData nmtData , int flag ) {
238166 if ((start .isNonNull () && !isAligned (start )) || nbytes .equal (0 )) {
239167 return WordFactory .nullPointer ();
240168 }
@@ -249,27 +177,7 @@ private Pointer commit0(PointerBase start, UnsignedWord nbytes, int access, NmtV
249177 }
250178 /* The memory returned by mmap is guaranteed to be zeroed. */
251179 final Pointer result = mmap (start , nbytes , accessAsProt (access ), flags , NO_FD , NO_FD_OFFSET );
252- if (result .notEqual (MAP_FAILED ())) {
253- commitAndMaybeReserve (start , nbytes , nmtData , flag );
254- return result ;
255- }
256- return nullPointer ();
257- }
258-
259- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
260- private void commitAndMaybeReserve (PointerBase start , UnsignedWord nbytes , NmtVirtualMemoryData nmtData , int flag ) {
261- if (nmtData .isNull ()) {
262- NativeMemoryTracking .recordCommit (nbytes , flag );
263- } else {
264- nmtData .setCommitted (nmtData .getCommitted ().add (nbytes ));
265- }
266- if (start .isNull ()) {
267- if (nmtData .isNull ()) {
268- NativeMemoryTracking .recordReserve (nbytes , flag );
269- } else {
270- nmtData .setReserved (nmtData .getReserved ().add (nbytes ));
271- }
272- }
180+ return result .notEqual (MAP_FAILED ()) ? result : nullPointer ();
273181 }
274182
275183 @ Override
@@ -285,41 +193,25 @@ public int protect(PointerBase start, UnsignedWord nbytes, int access) {
285193 @ Override
286194 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
287195 public int uncommit (PointerBase start , UnsignedWord nbytes ) {
288- return uncommit (start , nbytes , NmtFlag .mtNone .ordinal ());
289- }
290-
291- @ Override
292- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
293- public int uncommit (PointerBase start , UnsignedWord nbytes , int flag ) {
294196 if (start .isNull () || !isAligned (start ) || nbytes .equal (0 )) {
295197 return -1 ;
296198 }
297- NativeMemoryTracking . recordUncommit ( nbytes , flag );
199+
298200 final Pointer result = mmap (start , nbytes , PROT_NONE (), MAP_FIXED () | MAP_ANON () | MAP_PRIVATE () | MAP_NORESERVE (), NO_FD , NO_FD_OFFSET );
299201 return result .notEqual (MAP_FAILED ()) ? 0 : -1 ;
300202 }
301203
302204 @ Override
303205 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
304206 public int free (PointerBase start , UnsignedWord nbytes ) {
305- return free (start , nbytes , NmtFlag .mtNone .ordinal ());
306- }
307-
308- @ Override
309- @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
310- public int free (PointerBase start , UnsignedWord nbytes , int flag ) {
311207 if (start .isNull () || !isAligned (start ) || nbytes .equal (0 )) {
312208 return -1 ;
313209 }
314210
315211 UnsignedWord granularity = getGranularity ();
316212 Pointer mappingBegin = PointerUtils .roundDown (start , granularity );
317213 UnsignedWord mappingSize = UnsignedUtils .roundUp (nbytes , granularity );
318- int ret = munmap (mappingBegin , mappingSize );
319- if (ret == 0 ) {
320- NativeMemoryTracking .recordFree (mappingSize , flag );
321- }
322- return ret ;
214+ return munmap (mappingBegin , mappingSize );
323215 }
324216
325217 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
0 commit comments