< prev index next > test/hotspot/gtest/utilities/test_resourceHash.cpp
Print this page
/*
! * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
/*
! * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
ASSERT_TRUE(rh.remove(as_K(step)));
ASSERT_FALSE(rh.contains(as_K(step)));
rh.iterate(&et);
!
}
};
};
TEST_VM_F(SmallResourceHashtableTest, default) {
ASSERT_TRUE(rh.remove(as_K(step)));
ASSERT_FALSE(rh.contains(as_K(step)));
rh.iterate(&et);
! rh.unlink_all();
}
};
};
TEST_VM_F(SmallResourceHashtableTest, default) {
ASSERT_TRUE(rh.put(as_K(index), index));
}
DeleterTestIter dt(5);
rh.unlink(&dt);
ASSERT_FALSE(rh.get(as_K(5)));
+
+ rh.unlink_all();
+ for (uintptr_t i = 10; i > 0; --i) {
+ uintptr_t index = i - 1;
+ ASSERT_FALSE(rh.get(as_K(index)));
+ }
}
};
};
TEST_VM_F(GenericResourceHashtableTest, default) {
SimpleDeleter deleter;
_simple_test_table.unlink(&deleter);
ASSERT_EQ(s->refcount(), s_orig_count) << "refcount should be same as start";
}
+ TEST_VM_F(SimpleResourceHashtableDeleteTest, simle_unlink_all) {
+ TempNewSymbol t = SymbolTable::new_symbol("abcdefg_simple");
+ Symbol* s = t;
+ int s_orig_count = s->refcount();
+ _simple_test_table.put(s, 66);
+ ASSERT_EQ(s->refcount(), s_orig_count + 1) << "refcount should be incremented in table";
+
+ // Use unlink_all to remove the matching (or all) values from the table.
+ _simple_test_table.unlink_all();
+ ASSERT_EQ(s->refcount(), s_orig_count) << "refcount should be same as start";
+ }
+
// More complicated ResourceHashtable with SymbolHandle in the key. Since the *same* Symbol is part
// of the value, it's not necessary to manipulate the refcount of the key, but you must in the value.
// Luckily SymbolHandle does this.
class ResourceHashtableDeleteTest : public ::testing::Test {
public:
ASSERT_EQ(d->refcount(), d_orig_count + 1) << "refcount incremented in table";
Deleter deleter;
_test_table.unlink(&deleter);
ASSERT_EQ(d->refcount(), d_orig_count) << "refcount should be as we started";
}
+
+ TEST_VM_F(ResourceHashtableDeleteTest, value_unlink_all) {
+ TempNewSymbol d = SymbolTable::new_symbol("defghijklmnop");
+ int d_orig_count = d->refcount();
+ {
+ TestValue tv(d);
+ // Same as above, but the do_entry does nothing because the value is deleted when the
+ // hashtable node is deleted.
+ _test_table.put(d, tv);
+ ASSERT_EQ(d->refcount(), d_orig_count + 2) << "refcount incremented by copy";
+ }
+ ASSERT_EQ(d->refcount(), d_orig_count + 1) << "refcount incremented in table";
+ _test_table.unlink_all();
+ ASSERT_EQ(d->refcount(), d_orig_count) << "refcount should be as we started";
+ }
TEST_VM_F(ResourceHashtableDeleteTest, check_delete_ptr) {
TempNewSymbol s = SymbolTable::new_symbol("abcdefg_ptr");
int s_orig_count = s->refcount();
{
< prev index next >