8170490: Convert TestBufferingOopClosure_test to GTest
Reviewed-by: dfazunen, iignatyev
This commit is contained in:
parent
9c6128c943
commit
8d6d1e4cda
@ -42,7 +42,7 @@
|
|||||||
// buffered entries.
|
// buffered entries.
|
||||||
|
|
||||||
class BufferingOopClosure: public OopClosure {
|
class BufferingOopClosure: public OopClosure {
|
||||||
friend class TestBufferingOopClosure;
|
friend class BufferingOopClosureTest;
|
||||||
protected:
|
protected:
|
||||||
static const size_t BufferLength = 1024;
|
static const size_t BufferLength = 1024;
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ void InternalVMTests::run() {
|
|||||||
run_unit_test(VMStructs_test);
|
run_unit_test(VMStructs_test);
|
||||||
#endif
|
#endif
|
||||||
#if INCLUDE_ALL_GCS
|
#if INCLUDE_ALL_GCS
|
||||||
run_unit_test(TestBufferingOopClosure_test);
|
|
||||||
run_unit_test(ParallelCompact_test);
|
run_unit_test(ParallelCompact_test);
|
||||||
#endif
|
#endif
|
||||||
tty->print_cr("All internal VM tests passed");
|
tty->print_cr("All internal VM tests passed");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2016, 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
|
||||||
@ -19,20 +19,15 @@
|
|||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precompiled.hpp"
|
#include "precompiled.hpp"
|
||||||
#include "gc/g1/bufferingOopClosure.hpp"
|
#include "gc/g1/bufferingOopClosure.hpp"
|
||||||
#include "memory/iterator.hpp"
|
#include "memory/iterator.hpp"
|
||||||
#include "utilities/debug.hpp"
|
#include "unittest.hpp"
|
||||||
|
|
||||||
/////////////// Unit tests ///////////////
|
|
||||||
|
|
||||||
#ifndef PRODUCT
|
|
||||||
|
|
||||||
class TestBufferingOopClosure {
|
|
||||||
|
|
||||||
|
class BufferingOopClosureTest : public ::testing::Test {
|
||||||
|
public:
|
||||||
// Helper class to fake a set of oop*s and narrowOop*s.
|
// Helper class to fake a set of oop*s and narrowOop*s.
|
||||||
class FakeRoots {
|
class FakeRoots {
|
||||||
public:
|
public:
|
||||||
@ -121,14 +116,14 @@ class TestBufferingOopClosure {
|
|||||||
public:
|
public:
|
||||||
CountOopClosure() : _narrow_oop_count(0), _full_oop_count(0) {}
|
CountOopClosure() : _narrow_oop_count(0), _full_oop_count(0) {}
|
||||||
void do_oop(narrowOop* p) {
|
void do_oop(narrowOop* p) {
|
||||||
assert((uintptr_t(p) & FakeRoots::NarrowOopMarker) != 0,
|
EXPECT_NE(uintptr_t(0), (uintptr_t(p) & FakeRoots::NarrowOopMarker))
|
||||||
"The narrowOop was unexpectedly not marked with the NarrowOopMarker");
|
<< "The narrowOop was unexpectedly not marked with the NarrowOopMarker";
|
||||||
_narrow_oop_count++;
|
_narrow_oop_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_oop(oop* p){
|
void do_oop(oop* p){
|
||||||
assert((uintptr_t(p) & FakeRoots::NarrowOopMarker) == 0,
|
EXPECT_EQ(uintptr_t(0), (uintptr_t(p) & FakeRoots::NarrowOopMarker))
|
||||||
"The oop was unexpectedly marked with the NarrowOopMarker");
|
<< "The oop was unexpectedly marked with the NarrowOopMarker";
|
||||||
_full_oop_count++;
|
_full_oop_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,33 +148,14 @@ class TestBufferingOopClosure {
|
|||||||
|
|
||||||
boc.done();
|
boc.done();
|
||||||
|
|
||||||
#define assert_testCount(got, expected) \
|
EXPECT_EQ(num_narrow, coc.narrow_oop_count()) << "when running testCount("
|
||||||
assert((got) == (expected), \
|
<< num_narrow << ", " << num_full << ", " << do_oop_order << ")";
|
||||||
"Expected: %d, got: %d, when running testCount(%d, %d, %d)", \
|
|
||||||
(got), (expected), num_narrow, num_full, do_oop_order)
|
|
||||||
|
|
||||||
assert_testCount(num_narrow, coc.narrow_oop_count());
|
EXPECT_EQ(num_full, coc.full_oop_count()) << "when running testCount("
|
||||||
assert_testCount(num_full, coc.full_oop_count());
|
<< num_narrow << ", " << num_full << ", " << do_oop_order << ")";
|
||||||
assert_testCount(num_narrow + num_full, coc.all_oop_count());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void testCount() {
|
EXPECT_EQ(num_narrow + num_full, coc.all_oop_count()) << "when running testCount("
|
||||||
int buffer_length = BufferingOopClosure::BufferLength;
|
<< num_narrow << ", " << num_full << ", " << do_oop_order << ")";
|
||||||
|
|
||||||
for (int order = 0; order < FakeRoots::MaxOrder; order++) {
|
|
||||||
testCount(0, 0, order);
|
|
||||||
testCount(10, 0, order);
|
|
||||||
testCount(0, 10, order);
|
|
||||||
testCount(10, 10, order);
|
|
||||||
testCount(buffer_length, 10, order);
|
|
||||||
testCount(10, buffer_length, order);
|
|
||||||
testCount(buffer_length, buffer_length, order);
|
|
||||||
testCount(buffer_length + 1, 10, order);
|
|
||||||
testCount(10, buffer_length + 1, order);
|
|
||||||
testCount(buffer_length + 1, buffer_length, order);
|
|
||||||
testCount(buffer_length, buffer_length + 1, order);
|
|
||||||
testCount(buffer_length + 1, buffer_length + 1, order);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testIsBufferEmptyOrFull(int num_narrow, int num_full, bool expect_empty, bool expect_full) {
|
static void testIsBufferEmptyOrFull(int num_narrow, int num_full, bool expect_empty, bool expect_full) {
|
||||||
@ -190,34 +166,15 @@ class TestBufferingOopClosure {
|
|||||||
|
|
||||||
fr.oops_do(&boc, 0);
|
fr.oops_do(&boc, 0);
|
||||||
|
|
||||||
#define assert_testIsBufferEmptyOrFull(got, expected) \
|
EXPECT_EQ(expect_empty, boc.is_buffer_empty())
|
||||||
assert((got) == (expected), \
|
<< "when running testIsBufferEmptyOrFull("
|
||||||
"Expected: %d, got: %d. testIsBufferEmptyOrFull(%d, %d, %s, %s)", \
|
<< num_narrow << ", " << num_full << ", "
|
||||||
(got), (expected), num_narrow, num_full, \
|
<< expect_empty << ", " << expect_full << ")";
|
||||||
BOOL_TO_STR(expect_empty), BOOL_TO_STR(expect_full))
|
|
||||||
|
|
||||||
assert_testIsBufferEmptyOrFull(expect_empty, boc.is_buffer_empty());
|
EXPECT_EQ(expect_full, boc.is_buffer_full())
|
||||||
assert_testIsBufferEmptyOrFull(expect_full, boc.is_buffer_full());
|
<< "when running testIsBufferEmptyOrFull("
|
||||||
}
|
<< num_narrow << ", " << num_full << ", "
|
||||||
|
<< expect_empty << ", " << expect_full << ")";
|
||||||
static void testIsBufferEmptyOrFull() {
|
|
||||||
int bl = BufferingOopClosure::BufferLength;
|
|
||||||
|
|
||||||
testIsBufferEmptyOrFull(0, 0, true, false);
|
|
||||||
testIsBufferEmptyOrFull(1, 0, false, false);
|
|
||||||
testIsBufferEmptyOrFull(0, 1, false, false);
|
|
||||||
testIsBufferEmptyOrFull(1, 1, false, false);
|
|
||||||
testIsBufferEmptyOrFull(10, 0, false, false);
|
|
||||||
testIsBufferEmptyOrFull(0, 10, false, false);
|
|
||||||
testIsBufferEmptyOrFull(10, 10, false, false);
|
|
||||||
testIsBufferEmptyOrFull(0, bl, false, true);
|
|
||||||
testIsBufferEmptyOrFull(bl, 0, false, true);
|
|
||||||
testIsBufferEmptyOrFull(bl/2, bl/2, false, true);
|
|
||||||
testIsBufferEmptyOrFull(bl-1, 1, false, true);
|
|
||||||
testIsBufferEmptyOrFull(1, bl-1, false, true);
|
|
||||||
// Processed
|
|
||||||
testIsBufferEmptyOrFull(bl+1, 0, false, false);
|
|
||||||
testIsBufferEmptyOrFull(bl*2, 0, false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testEmptyAfterDone(int num_narrow, int num_full) {
|
static void testEmptyAfterDone(int num_narrow, int num_full) {
|
||||||
@ -231,41 +188,70 @@ class TestBufferingOopClosure {
|
|||||||
// Make sure all get processed.
|
// Make sure all get processed.
|
||||||
boc.done();
|
boc.done();
|
||||||
|
|
||||||
assert(boc.is_buffer_empty(),
|
EXPECT_TRUE(boc.is_buffer_empty()) << "Should be empty after call to done()."
|
||||||
"Should be empty after call to done(). testEmptyAfterDone(%d, %d)",
|
<< " testEmptyAfterDone(" << num_narrow << ", " << num_full << ")";
|
||||||
num_narrow, num_full);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testEmptyAfterDone() {
|
static int get_buffer_length() {
|
||||||
int bl = BufferingOopClosure::BufferLength;
|
return BufferingOopClosure::BufferLength;
|
||||||
|
|
||||||
testEmptyAfterDone(0, 0);
|
|
||||||
testEmptyAfterDone(1, 0);
|
|
||||||
testEmptyAfterDone(0, 1);
|
|
||||||
testEmptyAfterDone(1, 1);
|
|
||||||
testEmptyAfterDone(10, 0);
|
|
||||||
testEmptyAfterDone(0, 10);
|
|
||||||
testEmptyAfterDone(10, 10);
|
|
||||||
testEmptyAfterDone(0, bl);
|
|
||||||
testEmptyAfterDone(bl, 0);
|
|
||||||
testEmptyAfterDone(bl/2, bl/2);
|
|
||||||
testEmptyAfterDone(bl-1, 1);
|
|
||||||
testEmptyAfterDone(1, bl-1);
|
|
||||||
// Processed
|
|
||||||
testEmptyAfterDone(bl+1, 0);
|
|
||||||
testEmptyAfterDone(bl*2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void test() {
|
|
||||||
testCount();
|
|
||||||
testIsBufferEmptyOrFull();
|
|
||||||
testEmptyAfterDone();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestBufferingOopClosure_test() {
|
TEST_VM_F(BufferingOopClosureTest, count_test) {
|
||||||
TestBufferingOopClosure::test();
|
int bl = BufferingOopClosureTest::get_buffer_length();
|
||||||
|
|
||||||
|
for (int order = 0; order < FakeRoots::MaxOrder; order++) {
|
||||||
|
testCount(0, 0, order);
|
||||||
|
testCount(10, 0, order);
|
||||||
|
testCount(0, 10, order);
|
||||||
|
testCount(10, 10, order);
|
||||||
|
testCount(bl, 10, order);
|
||||||
|
testCount(10, bl, order);
|
||||||
|
testCount(bl, bl, order);
|
||||||
|
testCount(bl + 1, 10, order);
|
||||||
|
testCount(10, bl + 1, order);
|
||||||
|
testCount(bl + 1, bl, order);
|
||||||
|
testCount(bl, bl + 1, order);
|
||||||
|
testCount(bl + 1, bl + 1, order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
TEST_VM_F(BufferingOopClosureTest, buffer_empty_or_full) {
|
||||||
|
int bl = BufferingOopClosureTest::get_buffer_length();
|
||||||
|
|
||||||
|
testIsBufferEmptyOrFull(0, 0, true, false);
|
||||||
|
testIsBufferEmptyOrFull(1, 0, false, false);
|
||||||
|
testIsBufferEmptyOrFull(0, 1, false, false);
|
||||||
|
testIsBufferEmptyOrFull(1, 1, false, false);
|
||||||
|
testIsBufferEmptyOrFull(10, 0, false, false);
|
||||||
|
testIsBufferEmptyOrFull(0, 10, false, false);
|
||||||
|
testIsBufferEmptyOrFull(10, 10, false, false);
|
||||||
|
testIsBufferEmptyOrFull(0, bl, false, true);
|
||||||
|
testIsBufferEmptyOrFull(bl, 0, false, true);
|
||||||
|
testIsBufferEmptyOrFull(bl / 2, bl / 2, false, true);
|
||||||
|
testIsBufferEmptyOrFull(bl - 1, 1, false, true);
|
||||||
|
testIsBufferEmptyOrFull(1, bl - 1, false, true);
|
||||||
|
// Processed
|
||||||
|
testIsBufferEmptyOrFull(bl + 1, 0, false, false);
|
||||||
|
testIsBufferEmptyOrFull(bl * 2, 0, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_VM_F(BufferingOopClosureTest, empty_after_done) {
|
||||||
|
int bl = BufferingOopClosureTest::get_buffer_length();
|
||||||
|
|
||||||
|
testEmptyAfterDone(0, 0);
|
||||||
|
testEmptyAfterDone(1, 0);
|
||||||
|
testEmptyAfterDone(0, 1);
|
||||||
|
testEmptyAfterDone(1, 1);
|
||||||
|
testEmptyAfterDone(10, 0);
|
||||||
|
testEmptyAfterDone(0, 10);
|
||||||
|
testEmptyAfterDone(10, 10);
|
||||||
|
testEmptyAfterDone(0, bl);
|
||||||
|
testEmptyAfterDone(bl, 0);
|
||||||
|
testEmptyAfterDone(bl / 2, bl / 2);
|
||||||
|
testEmptyAfterDone(bl - 1, 1);
|
||||||
|
testEmptyAfterDone(1, bl - 1);
|
||||||
|
// Processed
|
||||||
|
testEmptyAfterDone(bl + 1, 0);
|
||||||
|
testEmptyAfterDone(bl * 2, 0);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user