Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 27 | |
| 28 #ifndef REGEXP_STACK_H_ | |
| 29 #define REGEXP_STACK_H_ | |
| 30 | |
| 31 namespace v8 { namespace internal { | |
| 32 | |
| 33 // Maintains a per-v8thread stack area that can be used by irregexp | |
| 34 // implementation for its backtracking stack. | |
| 35 // Since there is only one stack area, the Irregexp implementation is not | |
| 36 // re-entrant. I.e., no regular expressions may be executed in the same thread | |
| 37 // during a preempted Irregexp execution. | |
| 38 class RegExpStack { | |
| 39 public: | |
| 40 // Number of allocated locations on the stack below the limit. | |
| 41 // No sequence of pushes must be longer that this without doing a stack-limit | |
| 42 // check. | |
| 43 static const int kStackLimitSlack = 32; | |
| 44 | |
| 45 // Create and delete an instance to control the life-time of a growing stack. | |
| 46 RegExpStack(); // Initializes the stack memory area if necessary. | |
| 47 ~RegExpStack(); // Releases the stack if it has grown. | |
| 48 | |
| 49 // Gives the top of the memory used as stack. | |
| 50 static Address stack_top() { | |
| 51 ASSERT(thread_local_.memory_size_ != 0); | |
| 52 return thread_local_.memory_ + thread_local_.memory_size_; | |
| 53 } | |
| 54 | |
| 55 // The total size of the memory allocated for the stack. | |
| 56 static size_t stack_capacity() { return thread_local_.memory_size_; } | |
| 57 | |
| 58 // If the stack pointer gets below the limit, we should react and | |
| 59 // either grow the stack or report an out-of-stack exception. | |
| 60 // There is only a limited number of locations below the stack limit, | |
| 61 // so users of the stack should check the stack limit during any | |
| 62 // sequence of pushes longer that this. | |
| 63 static Address* limit_address() { | |
| 64 return &(thread_local_.limit_); | |
|
Erik Corry
2009/01/12 11:50:13
This looks like it would all fit on one line.
Lasse Reichstein
2009/01/12 13:03:59
Done.
| |
| 65 } | |
| 66 | |
| 67 // Ensures that there is a memory area with at least the specified size. | |
| 68 // If passing zero, the default/minimum size buffer is allocated. | |
| 69 static Address EnsureCapacity(size_t size); | |
| 70 | |
| 71 // Thread local archiving. | |
| 72 static size_t ArchiveSpacePerThread() { return sizeof(thread_local_); } | |
| 73 static char* ArchiveStack(char* to); | |
| 74 static char* RestoreStack(char* from); | |
| 75 | |
| 76 private: | |
| 77 // Artificial limit used when no memory has been allocated. | |
| 78 static const uint32_t kMemoryTop = 0xffffffff; | |
| 79 | |
| 80 // Minimal size of allocated stack area. | |
| 81 static const size_t kMinimumStackSize = 1 * KB; | |
| 82 | |
| 83 // Maximal size of allocated stack area. | |
| 84 static const size_t kMaximumStackSize = 256 * KB; | |
| 85 | |
| 86 // Structure holding the allocated memory, size and limit. | |
| 87 struct ThreadLocal { | |
| 88 ThreadLocal() | |
| 89 : memory_(NULL), | |
| 90 memory_size_(0), | |
| 91 limit_(reinterpret_cast<Address>(kMemoryTop)) {} | |
| 92 // If memory_size_ > 0 then memory_ must be non-NULL. | |
| 93 Address memory_; | |
| 94 size_t memory_size_; | |
| 95 Address limit_; | |
| 96 }; | |
| 97 | |
| 98 // Resets the buffer if it has grown beyond the default/minimum size. | |
| 99 // After this, the buffer is either the default size, or it is empty, so | |
| 100 // you have to call EnsureCapacity before using it again. | |
| 101 static void Reset(); | |
| 102 | |
| 103 static ThreadLocal thread_local_; | |
| 104 }; | |
| 105 | |
| 106 }} // namespace v8::internal | |
| 107 | |
| 108 #endif /* REGEXP_STACK_H_ */ | |
| OLD | NEW |