Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion test/regression/CppiaAdoptInstances/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import cpp.cppia.Module;
//
// Every call into script code runs on a joined native worker, so stale values
// it leaves on a stack do not decide what keeps a module loaded. The main
// thread only collects and prints.
// thread only collects and prints. The collection that counts what a module
// keeps scans the frames it runs in for pointers, and a slot nothing has
// written yet still holds what an earlier call left there, which can be the
// address of an object freed since and of a closure of the old module now:
// once, under ASan on Linux, the count found two closures where one stayed.
// So the stack below main's frame is cleared before each count
@:cppFileCode('
#include <thread>
#include <hx/Native.h>
Expand All @@ -19,6 +24,16 @@ static void runJoined(Dynamic callback) {
hx::AutoGCFreeZone freeZone;
worker.join();
}
#ifdef _MSC_VER
__declspec(noinline)
#else
__attribute__((noinline))
#endif
static void clearStack() {
void * volatile area[8192];
for (int i = 0; i < 8192; i++)
area[i] = 0;
}
')
class Main {
static var dir:String;
Expand Down Expand Up @@ -100,8 +115,10 @@ class Main {
untyped __cpp__("runJoined({0})", adopt);
untyped __cpp__("runJoined({0})", useMoved);
untyped __cpp__("runJoined({0})", useOld);
untyped __cpp__("clearStack()");
lines.push('the old module keeps only what stayed: ${retained()}');
untyped __cpp__("runJoined({0})", dropOld);
untyped __cpp__("clearStack()");
lines.push('and is freed once they go: "${retained()}"');
untyped __cpp__("runJoined({0})", dropAll);
for (line in lines)
Expand Down
Loading