LCOV - code coverage report
Current view: top level - src/regexp - regexp-stack.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 40 42 95.2 %
Date: 2019-04-17 Functions: 9 10 90.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      111463 : RegExpStackScope::RegExpStackScope(Isolate* isolate)
      13      111463 :     : regexp_stack_(isolate->regexp_stack()) {
      14             :   // Initialize, if not already initialized.
      15      111463 :   regexp_stack_->EnsureCapacity(0);
      16      111463 : }
      17             : 
      18             : 
      19      222926 : RegExpStackScope::~RegExpStackScope() {
      20             :   // Reset the buffer if it has grown.
      21      111463 :   regexp_stack_->Reset();
      22      111463 : }
      23             : 
      24      124852 : RegExpStack::RegExpStack() : isolate_(nullptr) {}
      25             : 
      26      124822 : RegExpStack::~RegExpStack() {
      27             :   thread_local_.Free();
      28       62411 : }
      29             : 
      30             : 
      31       32453 : char* RegExpStack::ArchiveStack(char* to) {
      32             :   size_t size = sizeof(thread_local_);
      33       32453 :   MemCopy(reinterpret_cast<void*>(to), &thread_local_, size);
      34       32453 :   thread_local_ = ThreadLocal();
      35       32453 :   return to + size;
      36             : }
      37             : 
      38             : 
      39       32453 : char* RegExpStack::RestoreStack(char* from) {
      40             :   size_t size = sizeof(thread_local_);
      41       32453 :   MemCopy(&thread_local_, reinterpret_cast<void*>(from), size);
      42       32453 :   return from + size;
      43             : }
      44             : 
      45             : 
      46           0 : void RegExpStack::Reset() {
      47      111463 :   if (thread_local_.memory_size_ > kMinimumStackSize) {
      48          96 :     DeleteArray(thread_local_.memory_);
      49          96 :     thread_local_ = ThreadLocal();
      50             :   }
      51           0 : }
      52             : 
      53             : 
      54        5918 : void RegExpStack::ThreadLocal::Free() {
      55       68329 :   if (memory_size_ > 0) {
      56        4145 :     DeleteArray(memory_);
      57             :     Clear();
      58             :   }
      59        5918 : }
      60             : 
      61             : 
      62      111813 : Address RegExpStack::EnsureCapacity(size_t size) {
      63      111813 :   if (size > kMaximumStackSize) return kNullAddress;
      64      111809 :   if (size < kMinimumStackSize) size = kMinimumStackSize;
      65      111809 :   if (thread_local_.memory_size_ < size) {
      66        4587 :     byte* new_memory = NewArray<byte>(size);
      67        4587 :     if (thread_local_.memory_size_ > 0) {
      68             :       // Copy original memory into top of new memory.
      69         346 :       MemCopy(new_memory + size - thread_local_.memory_size_,
      70         346 :               thread_local_.memory_, thread_local_.memory_size_);
      71         346 :       DeleteArray(thread_local_.memory_);
      72             :     }
      73        4587 :     thread_local_.memory_ = new_memory;
      74        4587 :     thread_local_.memory_size_ = size;
      75        4587 :     thread_local_.limit_ = reinterpret_cast<Address>(new_memory) +
      76        4587 :                            kStackLimitSlack * kSystemPointerSize;
      77             :   }
      78      111809 :   return reinterpret_cast<Address>(thread_local_.memory_) +
      79      111809 :          thread_local_.memory_size_;
      80             : }
      81             : 
      82             : 
      83             : }  // namespace internal
      84      122004 : }  // namespace v8

Generated by: LCOV version 1.10