LCOV - code coverage report
Current view: top level - src/heap - slot-set.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 55 55 100.0 %
Date: 2019-01-20 Functions: 12 12 100.0 %

          Line data    Source code
       1             : // Copyright 2018 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/heap/slot-set.h"
       6             : 
       7             : namespace v8 {
       8             : namespace internal {
       9             : 
      10       12109 : TypedSlots::~TypedSlots() {
      11       11285 :   Chunk* chunk = head_;
      12       35150 :   while (chunk != nullptr) {
      13       12580 :     Chunk* next = chunk->next;
      14       12580 :     delete[] chunk->buffer;
      15       12580 :     delete chunk;
      16             :     chunk = next;
      17             :   }
      18       11285 :   head_ = nullptr;
      19       11285 :   tail_ = nullptr;
      20       12109 : }
      21             : 
      22      689061 : void TypedSlots::Insert(SlotType type, uint32_t offset) {
      23      689061 :   TypedSlot slot = {TypeField::encode(type) | OffsetField::encode(offset)};
      24      689061 :   Chunk* chunk = EnsureChunk();
      25             :   DCHECK_LT(chunk->count, chunk->capacity);
      26      689075 :   chunk->buffer[chunk->count] = slot;
      27      689075 :   ++chunk->count;
      28      689075 : }
      29             : 
      30         824 : void TypedSlots::Merge(TypedSlots* other) {
      31         824 :   if (other->head_ == nullptr) {
      32         824 :     return;
      33             :   }
      34         824 :   if (head_ == nullptr) {
      35         464 :     head_ = other->head_;
      36         464 :     tail_ = other->tail_;
      37             :   } else {
      38         360 :     tail_->next = other->head_;
      39         360 :     tail_ = other->tail_;
      40             :   }
      41         824 :   other->head_ = nullptr;
      42         824 :   other->tail_ = nullptr;
      43             : }
      44             : 
      45      689069 : TypedSlots::Chunk* TypedSlots::EnsureChunk() {
      46      689069 :   if (!head_) {
      47       10821 :     head_ = tail_ = NewChunk(nullptr, kInitialBufferSize);
      48             :   }
      49      689069 :   if (head_->count == head_->capacity) {
      50        1759 :     head_ = NewChunk(head_, NextCapacity(head_->capacity));
      51             :   }
      52      689069 :   return head_;
      53             : }
      54             : 
      55       12580 : TypedSlots::Chunk* TypedSlots::NewChunk(Chunk* next, int capacity) {
      56       12580 :   Chunk* chunk = new Chunk;
      57       12580 :   chunk->next = next;
      58       12580 :   chunk->buffer = new TypedSlot[capacity];
      59       12580 :   chunk->capacity = capacity;
      60       12580 :   chunk->count = 0;
      61       12580 :   return chunk;
      62             : }
      63             : 
      64       31379 : TypedSlotSet::~TypedSlotSet() { FreeToBeFreedChunks(); }
      65             : 
      66       11614 : void TypedSlotSet::FreeToBeFreedChunks() {
      67       11614 :   base::MutexGuard guard(&to_be_freed_chunks_mutex_);
      68       11614 :   std::stack<std::unique_ptr<Chunk>> empty;
      69             :   to_be_freed_chunks_.swap(empty);
      70       11614 : }
      71             : 
      72        1258 : void TypedSlotSet::ClearInvalidSlots(
      73             :     const std::map<uint32_t, uint32_t>& invalid_ranges) {
      74             :   Chunk* chunk = LoadHead();
      75        3894 :   while (chunk != nullptr) {
      76        1378 :     TypedSlot* buffer = chunk->buffer;
      77        1378 :     int count = chunk->count;
      78       40806 :     for (int i = 0; i < count; i++) {
      79       39428 :       TypedSlot slot = LoadTypedSlot(buffer + i);
      80             :       SlotType type = TypeField::decode(slot.type_and_offset);
      81       39428 :       if (type == CLEARED_SLOT) continue;
      82       23755 :       uint32_t offset = OffsetField::decode(slot.type_and_offset);
      83             :       std::map<uint32_t, uint32_t>::const_iterator upper_bound =
      84             :           invalid_ranges.upper_bound(offset);
      85       23755 :       if (upper_bound == invalid_ranges.begin()) continue;
      86             :       // upper_bounds points to the invalid range after the given slot. Hence,
      87             :       // we have to go to the previous element.
      88             :       upper_bound--;
      89             :       DCHECK_LE(upper_bound->first, offset);
      90       22398 :       if (upper_bound->second > offset) {
      91             :         ClearTypedSlot(buffer + i);
      92             :       }
      93             :     }
      94             :     chunk = LoadNext(chunk);
      95             :   }
      96        1258 : }
      97             : 
      98             : }  // namespace internal
      99      183867 : }  // namespace v8

Generated by: LCOV version 1.10