< prev index next >

src/share/vm/gc/g1/g1CodeCacheRemSet.cpp

Print this page
rev 11782 : 8164230: Convert TestCodeCacheRemSet_test to GTest
Reviewed-by: duke

*** 23,85 **** */ #include "precompiled.hpp" #include "code/codeCache.hpp" #include "code/nmethod.hpp" #include "gc/g1/g1CodeCacheRemSet.hpp" #include "gc/g1/heapRegion.hpp" #include "memory/heap.hpp" #include "memory/iterator.hpp" #include "oops/oop.inline.hpp" #include "utilities/hashtable.inline.hpp" #include "utilities/stack.inline.hpp" - class CodeRootSetTable : public Hashtable<nmethod*, mtGC> { - friend class G1CodeRootSetTest; - typedef HashtableEntry<nmethod*, mtGC> Entry; - - static CodeRootSetTable* volatile _purge_list; - - CodeRootSetTable* _purge_next; - - unsigned int compute_hash(nmethod* nm) { - uintptr_t hash = (uintptr_t)nm; - return hash ^ (hash >> 7); // code heap blocks are 128byte aligned - } - - void remove_entry(Entry* e, Entry* previous); - Entry* new_entry(nmethod* nm); - - public: - CodeRootSetTable(int size) : Hashtable<nmethod*, mtGC>(size, sizeof(Entry)), _purge_next(NULL) {} - ~CodeRootSetTable(); - - // Needs to be protected locks - bool add(nmethod* nm); - bool remove(nmethod* nm); - - // Can be called without locking - bool contains(nmethod* nm); - - int entry_size() const { return BasicHashtable<mtGC>::entry_size(); } - - void copy_to(CodeRootSetTable* new_table); - void nmethods_do(CodeBlobClosure* blk); - - template<typename CB> - int remove_if(CB& should_remove); - - static void purge_list_append(CodeRootSetTable* tbl); - static void purge(); - - static size_t static_mem_size() { - return sizeof(_purge_list); - } - - size_t mem_size(); - }; - CodeRootSetTable* volatile CodeRootSetTable::_purge_list = NULL; size_t CodeRootSetTable::mem_size() { return sizeof(CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size()); } --- 23,41 ---- */ #include "precompiled.hpp" #include "code/codeCache.hpp" #include "code/nmethod.hpp" + #include "gc/g1/g1CodeCacheRemSet.internal.hpp" #include "gc/g1/g1CodeCacheRemSet.hpp" #include "gc/g1/heapRegion.hpp" #include "memory/heap.hpp" #include "memory/iterator.hpp" #include "oops/oop.inline.hpp" #include "utilities/hashtable.inline.hpp" #include "utilities/stack.inline.hpp" CodeRootSetTable* volatile CodeRootSetTable::_purge_list = NULL; size_t CodeRootSetTable::mem_size() { return sizeof(CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size()); }
*** 346,414 **** } if (_length == 0) { clear(); } } - - #ifndef PRODUCT - - class G1CodeRootSetTest { - public: - static void test() { - { - G1CodeRootSet set1; - assert(set1.is_empty(), "Code root set must be initially empty but is not."); - - assert(G1CodeRootSet::static_mem_size() == sizeof(void*), - "The code root set's static memory usage is incorrect, " SIZE_FORMAT " bytes", G1CodeRootSet::static_mem_size()); - - set1.add((nmethod*)1); - assert(set1.length() == 1, "Added exactly one element, but set contains " - SIZE_FORMAT " elements", set1.length()); - - const size_t num_to_add = (size_t)G1CodeRootSet::Threshold + 1; - - for (size_t i = 1; i <= num_to_add; i++) { - set1.add((nmethod*)1); - } - assert(set1.length() == 1, - "Duplicate detection should not have increased the set size but " - "is " SIZE_FORMAT, set1.length()); - - for (size_t i = 2; i <= num_to_add; i++) { - set1.add((nmethod*)(uintptr_t)(i)); - } - assert(set1.length() == num_to_add, - "After adding in total " SIZE_FORMAT " distinct code roots, they " - "need to be in the set, but there are only " SIZE_FORMAT, - num_to_add, set1.length()); - - assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable"); - - size_t num_popped = 0; - for (size_t i = 1; i <= num_to_add; i++) { - bool removed = set1.remove((nmethod*)i); - if (removed) { - num_popped += 1; - } else { - break; - } - } - assert(num_popped == num_to_add, - "Managed to pop " SIZE_FORMAT " code roots, but only " SIZE_FORMAT " " - "were added", num_popped, num_to_add); - assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable"); - - G1CodeRootSet::purge(); - - assert(CodeRootSetTable::_purge_list == NULL, "should have purged old small tables"); - - } - - } - }; - - void TestCodeCacheRemSet_test() { - G1CodeRootSetTest::test(); - } - - #endif --- 302,306 ----
< prev index next >