Lines Matching refs:space

34 namespace space {
43 void AddSpace(ContinuousSpace* space, bool revoke = true) {
48 heap->AddSpace(space);
49 heap->SetSpaceAsDefault(space);
65 mirror::Object* Alloc(space::MallocSpace* alloc_space, Thread* self, size_t bytes,
79 mirror::Object* AllocWithGrowth(space::MallocSpace* alloc_space, Thread* self, size_t bytes,
125 void SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
141 std::unique_ptr<Space> space(create_space("test", 16 * MB, 32 * MB, 32 * MB, nullptr));
142 EXPECT_TRUE(space.get() != nullptr);
146 std::unique_ptr<Space> space(create_space("test", 16 * MB, 16 * MB, 16 * MB, nullptr));
147 EXPECT_TRUE(space.get() != nullptr);
151 std::unique_ptr<Space> space(create_space("test", 32 * MB, 16 * MB, 16 * MB, nullptr));
152 EXPECT_TRUE(space.get() == nullptr);
156 std::unique_ptr<Space> space(create_space("test", 16 * MB, 16 * MB, 32 * MB, nullptr));
157 EXPECT_TRUE(space.get() != nullptr);
161 std::unique_ptr<Space> space(create_space("test", 16 * MB, 8 * MB, 32 * MB, nullptr));
162 EXPECT_TRUE(space.get() == nullptr);
166 std::unique_ptr<Space> space(create_space("test", 8 * MB, 16 * MB, 32 * MB, nullptr));
167 EXPECT_TRUE(space.get() != nullptr);
171 std::unique_ptr<Space> space(create_space("test", 8 * MB, 32 * MB, 16 * MB, nullptr));
172 EXPECT_TRUE(space.get() == nullptr);
182 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
183 ASSERT_TRUE(space != nullptr);
185 // Make space findable to the heap, will also delete space when runtime is cleaned up
186 AddSpace(space);
194 hs.NewHandle(Alloc(space, self, 1 * MB, &ptr1_bytes_allocated, &ptr1_usable_size,
203 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr, &dummy);
209 hs.NewHandle(AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated, &ptr3_usable_size,
218 mirror::Object* ptr4 = space->Alloc(self, 8 * MB, &dummy, nullptr, &dummy);
222 mirror::Object* ptr5 = space->AllocWithGrowth(self, 8 * MB, &dummy, nullptr, &dummy);
226 size_t free3 = space->AllocationSize(ptr3.Get(), nullptr);
228 EXPECT_EQ(free3, space->Free(self, ptr3.Assign(nullptr)));
234 hs.NewHandle(AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated, &ptr6_usable_size,
243 size_t free1 = space->AllocationSize(ptr1.Get(), nullptr);
244 space->Free(self, ptr1.Assign(nullptr));
247 // Make sure that the zygote space isn't directly at the start of the space.
248 EXPECT_TRUE(space->Alloc(self, 1U * MB, &dummy, nullptr, &dummy) != nullptr);
251 space::Space* old_space = space;
254 space::ZygoteSpace* zygote_space = space->CreateZygoteSpace("alloc space",
256 &space);
258 // Add the zygote space.
261 // Make space findable to the heap, will also delete space when runtime is cleaned up
262 AddSpace(space, false);
265 ptr1.Assign(Alloc(space, self, 1 * MB, &ptr1_bytes_allocated, &ptr1_usable_size,
274 ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr, &dummy);
278 ptr3.Assign(AllocWithGrowth(space, self, 2 * MB, &ptr3_bytes_allocated, &ptr3_usable_size,
285 space->Free(self, ptr3.Assign(nullptr));
288 free1 = space->AllocationSize(ptr1.Get(), nullptr);
289 space->Free(self, ptr1.Assign(nullptr));
295 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
296 ASSERT_TRUE(space != nullptr);
300 // Make space findable to the heap, will also delete space when runtime is cleaned up
301 AddSpace(space);
307 hs.NewHandle(Alloc(space, self, 1 * MB, &ptr1_bytes_allocated, &ptr1_usable_size,
316 mirror::Object* ptr2 = Alloc(space, self, 8 * MB, &dummy, nullptr, &dummy);
322 hs.NewHandle(AllocWithGrowth(space, self, 8 * MB, &ptr3_bytes_allocated, &ptr3_usable_size,
331 mirror::Object* ptr4 = Alloc(space, self, 8 * MB, &dummy, nullptr, &dummy);
335 mirror::Object* ptr5 = AllocWithGrowth(space, self, 8 * MB, &dummy, nullptr, &dummy);
339 size_t free3 = space->AllocationSize(ptr3.Get(), nullptr);
341 space->Free(self, ptr3.Assign(nullptr));
347 hs.NewHandle(AllocWithGrowth(space, self, 9 * MB, &ptr6_bytes_allocated, &ptr6_usable_size,
356 size_t free1 = space->AllocationSize(ptr1.Get(), nullptr);
357 space->Free(self, ptr1.Assign(nullptr));
362 MallocSpace* space(create_space("test", 4 * MB, 16 * MB, 16 * MB, nullptr));
363 ASSERT_TRUE(space != nullptr);
365 // Make space findable to the heap, will also delete space when runtime is cleaned up
366 AddSpace(space);
375 lots_of_objects[i] = Alloc(space, self, size_of_zero_length_byte_array, &allocation_size,
379 EXPECT_EQ(allocation_size, space->AllocationSize(lots_of_objects[i], &computed_usable_size));
386 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
391 lots_of_objects[i] = AllocWithGrowth(space, self, 1024, &allocation_size, &usable_size,
395 EXPECT_EQ(allocation_size, space->AllocationSize(lots_of_objects[i], &computed_usable_size));
402 space->FreeList(self, arraysize(lots_of_objects), lots_of_objects);
405 void SpaceTest::SizeFootPrintGrowthLimitAndTrimBody(MallocSpace* space, intptr_t object_size,
413 // The space's footprint equals amount of resources requested from system
414 size_t footprint = space->GetFootprint();
416 // The space must at least have its book keeping allocated
422 // space's size shouldn't exceed the initial size
423 EXPECT_LE(space->Size(), growth_limit);
425 // this invariant should always hold or else the space has grown to be larger than what the
426 // space believes its size is (which will break invariants)
427 EXPECT_GE(space->Size(), footprint);
429 // Fill the space with lots of small objects up to the growth limit
433 size_t amount_allocated = 0; // amount of space allocated
457 object.Assign(Alloc(space, self, alloc_size, &bytes_allocated, nullptr,
460 object.Assign(AllocWithGrowth(space, self, alloc_size, &bytes_allocated, nullptr,
463 footprint = space->GetFootprint();
464 EXPECT_GE(space->Size(), footprint); // invariant
467 size_t allocation_size = space->AllocationSize(object.Get(), nullptr);
485 CHECK_NE(last_object, 0u); // we should have filled the space
491 EXPECT_LE(space->Size(), growth_limit);
495 EXPECT_GE(space->Size(), amount_allocated);
502 // Give the space a haircut.
503 space->Trim();
507 footprint = space->GetFootprint();
511 EXPECT_GE(space->Size(), amount_allocated);
512 EXPECT_LE(space->Size(), growth_limit);
524 size_t allocation_size = space->AllocationSize(object, nullptr);
530 space->Free(self, object);
533 footprint = space->GetFootprint();
534 EXPECT_GE(space->Size(), footprint); // invariant
540 // The space has become empty here before allocating a large object
546 space->RevokeAllThreadLocalBuffers();
555 large_object.Assign(Alloc(space, self, three_quarters_space, &bytes_allocated, nullptr,
558 large_object.Assign(AllocWithGrowth(space, self, three_quarters_space, &bytes_allocated,
564 footprint = space->GetFootprint();
566 EXPECT_GE(space->Size(), footprint);
567 EXPECT_LE(space->Size(), growth_limit);
570 space->Free(self, large_object.Assign(nullptr));
573 footprint = space->GetFootprint();
575 EXPECT_GE(space->Size(), footprint);
576 EXPECT_LE(space->Size(), growth_limit);
587 MallocSpace* space(create_space("test", initial_size, growth_limit, capacity, nullptr));
588 ASSERT_TRUE(space != nullptr);
591 EXPECT_EQ(space->Capacity(), growth_limit);
592 EXPECT_EQ(space->NonGrowthLimitCapacity(), capacity);
594 // Make space findable to the heap, will also delete space when runtime is cleaned up
595 AddSpace(space);
599 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 1, initial_size);
600 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 2, growth_limit);
602 space->ClearGrowthLimit();
603 EXPECT_EQ(space->Capacity(), capacity);
604 SizeFootPrintGrowthLimitAndTrimBody(space, object_size, 3, capacity);
665 } // namespace space