LCOV - code coverage report
Current view: top level - src/regexp - regexp-stack.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 43 43 100.0 %
Date: 2019-01-20 Functions: 11 11 100.0 %

          Line data    Source code
       1             : // Copyright 2009 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/regexp/regexp-stack.h"
       6             : 
       7             : #include "src/isolate.h"
       8             : 
       9             : namespace v8 {
      10             : namespace internal {
      11             : 
      12      118169 : RegExpStackScope::RegExpStackScope(Isolate* isolate)
      13      118169 :     : regexp_stack_(isolate->regexp_stack()) {
      14             :   // Initialize, if not already initialized.
      15      118169 :   regexp_stack_->EnsureCapacity(0);
      16      118169 : }
      17             : 
      18             : 
      19      118169 : RegExpStackScope::~RegExpStackScope() {
      20             :   // Reset the buffer if it has grown.
      21      118169 :   regexp_stack_->Reset();
      22      118169 : }
      23             : 
      24      125766 : RegExpStack::RegExpStack() : isolate_(nullptr) {}
      25             : 
      26       62868 : RegExpStack::~RegExpStack() {
      27       62868 :   thread_local_.Free();
      28       62868 : }
      29             : 
      30             : 
      31       24256 : char* RegExpStack::ArchiveStack(char* to) {
      32             :   size_t size = sizeof(thread_local_);
      33       24256 :   MemCopy(reinterpret_cast<void*>(to), &thread_local_, size);
      34       24256 :   thread_local_ = ThreadLocal();
      35       24256 :   return to + size;
      36             : }
      37             : 
      38             : 
      39       24256 : char* RegExpStack::RestoreStack(char* from) {
      40             :   size_t size = sizeof(thread_local_);
      41       24256 :   MemCopy(&thread_local_, reinterpret_cast<void*>(from), size);
      42       24256 :   return from + size;
      43             : }
      44             : 
      45             : 
      46      118169 : void RegExpStack::Reset() {
      47      118169 :   if (thread_local_.memory_size_ > kMinimumStackSize) {
      48          88 :     DeleteArray(thread_local_.memory_);
      49          88 :     thread_local_ = ThreadLocal();
      50             :   }
      51      118169 : }
      52             : 
      53             : 
      54       68786 : void RegExpStack::ThreadLocal::Free() {
      55       68786 :   if (memory_size_ > 0) {
      56        5086 :     DeleteArray(memory_);
      57             :     Clear();
      58             :   }
      59       68786 : }
      60             : 
      61             : 
      62      118498 : Address RegExpStack::EnsureCapacity(size_t size) {
      63      118498 :   if (size > kMaximumStackSize) return kNullAddress;
      64      118493 :   if (size < kMinimumStackSize) size = kMinimumStackSize;
      65      118493 :   if (thread_local_.memory_size_ < size) {
      66        5498 :     byte* new_memory = NewArray<byte>(size);
      67        5498 :     if (thread_local_.memory_size_ > 0) {
      68             :       // Copy original memory into top of new memory.
      69         324 :       MemCopy(new_memory + size - thread_local_.memory_size_,
      70         324 :               thread_local_.memory_, thread_local_.memory_size_);
      71         324 :       DeleteArray(thread_local_.memory_);
      72             :     }
      73        5498 :     thread_local_.memory_ = new_memory;
      74        5498 :     thread_local_.memory_size_ = size;
      75        5498 :     thread_local_.limit_ = reinterpret_cast<Address>(new_memory) +
      76        5498 :                            kStackLimitSlack * kSystemPointerSize;
      77             :   }
      78      118493 :   return reinterpret_cast<Address>(thread_local_.memory_) +
      79      118493 :          thread_local_.memory_size_;
      80             : }
      81             : 
      82             : 
      83             : }  // namespace internal
      84      183867 : }  // namespace v8

Generated by: LCOV version 1.10