MCPcopy Create free account
hub / github.com/bytedance/bolt / run

Method run

bolt/common/memory/tests/MemoryPoolTest.cpp:2189–2277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2187 const int32_t op = folly::Random().rand32() % 4;
2188 switch (op) {
2189 case 0: {
2190 // Allocate buffers.
2191 if ((folly::Random().rand32() % 2) && !allocBuffers_.empty()) {
2192 pool_.free(allocBuffers_.back().first, allocBuffers_.back().second);
2193 allocBuffers_.pop_back();
2194 } else {
2195 const int64_t allocateBytes =
2196 folly::Random().rand32() % (maxMemory_ / 64);
2197 try {
2198 void* buffer = pool_.allocate(allocateBytes);
2199 BOLT_CHECK_NOT_NULL(buffer);
2200 allocBuffers_.push_back({buffer, allocateBytes});
2201 } catch (BoltException& e) {
2202 // Ignore memory limit exception.
2203 ASSERT_TRUE(e.message().find("Negative") == std::string::npos);
2204 return;
2205 }
2206 }
2207 break;
2208 }
2209 case 2: {
2210 // Contiguous allocations.
2211 if ((folly::Random().rand32() % 2) && !contiguousAllocations_.empty()) {
2212 pool_.freeContiguous(contiguousAllocations_.back());
2213 contiguousAllocations_.pop_back();
2214 } else {
2215 int64_t allocatePages = std::max<int64_t>(
2216 1,
2217 folly::Random().rand32() % Allocation::PageRun::kMaxPagesInRun);
2218 ContiguousAllocation allocation;
2219 if (folly::Random().oneIn(2) && !contiguousAllocations_.empty()) {
2220 allocation = std::move(contiguousAllocations_.back());
2221 contiguousAllocations_.pop_back();
2222 if (folly::Random().oneIn(2)) {
2223 allocatePages = std::max<int64_t>(1, allocation.numPages() - 4);
2224 }
2225 }
2226 try {
2227 pool_.allocateContiguous(allocatePages, allocation);
2228 contiguousAllocations_.push_back(std::move(allocation));
2229 } catch (BoltException& e) {
2230 // Ignore memory limit exception.
2231 ASSERT_TRUE(e.message().find("Negative") == std::string::npos);
2232 return;
2233 }
2234 }
2235 break;
2236 }
2237 case 1: {
2238 // Non-contiguous allocations.
2239 if ((folly::Random().rand32() % 2) &&
2240 !nonContiguiusAllocations_.empty()) {
2241 pool_.freeNonContiguous(nonContiguiusAllocations_.back());
2242 nonContiguiusAllocations_.pop_back();
2243 } else {
2244 const int64_t allocatePages = std::max<int64_t>(
2245 1,
2246 folly::Random().rand32() % Allocation::PageRun::kMaxPagesInRun);

Callers 1

TEST_PFunction · 0.45

Calls 15

backMethod · 0.80
pop_backMethod · 0.80
messageMethod · 0.80
rand32Method · 0.45
emptyMethod · 0.45
freeMethod · 0.45
allocateMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45
freeContiguousMethod · 0.45
oneInMethod · 0.45
numPagesMethod · 0.45

Tested by

no test coverage detected