V8 Project
regexp-stack.h
Go to the documentation of this file.
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 #ifndef V8_REGEXP_STACK_H_
6 #define V8_REGEXP_STACK_H_
7 
8 namespace v8 {
9 namespace internal {
10 
11 class RegExpStack;
12 
13 // Maintains a per-v8thread stack area that can be used by irregexp
14 // implementation for its backtracking stack.
15 // Since there is only one stack area, the Irregexp implementation is not
16 // re-entrant. I.e., no regular expressions may be executed in the same thread
17 // during a preempted Irregexp execution.
19  public:
20  // Create and delete an instance to control the life-time of a growing stack.
21 
22  // Initializes the stack memory area if necessary.
23  explicit RegExpStackScope(Isolate* isolate);
24  ~RegExpStackScope(); // Releases the stack if it has grown.
25 
26  RegExpStack* stack() const { return regexp_stack_; }
27 
28  private:
30 
32 };
33 
34 
35 class RegExpStack {
36  public:
37  // Number of allocated locations on the stack below the limit.
38  // No sequence of pushes must be longer that this without doing a stack-limit
39  // check.
40  static const int kStackLimitSlack = 32;
41 
42  // Gives the top of the memory used as stack.
46  }
47 
48  // The total size of the memory allocated for the stack.
50 
51  // If the stack pointer gets below the limit, we should react and
52  // either grow the stack or report an out-of-stack exception.
53  // There is only a limited number of locations below the stack limit,
54  // so users of the stack should check the stack limit during any
55  // sequence of pushes longer that this.
57 
58  // Ensures that there is a memory area with at least the specified size.
59  // If passing zero, the default/minimum size buffer is allocated.
60  Address EnsureCapacity(size_t size);
61 
62  // Thread local archiving.
63  static int ArchiveSpacePerThread() {
64  return static_cast<int>(sizeof(ThreadLocal));
65  }
66  char* ArchiveStack(char* to);
67  char* RestoreStack(char* from);
69 
70  private:
71  RegExpStack();
72  ~RegExpStack();
73 
74  // Artificial limit used when no memory has been allocated.
75  static const uintptr_t kMemoryTop = static_cast<uintptr_t>(-1);
76 
77  // Minimal size of allocated stack area.
78  static const size_t kMinimumStackSize = 1 * KB;
79 
80  // Maximal size of allocated stack area.
81  static const size_t kMaximumStackSize = 64 * MB;
82 
83  // Structure holding the allocated memory, size and limit.
84  struct ThreadLocal {
85  ThreadLocal() { Clear(); }
86  // If memory_size_ > 0 then memory_ must be non-NULL.
88  size_t memory_size_;
90  void Clear() {
91  memory_ = NULL;
92  memory_size_ = 0;
93  limit_ = reinterpret_cast<Address>(kMemoryTop);
94  }
95  void Free();
96  };
97 
98  // Address of allocated memory.
100  return reinterpret_cast<Address>(&thread_local_.memory_);
101  }
102 
103  // Address of size of allocated memory.
105  return reinterpret_cast<Address>(&thread_local_.memory_size_);
106  }
107 
108  // Resets the buffer if it has grown beyond the default/minimum size.
109  // After this, the buffer is either the default size, or it is empty, so
110  // you have to call EnsureCapacity before using it again.
111  void Reset();
112 
115 
116  friend class ExternalReference;
117  friend class Isolate;
118  friend class RegExpStackScope;
119 
121 };
122 
123 }} // namespace v8::internal
124 
125 #endif // V8_REGEXP_STACK_H_
DISALLOW_COPY_AND_ASSIGN(RegExpStackScope)
RegExpStackScope(Isolate *isolate)
Definition: regexp-stack.cc:12
RegExpStack * stack() const
Definition: regexp-stack.h:26
DISALLOW_COPY_AND_ASSIGN(RegExpStack)
static const int kStackLimitSlack
Definition: regexp-stack.h:40
char * ArchiveStack(char *to)
Definition: regexp-stack.cc:35
friend class ExternalReference
Definition: regexp-stack.h:116
Address EnsureCapacity(size_t size)
Definition: regexp-stack.cc:66
static const uintptr_t kMemoryTop
Definition: regexp-stack.h:75
char * RestoreStack(char *from)
Definition: regexp-stack.cc:43
static const size_t kMaximumStackSize
Definition: regexp-stack.h:81
static const size_t kMinimumStackSize
Definition: regexp-stack.h:78
static int ArchiveSpacePerThread()
Definition: regexp-stack.h:63
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
const int KB
Definition: globals.h:106
byte * Address
Definition: globals.h:101
const int MB
Definition: globals.h:107
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20