Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testGCChunkPool.cpp
blob12b42330d402b7639f86c7e00230f6d49ebf0a74
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include <utility>
10 #include "gc/GCLock.h"
11 #include "gc/GCRuntime.h"
12 #include "jsapi-tests/tests.h"
14 BEGIN_TEST(testGCChunkPool) {
15 using namespace js::gc;
17 const int N = 10;
18 ChunkPool pool;
20 // Create.
21 for (int i = 0; i < N; ++i) {
22 void* ptr = TenuredChunk::allocate(&cx->runtime()->gc);
23 CHECK(ptr);
24 TenuredChunk* chunk = TenuredChunk::emplace(ptr, &cx->runtime()->gc, true);
25 CHECK(chunk);
26 pool.push(chunk);
28 MOZ_ASSERT(pool.verify());
30 // Iterate.
31 uint32_t i = 0;
32 for (ChunkPool::Iter iter(pool); !iter.done(); iter.next(), ++i) {
33 CHECK(iter.get());
35 CHECK(i == pool.count());
36 MOZ_ASSERT(pool.verify());
38 // Push/Pop.
39 for (int i = 0; i < N; ++i) {
40 TenuredChunk* chunkA = pool.pop();
41 TenuredChunk* chunkB = pool.pop();
42 TenuredChunk* chunkC = pool.pop();
43 pool.push(chunkA);
44 pool.push(chunkB);
45 pool.push(chunkC);
47 MOZ_ASSERT(pool.verify());
49 // Remove.
50 TenuredChunk* chunk = nullptr;
51 int offset = N / 2;
52 for (ChunkPool::Iter iter(pool); !iter.done(); iter.next(), --offset) {
53 if (offset == 0) {
54 chunk = pool.remove(iter.get());
55 break;
58 CHECK(chunk);
59 MOZ_ASSERT(!pool.contains(chunk));
60 MOZ_ASSERT(pool.verify());
61 pool.push(chunk);
63 // Destruct.
64 js::AutoLockGC lock(cx->runtime());
65 for (ChunkPool::Iter iter(pool); !iter.done();) {
66 TenuredChunk* chunk = iter.get();
67 iter.next();
68 pool.remove(chunk);
69 UnmapPages(chunk, ChunkSize);
72 return true;
74 END_TEST(testGCChunkPool)