39 40 uint32_t Symbol::pack_hash_and_refcount(short hash, int refcount) { 41 STATIC_ASSERT(PERM_REFCOUNT == ((1 << 16) - 1)); 42 assert(refcount >= 0, "negative refcount"); 43 assert(refcount <= PERM_REFCOUNT, "invalid refcount"); 44 uint32_t hi = hash; 45 uint32_t lo = refcount; 46 return (hi << 16) | lo; 47 } 48 49 Symbol::Symbol(const u1* name, int length, int refcount) { 50 _hash_and_refcount = pack_hash_and_refcount((short)os::random(), refcount); 51 _length = length; 52 _body[0] = 0; // in case length == 0 53 for (int i = 0; i < length; i++) { 54 byte_at_put(i, name[i]); 55 } 56 } 57 58 void* Symbol::operator new(size_t sz, int len) throw() { 59 int alloc_size = size(len)*wordSize; 60 address res = (address) AllocateHeap(alloc_size, mtSymbol); 61 return res; 62 } 63 64 void* Symbol::operator new(size_t sz, int len, Arena* arena) throw() { 65 int alloc_size = size(len)*wordSize; 66 address res = (address)arena->Amalloc_4(alloc_size); 67 return res; 68 } 69 70 void Symbol::operator delete(void *p) { 71 assert(((Symbol*)p)->refcount() == 0, "should not call this"); 72 FreeHeap(p); 73 } 74 75 void Symbol::set_permanent() { 76 // This is called at a safepoint during dumping of a dynamic CDS archive. 77 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); 78 _hash_and_refcount = pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT); | 39 40 uint32_t Symbol::pack_hash_and_refcount(short hash, int refcount) { 41 STATIC_ASSERT(PERM_REFCOUNT == ((1 << 16) - 1)); 42 assert(refcount >= 0, "negative refcount"); 43 assert(refcount <= PERM_REFCOUNT, "invalid refcount"); 44 uint32_t hi = hash; 45 uint32_t lo = refcount; 46 return (hi << 16) | lo; 47 } 48 49 Symbol::Symbol(const u1* name, int length, int refcount) { 50 _hash_and_refcount = pack_hash_and_refcount((short)os::random(), refcount); 51 _length = length; 52 _body[0] = 0; // in case length == 0 53 for (int i = 0; i < length; i++) { 54 byte_at_put(i, name[i]); 55 } 56 } 57 58 void* Symbol::operator new(size_t sz, int len) throw() { 59 if (DumpSharedSpaces) { 60 // To get deterministic output from -Xshare:dump, we ensure that Symbols are allocated in 61 // increasing adresses. When the symbols are copied into the archive, we preserve their 62 // relative address order (see SortedSymbolClosure in metaspaceShared.cpp) 63 // 64 // We cannot use arena because arena chunks are allocated by the OS. As a result, for example, 65 // the archived symbol of "java/lang/Object" may sometimes be lower than "java/lang/String", and 66 // sometimes be higher. This would cause non-deterministic contents in the archive. 67 return Metaspace::allocate(ClassLoaderData::the_null_class_loader_data(), 68 size(len), MetaspaceObj::ClassType, Thread::current()); 69 } 70 int alloc_size = size(len)*wordSize; 71 address res = (address) AllocateHeap(alloc_size, mtSymbol); 72 return res; 73 } 74 75 void* Symbol::operator new(size_t sz, int len, Arena* arena) throw() { 76 int alloc_size = size(len)*wordSize; 77 address res = (address)arena->Amalloc_4(alloc_size); 78 return res; 79 } 80 81 void Symbol::operator delete(void *p) { 82 assert(((Symbol*)p)->refcount() == 0, "should not call this"); 83 FreeHeap(p); 84 } 85 86 void Symbol::set_permanent() { 87 // This is called at a safepoint during dumping of a dynamic CDS archive. 88 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); 89 _hash_and_refcount = pack_hash_and_refcount(extract_hash(_hash_and_refcount), PERM_REFCOUNT); |