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: 2017-04-26 Functions: 9 9 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      700478 : RegExpStackScope::RegExpStackScope(Isolate* isolate)
      13      700478 :     : regexp_stack_(isolate->regexp_stack()) {
      14             :   // Initialize, if not already initialized.
      15      700478 :   regexp_stack_->EnsureCapacity(0);
      16      700478 : }
      17             : 
      18             : 
      19      700478 : RegExpStackScope::~RegExpStackScope() {
      20             :   // Reset the buffer if it has grown.
      21      700478 :   regexp_stack_->Reset();
      22      700478 : }
      23             : 
      24             : 
      25       60782 : RegExpStack::RegExpStack()
      26       60782 :     : isolate_(NULL) {
      27       60782 : }
      28             : 
      29             : 
      30       59285 : RegExpStack::~RegExpStack() {
      31       59285 :   thread_local_.Free();
      32       59285 : }
      33             : 
      34             : 
      35       22574 : char* RegExpStack::ArchiveStack(char* to) {
      36             :   size_t size = sizeof(thread_local_);
      37       22574 :   MemCopy(reinterpret_cast<void*>(to), &thread_local_, size);
      38       22574 :   thread_local_ = ThreadLocal();
      39       22574 :   return to + size;
      40             : }
      41             : 
      42             : 
      43       22574 : char* RegExpStack::RestoreStack(char* from) {
      44             :   size_t size = sizeof(thread_local_);
      45       22574 :   MemCopy(&thread_local_, reinterpret_cast<void*>(from), size);
      46       22574 :   return from + size;
      47             : }
      48             : 
      49             : 
      50      700478 : void RegExpStack::Reset() {
      51      700478 :   if (thread_local_.memory_size_ > kMinimumStackSize) {
      52         139 :     DeleteArray(thread_local_.memory_);
      53         139 :     thread_local_ = ThreadLocal();
      54             :   }
      55      700478 : }
      56             : 
      57             : 
      58       66148 : void RegExpStack::ThreadLocal::Free() {
      59       66148 :   if (memory_size_ > 0) {
      60        5167 :     DeleteArray(memory_);
      61             :     Clear();
      62             :   }
      63       66148 : }
      64             : 
      65             : 
      66      700983 : Address RegExpStack::EnsureCapacity(size_t size) {
      67      700983 :   if (size > kMaximumStackSize) return NULL;
      68      700976 :   if (size < kMinimumStackSize) size = kMinimumStackSize;
      69      700976 :   if (thread_local_.memory_size_ < size) {
      70        6636 :     Address new_memory = NewArray<byte>(static_cast<int>(size));
      71        6636 :     if (thread_local_.memory_size_ > 0) {
      72             :       // Copy original memory into top of new memory.
      73         498 :       MemCopy(reinterpret_cast<void*>(new_memory + size -
      74         498 :                                       thread_local_.memory_size_),
      75             :               reinterpret_cast<void*>(thread_local_.memory_),
      76         498 :               thread_local_.memory_size_);
      77         498 :       DeleteArray(thread_local_.memory_);
      78             :     }
      79        6636 :     thread_local_.memory_ = new_memory;
      80        6636 :     thread_local_.memory_size_ = size;
      81        6636 :     thread_local_.limit_ = new_memory + kStackLimitSlack * kPointerSize;
      82             :   }
      83      700976 :   return thread_local_.memory_ + thread_local_.memory_size_;
      84             : }
      85             : 
      86             : 
      87             : }  // namespace internal
      88             : }  // namespace v8

Generated by: LCOV version 1.10