Skip to content

Commit

Permalink
give snapshot load threads semi-lisp status
Browse files Browse the repository at this point in the history
they grab mutexes and allocate. the former more or less requires
a thread, and the latter definitely does with whippet or mps.
These threads shouldn't need a VM however.
  • Loading branch information
Bike committed Nov 11, 2024
1 parent cdff588 commit befecba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/clasp/gctools/threadlocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ struct VirtualMachine {
// grow and etc.
static constexpr size_t MaxStackWords = 65536;
bool _Running;
core::T_O** _stackBottom;
core::T_O** _stackBottom = nullptr;
size_t _stackBytes;
core::T_O** _stackTop;
core::T_O** _stackGuard;
core::T_O** _stackPointer;
// only used by debugger
// has to be initialized because bytecode_call reads it
core::T_O** _framePointer = NULL;
core::T_O** _framePointer = nullptr;
#ifdef DEBUG_VIRTUAL_MACHINE
core::T_O* _data;
core::T_O* _data1;
Expand Down
6 changes: 6 additions & 0 deletions src/gctools/snapshotSaveLoad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3474,6 +3474,12 @@ void snapshot_load(void* maybeStartOfSnapshot, void* maybeEndOfSnapshot, const s
// lookup will cause multicore linking and with multicore linking we have to do things after this in a thread safe way
size_t objectId = allocatedObjectFile->_ObjectId;
pool.push_task([&obj_claspJIT, jitdylib, objectId]() {
// do_lookup can allocate, so set up a bit of a Lisp thread.
void* stacktop = &stacktop;
gctools::ThreadLocalStateLowLevel tlsll(stacktop);
core::ThreadLocalState tls;
my_thread_low_level = &tlsll;
my_thread = &tls;
std::string start;
std::string shutdown;
core::startup_shutdown_names(objectId, "", start, shutdown);
Expand Down
5 changes: 4 additions & 1 deletion src/gctools/threadlocal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ VirtualMachine::~VirtualMachine() {
#if 1
this->disable_guards();
#endif
gctools::RootClassAllocator<T_O>::freeRoots(this->_stackBottom);
// In snapshot load we make threads with no VM.
// We have nothing to free and _stackBottom is just its initial NULL.
if (this->_stackBottom)
gctools::RootClassAllocator<T_O>::freeRoots(this->_stackBottom);
}

// For main thread initialization - it happens too early and _Nil is undefined
Expand Down

0 comments on commit befecba

Please sign in to comment.