github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/internal/encoder/debug_go116.go (about) 1 // +build go1.16,!go1.17 2 3 /* 4 * Copyright 2021 ByteDance Inc. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package encoder 20 21 import ( 22 `os` 23 `strings` 24 `runtime` 25 `runtime/debug` 26 27 `github.com/bytedance/sonic/internal/jit` 28 ) 29 30 var ( 31 debugSyncGC = os.Getenv("SONIC_SYNC_GC") != "" 32 debugAsyncGC = os.Getenv("SONIC_NO_ASYNC_GC") == "" 33 ) 34 35 var ( 36 _Instr_End _Instr = newInsOp(_OP_null) 37 38 _F_gc = jit.Func(runtime.GC) 39 _F_force_gc = jit.Func(debug.FreeOSMemory) 40 _F_println = jit.Func(println_wrapper) 41 ) 42 43 func println_wrapper(i int, op1 int, op2 int){ 44 println(i, " Intrs ", op1, _OpNames[op1], "next: ", op2, _OpNames[op2]) 45 } 46 47 func (self *_Assembler) force_gc() { 48 self.call_go(_F_gc) 49 self.call_go(_F_force_gc) 50 } 51 52 func (self *_Assembler) debug_instr(i int, v *_Instr) { 53 if debugSyncGC { 54 if (i+1 == len(self.p)) { 55 self.print_gc(i, v, &_Instr_End) 56 } else { 57 next := &(self.p[i+1]) 58 self.print_gc(i, v, next) 59 name := _OpNames[next.op()] 60 if strings.Contains(name, "save") { 61 return 62 } 63 } 64 self.force_gc() 65 } 66 }