Skip to content

Commit

Permalink
Fixed snapshot save/load
Browse files Browse the repository at this point in the history
The badges for hashed objects were not being
saved and then were being ignored on load.
Both of these things are fixed now.
  • Loading branch information
meister authored and drmeister committed Jul 31, 2023
1 parent 1125bcf commit 5535cbf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/clasp/core/configure_clasp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ THE SOFTWARE.


#if 0
#define DEBUG_BADGE_SSL 1
//// DEBUG_RUNTIME defined and type errors print more info
//#define DEBUG_RUNTIME 1
//#define DEBUG_OBJECT_FILES 1
Expand All @@ -43,7 +44,7 @@ THE SOFTWARE.
//#define DEBUG_EVALUATE 1
//#define DEBUG_DTORS 1
//#define DEBUG_DYN_ENV_STACK 1
#define DEBUG_DTREE_INTERPRETER
//#define DEBUG_DTREE_INTERPRETER
//#define DEBUG_VIRTUAL_MACHINE 1
//#define DEBUG_DRAG_CXX_CALLS 1 // Slows down all calls in CXX wrappers - study impact
//#define DEBUG_DRAG_NATIVE_CALLS 1
Expand Down
3 changes: 3 additions & 0 deletions include/clasp/gctools/gcalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ namespace gctools {
DO_DRAG_GENERAL_ALLOCATION();
#if defined(USE_BOEHM)
Header_s* base = do_boehm_general_allocation(snapshot_save_load_init->_headStart->_badge_stamp_wtag_mtag,sizeWithHeader);
// transfer the badge
base->_badge_stamp_wtag_mtag._header_badge.store(snapshot_save_load_init->_headStart->_badge_stamp_wtag_mtag._header_badge.load());
# ifdef DEBUG_GUARD
// Copy the source from the image save/load memory.
base->_source = snapshot_save_load_init->_headStart->_source;
Expand All @@ -373,6 +375,7 @@ namespace gctools {
return sp;
#elif defined(USE_MMTK)
Header_s* base = do_mmtk_general_allocation(snapshot_save_load_init->_headStart->_badge_stamp_wtag_mtag,sizeWithHeader);
base->_badge_stamp_wtag_mtag._header_badge.store(snapshot_save_load_init->_headStart->_badge_stamp_wtag_mtag._header_badge.load());
# ifdef DEBUG_GUARD
// Copy the source from the image save/load memory.
base->_source = snapshot_save_load_init->_headStart->_source;
Expand Down
24 changes: 17 additions & 7 deletions src/gctools/snapshotSaveLoad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bool global_debugSnapshot = false;
namespace snapshotSaveLoad {

bool global_InSnapshotLoad = false;
size_t global_badge_count = 0;

struct MaybeTimeStartup {
std::chrono::time_point<std::chrono::steady_clock> start;
Expand Down Expand Up @@ -1651,6 +1652,7 @@ struct copy_objects_t : public walker_callback_t {
gctools::clasp_ptr_t clientEnd = clientStart + generalSize;
#ifdef DEBUG_BADGE_SSL
if (header->_badge_stamp_wtag_mtag._header_badge.load()>1) {
global_badge_count++;
printf("%s:%d:%s ===== create snapshot object %p with badge: %u\n", __FILE__, __LINE__, __FUNCTION__, header, header->_badge_stamp_wtag_mtag._header_badge.load() );
}
#endif
Expand Down Expand Up @@ -2255,6 +2257,7 @@ CL_DEFUN size_t gctools__memory_test(core::T_sp filename)

/* This is not allowed to do any allocations. */
void* snapshot_save_impl(void* data) {
global_badge_count = 0;
core::SaveLispAndDie* snapshot_data = (core::SaveLispAndDie*)data;
global_debugSnapshot = getenv("CLASP_DEBUG_SNAPSHOT")!=NULL;

Expand Down Expand Up @@ -2631,23 +2634,26 @@ void* snapshot_save_impl(void* data) {
while ( (c = getchar()) != '\n' && c != EOF ) { };
}
#endif
exit(0);

#ifdef DEBUG_BADGE_SSL
printf("%s:%d:%s global_badge_count = %lu\n", __FILE__, __LINE__, __FUNCTION__, global_badge_count );
#endif
#ifdef USE_BOEHM
printf("%s:%d:%s Not using GC_start_world_external();\n", __FILE__, __LINE__, __FUNCTION__ );
#endif
return NULL;
exit(0);
}


void snapshot_save(core::SaveLispAndDie& data) {


#ifdef DEBUG_BADGE_SSL
printf("%s:%d:%s snapshot_save dumping class hash-table\n", __FILE__, __LINE__, __FUNCTION__ );
core::HashTable_sp classNames = _lisp->_Roots._ClassTable;
printf("%s\n", classNames->hash_table_dump().c_str());
printf("%s:%d:%s done dumping class hash-table\n", __FILE__, __LINE__, __FUNCTION__ );

#endif

//
// For real save-lisp-and-die do the following (a simple 19 step plan)
//
Expand Down Expand Up @@ -3494,9 +3500,12 @@ void snapshot_load( void* maybeStartOfSnapshot, void* maybeEndOfSnapshot, const
);
countNullObjects++;
} else {
#if 0
#ifdef DEBUG_BADGE_SSL
if (init._headStart->_badge_stamp_wtag_mtag._header_badge.load()>1) {
printf("%s:%d:%s Copy/allocate snapshot object %p with badge: %u\n", __FILE__, __LINE__, __FUNCTION__, init._headStart, init._headStart->_badge_stamp_wtag_mtag._header_badge.load() );
global_badge_count++;
printf("%s:%d:%s global_badge_count = %lu --- copy/allocate snapshot object _headStart %p with badge: %u\n",
__FILE__, __LINE__, __FUNCTION__, global_badge_count,
init._headStart, init._headStart->_badge_stamp_wtag_mtag._header_badge.load() );
}
#endif
core::T_sp obj = gctools::GCObjectAllocator<core::General_O>::snapshot_save_load_allocate(&init);
Expand Down Expand Up @@ -3824,6 +3833,7 @@ void snapshot_load( void* maybeStartOfSnapshot, void* maybeEndOfSnapshot, const
}
}
}
#ifdef DEBUG_BADGE_SSL
printf("%s:%d:%s Finished snapshot_load checking room\n", __FILE__, __LINE__, __FUNCTION__ );
gctools::cl__room(kw::_sym_test);
printf("%s:%d:%s Finished snapshot_load dumping _lisp->_Roots._ClassTable\n", __FILE__, __LINE__, __FUNCTION__ );
Expand All @@ -3832,7 +3842,7 @@ void snapshot_load( void* maybeStartOfSnapshot, void* maybeEndOfSnapshot, const
printf("%s:%d:%s Finished snapshot_load checking find_class('cl:restart)\n", __FILE__, __LINE__, __FUNCTION__ );
core::T_sp theClass = cl__find_class(cl::_sym_restart, true, nil<core::T_O>());
printf("%s:%d:%s theClass = %p\n", __FILE__, __LINE__, __FUNCTION__, theClass.raw_());

#endif
}


Expand Down

0 comments on commit 5535cbf

Please sign in to comment.