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