debug_go116.go 1.6 KB

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