author | eosterlund |
Tue, 12 Nov 2019 20:01:23 +0000 | |
changeset 59038 | b9a42ca342db |
parent 53893 | ad56513c7e07 |
child 59249 | 29b0d0b61615 |
permissions | -rw-r--r-- |
53893
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
1 |
/* |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
4 |
* |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
8 |
* |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
13 |
* accompanied this code). |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
14 |
* |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
18 |
* |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
21 |
* questions. |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
22 |
*/ |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
23 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
25 |
#include "gc/z/zNMethodTableEntry.hpp" |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
26 |
#include "gc/z/zNMethodTableIteration.hpp" |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
27 |
#include "memory/iterator.hpp" |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
28 |
#include "runtime/atomic.hpp" |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
29 |
#include "utilities/debug.hpp" |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
30 |
#include "utilities/globalDefinitions.hpp" |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
31 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
32 |
ZNMethodTableIteration::ZNMethodTableIteration() : |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
33 |
_table(NULL), |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
34 |
_size(0), |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
35 |
_claimed(0) {} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
36 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
37 |
bool ZNMethodTableIteration::in_progress() const { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
38 |
return _table != NULL; |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
39 |
} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
40 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
41 |
void ZNMethodTableIteration::nmethods_do_begin(ZNMethodTableEntry* table, size_t size) { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
42 |
assert(!in_progress(), "precondition"); |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
43 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
44 |
_table = table; |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
45 |
_size = size; |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
46 |
_claimed = 0; |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
47 |
} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
48 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
49 |
void ZNMethodTableIteration::nmethods_do_end() { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
50 |
assert(_claimed >= _size, "Failed to claim all table entries"); |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
51 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
52 |
// Finish iteration |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
53 |
_table = NULL; |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
54 |
} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
55 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
56 |
void ZNMethodTableIteration::nmethods_do(NMethodClosure* cl) { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
57 |
for (;;) { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
58 |
// Claim table partition. Each partition is currently sized to span |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
59 |
// two cache lines. This number is just a guess, but seems to work well. |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
60 |
const size_t partition_size = (ZCacheLineSize * 2) / sizeof(ZNMethodTableEntry); |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
61 |
const size_t partition_start = MIN2(Atomic::add(partition_size, &_claimed) - partition_size, _size); |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
62 |
const size_t partition_end = MIN2(partition_start + partition_size, _size); |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
63 |
if (partition_start == partition_end) { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
64 |
// End of table |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
65 |
break; |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
66 |
} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
67 |
|
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
68 |
// Process table partition |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
69 |
for (size_t i = partition_start; i < partition_end; i++) { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
70 |
const ZNMethodTableEntry entry = _table[i]; |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
71 |
if (entry.registered()) { |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
72 |
cl->do_nmethod(entry.method()); |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
73 |
} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
74 |
} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
75 |
} |
ad56513c7e07
8219468: ZGC: Extract iteration functionality into a new ZNMethodTableIteration class
stefank
parents:
diff
changeset
|
76 |
} |