Skip to content

Commit a072f7c

Browse files
authored
Merge pull request #1664 from clasp-developers/boehm-cleanup
Upgrades to boehm gc 8.2.8 and cleans up some old code. More importantly, it enables the use of thread-local allocation, which should make consing more efficient in a multi threaded program.
2 parents 3b43dac + 794a982 commit a072f7c

File tree

12 files changed

+66
-445
lines changed

12 files changed

+66
-445
lines changed

include/clasp/gctools/boehm_config.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#define GC_VERSION_MAJOR 8
8787

8888
/* The micro version number of this GC release. */
89-
#define GC_VERSION_MICRO 0
89+
#define GC_VERSION_MICRO 8
9090

9191
/* The minor version number of this GC release. */
9292
#define GC_VERSION_MINOR 2
@@ -193,7 +193,7 @@
193193
#define PACKAGE_NAME "gc"
194194

195195
/* Define to the full name and version of this package. */
196-
#define PACKAGE_STRING "gc 8.2.0"
196+
#define PACKAGE_STRING "gc 8.2.8"
197197

198198
/* Define to the one symbol short name of this package. */
199199
#define PACKAGE_TARNAME "gc"
@@ -202,7 +202,7 @@
202202
#define PACKAGE_URL ""
203203

204204
/* Define to the version of this package. */
205-
#define PACKAGE_VERSION "8.2.0"
205+
#define PACKAGE_VERSION "8.2.8"
206206

207207
/* Define to enable parallel marking. */
208208
/* #undef PARALLEL_MARK */
@@ -256,7 +256,7 @@
256256
/* #undef USE_WINALLOC */
257257

258258
/* Version number of package */
259-
#define VERSION "8.2.0"
259+
#define VERSION "8.2.8"
260260

261261
/* The POSIX feature macro. */
262262
/* #undef _POSIX_C_SOURCE */

