blob: 9896a4833c0d4a7c5b19bf1fa841a43b93a49589 [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) {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070042 // For RosAlloc, revoke the thread local runs before moving onto a
43 // new alloc space.
44 Runtime::Current()->GetHeap()->RevokeAllThreadLocalBuffers();
Mathieu Chartier590fee92013-09-13 13:46:47 -070045 Runtime::Current()->GetHeap()->AddSpace(space);
Ian Rogers1d54e732013-05-02 21:10:01 -070046 }
Mathieu Chartier5647d182014-03-07 15:00:39 -080047
48 mirror::Class* GetByteArrayClass(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
49 SirtRef<mirror::ClassLoader> null_loader(self, nullptr);
50 if (byte_array_class_ == nullptr) {
51 mirror::Class* byte_array_class =
52 Runtime::Current()->GetClassLinker()->FindClass(self, "[B", null_loader);
53 EXPECT_TRUE(byte_array_class != nullptr);
54 byte_array_class_ = self->GetJniEnv()->NewLocalRef(byte_array_class);
55 EXPECT_TRUE(byte_array_class_ != nullptr);
56 }
57 return reinterpret_cast<mirror::Class*>(self->DecodeJObject(byte_array_class_));
58 }
59
60 mirror::Object* Alloc(space::MallocSpace* alloc_space, Thread* self, size_t bytes,
61 size_t* bytes_allocated, size_t* usable_size)
62 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
63 SirtRef<mirror::Class> byte_array_class(self, GetByteArrayClass(self));
64 mirror::Object* obj = alloc_space->Alloc(self, bytes, bytes_allocated, usable_size);
65 if (obj != nullptr) {
66 InstallClass(obj, byte_array_class.get(), bytes);
67 }
68 return obj;
69 }
70
71 mirror::Object* AllocWithGrowth(space::MallocSpace* alloc_space, Thread* self, size_t bytes,
72 size_t* bytes_allocated, size_t* usable_size)
73 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
74 SirtRef<mirror::Class> byte_array_class(self, GetByteArrayClass(self));
75 mirror::Object* obj = alloc_space->AllocWithGrowth(self, bytes, bytes_allocated, usable_size);
76 if (obj != nullptr) {
77 InstallClass(obj, byte_array_class.get(), bytes);
78 }
79 return obj;
80 }
81
82 void InstallClass(mirror::Object* o, mirror::Class* byte_array_class, size_t size)
Mathieu Chartier4e305412014-02-19 10:54:44 -080083 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -080084 // Note the minimum size, which is the size of a zero-length byte array.
85 EXPECT_GE(size, SizeOfZeroLengthByteArray());
Mathieu Chartier4e305412014-02-19 10:54:44 -080086 EXPECT_TRUE(byte_array_class != nullptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070087 o->SetClass(byte_array_class);
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070088 if (kUseBakerOrBrooksReadBarrier) {
89 // Like the proper heap object allocation, install and verify
90 // the correct read barrier pointer.
91 if (kUseBrooksReadBarrier) {
92 o->SetReadBarrierPointer(o);
93 }
94 o->AssertReadBarrierPointer();
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080095 }
Mathieu Chartier4e305412014-02-19 10:54:44 -080096 mirror::Array* arr = o->AsArray<kVerifyNone>();
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -080097 size_t header_size = SizeOfZeroLengthByteArray();
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070098 int32_t length = size - header_size;
99 arr->SetLength(length);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800100 EXPECT_EQ(arr->SizeOf<kVerifyNone>(), size);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700101 }
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800102
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800103 static size_t SizeOfZeroLengthByteArray() {
104 return mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimByte)).Uint32Value();
105 }
106
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800107 typedef MallocSpace* (*CreateSpaceFn)(const std::string& name, size_t initial_size, size_t growth_limit,
108 size_t capacity, byte* requested_begin);
109 void InitTestBody(CreateSpaceFn create_space);
110 void ZygoteSpaceTestBody(CreateSpaceFn create_space);
111 void AllocAndFreeTestBody(CreateSpaceFn create_space);
112 void AllocAndFreeListTestBody(CreateSpaceFn create_space);
113
114 void SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
115 int round, size_t growth_limit);
116 void SizeFootPrintGrowthLimitAndTrimDriver(size_t object_size, CreateSpaceFn create_space);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800117};
Brian Carlstrom9b7f2c22011-09-27 14:35:04 -0700118
Ian Rogers719d1a32014-03-06 12:13:39 -0800119static inline size_t test_rand(size_t* seed) {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700120 *seed = *seed * 1103515245 + 12345;
121 return *seed;
122}
123
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800124void SpaceTest::InitTestBody(CreateSpaceFn create_space) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700125 {
jeffhaoc1160702011-10-27 15:48:45 -0700126 // Init < max == growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800127 UniquePtr<Space> space(create_space("test", 16 * MB, 32 * MB, 32 * MB, nullptr));
128 EXPECT_TRUE(space.get() != nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700129 }
130 {
jeffhaoc1160702011-10-27 15:48:45 -0700131 // Init == max == growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800132 UniquePtr<Space> space(create_space("test", 16 * MB, 16 * MB, 16 * MB, nullptr));
133 EXPECT_TRUE(space.get() != nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700134 }
135 {
jeffhaoc1160702011-10-27 15:48:45 -0700136 // Init > max == growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800137 UniquePtr<Space> space(create_space("test", 32 * MB, 16 * MB, 16 * MB, nullptr));
138 EXPECT_TRUE(space.get() == nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700139 }
140 {
141 // Growth == init < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800142 UniquePtr<Space> space(create_space("test", 16 * MB, 16 * MB, 32 * MB, nullptr));
143 EXPECT_TRUE(space.get() != nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700144 }
145 {
146 // Growth < init < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800147 UniquePtr<Space> space(create_space("test", 16 * MB, 8 * MB, 32 * MB, nullptr));
148 EXPECT_TRUE(space.get() == nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700149 }
150 {
151 // Init < growth < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800152 UniquePtr<Space> space(create_space("test", 8 * MB, 16 * MB, 32 * MB, nullptr));
153 EXPECT_TRUE(space.get() != nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700154 }
155 {
156 // Init < max < growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800157 UniquePtr<Space> space(create_space("test", 8 * MB, 32 * MB, 16 * MB, nullptr));
158 EXPECT_TRUE(space.get() == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700159 }
160}
161
Mathieu Chartierdcf8d722012-08-02 14:55:54 -0700162// TODO: This test is not very good, we should improve it.
163// The test should do more allocations before the creation of the ZygoteSpace, and then do
164// allocations after the ZygoteSpace is created. The test should also do some GCs to ensure that
165// the GC works with the ZygoteSpace.
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800166void SpaceTest::ZygoteSpaceTestBody(CreateSpaceFn create_space) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800167 size_t dummy;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800168 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
169 ASSERT_TRUE(space != nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700170
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800171 // Make space findable to the heap, will also delete space when runtime is cleaned up
172 AddSpace(space);
173 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800174 ScopedObjectAccess soa(self);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700175
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800176 // Succeeds, fits without adjusting the footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800177 size_t ptr1_bytes_allocated, ptr1_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800178 SirtRef<mirror::Object> ptr1(self, Alloc(space, self, 1 * MB, &ptr1_bytes_allocated,
179 &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800180 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800181 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
182 EXPECT_LE(1U * MB, ptr1_usable_size);
183 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700184
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800185 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800186 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800187 EXPECT_TRUE(ptr2 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700188
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800189 // Succeeds, adjusts the footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800190 size_t ptr3_bytes_allocated, ptr3_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800191 SirtRef<mirror::Object> ptr3(self, AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated,
192 &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800193 EXPECT_TRUE(ptr3.get() != nullptr);
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800194 EXPECT_LE(8U * MB, ptr3_bytes_allocated);
Ian Rogers6fac4472014-02-25 17:01:10 -0800195 EXPECT_LE(8U * MB, ptr3_usable_size);
196 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700197
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800198 // Fails, requires a higher footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800199 mirror::Object* ptr4 = space->Alloc(self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800200 EXPECT_TRUE(ptr4 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700201
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800202 // Also fails, requires a higher allowed footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800203 mirror::Object* ptr5 = space->AllocWithGrowth(self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800204 EXPECT_TRUE(ptr5 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700205
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800206 // Release some memory.
Ian Rogers6fac4472014-02-25 17:01:10 -0800207 size_t free3 = space->AllocationSize(ptr3.get(), nullptr);
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800208 EXPECT_EQ(free3, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800209 EXPECT_EQ(free3, space->Free(self, ptr3.reset(nullptr)));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800210 EXPECT_LE(8U * MB, free3);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700211
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800212 // Succeeds, now that memory has been freed.
Ian Rogers6fac4472014-02-25 17:01:10 -0800213 size_t ptr6_bytes_allocated, ptr6_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800214 SirtRef<mirror::Object> ptr6(self, AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated,
215 &ptr6_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800216 EXPECT_TRUE(ptr6.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800217 EXPECT_LE(9U * MB, ptr6_bytes_allocated);
218 EXPECT_LE(9U * MB, ptr6_usable_size);
219 EXPECT_LE(ptr6_usable_size, ptr6_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700220
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800221 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800222 size_t free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800223 space->Free(self, ptr1.reset(nullptr));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800224 EXPECT_LE(1U * MB, free1);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700225
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800226 // Make sure that the zygote space isn't directly at the start of the space.
Ian Rogers6fac4472014-02-25 17:01:10 -0800227 EXPECT_TRUE(space->Alloc(self, 1U * MB, &dummy, nullptr) != nullptr);
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800228
229 gc::Heap* heap = Runtime::Current()->GetHeap();
230 space::Space* old_space = space;
231 heap->RemoveSpace(old_space);
232 space::ZygoteSpace* zygote_space = space->CreateZygoteSpace("alloc space",
233 heap->IsLowMemoryMode(),
234 &space);
235 delete old_space;
236 // Add the zygote space.
237 AddSpace(zygote_space);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700238
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800239 // Make space findable to the heap, will also delete space when runtime is cleaned up
240 AddSpace(space);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700241
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800242 // Succeeds, fits without adjusting the footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800243 ptr1.reset(Alloc(space, self, 1 * MB, &ptr1_bytes_allocated, &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800244 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800245 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
246 EXPECT_LE(1U * MB, ptr1_usable_size);
247 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700248
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800249 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800250 ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800251 EXPECT_TRUE(ptr2 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700252
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800253 // Succeeds, adjusts the footprint.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800254 ptr3.reset(AllocWithGrowth(space, self, 2 * MB, &ptr3_bytes_allocated, &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800255 EXPECT_TRUE(ptr3.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800256 EXPECT_LE(2U * MB, ptr3_bytes_allocated);
257 EXPECT_LE(2U * MB, ptr3_usable_size);
258 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800259 space->Free(self, ptr3.reset(nullptr));
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700260
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800261 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800262 free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800263 space->Free(self, ptr1.reset(nullptr));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800264 EXPECT_LE(1U * MB, free1);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700265}
266
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800267void SpaceTest::AllocAndFreeTestBody(CreateSpaceFn create_space) {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700268 size_t dummy = 0;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800269 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
270 ASSERT_TRUE(space != nullptr);
Ian Rogers50b35e22012-10-04 10:09:15 -0700271 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800272 ScopedObjectAccess soa(self);
Ian Rogers30fab402012-01-23 15:43:46 -0800273
Ian Rogers3bb17a62012-01-27 23:56:44 -0800274 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700275 AddSpace(space);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700276
Ian Rogers3bb17a62012-01-27 23:56:44 -0800277 // Succeeds, fits without adjusting the footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800278 size_t ptr1_bytes_allocated, ptr1_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800279 SirtRef<mirror::Object> ptr1(self, Alloc(space, self, 1 * MB, &ptr1_bytes_allocated,
280 &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800281 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800282 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
283 EXPECT_LE(1U * MB, ptr1_usable_size);
284 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700285
Ian Rogers3bb17a62012-01-27 23:56:44 -0800286 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800287 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800288 EXPECT_TRUE(ptr2 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700289
290 // Succeeds, adjusts the footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800291 size_t ptr3_bytes_allocated, ptr3_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800292 SirtRef<mirror::Object> ptr3(self, AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated,
293 &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800294 EXPECT_TRUE(ptr3.get() != nullptr);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700295 EXPECT_LE(8U * MB, ptr3_bytes_allocated);
Ian Rogers6fac4472014-02-25 17:01:10 -0800296 EXPECT_LE(8U * MB, ptr3_usable_size);
297 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700298
Ian Rogers3bb17a62012-01-27 23:56:44 -0800299 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800300 mirror::Object* ptr4 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800301 EXPECT_TRUE(ptr4 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700302
303 // Also fails, requires a higher allowed footprint.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800304 mirror::Object* ptr5 = AllocWithGrowth(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800305 EXPECT_TRUE(ptr5 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700306
307 // Release some memory.
Ian Rogers6fac4472014-02-25 17:01:10 -0800308 size_t free3 = space->AllocationSize(ptr3.get(), nullptr);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700309 EXPECT_EQ(free3, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800310 space->Free(self, ptr3.reset(nullptr));
Carl Shapiro69759ea2011-07-21 18:13:35 -0700311 EXPECT_LE(8U * MB, free3);
312
313 // Succeeds, now that memory has been freed.
Ian Rogers6fac4472014-02-25 17:01:10 -0800314 size_t ptr6_bytes_allocated, ptr6_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800315 SirtRef<mirror::Object> ptr6(self, AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated,
316 &ptr6_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800317 EXPECT_TRUE(ptr6.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800318 EXPECT_LE(9U * MB, ptr6_bytes_allocated);
319 EXPECT_LE(9U * MB, ptr6_usable_size);
320 EXPECT_LE(ptr6_usable_size, ptr6_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700321
322 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800323 size_t free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800324 space->Free(self, ptr1.reset(nullptr));
Carl Shapiro69759ea2011-07-21 18:13:35 -0700325 EXPECT_LE(1U * MB, free1);
326}
327
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800328void SpaceTest::AllocAndFreeListTestBody(CreateSpaceFn create_space) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800329 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
330 ASSERT_TRUE(space != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800331
332 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700333 AddSpace(space);
Ian Rogers50b35e22012-10-04 10:09:15 -0700334 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800335 ScopedObjectAccess soa(self);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800336
337 // Succeeds, fits without adjusting the max allowed footprint.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338 mirror::Object* lots_of_objects[1024];
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700339 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800340 size_t allocation_size, usable_size;
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800341 size_t size_of_zero_length_byte_array = SizeOfZeroLengthByteArray();
Mathieu Chartier5647d182014-03-07 15:00:39 -0800342 lots_of_objects[i] = Alloc(space, self, size_of_zero_length_byte_array, &allocation_size,
343 &usable_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800344 EXPECT_TRUE(lots_of_objects[i] != nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800345 SirtRef<mirror::Object> obj(self, lots_of_objects[i]);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800346 lots_of_objects[i] = obj.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800347 size_t computed_usable_size;
348 EXPECT_EQ(allocation_size, space->AllocationSize(lots_of_objects[i], &computed_usable_size));
349 EXPECT_EQ(usable_size, computed_usable_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800350 }
351
Mathieu Chartier4e305412014-02-19 10:54:44 -0800352 // Release memory and check pointers are nullptr.
353 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
354 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
355 EXPECT_TRUE(lots_of_objects[i] == nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800356 }
357
358 // Succeeds, fits by adjusting the max allowed footprint.
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700359 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800360 size_t allocation_size, usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800361 lots_of_objects[i] = AllocWithGrowth(space, self, 1024, &allocation_size, &usable_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800362 EXPECT_TRUE(lots_of_objects[i] != nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800363 SirtRef<mirror::Object> obj(self, lots_of_objects[i]);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800364 lots_of_objects[i] = obj.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800365 size_t computed_usable_size;
366 EXPECT_EQ(allocation_size, space->AllocationSize(lots_of_objects[i], &computed_usable_size));
367 EXPECT_EQ(usable_size, computed_usable_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800368 }
369
Mathieu Chartier4e305412014-02-19 10:54:44 -0800370 // Release memory and check pointers are nullptr
371 // TODO: This isn't compaction safe, fix.
372 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
373 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
374 EXPECT_TRUE(lots_of_objects[i] == nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800375 }
376}
377
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800378void SpaceTest::SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
Ian Rogers3bb17a62012-01-27 23:56:44 -0800379 int round, size_t growth_limit) {
380 if (((object_size > 0 && object_size >= static_cast<intptr_t>(growth_limit))) ||
381 ((object_size < 0 && -object_size >= static_cast<intptr_t>(growth_limit)))) {
382 // No allocation can succeed
383 return;
384 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800385
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700386 // The space's footprint equals amount of resources requested from system
387 size_t footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800388
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700389 // The space must at least have its book keeping allocated
Ian Rogers3bb17a62012-01-27 23:56:44 -0800390 EXPECT_GT(footprint, 0u);
391
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700392 // But it shouldn't exceed the initial size
Ian Rogers3bb17a62012-01-27 23:56:44 -0800393 EXPECT_LE(footprint, growth_limit);
394
395 // space's size shouldn't exceed the initial size
396 EXPECT_LE(space->Size(), growth_limit);
397
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700398 // this invariant should always hold or else the space has grown to be larger than what the
Ian Rogers3bb17a62012-01-27 23:56:44 -0800399 // space believes its size is (which will break invariants)
400 EXPECT_GE(space->Size(), footprint);
401
402 // Fill the space with lots of small objects up to the growth limit
403 size_t max_objects = (growth_limit / (object_size > 0 ? object_size : 8)) + 1;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800404 UniquePtr<mirror::Object*[]> lots_of_objects(new mirror::Object*[max_objects]);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800405 size_t last_object = 0; // last object for which allocation succeeded
406 size_t amount_allocated = 0; // amount of space allocated
Ian Rogers50b35e22012-10-04 10:09:15 -0700407 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800408 ScopedObjectAccess soa(self);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700409 size_t rand_seed = 123456789;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700410 for (size_t i = 0; i < max_objects; i++) {
Ian Rogers3bb17a62012-01-27 23:56:44 -0800411 size_t alloc_fails = 0; // number of failed allocations
412 size_t max_fails = 30; // number of times we fail allocation before giving up
413 for (; alloc_fails < max_fails; alloc_fails++) {
414 size_t alloc_size;
415 if (object_size > 0) {
416 alloc_size = object_size;
417 } else {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700418 alloc_size = test_rand(&rand_seed) % static_cast<size_t>(-object_size);
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800419 // Note the minimum size, which is the size of a zero-length byte array.
420 size_t size_of_zero_length_byte_array = SizeOfZeroLengthByteArray();
421 if (alloc_size < size_of_zero_length_byte_array) {
422 alloc_size = size_of_zero_length_byte_array;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800423 }
424 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800425 SirtRef<mirror::Object> object(self, nullptr);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700426 size_t bytes_allocated = 0;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800427 if (round <= 1) {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800428 object.reset(Alloc(space, self, alloc_size, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800429 } else {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800430 object.reset(AllocWithGrowth(space, self, alloc_size, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800431 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700432 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800433 EXPECT_GE(space->Size(), footprint); // invariant
Mathieu Chartier4e305412014-02-19 10:54:44 -0800434 if (object.get() != nullptr) { // allocation succeeded
Mathieu Chartier4e305412014-02-19 10:54:44 -0800435 lots_of_objects[i] = object.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800436 size_t allocation_size = space->AllocationSize(object.get(), nullptr);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700437 EXPECT_EQ(bytes_allocated, allocation_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800438 if (object_size > 0) {
439 EXPECT_GE(allocation_size, static_cast<size_t>(object_size));
440 } else {
441 EXPECT_GE(allocation_size, 8u);
442 }
443 amount_allocated += allocation_size;
444 break;
445 }
446 }
447 if (alloc_fails == max_fails) {
448 last_object = i;
449 break;
450 }
451 }
452 CHECK_NE(last_object, 0u); // we should have filled the space
453 EXPECT_GT(amount_allocated, 0u);
454
455 // We shouldn't have gone past the growth_limit
456 EXPECT_LE(amount_allocated, growth_limit);
457 EXPECT_LE(footprint, growth_limit);
458 EXPECT_LE(space->Size(), growth_limit);
459
460 // footprint and size should agree with amount allocated
461 EXPECT_GE(footprint, amount_allocated);
462 EXPECT_GE(space->Size(), amount_allocated);
463
464 // Release storage in a semi-adhoc manner
465 size_t free_increment = 96;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700466 while (true) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800467 {
468 ScopedThreadStateChange tsc(self, kNative);
469 // Give the space a haircut.
470 space->Trim();
471 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800472
473 // Bounds sanity
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700474 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800475 EXPECT_LE(amount_allocated, growth_limit);
476 EXPECT_GE(footprint, amount_allocated);
477 EXPECT_LE(footprint, growth_limit);
478 EXPECT_GE(space->Size(), amount_allocated);
479 EXPECT_LE(space->Size(), growth_limit);
480
481 if (free_increment == 0) {
482 break;
483 }
484
Mathieu Chartier4e305412014-02-19 10:54:44 -0800485 // Free some objects
486 for (size_t i = 0; i < last_object; i += free_increment) {
487 mirror::Object* object = lots_of_objects.get()[i];
488 if (object == nullptr) {
489 continue;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800490 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800491 size_t allocation_size = space->AllocationSize(object, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800492 if (object_size > 0) {
493 EXPECT_GE(allocation_size, static_cast<size_t>(object_size));
494 } else {
495 EXPECT_GE(allocation_size, 8u);
496 }
497 space->Free(self, object);
498 lots_of_objects.get()[i] = nullptr;
499 amount_allocated -= allocation_size;
500 footprint = space->GetFootprint();
501 EXPECT_GE(space->Size(), footprint); // invariant
Ian Rogers3bb17a62012-01-27 23:56:44 -0800502 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800503
504 free_increment >>= 1;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800505 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800506
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700507 // The space has become empty here before allocating a large object
508 // below. For RosAlloc, revoke thread-local runs, which are kept
509 // even when empty for a performance reason, so that they won't
510 // cause the following large object allocation to fail due to
511 // potential fragmentation. Note they are normally revoked at each
512 // GC (but no GC here.)
513 space->RevokeAllThreadLocalBuffers();
514
Ian Rogers3bb17a62012-01-27 23:56:44 -0800515 // All memory was released, try a large allocation to check freed memory is being coalesced
Mathieu Chartier4e305412014-02-19 10:54:44 -0800516 SirtRef<mirror::Object> large_object(self, nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800517 size_t three_quarters_space = (growth_limit / 2) + (growth_limit / 4);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700518 size_t bytes_allocated = 0;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800519 if (round <= 1) {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800520 large_object.reset(Alloc(space, self, three_quarters_space, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800521 } else {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800522 large_object.reset(AllocWithGrowth(space, self, three_quarters_space, &bytes_allocated,
523 nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800524 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800525 EXPECT_TRUE(large_object.get() != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800526
527 // 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 // Clean up
Mathieu Chartier4e305412014-02-19 10:54:44 -0800534 space->Free(self, large_object.reset(nullptr));
535
Ian Rogers3bb17a62012-01-27 23:56:44 -0800536 // Sanity check footprint
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700537 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800538 EXPECT_LE(footprint, growth_limit);
539 EXPECT_GE(space->Size(), footprint);
540 EXPECT_LE(space->Size(), growth_limit);
541}
542
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800543void SpaceTest::SizeFootPrintGrowthLimitAndTrimDriver(size_t object_size, CreateSpaceFn create_space) {
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800544 if (object_size < SizeOfZeroLengthByteArray()) {
545 // Too small for the object layout/model.
546 return;
547 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800548 size_t initial_size = 4 * MB;
549 size_t growth_limit = 8 * MB;
550 size_t capacity = 16 * MB;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800551 MallocSpace* space(create_space("test", initial_size, growth_limit, capacity, nullptr));
552 ASSERT_TRUE(space != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800553
554 // Basic sanity
555 EXPECT_EQ(space->Capacity(), growth_limit);
556 EXPECT_EQ(space->NonGrowthLimitCapacity(), capacity);
557
558 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700559 AddSpace(space);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800560
561 // In this round we don't allocate with growth and therefore can't grow past the initial size.
562 // This effectively makes the growth_limit the initial_size, so assert this.
563 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 1, initial_size);
564 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 2, growth_limit);
565 // Remove growth limit
566 space->ClearGrowthLimit();
567 EXPECT_EQ(space->Capacity(), capacity);
568 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 3, capacity);
569}
570
Andreas Gampe24651ec2014-02-27 13:26:16 -0800571#define TEST_SizeFootPrintGrowthLimitAndTrimStatic(name, spaceName, spaceFn, size) \
572 TEST_F(spaceName##StaticTest, SizeFootPrintGrowthLimitAndTrim_AllocationsOf_##name) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800573 SizeFootPrintGrowthLimitAndTrimDriver(size, spaceFn); \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800574 }
575
576#define TEST_SizeFootPrintGrowthLimitAndTrimRandom(name, spaceName, spaceFn, size) \
577 TEST_F(spaceName##RandomTest, SizeFootPrintGrowthLimitAndTrim_RandomAllocationsWithMax_##name) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800578 SizeFootPrintGrowthLimitAndTrimDriver(-size, spaceFn); \
Ian Rogers3bb17a62012-01-27 23:56:44 -0800579 }
580
Andreas Gampe24651ec2014-02-27 13:26:16 -0800581#define TEST_SPACE_CREATE_FN_BASE(spaceName, spaceFn) \
582 class spaceName##BaseTest : public SpaceTest { \
Andreas Gampea7433512014-02-21 13:19:23 -0800583 }; \
584 \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800585 TEST_F(spaceName##BaseTest, Init) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800586 InitTestBody(spaceFn); \
587 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800588 TEST_F(spaceName##BaseTest, ZygoteSpace) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800589 ZygoteSpaceTestBody(spaceFn); \
590 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800591 TEST_F(spaceName##BaseTest, AllocAndFree) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800592 AllocAndFreeTestBody(spaceFn); \
593 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800594 TEST_F(spaceName##BaseTest, AllocAndFreeList) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800595 AllocAndFreeListTestBody(spaceFn); \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800596 }
597
598#define TEST_SPACE_CREATE_FN_STATIC(spaceName, spaceFn) \
599 class spaceName##StaticTest : public SpaceTest { \
600 }; \
601 \
602 TEST_SizeFootPrintGrowthLimitAndTrimStatic(12B, spaceName, spaceFn, 12) \
603 TEST_SizeFootPrintGrowthLimitAndTrimStatic(16B, spaceName, spaceFn, 16) \
604 TEST_SizeFootPrintGrowthLimitAndTrimStatic(24B, spaceName, spaceFn, 24) \
605 TEST_SizeFootPrintGrowthLimitAndTrimStatic(32B, spaceName, spaceFn, 32) \
606 TEST_SizeFootPrintGrowthLimitAndTrimStatic(64B, spaceName, spaceFn, 64) \
607 TEST_SizeFootPrintGrowthLimitAndTrimStatic(128B, spaceName, spaceFn, 128) \
608 TEST_SizeFootPrintGrowthLimitAndTrimStatic(1KB, spaceName, spaceFn, 1 * KB) \
609 TEST_SizeFootPrintGrowthLimitAndTrimStatic(4KB, spaceName, spaceFn, 4 * KB) \
610 TEST_SizeFootPrintGrowthLimitAndTrimStatic(1MB, spaceName, spaceFn, 1 * MB) \
611 TEST_SizeFootPrintGrowthLimitAndTrimStatic(4MB, spaceName, spaceFn, 4 * MB) \
612 TEST_SizeFootPrintGrowthLimitAndTrimStatic(8MB, spaceName, spaceFn, 8 * MB)
613
614#define TEST_SPACE_CREATE_FN_RANDOM(spaceName, spaceFn) \
615 class spaceName##RandomTest : public SpaceTest { \
616 }; \
617 \
618 TEST_SizeFootPrintGrowthLimitAndTrimRandom(16B, spaceName, spaceFn, 16) \
619 TEST_SizeFootPrintGrowthLimitAndTrimRandom(24B, spaceName, spaceFn, 24) \
620 TEST_SizeFootPrintGrowthLimitAndTrimRandom(32B, spaceName, spaceFn, 32) \
621 TEST_SizeFootPrintGrowthLimitAndTrimRandom(64B, spaceName, spaceFn, 64) \
622 TEST_SizeFootPrintGrowthLimitAndTrimRandom(128B, spaceName, spaceFn, 128) \
623 TEST_SizeFootPrintGrowthLimitAndTrimRandom(1KB, spaceName, spaceFn, 1 * KB) \
624 TEST_SizeFootPrintGrowthLimitAndTrimRandom(4KB, spaceName, spaceFn, 4 * KB) \
625 TEST_SizeFootPrintGrowthLimitAndTrimRandom(1MB, spaceName, spaceFn, 1 * MB) \
626 TEST_SizeFootPrintGrowthLimitAndTrimRandom(4MB, spaceName, spaceFn, 4 * MB) \
627 TEST_SizeFootPrintGrowthLimitAndTrimRandom(8MB, spaceName, spaceFn, 8 * MB)
Ian Rogers3bb17a62012-01-27 23:56:44 -0800628
Ian Rogers1d54e732013-05-02 21:10:01 -0700629} // namespace space
630} // namespace gc
Carl Shapiro69759ea2011-07-21 18:13:35 -0700631} // namespace art
Andreas Gampea7433512014-02-21 13:19:23 -0800632
633#endif // ART_RUNTIME_GC_SPACE_SPACE_TEST_H_