< prev index next >

src/hotspot/share/utilities/hashtable.cpp

Print this page

 84 
 85   entry = (HashtableEntry<T, F>*)BasicHashtable<F>::new_entry(hashValue);
 86   entry->set_literal(obj);
 87   return entry;
 88 }
 89 
 90 // Version of hashtable entry allocation that allocates in the C heap directly.
 91 // The block allocator in BasicHashtable has less fragmentation, but the memory is not freed until
 92 // the whole table is freed. Use allocate_new_entry() if you want to individually free the memory
 93 // used by each entry
 94 template <class T, MEMFLAGS F> HashtableEntry<T, F>* Hashtable<T, F>::allocate_new_entry(unsigned int hashValue, T obj) {
 95   HashtableEntry<T, F>* entry = (HashtableEntry<T, F>*) NEW_C_HEAP_ARRAY(char, this->entry_size(), F);
 96 
 97   entry->set_hash(hashValue);
 98   entry->set_literal(obj);
 99   entry->set_next(NULL);
100   return entry;
101 }
102 
103 template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
104   if (NULL != _buckets) {
105     FREE_C_HEAP_ARRAY(HashtableBucket, _buckets);
106     _buckets = NULL;
107   }
108 }
109 
110 // For oops and Strings the size of the literal is interesting. For other types, nobody cares.
111 static int literal_size(ConstantPool*) { return 0; }
112 static int literal_size(Klass*)        { return 0; }
113 static int literal_size(nmethod*)      { return 0; }
114 
115 static int literal_size(Symbol *symbol) {
116   return symbol->size() * HeapWordSize;
117 }
118 
119 static int literal_size(oop obj) {
120   // NOTE: this would over-count if (pre-JDK8) java_lang_Class::has_offset_field() is true,
121   // and the String.value array is shared by several Strings. However, starting from JDK8,
122   // the String.value array is not shared anymore.
123   if (obj == NULL) {
124     return 0;
125   } else if (obj->klass() == SystemDictionary::String_klass()) {
126     return (obj->size() + java_lang_String::value(obj)->size()) * HeapWordSize;
127   } else {

 84 
 85   entry = (HashtableEntry<T, F>*)BasicHashtable<F>::new_entry(hashValue);
 86   entry->set_literal(obj);
 87   return entry;
 88 }
 89 
 90 // Version of hashtable entry allocation that allocates in the C heap directly.
 91 // The block allocator in BasicHashtable has less fragmentation, but the memory is not freed until
 92 // the whole table is freed. Use allocate_new_entry() if you want to individually free the memory
 93 // used by each entry
 94 template <class T, MEMFLAGS F> HashtableEntry<T, F>* Hashtable<T, F>::allocate_new_entry(unsigned int hashValue, T obj) {
 95   HashtableEntry<T, F>* entry = (HashtableEntry<T, F>*) NEW_C_HEAP_ARRAY(char, this->entry_size(), F);
 96 
 97   entry->set_hash(hashValue);
 98   entry->set_literal(obj);
 99   entry->set_next(NULL);
100   return entry;
101 }
102 
103 template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
104   FREE_C_HEAP_ARRAY(HashtableBucket, _buckets);
105   _buckets = NULL;


106 }
107 
108 // For oops and Strings the size of the literal is interesting. For other types, nobody cares.
109 static int literal_size(ConstantPool*) { return 0; }
110 static int literal_size(Klass*)        { return 0; }
111 static int literal_size(nmethod*)      { return 0; }
112 
113 static int literal_size(Symbol *symbol) {
114   return symbol->size() * HeapWordSize;
115 }
116 
117 static int literal_size(oop obj) {
118   // NOTE: this would over-count if (pre-JDK8) java_lang_Class::has_offset_field() is true,
119   // and the String.value array is shared by several Strings. However, starting from JDK8,
120   // the String.value array is not shared anymore.
121   if (obj == NULL) {
122     return 0;
123   } else if (obj->klass() == SystemDictionary::String_klass()) {
124     return (obj->size() + java_lang_String::value(obj)->size()) * HeapWordSize;
125   } else {
< prev index next >