author | kbarrett |
Mon, 29 Jan 2018 16:51:21 -0500 | |
changeset 48816 | 3495d6050efe |
parent 48808 | 2b0b7f222800 |
child 48886 | e1d09bd56d2d |
permissions | -rw-r--r-- |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
1 |
/* |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
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 |
#include "precompiled.hpp" |
48816
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
26 |
#include "gc/shared/oopStorage.inline.hpp" |
3495d6050efe
8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents:
48808
diff
changeset
|
27 |
#include "gc/shared/oopStorageParState.inline.hpp" |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
28 |
#include "logging/log.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
29 |
#include "memory/allocation.inline.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
30 |
#include "runtime/atomic.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
31 |
#include "runtime/handles.inline.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
32 |
#include "runtime/mutex.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
33 |
#include "runtime/mutexLocker.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
34 |
#include "runtime/orderAccess.inline.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
35 |
#include "runtime/safepoint.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
36 |
#include "runtime/stubRoutines.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
37 |
#include "utilities/align.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
38 |
#include "utilities/count_trailing_zeros.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
39 |
#include "utilities/debug.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
40 |
#include "utilities/globalDefinitions.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
41 |
#include "utilities/macros.hpp" |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
42 |
#include "utilities/ostream.hpp" |
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 |
OopStorage::BlockEntry::BlockEntry() : _prev(NULL), _next(NULL) {} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
45 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
46 |
OopStorage::BlockEntry::~BlockEntry() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
47 |
assert(_prev == NULL, "deleting attached block"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
48 |
assert(_next == NULL, "deleting attached block"); |
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 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
51 |
OopStorage::BlockList::BlockList(const BlockEntry& (*get_entry)(const Block& block)) : |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
52 |
_head(NULL), _tail(NULL), _get_entry(get_entry) |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
53 |
{} |
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 |
OopStorage::BlockList::~BlockList() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
56 |
// ~OopStorage() empties its lists before destroying them. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
57 |
assert(_head == NULL, "deleting non-empty block list"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
58 |
assert(_tail == NULL, "deleting non-empty block list"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
59 |
} |
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 |
void OopStorage::BlockList::push_front(const Block& block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
62 |
const Block* old = _head; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
63 |
if (old == NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
64 |
assert(_tail == NULL, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
65 |
_head = _tail = █ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
66 |
} else { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
67 |
_get_entry(block)._next = old; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
68 |
_get_entry(*old)._prev = █ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
69 |
_head = █ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
70 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
71 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
72 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
73 |
void OopStorage::BlockList::push_back(const Block& block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
74 |
const Block* old = _tail; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
75 |
if (old == NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
76 |
assert(_head == NULL, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
77 |
_head = _tail = █ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
78 |
} else { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
79 |
_get_entry(*old)._next = █ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
80 |
_get_entry(block)._prev = old; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
81 |
_tail = █ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
82 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
83 |
} |
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 |
void OopStorage::BlockList::unlink(const Block& block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
86 |
const BlockEntry& block_entry = _get_entry(block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
87 |
const Block* prev_blk = block_entry._prev; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
88 |
const Block* next_blk = block_entry._next; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
89 |
block_entry._prev = NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
90 |
block_entry._next = NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
91 |
if ((prev_blk == NULL) && (next_blk == NULL)) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
92 |
assert(_head == &block, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
93 |
assert(_tail == &block, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
94 |
_head = _tail = NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
95 |
} else if (prev_blk == NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
96 |
assert(_head == &block, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
97 |
_get_entry(*next_blk)._prev = NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
98 |
_head = next_blk; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
99 |
} else if (next_blk == NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
100 |
assert(_tail == &block, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
101 |
_get_entry(*prev_blk)._next = NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
102 |
_tail = prev_blk; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
103 |
} else { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
104 |
_get_entry(*next_blk)._prev = prev_blk; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
105 |
_get_entry(*prev_blk)._next = next_blk; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
106 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
107 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
108 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
109 |
// Blocks start with an array of BitsPerWord oop entries. That array |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
110 |
// is divided into conceptual BytesPerWord sections of BitsPerWord |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
111 |
// entries. Blocks are allocated aligned on section boundaries, for |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
112 |
// the convenience of mapping from an entry to the containing block; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
113 |
// see block_for_ptr(). Aligning on section boundary rather than on |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
114 |
// the full _data wastes a lot less space, but makes for a bit more |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
115 |
// work in block_for_ptr(). |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
116 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
117 |
const unsigned section_size = BitsPerByte; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
118 |
const unsigned section_count = BytesPerWord; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
119 |
const unsigned block_alignment = sizeof(oop) * section_size; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
120 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
121 |
// VS2013 warns (C4351) that elements of _data will be *correctly* default |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
122 |
// initialized, unlike earlier versions that *incorrectly* did not do so. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
123 |
#ifdef _WINDOWS |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
124 |
#pragma warning(push) |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
125 |
#pragma warning(disable: 4351) |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
126 |
#endif // _WINDOWS |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
127 |
OopStorage::Block::Block(const OopStorage* owner, void* memory) : |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
128 |
_data(), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
129 |
_allocated_bitmask(0), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
130 |
_owner(owner), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
131 |
_memory(memory), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
132 |
_active_entry(), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
133 |
_allocate_entry() |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
134 |
{ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
135 |
STATIC_ASSERT(_data_pos == 0); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
136 |
STATIC_ASSERT(section_size * section_count == ARRAY_SIZE(_data)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
137 |
assert(offset_of(Block, _data) == _data_pos, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
138 |
assert(owner != NULL, "NULL owner"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
139 |
assert(is_aligned(this, block_alignment), "misaligned block"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
140 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
141 |
#ifdef _WINDOWS |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
142 |
#pragma warning(pop) |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
143 |
#endif |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
144 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
145 |
OopStorage::Block::~Block() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
146 |
// Clear fields used by block_for_ptr and entry validation, which |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
147 |
// might help catch bugs. Volatile to prevent dead-store elimination. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
148 |
const_cast<uintx volatile&>(_allocated_bitmask) = 0; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
149 |
const_cast<OopStorage* volatile&>(_owner) = NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
150 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
151 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
152 |
const OopStorage::BlockEntry& OopStorage::Block::get_active_entry(const Block& block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
153 |
return block._active_entry; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
154 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
155 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
156 |
const OopStorage::BlockEntry& OopStorage::Block::get_allocate_entry(const Block& block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
157 |
return block._allocate_entry; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
158 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
159 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
160 |
size_t OopStorage::Block::allocation_size() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
161 |
// _data must be first member, so aligning Block aligns _data. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
162 |
STATIC_ASSERT(_data_pos == 0); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
163 |
return sizeof(Block) + block_alignment - sizeof(void*); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
164 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
165 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
166 |
size_t OopStorage::Block::allocation_alignment_shift() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
167 |
return exact_log2(block_alignment); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
168 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
169 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
170 |
inline bool is_full_bitmask(uintx bitmask) { return ~bitmask == 0; } |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
171 |
inline bool is_empty_bitmask(uintx bitmask) { return bitmask == 0; } |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
172 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
173 |
bool OopStorage::Block::is_full() const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
174 |
return is_full_bitmask(allocated_bitmask()); |
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 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
177 |
bool OopStorage::Block::is_empty() const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
178 |
return is_empty_bitmask(allocated_bitmask()); |
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 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
181 |
uintx OopStorage::Block::bitmask_for_entry(const oop* ptr) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
182 |
return bitmask_for_index(get_index(ptr)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
183 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
184 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
185 |
uintx OopStorage::Block::cmpxchg_allocated_bitmask(uintx new_value, uintx compare_value) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
186 |
return Atomic::cmpxchg(new_value, &_allocated_bitmask, compare_value); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
187 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
188 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
189 |
bool OopStorage::Block::contains(const oop* ptr) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
190 |
const oop* base = get_pointer(0); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
191 |
return (base <= ptr) && (ptr < (base + ARRAY_SIZE(_data))); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
192 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
193 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
194 |
unsigned OopStorage::Block::get_index(const oop* ptr) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
195 |
assert(contains(ptr), PTR_FORMAT " not in block " PTR_FORMAT, p2i(ptr), p2i(this)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
196 |
return static_cast<unsigned>(ptr - get_pointer(0)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
197 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
198 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
199 |
oop* OopStorage::Block::allocate() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
200 |
// Use CAS loop because release may change bitmask outside of lock. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
201 |
uintx allocated = allocated_bitmask(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
202 |
while (true) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
203 |
assert(!is_full_bitmask(allocated), "attempt to allocate from full block"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
204 |
unsigned index = count_trailing_zeros(~allocated); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
205 |
uintx new_value = allocated | bitmask_for_index(index); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
206 |
uintx fetched = cmpxchg_allocated_bitmask(new_value, allocated); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
207 |
if (fetched == allocated) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
208 |
return get_pointer(index); // CAS succeeded; return entry for index. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
209 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
210 |
allocated = fetched; // CAS failed; retry with latest value. |
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 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
213 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
214 |
OopStorage::Block* OopStorage::Block::new_block(const OopStorage* owner) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
215 |
// _data must be first member: aligning block => aligning _data. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
216 |
STATIC_ASSERT(_data_pos == 0); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
217 |
size_t size_needed = allocation_size(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
218 |
void* memory = NEW_C_HEAP_ARRAY_RETURN_NULL(char, size_needed, mtGC); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
219 |
if (memory == NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
220 |
return NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
221 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
222 |
void* block_mem = align_up(memory, block_alignment); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
223 |
assert(sizeof(Block) + pointer_delta(block_mem, memory, 1) <= size_needed, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
224 |
"allocated insufficient space for aligned block"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
225 |
return ::new (block_mem) Block(owner, memory); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
226 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
227 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
228 |
void OopStorage::Block::delete_block(const Block& block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
229 |
void* memory = block._memory; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
230 |
block.Block::~Block(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
231 |
FREE_C_HEAP_ARRAY(char, memory); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
232 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
233 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
234 |
// This can return a false positive if ptr is not contained by some |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
235 |
// block. For some uses, it is a precondition that ptr is valid, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
236 |
// e.g. contained in some block in owner's _active_list. Other uses |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
237 |
// require additional validation of the result. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
238 |
OopStorage::Block* |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
239 |
OopStorage::Block::block_for_ptr(const OopStorage* owner, const oop* ptr) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
240 |
assert(CanUseSafeFetchN(), "precondition"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
241 |
STATIC_ASSERT(_data_pos == 0); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
242 |
// Const-ness of ptr is not related to const-ness of containing block. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
243 |
// Blocks are allocated section-aligned, so get the containing section. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
244 |
oop* section_start = align_down(const_cast<oop*>(ptr), block_alignment); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
245 |
// Start with a guess that the containing section is the last section, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
246 |
// so the block starts section_count-1 sections earlier. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
247 |
oop* section = section_start - (section_size * (section_count - 1)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
248 |
// Walk up through the potential block start positions, looking for |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
249 |
// the owner in the expected location. If we're below the actual block |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
250 |
// start position, the value at the owner position will be some oop |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
251 |
// (possibly NULL), which can never match the owner. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
252 |
intptr_t owner_addr = reinterpret_cast<intptr_t>(owner); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
253 |
for (unsigned i = 0; i < section_count; ++i, section += section_size) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
254 |
Block* candidate = reinterpret_cast<Block*>(section); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
255 |
intptr_t* candidate_owner_addr |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
256 |
= reinterpret_cast<intptr_t*>(&candidate->_owner); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
257 |
if (SafeFetchN(candidate_owner_addr, 0) == owner_addr) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
258 |
return candidate; |
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 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
261 |
return NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
262 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
263 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
264 |
bool OopStorage::is_valid_block_locked_or_safepoint(const Block* check_block) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
265 |
assert_locked_or_safepoint(_allocate_mutex); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
266 |
// For now, simple linear search. Do something more clever if this |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
267 |
// is a performance bottleneck, particularly for allocation_status. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
268 |
for (const Block* block = _active_list.chead(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
269 |
block != NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
270 |
block = _active_list.next(*block)) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
271 |
if (check_block == block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
272 |
return true; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
273 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
274 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
275 |
return false; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
276 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
277 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
278 |
#ifdef ASSERT |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
279 |
void OopStorage::assert_at_safepoint() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
280 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
281 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
282 |
#endif // ASSERT |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
283 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
284 |
////////////////////////////////////////////////////////////////////////////// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
285 |
// Allocation |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
286 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
287 |
// Allocation involves the _allocate_list, which contains a subset of the |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
288 |
// blocks owned by a storage object. This is a doubly-linked list, linked |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
289 |
// through dedicated fields in the blocks. Full blocks are removed from this |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
290 |
// list, though they are still present in the _active_list. Empty blocks are |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
291 |
// kept at the end of the _allocate_list, to make it easy for empty block |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
292 |
// deletion to find them. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
293 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
294 |
// allocate(), release(), and delete_empty_blocks_concurrent() all lock the |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
295 |
// _allocate_mutex while performing any list modifications. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
296 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
297 |
// allocate() and release() update a block's _allocated_bitmask using CAS |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
298 |
// loops. This prevents loss of updates even though release() may perform |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
299 |
// some updates without any locking. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
300 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
301 |
// allocate() obtains the entry from the first block in the _allocate_list, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
302 |
// and updates that block's _allocated_bitmask to indicate the entry is in |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
303 |
// use. If this makes the block full (all entries in use), the block is |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
304 |
// removed from the _allocate_list so it won't be considered by future |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
305 |
// allocations until some entries in it are relased. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
306 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
307 |
// release() looks up the block for the entry without locking. Once the block |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
308 |
// has been determined, its _allocated_bitmask needs to be updated, and its |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
309 |
// position in the _allocate_list may need to be updated. There are two |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
310 |
// cases: |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
311 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
312 |
// (a) If the block is neither full nor would become empty with the release of |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
313 |
// the entry, only its _allocated_bitmask needs to be updated. But if the CAS |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
314 |
// update fails, the applicable case may change for the retry. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
315 |
// |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
316 |
// (b) Otherwise, the _allocate_list will also need to be modified. This |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
317 |
// requires locking the _allocate_mutex, and then attempting to CAS the |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
318 |
// _allocated_bitmask. If the CAS fails, the applicable case may change for |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
319 |
// the retry. If the CAS succeeds, then update the _allocate_list according |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
320 |
// to the the state changes. If the block changed from full to not full, then |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
321 |
// it needs to be added to the _allocate_list, for use in future allocations. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
322 |
// If the block changed from not empty to empty, then it is moved to the end |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
323 |
// of the _allocate_list, for ease of empty block deletion processing. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
324 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
325 |
oop* OopStorage::allocate() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
326 |
MutexLockerEx ml(_allocate_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
327 |
Block* block = _allocate_list.head(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
328 |
if (block == NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
329 |
// No available blocks; make a new one, and add to storage. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
330 |
{ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
331 |
MutexUnlockerEx mul(_allocate_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
332 |
block = Block::new_block(this); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
333 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
334 |
if (block != NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
335 |
// Add new block to storage. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
336 |
log_info(oopstorage, blocks)("%s: new block " PTR_FORMAT, name(), p2i(block)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
337 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
338 |
// Add to end of _allocate_list. The mutex release allowed |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
339 |
// other threads to add blocks to the _allocate_list. We prefer |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
340 |
// to allocate from non-empty blocks, to allow empty blocks to |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
341 |
// be deleted. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
342 |
_allocate_list.push_back(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
343 |
++_empty_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
344 |
// Add to front of _active_list, and then record as the head |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
345 |
// block, for concurrent iteration protocol. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
346 |
_active_list.push_front(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
347 |
++_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
348 |
// Ensure all setup of block is complete before making it visible. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
349 |
OrderAccess::release_store(&_active_head, block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
350 |
} else { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
351 |
log_info(oopstorage, blocks)("%s: failed new block allocation", name()); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
352 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
353 |
block = _allocate_list.head(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
354 |
if (block == NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
355 |
// Failed to make new block, and no other thread made a block |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
356 |
// available while the mutex was released, so return failure. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
357 |
return NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
358 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
359 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
360 |
// Allocate from first block. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
361 |
assert(block != NULL, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
362 |
assert(!block->is_full(), "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
363 |
if (block->is_empty()) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
364 |
// Transitioning from empty to not empty. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
365 |
log_debug(oopstorage, blocks)("%s: block not empty " PTR_FORMAT, name(), p2i(block)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
366 |
--_empty_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
367 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
368 |
oop* result = block->allocate(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
369 |
assert(result != NULL, "allocation failed"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
370 |
assert(!block->is_empty(), "postcondition"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
371 |
Atomic::inc(&_allocation_count); // release updates outside lock. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
372 |
if (block->is_full()) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
373 |
// Transitioning from not full to full. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
374 |
// Remove full blocks from consideration by future allocates. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
375 |
log_debug(oopstorage, blocks)("%s: block full " PTR_FORMAT, name(), p2i(block)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
376 |
_allocate_list.unlink(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
377 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
378 |
log_info(oopstorage, ref)("%s: allocated " PTR_FORMAT, name(), p2i(result)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
379 |
return result; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
380 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
381 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
382 |
OopStorage::Block* OopStorage::find_block_or_null(const oop* ptr) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
383 |
assert(ptr != NULL, "precondition"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
384 |
return Block::block_for_ptr(this, ptr); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
385 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
386 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
387 |
void OopStorage::release_from_block(Block& block, uintx releasing) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
388 |
assert(releasing != 0, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
389 |
uintx allocated = block.allocated_bitmask(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
390 |
while (true) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
391 |
assert(releasing == (allocated & releasing), "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
392 |
uintx new_value = allocated ^ releasing; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
393 |
// CAS new_value into block's allocated bitmask, retrying with |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
394 |
// updated allocated bitmask until the CAS succeeds. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
395 |
uintx fetched; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
396 |
if (!is_full_bitmask(allocated) && !is_empty_bitmask(new_value)) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
397 |
fetched = block.cmpxchg_allocated_bitmask(new_value, allocated); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
398 |
if (fetched == allocated) return; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
399 |
} else { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
400 |
// Need special handling if transitioning from full to not full, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
401 |
// or from not empty to empty. For those cases, must hold the |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
402 |
// _allocation_mutex when updating the allocated bitmask, to |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
403 |
// ensure the associated list manipulations will be consistent |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
404 |
// with the allocation bitmask that is visible to other threads |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
405 |
// in allocate() or deleting empty blocks. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
406 |
MutexLockerEx ml(_allocate_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
407 |
fetched = block.cmpxchg_allocated_bitmask(new_value, allocated); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
408 |
if (fetched == allocated) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
409 |
// CAS succeeded; handle special cases, which might no longer apply. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
410 |
if (is_full_bitmask(allocated)) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
411 |
// Transitioning from full to not-full; add to _allocate_list. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
412 |
log_debug(oopstorage, blocks)("%s: block not full " PTR_FORMAT, name(), p2i(&block)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
413 |
_allocate_list.push_front(block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
414 |
assert(!block.is_full(), "invariant"); // Still not full. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
415 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
416 |
if (is_empty_bitmask(new_value)) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
417 |
// Transitioning from not-empty to empty; move to end of |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
418 |
// _allocate_list, to make it a deletion candidate. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
419 |
log_debug(oopstorage, blocks)("%s: block empty " PTR_FORMAT, name(), p2i(&block)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
420 |
_allocate_list.unlink(block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
421 |
_allocate_list.push_back(block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
422 |
++_empty_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
423 |
assert(block.is_empty(), "invariant"); // Still empty. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
424 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
425 |
return; // Successful CAS and transitions handled. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
426 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
427 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
428 |
// CAS failed; retry with latest value. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
429 |
allocated = fetched; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
430 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
431 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
432 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
433 |
#ifdef ASSERT |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
434 |
void OopStorage::check_release(const Block* block, const oop* ptr) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
435 |
switch (allocation_status_validating_block(block, ptr)) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
436 |
case INVALID_ENTRY: |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
437 |
fatal("Releasing invalid entry: " PTR_FORMAT, p2i(ptr)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
438 |
break; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
439 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
440 |
case UNALLOCATED_ENTRY: |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
441 |
fatal("Releasing unallocated entry: " PTR_FORMAT, p2i(ptr)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
442 |
break; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
443 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
444 |
case ALLOCATED_ENTRY: |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
445 |
assert(block->contains(ptr), "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
446 |
break; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
447 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
448 |
default: |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
449 |
ShouldNotReachHere(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
450 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
451 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
452 |
#endif // ASSERT |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
453 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
454 |
inline void check_release_entry(const oop* entry) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
455 |
assert(entry != NULL, "Releasing NULL"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
456 |
assert(*entry == NULL, "Releasing uncleared entry: " PTR_FORMAT, p2i(entry)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
457 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
458 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
459 |
void OopStorage::release(const oop* ptr) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
460 |
check_release_entry(ptr); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
461 |
Block* block = find_block_or_null(ptr); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
462 |
check_release(block, ptr); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
463 |
log_info(oopstorage, ref)("%s: released " PTR_FORMAT, name(), p2i(ptr)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
464 |
release_from_block(*block, block->bitmask_for_entry(ptr)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
465 |
Atomic::dec(&_allocation_count); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
466 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
467 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
468 |
void OopStorage::release(const oop* const* ptrs, size_t size) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
469 |
size_t i = 0; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
470 |
while (i < size) { |
48808
2b0b7f222800
8195690: JNI GetObjectRefType doesn't handle NULL
kbarrett
parents:
48787
diff
changeset
|
471 |
check_release_entry(ptrs[i]); |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
472 |
Block* block = find_block_or_null(ptrs[i]); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
473 |
check_release(block, ptrs[i]); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
474 |
log_info(oopstorage, ref)("%s: released " PTR_FORMAT, name(), p2i(ptrs[i])); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
475 |
size_t count = 0; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
476 |
uintx releasing = 0; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
477 |
for ( ; i < size; ++i) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
478 |
const oop* entry = ptrs[i]; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
479 |
// If entry not in block, finish block and resume outer loop with entry. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
480 |
if (!block->contains(entry)) break; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
481 |
check_release_entry(entry); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
482 |
// Add entry to releasing bitmap. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
483 |
log_info(oopstorage, ref)("%s: released " PTR_FORMAT, name(), p2i(entry)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
484 |
uintx entry_bitmask = block->bitmask_for_entry(entry); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
485 |
assert((releasing & entry_bitmask) == 0, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
486 |
"Duplicate entry: " PTR_FORMAT, p2i(entry)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
487 |
releasing |= entry_bitmask; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
488 |
++count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
489 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
490 |
// Release the contiguous entries that are in block. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
491 |
release_from_block(*block, releasing); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
492 |
Atomic::sub(count, &_allocation_count); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
493 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
494 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
495 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
496 |
const char* dup_name(const char* name) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
497 |
char* dup = NEW_C_HEAP_ARRAY(char, strlen(name) + 1, mtGC); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
498 |
strcpy(dup, name); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
499 |
return dup; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
500 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
501 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
502 |
OopStorage::OopStorage(const char* name, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
503 |
Mutex* allocate_mutex, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
504 |
Mutex* active_mutex) : |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
505 |
_name(dup_name(name)), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
506 |
_active_list(&Block::get_active_entry), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
507 |
_allocate_list(&Block::get_allocate_entry), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
508 |
_active_head(NULL), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
509 |
_allocate_mutex(allocate_mutex), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
510 |
_active_mutex(active_mutex), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
511 |
_allocation_count(0), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
512 |
_block_count(0), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
513 |
_empty_block_count(0), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
514 |
_concurrent_iteration_active(false) |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
515 |
{ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
516 |
assert(_active_mutex->rank() < _allocate_mutex->rank(), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
517 |
"%s: active_mutex must have lower rank than allocate_mutex", _name); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
518 |
assert(_active_mutex->_safepoint_check_required != Mutex::_safepoint_check_always, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
519 |
"%s: active mutex requires safepoint check", _name); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
520 |
assert(_allocate_mutex->_safepoint_check_required != Mutex::_safepoint_check_always, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
521 |
"%s: allocate mutex requires safepoint check", _name); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
522 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
523 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
524 |
void OopStorage::delete_empty_block(const Block& block) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
525 |
assert(block.is_empty(), "discarding non-empty block"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
526 |
log_info(oopstorage, blocks)("%s: delete empty block " PTR_FORMAT, name(), p2i(&block)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
527 |
Block::delete_block(block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
528 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
529 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
530 |
OopStorage::~OopStorage() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
531 |
Block* block; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
532 |
while ((block = _allocate_list.head()) != NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
533 |
_allocate_list.unlink(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
534 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
535 |
while ((block = _active_list.head()) != NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
536 |
_active_list.unlink(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
537 |
Block::delete_block(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
538 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
539 |
FREE_C_HEAP_ARRAY(char, _name); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
540 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
541 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
542 |
void OopStorage::delete_empty_blocks_safepoint(size_t retain) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
543 |
assert_at_safepoint(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
544 |
// Don't interfere with a concurrent iteration. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
545 |
if (_concurrent_iteration_active) return; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
546 |
// Compute the number of blocks to remove, to minimize volatile accesses. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
547 |
size_t empty_blocks = _empty_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
548 |
if (retain < empty_blocks) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
549 |
size_t remove_count = empty_blocks - retain; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
550 |
// Update volatile counters once. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
551 |
_block_count -= remove_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
552 |
_empty_block_count -= remove_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
553 |
do { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
554 |
const Block* block = _allocate_list.ctail(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
555 |
assert(block != NULL, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
556 |
assert(block->is_empty(), "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
557 |
// Remove block from lists, and delete it. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
558 |
_active_list.unlink(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
559 |
_allocate_list.unlink(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
560 |
delete_empty_block(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
561 |
} while (--remove_count > 0); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
562 |
// Update _active_head, in case current value was in deleted set. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
563 |
_active_head = _active_list.head(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
564 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
565 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
566 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
567 |
void OopStorage::delete_empty_blocks_concurrent(size_t retain) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
568 |
MutexLockerEx ml(_allocate_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
569 |
// Other threads could be adding to the empty block count while we |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
570 |
// release the mutex across the block deletions. Set an upper bound |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
571 |
// on how many blocks we'll try to release, so other threads can't |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
572 |
// cause an unbounded stay in this function. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
573 |
if (_empty_block_count <= retain) return; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
574 |
size_t limit = _empty_block_count - retain; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
575 |
for (size_t i = 0; (i < limit) && (retain < _empty_block_count); ++i) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
576 |
const Block* block = _allocate_list.ctail(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
577 |
assert(block != NULL, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
578 |
assert(block->is_empty(), "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
579 |
{ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
580 |
MutexLockerEx aml(_active_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
581 |
// Don't interfere with a concurrent iteration. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
582 |
if (_concurrent_iteration_active) return; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
583 |
// Remove block from _active_list, updating head if needed. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
584 |
_active_list.unlink(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
585 |
--_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
586 |
if (block == _active_head) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
587 |
_active_head = _active_list.head(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
588 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
589 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
590 |
// Remove block from _allocate_list and delete it. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
591 |
_allocate_list.unlink(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
592 |
--_empty_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
593 |
// Release mutex while deleting block. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
594 |
MutexUnlockerEx ul(_allocate_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
595 |
delete_empty_block(*block); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
596 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
597 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
598 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
599 |
OopStorage::EntryStatus |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
600 |
OopStorage::allocation_status_validating_block(const Block* block, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
601 |
const oop* ptr) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
602 |
MutexLockerEx ml(_allocate_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
603 |
if ((block == NULL) || !is_valid_block_locked_or_safepoint(block)) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
604 |
return INVALID_ENTRY; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
605 |
} else if ((block->allocated_bitmask() & block->bitmask_for_entry(ptr)) != 0) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
606 |
return ALLOCATED_ENTRY; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
607 |
} else { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
608 |
return UNALLOCATED_ENTRY; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
609 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
610 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
611 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
612 |
OopStorage::EntryStatus OopStorage::allocation_status(const oop* ptr) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
613 |
return allocation_status_validating_block(find_block_or_null(ptr), ptr); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
614 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
615 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
616 |
size_t OopStorage::allocation_count() const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
617 |
return _allocation_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
618 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
619 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
620 |
size_t OopStorage::block_count() const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
621 |
return _block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
622 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
623 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
624 |
size_t OopStorage::empty_block_count() const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
625 |
return _empty_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
626 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
627 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
628 |
size_t OopStorage::total_memory_usage() const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
629 |
size_t total_size = sizeof(OopStorage); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
630 |
total_size += strlen(name()) + 1; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
631 |
total_size += block_count() * Block::allocation_size(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
632 |
return total_size; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
633 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
634 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
635 |
// Parallel iteration support |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
636 |
#if INCLUDE_ALL_GCS |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
637 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
638 |
static char* not_started_marker_dummy = NULL; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
639 |
static void* const not_started_marker = ¬_started_marker_dummy; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
640 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
641 |
OopStorage::BasicParState::BasicParState(OopStorage* storage, bool concurrent) : |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
642 |
_storage(storage), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
643 |
_next_block(not_started_marker), |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
644 |
_concurrent(concurrent) |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
645 |
{ |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
646 |
update_iteration_state(true); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
647 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
648 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
649 |
OopStorage::BasicParState::~BasicParState() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
650 |
update_iteration_state(false); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
651 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
652 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
653 |
void OopStorage::BasicParState::update_iteration_state(bool value) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
654 |
if (_concurrent) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
655 |
MutexLockerEx ml(_storage->_active_mutex, Mutex::_no_safepoint_check_flag); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
656 |
assert(_storage->_concurrent_iteration_active != value, "precondition"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
657 |
_storage->_concurrent_iteration_active = value; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
658 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
659 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
660 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
661 |
void OopStorage::BasicParState::ensure_iteration_started() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
662 |
if (!_concurrent) assert_at_safepoint(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
663 |
assert(!_concurrent || _storage->_concurrent_iteration_active, "invariant"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
664 |
// Ensure _next_block is not the not_started_marker, setting it to |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
665 |
// the _active_head to start the iteration if necessary. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
666 |
if (OrderAccess::load_acquire(&_next_block) == not_started_marker) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
667 |
Atomic::cmpxchg(_storage->_active_head, &_next_block, not_started_marker); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
668 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
669 |
assert(_next_block != not_started_marker, "postcondition"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
670 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
671 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
672 |
OopStorage::Block* OopStorage::BasicParState::claim_next_block() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
673 |
assert(_next_block != not_started_marker, "Iteration not started"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
674 |
void* next = _next_block; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
675 |
while (next != NULL) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
676 |
void* new_next = _storage->_active_list.next(*static_cast<Block*>(next)); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
677 |
void* fetched = Atomic::cmpxchg(new_next, &_next_block, next); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
678 |
if (fetched == next) break; // Claimed. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
679 |
next = fetched; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
680 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
681 |
return static_cast<Block*>(next); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
682 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
683 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
684 |
#endif // INCLUDE_ALL_GCS |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
685 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
686 |
const char* OopStorage::name() const { return _name; } |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
687 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
688 |
#ifndef PRODUCT |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
689 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
690 |
void OopStorage::print_on(outputStream* st) const { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
691 |
size_t allocations = _allocation_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
692 |
size_t blocks = _block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
693 |
size_t empties = _empty_block_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
694 |
// Comparison is being careful about racy accesses. |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
695 |
size_t used = (blocks < empties) ? 0 : (blocks - empties); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
696 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
697 |
double data_size = section_size * section_count; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
698 |
double alloc_percentage = percent_of((double)allocations, used * data_size); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
699 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
700 |
st->print("%s: " SIZE_FORMAT " entries in " SIZE_FORMAT " blocks (%.F%%), " |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
701 |
SIZE_FORMAT " empties, " SIZE_FORMAT " bytes", |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
702 |
name(), allocations, used, alloc_percentage, |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
703 |
empties, total_memory_usage()); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
704 |
if (_concurrent_iteration_active) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
705 |
st->print(", concurrent iteration active"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
706 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
707 |
} |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
708 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff
changeset
|
709 |
#endif // !PRODUCT |