diff --git a/internal/engine/compiler/engine.go b/internal/engine/compiler/engine.go index 6f46cb4f79..1c7764c9d5 100644 --- a/internal/engine/compiler/engine.go +++ b/internal/engine/compiler/engine.go @@ -498,9 +498,9 @@ func (s nativeCallStatusCode) String() (ret string) { return } -// releaseCompiledModule is a runtime.SetFinalizer function that munmaps the compiledModule.executable. -func releaseCompiledModule(cm *compiledModule) { - if err := cm.executable.Unmap(); err != nil { +// releaseCompiledCode is a runtime.SetFinalizer function that munmaps the compiledCode.executable. +func releaseCompiledCode(code *compiledCode) { + if err := code.executable.Unmap(); err != nil { // munmap failure cannot recover, and happen asynchronously on the // finalizer thread. While finalizer functions can return errors, // they are ignored. @@ -555,7 +555,7 @@ func (e *engine) CompileModule(_ context.Context, module *wasm.Module, listeners } // As this uses mmap, we need to munmap on the compiled machine code when it's GCed. - e.setFinalizer(cm, releaseCompiledModule) + e.setFinalizer(cm.compiledCode, releaseCompiledCode) ln := len(listeners) cmp := newCompiler() asmNodes := new(asmNodes) diff --git a/internal/engine/compiler/engine_cache.go b/internal/engine/compiler/engine_cache.go index de6a7e3dd0..fe4d998d95 100644 --- a/internal/engine/compiler/engine_cache.go +++ b/internal/engine/compiler/engine_cache.go @@ -51,7 +51,7 @@ func (e *engine) getCompiledModule(module *wasm.Module, listeners []experimental } // As this uses mmap, we need to munmap on the compiled machine code when it's GCed. - e.setFinalizer(cm, releaseCompiledModule) + e.setFinalizer(cm.compiledCode, releaseCompiledCode) } return } diff --git a/internal/engine/compiler/engine_test.go b/internal/engine/compiler/engine_test.go index c68a05865f..5b7daf8dec 100644 --- a/internal/engine/compiler/engine_test.go +++ b/internal/engine/compiler/engine_test.go @@ -26,14 +26,14 @@ func requireSupportedOSArch(t *testing.T) { } } -type fakeFinalizer map[*compiledModule]func(module *compiledModule) +type fakeFinalizer map[*compiledCode]func(code *compiledCode) func (f fakeFinalizer) setFinalizer(obj interface{}, finalizer interface{}) { - cf := obj.(*compiledModule) + cf := obj.(*compiledCode) if _, ok := f[cf]; ok { // easier than adding a field for testing.T panic(fmt.Sprintf("BUG: %v already had its finalizer set", cf)) } - f[cf] = finalizer.(func(*compiledModule)) + f[cf] = finalizer.(func(*compiledCode)) } func TestCompiler_CompileModule(t *testing.T) { @@ -95,10 +95,8 @@ func TestCompiler_CompileModule(t *testing.T) { func TestCompiler_Releasecode_Panic(t *testing.T) { captured := require.CapturePanic(func() { - releaseCompiledModule(&compiledModule{ - compiledCode: &compiledCode{ - executable: makeCodeSegment(1, 2), - }, + releaseCompiledCode(&compiledCode{ + executable: makeCodeSegment(1, 2), }) }) require.Contains(t, captured.Error(), "compiler: failed to munmap code segment")