OLD | NEW |
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 14 matching lines...) Expand all Loading... |
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 #include "v8.h" | 28 #include "v8.h" |
29 #include "top.h" | 29 #include "top.h" |
30 #include "regexp-stack.h" | 30 #include "regexp-stack.h" |
31 | 31 |
32 namespace v8 { | 32 namespace v8 { |
33 namespace internal { | 33 namespace internal { |
34 | 34 |
| 35 RegExpStackData::RegExpStackData() |
| 36 :thread_local_(), |
| 37 static_offsets_vector_(NULL) { |
| 38 } |
| 39 |
35 RegExpStack::RegExpStack() { | 40 RegExpStack::RegExpStack() { |
36 // Initialize, if not already initialized. | 41 // Initialize, if not already initialized. |
37 RegExpStack::EnsureCapacity(0); | 42 RegExpStack::EnsureCapacity(0); |
38 } | 43 } |
39 | 44 |
40 | 45 |
41 RegExpStack::~RegExpStack() { | 46 RegExpStack::~RegExpStack() { |
42 // Reset the buffer if it has grown. | 47 // Reset the buffer if it has grown. |
43 RegExpStack::Reset(); | 48 RegExpStack::Reset(); |
44 } | 49 } |
45 | 50 |
46 | 51 |
47 char* RegExpStack::ArchiveStack(char* to) { | 52 char* RegExpStack::ArchiveStack(char* to) { |
48 size_t size = sizeof(thread_local_); | 53 RegExpStackData::ThreadLocal & thread_local = v8_context()-> |
| 54 reg_exp_stack_data_.thread_local_; |
| 55 size_t size = sizeof(RegExpStackData::ThreadLocal); |
49 memcpy(reinterpret_cast<void*>(to), | 56 memcpy(reinterpret_cast<void*>(to), |
50 &thread_local_, | 57 &thread_local, |
51 size); | 58 size); |
52 thread_local_ = ThreadLocal(); | 59 thread_local = RegExpStackData::ThreadLocal(); |
53 return to + size; | 60 return to + size; |
54 } | 61 } |
55 | 62 |
56 | 63 |
57 char* RegExpStack::RestoreStack(char* from) { | 64 char* RegExpStack::RestoreStack(char* from) { |
58 size_t size = sizeof(thread_local_); | 65 size_t size = sizeof(RegExpStackData::ThreadLocal); |
59 memcpy(&thread_local_, reinterpret_cast<void*>(from), size); | 66 memcpy(&v8_context()->reg_exp_stack_data_.thread_local_, |
| 67 reinterpret_cast<void*>(from), size); |
60 return from + size; | 68 return from + size; |
61 } | 69 } |
62 | 70 |
63 | 71 |
64 void RegExpStack::Reset() { | 72 void RegExpStack::Reset() { |
65 if (thread_local_.memory_size_ > kMinimumStackSize) { | 73 RegExpStackData::ThreadLocal & thread_local = v8_context()-> |
66 DeleteArray(thread_local_.memory_); | 74 reg_exp_stack_data_.thread_local_; |
67 thread_local_ = ThreadLocal(); | 75 if (thread_local.memory_size_ > kMinimumStackSize) { |
| 76 DeleteArray(thread_local.memory_); |
| 77 thread_local = RegExpStackData::ThreadLocal(); |
68 } | 78 } |
69 } | 79 } |
70 | 80 |
71 | 81 |
72 void RegExpStack::ThreadLocal::Free() { | 82 void RegExpStackData::ThreadLocal::Free() { |
73 if (thread_local_.memory_size_ > 0) { | 83 ThreadLocal & thread_local = v8_context()-> |
74 DeleteArray(thread_local_.memory_); | 84 reg_exp_stack_data_.thread_local_; |
75 thread_local_ = ThreadLocal(); | 85 if (thread_local.memory_size_ > 0) { |
| 86 DeleteArray(thread_local.memory_); |
| 87 thread_local = ThreadLocal(); |
76 } | 88 } |
77 } | 89 } |
78 | 90 |
79 | 91 |
80 Address RegExpStack::EnsureCapacity(size_t size) { | 92 Address RegExpStack::EnsureCapacity(size_t size) { |
81 if (size > kMaximumStackSize) return NULL; | 93 if (size > kMaximumStackSize) return NULL; |
82 if (size < kMinimumStackSize) size = kMinimumStackSize; | 94 if (size < kMinimumStackSize) size = kMinimumStackSize; |
83 if (thread_local_.memory_size_ < size) { | 95 RegExpStackData::ThreadLocal & thread_local = v8_context()-> |
| 96 reg_exp_stack_data_.thread_local_; |
| 97 if (thread_local.memory_size_ < size) { |
84 Address new_memory = NewArray<byte>(static_cast<int>(size)); | 98 Address new_memory = NewArray<byte>(static_cast<int>(size)); |
85 if (thread_local_.memory_size_ > 0) { | 99 if (thread_local.memory_size_ > 0) { |
86 // Copy original memory into top of new memory. | 100 // Copy original memory into top of new memory. |
87 memcpy(reinterpret_cast<void*>( | 101 memcpy(reinterpret_cast<void*>( |
88 new_memory + size - thread_local_.memory_size_), | 102 new_memory + size - thread_local.memory_size_), |
89 reinterpret_cast<void*>(thread_local_.memory_), | 103 reinterpret_cast<void*>(thread_local.memory_), |
90 thread_local_.memory_size_); | 104 thread_local.memory_size_); |
91 DeleteArray(thread_local_.memory_); | 105 DeleteArray(thread_local.memory_); |
92 } | 106 } |
93 thread_local_.memory_ = new_memory; | 107 thread_local.memory_ = new_memory; |
94 thread_local_.memory_size_ = size; | 108 thread_local.memory_size_ = size; |
95 thread_local_.limit_ = new_memory + kStackLimitSlack * kPointerSize; | 109 thread_local.limit_ = new_memory + kStackLimitSlack * kPointerSize; |
96 } | 110 } |
97 return thread_local_.memory_ + thread_local_.memory_size_; | 111 return thread_local.memory_ + thread_local.memory_size_; |
98 } | 112 } |
99 | 113 |
100 | |
101 RegExpStack::ThreadLocal RegExpStack::thread_local_; | |
102 | |
103 }} // namespace v8::internal | 114 }} // namespace v8::internal |
OLD | NEW |