Skip to content

Commit da241bf

Browse files
committed
Solve bug introduced by 0a8e426 ; this forced to executed the destroy events of the functions, classes and objects after the runtime is destroyed and this is very problematic. The destruction has been moved after the destroy children. Apparently this should not be a problem, but maybe this should be separated into two different functions if there is some special case of a loader. For now it works on node (which is the problematic one) and for the rest of loaders, which is exactly the same behavior as before.
1 parent 1451753 commit da241bf

File tree

21 files changed

+53
-28
lines changed

21 files changed

+53
-28
lines changed

source/loader/include/loader/loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ LOADER_API value loader_metadata(void);
9393

9494
LOADER_API int loader_clear(void *handle);
9595

96-
LOADER_API void loader_unload_children(void);
96+
LOADER_API void loader_unload_children(loader_impl impl);
9797

9898
LOADER_API int loader_unload(void);
9999

source/loader/include/loader/loader_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ LOADER_API value loader_impl_metadata(loader_impl impl);
7676

7777
LOADER_API int loader_impl_clear(void *handle);
7878

79+
LOADER_API void loader_impl_destroy_objects(loader_impl impl);
80+
7981
LOADER_API void loader_impl_destroy(loader_impl impl);
8082

8183
LOADER_API loader_impl loader_impl_create_proxy(void);

source/loader/source/loader.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ int loader_clear(void *handle)
806806
return loader_impl_clear(handle);
807807
}
808808

809-
void loader_unload_children()
809+
void loader_unload_children(loader_impl impl)
810810
{
811811
loader l = loader_singleton();
812812
uint64_t current = thread_id_get_current();
@@ -847,6 +847,12 @@ void loader_unload_children()
847847
}
848848

849849
vector_destroy(stack);
850+
851+
/* Clear all objects and types related to the loader once all childs have been destroyed */
852+
if (impl != NULL)
853+
{
854+
loader_impl_destroy_objects(impl);
855+
}
850856
}
851857

852858
int loader_unload()
@@ -870,7 +876,7 @@ int loader_unload()
870876
/* TODO: How to deal with this? */
871877
}
872878

873-
loader_unload_children();
879+
loader_unload_children(NULL);
874880
}
875881

876882
/* Clear the implementation tag map */

source/loader/source/loader_impl.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,27 @@ int loader_impl_destroy_exec_path_map_cb_iterate(set s, set_key key, set_value v
11071107
return 0;
11081108
}
11091109

1110+
void loader_impl_destroy_objects(loader_impl impl)
1111+
{
1112+
/* This iterates through all functions, classes objects and types,
1113+
* it is necessary to be executed on demand because those can have
1114+
* implementations in the loader implementation which need to be GCed
1115+
* or freed properly before the runtime goes down but after the
1116+
* destroy has been issued, so while it is destroying, we can still
1117+
* retrieve the data for introspection or for whatever we need
1118+
*/
1119+
if (impl != NULL)
1120+
{
1121+
set_iterate(impl->handle_impl_map, &loader_impl_destroy_handle_map_cb_iterate, NULL);
1122+
1123+
set_destroy(impl->handle_impl_map);
1124+
1125+
set_iterate(impl->type_info_map, &loader_impl_destroy_type_map_cb_iterate, NULL);
1126+
1127+
set_destroy(impl->type_info_map);
1128+
}
1129+
}
1130+
11101131
void loader_impl_destroy(loader_impl impl)
11111132
{
11121133
if (impl != NULL)
@@ -1125,14 +1146,6 @@ void loader_impl_destroy(loader_impl impl)
11251146
impl->init = 1;
11261147
}
11271148

1128-
set_iterate(impl->handle_impl_map, &loader_impl_destroy_handle_map_cb_iterate, NULL);
1129-
1130-
set_destroy(impl->handle_impl_map);
1131-
1132-
set_iterate(impl->type_info_map, &loader_impl_destroy_type_map_cb_iterate, NULL);
1133-
1134-
set_destroy(impl->type_info_map);
1135-
11361149
set_iterate(impl->exec_path_map, &loader_impl_destroy_exec_path_map_cb_iterate, NULL);
11371150

11381151
set_destroy(impl->exec_path_map);

source/loaders/c_loader/source/c_loader_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ int c_loader_impl_destroy(loader_impl impl)
289289
if (c_impl != NULL)
290290
{
291291
/* Destroy children loaders */
292-
loader_unload_children();
292+
loader_unload_children(impl);
293293

294294
delete c_impl;
295295

source/loaders/cob_loader/source/cob_loader_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ int cob_loader_impl_destroy(loader_impl impl)
259259
(void)impl;
260260

261261
// Destroy children loaders
262-
loader_unload_children();
262+
loader_unload_children(impl);
263263

264264
return cobtidy();
265265
}

source/loaders/cs_loader/source/cs_loader_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ int cs_loader_impl_destroy(loader_impl impl)
396396
netcore_handle nhandle = (netcore_handle)loader_impl_get(impl);
397397

398398
/* Destroy children loaders */
399-
loader_unload_children();
399+
loader_unload_children(impl);
400400

401401
simple_netcore_destroy(nhandle);
402402

source/loaders/dart_loader/source/dart_loader_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ int dart_loader_impl_destroy(loader_impl impl)
571571
if (dart_impl != nullptr)
572572
{
573573
/* Destroy children loaders */
574-
loader_unload_children();
574+
loader_unload_children(impl);
575575

576576
delete dart_impl;
577577

source/loaders/file_loader/source/file_loader_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ int file_loader_impl_destroy(loader_impl impl)
439439
if (file_impl != NULL)
440440
{
441441
/* Destroy children loaders */
442-
loader_unload_children();
442+
loader_unload_children(impl);
443443

444444
free(file_impl);
445445

source/loaders/java_loader/source/java_loader_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ int java_loader_impl_destroy(loader_impl impl)
307307
std::cout << "1ffffffffffffffffffffffffffff" << std::endl;
308308

309309
/* Destroy children loaders */
310-
loader_unload_children();
310+
loader_unload_children(impl);
311311
std::cout << "2ffffffffffffffffffffffffffff" << std::endl;
312312

313313
java_impl->jvm->DestroyJavaVM();

0 commit comments

Comments
 (0)