changeset 2273:352622fd140a

7032129: Native memory usage grow unexpectedly for vm/oom/*InternedString tests Reviewed-by: kvn, kamg, jcoomes
author never
date Thu, 31 Mar 2011 14:00:41 -0700
parents 38fea01eb669
children 2a5104162671
files src/share/vm/classfile/javaClasses.cpp src/share/vm/classfile/javaClasses.hpp src/share/vm/classfile/symbolTable.cpp src/share/vm/classfile/symbolTable.hpp src/share/vm/memory/dump.cpp
diffstat 5 files changed, 40 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/javaClasses.cpp	Thu Mar 31 02:31:57 2011 -0700
+++ b/src/share/vm/classfile/javaClasses.cpp	Thu Mar 31 14:00:41 2011 -0700
@@ -301,6 +301,15 @@
   return result;
 }
 
+unsigned int java_lang_String::hash_string(oop java_string) {
+  typeArrayOop value  = java_lang_String::value(java_string);
+  int          offset = java_lang_String::offset(java_string);
+  int          length = java_lang_String::length(java_string);
+
+  if (length == 0) return 0;
+  return hash_string(value->char_at_addr(offset), length);
+}
+
 Symbol* java_lang_String::as_symbol(Handle java_string, TRAPS) {
   oop          obj    = java_string();
   typeArrayOop value  = java_lang_String::value(obj);
--- a/src/share/vm/classfile/javaClasses.hpp	Thu Mar 31 02:31:57 2011 -0700
+++ b/src/share/vm/classfile/javaClasses.hpp	Thu Mar 31 14:00:41 2011 -0700
@@ -109,6 +109,30 @@
   static char*  as_platform_dependent_str(Handle java_string, TRAPS);
   static jchar* as_unicode_string(oop java_string, int& length);
 
+  // Compute the hash value for a java.lang.String object which would
+  // contain the characters passed in. This hash value is used for at
+  // least two purposes.
+  //
+  // (a) As the hash value used by the StringTable for bucket selection
+  //     and comparison (stored in the HashtableEntry structures).  This
+  //     is used in the String.intern() method.
+  //
+  // (b) As the hash value used by the String object itself, in
+  //     String.hashCode().  This value is normally calculate in Java code
+  //     in the String.hashCode method(), but is precomputed for String
+  //     objects in the shared archive file.
+  //
+  //     For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
+  static unsigned int hash_string(jchar* s, int len) {
+    unsigned int h = 0;
+    while (len-- > 0) {
+      h = 31*h + (unsigned int) *s;
+      s++;
+    }
+    return h;
+  }
+  static unsigned int hash_string(oop java_string);
+
   static bool equals(oop java_string, jchar* chars, int len);
 
   // Conversion between '.' and '/' formats
--- a/src/share/vm/classfile/symbolTable.cpp	Thu Mar 31 02:31:57 2011 -0700
+++ b/src/share/vm/classfile/symbolTable.cpp	Thu Mar 31 14:00:41 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -480,33 +480,6 @@
 
 
 // --------------------------------------------------------------------------
-
-
-// Compute the hash value for a java.lang.String object which would
-// contain the characters passed in. This hash value is used for at
-// least two purposes.
-//
-// (a) As the hash value used by the StringTable for bucket selection
-//     and comparison (stored in the HashtableEntry structures).  This
-//     is used in the String.intern() method.
-//
-// (b) As the hash value used by the String object itself, in
-//     String.hashCode().  This value is normally calculate in Java code
-//     in the String.hashCode method(), but is precomputed for String
-//     objects in the shared archive file.
-//
-//     For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
-
-int StringTable::hash_string(jchar* s, int len) {
-  unsigned h = 0;
-  while (len-- > 0) {
-    h = 31*h + (unsigned) *s;
-    s++;
-  }
-  return h;
-}
-
-
 StringTable* StringTable::_the_table = NULL;
 
 oop StringTable::lookup(int index, jchar* name,
@@ -561,7 +534,7 @@
   ResourceMark rm;
   int length;
   jchar* chars = symbol->as_unicode(length);
-  unsigned int hashValue = hash_string(chars, length);
+  unsigned int hashValue = java_lang_String::hash_string(chars, length);
   int index = the_table()->hash_to_index(hashValue);
   return the_table()->lookup(index, chars, length, hashValue);
 }
@@ -569,7 +542,7 @@
 
 oop StringTable::intern(Handle string_or_null, jchar* name,
                         int len, TRAPS) {
-  unsigned int hashValue = hash_string(name, len);
+  unsigned int hashValue = java_lang_String::hash_string(name, len);
   int index = the_table()->hash_to_index(hashValue);
   oop string = the_table()->lookup(index, name, len, hashValue);
 
@@ -663,10 +636,7 @@
       oop s = p->literal();
       guarantee(s != NULL, "interned string is NULL");
       guarantee(s->is_perm() || !JavaObjectsInPerm, "interned string not in permspace");
-
-      int length;
-      jchar* chars = java_lang_String::as_unicode_string(s, length);
-      unsigned int h = hash_string(chars, length);
+      unsigned int h = java_lang_String::hash_string(s);
       guarantee(p->hash() == h, "broken hash in string table entry");
       guarantee(the_table()->hash_to_index(h) == i,
                 "wrong index in string table");
--- a/src/share/vm/classfile/symbolTable.hpp	Thu Mar 31 02:31:57 2011 -0700
+++ b/src/share/vm/classfile/symbolTable.hpp	Thu Mar 31 14:00:41 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -242,8 +242,6 @@
     _the_table = new StringTable(t, number_of_entries);
   }
 
-  static int hash_string(jchar* s, int len);
-
   // GC support
   //   Delete pointers to otherwise-unreachable objects.
   static void unlink(BoolObjectClosure* cl);
--- a/src/share/vm/memory/dump.cpp	Thu Mar 31 02:31:57 2011 -0700
+++ b/src/share/vm/memory/dump.cpp	Thu Mar 31 14:00:41 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,16 +80,7 @@
       oop obj = *p;
       if (obj->klass() == SystemDictionary::String_klass()) {
 
-        int hash;
-        typeArrayOop value = java_lang_String::value(obj);
-        int length = java_lang_String::length(obj);
-        if (length == 0) {
-          hash = 0;
-        } else {
-          int offset = java_lang_String::offset(obj);
-          jchar* s = value->char_at_addr(offset);
-          hash = StringTable::hash_string(s, length);
-        }
+        int hash = java_lang_String::hash_string(obj);
         obj->int_field_put(hash_offset, hash);
       }
     }