hotspot/src/share/vm/utilities/hashtable.cpp
changeset 46475 75902cea18af
parent 46435 3f6cac9867d4
child 46488 01c282163d38
equal deleted inserted replaced
46474:c872a196b75f 46475:75902cea18af
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "classfile/altHashing.hpp"
    26 #include "classfile/altHashing.hpp"
       
    27 #include "classfile/dictionary.hpp"
    27 #include "classfile/javaClasses.inline.hpp"
    28 #include "classfile/javaClasses.inline.hpp"
       
    29 #include "classfile/moduleEntry.hpp"
       
    30 #include "classfile/packageEntry.hpp"
       
    31 #include "classfile/protectionDomainCache.hpp"
    28 #include "classfile/stringTable.hpp"
    32 #include "classfile/stringTable.hpp"
    29 #include "memory/allocation.inline.hpp"
    33 #include "memory/allocation.inline.hpp"
    30 #include "memory/filemap.hpp"
    34 #include "memory/filemap.hpp"
    31 #include "memory/resourceArea.hpp"
    35 #include "memory/resourceArea.hpp"
    32 #include "oops/oop.inline.hpp"
    36 #include "oops/oop.inline.hpp"
   274     }
   278     }
   275   }
   279   }
   276 }
   280 }
   277 
   281 
   278 
   282 
   279 template <MEMFLAGS F> void BasicHashtable<F>::verify() {
   283 template <MEMFLAGS F>
   280   int count = 0;
   284 template <class T> void BasicHashtable<F>::verify_table(const char* table_name) {
   281   for (int i = 0; i < table_size(); i++) {
   285   int element_count = 0;
   282     for (BasicHashtableEntry<F>* p = bucket(i); p != NULL; p = p->next()) {
   286   int max_bucket_count = 0;
   283       ++count;
   287   for (int index = 0; index < table_size(); index++) {
   284     }
   288     int bucket_count = 0;
   285   }
   289     for (T* probe = (T*)bucket(index); probe != NULL; probe = probe->next()) {
   286   assert(count == number_of_entries(), "number of hashtable entries incorrect");
   290       probe->verify();
       
   291       bucket_count++;
       
   292     }
       
   293     element_count += bucket_count;
       
   294     max_bucket_count = MAX2(max_bucket_count, bucket_count);
       
   295   }
       
   296   guarantee(number_of_entries() == element_count,
       
   297             "Verify of %s failed", table_name);
       
   298   DEBUG_ONLY(verify_lookup_length(max_bucket_count, table_name));
   287 }
   299 }
   288 
   300 
   289 
   301 
   290 #endif // PRODUCT
   302 #endif // PRODUCT
   291 
   303 
   292 #ifdef ASSERT
   304 #ifdef ASSERT
   293 
   305 
   294 template <MEMFLAGS F> bool BasicHashtable<F>::verify_lookup_length(double load, const char *table_name) {
   306 // Assert if the longest bucket is 10x longer than the average bucket size.
   295   if ((!_lookup_warning) && (_lookup_count != 0)
   307 // Could change back to a warning, but warnings are not noticed.
   296       && ((double)_lookup_length / (double)_lookup_count > load * 2.0)) {
   308 template <MEMFLAGS F> void BasicHashtable<F>::verify_lookup_length(int max_bucket_count, const char *table_name) {
   297     warning("Performance bug: %s lookup_count=%d "
   309   log_info(hashtables)("%s max bucket size %d element count %d table size %d", table_name,
   298             "lookup_length=%d average=%lf load=%f",
   310                        max_bucket_count, _number_of_entries, _table_size);
   299             table_name, _lookup_count, _lookup_length,
   311   assert (max_bucket_count < ((1 + number_of_entries()/table_size())*10), "Table is unbalanced");
   300             (double)_lookup_length / _lookup_count, load);
       
   301     _lookup_warning = true;
       
   302 
       
   303     return false;
       
   304   }
       
   305   return true;
       
   306 }
   312 }
   307 
   313 
   308 #endif
   314 #endif
   309 
   315 
   310 
   316 
   342 template class Hashtable<Symbol*, mtTracing>;
   348 template class Hashtable<Symbol*, mtTracing>;
   343 template class HashtableEntry<Symbol*, mtTracing>;
   349 template class HashtableEntry<Symbol*, mtTracing>;
   344 template class BasicHashtable<mtTracing>;
   350 template class BasicHashtable<mtTracing>;
   345 #endif
   351 #endif
   346 template class BasicHashtable<mtCompiler>;
   352 template class BasicHashtable<mtCompiler>;
       
   353 
       
   354 template void BasicHashtable<mtClass>::verify_table<DictionaryEntry>(char const*);
       
   355 template void BasicHashtable<mtModule>::verify_table<ModuleEntry>(char const*);
       
   356 template void BasicHashtable<mtModule>::verify_table<PackageEntry>(char const*);
       
   357 template void BasicHashtable<mtClass>::verify_table<ProtectionDomainCacheEntry>(char const*);