diff src/share/vm/oops/symbol.cpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 1d7922586cf6
children bd7a7ce2e264
line wrap: on
line diff
--- a/src/share/vm/oops/symbol.cpp	Fri Aug 31 16:39:35 2012 -0700
+++ b/src/share/vm/oops/symbol.cpp	Sat Sep 01 13:25:18 2012 -0400
@@ -24,10 +24,12 @@
 
 
 #include "precompiled.hpp"
-#include "oops/oop.inline.hpp"
+#include "classfile/altHashing.hpp"
+#include "classfile/classLoaderData.hpp"
 #include "oops/symbol.hpp"
 #include "runtime/os.hpp"
 #include "memory/allocation.inline.hpp"
+#include "memory/resourceArea.hpp"
 
 Symbol::Symbol(const u1* name, int length, int refcount) : _refcount(refcount), _length(length) {
   _identity_hash = os::random();
@@ -37,19 +39,30 @@
 }
 
 void* Symbol::operator new(size_t sz, int len, TRAPS) {
-  int alloc_size = object_size(len)*HeapWordSize;
+  int alloc_size = size(len)*HeapWordSize;
   address res = (address) AllocateHeap(alloc_size, mtSymbol);
-  DEBUG_ONLY(set_allocation_type(res, ResourceObj::C_HEAP);)
   return res;
 }
 
 void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) {
-  int alloc_size = object_size(len)*HeapWordSize;
+  int alloc_size = size(len)*HeapWordSize;
   address res = (address)arena->Amalloc(alloc_size);
-  DEBUG_ONLY(set_allocation_type(res, ResourceObj::ARENA);)
   return res;
 }
 
+void* Symbol::operator new(size_t sz, int len, ClassLoaderData* loader_data, TRAPS) {
+  address res;
+  int alloc_size = size(len)*HeapWordSize;
+  res = (address) Metaspace::allocate(loader_data, size(len), true,
+                                      Metaspace::NonClassType, CHECK_NULL);
+  return res;
+}
+
+void Symbol::operator delete(void *p) {
+  assert(((Symbol*)p)->refcount() == 0, "should not call this");
+  FreeHeap(p);
+}
+
 // ------------------------------------------------------------------
 // Symbol::equals
 //
@@ -191,6 +204,12 @@
   return str;
 }
 
+// Alternate hashing for unbalanced symbol tables.
+unsigned int Symbol::new_hash(jint seed) {
+  ResourceMark rm;
+  // Use alternate hashing algorithm on this symbol.
+  return AltHashing::murmur3_32(seed, (const jbyte*)as_C_string(), utf8_length());
+}
 
 void Symbol::print_on(outputStream* st) const {
   if (this == NULL) {