diff --git a/service/oomkiller/badcleanup.go b/service/oomkiller/badcleanup.go index 4ba4b0ce..3b42e758 100644 --- a/service/oomkiller/badcleanup.go +++ b/service/oomkiller/badcleanup.go @@ -1,4 +1,4 @@ -//go:build badlinkname +//go:build badlinkname && !goexperiment.jsonv2 package oomkiller @@ -7,13 +7,21 @@ import ( _ "unsafe" ) -//go:linkname jsonFieldCache json.fieldCache +//go:linkname jsonEncoderCache encoding/json.encoderCache +var jsonEncoderCache sync.Map + +//go:linkname jsonFieldCache encoding/json.fieldCache var jsonFieldCache sync.Map +//go:linkname contextJSONEncoderCache github.com/sagernet/sing/common/json/internal/contextjson.encoderCache +var contextJSONEncoderCache sync.Map + //go:linkname contextJSONFieldCache github.com/sagernet/sing/common/json/internal/contextjson.fieldCache var contextJSONFieldCache sync.Map func badCleanup() { + jsonEncoderCache.Clear() jsonFieldCache.Clear() + contextJSONEncoderCache.Clear() contextJSONFieldCache.Clear() } diff --git a/service/oomkiller/badcleanup_jsonv2.go b/service/oomkiller/badcleanup_jsonv2.go new file mode 100644 index 00000000..16d8b10a --- /dev/null +++ b/service/oomkiller/badcleanup_jsonv2.go @@ -0,0 +1,23 @@ +//go:build badlinkname && goexperiment.jsonv2 + +package oomkiller + +import ( + "sync" + _ "unsafe" +) + +//go:linkname jsonArshalerCache encoding/json/v2.lookupArshalerCache +var jsonArshalerCache sync.Map + +//go:linkname contextJSONEncoderCache github.com/sagernet/sing/common/json/internal/contextjson.encoderCache +var contextJSONEncoderCache sync.Map + +//go:linkname contextJSONFieldCache github.com/sagernet/sing/common/json/internal/contextjson.fieldCache +var contextJSONFieldCache sync.Map + +func badCleanup() { + jsonArshalerCache.Clear() + contextJSONEncoderCache.Clear() + contextJSONFieldCache.Clear() +}