1
1
/*
2
- * Copyright (c) 1998, 2019 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1998, 2020 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -60,9 +60,12 @@ class IndexSet : public ResourceObj {
60
60
// membership of the element in the set.
61
61
62
62
// The lengths of the index bitfields
63
- enum { bit_index_length = 5 ,
64
- word_index_length = 3 ,
65
- block_index_length = 8 // not used
63
+ enum {
64
+ // Each block consists of 256 bits
65
+ block_index_length = 8 ,
66
+ // Split over 4 or 8 words depending on bitness
67
+ word_index_length = block_index_length - LogBitsPerWord,
68
+ bit_index_length = block_index_length - word_index_length,
66
69
};
67
70
68
71
// Derived constants used for manipulating the index bitfields
@@ -88,7 +91,7 @@ class IndexSet : public ResourceObj {
88
91
return mask_bits (element >> word_index_offset,word_index_mask);
89
92
}
90
93
static uint get_bit_index (uint element) {
91
- return mask_bits (element,bit_index_mask);
94
+ return mask_bits (element, bit_index_mask);
92
95
}
93
96
94
97
// ------------------------------ class BitBlock ----------------------------
@@ -102,17 +105,17 @@ class IndexSet : public ResourceObj {
102
105
// All of BitBlocks fields and methods are declared private. We limit
103
106
// access to IndexSet and IndexSetIterator.
104
107
105
- // A BitBlock is composed of some number of 32 bit words. When a BitBlock
108
+ // A BitBlock is composed of some number of 32- or 64- bit words. When a BitBlock
106
109
// is not in use by any IndexSet, it is stored on a free list. The next field
107
- // is used by IndexSet to mainting this free list.
110
+ // is used by IndexSet to maintain this free list.
108
111
109
112
union {
110
- uint32_t _words[words_per_block];
113
+ uintptr_t _words[words_per_block];
111
114
BitBlock *_next;
112
115
} _data;
113
116
114
117
// accessors
115
- uint32_t * words () { return _data._words ; }
118
+ uintptr_t * words () { return _data._words ; }
116
119
void set_next (BitBlock *next) { _data._next = next; }
117
120
BitBlock *next () { return _data._next ; }
118
121
@@ -121,32 +124,32 @@ class IndexSet : public ResourceObj {
121
124
// not assume that the block index has been masked out.
122
125
123
126
void clear () {
124
- memset (words (), 0 , sizeof (uint32_t ) * words_per_block);
127
+ memset (words (), 0 , sizeof (uintptr_t ) * words_per_block);
125
128
}
126
129
127
130
bool member (uint element) {
128
131
uint word_index = IndexSet::get_word_index (element);
129
- uint bit_index = IndexSet::get_bit_index (element);
132
+ uintptr_t bit_index = IndexSet::get_bit_index (element);
130
133
131
- return ((words ()[word_index] & (uint32_t )( 0x1 << bit_index)) != 0 );
134
+ return ((words ()[word_index] & (uintptr_t ( 1 ) << bit_index)) != 0 );
132
135
}
133
136
134
137
bool insert (uint element) {
135
138
uint word_index = IndexSet::get_word_index (element);
136
- uint bit_index = IndexSet::get_bit_index (element);
139
+ uintptr_t bit_index = IndexSet::get_bit_index (element);
137
140
138
- uint32_t bit = ( 0x1 << bit_index) ;
139
- uint32_t before = words ()[word_index];
141
+ uintptr_t bit = uintptr_t ( 1 ) << bit_index;
142
+ uintptr_t before = words ()[word_index];
140
143
words ()[word_index] = before | bit;
141
144
return ((before & bit) != 0 );
142
145
}
143
146
144
147
bool remove (uint element) {
145
148
uint word_index = IndexSet::get_word_index (element);
146
- uint bit_index = IndexSet::get_bit_index (element);
149
+ uintptr_t bit_index = IndexSet::get_bit_index (element);
147
150
148
- uint32_t bit = ( 0x1 << bit_index) ;
149
- uint32_t before = words ()[word_index];
151
+ uintptr_t bit = uintptr_t ( 1 ) << bit_index;
152
+ uintptr_t before = words ()[word_index];
150
153
words ()[word_index] = before & ~bit;
151
154
return ((before & bit) != 0 );
152
155
}
@@ -376,7 +379,7 @@ class IndexSetIterator {
376
379
377
380
private:
378
381
// The current word we are inspecting
379
- uint32_t _current;
382
+ uintptr_t _current;
380
383
381
384
// What element number are we currently on?
382
385
uint _value;
@@ -391,7 +394,7 @@ class IndexSetIterator {
391
394
uint _max_blocks;
392
395
393
396
// A pointer to the contents of the current block
394
- uint32_t * _words;
397
+ uintptr_t * _words;
395
398
396
399
// A pointer to the blocks in our set
397
400
IndexSet::BitBlock **_blocks;
@@ -447,7 +450,7 @@ class IndexSetIterator {
447
450
448
451
// Return the next element of the set.
449
452
uint next_value () {
450
- uint current = _current;
453
+ uintptr_t current = _current;
451
454
assert (current != 0 , " sanity" );
452
455
uint advance = count_trailing_zeros (current);
453
456
assert (((current >> advance) & 0x1 ) == 1 , " sanity" );
0 commit comments