Path: blob/master/test/hotspot/gtest/gc/g1/test_g1CodeCacheRemSet.cpp
41152 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/g1/g1CodeRootSetTable.hpp"25#include "gc/g1/g1CodeCacheRemSet.hpp"26#include "unittest.hpp"2728class G1CodeRootSetTest : public ::testing::Test {29public:3031size_t threshold() {32return G1CodeRootSet::Threshold;33}3435G1CodeRootSetTable* purge_list() {36return G1CodeRootSetTable::_purge_list;37}38};3940TEST_VM_F(G1CodeRootSetTest, g1_code_cache_rem_set) {41G1CodeRootSet root_set;4243ASSERT_TRUE(root_set.is_empty()) << "Code root set must be initially empty "44"but is not.";4546ASSERT_EQ(G1CodeRootSet::static_mem_size(), sizeof (void*)) <<47"The code root set's static memory usage is incorrect, "48<< G1CodeRootSet::static_mem_size() << " bytes";4950root_set.add((nmethod*) 1);51ASSERT_EQ(root_set.length(), (size_t) 1) << "Added exactly one element, but"52" set contains " << root_set.length() << " elements";5354const size_t num_to_add = (size_t) threshold() + 1;5556for (size_t i = 1; i <= num_to_add; i++) {57root_set.add((nmethod*) 1);58}59ASSERT_EQ(root_set.length(), (size_t) 1)60<< "Duplicate detection should not have increased the set size but "61<< "is " << root_set.length();6263for (size_t i = 2; i <= num_to_add; i++) {64root_set.add((nmethod*) (uintptr_t) (i));65}6667ASSERT_EQ(root_set.length(), num_to_add)68<< "After adding in total " << num_to_add << " distinct code roots, "69"they need to be in the set, but there are only " << root_set.length();7071ASSERT_NE(purge_list(), (G1CodeRootSetTable*) NULL)72<< "should have grown to large hashtable";7374size_t num_popped = 0;75for (size_t i = 1; i <= num_to_add; i++) {76bool removed = root_set.remove((nmethod*) i);77if (removed) {78num_popped += 1;79} else {80break;81}82}83ASSERT_EQ(num_popped, num_to_add)84<< "Managed to pop " << num_popped << " code roots, but only "85<< num_to_add << " were added";86ASSERT_NE(purge_list(), (G1CodeRootSetTable*) NULL)87<< "should have grown to large hashtable";8889G1CodeRootSet::purge();9091ASSERT_EQ(purge_list(), (G1CodeRootSetTable*) NULL)92<< "should have purged old small tables";93}949596