Thu, 31 Mar 2011 14:00:41 -0700
7032129: Native memory usage grow unexpectedly for vm/oom/*InternedString tests
Reviewed-by: kvn, kamg, jcoomes
1.1 --- a/src/share/vm/classfile/javaClasses.cpp Thu Mar 31 02:31:57 2011 -0700 1.2 +++ b/src/share/vm/classfile/javaClasses.cpp Thu Mar 31 14:00:41 2011 -0700 1.3 @@ -301,6 +301,15 @@ 1.4 return result; 1.5 } 1.6 1.7 +unsigned int java_lang_String::hash_string(oop java_string) { 1.8 + typeArrayOop value = java_lang_String::value(java_string); 1.9 + int offset = java_lang_String::offset(java_string); 1.10 + int length = java_lang_String::length(java_string); 1.11 + 1.12 + if (length == 0) return 0; 1.13 + return hash_string(value->char_at_addr(offset), length); 1.14 +} 1.15 + 1.16 Symbol* java_lang_String::as_symbol(Handle java_string, TRAPS) { 1.17 oop obj = java_string(); 1.18 typeArrayOop value = java_lang_String::value(obj);
2.1 --- a/src/share/vm/classfile/javaClasses.hpp Thu Mar 31 02:31:57 2011 -0700 2.2 +++ b/src/share/vm/classfile/javaClasses.hpp Thu Mar 31 14:00:41 2011 -0700 2.3 @@ -109,6 +109,30 @@ 2.4 static char* as_platform_dependent_str(Handle java_string, TRAPS); 2.5 static jchar* as_unicode_string(oop java_string, int& length); 2.6 2.7 + // Compute the hash value for a java.lang.String object which would 2.8 + // contain the characters passed in. This hash value is used for at 2.9 + // least two purposes. 2.10 + // 2.11 + // (a) As the hash value used by the StringTable for bucket selection 2.12 + // and comparison (stored in the HashtableEntry structures). This 2.13 + // is used in the String.intern() method. 2.14 + // 2.15 + // (b) As the hash value used by the String object itself, in 2.16 + // String.hashCode(). This value is normally calculate in Java code 2.17 + // in the String.hashCode method(), but is precomputed for String 2.18 + // objects in the shared archive file. 2.19 + // 2.20 + // For this reason, THIS ALGORITHM MUST MATCH String.hashCode(). 2.21 + static unsigned int hash_string(jchar* s, int len) { 2.22 + unsigned int h = 0; 2.23 + while (len-- > 0) { 2.24 + h = 31*h + (unsigned int) *s; 2.25 + s++; 2.26 + } 2.27 + return h; 2.28 + } 2.29 + static unsigned int hash_string(oop java_string); 2.30 + 2.31 static bool equals(oop java_string, jchar* chars, int len); 2.32 2.33 // Conversion between '.' and '/' formats
3.1 --- a/src/share/vm/classfile/symbolTable.cpp Thu Mar 31 02:31:57 2011 -0700 3.2 +++ b/src/share/vm/classfile/symbolTable.cpp Thu Mar 31 14:00:41 2011 -0700 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -480,33 +480,6 @@ 3.11 3.12 3.13 // -------------------------------------------------------------------------- 3.14 - 3.15 - 3.16 -// Compute the hash value for a java.lang.String object which would 3.17 -// contain the characters passed in. This hash value is used for at 3.18 -// least two purposes. 3.19 -// 3.20 -// (a) As the hash value used by the StringTable for bucket selection 3.21 -// and comparison (stored in the HashtableEntry structures). This 3.22 -// is used in the String.intern() method. 3.23 -// 3.24 -// (b) As the hash value used by the String object itself, in 3.25 -// String.hashCode(). This value is normally calculate in Java code 3.26 -// in the String.hashCode method(), but is precomputed for String 3.27 -// objects in the shared archive file. 3.28 -// 3.29 -// For this reason, THIS ALGORITHM MUST MATCH String.hashCode(). 3.30 - 3.31 -int StringTable::hash_string(jchar* s, int len) { 3.32 - unsigned h = 0; 3.33 - while (len-- > 0) { 3.34 - h = 31*h + (unsigned) *s; 3.35 - s++; 3.36 - } 3.37 - return h; 3.38 -} 3.39 - 3.40 - 3.41 StringTable* StringTable::_the_table = NULL; 3.42 3.43 oop StringTable::lookup(int index, jchar* name, 3.44 @@ -561,7 +534,7 @@ 3.45 ResourceMark rm; 3.46 int length; 3.47 jchar* chars = symbol->as_unicode(length); 3.48 - unsigned int hashValue = hash_string(chars, length); 3.49 + unsigned int hashValue = java_lang_String::hash_string(chars, length); 3.50 int index = the_table()->hash_to_index(hashValue); 3.51 return the_table()->lookup(index, chars, length, hashValue); 3.52 } 3.53 @@ -569,7 +542,7 @@ 3.54 3.55 oop StringTable::intern(Handle string_or_null, jchar* name, 3.56 int len, TRAPS) { 3.57 - unsigned int hashValue = hash_string(name, len); 3.58 + unsigned int hashValue = java_lang_String::hash_string(name, len); 3.59 int index = the_table()->hash_to_index(hashValue); 3.60 oop string = the_table()->lookup(index, name, len, hashValue); 3.61 3.62 @@ -663,10 +636,7 @@ 3.63 oop s = p->literal(); 3.64 guarantee(s != NULL, "interned string is NULL"); 3.65 guarantee(s->is_perm() || !JavaObjectsInPerm, "interned string not in permspace"); 3.66 - 3.67 - int length; 3.68 - jchar* chars = java_lang_String::as_unicode_string(s, length); 3.69 - unsigned int h = hash_string(chars, length); 3.70 + unsigned int h = java_lang_String::hash_string(s); 3.71 guarantee(p->hash() == h, "broken hash in string table entry"); 3.72 guarantee(the_table()->hash_to_index(h) == i, 3.73 "wrong index in string table");
4.1 --- a/src/share/vm/classfile/symbolTable.hpp Thu Mar 31 02:31:57 2011 -0700 4.2 +++ b/src/share/vm/classfile/symbolTable.hpp Thu Mar 31 14:00:41 2011 -0700 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -242,8 +242,6 @@ 4.11 _the_table = new StringTable(t, number_of_entries); 4.12 } 4.13 4.14 - static int hash_string(jchar* s, int len); 4.15 - 4.16 // GC support 4.17 // Delete pointers to otherwise-unreachable objects. 4.18 static void unlink(BoolObjectClosure* cl);
5.1 --- a/src/share/vm/memory/dump.cpp Thu Mar 31 02:31:57 2011 -0700 5.2 +++ b/src/share/vm/memory/dump.cpp Thu Mar 31 14:00:41 2011 -0700 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 5.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 5.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.8 * 5.9 * This code is free software; you can redistribute it and/or modify it 5.10 @@ -80,16 +80,7 @@ 5.11 oop obj = *p; 5.12 if (obj->klass() == SystemDictionary::String_klass()) { 5.13 5.14 - int hash; 5.15 - typeArrayOop value = java_lang_String::value(obj); 5.16 - int length = java_lang_String::length(obj); 5.17 - if (length == 0) { 5.18 - hash = 0; 5.19 - } else { 5.20 - int offset = java_lang_String::offset(obj); 5.21 - jchar* s = value->char_at_addr(offset); 5.22 - hash = StringTable::hash_string(s, length); 5.23 - } 5.24 + int hash = java_lang_String::hash_string(obj); 5.25 obj->int_field_put(hash_offset, hash); 5.26 } 5.27 }