25 26 #include "precompiled.hpp" 27 #include "classfile/altHashing.hpp" 28 #include "classfile/classLoaderData.hpp" 29 #include "memory/allocation.inline.hpp" 30 #include "memory/resourceArea.hpp" 31 #include "oops/symbol.hpp" 32 #include "runtime/atomic.inline.hpp" 33 #include "runtime/os.hpp" 34 35 Symbol::Symbol(const u1* name, int length, int refcount) { 36 _refcount = refcount; 37 _length = length; 38 _identity_hash = (short)os::random(); 39 for (int i = 0; i < _length; i++) { 40 byte_at_put(i, name[i]); 41 } 42 } 43 44 void* Symbol::operator new(size_t sz, int len, TRAPS) throw() { 45 int alloc_size = size(len)*HeapWordSize; 46 address res = (address) AllocateHeap(alloc_size, mtSymbol); 47 return res; 48 } 49 50 void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) throw() { 51 int alloc_size = size(len)*HeapWordSize; 52 address res = (address)arena->Amalloc(alloc_size); 53 return res; 54 } 55 56 void* Symbol::operator new(size_t sz, int len, ClassLoaderData* loader_data, TRAPS) throw() { 57 address res; 58 int alloc_size = size(len)*HeapWordSize; 59 res = (address) Metaspace::allocate(loader_data, size(len), true, 60 MetaspaceObj::SymbolType, CHECK_NULL); 61 return res; 62 } 63 64 void Symbol::operator delete(void *p) { 65 assert(((Symbol*)p)->refcount() == 0, "should not call this"); 66 FreeHeap(p); 67 } 68 69 // ------------------------------------------------------------------ 70 // Symbol::equals 71 // 72 // Compares the symbol with a string of the given length. 73 bool Symbol::equals(const char* str, int len) const { 74 int l = utf8_length(); 75 if (l != len) return false; 76 while (l-- > 0) { 77 if (str[l] != (char) byte_at(l)) 78 return false; | 25 26 #include "precompiled.hpp" 27 #include "classfile/altHashing.hpp" 28 #include "classfile/classLoaderData.hpp" 29 #include "memory/allocation.inline.hpp" 30 #include "memory/resourceArea.hpp" 31 #include "oops/symbol.hpp" 32 #include "runtime/atomic.inline.hpp" 33 #include "runtime/os.hpp" 34 35 Symbol::Symbol(const u1* name, int length, int refcount) { 36 _refcount = refcount; 37 _length = length; 38 _identity_hash = (short)os::random(); 39 for (int i = 0; i < _length; i++) { 40 byte_at_put(i, name[i]); 41 } 42 } 43 44 void* Symbol::operator new(size_t sz, int len, TRAPS) throw() { 45 int alloc_size = size(len)*wordSize; 46 address res = (address) AllocateHeap(alloc_size, mtSymbol); 47 return res; 48 } 49 50 void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) throw() { 51 int alloc_size = size(len)*wordSize; 52 address res = (address)arena->Amalloc_4(alloc_size); 53 return res; 54 } 55 56 void* Symbol::operator new(size_t sz, int len, ClassLoaderData* loader_data, TRAPS) throw() { 57 address res; 58 res = (address) Metaspace::allocate(loader_data, size(len), true, 59 MetaspaceObj::SymbolType, CHECK_NULL); 60 return res; 61 } 62 63 void Symbol::operator delete(void *p) { 64 assert(((Symbol*)p)->refcount() == 0, "should not call this"); 65 FreeHeap(p); 66 } 67 68 // ------------------------------------------------------------------ 69 // Symbol::equals 70 // 71 // Compares the symbol with a string of the given length. 72 bool Symbol::equals(const char* str, int len) const { 73 int l = utf8_length(); 74 if (l != len) return false; 75 while (l-- > 0) { 76 if (str[l] != (char) byte_at(l)) 77 return false; |