override fun maybePerformGc()

in src/main/kotlin/io/bazel/worker/CpuTimeBasedGcScheduler.kt [24:37]


  override fun maybePerformGc() {
    if (!cpuUsageBeforeGc.isZero) {
      val currentCpuTime = cpuTime
      val lastCpuTime = cpuTimeAtLastGc.get()
      // Do GC when enough CPU time has been used, but only if nobody else beat us to it.
      if (currentCpuTime.minus(lastCpuTime).compareTo(cpuUsageBeforeGc) > 0 &&
        cpuTimeAtLastGc.compareAndSet(lastCpuTime, currentCpuTime)
      ) {
        System.gc()
        // Avoid counting GC CPU time against CPU time before next GC.
        cpuTimeAtLastGc.compareAndSet(currentCpuTime, cpuTime)
      }
    }
  }