1 | /* |
2 | * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | * |
5 | * This code is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 2 only, as |
7 | * published by the Free Software Foundation. |
8 | * |
9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * version 2 for more details (a copy is included in the LICENSE file that |
13 | * accompanied this code). |
14 | * |
15 | * You should have received a copy of the GNU General Public License version |
16 | * 2 along with this work; if not, write to the Free Software Foundation, |
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | * |
23 | */ |
24 | |
25 | #ifndef SHARE_GC_SHARED_SOFTREFPOLICY_HPP |
26 | #define SHARE_GC_SHARED_SOFTREFPOLICY_HPP |
27 | |
28 | #include "memory/allocation.hpp" |
29 | |
30 | class SoftRefPolicy { |
31 | private: |
32 | // Set to true when policy wants soft refs cleared. |
33 | // Reset to false by gc after it clears all soft refs. |
34 | bool _should_clear_all_soft_refs; |
35 | |
36 | // Set to true by the GC if the just-completed gc cleared all |
37 | // softrefs. This is set to true whenever a gc clears all softrefs, and |
38 | // set to false each time gc returns to the mutator. For example, in the |
39 | // ParallelScavengeHeap case the latter would be done toward the end of |
40 | // mem_allocate() where it returns op.result() |
41 | bool _all_soft_refs_clear; |
42 | |
43 | public: |
44 | SoftRefPolicy(); |
45 | |
46 | bool should_clear_all_soft_refs() { return _should_clear_all_soft_refs; } |
47 | void set_should_clear_all_soft_refs(bool v) { _should_clear_all_soft_refs = v; } |
48 | // Returns the current value of _should_clear_all_soft_refs. |
49 | // _should_clear_all_soft_refs is set to false as a side effect. |
50 | bool use_should_clear_all_soft_refs(bool v); |
51 | bool all_soft_refs_clear() { return _all_soft_refs_clear; } |
52 | void set_all_soft_refs_clear(bool v) { _all_soft_refs_clear = v; } |
53 | |
54 | // Called by the GC after Soft Refs have been cleared to indicate |
55 | // that the request in _should_clear_all_soft_refs has been fulfilled. |
56 | virtual void cleared_all_soft_refs(); |
57 | }; |
58 | |
59 | class ClearedAllSoftRefs : public StackObj { |
60 | bool _clear_all_soft_refs; |
61 | SoftRefPolicy* _soft_ref_policy; |
62 | public: |
63 | ClearedAllSoftRefs(bool clear_all_soft_refs, SoftRefPolicy* soft_ref_policy) : |
64 | _clear_all_soft_refs(clear_all_soft_refs), |
65 | _soft_ref_policy(soft_ref_policy) {} |
66 | |
67 | ~ClearedAllSoftRefs() { |
68 | if (_clear_all_soft_refs) { |
69 | _soft_ref_policy->cleared_all_soft_refs(); |
70 | } |
71 | } |
72 | |
73 | bool should_clear() { return _clear_all_soft_refs; } |
74 | }; |
75 | |
76 | #endif // SHARE_GC_SHARED_SOFTREFPOLICY_HPP |
77 | |