< prev index next >

src/hotspot/share/gc/g1/g1StringDedupTable.cpp

G1BarrierSet_merge

7  *                                                                                                                                   
8  * This code is distributed in the hope that it will be useful, but WITHOUT                                                          
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or                                                             
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License                                                             
11  * version 2 for more details (a copy is included in the LICENSE file that                                                           
12  * accompanied this code).                                                                                                           
13  *                                                                                                                                   
14  * You should have received a copy of the GNU General Public License version                                                         
15  * 2 along with this work; if not, write to the Free Software Foundation,                                                            
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.                                                                     
17  *                                                                                                                                   
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA                                                           
19  * or visit www.oracle.com if you need additional information or have any                                                            
20  * questions.                                                                                                                        
21  *                                                                                                                                   
22  */                                                                                                                                  
23 
24 #include "precompiled.hpp"                                                                                                           
25 #include "classfile/altHashing.hpp"                                                                                                  
26 #include "classfile/javaClasses.inline.hpp"                                                                                          
                                                                                                                                     
27 #include "gc/g1/g1CollectedHeap.inline.hpp"                                                                                          
28 #include "gc/g1/g1SATBCardTableModRefBS.hpp"                                                                                         
29 #include "gc/g1/g1StringDedup.hpp"                                                                                                   
30 #include "gc/g1/g1StringDedupTable.hpp"                                                                                              
31 #include "gc/shared/gcLocker.hpp"                                                                                                    
32 #include "logging/log.hpp"                                                                                                           
33 #include "memory/padded.inline.hpp"                                                                                                  
34 #include "oops/arrayOop.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 

7  *
8  * This code is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #include "precompiled.hpp"
25 #include "classfile/altHashing.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "gc/g1/g1BarrierSet.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 "logging/log.hpp"
33 #include "memory/padded.inline.hpp"
34 #include "oops/arrayOop.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 

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;                                                                                                                       

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::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;
< prev index next >