author | pliden |
Tue, 10 Sep 2019 11:11:31 +0200 | |
changeset 58066 | 8407928b9fe5 |
parent 54834 | 39ba09047e19 |
child 58237 | 944b58cbaf93 |
permissions | -rw-r--r-- |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
1 |
/* |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
4 |
* |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
8 |
* |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
13 |
* accompanied this code). |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
14 |
* |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
18 |
* |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
21 |
* questions. |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
22 |
*/ |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
23 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
25 |
#include "gc/z/zHeap.inline.hpp" |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
26 |
#include "gc/z/zUncommitter.hpp" |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
27 |
#include "runtime/mutexLocker.hpp" |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
28 |
#include "runtime/os.hpp" |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
29 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
30 |
ZUncommitter::ZUncommitter() : |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
31 |
_monitor(Monitor::leaf, "ZUncommitter", false, Monitor::_safepoint_check_never), |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
32 |
_stop(false) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
33 |
set_name("ZUncommitter"); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
34 |
create_and_start(); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
35 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
36 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
37 |
bool ZUncommitter::idle(uint64_t timeout) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
38 |
// Idle for at least one second |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
39 |
const uint64_t expires = os::elapsedTime() + MAX2(timeout, 1ul); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
40 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
41 |
for (;;) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
42 |
// We might wake up spuriously from wait, so always recalculate |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
43 |
// the timeout after a wakeup to see if we need to wait again. |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
44 |
const uint64_t now = os::elapsedTime(); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
45 |
const uint64_t remaining = expires - MIN2(expires, now); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
46 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
47 |
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
48 |
if (remaining > 0 && !_stop) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
49 |
ml.wait(remaining * MILLIUNITS); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
50 |
} else { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
51 |
return !_stop; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
52 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
53 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
54 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
55 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
56 |
void ZUncommitter::run_service() { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
57 |
for (;;) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
58 |
// Try uncommit unused memory |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
59 |
const uint64_t timeout = ZHeap::heap()->uncommit(ZUncommitDelay); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
60 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
61 |
log_trace(gc, heap)("Uncommit Timeout: " UINT64_FORMAT "s", timeout); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
62 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
63 |
// Idle until next attempt |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
64 |
if (!idle(timeout)) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
65 |
return; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
66 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
67 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
68 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
69 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
70 |
void ZUncommitter::stop_service() { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
71 |
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
72 |
_stop = true; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
73 |
ml.notify(); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
diff
changeset
|
74 |
} |