include/clasp/gctools/gc_boot.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,21 @@ struct Container_layout {
153153

154154
enum Layout_operation { class_container_op, bitunit_container_op, templated_op, undefined_op };
155155

156+
#ifdef USE_BOEHM
156157
#define KIND_UNDEFINED 99999
157158
struct Boehm_info {
158159
bool _kind_defined = false;
159-
int _container_element_work = 0;
160160
uintptr_t _kind = KIND_UNDEFINED;
161161
};
162+
#endif // USE_BOEHM
162163

163164
struct Stamp_layout {
164165
// One of class_container_op, bitunit_container_op, templated_op
165166
Layout_operation layout_op = undefined_op;
166167
const char* name;
168+
#ifdef USE_BOEHM
167169
Boehm_info boehm;
170+
#endif // USE_BOEHM
168171
// A bitmap of pointer fields for mps fixing and (once shifted right to skip clasp header - boehm marking)
169172
// The most significant bit indicates the vtable - it must be zero
170173
uintptr_t class_field_pointer_bitmap = 0;

include/clasp/gctools/gcalloc_boehm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#define ALIGNED_GC_MALLOC(sz) MAYBE_MONITOR_ALLOC(GC_MALLOC(sz), sz)
55
#define ALIGNED_GC_MALLOC_ATOMIC(sz) MAYBE_MONITOR_ALLOC(GC_MALLOC_ATOMIC(sz), sz)
66
#define ALIGNED_GC_MALLOC_UNCOLLECTABLE(sz) MAYBE_MONITOR_ALLOC(GC_MALLOC_UNCOLLECTABLE(sz), sz)
7-
#define ALIGNED_GC_MALLOC_KIND(sz, knd) MAYBE_MONITOR_ALLOC(GC_malloc_kind_global(sz, knd), sz)
8-
#define ALIGNED_GC_MALLOC_STRONG_WEAK_KIND(sz, knd) MAYBE_MONITOR_ALLOC(GC_malloc_kind_global(sz, knd), sz)
7+
#define ALIGNED_GC_MALLOC_KIND(sz, knd) MAYBE_MONITOR_ALLOC(GC_malloc_kind(sz, knd), sz)
8+
#define ALIGNED_GC_MALLOC_STRONG_WEAK_KIND(sz, knd) MAYBE_MONITOR_ALLOC(GC_malloc_kind(sz, knd), sz)
99
#define ALIGNED_GC_MALLOC_ATOMIC_KIND(stmp, sz, knd, kndaddr) \
1010
MAYBE_MONITOR_ALLOC( \
11-
(knd == GC_I_PTRFREE) ? GC_malloc_kind_global(sz, knd) : malloc_kind_error(GC_I_PTRFREE, knd, sz, stmp, kndaddr), sz)
11+
(knd == GC_I_PTRFREE) ? GC_malloc_kind(sz, knd) : malloc_kind_error(GC_I_PTRFREE, knd, sz, stmp, kndaddr), sz)
1212
#define ALIGNED_GC_MALLOC_UNCOLLECTABLE_KIND(sz, knd) \
1313
MAYBE_MONITOR_ALLOC(GC_generic_malloc_uncollectable(sz, knd), sz)
1414
#else

include/clasp/gctools/gcweak.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,8 @@ struct WeakPointer {
8989
void store_no_lock(core::T_sp); // ditto.
9090
void store(core::T_sp);
9191
void fixupInternalsForSnapshotSaveLoad(snapshotSaveLoad::Fixup*);
92-
public: // has to be public for precise GC reasons even though it's not scanned?
93-
// This is a Tagged rather than a T_sp because something in gc_boot seems to
94-
// check for T_sps in atomic (pointerless) objects. Rather than lie harder we
95-
// can just do this and build a T_sp from it as required.
96-
Tagged _value;
92+
private:
93+
core::T_sp _value;
9794
#ifdef USE_BOEHM
9895
// flag needed to disambiguate fixnum 0 from splatted pointer
9996
bool _splattablep = false;

include/clasp/gctools/memoryManagement.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,6 @@ class BaseHeader_s {
483483
void* fwdPointer() const { return reinterpret_cast<void*>(this->_header_data[0] & (~(uintptr_t)mtag_mask)); };
484484
/*! Return the size of the fwd block - without the header. This reaches into the client area to get the size */
485485
void setFwdPointer(void* ptr) { this->_header_data[0] = reinterpret_cast<uintptr_t>(ptr) | fwd_mtag; };
486-
uintptr_t fwdSize() const { return this->_header_data[1]; };
487-
/*! This writes into the first tagged_stamp_t sized word of the client data. */
488-
void setFwdSize(size_t sz) { this->_header_data[1] = sz; };
489486
/*! Define the header as a pad, pass pad_tag or pad1_tag */
490487
void setPad(tagged_stamp_t p) { this->_header_data[0] = p; };
491488
/*! Return the pad1 size */
@@ -610,7 +607,7 @@ class BaseHeader_s {
610607
return "Header_CONS";
611608
} else if (this->_badge_stamp_wtag_mtag.fwdP()) {
612609
std::stringstream ss;
613-
ss << "Fwd/ptr=" << this->_badge_stamp_wtag_mtag.fwdPointer() << "/sz=" << this->_badge_stamp_wtag_mtag.fwdSize();
610+
ss << "Fwd/ptr=" << this->_badge_stamp_wtag_mtag.fwdPointer();
614611
return ss.str();
615612
} else if (this->_badge_stamp_wtag_mtag.pad1P()) {
616613
return "Pad1";

repos.sexp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
(:name :bdwgc
208208
:repository "https://github.com/ivmai/bdwgc.git"
209209
:directory "src/bdwgc/"
210-
:commit "v8.2.0")
210+
:commit "v8.2.8")
211211
(:name :libatomic_ops
212212
:repository "https://github.com/ivmai/libatomic_ops.git"
213213
:directory "src/libatomic_ops/"

src/gctools/cons_scan.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define POINTER_FIX(field) // Macro to fix pointer at field
1111
#define CONS_SCAN // Macro to turn on #ifdef inclusion of code
1212
#define CONS_SKIP // Macro to turn on #ifdef inclusion of code
13-
#define CONS_FWD // Macro to turn on #ifdef inclusion of code
1413
#define EXTRA_ARGUMENTS // Add extra arguments
1514
*/
1615

@@ -59,19 +58,3 @@ ADDR_T CONS_SKIP(ADDR_T client, size_t& objectSize) {
5958
return client;
6059
}
6160
#endif // CONS_SKIP
62-
63-
#ifdef CONS_FWD
64-
#ifdef CONS_SKIP_IN_CONS_FWD
65-
ADDR_T CONS_SKIP_IN_CONS_FWD(ADDR_T client);
66-
#endif // CONS_SKIP_IN_CONS_FWD
67-
68-
static void CONS_FWD(ADDR_T old_client, ADDR_T new_client) {
69-
// printf("%s:%d in %s\n", __FILE__, __LINE__, __FUNCTION__ );
70-
// I'm assuming both old and new client pointers have valid headers at this point
71-
CONS_SKIP_IN_CONS_FWD(old_client);
72-
core::Cons_O* cons = reinterpret_cast<core::Cons_O*>(old_client);
73-
gctools::Header_s* header = (gctools::Header_s*)gctools::ConsPtrToHeaderPtr(cons);
74-
header->_badge_stamp_wtag_mtag.setFwdPointer((void*)new_client);
75-
header->_badge_stamp_wtag_mtag.setFwdSize(sizeof(core::Cons_O));
76-
}
77-
#endif // CONS_FWD

src/gctools/gc_boot.cc

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
#define DGC_PRINT(...)
2121
#endif
2222

23-
#if defined(USE_BOEHM) && defined(USE_PRECISE_GC)
24-
extern "C" {
25-
void* obj_skip(void*);
26-
};
27-
#define GC_LISP_OBJECT_MARK
28-
#include "obj_scan.cc"
29-
#undef GC_LISP_OBJECT_MARK
30-
#endif
31-
3223
namespace gctools {
3324

3425
uintptr_t global_lisp_kind;
@@ -400,17 +391,12 @@ void walk_stamp_field_layout_tables(WalkKind walk, std::ostream& fout) {
400391
}
401392

402393
// Use boehm in the precise GC mode
403-
// global_container_proc_index = GC_new_proc_inner((GC_mark_proc)class_container_mark);
404-
global_lisp_kind = GC_new_kind(GC_new_free_list(), GC_DS_LENGTH, 1, 1);
405-
global_cons_kind = GC_new_kind(GC_new_free_list(), GC_DS_LENGTH, 1, 1);
406-
global_class_kind =
407-
GC_new_kind(GC_new_free_list(), GC_DS_LENGTH, 1,
408-
1); // GC_MAKE_PROC(GC_new_proc((GC_mark_proc)Lisp_object_mark),0), 0, 1); // GC_DS_LENGTH, 1, 1);
409-
global_container_kind = GC_new_kind(
410-
GC_new_free_list(), GC_DS_LENGTH, 1,
411-
1); // */ GC_new_kind(GC_new_free_list(), GC_MAKE_PROC(global_container_proc_index,0),0,1); // GC_DS_LENGTH, 1, 1);
412-
global_code_kind = GC_new_kind(GC_new_free_list(), GC_DS_LENGTH, 1, 1);
413-
global_atomic_kind = GC_I_PTRFREE; // GC_new_kind(GC_new_free_list(), GC_DS_LENGTH, 0, 1);
394+
global_lisp_kind = GC_I_NORMAL;
395+
global_cons_kind = GC_I_NORMAL;
396+
global_class_kind = GC_I_NORMAL;
397+
global_container_kind = GC_I_NORMAL;
398+
global_code_kind = GC_I_NORMAL;
399+
global_atomic_kind = GC_I_PTRFREE;
414400
for (cur_stamp = 0; cur_stamp <= local_stamp_max; ++cur_stamp) {
415401
if (local_stamp_layout[cur_stamp].layout_op != undefined_op) {
416402
#ifdef DUMP_PRECISE_CALC
@@ -461,10 +447,6 @@ void walk_stamp_field_layout_tables(WalkKind walk, std::ostream& fout) {
461447
"%s:%d WARNING There are too many pointers (%d) in each element of a container to break up the work for boehm\n",
462448
__FILE__, __LINE__, pointer_count);
463449
}
464-
// Calculate the number of elements worth of pointers are processed with each
465-
// call to the marking procedure
466-
int container_element_work = pointer_count ? (GC_PROC_BYTES / 8 / 2) / pointer_count : 0;
467-
local_stamp_layout[cur_stamp].boehm._container_element_work = container_element_work;
468450
if (class_bitmap && !container_bitmap) {
469451
// There are no pointers in the container part
470452
// - so we can use the bitmap_skip_header
@@ -512,11 +494,13 @@ void walk_stamp_field_layout_tables(WalkKind walk, std::ostream& fout) {
512494
} else if (walk == precise_info) {
513495
// Check that everything is ok
514496
if (getenv("CLASP_DEBUG_STAMP_INFO")) {
497+
#if defined(USE_BOEHM) && defined(USE_PRECISE_GC)
515498
for (size_t stamp = 0; stamp <= local_stamp_max; stamp++) {
516499
printf("%s:%d:%s stamp: %3lu boehm._kind_defined %2d boehm._kind %5lu name: %s\n", __FILE__, __LINE__, __FUNCTION__,
517500
stamp, local_stamp_layout[stamp].boehm._kind_defined, local_stamp_layout[stamp].boehm._kind,
518501
local_stamp_layout[stamp].name);
519502
}
503+
#endif // defined(USE_BOEHM) && defined(USE_PRECISE_GC)
520504
printf("%s:%d:%s local_stamp_max: %lu\n", __FILE__, __LINE__, __FUNCTION__, local_stamp_max);
521505
}
522506
global_stamp_max = local_stamp_max;

src/gctools/gcweak.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ THE SOFTWARE.
3434
namespace gctools {
3535

3636
#ifdef USE_BOEHM
37-
WeakPointer::WeakPointer(core::T_sp o) : _value(o.tagged_()) {
37+
WeakPointer::WeakPointer(core::T_sp o) : _value(o) {
3838
if (o.objectp()) { // pointer, so we're actually weak
3939
_splattablep = true;
4040
// note: deregistered automatically if the weak pointer itself is dealloc'd
@@ -45,8 +45,8 @@ WeakPointer::WeakPointer(core::T_sp o) : _value(o.tagged_()) {
4545
void* WeakPointer::value_helper(void* data) {
4646
value_helper_s* vhsp = (value_helper_s*)data;
4747
if (vhsp->wp->_value || !vhsp->wp->_splattablep) // not splatted
48-
// construct a T_sp in the result
49-
vhsp->result.emplace(vhsp->wp->_value);
48+
// put a T_sp in the result
49+
vhsp->result = vhsp->wp->_value;
5050
// otherwise, leave the result default constructed (no T_sp)
5151
return nullptr; // unused
5252
}
@@ -59,11 +59,11 @@ std::optional<core::T_sp> WeakPointer::value() const {
5959
}
6060
std::optional<core::T_sp> WeakPointer::value_no_lock() const {
6161
if (_value || !_splattablep)
62-
return core::T_sp(_value);
62+
return _value;
6363
else return std::nullopt;
6464
}
6565
void WeakPointer::store_no_lock(core::T_sp o) {
66-
_value = o.tagged_();
66+
_value = o;
6767
_splattablep = o.objectp();
6868
// links set up in fixupInternals below.
6969
}
@@ -76,31 +76,30 @@ void WeakPointer::store(core::T_sp o) {
7676
_splattablep = false;
7777
GC_unregister_disappearing_link((void**)&_value);
7878
}
79-
_value = o.tagged_();
79+
_value = o;
8080
}
8181

8282
void WeakPointer::fixupInternalsForSnapshotSaveLoad(snapshotSaveLoad::Fixup* fixup) {
8383
if (snapshotSaveLoad::operation(fixup) == snapshotSaveLoad::LoadOp) {
8484
// We do this later rather than in store_no_lock because register/deregister
8585
// unconditionally grab a lock. This is a bit of a KLUDGE.
86-
core::T_sp o(_value);
87-
if (o.objectp()) {
86+
if (_value.objectp()) {
8887
_splattablep = true;
8988
// Implicitly removes any previous registration, per boehm docs.
90-
GC_general_register_disappearing_link((void**)&_value, &*o);
89+
GC_general_register_disappearing_link((void**)&_value, &*_value);
9190
} else {
9291
_splattablep = false;
9392
GC_unregister_disappearing_link((void**)&_value);
9493
}
9594
}
9695
}
9796
#else // not-actually-weak pointers - TODO for your other GC!
98-
WeakPointer::WeakPointer(core::T_sp o) : _value(o.tagged_()) {}
97+
WeakPointer::WeakPointer(core::T_sp o) : _value(o) {}
9998

10099
// always valid
101-
std::optional<core::T_sp> WeakPointer::value() const { return core::T_sp(_value); }
100+
std::optional<core::T_sp> WeakPointer::value() const { return _value; }
102101
std::optional<core::T_sp> WeakPointer::value_no_lock() const { return value(); }
103-
void WeakPointer::store_no_lock(core::T_sp o) { _value = o.tagged_(); }
102+
void WeakPointer::store_no_lock(core::T_sp o) { _value = o; }
104103
void WeakPointer::store(core::T_sp o) { store_no_lock(o); }
105104
void WeakPointer::fixupInternalsForSnapshotSaveLoad(snapshotSaveLoad::Fixup*) {}
106105
#endif

src/gctools/memoryManagement.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,6 @@ void rawHeaderDescribe(const uintptr_t* headerP) {
400400
Header_s* hdr = (Header_s*)headerP;
401401
printf(" 0x%p : 0x%" PRIuPTR " 0x%" PRIuPTR "\n", headerP, *headerP, *(headerP + 1));
402402
printf(" fwd_tag - fwd address: 0x%" PRIuPTR "\n", (*headerP) & Header_s::mtag_mask);
403-
printf(" fwdSize = %" PRIuPTR "/0x%" PRIuPTR "\n", hdr->_badge_stamp_wtag_mtag.fwdSize(),
404-
hdr->_badge_stamp_wtag_mtag.fwdSize());
405403
} break;
406404
case Header_s::pad1_mtag:
407405
printf(" 0x%p : 0x%" PRIuPTR " 0x%" PRIuPTR "\n", headerP, *headerP, *(headerP + 1));
@@ -1017,7 +1015,7 @@ size_t objectSize(BaseHeader_s* header) {
10171015
// It's a general object - walk it
10181016
size_t objectSize;
10191017
uintptr_t client = (uintptr_t)HeaderPtrToGeneralPtr<void*>(header);
1020-
mw_obj_skip(client, false, objectSize);
1018+
mw_obj_skip(client, objectSize);
10211019
return objectSize;
10221020
}
10231021
}

0 commit comments

Comments
 (0)