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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/altHashing.hpp"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "gc/g1/g1CollectedHeap.inline.hpp"
29 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
30 #include "gc/g1/g1StringDedup.hpp"
31 #include "gc/g1/g1StringDedupTable.hpp"
32 #include "gc/shared/gcLocker.hpp"
33 #include "logging/log.hpp"
34 #include "memory/padded.inline.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "oops/typeArrayOop.hpp"
37 #include "runtime/mutexLocker.hpp"
38
39 //
40 // Freelist in the deduplication table entry cache. Links table
41 // entries together using their _next fields.
42 //
43 class G1StringDedupEntryFreeList : public CHeapObj<mtGC> {
44 private:
45 G1StringDedupEntry* _list;
46 size_t _length;
47
48 public:
49 G1StringDedupEntryFreeList() :
50 _list(NULL),
51 _length(0) {
52 }
326 if (use_java_hash() && hash != 0) {
327 // Store hash code in cache
328 java_lang_String::set_hash(java_string, hash);
329 }
330 }
331
332 typeArrayOop existing_value = lookup_or_add(value, latin1, hash);
333 if (existing_value == value) {
334 // Same value, already known
335 stat.inc_known();
336 return;
337 }
338
339 // Get size of value array
340 uintx size_in_bytes = value->size() * HeapWordSize;
341 stat.inc_new(size_in_bytes);
342
343 if (existing_value != NULL) {
344 // Enqueue the reference to make sure it is kept alive. Concurrent mark might
345 // otherwise declare it dead if there are no other strong references to this object.
346 G1SATBCardTableModRefBS::enqueue(existing_value);
347
348 // Existing value found, deduplicate string
349 java_lang_String::set_value(java_string, existing_value);
350
351 if (G1CollectedHeap::heap()->is_in_young(value)) {
352 stat.inc_deduped_young(size_in_bytes);
353 } else {
354 stat.inc_deduped_old(size_in_bytes);
355 }
356 }
357 }
358
359 G1StringDedupTable* G1StringDedupTable::prepare_resize() {
360 size_t size = _table->_size;
361
362 // Check if the hashtable needs to be resized
363 if (_table->_entries > _table->_grow_threshold) {
364 // Grow table, double the size
365 size *= 2;
366 if (size > _max_size) {
|
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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/altHashing.hpp"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "gc/g1/g1CollectedHeap.inline.hpp"
29 #include "gc/g1/g1StringDedup.hpp"
30 #include "gc/g1/g1StringDedupTable.hpp"
31 #include "gc/shared/gcLocker.hpp"
32 #include "gc/shared/satbMarkQueue.hpp"
33 #include "logging/log.hpp"
34 #include "memory/padded.inline.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "oops/typeArrayOop.hpp"
37 #include "runtime/mutexLocker.hpp"
38
39 //
40 // Freelist in the deduplication table entry cache. Links table
41 // entries together using their _next fields.
42 //
43 class G1StringDedupEntryFreeList : public CHeapObj<mtGC> {
44 private:
45 G1StringDedupEntry* _list;
46 size_t _length;
47
48 public:
49 G1StringDedupEntryFreeList() :
50 _list(NULL),
51 _length(0) {
52 }
326 if (use_java_hash() && hash != 0) {
327 // Store hash code in cache
328 java_lang_String::set_hash(java_string, hash);
329 }
330 }
331
332 typeArrayOop existing_value = lookup_or_add(value, latin1, hash);
333 if (existing_value == value) {
334 // Same value, already known
335 stat.inc_known();
336 return;
337 }
338
339 // Get size of value array
340 uintx size_in_bytes = value->size() * HeapWordSize;
341 stat.inc_new(size_in_bytes);
342
343 if (existing_value != NULL) {
344 // Enqueue the reference to make sure it is kept alive. Concurrent mark might
345 // otherwise declare it dead if there are no other strong references to this object.
346 SATBMarkQueue::enqueue(existing_value);
347
348 // Existing value found, deduplicate string
349 java_lang_String::set_value(java_string, existing_value);
350
351 if (G1CollectedHeap::heap()->is_in_young(value)) {
352 stat.inc_deduped_young(size_in_bytes);
353 } else {
354 stat.inc_deduped_old(size_in_bytes);
355 }
356 }
357 }
358
359 G1StringDedupTable* G1StringDedupTable::prepare_resize() {
360 size_t size = _table->_size;
361
362 // Check if the hashtable needs to be resized
363 if (_table->_entries > _table->_grow_threshold) {
364 // Grow table, double the size
365 size *= 2;
366 if (size > _max_size) {
|