32
32
#include " runtime/os.hpp"
33
33
#include " runtime/thread.hpp"
34
34
#include " utilities/align.hpp"
35
+ #include " utilities/powerOfTwo.hpp"
35
36
36
37
class ZIndexDistributorStriped : public CHeapObj <mtGC> {
37
38
static const int MemSize = 4096 ;
39
+ static const int StripeCount = MemSize / ZCacheLineSize;
38
40
39
- const int _max_index ;
41
+ const int _count ;
40
42
// For claiming a stripe
41
43
volatile int _claim_stripe;
42
44
// For claiming inside a stripe
@@ -51,20 +53,19 @@ class ZIndexDistributorStriped : public CHeapObj<mtGC> {
51
53
}
52
54
53
55
public:
54
- ZIndexDistributorStriped (int max_index )
55
- : _max_index(max_index ),
56
+ ZIndexDistributorStriped (int count )
57
+ : _count(count ),
56
58
_claim_stripe (0 ),
57
59
_mem() {
58
60
memset (_mem, 0 , MemSize + ZCacheLineSize);
59
61
}
60
62
61
63
template <typename Function>
62
64
void do_indices (Function function) {
63
- const int count = MemSize / ZCacheLineSize;
64
- const int stripe_max = _max_index / count;
65
+ const int stripe_max = _count / StripeCount;
65
66
66
67
// Use claiming
67
- for (int i; (i = claim_stripe ()) < count ;) {
68
+ for (int i; (i = claim_stripe ()) < StripeCount ;) {
68
69
for (int index ; (index = Atomic::fetch_then_add (claim_addr (i), 1 , memory_order_relaxed)) < stripe_max;) {
69
70
if (!function (i * stripe_max + index )) {
70
71
return ;
@@ -73,14 +74,19 @@ class ZIndexDistributorStriped : public CHeapObj<mtGC> {
73
74
}
74
75
75
76
// Use stealing
76
- for (int i = 0 ; i < count ; i++) {
77
+ for (int i = 0 ; i < StripeCount ; i++) {
77
78
for (int index ; (index = Atomic::fetch_then_add (claim_addr (i), 1 , memory_order_relaxed)) < stripe_max;) {
78
79
if (!function (i * stripe_max + index )) {
79
80
return ;
80
81
}
81
82
}
82
83
}
83
84
}
85
+
86
+ static size_t get_count (size_t max_count) {
87
+ // Must be multiple of the StripeCount
88
+ return align_up (max_count, StripeCount);
89
+ }
84
90
};
85
91
86
92
class ZIndexDistributorClaimTree : public CHeapObj <mtGC> {
@@ -290,6 +296,12 @@ class ZIndexDistributorClaimTree : public CHeapObj<mtGC> {
290
296
claim_and_do (function, indices, 0 /* level */ );
291
297
steal_and_do (function, indices, 0 /* level */ );
292
298
}
299
+
300
+ static size_t get_count (size_t max_count) {
301
+ // Must be at least claim_level_size(ClaimLevels) and a power of two
302
+ const size_t min_count = claim_level_size (ClaimLevels);
303
+ return round_up_power_of_2 (MAX2 (max_count, min_count));
304
+ }
293
305
};
294
306
295
307
// Using dynamically allocated objects just to be able to evaluate
@@ -328,4 +340,17 @@ inline void ZIndexDistributor::do_indices(Function function) {
328
340
};
329
341
}
330
342
343
+ inline size_t ZIndexDistributor::get_count (size_t max_count) {
344
+ size_t required_count;
345
+ switch (ZIndexDistributorStrategy) {
346
+ case 0 : required_count = ZIndexDistributorClaimTree::get_count (max_count); break ;
347
+ case 1 : required_count = ZIndexDistributorStriped::get_count (max_count); break ;
348
+ default : fatal (" Unknown ZIndexDistributorStrategy" );
349
+ };
350
+
351
+ assert (max_count <= required_count, " unsupported max_count: %zu" , max_count);
352
+
353
+ return required_count;
354
+ }
355
+
331
356
#endif // SHARE_GC_Z_ZINDEXDISTRIBUTOR_INLINE_HPP
1 commit comments
openjdk-notifier[bot] commentedon Mar 4, 2025
Review
Issues