| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 RegExpStack::~RegExpStack() { | 53 RegExpStack::~RegExpStack() { |
| 54 thread_local_.Free(); | 54 thread_local_.Free(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 char* RegExpStack::ArchiveStack(char* to) { | 58 char* RegExpStack::ArchiveStack(char* to) { |
| 59 size_t size = sizeof(thread_local_); | 59 size_t size = sizeof(thread_local_); |
| 60 memcpy(reinterpret_cast<void*>(to), | 60 OS::MemCopy(reinterpret_cast<void*>(to), &thread_local_, size); |
| 61 &thread_local_, | |
| 62 size); | |
| 63 thread_local_ = ThreadLocal(); | 61 thread_local_ = ThreadLocal(); |
| 64 return to + size; | 62 return to + size; |
| 65 } | 63 } |
| 66 | 64 |
| 67 | 65 |
| 68 char* RegExpStack::RestoreStack(char* from) { | 66 char* RegExpStack::RestoreStack(char* from) { |
| 69 size_t size = sizeof(thread_local_); | 67 size_t size = sizeof(thread_local_); |
| 70 memcpy(&thread_local_, reinterpret_cast<void*>(from), size); | 68 OS::MemCopy(&thread_local_, reinterpret_cast<void*>(from), size); |
| 71 return from + size; | 69 return from + size; |
| 72 } | 70 } |
| 73 | 71 |
| 74 | 72 |
| 75 void RegExpStack::Reset() { | 73 void RegExpStack::Reset() { |
| 76 if (thread_local_.memory_size_ > kMinimumStackSize) { | 74 if (thread_local_.memory_size_ > kMinimumStackSize) { |
| 77 DeleteArray(thread_local_.memory_); | 75 DeleteArray(thread_local_.memory_); |
| 78 thread_local_ = ThreadLocal(); | 76 thread_local_ = ThreadLocal(); |
| 79 } | 77 } |
| 80 } | 78 } |
| 81 | 79 |
| 82 | 80 |
| 83 void RegExpStack::ThreadLocal::Free() { | 81 void RegExpStack::ThreadLocal::Free() { |
| 84 if (memory_size_ > 0) { | 82 if (memory_size_ > 0) { |
| 85 DeleteArray(memory_); | 83 DeleteArray(memory_); |
| 86 Clear(); | 84 Clear(); |
| 87 } | 85 } |
| 88 } | 86 } |
| 89 | 87 |
| 90 | 88 |
| 91 Address RegExpStack::EnsureCapacity(size_t size) { | 89 Address RegExpStack::EnsureCapacity(size_t size) { |
| 92 if (size > kMaximumStackSize) return NULL; | 90 if (size > kMaximumStackSize) return NULL; |
| 93 if (size < kMinimumStackSize) size = kMinimumStackSize; | 91 if (size < kMinimumStackSize) size = kMinimumStackSize; |
| 94 if (thread_local_.memory_size_ < size) { | 92 if (thread_local_.memory_size_ < size) { |
| 95 Address new_memory = NewArray<byte>(static_cast<int>(size)); | 93 Address new_memory = NewArray<byte>(static_cast<int>(size)); |
| 96 if (thread_local_.memory_size_ > 0) { | 94 if (thread_local_.memory_size_ > 0) { |
| 97 // Copy original memory into top of new memory. | 95 // Copy original memory into top of new memory. |
| 98 memcpy(reinterpret_cast<void*>( | 96 OS::MemCopy( |
| 99 new_memory + size - thread_local_.memory_size_), | 97 reinterpret_cast<void*>( |
| 100 reinterpret_cast<void*>(thread_local_.memory_), | 98 new_memory + size - thread_local_.memory_size_), |
| 101 thread_local_.memory_size_); | 99 reinterpret_cast<void*>(thread_local_.memory_), |
| 100 thread_local_.memory_size_); |
| 102 DeleteArray(thread_local_.memory_); | 101 DeleteArray(thread_local_.memory_); |
| 103 } | 102 } |
| 104 thread_local_.memory_ = new_memory; | 103 thread_local_.memory_ = new_memory; |
| 105 thread_local_.memory_size_ = size; | 104 thread_local_.memory_size_ = size; |
| 106 thread_local_.limit_ = new_memory + kStackLimitSlack * kPointerSize; | 105 thread_local_.limit_ = new_memory + kStackLimitSlack * kPointerSize; |
| 107 } | 106 } |
| 108 return thread_local_.memory_ + thread_local_.memory_size_; | 107 return thread_local_.memory_ + thread_local_.memory_size_; |
| 109 } | 108 } |
| 110 | 109 |
| 111 | 110 |
| 112 }} // namespace v8::internal | 111 }} // namespace v8::internal |
| OLD | NEW |