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 // List of deduplication table entries. Links table
41 // entries together using their _next fields.
42 //
43 class G1StringDedupEntryList : public CHeapObj<mtGC> {
44 private:
45 G1StringDedupEntry* _list;
46 size_t _length;
47
48 public:
49 G1StringDedupEntryList() :
365 if (use_java_hash() && hash != 0) {
366 // Store hash code in cache
367 java_lang_String::set_hash(java_string, hash);
368 }
369 }
370
371 typeArrayOop existing_value = lookup_or_add(value, latin1, hash);
372 if (existing_value == value) {
373 // Same value, already known
374 stat.inc_known();
375 return;
376 }
377
378 // Get size of value array
379 uintx size_in_bytes = value->size() * HeapWordSize;
380 stat.inc_new(size_in_bytes);
381
382 if (existing_value != NULL) {
383 // Enqueue the reference to make sure it is kept alive. Concurrent mark might
384 // otherwise declare it dead if there are no other strong references to this object.
385 G1SATBCardTableModRefBS::enqueue(existing_value);
386
387 // Existing value found, deduplicate string
388 java_lang_String::set_value(java_string, existing_value);
389
390 if (G1CollectedHeap::heap()->is_in_young(value)) {
391 stat.inc_deduped_young(size_in_bytes);
392 } else {
393 stat.inc_deduped_old(size_in_bytes);
394 }
395 }
396 }
397
398 G1StringDedupTable* G1StringDedupTable::prepare_resize() {
399 size_t size = _table->_size;
400
401 // Check if the hashtable needs to be resized
402 if (_table->_entries > _table->_grow_threshold) {
403 // Grow table, double the size
404 size *= 2;
405 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/g1BarrierSet.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 // List of deduplication table entries. Links table
41 // entries together using their _next fields.
42 //
43 class G1StringDedupEntryList : public CHeapObj<mtGC> {
44 private:
45 G1StringDedupEntry* _list;
46 size_t _length;
47
48 public:
49 G1StringDedupEntryList() :
365 if (use_java_hash() && hash != 0) {
366 // Store hash code in cache
367 java_lang_String::set_hash(java_string, hash);
368 }
369 }
370
371 typeArrayOop existing_value = lookup_or_add(value, latin1, hash);
372 if (existing_value == value) {
373 // Same value, already known
374 stat.inc_known();
375 return;
376 }
377
378 // Get size of value array
379 uintx size_in_bytes = value->size() * HeapWordSize;
380 stat.inc_new(size_in_bytes);
381
382 if (existing_value != NULL) {
383 // Enqueue the reference to make sure it is kept alive. Concurrent mark might
384 // otherwise declare it dead if there are no other strong references to this object.
385 G1BarrierSet::satb_enqueue(existing_value);
386
387 // Existing value found, deduplicate string
388 java_lang_String::set_value(java_string, existing_value);
389
390 if (G1CollectedHeap::heap()->is_in_young(value)) {
391 stat.inc_deduped_young(size_in_bytes);
392 } else {
393 stat.inc_deduped_old(size_in_bytes);
394 }
395 }
396 }
397
398 G1StringDedupTable* G1StringDedupTable::prepare_resize() {
399 size_t size = _table->_size;
400
401 // Check if the hashtable needs to be resized
402 if (_table->_entries > _table->_grow_threshold) {
403 // Grow table, double the size
404 size *= 2;
405 if (size > _max_size) {
|