Lines Matching refs:pool
19 static size_t ScratchBlockSize(SkSBlockAllocator<N>& pool) {
20 return (size_t) pool->scratchBlockSize();
26 static int block_count(const SkSBlockAllocator<N>& pool) {
28 for (const Block* b : pool->blocks()) {
36 static Block* get_block(SkSBlockAllocator<N>& pool, int blockIndex) {
39 for (Block* b: pool->blocks()) {
55 static size_t total_size(SkSBlockAllocator<N>& pool) {
56 return pool->totalSize() - BlockAllocatorTestAccess::ScratchBlockSize(pool);
60 static size_t add_block(SkSBlockAllocator<N>& pool) {
61 size_t currentSize = total_size(pool);
62 SkBlockAllocator::Block* current = pool->currentBlock();
63 while(pool->currentBlock() == current) {
64 pool->template allocate<4>(pool->preallocSize() / 2);
66 return total_size(pool) - currentSize;
70 static void* alloc_byte(SkSBlockAllocator<N>& pool) {
71 auto br = pool->template allocate<1>(1);
102 SkSBlockAllocator<1024> pool{};
103 SkDEBUGCODE(pool->validate();)
118 REPORTER_ASSERT(r, pool->currentBlock() == br.fBlock);
132 auto p1 = pool->allocate<1>(14);
135 auto p2 = pool->allocate<2>(24);
138 auto p4 = pool->allocate<4>(28);
141 auto p8 = pool->allocate<8>(40);
144 auto p16 = pool->allocate<16>(64);
147 auto p32 = pool->allocate<32>(96);
151 REPORTER_ASSERT(r, total_size(pool) == pool->preallocSize());
152 SkDEBUGCODE(pool->validate();)
155 size_t avail = pool->currentBlock()->avail<4>();
156 auto pAvail = pool->allocate<4>(avail);
161 REPORTER_ASSERT(r, pool->currentBlock()->avail<4>() < 4);
162 auto pNextBlock = pool->allocate<4>(4);
164 REPORTER_ASSERT(r, total_size(pool) > pool->preallocSize());
167 size_t currentSize = total_size(pool);
168 size_t bigRequest = pool->currentBlock()->avail<4>() * 2;
169 auto pTooBig = pool->allocate<4>(bigRequest);
171 REPORTER_ASSERT(r, total_size(pool) > currentSize);
174 REPORTER_ASSERT(r, total_size(pool) - currentSize < 4096);
175 currentSize = total_size(pool);
176 auto pReallyTooBig = pool->allocate<4>(4096);
178 REPORTER_ASSERT(r, total_size(pool) >= currentSize + 4096);
179 SkDEBUGCODE(pool->validate();)
183 SkSBlockAllocator<1024> pool{};
184 SkDEBUGCODE(pool->validate();)
187 SkBlockAllocator::ByteRange p = pool->allocate<4>(16);
195 auto pNext = pool->allocate<4>(16);
221 pNext = pool->allocate<4>(16);
224 SkDEBUGCODE(pool->validate();)
236 SkSBlockAllocator<1024> pool{};
237 SkDEBUGCODE(pool->validate();)
240 auto p = pool->allocate<8>(32);
241 REPORTER_ASSERT(r, pool->currentBlock()->release(p.fStart, p.fEnd));
243 auto p2 = pool->allocate<8>(32);
247 auto p3 = pool->allocate<8>(64);
253 auto p4 = pool->allocate<8>(16);
254 auto p5 = pool->allocate<8>(96);
260 p = pool->allocate<8>(32);
264 SkDEBUGCODE(pool->validate();)
270 SkSBlockAllocator<1024> pool{};
271 SkDEBUGCODE(pool->validate();)
276 ptrs.push_back(pool->allocate<4>(16));
280 SkDEBUGCODE(pool->validate();)
288 SkDEBUGCODE(pool->validate();)
289 REPORTER_ASSERT(r, pool->allocate<4>(16).fStart == ptrs[0].fStart);
307 SkSBlockAllocator<kInitSize> pool{(GrowthPolicy) gp};
308 SkDEBUGCODE(pool->validate();)
310 REPORTER_ASSERT(r, kExpectedSizes[gp][0] == total_size(pool));
312 REPORTER_ASSERT(r, kExpectedSizes[gp][i] == add_block(pool));
315 SkDEBUGCODE(pool->validate();)
322 SkSBlockAllocator<kBlockIncrement> pool{GrowthPolicy::kLinear};
323 SkDEBUGCODE(pool->validate();)
325 void* firstAlloc = alloc_byte(pool);
328 add_block(pool);
329 add_block(pool);
330 add_block(pool);
331 SkDEBUGCODE(pool->validate();)
333 REPORTER_ASSERT(r, block_count(pool) == 4); // 3 added plus the implicit head
335 get_block(pool, 0)->setMetadata(2);
339 pool->reset();
340 SkDEBUGCODE(pool->validate();)
342 REPORTER_ASSERT(r,block_count(pool) == 1);
343 REPORTER_ASSERT(r, pool->preallocSize() == pool->totalSize());
344 REPORTER_ASSERT(r, get_block(pool, 0)->metadata() == 0);
346 REPORTER_ASSERT(r, firstAlloc == alloc_byte(pool));
347 REPORTER_ASSERT(r, 2 * kBlockIncrement == add_block(pool));
348 REPORTER_ASSERT(r, 3 * kBlockIncrement == add_block(pool));
349 SkDEBUGCODE(pool->validate();)
356 SkSBlockAllocator<1024> pool{(GrowthPolicy) gp};
357 SkDEBUGCODE(pool->validate();)
359 void* firstAlloc = alloc_byte(pool);
361 size_t b1Size = total_size(pool);
362 size_t b2Size = add_block(pool);
363 size_t b3Size = add_block(pool);
364 size_t b4Size = add_block(pool);
365 SkDEBUGCODE(pool->validate();)
367 get_block(pool, 0)->setMetadata(1);
368 get_block(pool, 1)->setMetadata(2);
369 get_block(pool, 2)->setMetadata(3);
370 get_block(pool, 3)->setMetadata(4);
374 REPORTER_ASSERT(r, total_size(pool) == b1Size + b2Size + b3Size + b4Size);
375 pool->releaseBlock(get_block(pool, 1));
376 REPORTER_ASSERT(r, block_count(pool) == 3);
377 REPORTER_ASSERT(r, get_block(pool, 1)->metadata() == 3);
378 REPORTER_ASSERT(r, total_size(pool) == b1Size + b3Size + b4Size);
380 pool->releaseBlock(get_block(pool, 1));
381 REPORTER_ASSERT(r, block_count(pool) == 2);
382 REPORTER_ASSERT(r, get_block(pool, 1)->metadata() == 4);
383 REPORTER_ASSERT(r, total_size(pool) == b1Size + b4Size);
385 pool->releaseBlock(get_block(pool, 1));
386 REPORTER_ASSERT(r, block_count(pool) == 1);
387 REPORTER_ASSERT(r, total_size(pool) == b1Size);
391 pool->resetScratchSpace();
392 size_t size = add_block(pool);
394 pool->releaseBlock(get_block(pool, 1));
397 pool->releaseBlock(get_block(pool, 0));
398 REPORTER_ASSERT(r, total_size(pool) == pool->preallocSize());
399 REPORTER_ASSERT(r, block_count(pool) == 1);
400 REPORTER_ASSERT(r, firstAlloc == alloc_byte(pool));
401 REPORTER_ASSERT(r, get_block(pool, 0)->metadata() == 0); // metadata reset too
405 add_block(pool);
406 add_block(pool);
407 pool->releaseBlock(get_block(pool, 0));
408 REPORTER_ASSERT(r, block_count(pool) == 3);
409 SkDEBUGCODE(pool->validate();)
414 SkSBlockAllocator<256> pool;
416 pool->headBlock()->setMetadata(1);
417 add_block(pool);
418 add_block(pool);
419 add_block(pool);
423 for (auto* b : pool->blocks()) {
424 pool->releaseBlock(b);
428 // pool should have just the head block, but was reset
429 REPORTER_ASSERT(r, pool->headBlock()->metadata() == 0);
430 REPORTER_ASSERT(r, block_count(pool) == 1);
433 pool->headBlock()->setMetadata(1);
434 add_block(pool);
435 add_block(pool);
436 add_block(pool);
440 for (auto* b : pool->rblocks()) {
441 pool->releaseBlock(b);
445 // pool should have just the head block, but was reset
446 REPORTER_ASSERT(r, pool->headBlock()->metadata() == 0);
447 REPORTER_ASSERT(r, block_count(pool) == 1);
451 SkSBlockAllocator<256> pool;
453 size_t added = add_block(pool);
454 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) == 0);
455 size_t total = pool->totalSize();
456 pool->releaseBlock(pool->currentBlock());
459 REPORTER_ASSERT(r, pool->totalSize() == total);
460 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) == added);
463 pool->reset();
464 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) == 0);
467 size_t avail = pool->currentBlock()->avail();
469 pool->reserve(reserve);
470 REPORTER_ASSERT(r, (size_t) pool->currentBlock()->avail() == avail);
471 // And rounds up to the fixed size of this pool's growth policy
472 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) >= reserve &&
473 BlockAllocatorTestAccess::ScratchBlockSize(pool) % 256 == 0);
476 size_t preAllocTotalSize = pool->totalSize();
477 pool->allocate<1>(avail + 1);
478 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) == 0);
479 REPORTER_ASSERT(r, pool->totalSize() == preAllocTotalSize);
483 pool->reserve(pool->currentBlock()->avail());
484 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) == 0);
487 pool->reserve(pool->currentBlock()->avail(), SkBlockAllocator::kIgnoreExistingBytes_Flag);
488 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) > 0);
492 pool->resetScratchSpace();
493 pool->reserve(32, SkBlockAllocator::kIgnoreGrowthPolicy_Flag);
494 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) > 0 &&
495 BlockAllocatorTestAccess::ScratchBlockSize(pool) < 256);
499 SkBlockAllocator::Block* oldTail = pool->currentBlock();
502 pool->reserve(scratchAvail);
503 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) >= scratchAvail);
507 scratchAvail = BlockAllocatorTestAccess::ScratchBlockSize(pool);
508 pool->allocate<1>(scratchAvail + 1);
509 REPORTER_ASSERT(r, pool->currentBlock() != oldTail);
510 REPORTER_ASSERT(r, BlockAllocatorTestAccess::ScratchBlockSize(pool) == scratchAvail);
564 SkSBlockAllocator<1024> pool{};
565 SkDEBUGCODE(pool->validate();)
569 auto p1 = pool->allocate<16, sizeof(TestMeta)>(16);
570 SkDEBUGCODE(pool->validate();)
583 auto p2 = pool->allocate<alignof(TestMetaBig), sizeof(TestMetaBig)>(16);
584 SkDEBUGCODE(pool->validate();)
602 SkSBlockAllocator<256> pool{};
603 SkDEBUGCODE(pool->validate();)
605 REPORTER_ASSERT(r, pool->metadata() == 0); // initial value
607 pool->setMetadata(4);
608 REPORTER_ASSERT(r, pool->metadata() == 4);
612 pool->releaseBlock(pool->headBlock());
613 REPORTER_ASSERT(r, pool->metadata() == 4);
616 pool->reset();
617 REPORTER_ASSERT(r, pool->metadata() == 0);
621 static void run_owning_block_test(skiatest::Reporter* r, SkBlockAllocator* pool) {
622 auto br = pool->allocate<Align, Padding>(1);
627 Block* block = pool->owningBlock<Align, Padding>(userPtr, br.fStart);
630 block = pool->owningBlock<Align>(metaPtr, br.fStart);
638 static void run_owning_block_tests(skiatest::Reporter* r, SkBlockAllocator* pool) {
639 run_owning_block_test<1, Padding>(r, pool);
640 run_owning_block_test<2, Padding>(r, pool);
641 run_owning_block_test<4, Padding>(r, pool);
642 run_owning_block_test<8, Padding>(r, pool);
643 run_owning_block_test<16, Padding>(r, pool);
644 run_owning_block_test<32, Padding>(r, pool);
645 run_owning_block_test<64, Padding>(r, pool);
646 run_owning_block_test<128, Padding>(r, pool);
650 SkSBlockAllocator<1024> pool{};
651 SkDEBUGCODE(pool->validate();)
653 run_owning_block_tests<1>(r, pool.allocator());
654 run_owning_block_tests<2>(r, pool.allocator());
655 run_owning_block_tests<4>(r, pool.allocator());
656 run_owning_block_tests<8>(r, pool.allocator());
657 run_owning_block_tests<16>(r, pool.allocator());
658 run_owning_block_tests<32>(r, pool.allocator());
661 run_owning_block_tests<3>(r, pool.allocator());
662 run_owning_block_tests<9>(r, pool.allocator());
663 run_owning_block_tests<17>(r, pool.allocator());