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