tweag / asterius

DEPRECATED in favor of ghc wasm backend, see https://www.tweag.io/blog/2022-11-22-wasm-backend-merged-in-ghc
1.98k stars 55 forks source link

Runtime error related with GC options `--gc-threshold` #909

Open freedomhero opened 1 year ago

freedomhero commented 1 year ago

Describe the bug I got runtime errors when trying to run a heavy project by ahc-dist command with --gc-threshold option. Different errors were throwed according to --gc-threshold value for the same program. Here's the commands and the corresponding errors:

file:///workspace/rts.gc.mjs:466
        throw new WebAssembly.RuntimeError();
        ^

RuntimeError
    at GC.evacuateClosure (file:///workspace/rts.gc.mjs:466:15)
    at GC.scavengeClosureAt (file:///workspace/rts.gc.mjs:477:34)
    at GC.scavengePointersFirst (file:///workspace/rts.gc.mjs:481:41)
    at GC.scavengeClosure (file:///workspace/rts.gc.mjs:826:14)
    at GC.scavengeLoop (file:///workspace/rts.gc.mjs:750:31)
    at GC.performGC (file:///workspace/rts.gc.mjs:1065:10)
    at Scheduler.returnedFromTSO (file:///workspace/rts.scheduler.mjs:114:17)
    at Scheduler.tick (file:///workspace/rts.scheduler.mjs:355:14)
    at Immediate.<anonymous> (file:///workspace/rts.scheduler.mjs:118:33)
    at processImmediate (node:internal/timers:463:21)

<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 0xa68bf0 node::Abort() [node] 2: 0x99bc4d node::FatalError(char const, char const) [node] 3: 0xc433ae v8::Utils::ReportOOMFailure(v8::internal::Isolate, char const, bool) [node] 4: 0xc43727 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate, char const, bool) [node] 5: 0xe0d315 [node] 6: 0xe3c8a3 v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject, int) [node] 7: 0xe49456 v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::MemoryChunk, long) [node] 8: 0xe3557f v8::internal::Evacuator::EvacuatePage(v8::internal::MemoryChunk) [node] 9: 0xe357f8 v8::internal::PageEvacuationTask::RunInParallel(v8::internal::ItemParallelJob::Task::Runner) [node] 10: 0xe27619 v8::internal::ItemParallelJob::Run() [node] 11: 0xe4b3e0 void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks<v8::internal::FullEvacuator, v8::internal::MarkCompactCollector>(v8::internal::MarkCompactCollector, v8::internal::ItemParallelJob, v8::internal::MigrationObserver, long) [node] 12: 0xe4bc23 v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [node] 13: 0xe4bfe5 v8::internal::MarkCompactCollector::Evacuate() [node] 14: 0xe5e751 v8::internal::MarkCompactCollector::CollectGarbage() [node] 15: 0xe1a618 v8::internal::Heap::MarkCompact() [node] 16: 0xe1bfa8 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 17: 0xe1f54c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node] 18: 0xde346a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node] 19: 0x1139f2b v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long, v8::internal::Isolate) [node] 20: 0x14d0c99 [node]


* `ahc-dist --input-exe myprog --run --gc-threshold=350`

file:///workspace/rts.memory.mjs:101 return this.dataView.getBigUint64(p, true); ^

RangeError: Offset is outside the bounds of the DataView at DataView.getBigUint64 () at Memory.i64Load (file:///workspace/rts.memory.mjs:101:26) at GC.evacuateClosure (file:///workspace/rts.gc.mjs:255:37) at GC.scavengeClosureAt (file:///workspace/rts.gc.mjs:477:34) at GC.scavengePointersFirst (file:///workspace/rts.gc.mjs:481:41) at GC.scavengeClosure (file:///workspace/rts.gc.mjs:799:14) at GC.scavengeLoop (file:///workspace/rts.gc.mjs:750:31) at GC.performGC (file:///workspace/rts.gc.mjs:1065:10) at Scheduler.returnedFromTSO (file:///workspace/rts.scheduler.mjs:114:17) at Scheduler.tick (file:///workspace/rts.scheduler.mjs:355:14)


* `ahc-dist --input-exe myprog --run --gc-threshold=550`

JSException RuntimeError: function signature mismatch at :wasm-function[4596]:0xdd37f at scheduleTSO (:wasm-function[4597]:0xdd3ac) at Scheduler.tick (file:///workspace/rts.scheduler.mjs:347:22) at Immediate. (file:///workspace/rts.scheduler.mjs:118:33) at processImmediate (node:internal/timers:463:21)



**To Reproduce**
It's in a private repo now, sorry for the inconvenience. But I can provide access if needed.

**Expected behavior**
The expected behavior is only the performance differences when given different values for `--gc-threshold`, and the progrom should all end with success.

**Environment**
 - OS name + version: MacOS 12.6
 - Version of the code: docker latest

**Additional context**
Add any other context about the problem here.
freedomhero commented 1 year ago

Maybe related with https://github.com/tweag/asterius/issues/97