author | stuefe |
Tue, 26 Nov 2019 16:21:29 +0100 | |
branch | stuefe-new-metaspace-branch |
changeset 59272 | 54750b448264 |
parent 57975 | a333fdeb8de0 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52421
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
4 |
* |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
8 |
* |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
13 |
* accompanied this code). |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
14 |
* |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
18 |
* |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
21 |
* questions. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
22 |
* |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
23 |
*/ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
24 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
25 |
#ifndef SHARE_GC_SHARED_OOPSTORAGE_HPP |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
26 |
#define SHARE_GC_SHARED_OOPSTORAGE_HPP |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
27 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
29 |
#include "oops/oop.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
30 |
#include "utilities/globalDefinitions.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
31 |
#include "utilities/macros.hpp" |
51511
eb8d5aeabab3
8209850: Allow NamedThreads to use GlobalCounter critical sections
kbarrett
parents:
50954
diff
changeset
|
32 |
#include "utilities/singleWriterSynchronizer.hpp" |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
33 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
34 |
class Mutex; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
35 |
class outputStream; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
36 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
37 |
// OopStorage supports management of off-heap references to objects allocated |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
38 |
// in the Java heap. An OopStorage object provides a set of Java object |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
39 |
// references (oop values), which clients refer to via oop* handles to the |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
40 |
// associated OopStorage entries. Clients allocate entries to create a |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
41 |
// (possibly weak) reference to a Java object, use that reference, and release |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
42 |
// the reference when no longer needed. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
43 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
44 |
// The garbage collector must know about all OopStorage objects and their |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
45 |
// reference strength. OopStorage provides the garbage collector with support |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
46 |
// for iteration over all the allocated entries. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
47 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
48 |
// There are several categories of interaction with an OopStorage object. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
49 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
50 |
// (1) allocation and release of entries, by the mutator or the VM. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
51 |
// (2) iteration by the garbage collector, possibly concurrent with mutator. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
52 |
// (3) iteration by other, non-GC, tools (only at safepoints). |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
53 |
// (4) cleanup of unused internal storage, possibly concurrent with mutator. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
54 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
55 |
// A goal of OopStorage is to make these interactions thread-safe, while |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
56 |
// minimizing potential lock contention issues within and between these |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
57 |
// categories. In particular, support for concurrent iteration by the garbage |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
58 |
// collector, under certain restrictions, is required. Further, it must not |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
59 |
// block nor be blocked by other operations for long periods. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
60 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
61 |
// Internally, OopStorage is a set of Block objects, from which entries are |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
62 |
// allocated and released. A block contains an oop[] and a bitmask indicating |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
63 |
// which entries are in use (have been allocated and not yet released). New |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
64 |
// blocks are constructed and added to the storage object when an entry |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
65 |
// allocation request is made and there are no blocks with unused entries. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
66 |
// Blocks may be removed and deleted when empty. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
67 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
68 |
// There are two important (and somewhat intertwined) protocols governing |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
69 |
// concurrent access to a storage object. These are the Concurrent Iteration |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
70 |
// Protocol and the Allocation Protocol. See the ParState class for a |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
71 |
// discussion of concurrent iteration and the management of thread |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
72 |
// interactions for this protocol. Similarly, see the allocate() function for |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
73 |
// a discussion of allocation. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
74 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
75 |
class OopStorage : public CHeapObj<mtGC> { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
76 |
public: |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
77 |
OopStorage(const char* name, Mutex* allocation_mutex, Mutex* active_mutex); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
78 |
~OopStorage(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
79 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
80 |
// These count and usage accessors are racy unless at a safepoint. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
81 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
82 |
// The number of allocated and not yet released entries. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
83 |
size_t allocation_count() const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
84 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
85 |
// The number of blocks of entries. Useful for sizing parallel iteration. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
86 |
size_t block_count() const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
87 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
88 |
// Total number of blocks * memory allocation per block, plus |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
89 |
// bookkeeping overhead, including this storage object. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
90 |
size_t total_memory_usage() const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
91 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
92 |
enum EntryStatus { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
93 |
INVALID_ENTRY, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
94 |
UNALLOCATED_ENTRY, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
95 |
ALLOCATED_ENTRY |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
96 |
}; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
97 |
|
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
98 |
// Locks _allocation_mutex. |
48808
2b0b7f222800
8195690: JNI GetObjectRefType doesn't handle NULL
kbarrett
parents:
48806
diff
changeset
|
99 |
// precondition: ptr != NULL. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
100 |
EntryStatus allocation_status(const oop* ptr) const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
101 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
102 |
// Allocates and returns a new entry. Returns NULL if memory allocation |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
103 |
// failed. Locks _allocation_mutex. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
104 |
// postcondition: *result == NULL. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
105 |
oop* allocate(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
106 |
|
48886 | 107 |
// Deallocates ptr. No locking. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
108 |
// precondition: ptr is a valid allocated entry. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
109 |
// precondition: *ptr == NULL. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
110 |
void release(const oop* ptr); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
111 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
112 |
// Releases all the ptrs. Possibly faster than individual calls to |
48886 | 113 |
// release(oop*). Best if ptrs is sorted by address. No locking. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
114 |
// precondition: All elements of ptrs are valid allocated entries. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
115 |
// precondition: *ptrs[i] == NULL, for i in [0,size). |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
116 |
void release(const oop* const* ptrs, size_t size); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
117 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
118 |
// Applies f to each allocated entry's location. f must be a function or |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
119 |
// function object. Assume p is either a const oop* or an oop*, depending |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
120 |
// on whether the associated storage is const or non-const, respectively. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
121 |
// Then f(p) must be a valid expression. The result of invoking f(p) must |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
122 |
// be implicitly convertible to bool. Iteration terminates and returns |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
123 |
// false if any invocation of f returns false. Otherwise, the result of |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
124 |
// iteration is true. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
125 |
// precondition: at safepoint. |
48816
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
126 |
template<typename F> inline bool iterate_safepoint(F f); |
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
127 |
template<typename F> inline bool iterate_safepoint(F f) const; |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
128 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
129 |
// oops_do and weak_oops_do are wrappers around iterate_safepoint, providing |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
130 |
// an adaptation layer allowing the use of existing is-alive closures and |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
131 |
// OopClosures. Assume p is either const oop* or oop*, depending on whether |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
132 |
// the associated storage is const or non-const, respectively. Then |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
133 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
134 |
// - closure->do_oop(p) must be a valid expression whose value is ignored. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
135 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
136 |
// - is_alive->do_object_b(*p) must be a valid expression whose value is |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
137 |
// convertible to bool. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
138 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
139 |
// For weak_oops_do, if *p == NULL then neither is_alive nor closure will be |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
140 |
// invoked for p. If is_alive->do_object_b(*p) is false, then closure will |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
141 |
// not be invoked on p, and *p will be set to NULL. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
142 |
|
48816
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
143 |
template<typename Closure> inline void oops_do(Closure* closure); |
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
144 |
template<typename Closure> inline void oops_do(Closure* closure) const; |
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
145 |
template<typename Closure> inline void weak_oops_do(Closure* closure); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
146 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
147 |
template<typename IsAliveClosure, typename Closure> |
48816
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
148 |
inline void weak_oops_do(IsAliveClosure* is_alive, Closure* closure); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
149 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
150 |
// Parallel iteration is for the exclusive use of the GC. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
151 |
// Other clients must use serial iteration. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
152 |
template<bool concurrent, bool is_const> class ParState; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
153 |
|
52421
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
154 |
// Service thread cleanup support. |
55569
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
155 |
|
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
156 |
// Called by the service thread to process any pending cleanups for this |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
157 |
// storage object. Drains the _deferred_updates list, and deletes empty |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
158 |
// blocks. Stops deleting if there is an in-progress concurrent |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
159 |
// iteration. Locks both the _allocation_mutex and the _active_mutex, and |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
160 |
// may safepoint. Deletion may be throttled, with only some available |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
161 |
// work performed, in order to allow other Service thread subtasks to run. |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
162 |
// Returns true if there may be more work to do, false if nothing to do. |
52421
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
163 |
bool delete_empty_blocks(); |
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
164 |
|
55569
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
165 |
// Called by safepoint cleanup to notify the service thread (via |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
166 |
// Service_lock) that there may be some OopStorage objects with pending |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
167 |
// cleanups to process. |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
168 |
static void trigger_cleanup_if_needed(); |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
169 |
|
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
170 |
// Called by the service thread (while holding Service_lock) to to test |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
171 |
// for pending cleanup requests, and resets the request state to allow |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
172 |
// recognition of new requests. Returns true if there was a pending |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
173 |
// request. |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
174 |
static bool has_cleanup_work_and_reset(); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
175 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
176 |
// Debugging and logging support. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
177 |
const char* name() const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
178 |
void print_on(outputStream* st) const PRODUCT_RETURN; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
179 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
180 |
// Provides access to storage internals, for unit testing. |
48806 | 181 |
// Declare, but not define, the public class OopStorage::TestAccess. |
182 |
// That class is defined as part of the unit-test. It "exports" the needed |
|
183 |
// private types by providing public typedefs for them. |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
184 |
class TestAccess; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
185 |
|
57975
a333fdeb8de0
8224214: [AIX] Remove support for legacy xlc compiler
mbaesken
parents:
55569
diff
changeset
|
186 |
private: |
49977
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
187 |
class Block; // Fixed-size array of oops, plus bookkeeping. |
50209
2fdce199fcb9
8202863: Rename OopStorage inner collection classes
kbarrett
parents:
49977
diff
changeset
|
188 |
class ActiveArray; // Array of Blocks, plus bookkeeping. |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
189 |
class AllocationListEntry; // Provides AllocationList links in a Block. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
190 |
|
49977
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
191 |
// Doubly-linked list of Blocks. |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
192 |
class AllocationList { |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
193 |
const Block* _head; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
194 |
const Block* _tail; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
195 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
196 |
// Noncopyable. |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
197 |
AllocationList(const AllocationList&); |
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
198 |
AllocationList& operator=(const AllocationList&); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
199 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
200 |
public: |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
201 |
AllocationList(); |
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
202 |
~AllocationList(); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
203 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
204 |
Block* head(); |
49977
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
205 |
Block* tail(); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
206 |
const Block* chead() const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
207 |
const Block* ctail() const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
208 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
209 |
Block* prev(Block& block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
210 |
Block* next(Block& block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
211 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
212 |
const Block* prev(const Block& block) const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
213 |
const Block* next(const Block& block) const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
214 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
215 |
void push_front(const Block& block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
216 |
void push_back(const Block& block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
217 |
void unlink(const Block& block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
218 |
}; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
219 |
|
48806 | 220 |
private: |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
221 |
const char* _name; |
50209
2fdce199fcb9
8202863: Rename OopStorage inner collection classes
kbarrett
parents:
49977
diff
changeset
|
222 |
ActiveArray* _active_array; |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
223 |
AllocationList _allocation_list; |
48886 | 224 |
Block* volatile _deferred_updates; |
50954
f85092465b0c
8204834: Fix confusing "allocate" naming in OopStorage
kbarrett
parents:
50513
diff
changeset
|
225 |
Mutex* _allocation_mutex; |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
226 |
Mutex* _active_mutex; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
227 |
|
49977
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
228 |
// Volatile for racy unlocked accesses. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
229 |
volatile size_t _allocation_count; |
49977
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
230 |
|
50332
d0d933d61610
8204179: [BACKOUT] OopStorage should use GlobalCounter
kbarrett
parents:
50300
diff
changeset
|
231 |
// Protection for _active_array. |
51511
eb8d5aeabab3
8209850: Allow NamedThreads to use GlobalCounter critical sections
kbarrett
parents:
50954
diff
changeset
|
232 |
mutable SingleWriterSynchronizer _protect_active; |
50332
d0d933d61610
8204179: [BACKOUT] OopStorage should use GlobalCounter
kbarrett
parents:
50300
diff
changeset
|
233 |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
234 |
// mutable because this gets set even for const iteration. |
52037
d2a6c3cbc110
8211718: Supporting multiple concurrent OopStorage iterators
eosterlund
parents:
51511
diff
changeset
|
235 |
mutable int _concurrent_iteration_count; |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
236 |
|
55569
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
53244
diff
changeset
|
237 |
volatile bool _needs_cleanup; |
52421
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
238 |
|
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
239 |
bool try_add_block(); |
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
240 |
Block* block_for_allocation(); |
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
241 |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
242 |
Block* find_block_or_null(const oop* ptr) const; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
243 |
void delete_empty_block(const Block& block); |
48886 | 244 |
bool reduce_deferred_updates(); |
52421
3021c1ad958b
8210986: Add OopStorage cleanup to ServiceThread
kbarrett
parents:
52037
diff
changeset
|
245 |
void record_needs_cleanup(); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
246 |
|
49977
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
247 |
// Managing _active_array. |
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
248 |
bool expand_active_array(); |
50209
2fdce199fcb9
8202863: Rename OopStorage inner collection classes
kbarrett
parents:
49977
diff
changeset
|
249 |
void replace_active_array(ActiveArray* new_array); |
2fdce199fcb9
8202863: Rename OopStorage inner collection classes
kbarrett
parents:
49977
diff
changeset
|
250 |
ActiveArray* obtain_active_array() const; |
2fdce199fcb9
8202863: Rename OopStorage inner collection classes
kbarrett
parents:
49977
diff
changeset
|
251 |
void relinquish_block_array(ActiveArray* array) const; |
49977
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
252 |
class WithActiveArray; // RAII helper for active array access. |
9f758f0bb058
8200557: OopStorage parallel iteration scales poorly
kbarrett
parents:
49711
diff
changeset
|
253 |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
254 |
template<typename F, typename Storage> |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
255 |
static bool iterate_impl(F f, Storage* storage); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
256 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
257 |
// Implementation support for parallel iteration |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
258 |
class BasicParState; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
259 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
260 |
// Wrapper for OopClosure-style function, so it can be used with |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
261 |
// iterate. Assume p is of type oop*. Then cl->do_oop(p) must be a |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
262 |
// valid expression whose value may be ignored. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
263 |
template<typename Closure> class OopFn; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
264 |
template<typename Closure> static OopFn<Closure> oop_fn(Closure* cl); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
265 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
266 |
// Wrapper for BoolObjectClosure + iteration handler pair, so they |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
267 |
// can be used with iterate. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
268 |
template<typename IsAlive, typename F> class IfAliveFn; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
269 |
template<typename IsAlive, typename F> |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
270 |
static IfAliveFn<IsAlive, F> if_alive_fn(IsAlive* is_alive, F f); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
271 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
272 |
// Wrapper for iteration handler, automatically skipping NULL entries. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
273 |
template<typename F> class SkipNullFn; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
274 |
template<typename F> static SkipNullFn<F> skip_null_fn(F f); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
275 |
}; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
276 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52421
diff
changeset
|
277 |
#endif // SHARE_GC_SHARED_OOPSTORAGE_HPP |