8176593: Throwable::getStackTrace performance regression

Reviewed-by: jiangli, iklam, coleenp, sspitsyn
This commit is contained in:
Claes Redestad 2017-03-15 13:03:13 +01:00
parent 1cd78903a8
commit c40d2d5af7
2 changed files with 32 additions and 22 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -96,10 +96,14 @@ CompactHashtable<oop, char> StringTable::_shared_table;
// Pick hashing algorithm // Pick hashing algorithm
unsigned int StringTable::hash_string(const jchar* s, int len) { unsigned int StringTable::hash_string(const jchar* s, int len) {
return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) : return use_alternate_hashcode() ? alt_hash_string(s, len) :
java_lang_String::hash_code(s, len); java_lang_String::hash_code(s, len);
} }
unsigned int StringTable::alt_hash_string(const jchar* s, int len) {
return AltHashing::murmur3_32(seed(), s, len);
}
unsigned int StringTable::hash_string(oop string) { unsigned int StringTable::hash_string(oop string) {
EXCEPTION_MARK; EXCEPTION_MARK;
if (string == NULL) { if (string == NULL) {
@ -117,11 +121,10 @@ unsigned int StringTable::hash_string(oop string) {
} }
} }
oop StringTable::lookup_shared(jchar* name, int len) { oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) {
// java_lang_String::hash_code() was used to compute hash values in the shared table. Don't assert(hash == java_lang_String::hash_code(name, len),
// use the hash value from StringTable::hash_string() as it might use alternate hashcode. "hash must be computed using java_lang_String::hash_code");
return _shared_table.lookup((const char*)name, return _shared_table.lookup((const char*)name, hash, len);
java_lang_String::hash_code(name, len), len);
} }
oop StringTable::lookup_in_main_table(int index, jchar* name, oop StringTable::lookup_in_main_table(int index, jchar* name,
@ -156,7 +159,7 @@ oop StringTable::basic_add(int index_arg, Handle string, jchar* name,
unsigned int hashValue; unsigned int hashValue;
int index; int index;
if (use_alternate_hashcode()) { if (use_alternate_hashcode()) {
hashValue = hash_string(name, len); hashValue = alt_hash_string(name, len);
index = hash_to_index(hashValue); index = hash_to_index(hashValue);
} else { } else {
hashValue = hashValue_arg; hashValue = hashValue_arg;
@ -199,12 +202,15 @@ static void ensure_string_alive(oop string) {
} }
oop StringTable::lookup(jchar* name, int len) { oop StringTable::lookup(jchar* name, int len) {
oop string = lookup_shared(name, len); // shared table always uses java_lang_String::hash_code
unsigned int hash = java_lang_String::hash_code(name, len);
oop string = lookup_shared(name, len, hash);
if (string != NULL) { if (string != NULL) {
return string; return string;
} }
if (use_alternate_hashcode()) {
unsigned int hash = hash_string(name, len); hash = alt_hash_string(name, len);
}
int index = the_table()->hash_to_index(hash); int index = the_table()->hash_to_index(hash);
string = the_table()->lookup_in_main_table(index, name, len, hash); string = the_table()->lookup_in_main_table(index, name, len, hash);
@ -215,12 +221,15 @@ oop StringTable::lookup(jchar* name, int len) {
oop StringTable::intern(Handle string_or_null, jchar* name, oop StringTable::intern(Handle string_or_null, jchar* name,
int len, TRAPS) { int len, TRAPS) {
oop found_string = lookup_shared(name, len); // shared table always uses java_lang_String::hash_code
unsigned int hashValue = java_lang_String::hash_code(name, len);
oop found_string = lookup_shared(name, len, hashValue);
if (found_string != NULL) { if (found_string != NULL) {
return found_string; return found_string;
} }
if (use_alternate_hashcode()) {
unsigned int hashValue = hash_string(name, len); hashValue = alt_hash_string(name, len);
}
int index = the_table()->hash_to_index(hashValue); int index = the_table()->hash_to_index(hashValue);
found_string = the_table()->lookup_in_main_table(index, name, len, hashValue); found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -56,7 +56,7 @@ private:
unsigned int hashValue, TRAPS); unsigned int hashValue, TRAPS);
oop lookup_in_main_table(int index, jchar* chars, int length, unsigned int hashValue); oop lookup_in_main_table(int index, jchar* chars, int length, unsigned int hashValue);
static oop lookup_shared(jchar* name, int len); static oop lookup_shared(jchar* name, int len, unsigned int hash);
// Apply the give oop closure to the entries to the buckets // Apply the give oop closure to the entries to the buckets
// in the range [start_idx, end_idx). // in the range [start_idx, end_idx).
@ -65,6 +65,13 @@ private:
// in the range [start_idx, end_idx). // in the range [start_idx, end_idx).
static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed); static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed);
// Hashing algorithm, used 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.
static unsigned int hash_string(const jchar* s, int len);
static unsigned int hash_string(oop string);
static unsigned int alt_hash_string(const jchar* s, int len);
StringTable() : RehashableHashtable<oop, mtSymbol>((int)StringTableSize, StringTable() : RehashableHashtable<oop, mtSymbol>((int)StringTableSize,
sizeof (HashtableEntry<oop, mtSymbol>)) {} sizeof (HashtableEntry<oop, mtSymbol>)) {}
@ -109,12 +116,6 @@ public:
} }
static void possibly_parallel_oops_do(OopClosure* f); static void possibly_parallel_oops_do(OopClosure* f);
// Hashing algorithm, used 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.
static unsigned int hash_string(const jchar* s, int len);
static unsigned int hash_string(oop string);
// Internal test. // Internal test.
static void test_alt_hash() PRODUCT_RETURN; static void test_alt_hash() PRODUCT_RETURN;