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-02-19 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      111208 : RegExpStackScope::RegExpStackScope(Isolate* isolate)
      13      111208 :     : regexp_stack_(isolate->regexp_stack()) {
      14             :   // Initialize, if not already initialized.
      15      111208 :   regexp_stack_->EnsureCapacity(0);
      16      111208 : }
      17             : 
      18             : 
      19      111208 : RegExpStackScope::~RegExpStackScope() {
      20             :   // Reset the buffer if it has grown.
      21      111208 :   regexp_stack_->Reset();
      22      111208 : }
      23             : 
      24      122096 : RegExpStack::RegExpStack() : isolate_(nullptr) {}
      25             : 
      26       61034 : RegExpStack::~RegExpStack() {
      27       61034 :   thread_local_.Free();
      28       61034 : }
      29             : 
      30             : 
      31       23397 : char* RegExpStack::ArchiveStack(char* to) {
      32             :   size_t size = sizeof(thread_local_);
      33       23397 :   MemCopy(reinterpret_cast<void*>(to), &thread_local_, size);
      34       23397 :   thread_local_ = ThreadLocal();
      35       23397 :   return to + size;
      36             : }
      37             : 
      38             : 
      39       23397 : char* RegExpStack::RestoreStack(char* from) {
      40             :   size_t size = sizeof(thread_local_);
      41       23397 :   MemCopy(&thread_local_, reinterpret_cast<void*>(from), size);
      42       23397 :   return from + size;
      43             : }
      44             : 
      45             : 
      46      111208 : void RegExpStack::Reset() {
      47      111208 :   if (thread_local_.memory_size_ > kMinimumStackSize) {
      48          76 :     DeleteArray(thread_local_.memory_);
      49          76 :     thread_local_ = ThreadLocal();
      50             :   }
      51      111208 : }
      52             : 
      53             : 
      54       66940 : void RegExpStack::ThreadLocal::Free() {
      55       66940 :   if (memory_size_ > 0) {
      56        4085 :     DeleteArray(memory_);
      57             :     Clear();
      58             :   }
      59       66940 : }
      60             : 
      61             : 
      62      111490 : Address RegExpStack::EnsureCapacity(size_t size) {
      63      111490 :   if (size > kMaximumStackSize) return kNullAddress;
      64      111486 :   if (size < kMinimumStackSize) size = kMinimumStackSize;
      65      111486 :   if (thread_local_.memory_size_ < size) {
      66        4439 :     byte* new_memory = NewArray<byte>(size);
      67        4439 :     if (thread_local_.memory_size_ > 0) {
      68             :       // Copy original memory into top of new memory.
      69         278 :       MemCopy(new_memory + size - thread_local_.memory_size_,
      70         278 :               thread_local_.memory_, thread_local_.memory_size_);
      71         278 :       DeleteArray(thread_local_.memory_);
      72             :     }
      73        4439 :     thread_local_.memory_ = new_memory;
      74        4439 :     thread_local_.memory_size_ = size;
      75        4439 :     thread_local_.limit_ = reinterpret_cast<Address>(new_memory) +
      76        4439 :                            kStackLimitSlack * kSystemPointerSize;
      77             :   }
      78      111486 :   return reinterpret_cast<Address>(thread_local_.memory_) +
      79      111486 :          thread_local_.memory_size_;
      80             : }
      81             : 
      82             : 
      83             : }  // namespace internal
      84      178779 : }  // namespace v8

Generated by: LCOV version 1.10