author | pliden |
Thu, 03 Oct 2019 10:54:18 +0200 | |
changeset 58452 | 61437e06602a |
parent 58287 | a7f16447085e |
child 58679 | 9c3209ff7550 |
child 58787 | 32d39d9525f9 |
permissions | -rw-r--r-- |
58287
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
1 |
/* |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
4 |
* |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
8 |
* |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
13 |
* accompanied this code). |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
14 |
* |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
18 |
* |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
21 |
* questions. |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
22 |
*/ |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
23 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
25 |
#include "gc/z/zAddress.inline.hpp" |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
26 |
#include "gc/z/zVirtualMemory.hpp" |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
27 |
#include "logging/log.hpp" |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
28 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
29 |
#include <sys/mman.h> |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
30 |
#include <sys/types.h> |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
31 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
32 |
static void unmap(uintptr_t start, size_t size) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
33 |
const int res = munmap((void*)start, size); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
34 |
assert(res == 0, "Failed to unmap memory"); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
35 |
} |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
36 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
37 |
static bool map(uintptr_t start, size_t size) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
38 |
const void* const res = mmap((void*)start, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
39 |
if (res == MAP_FAILED) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
40 |
// Failed to reserve memory |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
41 |
return false; |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
42 |
} |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
43 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
44 |
if ((uintptr_t)res != start) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
45 |
// Failed to reserve memory at the requested address |
58452
61437e06602a
8231774: ZGC: ZVirtualMemoryManager unmaps incorrect address
pliden
parents:
58287
diff
changeset
|
46 |
unmap((uintptr_t)res, size); |
58287
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
47 |
return false; |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
48 |
} |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
49 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
50 |
// Success |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
51 |
return true; |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
52 |
} |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
53 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
54 |
bool ZVirtualMemoryManager::reserve_platform(uintptr_t start, size_t size) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
55 |
// Reserve address views |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
56 |
const uintptr_t marked0 = ZAddress::marked0(start); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
57 |
const uintptr_t marked1 = ZAddress::marked1(start); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
58 |
const uintptr_t remapped = ZAddress::remapped(start); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
59 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
60 |
if (!map(marked0, size)) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
61 |
return false; |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
62 |
} |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
63 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
64 |
if (!map(marked1, size)) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
65 |
unmap(marked0, size); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
66 |
return false; |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
67 |
} |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
68 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
69 |
if (!map(remapped, size)) { |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
70 |
unmap(marked0, size); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
71 |
unmap(marked1, size); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
72 |
return false; |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
73 |
} |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
74 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
75 |
// Register address views with native memory tracker |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
76 |
nmt_reserve(marked0, size); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
77 |
nmt_reserve(marked1, size); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
78 |
nmt_reserve(remapped, size); |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
79 |
|
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
80 |
return true; |
a7f16447085e
8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents:
diff
changeset
|
81 |
} |