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

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

Issue 435003: Patch for allowing several V8 instances in process:... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years 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.cc ('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 RegExpStackData {
35 public:
36 unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize_;
37 unibrow::Mapping<unibrow::Ecma262UnCanonicalize> uncanonicalize_;
38 unibrow::Mapping<unibrow::CanonicalizationRange> canonrange_;
39 private:
40 // Structure holding the allocated memory, size and limit.
41 // Structure holding the allocated memory, size and limit.
42 struct ThreadLocal {
43 ThreadLocal()
44 : memory_(NULL),
45 memory_size_(0),
46 limit_(reinterpret_cast<Address>(kMemoryTop)) {}
47 // If memory_size_ > 0 then memory_ must be non-NULL.
48 Address memory_;
49 size_t memory_size_;
50 Address limit_;
51 void Free();
52
53 private:
54 ThreadLocal(const ThreadLocal& another);
55 };
56
57 // Artificial limit used when no memory has been allocated.
58 static const uintptr_t kMemoryTop = static_cast<uintptr_t>(-1);
59
60 ThreadLocal thread_local_;
61
62 int* static_offsets_vector_;
63
64 friend class RegExpStack;
65 friend class V8Context;
66 friend class OffsetsVector;
67
68 RegExpStackData();
69 DISALLOW_COPY_AND_ASSIGN(RegExpStackData);
70 };
71
34 // Maintains a per-v8thread stack area that can be used by irregexp 72 // Maintains a per-v8thread stack area that can be used by irregexp
35 // implementation for its backtracking stack. 73 // implementation for its backtracking stack.
36 // Since there is only one stack area, the Irregexp implementation is not 74 // 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 75 // re-entrant. I.e., no regular expressions may be executed in the same thread
38 // during a preempted Irregexp execution. 76 // during a preempted Irregexp execution.
39 class RegExpStack { 77 class RegExpStack {
40 public: 78 public:
41 // Number of allocated locations on the stack below the limit. 79 // 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 80 // No sequence of pushes must be longer that this without doing a stack-limit
43 // check. 81 // check.
44 static const int kStackLimitSlack = 32; 82 static const int kStackLimitSlack = 32;
45 83
46 // Create and delete an instance to control the life-time of a growing stack. 84 // Create and delete an instance to control the life-time of a growing stack.
47 RegExpStack(); // Initializes the stack memory area if necessary. 85 RegExpStack(); // Initializes the stack memory area if necessary.
48 ~RegExpStack(); // Releases the stack if it has grown. 86 ~RegExpStack(); // Releases the stack if it has grown.
49 87
50 // Gives the top of the memory used as stack. 88 // Gives the top of the memory used as stack.
51 static Address stack_base() { 89 static Address stack_base() {
52 ASSERT(thread_local_.memory_size_ != 0); 90 RegExpStackData::ThreadLocal & thread_local = v8_context()->
53 return thread_local_.memory_ + thread_local_.memory_size_; 91 reg_exp_stack_data_.thread_local_;
92 ASSERT(thread_local.memory_size_ != 0);
93 return thread_local.memory_ + thread_local.memory_size_;
54 } 94 }
55 95
56 // The total size of the memory allocated for the stack. 96 // The total size of the memory allocated for the stack.
57 static size_t stack_capacity() { return thread_local_.memory_size_; } 97 static size_t stack_capacity() {
98 return v8_context()->reg_exp_stack_data_.thread_local_.memory_size_;
99 }
58 100
59 // If the stack pointer gets below the limit, we should react and 101 // If the stack pointer gets below the limit, we should react and
60 // either grow the stack or report an out-of-stack exception. 102 // either grow the stack or report an out-of-stack exception.
61 // There is only a limited number of locations below the stack limit, 103 // 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 104 // so users of the stack should check the stack limit during any
63 // sequence of pushes longer that this. 105 // sequence of pushes longer that this.
64 static Address* limit_address() { return &(thread_local_.limit_); } 106 static Address* limit_address() {
107 return &(v8_context()->reg_exp_stack_data_.thread_local_.limit_);
108 }
65 109
66 // Ensures that there is a memory area with at least the specified size. 110 // Ensures that there is a memory area with at least the specified size.
67 // If passing zero, the default/minimum size buffer is allocated. 111 // If passing zero, the default/minimum size buffer is allocated.
68 static Address EnsureCapacity(size_t size); 112 static Address EnsureCapacity(size_t size);
69 113
70 // Thread local archiving. 114 // Thread local archiving.
71 static int ArchiveSpacePerThread() { 115 static int ArchiveSpacePerThread() {
72 return static_cast<int>(sizeof(thread_local_)); 116 return static_cast<int>(sizeof(RegExpStackData::ThreadLocal));
73 } 117 }
74 static char* ArchiveStack(char* to); 118 static char* ArchiveStack(char* to);
75 static char* RestoreStack(char* from); 119 static char* RestoreStack(char* from);
76 static void FreeThreadResources() { thread_local_.Free(); } 120 static void FreeThreadResources() {
121 v8_context()->reg_exp_stack_data_.thread_local_.Free();
122 }
77 123
78 private: 124 private:
79 // Artificial limit used when no memory has been allocated.
80 static const uintptr_t kMemoryTop = static_cast<uintptr_t>(-1);
81 125
82 // Minimal size of allocated stack area. 126 // Minimal size of allocated stack area.
83 static const size_t kMinimumStackSize = 1 * KB; 127 static const size_t kMinimumStackSize = 1 * KB;
84 128
85 // Maximal size of allocated stack area. 129 // Maximal size of allocated stack area.
86 static const size_t kMaximumStackSize = 64 * MB; 130 static const size_t kMaximumStackSize = 64 * MB;
87 131
88 // Structure holding the allocated memory, size and limit.
89 struct ThreadLocal {
90 ThreadLocal()
91 : memory_(NULL),
92 memory_size_(0),
93 limit_(reinterpret_cast<Address>(kMemoryTop)) {}
94 // If memory_size_ > 0 then memory_ must be non-NULL.
95 Address memory_;
96 size_t memory_size_;
97 Address limit_;
98 void Free();
99 };
100
101 // Resets the buffer if it has grown beyond the default/minimum size. 132 // Resets the buffer if it has grown beyond the default/minimum size.
102 // After this, the buffer is either the default size, or it is empty, so 133 // After this, the buffer is either the default size, or it is empty, so
103 // you have to call EnsureCapacity before using it again. 134 // you have to call EnsureCapacity before using it again.
104 static void Reset(); 135 static void Reset();
105
106 static ThreadLocal thread_local_;
107 }; 136 };
108 137
109 }} // namespace v8::internal 138 }} // namespace v8::internal
110 139
111 #endif // V8_REGEXP_STACK_H_ 140 #endif // V8_REGEXP_STACK_H_
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler.cc ('k') | src/regexp-stack.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698