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