Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: src/regexp-stack.h

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/regexp-macro-assembler-irregexp-inl.h ('k') | src/regexp-stack.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_REGEXP_STACK_H_ 28 #ifndef V8_REGEXP_STACK_H_
29 #define V8_REGEXP_STACK_H_ 29 #define V8_REGEXP_STACK_H_
30 30
31 namespace v8 { 31 namespace v8 {
32 namespace internal { 32 namespace internal {
33 33
34 class RegExpStack;
35
34 // Maintains a per-v8thread stack area that can be used by irregexp 36 // Maintains a per-v8thread stack area that can be used by irregexp
35 // implementation for its backtracking stack. 37 // implementation for its backtracking stack.
36 // Since there is only one stack area, the Irregexp implementation is not 38 // Since there is only one stack area, the Irregexp implementation is not
37 // re-entrant. I.e., no regular expressions may be executed in the same thread 39 // re-entrant. I.e., no regular expressions may be executed in the same thread
38 // during a preempted Irregexp execution. 40 // during a preempted Irregexp execution.
41 class RegExpStackScope {
42 public:
43 // Create and delete an instance to control the life-time of a growing stack.
44
45 // Initializes the stack memory area if necessary.
46 explicit RegExpStackScope(Isolate* isolate);
47 ~RegExpStackScope(); // Releases the stack if it has grown.
48
49 RegExpStack* stack() const { return regexp_stack_; }
50
51 private:
52 RegExpStack* regexp_stack_;
53
54 DISALLOW_COPY_AND_ASSIGN(RegExpStackScope);
55 };
56
57
39 class RegExpStack { 58 class RegExpStack {
40 public: 59 public:
41 // Number of allocated locations on the stack below the limit. 60 // Number of allocated locations on the stack below the limit.
42 // No sequence of pushes must be longer that this without doing a stack-limit 61 // No sequence of pushes must be longer that this without doing a stack-limit
43 // check. 62 // check.
44 static const int kStackLimitSlack = 32; 63 static const int kStackLimitSlack = 32;
45 64
46 // Create and delete an instance to control the life-time of a growing stack.
47 RegExpStack(); // Initializes the stack memory area if necessary.
48 ~RegExpStack(); // Releases the stack if it has grown.
49
50 // Gives the top of the memory used as stack. 65 // Gives the top of the memory used as stack.
51 static Address stack_base() { 66 Address stack_base() {
52 ASSERT(thread_local_.memory_size_ != 0); 67 ASSERT(thread_local_.memory_size_ != 0);
53 return thread_local_.memory_ + thread_local_.memory_size_; 68 return thread_local_.memory_ + thread_local_.memory_size_;
54 } 69 }
55 70
56 // The total size of the memory allocated for the stack. 71 // The total size of the memory allocated for the stack.
57 static size_t stack_capacity() { return thread_local_.memory_size_; } 72 size_t stack_capacity() { return thread_local_.memory_size_; }
58 73
59 // If the stack pointer gets below the limit, we should react and 74 // If the stack pointer gets below the limit, we should react and
60 // either grow the stack or report an out-of-stack exception. 75 // either grow the stack or report an out-of-stack exception.
61 // There is only a limited number of locations below the stack limit, 76 // There is only a limited number of locations below the stack limit,
62 // so users of the stack should check the stack limit during any 77 // so users of the stack should check the stack limit during any
63 // sequence of pushes longer that this. 78 // sequence of pushes longer that this.
64 static Address* limit_address() { return &(thread_local_.limit_); } 79 Address* limit_address() { return &(thread_local_.limit_); }
65 80
66 // Ensures that there is a memory area with at least the specified size. 81 // Ensures that there is a memory area with at least the specified size.
67 // If passing zero, the default/minimum size buffer is allocated. 82 // If passing zero, the default/minimum size buffer is allocated.
68 static Address EnsureCapacity(size_t size); 83 Address EnsureCapacity(size_t size);
69 84
70 // Thread local archiving. 85 // Thread local archiving.
71 static int ArchiveSpacePerThread() { 86 static int ArchiveSpacePerThread() {
72 return static_cast<int>(sizeof(thread_local_)); 87 return static_cast<int>(sizeof(ThreadLocal));
73 } 88 }
74 static char* ArchiveStack(char* to); 89 char* ArchiveStack(char* to);
75 static char* RestoreStack(char* from); 90 char* RestoreStack(char* from);
76 static void FreeThreadResources() { thread_local_.Free(); } 91 void FreeThreadResources() { thread_local_.Free(); }
92 private:
93 RegExpStack();
94 ~RegExpStack();
77 95
78 private:
79 // Artificial limit used when no memory has been allocated. 96 // Artificial limit used when no memory has been allocated.
80 static const uintptr_t kMemoryTop = static_cast<uintptr_t>(-1); 97 static const uintptr_t kMemoryTop = static_cast<uintptr_t>(-1);
81 98
82 // Minimal size of allocated stack area. 99 // Minimal size of allocated stack area.
83 static const size_t kMinimumStackSize = 1 * KB; 100 static const size_t kMinimumStackSize = 1 * KB;
84 101
85 // Maximal size of allocated stack area. 102 // Maximal size of allocated stack area.
86 static const size_t kMaximumStackSize = 64 * MB; 103 static const size_t kMaximumStackSize = 64 * MB;
87 104
88 // Structure holding the allocated memory, size and limit. 105 // Structure holding the allocated memory, size and limit.
89 struct ThreadLocal { 106 struct ThreadLocal {
90 ThreadLocal() 107 ThreadLocal() { Clear(); }
91 : memory_(NULL),
92 memory_size_(0),
93 limit_(reinterpret_cast<Address>(kMemoryTop)) {}
94 // If memory_size_ > 0 then memory_ must be non-NULL. 108 // If memory_size_ > 0 then memory_ must be non-NULL.
95 Address memory_; 109 Address memory_;
96 size_t memory_size_; 110 size_t memory_size_;
97 Address limit_; 111 Address limit_;
112 void Clear() {
113 memory_ = NULL;
114 memory_size_ = 0;
115 limit_ = reinterpret_cast<Address>(kMemoryTop);
116 }
98 void Free(); 117 void Free();
99 }; 118 };
100 119
101 // Address of allocated memory. 120 // Address of allocated memory.
102 static Address memory_address() { 121 Address memory_address() {
103 return reinterpret_cast<Address>(&thread_local_.memory_); 122 return reinterpret_cast<Address>(&thread_local_.memory_);
104 } 123 }
105 124
106 // Address of size of allocated memory. 125 // Address of size of allocated memory.
107 static Address memory_size_address() { 126 Address memory_size_address() {
108 return reinterpret_cast<Address>(&thread_local_.memory_size_); 127 return reinterpret_cast<Address>(&thread_local_.memory_size_);
109 } 128 }
110 129
111 // Resets the buffer if it has grown beyond the default/minimum size. 130 // Resets the buffer if it has grown beyond the default/minimum size.
112 // After this, the buffer is either the default size, or it is empty, so 131 // After this, the buffer is either the default size, or it is empty, so
113 // you have to call EnsureCapacity before using it again. 132 // you have to call EnsureCapacity before using it again.
114 static void Reset(); 133 void Reset();
115 134
116 static ThreadLocal thread_local_; 135 ThreadLocal thread_local_;
136 Isolate* isolate_;
117 137
118 friend class ExternalReference; 138 friend class ExternalReference;
139 friend class Isolate;
140 friend class RegExpStackScope;
141
142 DISALLOW_COPY_AND_ASSIGN(RegExpStack);
119 }; 143 };
120 144
121 }} // namespace v8::internal 145 }} // namespace v8::internal
122 146
123 #endif // V8_REGEXP_STACK_H_ 147 #endif // V8_REGEXP_STACK_H_
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler-irregexp-inl.h ('k') | src/regexp-stack.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698