blob: 5c735df4577286412f4ebbc8c2bfc2268eedc2b0 [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 Yamauchi624468c2014-03-31 15:14:47 -070088 if (kUseBrooksReadBarrier) {
89 o->SetReadBarrierPointer(o);
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080090 }
Mathieu Chartier4e305412014-02-19 10:54:44 -080091 mirror::Array* arr = o->AsArray<kVerifyNone>();
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -080092 size_t header_size = SizeOfZeroLengthByteArray();
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070093 int32_t length = size - header_size;
94 arr->SetLength(length);
Mathieu Chartier4e305412014-02-19 10:54:44 -080095 EXPECT_EQ(arr->SizeOf<kVerifyNone>(), size);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070096 }
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -080097
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -080098 static size_t SizeOfZeroLengthByteArray() {
99 return mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimByte)).Uint32Value();
100 }
101
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800102 typedef MallocSpace* (*CreateSpaceFn)(const std::string& name, size_t initial_size, size_t growth_limit,
103 size_t capacity, byte* requested_begin);
104 void InitTestBody(CreateSpaceFn create_space);
105 void ZygoteSpaceTestBody(CreateSpaceFn create_space);
106 void AllocAndFreeTestBody(CreateSpaceFn create_space);
107 void AllocAndFreeListTestBody(CreateSpaceFn create_space);
108
109 void SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
110 int round, size_t growth_limit);
111 void SizeFootPrintGrowthLimitAndTrimDriver(size_t object_size, CreateSpaceFn create_space);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800112};
Brian Carlstrom9b7f2c22011-09-27 14:35:04 -0700113
Ian Rogers719d1a32014-03-06 12:13:39 -0800114static inline size_t test_rand(size_t* seed) {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700115 *seed = *seed * 1103515245 + 12345;
116 return *seed;
117}
118
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800119void SpaceTest::InitTestBody(CreateSpaceFn create_space) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700120 {
jeffhaoc1160702011-10-27 15:48:45 -0700121 // Init < max == growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800122 UniquePtr<Space> space(create_space("test", 16 * MB, 32 * MB, 32 * MB, nullptr));
123 EXPECT_TRUE(space.get() != nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700124 }
125 {
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, 16 * MB, 16 * 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", 32 * MB, 16 * MB, 16 * MB, nullptr));
133 EXPECT_TRUE(space.get() == nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700134 }
135 {
136 // Growth == init < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800137 UniquePtr<Space> space(create_space("test", 16 * MB, 16 * MB, 32 * 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, 8 * MB, 32 * MB, nullptr));
143 EXPECT_TRUE(space.get() == nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700144 }
145 {
146 // Init < growth < max
Mathieu Chartier4e305412014-02-19 10:54:44 -0800147 UniquePtr<Space> space(create_space("test", 8 * MB, 16 * MB, 32 * MB, nullptr));
148 EXPECT_TRUE(space.get() != nullptr);
jeffhaoc1160702011-10-27 15:48:45 -0700149 }
150 {
151 // Init < max < growth
Mathieu Chartier4e305412014-02-19 10:54:44 -0800152 UniquePtr<Space> space(create_space("test", 8 * MB, 32 * MB, 16 * MB, nullptr));
153 EXPECT_TRUE(space.get() == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700154 }
155}
156
Mathieu Chartierdcf8d722012-08-02 14:55:54 -0700157// TODO: This test is not very good, we should improve it.
158// The test should do more allocations before the creation of the ZygoteSpace, and then do
159// allocations after the ZygoteSpace is created. The test should also do some GCs to ensure that
160// the GC works with the ZygoteSpace.
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800161void SpaceTest::ZygoteSpaceTestBody(CreateSpaceFn create_space) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800162 size_t dummy;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800163 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
164 ASSERT_TRUE(space != nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700165
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800166 // Make space findable to the heap, will also delete space when runtime is cleaned up
167 AddSpace(space);
168 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800169 ScopedObjectAccess soa(self);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700170
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800171 // Succeeds, fits without adjusting the footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800172 size_t ptr1_bytes_allocated, ptr1_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800173 SirtRef<mirror::Object> ptr1(self, Alloc(space, self, 1 * MB, &ptr1_bytes_allocated,
174 &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800175 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800176 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
177 EXPECT_LE(1U * MB, ptr1_usable_size);
178 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700179
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800180 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800181 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800182 EXPECT_TRUE(ptr2 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700183
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800184 // Succeeds, adjusts the footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800185 size_t ptr3_bytes_allocated, ptr3_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800186 SirtRef<mirror::Object> ptr3(self, AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated,
187 &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800188 EXPECT_TRUE(ptr3.get() != nullptr);
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800189 EXPECT_LE(8U * MB, ptr3_bytes_allocated);
Ian Rogers6fac4472014-02-25 17:01:10 -0800190 EXPECT_LE(8U * MB, ptr3_usable_size);
191 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700192
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800193 // Fails, requires a higher footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800194 mirror::Object* ptr4 = space->Alloc(self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800195 EXPECT_TRUE(ptr4 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700196
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800197 // Also fails, requires a higher allowed footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800198 mirror::Object* ptr5 = space->AllocWithGrowth(self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 EXPECT_TRUE(ptr5 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700200
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800201 // Release some memory.
Ian Rogers6fac4472014-02-25 17:01:10 -0800202 size_t free3 = space->AllocationSize(ptr3.get(), nullptr);
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800203 EXPECT_EQ(free3, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800204 EXPECT_EQ(free3, space->Free(self, ptr3.reset(nullptr)));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800205 EXPECT_LE(8U * MB, free3);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700206
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800207 // Succeeds, now that memory has been freed.
Ian Rogers6fac4472014-02-25 17:01:10 -0800208 size_t ptr6_bytes_allocated, ptr6_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800209 SirtRef<mirror::Object> ptr6(self, AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated,
210 &ptr6_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800211 EXPECT_TRUE(ptr6.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800212 EXPECT_LE(9U * MB, ptr6_bytes_allocated);
213 EXPECT_LE(9U * MB, ptr6_usable_size);
214 EXPECT_LE(ptr6_usable_size, ptr6_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700215
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800216 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800217 size_t free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800218 space->Free(self, ptr1.reset(nullptr));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800219 EXPECT_LE(1U * MB, free1);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700220
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800221 // Make sure that the zygote space isn't directly at the start of the space.
Ian Rogers6fac4472014-02-25 17:01:10 -0800222 EXPECT_TRUE(space->Alloc(self, 1U * MB, &dummy, nullptr) != nullptr);
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800223
224 gc::Heap* heap = Runtime::Current()->GetHeap();
225 space::Space* old_space = space;
226 heap->RemoveSpace(old_space);
227 space::ZygoteSpace* zygote_space = space->CreateZygoteSpace("alloc space",
228 heap->IsLowMemoryMode(),
229 &space);
230 delete old_space;
231 // Add the zygote space.
232 AddSpace(zygote_space);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700233
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800234 // Make space findable to the heap, will also delete space when runtime is cleaned up
235 AddSpace(space);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700236
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800237 // Succeeds, fits without adjusting the footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800238 ptr1.reset(Alloc(space, self, 1 * MB, &ptr1_bytes_allocated, &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800239 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800240 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
241 EXPECT_LE(1U * MB, ptr1_usable_size);
242 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700243
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800244 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800245 ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800246 EXPECT_TRUE(ptr2 == nullptr);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700247
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800248 // Succeeds, adjusts the footprint.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800249 ptr3.reset(AllocWithGrowth(space, self, 2 * MB, &ptr3_bytes_allocated, &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800250 EXPECT_TRUE(ptr3.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800251 EXPECT_LE(2U * MB, ptr3_bytes_allocated);
252 EXPECT_LE(2U * MB, ptr3_usable_size);
253 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800254 space->Free(self, ptr3.reset(nullptr));
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700255
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800256 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800257 free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800258 space->Free(self, ptr1.reset(nullptr));
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800259 EXPECT_LE(1U * MB, free1);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700260}
261
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800262void SpaceTest::AllocAndFreeTestBody(CreateSpaceFn create_space) {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700263 size_t dummy = 0;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800264 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
265 ASSERT_TRUE(space != nullptr);
Ian Rogers50b35e22012-10-04 10:09:15 -0700266 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800267 ScopedObjectAccess soa(self);
Ian Rogers30fab402012-01-23 15:43:46 -0800268
Ian Rogers3bb17a62012-01-27 23:56:44 -0800269 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700270 AddSpace(space);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700271
Ian Rogers3bb17a62012-01-27 23:56:44 -0800272 // Succeeds, fits without adjusting the footprint limit.
Ian Rogers6fac4472014-02-25 17:01:10 -0800273 size_t ptr1_bytes_allocated, ptr1_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800274 SirtRef<mirror::Object> ptr1(self, Alloc(space, self, 1 * MB, &ptr1_bytes_allocated,
275 &ptr1_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800276 EXPECT_TRUE(ptr1.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800277 EXPECT_LE(1U * MB, ptr1_bytes_allocated);
278 EXPECT_LE(1U * MB, ptr1_usable_size);
279 EXPECT_LE(ptr1_usable_size, ptr1_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700280
Ian Rogers3bb17a62012-01-27 23:56:44 -0800281 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800282 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800283 EXPECT_TRUE(ptr2 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700284
285 // Succeeds, adjusts the footprint.
Ian Rogers6fac4472014-02-25 17:01:10 -0800286 size_t ptr3_bytes_allocated, ptr3_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800287 SirtRef<mirror::Object> ptr3(self, AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated,
288 &ptr3_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800289 EXPECT_TRUE(ptr3.get() != nullptr);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700290 EXPECT_LE(8U * MB, ptr3_bytes_allocated);
Ian Rogers6fac4472014-02-25 17:01:10 -0800291 EXPECT_LE(8U * MB, ptr3_usable_size);
292 EXPECT_LE(ptr3_usable_size, ptr3_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700293
Ian Rogers3bb17a62012-01-27 23:56:44 -0800294 // Fails, requires a higher footprint limit.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800295 mirror::Object* ptr4 = Alloc(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800296 EXPECT_TRUE(ptr4 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700297
298 // Also fails, requires a higher allowed footprint.
Mathieu Chartier5647d182014-03-07 15:00:39 -0800299 mirror::Object* ptr5 = AllocWithGrowth(space, self, 8 * MB, &dummy, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800300 EXPECT_TRUE(ptr5 == nullptr);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700301
302 // Release some memory.
Ian Rogers6fac4472014-02-25 17:01:10 -0800303 size_t free3 = space->AllocationSize(ptr3.get(), nullptr);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700304 EXPECT_EQ(free3, ptr3_bytes_allocated);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800305 space->Free(self, ptr3.reset(nullptr));
Carl Shapiro69759ea2011-07-21 18:13:35 -0700306 EXPECT_LE(8U * MB, free3);
307
308 // Succeeds, now that memory has been freed.
Ian Rogers6fac4472014-02-25 17:01:10 -0800309 size_t ptr6_bytes_allocated, ptr6_usable_size;
Mathieu Chartier5647d182014-03-07 15:00:39 -0800310 SirtRef<mirror::Object> ptr6(self, AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated,
311 &ptr6_usable_size));
Mathieu Chartier4e305412014-02-19 10:54:44 -0800312 EXPECT_TRUE(ptr6.get() != nullptr);
Ian Rogers6fac4472014-02-25 17:01:10 -0800313 EXPECT_LE(9U * MB, ptr6_bytes_allocated);
314 EXPECT_LE(9U * MB, ptr6_usable_size);
315 EXPECT_LE(ptr6_usable_size, ptr6_bytes_allocated);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700316
317 // Final clean up.
Ian Rogers6fac4472014-02-25 17:01:10 -0800318 size_t free1 = space->AllocationSize(ptr1.get(), nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800319 space->Free(self, ptr1.reset(nullptr));
Carl Shapiro69759ea2011-07-21 18:13:35 -0700320 EXPECT_LE(1U * MB, free1);
321}
322
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800323void SpaceTest::AllocAndFreeListTestBody(CreateSpaceFn create_space) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800324 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
325 ASSERT_TRUE(space != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800326
327 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700328 AddSpace(space);
Ian Rogers50b35e22012-10-04 10:09:15 -0700329 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800330 ScopedObjectAccess soa(self);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800331
332 // Succeeds, fits without adjusting the max allowed footprint.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333 mirror::Object* lots_of_objects[1024];
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700334 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
Ian Rogers6fac4472014-02-25 17:01:10 -0800335 size_t allocation_size, usable_size;
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800336 size_t size_of_zero_length_byte_array = SizeOfZeroLengthByteArray();
Mathieu Chartier5647d182014-03-07 15:00:39 -0800337 lots_of_objects[i] = Alloc(space, self, size_of_zero_length_byte_array, &allocation_size,
338 &usable_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800339 EXPECT_TRUE(lots_of_objects[i] != nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800340 SirtRef<mirror::Object> obj(self, lots_of_objects[i]);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800341 lots_of_objects[i] = obj.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800342 size_t computed_usable_size;
343 EXPECT_EQ(allocation_size, space->AllocationSize(lots_of_objects[i], &computed_usable_size));
344 EXPECT_EQ(usable_size, computed_usable_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800345 }
346
Mathieu Chartier4e305412014-02-19 10:54:44 -0800347 // Release memory and check pointers are nullptr.
348 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
349 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
350 EXPECT_TRUE(lots_of_objects[i] == nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800351 }
352
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 Chartier4e305412014-02-19 10:54:44 -0800365 // Release memory and check pointers are nullptr
366 // TODO: This isn't compaction safe, fix.
367 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
368 for (size_t i = 0; i < arraysize(lots_of_objects); i++) {
369 EXPECT_TRUE(lots_of_objects[i] == nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800370 }
371}
372
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800373void SpaceTest::SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
Ian Rogers3bb17a62012-01-27 23:56:44 -0800374 int round, size_t growth_limit) {
375 if (((object_size > 0 && object_size >= static_cast<intptr_t>(growth_limit))) ||
376 ((object_size < 0 && -object_size >= static_cast<intptr_t>(growth_limit)))) {
377 // No allocation can succeed
378 return;
379 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800380
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700381 // The space's footprint equals amount of resources requested from system
382 size_t footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800383
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700384 // The space must at least have its book keeping allocated
Ian Rogers3bb17a62012-01-27 23:56:44 -0800385 EXPECT_GT(footprint, 0u);
386
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700387 // But it shouldn't exceed the initial size
Ian Rogers3bb17a62012-01-27 23:56:44 -0800388 EXPECT_LE(footprint, growth_limit);
389
390 // space's size shouldn't exceed the initial size
391 EXPECT_LE(space->Size(), growth_limit);
392
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700393 // this invariant should always hold or else the space has grown to be larger than what the
Ian Rogers3bb17a62012-01-27 23:56:44 -0800394 // space believes its size is (which will break invariants)
395 EXPECT_GE(space->Size(), footprint);
396
397 // Fill the space with lots of small objects up to the growth limit
398 size_t max_objects = (growth_limit / (object_size > 0 ? object_size : 8)) + 1;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399 UniquePtr<mirror::Object*[]> lots_of_objects(new mirror::Object*[max_objects]);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800400 size_t last_object = 0; // last object for which allocation succeeded
401 size_t amount_allocated = 0; // amount of space allocated
Ian Rogers50b35e22012-10-04 10:09:15 -0700402 Thread* self = Thread::Current();
Mathieu Chartier4e305412014-02-19 10:54:44 -0800403 ScopedObjectAccess soa(self);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700404 size_t rand_seed = 123456789;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700405 for (size_t i = 0; i < max_objects; i++) {
Ian Rogers3bb17a62012-01-27 23:56:44 -0800406 size_t alloc_fails = 0; // number of failed allocations
407 size_t max_fails = 30; // number of times we fail allocation before giving up
408 for (; alloc_fails < max_fails; alloc_fails++) {
409 size_t alloc_size;
410 if (object_size > 0) {
411 alloc_size = object_size;
412 } else {
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700413 alloc_size = test_rand(&rand_seed) % static_cast<size_t>(-object_size);
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800414 // Note the minimum size, which is the size of a zero-length byte array.
415 size_t size_of_zero_length_byte_array = SizeOfZeroLengthByteArray();
416 if (alloc_size < size_of_zero_length_byte_array) {
417 alloc_size = size_of_zero_length_byte_array;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800418 }
419 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800420 SirtRef<mirror::Object> object(self, nullptr);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700421 size_t bytes_allocated = 0;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800422 if (round <= 1) {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800423 object.reset(Alloc(space, self, alloc_size, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800424 } else {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800425 object.reset(AllocWithGrowth(space, self, alloc_size, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800426 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700427 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800428 EXPECT_GE(space->Size(), footprint); // invariant
Mathieu Chartier4e305412014-02-19 10:54:44 -0800429 if (object.get() != nullptr) { // allocation succeeded
Mathieu Chartier4e305412014-02-19 10:54:44 -0800430 lots_of_objects[i] = object.get();
Ian Rogers6fac4472014-02-25 17:01:10 -0800431 size_t allocation_size = space->AllocationSize(object.get(), nullptr);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700432 EXPECT_EQ(bytes_allocated, allocation_size);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800433 if (object_size > 0) {
434 EXPECT_GE(allocation_size, static_cast<size_t>(object_size));
435 } else {
436 EXPECT_GE(allocation_size, 8u);
437 }
438 amount_allocated += allocation_size;
439 break;
440 }
441 }
442 if (alloc_fails == max_fails) {
443 last_object = i;
444 break;
445 }
446 }
447 CHECK_NE(last_object, 0u); // we should have filled the space
448 EXPECT_GT(amount_allocated, 0u);
449
450 // We shouldn't have gone past the growth_limit
451 EXPECT_LE(amount_allocated, growth_limit);
452 EXPECT_LE(footprint, growth_limit);
453 EXPECT_LE(space->Size(), growth_limit);
454
455 // footprint and size should agree with amount allocated
456 EXPECT_GE(footprint, amount_allocated);
457 EXPECT_GE(space->Size(), amount_allocated);
458
459 // Release storage in a semi-adhoc manner
460 size_t free_increment = 96;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700461 while (true) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800462 {
463 ScopedThreadStateChange tsc(self, kNative);
464 // Give the space a haircut.
465 space->Trim();
466 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800467
468 // Bounds sanity
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700469 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800470 EXPECT_LE(amount_allocated, growth_limit);
471 EXPECT_GE(footprint, amount_allocated);
472 EXPECT_LE(footprint, growth_limit);
473 EXPECT_GE(space->Size(), amount_allocated);
474 EXPECT_LE(space->Size(), growth_limit);
475
476 if (free_increment == 0) {
477 break;
478 }
479
Mathieu Chartier4e305412014-02-19 10:54:44 -0800480 // Free some objects
481 for (size_t i = 0; i < last_object; i += free_increment) {
482 mirror::Object* object = lots_of_objects.get()[i];
483 if (object == nullptr) {
484 continue;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800485 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800486 size_t allocation_size = space->AllocationSize(object, nullptr);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800487 if (object_size > 0) {
488 EXPECT_GE(allocation_size, static_cast<size_t>(object_size));
489 } else {
490 EXPECT_GE(allocation_size, 8u);
491 }
492 space->Free(self, object);
493 lots_of_objects.get()[i] = nullptr;
494 amount_allocated -= allocation_size;
495 footprint = space->GetFootprint();
496 EXPECT_GE(space->Size(), footprint); // invariant
Ian Rogers3bb17a62012-01-27 23:56:44 -0800497 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800498
499 free_increment >>= 1;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800500 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800501
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700502 // The space has become empty here before allocating a large object
503 // below. For RosAlloc, revoke thread-local runs, which are kept
504 // even when empty for a performance reason, so that they won't
505 // cause the following large object allocation to fail due to
506 // potential fragmentation. Note they are normally revoked at each
507 // GC (but no GC here.)
508 space->RevokeAllThreadLocalBuffers();
509
Ian Rogers3bb17a62012-01-27 23:56:44 -0800510 // All memory was released, try a large allocation to check freed memory is being coalesced
Mathieu Chartier4e305412014-02-19 10:54:44 -0800511 SirtRef<mirror::Object> large_object(self, nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800512 size_t three_quarters_space = (growth_limit / 2) + (growth_limit / 4);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -0700513 size_t bytes_allocated = 0;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800514 if (round <= 1) {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800515 large_object.reset(Alloc(space, self, three_quarters_space, &bytes_allocated, nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800516 } else {
Mathieu Chartier5647d182014-03-07 15:00:39 -0800517 large_object.reset(AllocWithGrowth(space, self, three_quarters_space, &bytes_allocated,
518 nullptr));
Ian Rogers3bb17a62012-01-27 23:56:44 -0800519 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800520 EXPECT_TRUE(large_object.get() != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800521
522 // Sanity check footprint
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700523 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800524 EXPECT_LE(footprint, growth_limit);
525 EXPECT_GE(space->Size(), footprint);
526 EXPECT_LE(space->Size(), growth_limit);
527
528 // Clean up
Mathieu Chartier4e305412014-02-19 10:54:44 -0800529 space->Free(self, large_object.reset(nullptr));
530
Ian Rogers3bb17a62012-01-27 23:56:44 -0800531 // Sanity check footprint
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700532 footprint = space->GetFootprint();
Ian Rogers3bb17a62012-01-27 23:56:44 -0800533 EXPECT_LE(footprint, growth_limit);
534 EXPECT_GE(space->Size(), footprint);
535 EXPECT_LE(space->Size(), growth_limit);
536}
537
Hiroshi Yamauchi3ddbd422013-12-06 17:43:36 -0800538void SpaceTest::SizeFootPrintGrowthLimitAndTrimDriver(size_t object_size, CreateSpaceFn create_space) {
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800539 if (object_size < SizeOfZeroLengthByteArray()) {
540 // Too small for the object layout/model.
541 return;
542 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800543 size_t initial_size = 4 * MB;
544 size_t growth_limit = 8 * MB;
545 size_t capacity = 16 * MB;
Mathieu Chartier4e305412014-02-19 10:54:44 -0800546 MallocSpace* space(create_space("test", initial_size, growth_limit, capacity, nullptr));
547 ASSERT_TRUE(space != nullptr);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800548
549 // Basic sanity
550 EXPECT_EQ(space->Capacity(), growth_limit);
551 EXPECT_EQ(space->NonGrowthLimitCapacity(), capacity);
552
553 // Make space findable to the heap, will also delete space when runtime is cleaned up
Mathieu Chartier590fee92013-09-13 13:46:47 -0700554 AddSpace(space);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800555
556 // In this round we don't allocate with growth and therefore can't grow past the initial size.
557 // This effectively makes the growth_limit the initial_size, so assert this.
558 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 1, initial_size);
559 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 2, growth_limit);
560 // Remove growth limit
561 space->ClearGrowthLimit();
562 EXPECT_EQ(space->Capacity(), capacity);
563 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 3, capacity);
564}
565
Andreas Gampe24651ec2014-02-27 13:26:16 -0800566#define TEST_SizeFootPrintGrowthLimitAndTrimStatic(name, spaceName, spaceFn, size) \
567 TEST_F(spaceName##StaticTest, SizeFootPrintGrowthLimitAndTrim_AllocationsOf_##name) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800568 SizeFootPrintGrowthLimitAndTrimDriver(size, spaceFn); \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800569 }
570
571#define TEST_SizeFootPrintGrowthLimitAndTrimRandom(name, spaceName, spaceFn, size) \
572 TEST_F(spaceName##RandomTest, SizeFootPrintGrowthLimitAndTrim_RandomAllocationsWithMax_##name) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800573 SizeFootPrintGrowthLimitAndTrimDriver(-size, spaceFn); \
Ian Rogers3bb17a62012-01-27 23:56:44 -0800574 }
575
Andreas Gampe24651ec2014-02-27 13:26:16 -0800576#define TEST_SPACE_CREATE_FN_BASE(spaceName, spaceFn) \
577 class spaceName##BaseTest : public SpaceTest { \
Andreas Gampea7433512014-02-21 13:19:23 -0800578 }; \
579 \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800580 TEST_F(spaceName##BaseTest, Init) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800581 InitTestBody(spaceFn); \
582 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800583 TEST_F(spaceName##BaseTest, ZygoteSpace) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800584 ZygoteSpaceTestBody(spaceFn); \
585 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800586 TEST_F(spaceName##BaseTest, AllocAndFree) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800587 AllocAndFreeTestBody(spaceFn); \
588 } \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800589 TEST_F(spaceName##BaseTest, AllocAndFreeList) { \
Andreas Gampea7433512014-02-21 13:19:23 -0800590 AllocAndFreeListTestBody(spaceFn); \
Andreas Gampe24651ec2014-02-27 13:26:16 -0800591 }
592
593#define TEST_SPACE_CREATE_FN_STATIC(spaceName, spaceFn) \
594 class spaceName##StaticTest : public SpaceTest { \
595 }; \
596 \
597 TEST_SizeFootPrintGrowthLimitAndTrimStatic(12B, spaceName, spaceFn, 12) \
598 TEST_SizeFootPrintGrowthLimitAndTrimStatic(16B, spaceName, spaceFn, 16) \
599 TEST_SizeFootPrintGrowthLimitAndTrimStatic(24B, spaceName, spaceFn, 24) \
600 TEST_SizeFootPrintGrowthLimitAndTrimStatic(32B, spaceName, spaceFn, 32) \
601 TEST_SizeFootPrintGrowthLimitAndTrimStatic(64B, spaceName, spaceFn, 64) \
602 TEST_SizeFootPrintGrowthLimitAndTrimStatic(128B, spaceName, spaceFn, 128) \
603 TEST_SizeFootPrintGrowthLimitAndTrimStatic(1KB, spaceName, spaceFn, 1 * KB) \
604 TEST_SizeFootPrintGrowthLimitAndTrimStatic(4KB, spaceName, spaceFn, 4 * KB) \
605 TEST_SizeFootPrintGrowthLimitAndTrimStatic(1MB, spaceName, spaceFn, 1 * MB) \
606 TEST_SizeFootPrintGrowthLimitAndTrimStatic(4MB, spaceName, spaceFn, 4 * MB) \
607 TEST_SizeFootPrintGrowthLimitAndTrimStatic(8MB, spaceName, spaceFn, 8 * MB)
608
609#define TEST_SPACE_CREATE_FN_RANDOM(spaceName, spaceFn) \
610 class spaceName##RandomTest : public SpaceTest { \
611 }; \
612 \
613 TEST_SizeFootPrintGrowthLimitAndTrimRandom(16B, spaceName, spaceFn, 16) \
614 TEST_SizeFootPrintGrowthLimitAndTrimRandom(24B, spaceName, spaceFn, 24) \
615 TEST_SizeFootPrintGrowthLimitAndTrimRandom(32B, spaceName, spaceFn, 32) \
616 TEST_SizeFootPrintGrowthLimitAndTrimRandom(64B, spaceName, spaceFn, 64) \
617 TEST_SizeFootPrintGrowthLimitAndTrimRandom(128B, spaceName, spaceFn, 128) \
618 TEST_SizeFootPrintGrowthLimitAndTrimRandom(1KB, spaceName, spaceFn, 1 * KB) \
619 TEST_SizeFootPrintGrowthLimitAndTrimRandom(4KB, spaceName, spaceFn, 4 * KB) \
620 TEST_SizeFootPrintGrowthLimitAndTrimRandom(1MB, spaceName, spaceFn, 1 * MB) \
621 TEST_SizeFootPrintGrowthLimitAndTrimRandom(4MB, spaceName, spaceFn, 4 * MB) \
622 TEST_SizeFootPrintGrowthLimitAndTrimRandom(8MB, spaceName, spaceFn, 8 * MB)
Ian Rogers3bb17a62012-01-27 23:56:44 -0800623
Ian Rogers1d54e732013-05-02 21:10:01 -0700624} // namespace space
625} // namespace gc
Carl Shapiro69759ea2011-07-21 18:13:35 -0700626} // namespace art
Andreas Gampea7433512014-02-21 13:19:23 -0800627
628#endif // ART_RUNTIME_GC_SPACE_SPACE_TEST_H_