src/share/vm/oops/symbol.cpp

changeset 4037
da91efe96a93
parent 3969
1d7922586cf6
child 4267
bd7a7ce2e264
     1.1 --- a/src/share/vm/oops/symbol.cpp	Fri Aug 31 16:39:35 2012 -0700
     1.2 +++ b/src/share/vm/oops/symbol.cpp	Sat Sep 01 13:25:18 2012 -0400
     1.3 @@ -24,10 +24,12 @@
     1.4  
     1.5  
     1.6  #include "precompiled.hpp"
     1.7 -#include "oops/oop.inline.hpp"
     1.8 +#include "classfile/altHashing.hpp"
     1.9 +#include "classfile/classLoaderData.hpp"
    1.10  #include "oops/symbol.hpp"
    1.11  #include "runtime/os.hpp"
    1.12  #include "memory/allocation.inline.hpp"
    1.13 +#include "memory/resourceArea.hpp"
    1.14  
    1.15  Symbol::Symbol(const u1* name, int length, int refcount) : _refcount(refcount), _length(length) {
    1.16    _identity_hash = os::random();
    1.17 @@ -37,19 +39,30 @@
    1.18  }
    1.19  
    1.20  void* Symbol::operator new(size_t sz, int len, TRAPS) {
    1.21 -  int alloc_size = object_size(len)*HeapWordSize;
    1.22 +  int alloc_size = size(len)*HeapWordSize;
    1.23    address res = (address) AllocateHeap(alloc_size, mtSymbol);
    1.24 -  DEBUG_ONLY(set_allocation_type(res, ResourceObj::C_HEAP);)
    1.25    return res;
    1.26  }
    1.27  
    1.28  void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) {
    1.29 -  int alloc_size = object_size(len)*HeapWordSize;
    1.30 +  int alloc_size = size(len)*HeapWordSize;
    1.31    address res = (address)arena->Amalloc(alloc_size);
    1.32 -  DEBUG_ONLY(set_allocation_type(res, ResourceObj::ARENA);)
    1.33    return res;
    1.34  }
    1.35  
    1.36 +void* Symbol::operator new(size_t sz, int len, ClassLoaderData* loader_data, TRAPS) {
    1.37 +  address res;
    1.38 +  int alloc_size = size(len)*HeapWordSize;
    1.39 +  res = (address) Metaspace::allocate(loader_data, size(len), true,
    1.40 +                                      Metaspace::NonClassType, CHECK_NULL);
    1.41 +  return res;
    1.42 +}
    1.43 +
    1.44 +void Symbol::operator delete(void *p) {
    1.45 +  assert(((Symbol*)p)->refcount() == 0, "should not call this");
    1.46 +  FreeHeap(p);
    1.47 +}
    1.48 +
    1.49  // ------------------------------------------------------------------
    1.50  // Symbol::equals
    1.51  //
    1.52 @@ -191,6 +204,12 @@
    1.53    return str;
    1.54  }
    1.55  
    1.56 +// Alternate hashing for unbalanced symbol tables.
    1.57 +unsigned int Symbol::new_hash(jint seed) {
    1.58 +  ResourceMark rm;
    1.59 +  // Use alternate hashing algorithm on this symbol.
    1.60 +  return AltHashing::murmur3_32(seed, (const jbyte*)as_C_string(), utf8_length());
    1.61 +}
    1.62  
    1.63  void Symbol::print_on(outputStream* st) const {
    1.64    if (this == NULL) {

mercurial