blob: 28200dfbfccc92a4bbf11280b8759e5eaba4ea72 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro69759ea2011-07-21 18:13:35 -070016
Andreas Gampea7433512014-02-21 13:19:23 -080017#ifndef ART_RUNTIME_GC_SPACE_SPACE_TEST_H_
18#define ART_RUNTIME_GC_SPACE_SPACE_TEST_H_
19
Mathieu Chartiera1602f22014-01-13 17:19:19 -080020#include "zygote_space.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070021
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080022#include <stdint.h>
23
24#include "common_runtime_test.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070025#include "globals.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070026#include "UniquePtr.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070027#include "mirror/array-inl.h"
28#include "mirror/object-inl.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070029
30namespace art {
Ian Rogers1d54e732013-05-02 21:10:01 -070031namespace gc {
32namespace space {
Carl Shapiro69759ea2011-07-21 18:13:35 -070033
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080034class SpaceTest : public CommonRuntimeTest {
Ian Rogers3bb17a62012-01-27 23:56:44 -080035 public:
Mathieu Chartier5647d182014-03-07 15:00:39 -080036 jobject byte_array_class_;
37
38 SpaceTest() : byte_array_class_(nullptr) {
39 }
40
Mathieu Chartier590fee92013-09-13 13:46:47 -070041 void AddSpace(ContinuousSpace* space) {
Mathieu Chartier73d1e172014-04-11 17:53:48 -070042 // By passing true, AddSpace() does the revoke.
43 Runtime::Current()->GetHeap()->AddSpace(space, true);
Ian Rogers1d54e732013-05-02 21:10:01 -070044 }
Mathieu Chartier5647d182014-03-07 15:00:39 -080045
46 mirror::Class* GetByteArrayClass(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
47 SirtRef<mirror::ClassLoader> null_loader(self, nullptr);
48 if (byte_array_class_ == nullptr) {
49 mirror::Class* byte_array_class =
50 Runtime::Current()->GetClassLinker()->FindClass(self, "[B", null_loader);
51 EXPECT_TRUE(byte_array_class != nullptr);
52 byte_array_class_ = self->GetJniEnv()->NewLocalRef(byte_array_class);
53 EXPECT_TRUE(byte_array_class_ != nullptr);
54 }
55 return reinterpret_cast<mirror::Class*>(self->DecodeJObject(byte_array_class_));
56 }
57
58 mirror::Object* Alloc(space::MallocSpace* alloc_space, Thread* self, size_t bytes,
59 size_t* bytes_allocated, size_t* usable_size)
60 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
61 SirtRef<mirror::Class> byte_array_class(self, GetByteArrayClass(self));
62 mirror::Object* obj = alloc_space->Alloc(self, bytes, bytes_allocated, usable_size);
63 if (obj != nullptr) {
64 InstallClass(obj, byte_array_class.get(), bytes);
65 }
66 return obj;
67 }
68
69 mirror::Object* AllocWithGrowth(space::MallocSpace* alloc_space, Thread* self, size_t bytes,
70 size_t* bytes_allocated, size_t* usable_size)
71 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
72 SirtRef<mirror::Class> byte_array_class(self, GetByteArrayClass(self));
73 mirror::Object* obj = alloc_space->AllocWithGrowth(self, bytes, bytes_allocated, usable_size);
74 if (obj != nullptr) {
75 InstallClass(obj, byte_array_class.get(), bytes);
76 }
77 return obj;
78 }
79
80 void InstallClass(mirror::Object* o, mirror::Class* byte_array_class, size_t size)
Mathieu Chartier4e305412014-02-19 10:54:44 -080081 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -080082 // Note the minimum size, which is the size of a zero-length byte array.
83 EXPECT_GE(size, SizeOfZeroLengthByteArray());
Mathieu Chartier4e305412014-02-19 10:54:44 -080084 EXPECT_TRUE(byte_array_class != nullptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070085 o->SetClass(byte_array_class);
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070086 if (kUseBakerOrBrooksReadBarrier) {
87 // Like the proper heap object allocation, install and verify
88 // the correct read barrier pointer.
89 if (kUseBrooksReadBarrier) {
90 o->SetReadBarrierPointer(o);
91 }
92 o->AssertReadBarrierPointer();
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080093 }
Mathieu Chartier4e305412014-02-19 10:54:44 -080094 mirror::Array* arr = o->AsArray<kVerifyNone>();
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -080095 size_t header_size = SizeOfZeroLengthByteArray();
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070096 int32_t length = size - header_size;
97 arr->SetLength(length);
Mathieu Chartier4e305412014-02-19 10:54:44 -080098 EXPECT_EQ(arr->SizeOf<kVerifyNone>(), size);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070099 }
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800100
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800101 static size_t SizeOfZeroLengthByteArray() {
102 return mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimByte)).Uint32Value();
103 }
104
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800105 typedef MallocSpace* (*CreateSpaceFn)(const std::string& name, size_t initial_size, size_t growth_limit,
106 size_t capacity, byte* requested_begin);
107 void InitTestBody(CreateSpaceFn create_space);
108 void ZygoteSpaceTestBody(CreateSpaceFn create_space);
109 void AllocAndFreeTestBody(CreateSpaceFn create_space);
110 void AllocAndFreeListTestBody(CreateSpaceFn create_space);
111
112 void SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
113 int round, size_t growth_limit);
114 void SizeFootPrintGrowthLimitAndTrimDriver(size_t object_size, CreateSpaceFn create_space);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800115};
Brian Carlstrom9b7f2c22011-09-27 14:35:04 -0700116
Ian Rogers719d1a32014-03-06 12:13:39 -0800117static inline size_t test_rand(size_t* seed) {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700118 *seed = *seed * 1103515245 + 12345;
119 return *seed;
120}
121
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800122void SpaceTest::InitTestBody(CreateSpaceFn create_space) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700123 {
jeffhaoc1160702011-10-27 15:48:45 -0700124 // Init < max == growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800125 UniquePtr<Space> space(create_space("test", 16 * MB, 32 * MB, 32 * MB, nullptr));
126 EXPECT_TRUE(space.get() != nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700127 }
128 {
jeffhaoc1160702011-10-27 15:48:45 -0700129 // Init == max == growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800130 UniquePtr<Space> space(create_space("test", 16 * MB, 16 * MB, 16 * MB, nullptr));
131 EXPECT_TRUE(space.get() != nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700132 }
133 {
jeffhaoc1160702011-10-27 15:48:45 -0700134 // Init > max == growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800135 UniquePtr<Space> space(create_space("test", 32 * MB, 16 * MB, 16 * MB, nullptr));
136 EXPECT_TRUE(space.get() == nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700137 }
138 {
139 // Growth == init < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800140 UniquePtr<Space> space(create_space("test", 16 * MB, 16 * MB, 32 * MB, nullptr));
141 EXPECT_TRUE(space.get() != nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700142 }
143 {
144 // Growth < init < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800145 UniquePtr<Space> space(create_space("test", 16 * MB, 8 * MB, 32 * MB, nullptr));
146 EXPECT_TRUE(space.get() == nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700147 }
148 {
149 // Init < growth < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800150 UniquePtr<Space> space(create_space("test", 8 * MB, 16 * MB, 32 * MB, nullptr));
151 EXPECT_TRUE(space.get() != nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700152 }
153 {
154 // Init < max < growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800155 UniquePtr<Space> space(create_space("test", 8 * MB, 32 * MB, 16 * MB, nullptr));
156 EXPECT_TRUE(space.get() == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700157 }
158}
159
Mathieu Chartierdcf8d722012-08-02 14:55:54 -0700160// TODO: This test is not very good, we should improve it.
161// The test should do more allocations before the creation of the ZygoteSpace, and then do
162// allocations after the ZygoteSpace is created. The test should also do some GCs to ensure that
163// the GC works with the ZygoteSpace.
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800164void SpaceTest::ZygoteSpaceTestBody(CreateSpaceFn create_space) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800165 size_t dummy;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800166 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
167 ASSERT_TRUE(space != nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700168
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800169 // Make space findable to the heap, will also delete space when runtime is cleaned up
170 AddSpace(space);
171 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800172 ScopedObjectAccess soa(self);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700173
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800174 // Succeeds, fits without adjusting the footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800175 size_t ptr1_bytes_allocated, ptr1_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800176 SirtRef<mirror::Object> ptr1(self, Alloc(space, self, 1 * MB, &ptr1_bytes_allocated,
177 &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800178 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800179 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
180 EXPECT_LE(1U * MB, ptr1_usable_size);
181 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700182
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800183 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800184 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800185 EXPECT_TRUE(ptr2 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700186
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800187 // Succeeds, adjusts the footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800188 size_t ptr3_bytes_allocated, ptr3_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800189 SirtRef<mirror::Object> ptr3(self, AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated,
190 &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800191 EXPECT_TRUE(ptr3.get() != nullptr);
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800192 EXPECT_LE(8U * MB, ptr3_bytes_allocated);
Ian Rogers6fac4472014-02-25 17:01:10 -0800193 EXPECT_LE(8U * MB, ptr3_usable_size);
194 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700195
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800196 // Fails, requires a higher footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800197 mirror::Object* ptr4 = space->Alloc(self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800198 EXPECT_TRUE(ptr4 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700199
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800200 // Also fails, requires a higher allowed footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800201 mirror::Object* ptr5 = space->AllocWithGrowth(self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800202 EXPECT_TRUE(ptr5 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700203
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800204 // Release some memory.
Ian Rogers6fac4472014-02-25 17:01:10 -0800205 size_t free3 = space->AllocationSize(ptr3.get(), nullptr);
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800206 EXPECT_EQ(free3, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800207 EXPECT_EQ(free3, space->Free(self, ptr3.reset(nullptr)));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800208 EXPECT_LE(8U * MB, free3);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700209
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800210 // Succeeds, now that memory has been freed.
Ian Rogers6fac4472014-02-25 17:01:10 -0800211 size_t ptr6_bytes_allocated, ptr6_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800212 SirtRef<mirror::Object> ptr6(self, AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated,
213 &ptr6_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800214 EXPECT_TRUE(ptr6.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800215 EXPECT_LE(9U * MB, ptr6_bytes_allocated);
216 EXPECT_LE(9U * MB, ptr6_usable_size);
217 EXPECT_LE(ptr6_usable_size, ptr6_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700218
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800219 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800220 size_t free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800221 space->Free(self, ptr1.reset(nullptr));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800222 EXPECT_LE(1U * MB, free1);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700223
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800224 // Make sure that the zygote space isn't directly at the start of the space.
Ian Rogers6fac4472014-02-25 17:01:10 -0800225 EXPECT_TRUE(space->Alloc(self, 1U * MB, &dummy, nullptr) != nullptr);
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800226
227 gc::Heap* heap = Runtime::Current()->GetHeap();
228 space::Space* old_space = space;
229 heap->RemoveSpace(old_space);
230 space::ZygoteSpace* zygote_space = space->CreateZygoteSpace("alloc space",
231 heap->IsLowMemoryMode(),
232 &space);
233 delete old_space;
234 // Add the zygote space.
235 AddSpace(zygote_space);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700236
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800237 // Make space findable to the heap, will also delete space when runtime is cleaned up
238 AddSpace(space);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700239
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800240 // Succeeds, fits without adjusting the footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800241 ptr1.reset(Alloc(space, self, 1 * MB, &ptr1_bytes_allocated, &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800242 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800243 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
244 EXPECT_LE(1U * MB, ptr1_usable_size);
245 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700246
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800247 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800248 ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800249 EXPECT_TRUE(ptr2 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700250
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800251 // Succeeds, adjusts the footprint.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800252 ptr3.reset(AllocWithGrowth(space, self, 2 * MB, &ptr3_bytes_allocated, &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800253 EXPECT_TRUE(ptr3.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800254 EXPECT_LE(2U * MB, ptr3_bytes_allocated);
255 EXPECT_LE(2U * MB, ptr3_usable_size);
256 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800257 space->Free(self, ptr3.reset(nullptr));
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700258
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800259 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800260 free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800261 space->Free(self, ptr1.reset(nullptr));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800262 EXPECT_LE(1U * MB, free1);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700263}
264
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800265void SpaceTest::AllocAndFreeTestBody(CreateSpaceFn create_space) {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700266 size_t dummy = 0;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800267 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
268 ASSERT_TRUE(space != nullptr);
Ian Rogers50b35e22012-10-04 10:09:15 -0700269 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800270 ScopedObjectAccess soa(self);
Ian Rogers30fab402012-01-23 15:43:46 -0800271
Ian Rogers3bb17a62012-01-27 23:56:44 -0800272 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700273 AddSpace(space);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700274
Ian Rogers3bb17a62012-01-27 23:56:44 -0800275 // Succeeds, fits without adjusting the footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800276 size_t ptr1_bytes_allocated, ptr1_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800277 SirtRef<mirror::Object> ptr1(self, Alloc(space, self, 1 * MB, &ptr1_bytes_allocated,
278 &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800279 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800280 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
281 EXPECT_LE(1U * MB, ptr1_usable_size);
282 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700283
Ian Rogers3bb17a62012-01-27 23:56:44 -0800284 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800285 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800286 EXPECT_TRUE(ptr2 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700287
288 // Succeeds, adjusts the footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800289 size_t ptr3_bytes_allocated, ptr3_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800290 SirtRef<mirror::Object> ptr3(self, AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated,
291 &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800292 EXPECT_TRUE(ptr3.get() != nullptr);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700293 EXPECT_LE(8U * MB, ptr3_bytes_allocated);
Ian Rogers6fac4472014-02-25 17:01:10 -0800294 EXPECT_LE(8U * MB, ptr3_usable_size);
295 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700296
Ian Rogers3bb17a62012-01-27 23:56:44 -0800297 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800298 mirror::Object* ptr4 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800299 EXPECT_TRUE(ptr4 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700300
301 // Also fails, requires a higher allowed footprint.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800302 mirror::Object* ptr5 = AllocWithGrowth(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800303 EXPECT_TRUE(ptr5 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700304
305 // Release some memory.
Ian Rogers6fac4472014-02-25 17:01:10 -0800306 size_t free3 = space->AllocationSize(ptr3.get(), nullptr);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700307 EXPECT_EQ(free3, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800308 space->Free(self, ptr3.reset(nullptr));
Carl Shapiro69759ea2011-07-21 18:13:35 -0700309 EXPECT_LE(8U * MB, free3);
310
311 // Succeeds, now that memory has been freed.
Ian Rogers6fac4472014-02-25 17:01:10 -0800312 size_t ptr6_bytes_allocated, ptr6_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800313 SirtRef<mirror::Object> ptr6(self, AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated,
314 &ptr6_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800315 EXPECT_TRUE(ptr6.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800316 EXPECT_LE(9U * MB, ptr6_bytes_allocated);
317 EXPECT_LE(9U * MB, ptr6_usable_size);
318 EXPECT_LE(ptr6_usable_size, ptr6_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700319
320 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800321 size_t free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800322 space->Free(self, ptr1.reset(nullptr));
Carl Shapiro69759ea2011-07-21 18:13:35 -0700323 EXPECT_LE(1U * MB, free1);
324}
325
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800326void SpaceTest::AllocAndFreeListTestBody(CreateSpaceFn create_space) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800327 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
328 ASSERT_TRUE(space != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800329
330 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700331 AddSpace(space);
Ian Rogers50b35e22012-10-04 10:09:15 -0700332 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800333 ScopedObjectAccess soa(self);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800334
335 // Succeeds, fits without adjusting the max allowed footprint.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 mirror::Object* lots_of_objects[1024];
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700337 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800338 size_t allocation_size, usable_size;
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800339 size_t size_of_zero_length_byte_array = SizeOfZeroLengthByteArray();
Mathieu Chartier5647d182014-03-07 15:00:39 -0800340 lots_of_objects[i] = Alloc(space, self, size_of_zero_length_byte_array, &allocation_size,
341 &usable_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800342 EXPECT_TRUE(lots_of_objects[i] != nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800343 SirtRef<mirror::Object> obj(self, lots_of_objects[i]);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800344 lots_of_objects[i] = obj.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800345 size_t computed_usable_size;
346 EXPECT_EQ(allocation_size, space->AllocationSize(lots_of_objects[i], &computed_usable_size));
347 EXPECT_EQ(usable_size, computed_usable_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800348 }
349
Mathieu Chartier73d1e172014-04-11 17:53:48 -0700350 // Release memory.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800351 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800352
353 // Succeeds, fits by adjusting the max allowed footprint.
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700354 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800355 size_t allocation_size, usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800356 lots_of_objects[i] = AllocWithGrowth(space, self, 1024, &allocation_size, &usable_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800357 EXPECT_TRUE(lots_of_objects[i] != nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800358 SirtRef<mirror::Object> obj(self, lots_of_objects[i]);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800359 lots_of_objects[i] = obj.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800360 size_t computed_usable_size;
361 EXPECT_EQ(allocation_size, space->AllocationSize(lots_of_objects[i], &computed_usable_size));
362 EXPECT_EQ(usable_size, computed_usable_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800363 }
364
Mathieu Chartier73d1e172014-04-11 17:53:48 -0700365 // Release memory.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800366 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800367}
368
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800369void SpaceTest::SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
Ian Rogers3bb17a62012-01-27 23:56:44 -0800370 int round, size_t growth_limit) {
371 if (((object_size > 0 && object_size >= static_cast<intptr_t>(growth_limit))) ||
372 ((object_size < 0 && -object_size >= static_cast<intptr_t>(growth_limit)))) {
373 // No allocation can succeed
374 return;
375 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800376
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700377 // The space's footprint equals amount of resources requested from system
378 size_t footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800379
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700380 // The space must at least have its book keeping allocated
Ian Rogers3bb17a62012-01-27 23:56:44 -0800381 EXPECT_GT(footprint, 0u);
382
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700383 // But it shouldn't exceed the initial size
Ian Rogers3bb17a62012-01-27 23:56:44 -0800384 EXPECT_LE(footprint, growth_limit);
385
386 // space's size shouldn't exceed the initial size
387 EXPECT_LE(space->Size(), growth_limit);
388
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700389 // this invariant should always hold or else the space has grown to be larger than what the
Ian Rogers3bb17a62012-01-27 23:56:44 -0800390 // space believes its size is (which will break invariants)
391 EXPECT_GE(space->Size(), footprint);
392
393 // Fill the space with lots of small objects up to the growth limit
394 size_t max_objects = (growth_limit / (object_size > 0 ? object_size : 8)) + 1;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800395 UniquePtr<mirror::Object*[]> lots_of_objects(new mirror::Object*[max_objects]);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800396 size_t last_object = 0; // last object for which allocation succeeded
397 size_t amount_allocated = 0; // amount of space allocated
Ian Rogers50b35e22012-10-04 10:09:15 -0700398 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800399 ScopedObjectAccess soa(self);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700400 size_t rand_seed = 123456789;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700401 for (size_t i = 0; i < max_objects; i++) {
Ian Rogers3bb17a62012-01-27 23:56:44 -0800402 size_t alloc_fails = 0; // number of failed allocations
403 size_t max_fails = 30; // number of times we fail allocation before giving up
404 for (; alloc_fails < max_fails; alloc_fails++) {
405 size_t alloc_size;
406 if (object_size > 0) {
407 alloc_size = object_size;
408 } else {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700409 alloc_size = test_rand(&rand_seed) % static_cast<size_t>(-object_size);
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800410 // Note the minimum size, which is the size of a zero-length byte array.
411 size_t size_of_zero_length_byte_array = SizeOfZeroLengthByteArray();
412 if (alloc_size < size_of_zero_length_byte_array) {
413 alloc_size = size_of_zero_length_byte_array;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800414 }
415 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800416 SirtRef<mirror::Object> object(self, nullptr);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700417 size_t bytes_allocated = 0;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800418 if (round <= 1) {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800419 object.reset(Alloc(space, self, alloc_size, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800420 } else {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800421 object.reset(AllocWithGrowth(space, self, alloc_size, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800422 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700423 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800424 EXPECT_GE(space->Size(), footprint); // invariant
Mathieu Chartier4e305412014-02-19 10:54:44 -0800425 if (object.get() != nullptr) { // allocation succeeded
Mathieu Chartier4e305412014-02-19 10:54:44 -0800426 lots_of_objects[i] = object.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800427 size_t allocation_size = space->AllocationSize(object.get(), nullptr);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700428 EXPECT_EQ(bytes_allocated, allocation_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800429 if (object_size > 0) {
430 EXPECT_GE(allocation_size, static_cast<size_t>(object_size));
431 } else {
432 EXPECT_GE(allocation_size, 8u);
433 }
434 amount_allocated += allocation_size;
435 break;
436 }
437 }
438 if (alloc_fails == max_fails) {
439 last_object = i;
440 break;
441 }
442 }
443 CHECK_NE(last_object, 0u); // we should have filled the space
444 EXPECT_GT(amount_allocated, 0u);
445
446 // We shouldn't have gone past the growth_limit
447 EXPECT_LE(amount_allocated, growth_limit);
448 EXPECT_LE(footprint, growth_limit);
449 EXPECT_LE(space->Size(), growth_limit);
450
451 // footprint and size should agree with amount allocated
452 EXPECT_GE(footprint, amount_allocated);
453 EXPECT_GE(space->Size(), amount_allocated);
454
455 // Release storage in a semi-adhoc manner
456 size_t free_increment = 96;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700457 while (true) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800458 {
459 ScopedThreadStateChange tsc(self, kNative);
460 // Give the space a haircut.
461 space->Trim();
462 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800463
464 // Bounds sanity
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700465 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800466 EXPECT_LE(amount_allocated, growth_limit);
467 EXPECT_GE(footprint, amount_allocated);
468 EXPECT_LE(footprint, growth_limit);
469 EXPECT_GE(space->Size(), amount_allocated);
470 EXPECT_LE(space->Size(), growth_limit);
471
472 if (free_increment == 0) {
473 break;
474 }
475
Mathieu Chartier4e305412014-02-19 10:54:44 -0800476 // Free some objects
477 for (size_t i = 0; i < last_object; i += free_increment) {
478 mirror::Object* object = lots_of_objects.get()[i];
479 if (object == nullptr) {
480 continue;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800481 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800482 size_t allocation_size = space->AllocationSize(object, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800483 if (object_size > 0) {
484 EXPECT_GE(allocation_size, static_cast<size_t>(object_size));
485 } else {
486 EXPECT_GE(allocation_size, 8u);
487 }
488 space->Free(self, object);
489 lots_of_objects.get()[i] = nullptr;
490 amount_allocated -= allocation_size;
491 footprint = space->GetFootprint();
492 EXPECT_GE(space->Size(), footprint); // invariant
Ian Rogers3bb17a62012-01-27 23:56:44 -0800493 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800494
495 free_increment >>= 1;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800496 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800497
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700498 // The space has become empty here before allocating a large object
499 // below. For RosAlloc, revoke thread-local runs, which are kept
500 // even when empty for a performance reason, so that they won't
501 // cause the following large object allocation to fail due to
502 // potential fragmentation. Note they are normally revoked at each
503 // GC (but no GC here.)
504 space->RevokeAllThreadLocalBuffers();
505
Ian Rogers3bb17a62012-01-27 23:56:44 -0800506 // All memory was released, try a large allocation to check freed memory is being coalesced
Mathieu Chartier4e305412014-02-19 10:54:44 -0800507 SirtRef<mirror::Object> large_object(self, nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800508 size_t three_quarters_space = (growth_limit / 2) + (growth_limit / 4);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700509 size_t bytes_allocated = 0;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800510 if (round <= 1) {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800511 large_object.reset(Alloc(space, self, three_quarters_space, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800512 } else {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800513 large_object.reset(AllocWithGrowth(space, self, three_quarters_space, &bytes_allocated,
514 nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800515 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800516 EXPECT_TRUE(large_object.get() != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800517
518 // Sanity check footprint
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700519 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800520 EXPECT_LE(footprint, growth_limit);
521 EXPECT_GE(space->Size(), footprint);
522 EXPECT_LE(space->Size(), growth_limit);
523
524 // Clean up
Mathieu Chartier4e305412014-02-19 10:54:44 -0800525 space->Free(self, large_object.reset(nullptr));
526
Ian Rogers3bb17a62012-01-27 23:56:44 -0800527 // Sanity check footprint
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700528 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800529 EXPECT_LE(footprint, growth_limit);
530 EXPECT_GE(space->Size(), footprint);
531 EXPECT_LE(space->Size(), growth_limit);
532}
533
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800534void SpaceTest::SizeFootPrintGrowthLimitAndTrimDriver(size_t object_size, CreateSpaceFn create_space) {
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800535 if (object_size < SizeOfZeroLengthByteArray()) {
536 // Too small for the object layout/model.
537 return;
538 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800539 size_t initial_size = 4 * MB;
540 size_t growth_limit = 8 * MB;
541 size_t capacity = 16 * MB;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800542 MallocSpace* space(create_space("test", initial_size, growth_limit, capacity, nullptr));
543 ASSERT_TRUE(space != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800544
545 // Basic sanity
546 EXPECT_EQ(space->Capacity(), growth_limit);
547 EXPECT_EQ(space->NonGrowthLimitCapacity(), capacity);
548
549 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700550 AddSpace(space);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800551
552 // In this round we don't allocate with growth and therefore can't grow past the initial size.
553 // This effectively makes the growth_limit the initial_size, so assert this.
554 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 1, initial_size);
555 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 2, growth_limit);
556 // Remove growth limit
557 space->ClearGrowthLimit();
558 EXPECT_EQ(space->Capacity(), capacity);
559 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 3, capacity);
560}
561
Andreas Gampe24651ec2014-02-27 13:26:16 -0800562#define TEST_SizeFootPrintGrowthLimitAndTrimStatic(name, spaceName, spaceFn, size) \
563 TEST_F(spaceName##StaticTest, SizeFootPrintGrowthLimitAndTrim_AllocationsOf_##name) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800564 SizeFootPrintGrowthLimitAndTrimDriver(size, spaceFn); \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800565 }
566
567#define TEST_SizeFootPrintGrowthLimitAndTrimRandom(name, spaceName, spaceFn, size) \
568 TEST_F(spaceName##RandomTest, SizeFootPrintGrowthLimitAndTrim_RandomAllocationsWithMax_##name) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800569 SizeFootPrintGrowthLimitAndTrimDriver(-size, spaceFn); \
Ian Rogers3bb17a62012-01-27 23:56:44 -0800570 }
571
Andreas Gampe24651ec2014-02-27 13:26:16 -0800572#define TEST_SPACE_CREATE_FN_BASE(spaceName, spaceFn) \
573 class spaceName##BaseTest : public SpaceTest { \
Andreas Gampea7433512014-02-21 13:19:23 -0800574 }; \
575 \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800576 TEST_F(spaceName##BaseTest, Init) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800577 InitTestBody(spaceFn); \
578 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800579 TEST_F(spaceName##BaseTest, ZygoteSpace) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800580 ZygoteSpaceTestBody(spaceFn); \
581 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800582 TEST_F(spaceName##BaseTest, AllocAndFree) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800583 AllocAndFreeTestBody(spaceFn); \
584 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800585 TEST_F(spaceName##BaseTest, AllocAndFreeList) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800586 AllocAndFreeListTestBody(spaceFn); \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800587 }
588
589#define TEST_SPACE_CREATE_FN_STATIC(spaceName, spaceFn) \
590 class spaceName##StaticTest : public SpaceTest { \
591 }; \
592 \
593 TEST_SizeFootPrintGrowthLimitAndTrimStatic(12B, spaceName, spaceFn, 12) \
594 TEST_SizeFootPrintGrowthLimitAndTrimStatic(16B, spaceName, spaceFn, 16) \
595 TEST_SizeFootPrintGrowthLimitAndTrimStatic(24B, spaceName, spaceFn, 24) \
596 TEST_SizeFootPrintGrowthLimitAndTrimStatic(32B, spaceName, spaceFn, 32) \
597 TEST_SizeFootPrintGrowthLimitAndTrimStatic(64B, spaceName, spaceFn, 64) \
598 TEST_SizeFootPrintGrowthLimitAndTrimStatic(128B, spaceName, spaceFn, 128) \
599 TEST_SizeFootPrintGrowthLimitAndTrimStatic(1KB, spaceName, spaceFn, 1 * KB) \
600 TEST_SizeFootPrintGrowthLimitAndTrimStatic(4KB, spaceName, spaceFn, 4 * KB) \
601 TEST_SizeFootPrintGrowthLimitAndTrimStatic(1MB, spaceName, spaceFn, 1 * MB) \
602 TEST_SizeFootPrintGrowthLimitAndTrimStatic(4MB, spaceName, spaceFn, 4 * MB) \
603 TEST_SizeFootPrintGrowthLimitAndTrimStatic(8MB, spaceName, spaceFn, 8 * MB)
604
605#define TEST_SPACE_CREATE_FN_RANDOM(spaceName, spaceFn) \
606 class spaceName##RandomTest : public SpaceTest { \
607 }; \
608 \
609 TEST_SizeFootPrintGrowthLimitAndTrimRandom(16B, spaceName, spaceFn, 16) \
610 TEST_SizeFootPrintGrowthLimitAndTrimRandom(24B, spaceName, spaceFn, 24) \
611 TEST_SizeFootPrintGrowthLimitAndTrimRandom(32B, spaceName, spaceFn, 32) \
612 TEST_SizeFootPrintGrowthLimitAndTrimRandom(64B, spaceName, spaceFn, 64) \
613 TEST_SizeFootPrintGrowthLimitAndTrimRandom(128B, spaceName, spaceFn, 128) \
614 TEST_SizeFootPrintGrowthLimitAndTrimRandom(1KB, spaceName, spaceFn, 1 * KB) \
615 TEST_SizeFootPrintGrowthLimitAndTrimRandom(4KB, spaceName, spaceFn, 4 * KB) \
616 TEST_SizeFootPrintGrowthLimitAndTrimRandom(1MB, spaceName, spaceFn, 1 * MB) \
617 TEST_SizeFootPrintGrowthLimitAndTrimRandom(4MB, spaceName, spaceFn, 4 * MB) \
618 TEST_SizeFootPrintGrowthLimitAndTrimRandom(8MB, spaceName, spaceFn, 8 * MB)
Ian Rogers3bb17a62012-01-27 23:56:44 -0800619
Ian Rogers1d54e732013-05-02 21:10:01 -0700620} // namespace space
621} // namespace gc
Carl Shapiro69759ea2011-07-21 18:13:35 -0700622} // namespace art
Andreas Gampea7433512014-02-21 13:19:23 -0800623
624#endif // ART_RUNTIME_GC_SPACE_SPACE_TEST_H_