summaryrefslogtreecommitdiffstats
path: root/src/space_test.cc
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2012-01-23 15:43:46 -0800
committerIan Rogers <irogers@google.com>2012-01-26 17:32:10 -0800
commit30fab40ee5a07af6b8c3b6b0e9438071695a57f4 (patch)
tree86514e3535c8b23cf52249a202076b59ac532021 /src/space_test.cc
parentf3778f66879fa038a7c9ebe46d5bc4167ddef7d8 (diff)
downloadart-30fab40ee5a07af6b8c3b6b0e9438071695a57f4.zip
art-30fab40ee5a07af6b8c3b6b0e9438071695a57f4.tar.gz
art-30fab40ee5a07af6b8c3b6b0e9438071695a57f4.tar.bz2
Upgrade to latest dlmalloc. Refactor Heap and related APIs to use STL like naming.
We fail assertions in the existing heap code, as does Dalvik. This refactoring is to clean the heap and space APIs and to reduce duplication of data and thereby solve a failing assertion in the card table. This change also wires up clearing of soft references including before out-of-memory errors are reported. In doing this change it was made clear that mspaces are buggy (and violating invariants with the garbage collector). This change upgrades to an un-Android molested version of dlmalloc-2.8.5 and implements a version of the mspace morecore routine under ART control. run-test 061-out-of-memory is updated for current heap sizes. Change-Id: I377e83ab2a8c78afb9b1881f03356929e2c9dc64
Diffstat (limited to 'src/space_test.cc')
-rw-r--r--src/space_test.cc37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/space_test.cc b/src/space_test.cc
index c54a584..f6d1191 100644
--- a/src/space_test.cc
+++ b/src/space_test.cc
@@ -13,67 +13,71 @@ class SpaceTest : public CommonTest {};
TEST_F(SpaceTest, Init) {
{
// Init < max == growth
- UniquePtr<Space> space(Space::Create("test", 16 * MB, 32 * MB, 32 * MB, NULL));
+ UniquePtr<Space> space(Space::CreateAllocSpace("test", 16 * MB, 32 * MB, 32 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Init == max == growth
- UniquePtr<Space> space(Space::Create("test", 16 * MB, 16 * MB, 16 * MB, NULL));
+ UniquePtr<Space> space(Space::CreateAllocSpace("test", 16 * MB, 16 * MB, 16 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Init > max == growth
- UniquePtr<Space> space(Space::Create("test", 32 * MB, 16 * MB, 16 * MB, NULL));
+ UniquePtr<Space> space(Space::CreateAllocSpace("test", 32 * MB, 16 * MB, 16 * MB, NULL));
EXPECT_TRUE(space.get() == NULL);
}
{
// Growth == init < max
- UniquePtr<Space> space(Space::Create("test", 16 * MB, 32 * MB, 16 * MB, NULL));
+ UniquePtr<Space> space(Space::CreateAllocSpace("test", 16 * MB, 16 * MB, 32 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Growth < init < max
- UniquePtr<Space> space(Space::Create("test", 16 * MB, 32 * MB, 8 * MB, NULL));
+ UniquePtr<Space> space(Space::CreateAllocSpace("test", 16 * MB, 8 * MB, 32 * MB, NULL));
EXPECT_TRUE(space.get() == NULL);
}
{
// Init < growth < max
- UniquePtr<Space> space(Space::Create("test", 8 * MB, 32 * MB, 16 * MB, NULL));
+ UniquePtr<Space> space(Space::CreateAllocSpace("test", 8 * MB, 16 * MB, 32 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Init < max < growth
- UniquePtr<Space> space(Space::Create("test", 8 * MB, 16 * MB, 32 * MB, NULL));
+ UniquePtr<Space> space(Space::CreateAllocSpace("test", 8 * MB, 32 * MB, 16 * MB, NULL));
EXPECT_TRUE(space.get() == NULL);
}
}
TEST_F(SpaceTest, AllocAndFree) {
- UniquePtr<Space> space(Space::Create("test", 4 * MB, 16 * MB, 16 * MB, NULL));
- ASSERT_TRUE(space.get() != NULL);
+ AllocSpace* space(Space::CreateAllocSpace("test", 4 * MB, 16 * MB, 16 * MB, NULL));
+ ASSERT_TRUE(space != NULL);
+
+ // Make space findable to the heap, will also delete class when runtime is cleaned up
+ Heap::AddSpace(space);
// Succeeds, fits without adjusting the max allowed footprint.
- void* ptr1 = space->AllocWithoutGrowth(1 * MB);
+ Object* ptr1 = space->AllocWithoutGrowth(1 * MB);
EXPECT_TRUE(ptr1 != NULL);
// Fails, requires a higher allowed footprint.
- void* ptr2 = space->AllocWithoutGrowth(8 * MB);
+ Object* ptr2 = space->AllocWithoutGrowth(8 * MB);
EXPECT_TRUE(ptr2 == NULL);
// Succeeds, adjusts the footprint.
- void* ptr3 = space->AllocWithGrowth(8 * MB);
+ Object* ptr3 = space->AllocWithGrowth(8 * MB);
EXPECT_TRUE(ptr3 != NULL);
// Fails, requires a higher allowed footprint.
- void* ptr4 = space->AllocWithoutGrowth(8 * MB);
+ Object* ptr4 = space->AllocWithoutGrowth(8 * MB);
EXPECT_FALSE(ptr4 != NULL);
// Also fails, requires a higher allowed footprint.
- void* ptr5 = space->AllocWithGrowth(8 * MB);
+ Object* ptr5 = space->AllocWithGrowth(8 * MB);
EXPECT_FALSE(ptr5 != NULL);
// Release some memory.
- size_t free3 = space->Free(ptr3);
+ size_t free3 = space->AllocationSize(ptr3);
+ space->Free(ptr3);
EXPECT_LE(8U * MB, free3);
// Succeeds, now that memory has been freed.
@@ -81,7 +85,8 @@ TEST_F(SpaceTest, AllocAndFree) {
EXPECT_TRUE(ptr6 != NULL);
// Final clean up.
- size_t free1 = space->Free(ptr1);
+ size_t free1 = space->AllocationSize(ptr1);
+ space->Free(ptr1);
EXPECT_LE(1U * MB, free1);
}