mesh-rb 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/ext/mesh/extconf.rb +22 -4
- data/ext/mesh/mesh.tar.gz +0 -0
- data/lib/mesh/version.rb +1 -1
- data/mesh.gemspec +3 -2
- metadata +4 -120
- data/ext/mesh/mesh/.bazelrc +0 -20
- data/ext/mesh/mesh/.bazelversion +0 -1
- data/ext/mesh/mesh/.clang-format +0 -15
- data/ext/mesh/mesh/.dockerignore +0 -5
- data/ext/mesh/mesh/.editorconfig +0 -16
- data/ext/mesh/mesh/.gitattributes +0 -4
- data/ext/mesh/mesh/.github/workflows/main.yml +0 -144
- data/ext/mesh/mesh/.gitignore +0 -51
- data/ext/mesh/mesh/AUTHORS +0 -5
- data/ext/mesh/mesh/CMakeLists.txt +0 -270
- data/ext/mesh/mesh/CODE_OF_CONDUCT.md +0 -77
- data/ext/mesh/mesh/Dockerfile +0 -30
- data/ext/mesh/mesh/LICENSE +0 -201
- data/ext/mesh/mesh/Makefile +0 -81
- data/ext/mesh/mesh/README.md +0 -97
- data/ext/mesh/mesh/WORKSPACE +0 -50
- data/ext/mesh/mesh/bazel +0 -350
- data/ext/mesh/mesh/mesh-pldi19-powers.pdf +0 -0
- data/ext/mesh/mesh/src/BUILD +0 -222
- data/ext/mesh/mesh/src/CMakeLists.txt +0 -85
- data/ext/mesh/mesh/src/bitmap.h +0 -590
- data/ext/mesh/mesh/src/cheap_heap.h +0 -170
- data/ext/mesh/mesh/src/common.h +0 -377
- data/ext/mesh/mesh/src/copts.bzl +0 -31
- data/ext/mesh/mesh/src/d_assert.cc +0 -75
- data/ext/mesh/mesh/src/fixed_array.h +0 -124
- data/ext/mesh/mesh/src/global_heap.cc +0 -547
- data/ext/mesh/mesh/src/global_heap.h +0 -569
- data/ext/mesh/mesh/src/gnu_wrapper.cc +0 -75
- data/ext/mesh/mesh/src/internal.h +0 -356
- data/ext/mesh/mesh/src/libmesh.cc +0 -239
- data/ext/mesh/mesh/src/mac_wrapper.cc +0 -528
- data/ext/mesh/mesh/src/measure_rss.cc +0 -44
- data/ext/mesh/mesh/src/measure_rss.h +0 -20
- data/ext/mesh/mesh/src/meshable_arena.cc +0 -776
- data/ext/mesh/mesh/src/meshable_arena.h +0 -309
- data/ext/mesh/mesh/src/meshing.h +0 -60
- data/ext/mesh/mesh/src/mini_heap.h +0 -532
- data/ext/mesh/mesh/src/mmap_heap.h +0 -104
- data/ext/mesh/mesh/src/one_way_mmap_heap.h +0 -77
- data/ext/mesh/mesh/src/partitioned_heap.h +0 -111
- data/ext/mesh/mesh/src/plasma/mesh.h +0 -33
- data/ext/mesh/mesh/src/real.cc +0 -52
- data/ext/mesh/mesh/src/real.h +0 -36
- data/ext/mesh/mesh/src/rng/mwc.h +0 -296
- data/ext/mesh/mesh/src/rng/mwc64.h +0 -58
- data/ext/mesh/mesh/src/rpl_printf.c +0 -1991
- data/ext/mesh/mesh/src/runtime.cc +0 -393
- data/ext/mesh/mesh/src/runtime.h +0 -114
- data/ext/mesh/mesh/src/shuffle_vector.h +0 -287
- data/ext/mesh/mesh/src/size_classes.def +0 -251
- data/ext/mesh/mesh/src/static/if.h +0 -36
- data/ext/mesh/mesh/src/static/log.h +0 -43
- data/ext/mesh/mesh/src/testing/benchmark/local_refill.cc +0 -103
- data/ext/mesh/mesh/src/testing/big-alloc.c +0 -28
- data/ext/mesh/mesh/src/testing/fragmenter.cc +0 -128
- data/ext/mesh/mesh/src/testing/global-large-stress.cc +0 -25
- data/ext/mesh/mesh/src/testing/local-alloc.c +0 -16
- data/ext/mesh/mesh/src/testing/meshing_benchmark.cc +0 -189
- data/ext/mesh/mesh/src/testing/thread.cc +0 -35
- data/ext/mesh/mesh/src/testing/unit/alignment.cc +0 -56
- data/ext/mesh/mesh/src/testing/unit/bitmap_test.cc +0 -274
- data/ext/mesh/mesh/src/testing/unit/concurrent_mesh_test.cc +0 -185
- data/ext/mesh/mesh/src/testing/unit/mesh_test.cc +0 -143
- data/ext/mesh/mesh/src/testing/unit/rng_test.cc +0 -22
- data/ext/mesh/mesh/src/testing/unit/size_class_test.cc +0 -66
- data/ext/mesh/mesh/src/testing/unit/triple_mesh_test.cc +0 -285
- data/ext/mesh/mesh/src/testing/userfaultfd-kernel-copy.cc +0 -164
- data/ext/mesh/mesh/src/thread_local_heap.cc +0 -163
- data/ext/mesh/mesh/src/thread_local_heap.h +0 -268
- data/ext/mesh/mesh/src/wrapper.cc +0 -433
- data/ext/mesh/mesh/support/export_mesh.cmake +0 -28
- data/ext/mesh/mesh/support/gen-size-classes +0 -57
- data/ext/mesh/mesh/support/install_all_configs +0 -33
- data/ext/mesh/mesh/support/remove_export_mesh.cmake +0 -48
- data/ext/mesh/mesh/support/update-bazelisk +0 -8
- data/ext/mesh/mesh/theory/32m80.png +0 -0
- data/ext/mesh/mesh/theory/64m80ind.png +0 -0
- data/ext/mesh/mesh/theory/bound_comparison.py +0 -67
- data/ext/mesh/mesh/theory/bounds/impdeg+1 +0 -135
- data/ext/mesh/mesh/theory/choose.py +0 -43
- data/ext/mesh/mesh/theory/common.py +0 -42
- data/ext/mesh/mesh/theory/compute_exp_Y.py +0 -134
- data/ext/mesh/mesh/theory/createRandomString.py +0 -69
- data/ext/mesh/mesh/theory/deg_bound_check.py +0 -100
- data/ext/mesh/mesh/theory/degcheck.py +0 -47
- data/ext/mesh/mesh/theory/dumps/32,1,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,2,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,3,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,4,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,5,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,6,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,7,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,8,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,9,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/experiment.py +0 -303
- data/ext/mesh/mesh/theory/experiment_raw_results/.gitignore +0 -0
- data/ext/mesh/mesh/theory/greedy_experiment.py +0 -66
- data/ext/mesh/mesh/theory/greedy_experiment_copy.py +0 -46
- data/ext/mesh/mesh/theory/greedy_experiment_q.py +0 -75
- data/ext/mesh/mesh/theory/makeGraph.py +0 -64
- data/ext/mesh/mesh/theory/manyreps.png +0 -0
- data/ext/mesh/mesh/theory/manystrings.png +0 -0
- data/ext/mesh/mesh/theory/match_vs_color_experiment.py +0 -94
- data/ext/mesh/mesh/theory/maxmatch_vs_E[Y].py +0 -162
- data/ext/mesh/mesh/theory/maxmatch_vs_greedymatch.py +0 -96
- data/ext/mesh/mesh/theory/maxvdeg+1imp++32,80.png +0 -0
- data/ext/mesh/mesh/theory/mesh_util.py +0 -322
- data/ext/mesh/mesh/theory/meshers.py +0 -452
- data/ext/mesh/mesh/theory/meshingBenchmark.py +0 -96
- data/ext/mesh/mesh/theory/occupancyComparison.py +0 -133
- data/ext/mesh/mesh/theory/randmatch_vs_greedymatch.py +0 -97
- data/ext/mesh/mesh/theory/randmatch_vs_greedymatch_q.py +0 -103
- data/ext/mesh/mesh/theory/randmatch_vs_greedymatch_time.py +0 -117
- data/ext/mesh/mesh/theory/read_mesh_dump.py +0 -82
- data/ext/mesh/mesh/theory/test.py +0 -70
- data/ext/mesh/mesh/tools/bazel +0 -1
@@ -1,35 +0,0 @@
|
|
1
|
-
#include <iostream>
|
2
|
-
#include <mutex>
|
3
|
-
#include <thread>
|
4
|
-
|
5
|
-
int g_i = 0;
|
6
|
-
std::mutex g_i_mutex; // protects g_i
|
7
|
-
|
8
|
-
volatile __thread char *c;
|
9
|
-
|
10
|
-
void safe_increment() {
|
11
|
-
std::lock_guard<std::mutex> lock(g_i_mutex);
|
12
|
-
++g_i;
|
13
|
-
|
14
|
-
for (size_t i = 0; i < 100; ++i) {
|
15
|
-
c = new char[16];
|
16
|
-
delete c;
|
17
|
-
}
|
18
|
-
|
19
|
-
std::cout << std::this_thread::get_id() << ": " << g_i << '\n';
|
20
|
-
|
21
|
-
// g_i_mutex is automatically released when lock
|
22
|
-
// goes out of scope
|
23
|
-
}
|
24
|
-
|
25
|
-
int main() {
|
26
|
-
std::cout << __func__ << ": " << g_i << '\n';
|
27
|
-
|
28
|
-
std::thread t1(safe_increment);
|
29
|
-
std::thread t2(safe_increment);
|
30
|
-
|
31
|
-
t1.join();
|
32
|
-
t2.join();
|
33
|
-
|
34
|
-
std::cout << __func__ << ": " << g_i << '\n';
|
35
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
|
2
|
-
// Copyright 2017 University of Massachusetts, Amherst
|
3
|
-
|
4
|
-
#include <stdalign.h>
|
5
|
-
#include <cstdint>
|
6
|
-
#include <cstdlib>
|
7
|
-
|
8
|
-
#include "gtest/gtest.h"
|
9
|
-
|
10
|
-
#include "common.h"
|
11
|
-
#include "internal.h"
|
12
|
-
#include "thread_local_heap.h"
|
13
|
-
|
14
|
-
using namespace mesh;
|
15
|
-
|
16
|
-
TEST(Alignment, NaturalAlignment) {
|
17
|
-
auto heap = ThreadLocalHeap::GetHeap();
|
18
|
-
|
19
|
-
void **ptrs = reinterpret_cast<void **>(calloc(256, sizeof(void *)));
|
20
|
-
for (size_t size = 0; size < 4096; size += 4) {
|
21
|
-
for (size_t alignment = 2; alignment <= 4096; alignment *= 2) {
|
22
|
-
// debug("size: %zu align: %zu\n", size, alignment);
|
23
|
-
bool logged = false;
|
24
|
-
for (size_t i = 0; i <= 256; i++) {
|
25
|
-
void *ptr = heap->memalign(alignment, size);
|
26
|
-
if (!logged) {
|
27
|
-
size_t actual = heap->getSize(ptr);
|
28
|
-
// debug("%10zu %10zu %10zu %10p\n", size, actual, alignment, ptr);
|
29
|
-
logged = true;
|
30
|
-
}
|
31
|
-
const auto ptrval = reinterpret_cast<uintptr_t>(ptr);
|
32
|
-
ASSERT_EQ(ptrval % alignment, 0UL);
|
33
|
-
ptrs[i] = ptr;
|
34
|
-
}
|
35
|
-
for (size_t i = 0; i <= 256; i++) {
|
36
|
-
heap->free(ptrs[i]);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
heap->releaseAll();
|
41
|
-
mesh::runtime().heap().flushAllBins();
|
42
|
-
memset(ptrs, 0, 256 * sizeof(void *));
|
43
|
-
free(ptrs);
|
44
|
-
}
|
45
|
-
|
46
|
-
TEST(Alignment, NonOverlapping) {
|
47
|
-
auto heap = ThreadLocalHeap::GetHeap();
|
48
|
-
|
49
|
-
const uintptr_t a = reinterpret_cast<uintptr_t>(heap->malloc(-8));
|
50
|
-
const uintptr_t b = reinterpret_cast<uintptr_t>(heap->malloc(-8));
|
51
|
-
|
52
|
-
// we should return nullptr for crazy allocations like this.
|
53
|
-
// Fixes #62
|
54
|
-
ASSERT_EQ(a, NULL);
|
55
|
-
ASSERT_EQ(b, NULL);
|
56
|
-
}
|
@@ -1,274 +0,0 @@
|
|
1
|
-
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
|
2
|
-
// Copyright 2017 University of Massachusetts, Amherst
|
3
|
-
|
4
|
-
#include <cstdint>
|
5
|
-
#include <cstdlib>
|
6
|
-
#include <unordered_map>
|
7
|
-
|
8
|
-
#include "gtest/gtest.h"
|
9
|
-
|
10
|
-
#include "bitmap.h"
|
11
|
-
|
12
|
-
#include "heaplayers.h"
|
13
|
-
|
14
|
-
TEST(BitmapTest, RepresentationSize) {
|
15
|
-
ASSERT_EQ(0UL, mesh::bitmap::representationSize(0));
|
16
|
-
ASSERT_EQ(8UL, mesh::bitmap::representationSize(1));
|
17
|
-
ASSERT_EQ(8UL, mesh::bitmap::representationSize(64));
|
18
|
-
ASSERT_EQ(32UL, mesh::bitmap::representationSize(256));
|
19
|
-
ASSERT_EQ(4UL, mesh::bitmap::representationSize(256) / sizeof(size_t));
|
20
|
-
}
|
21
|
-
|
22
|
-
TEST(BitmapTest, LowestSetBitAt) {
|
23
|
-
mesh::internal::RelaxedBitmap bits{128};
|
24
|
-
|
25
|
-
bits.tryToSet(6);
|
26
|
-
ASSERT_EQ(6UL, bits.lowestSetBitAt(0));
|
27
|
-
ASSERT_EQ(6UL, bits.lowestSetBitAt(5));
|
28
|
-
ASSERT_EQ(6UL, bits.lowestSetBitAt(6));
|
29
|
-
ASSERT_EQ(128UL, bits.lowestSetBitAt(7));
|
30
|
-
bits.tryToSet(123);
|
31
|
-
ASSERT_EQ(123UL, bits.lowestSetBitAt(7));
|
32
|
-
}
|
33
|
-
|
34
|
-
TEST(BitmapTest, HighestSetBitAt) {
|
35
|
-
mesh::internal::RelaxedBitmap bits{128};
|
36
|
-
|
37
|
-
bits.tryToSet(6);
|
38
|
-
ASSERT_EQ(0UL, bits.highestSetBitBeforeOrAt(0));
|
39
|
-
ASSERT_EQ(0UL, bits.highestSetBitBeforeOrAt(5));
|
40
|
-
ASSERT_EQ(6UL, bits.highestSetBitBeforeOrAt(6));
|
41
|
-
ASSERT_EQ(6UL, bits.highestSetBitBeforeOrAt(7));
|
42
|
-
ASSERT_EQ(6UL, bits.highestSetBitBeforeOrAt(127));
|
43
|
-
bits.tryToSet(123);
|
44
|
-
ASSERT_EQ(123UL, bits.highestSetBitBeforeOrAt(127));
|
45
|
-
}
|
46
|
-
|
47
|
-
TEST(BitmapTest, SetAndExchangeAll) {
|
48
|
-
const auto maxCount = 128;
|
49
|
-
|
50
|
-
mesh::internal::Bitmap bitmap{maxCount};
|
51
|
-
bitmap.tryToSet(3);
|
52
|
-
bitmap.tryToSet(4);
|
53
|
-
bitmap.tryToSet(127);
|
54
|
-
|
55
|
-
mesh::internal::RelaxedFixedBitmap newBitmap{maxCount};
|
56
|
-
newBitmap.setAll(maxCount);
|
57
|
-
|
58
|
-
mesh::internal::RelaxedFixedBitmap localBits{maxCount};
|
59
|
-
bitmap.setAndExchangeAll(localBits.mut_bits(), newBitmap.bits());
|
60
|
-
localBits.invert();
|
61
|
-
|
62
|
-
for (auto const &i : localBits) {
|
63
|
-
if (i >= maxCount) {
|
64
|
-
break;
|
65
|
-
}
|
66
|
-
ASSERT_TRUE(bitmap.isSet(i));
|
67
|
-
ASSERT_TRUE(newBitmap.isSet(i));
|
68
|
-
switch (i) {
|
69
|
-
case 3:
|
70
|
-
case 4:
|
71
|
-
case 127:
|
72
|
-
ASSERT_FALSE(localBits.isSet(i));
|
73
|
-
break;
|
74
|
-
default:
|
75
|
-
ASSERT_TRUE(localBits.isSet(i));
|
76
|
-
break;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
TEST(BitmapTest, SetAll) {
|
82
|
-
const auto maxCount = 88;
|
83
|
-
|
84
|
-
uint64_t bits1[4] = {0, 0, 0, 0};
|
85
|
-
mesh::internal::RelaxedBitmap bitmap1{maxCount, reinterpret_cast<char *>(bits1), false};
|
86
|
-
for (size_t i = 0; i < maxCount; i++) {
|
87
|
-
bitmap1.tryToSet(i);
|
88
|
-
}
|
89
|
-
|
90
|
-
uint64_t bits2[4] = {0, 0, 0, 0};
|
91
|
-
mesh::internal::RelaxedBitmap bitmap2{maxCount, reinterpret_cast<char *>(bits2), false};
|
92
|
-
bitmap2.setAll(maxCount);
|
93
|
-
|
94
|
-
for (size_t i = 0; i < maxCount; i++) {
|
95
|
-
ASSERT_TRUE(bitmap1.isSet(i));
|
96
|
-
ASSERT_TRUE(bitmap2.isSet(i));
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
TEST(BitmapTest, SetGet) {
|
101
|
-
const int NTRIALS = 1000;
|
102
|
-
|
103
|
-
for (int n = 2; n <= mesh::internal::Bitmap::MaxBitCount; n *= 2) {
|
104
|
-
mesh::internal::Bitmap b{static_cast<size_t>(n)};
|
105
|
-
int *rnd = reinterpret_cast<int *>(calloc(n, sizeof(int)));
|
106
|
-
|
107
|
-
for (int k = 0; k < NTRIALS; k++) {
|
108
|
-
// Generate a random stream of bits.
|
109
|
-
ASSERT_NE(rnd, nullptr);
|
110
|
-
|
111
|
-
for (int i = 0; i < n; i++) {
|
112
|
-
rnd[i] = lrand48() % 2;
|
113
|
-
}
|
114
|
-
|
115
|
-
for (int i = 0; i < n; i++) {
|
116
|
-
if (rnd[i] == 0) {
|
117
|
-
bool r = b.tryToSet(i);
|
118
|
-
ASSERT_TRUE(r);
|
119
|
-
} else {
|
120
|
-
ASSERT_FALSE(b.isSet(i));
|
121
|
-
b.unset(i);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
for (int i = 0; i < n; i++) {
|
125
|
-
if (rnd[i] == 0) {
|
126
|
-
ASSERT_TRUE(b.isSet(i));
|
127
|
-
b.unset(i);
|
128
|
-
} else {
|
129
|
-
ASSERT_FALSE(b.isSet(i));
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
free(rnd);
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
TEST(BitmapTest, SetGetRelaxed) {
|
138
|
-
const int NTRIALS = 1000;
|
139
|
-
|
140
|
-
for (int n = 10; n < 10000; n *= 2) {
|
141
|
-
mesh::internal::RelaxedBitmap b{static_cast<size_t>(n)};
|
142
|
-
int *rnd = reinterpret_cast<int *>(calloc(n, sizeof(int)));
|
143
|
-
|
144
|
-
for (int k = 0; k < NTRIALS; k++) {
|
145
|
-
// Generate a random stream of bits.
|
146
|
-
ASSERT_NE(rnd, nullptr);
|
147
|
-
|
148
|
-
for (int i = 0; i < n; i++) {
|
149
|
-
rnd[i] = lrand48() % 2;
|
150
|
-
}
|
151
|
-
|
152
|
-
for (int i = 0; i < n; i++) {
|
153
|
-
if (rnd[i] == 0) {
|
154
|
-
bool r = b.tryToSet(i);
|
155
|
-
ASSERT_TRUE(r);
|
156
|
-
} else {
|
157
|
-
ASSERT_FALSE(b.isSet(i));
|
158
|
-
b.unset(i);
|
159
|
-
}
|
160
|
-
}
|
161
|
-
for (int i = 0; i < n; i++) {
|
162
|
-
if (rnd[i] == 0) {
|
163
|
-
ASSERT_TRUE(b.isSet(i));
|
164
|
-
b.unset(i);
|
165
|
-
} else {
|
166
|
-
ASSERT_FALSE(b.isSet(i));
|
167
|
-
}
|
168
|
-
}
|
169
|
-
}
|
170
|
-
free(rnd);
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
TEST(BitmapTest, Builtins) {
|
175
|
-
mesh::internal::Bitmap b{256};
|
176
|
-
|
177
|
-
uint64_t i = b.setFirstEmpty();
|
178
|
-
ASSERT_EQ(i, 0ULL);
|
179
|
-
|
180
|
-
b.unset(i);
|
181
|
-
|
182
|
-
static constexpr uint64_t curr = 66;
|
183
|
-
for (size_t i = 0; i < curr; i++) {
|
184
|
-
b.tryToSet(i);
|
185
|
-
}
|
186
|
-
|
187
|
-
i = b.setFirstEmpty();
|
188
|
-
ASSERT_EQ(i, curr);
|
189
|
-
|
190
|
-
for (size_t i = 0; i < curr; i++) {
|
191
|
-
b.unset(i);
|
192
|
-
}
|
193
|
-
|
194
|
-
i = b.setFirstEmpty();
|
195
|
-
ASSERT_EQ(i, 0ULL);
|
196
|
-
|
197
|
-
i = b.setFirstEmpty(4);
|
198
|
-
ASSERT_EQ(i, 4ULL);
|
199
|
-
|
200
|
-
i = b.setFirstEmpty(111);
|
201
|
-
ASSERT_EQ(i, 111ULL);
|
202
|
-
}
|
203
|
-
|
204
|
-
TEST(BitmapTest, Iter) {
|
205
|
-
mesh::internal::RelaxedBitmap b{512};
|
206
|
-
|
207
|
-
b.tryToSet(0);
|
208
|
-
b.tryToSet(200);
|
209
|
-
b.tryToSet(500);
|
210
|
-
|
211
|
-
std::unordered_map<size_t, bool> bits;
|
212
|
-
|
213
|
-
ASSERT_EQ(bits.size(), 0ULL);
|
214
|
-
|
215
|
-
size_t n = 0;
|
216
|
-
for (auto const &off : b) {
|
217
|
-
bits[off] = true;
|
218
|
-
n++;
|
219
|
-
}
|
220
|
-
|
221
|
-
ASSERT_EQ(n, 3ULL);
|
222
|
-
ASSERT_EQ(bits.size(), 3ULL);
|
223
|
-
|
224
|
-
ASSERT_EQ(bits[0], true);
|
225
|
-
ASSERT_EQ(bits[200], true);
|
226
|
-
ASSERT_EQ(bits[500], true);
|
227
|
-
|
228
|
-
ASSERT_EQ(bits[1], false);
|
229
|
-
}
|
230
|
-
|
231
|
-
TEST(BitmapTest, Iter2) {
|
232
|
-
mesh::internal::RelaxedBitmap b{512};
|
233
|
-
|
234
|
-
b.tryToSet(200);
|
235
|
-
b.tryToSet(500);
|
236
|
-
|
237
|
-
std::unordered_map<size_t, bool> bits;
|
238
|
-
|
239
|
-
ASSERT_EQ(bits.size(), 0ULL);
|
240
|
-
|
241
|
-
size_t n = 0;
|
242
|
-
for (auto const &off : b) {
|
243
|
-
bits[off] = true;
|
244
|
-
n++;
|
245
|
-
}
|
246
|
-
|
247
|
-
ASSERT_EQ(n, 2ULL);
|
248
|
-
ASSERT_EQ(bits.size(), 2ULL);
|
249
|
-
|
250
|
-
ASSERT_EQ(bits[200], true);
|
251
|
-
ASSERT_EQ(bits[500], true);
|
252
|
-
|
253
|
-
ASSERT_EQ(bits.find(0), bits.end());
|
254
|
-
}
|
255
|
-
|
256
|
-
TEST(BitmapTest, SetHalf) {
|
257
|
-
for (size_t i = 2; i <= 2048; i *= 2) {
|
258
|
-
const auto nBits = i;
|
259
|
-
|
260
|
-
mesh::internal::RelaxedBitmap bitmap{nBits};
|
261
|
-
|
262
|
-
ASSERT_TRUE(bitmap.byteCount() >= nBits / 8);
|
263
|
-
|
264
|
-
for (size_t i = 0; i < nBits / 2; i++) {
|
265
|
-
bitmap.tryToSet(i);
|
266
|
-
ASSERT_TRUE(bitmap.isSet(i));
|
267
|
-
ASSERT_TRUE(bitmap.inUseCount() == i + 1);
|
268
|
-
}
|
269
|
-
|
270
|
-
ASSERT_TRUE(bitmap.isSet(0));
|
271
|
-
|
272
|
-
ASSERT_TRUE(bitmap.inUseCount() == nBits / 2);
|
273
|
-
}
|
274
|
-
}
|
@@ -1,185 +0,0 @@
|
|
1
|
-
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
|
2
|
-
// Copyright 2017 University of Massachusetts, Amherst
|
3
|
-
|
4
|
-
#include <sched.h>
|
5
|
-
#include <stdint.h>
|
6
|
-
#include <stdlib.h>
|
7
|
-
|
8
|
-
#include <atomic>
|
9
|
-
#include <mutex>
|
10
|
-
#include <thread>
|
11
|
-
|
12
|
-
#include "gtest/gtest.h"
|
13
|
-
|
14
|
-
#include "internal.h"
|
15
|
-
#include "meshing.h"
|
16
|
-
#include "runtime.h"
|
17
|
-
#include "shuffle_vector.h"
|
18
|
-
|
19
|
-
using namespace std;
|
20
|
-
using namespace mesh;
|
21
|
-
|
22
|
-
static constexpr uint32_t StrLen = 128;
|
23
|
-
static constexpr uint32_t ObjCount = 32;
|
24
|
-
|
25
|
-
static char *s1;
|
26
|
-
static char *s2;
|
27
|
-
|
28
|
-
static atomic<int> ShouldExit;
|
29
|
-
static atomic<int> ShouldContinueTest;
|
30
|
-
|
31
|
-
// we need to wrap pthread_create so that we can safely implement a
|
32
|
-
// stop-the-world quiescent period for the copy/mremap phase of
|
33
|
-
// meshing -- copied from libmesh.cc
|
34
|
-
|
35
|
-
#ifdef __APPLE__
|
36
|
-
#define PTHREAD_CREATE_THROW
|
37
|
-
#else
|
38
|
-
#define PTHREAD_CREATE_THROW throw()
|
39
|
-
#endif
|
40
|
-
|
41
|
-
extern "C" int pthread_create(pthread_t *thread, const pthread_attr_t *attr, mesh::PthreadFn startRoutine,
|
42
|
-
void *arg) PTHREAD_CREATE_THROW {
|
43
|
-
return mesh::runtime().createThread(thread, attr, startRoutine, arg);
|
44
|
-
}
|
45
|
-
|
46
|
-
static void writerThread() {
|
47
|
-
ShouldContinueTest = 1;
|
48
|
-
|
49
|
-
for (size_t i = 1; i < numeric_limits<uint64_t>::max(); i++) {
|
50
|
-
if (i % 1000000 == 0 && ShouldExit)
|
51
|
-
return;
|
52
|
-
|
53
|
-
s1[0] = 'A';
|
54
|
-
s2[0] = 'Z';
|
55
|
-
}
|
56
|
-
|
57
|
-
debug("loop ended before ShouldExit\n");
|
58
|
-
}
|
59
|
-
|
60
|
-
// shows up in strace logs, but otherwise does nothing
|
61
|
-
static inline void note(const char *note) {
|
62
|
-
int _ __attribute__((unused)) = write(-1, note, strlen(note));
|
63
|
-
}
|
64
|
-
|
65
|
-
static void meshTestConcurrentWrite(bool invert) {
|
66
|
-
if (!kMeshingEnabled) {
|
67
|
-
GTEST_SKIP();
|
68
|
-
}
|
69
|
-
|
70
|
-
const auto tid = gettid();
|
71
|
-
GlobalHeap &gheap = runtime().heap();
|
72
|
-
|
73
|
-
// disable automatic meshing for this test
|
74
|
-
gheap.setMeshPeriodMs(kZeroMs);
|
75
|
-
|
76
|
-
ASSERT_EQ(gheap.getAllocatedMiniheapCount(), 0UL);
|
77
|
-
|
78
|
-
FixedArray<MiniHeap, 1> array{};
|
79
|
-
|
80
|
-
// allocate three miniheaps for the same object size from our global heap
|
81
|
-
gheap.allocSmallMiniheaps(SizeMap::SizeClass(StrLen), StrLen, array, tid);
|
82
|
-
MiniHeap *mh1 = array[0];
|
83
|
-
array.clear();
|
84
|
-
|
85
|
-
gheap.allocSmallMiniheaps(SizeMap::SizeClass(StrLen), StrLen, array, tid);
|
86
|
-
MiniHeap *mh2 = array[0];
|
87
|
-
array.clear();
|
88
|
-
|
89
|
-
ASSERT_EQ(gheap.getAllocatedMiniheapCount(), 2UL);
|
90
|
-
|
91
|
-
// sanity checks
|
92
|
-
ASSERT_TRUE(mh1 != mh2);
|
93
|
-
ASSERT_EQ(mh1->maxCount(), mh2->maxCount());
|
94
|
-
ASSERT_EQ(mh1->maxCount(), ObjCount);
|
95
|
-
|
96
|
-
// allocate two c strings, one from each miniheap at different offsets
|
97
|
-
s1 = reinterpret_cast<char *>(mh1->mallocAt(gheap.arenaBegin(), 0));
|
98
|
-
s2 = reinterpret_cast<char *>(mh2->mallocAt(gheap.arenaBegin(), ObjCount - 1));
|
99
|
-
|
100
|
-
ASSERT_TRUE(s1 != nullptr);
|
101
|
-
ASSERT_TRUE(s2 != nullptr);
|
102
|
-
|
103
|
-
// fill in the strings, set the trailing null byte
|
104
|
-
memset(s1, 'A', StrLen);
|
105
|
-
memset(s2, 'Z', StrLen);
|
106
|
-
s1[StrLen - 1] = 0;
|
107
|
-
s2[StrLen - 1] = 0;
|
108
|
-
|
109
|
-
// copy these strings so we can check the contents after meshing
|
110
|
-
char *v1 = strdup(s1);
|
111
|
-
char *v2 = strdup(s2);
|
112
|
-
ASSERT_STREQ(s1, v1);
|
113
|
-
ASSERT_STREQ(s2, v2);
|
114
|
-
|
115
|
-
ASSERT_EQ(mh1->inUseCount(), 1UL);
|
116
|
-
ASSERT_EQ(mh2->inUseCount(), 1UL);
|
117
|
-
|
118
|
-
if (invert) {
|
119
|
-
MiniHeap *tmp = mh1;
|
120
|
-
mh1 = mh2;
|
121
|
-
mh2 = tmp;
|
122
|
-
}
|
123
|
-
|
124
|
-
thread writer(writerThread);
|
125
|
-
|
126
|
-
while (ShouldContinueTest != 1)
|
127
|
-
sched_yield();
|
128
|
-
|
129
|
-
const auto bitmap1 = mh1->bitmap().bits();
|
130
|
-
const auto bitmap2 = mh2->bitmap().bits();
|
131
|
-
const auto len = mh1->bitmap().byteCount();
|
132
|
-
ASSERT_EQ(len, mh2->bitmap().byteCount());
|
133
|
-
|
134
|
-
ASSERT_TRUE(mesh::bitmapsMeshable(bitmap1, bitmap2, len));
|
135
|
-
|
136
|
-
note("ABOUT TO MESH");
|
137
|
-
// mesh the two miniheaps together
|
138
|
-
gheap.meshLocked(mh1, mh2);
|
139
|
-
note("DONE MESHING");
|
140
|
-
|
141
|
-
// ensure the count of set bits looks right
|
142
|
-
ASSERT_EQ(mh1->inUseCount(), 2UL);
|
143
|
-
|
144
|
-
// check that our two allocated objects still look right
|
145
|
-
ASSERT_STREQ(s1, v1);
|
146
|
-
ASSERT_STREQ(s2, v2);
|
147
|
-
|
148
|
-
// get an aliased pointer to the second string by pointer arithmetic
|
149
|
-
// on the first string
|
150
|
-
char *s3 = s1 + (ObjCount - 1) * StrLen;
|
151
|
-
ASSERT_STREQ(s2, s3);
|
152
|
-
|
153
|
-
ShouldExit = 1;
|
154
|
-
writer.join();
|
155
|
-
|
156
|
-
// modify the second string, ensure the modification shows up on
|
157
|
-
// string 3 (would fail if the two miniheaps weren't meshed)
|
158
|
-
s2[0] = 'b';
|
159
|
-
ASSERT_EQ(s3[0], 'b');
|
160
|
-
|
161
|
-
// now free the objects by going through the global heap -- it
|
162
|
-
// should redirect both objects to the same miniheap
|
163
|
-
gheap.free(s1);
|
164
|
-
ASSERT_TRUE(!mh1->isEmpty());
|
165
|
-
gheap.free(s2);
|
166
|
-
ASSERT_TRUE(mh1->isEmpty()); // safe because mh1 isn't "done"
|
167
|
-
|
168
|
-
note("ABOUT TO FREE");
|
169
|
-
gheap.freeMiniheap(mh1);
|
170
|
-
note("DONE FREE");
|
171
|
-
|
172
|
-
note("ABOUT TO SCAVENGE");
|
173
|
-
gheap.scavenge(true);
|
174
|
-
note("DONE SCAVENGE");
|
175
|
-
|
176
|
-
ASSERT_EQ(gheap.getAllocatedMiniheapCount(), 0UL);
|
177
|
-
}
|
178
|
-
|
179
|
-
TEST(ConcurrentMeshTest, TryMesh) {
|
180
|
-
meshTestConcurrentWrite(false);
|
181
|
-
}
|
182
|
-
|
183
|
-
TEST(ConcurrentMeshTest, TryMeshInverse) {
|
184
|
-
meshTestConcurrentWrite(true);
|
185
|
-
}
|