1 /*
2 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
87
88 float RSHashTable::TableOccupancyFactor = 0.5f;
89
90 RSHashTable::RSHashTable(size_t capacity) :
91 _num_entries(0),
92 _capacity(capacity),
93 _capacity_mask(capacity-1),
94 _occupied_entries(0),
95 _occupied_cards(0),
96 _entries(NULL),
97 _buckets(NEW_C_HEAP_ARRAY(int, capacity, mtGC)),
98 _free_region(0),
99 _free_list(NullEntry)
100 {
101 _num_entries = (capacity * TableOccupancyFactor) + 1;
102 _entries = (SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, _num_entries * SparsePRTEntry::size(), mtGC);
103 clear();
104 }
105
106 RSHashTable::~RSHashTable() {
107 if (_entries != NULL) {
108 FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
109 _entries = NULL;
110 }
111 if (_buckets != NULL) {
112 FREE_C_HEAP_ARRAY(int, _buckets);
113 _buckets = NULL;
114 }
115 }
116
117 void RSHashTable::clear() {
118 _occupied_entries = 0;
119 _occupied_cards = 0;
120 guarantee(_entries != NULL, "INV");
121 guarantee(_buckets != NULL, "INV");
122
123 guarantee(_capacity <= ((size_t)1 << (sizeof(int)*BitsPerByte-1)) - 1,
124 "_capacity too large");
125
126 // This will put -1 == NullEntry in the key field of all entries.
127 memset((void*)_entries, NullEntry, _num_entries * SparsePRTEntry::size());
128 memset((void*)_buckets, NullEntry, _capacity * sizeof(int));
129 _free_list = NullEntry;
130 _free_region = 0;
131 }
132
133 bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) {
134 SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
|
1 /*
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
87
88 float RSHashTable::TableOccupancyFactor = 0.5f;
89
90 RSHashTable::RSHashTable(size_t capacity) :
91 _num_entries(0),
92 _capacity(capacity),
93 _capacity_mask(capacity-1),
94 _occupied_entries(0),
95 _occupied_cards(0),
96 _entries(NULL),
97 _buckets(NEW_C_HEAP_ARRAY(int, capacity, mtGC)),
98 _free_region(0),
99 _free_list(NullEntry)
100 {
101 _num_entries = (capacity * TableOccupancyFactor) + 1;
102 _entries = (SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, _num_entries * SparsePRTEntry::size(), mtGC);
103 clear();
104 }
105
106 RSHashTable::~RSHashTable() {
107 FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
108 FREE_C_HEAP_ARRAY(int, _buckets);
109 }
110
111 void RSHashTable::clear() {
112 _occupied_entries = 0;
113 _occupied_cards = 0;
114 guarantee(_entries != NULL, "INV");
115 guarantee(_buckets != NULL, "INV");
116
117 guarantee(_capacity <= ((size_t)1 << (sizeof(int)*BitsPerByte-1)) - 1,
118 "_capacity too large");
119
120 // This will put -1 == NullEntry in the key field of all entries.
121 memset((void*)_entries, NullEntry, _num_entries * SparsePRTEntry::size());
122 memset((void*)_buckets, NullEntry, _capacity * sizeof(int));
123 _free_list = NullEntry;
124 _free_region = 0;
125 }
126
127 bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) {
128 SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
|