1 // Copyright 2019 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/codegen/tick-counter.h" 6 7 #include "src/base/logging.h" 8 #include "src/base/macros.h" 9 #include "src/heap/local-heap.h" 10 11 namespace v8 { 12 namespace internal { 13 TickAndMaybeEnterSafepoint()14void TickCounter::TickAndMaybeEnterSafepoint() { 15 ++ticks_; 16 // Magical number to detect performance bugs or compiler divergence. 17 // Selected as being roughly 10x of what's needed frequently. 18 constexpr size_t kMaxTicks = 100000000; 19 USE(kMaxTicks); 20 DCHECK_LT(ticks_, kMaxTicks); 21 22 if (local_heap_) local_heap_->Safepoint(); 23 } 24 AttachLocalHeap(LocalHeap * local_heap)25void TickCounter::AttachLocalHeap(LocalHeap* local_heap) { 26 DCHECK_NULL(local_heap_); 27 local_heap_ = local_heap; 28 DCHECK_NOT_NULL(local_heap_); 29 } 30 DetachLocalHeap()31void TickCounter::DetachLocalHeap() { local_heap_ = nullptr; } 32 33 } // namespace internal 34 } // namespace v8 35