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 30 matching lines...) Expand all Loading... |
41 // Number of allocated locations on the stack below the limit. | 41 // 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 | 42 // No sequence of pushes must be longer that this without doing a stack-limit |
43 // check. | 43 // check. |
44 static const int kStackLimitSlack = 32; | 44 static const int kStackLimitSlack = 32; |
45 | 45 |
46 // Create and delete an instance to control the life-time of a growing stack. | 46 // Create and delete an instance to control the life-time of a growing stack. |
47 RegExpStack(); // Initializes the stack memory area if necessary. | 47 RegExpStack(); // Initializes the stack memory area if necessary. |
48 ~RegExpStack(); // Releases the stack if it has grown. | 48 ~RegExpStack(); // Releases the stack if it has grown. |
49 | 49 |
50 // Gives the top of the memory used as stack. | 50 // Gives the top of the memory used as stack. |
51 static Address stack_top() { | 51 static Address stack_base() { |
52 ASSERT(thread_local_.memory_size_ != 0); | 52 ASSERT(thread_local_.memory_size_ != 0); |
53 return thread_local_.memory_ + thread_local_.memory_size_; | 53 return thread_local_.memory_ + thread_local_.memory_size_; |
54 } | 54 } |
55 | 55 |
56 // The total size of the memory allocated for the stack. | 56 // The total size of the memory allocated for the stack. |
57 static size_t stack_capacity() { return thread_local_.memory_size_; } | 57 static size_t stack_capacity() { return thread_local_.memory_size_; } |
58 | 58 |
59 // If the stack pointer gets below the limit, we should react and | 59 // If the stack pointer gets below the limit, we should react and |
60 // either grow the stack or report an out-of-stack exception. | 60 // either grow the stack or report an out-of-stack exception. |
61 // There is only a limited number of locations below the stack limit, | 61 // 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 | 62 // so users of the stack should check the stack limit during any |
63 // sequence of pushes longer that this. | 63 // sequence of pushes longer that this. |
64 static Address* limit_address() { return &(thread_local_.limit_); } | 64 static Address* limit_address() { return &(thread_local_.limit_); } |
65 | 65 |
66 // Ensures that there is a memory area with at least the specified size. | 66 // Ensures that there is a memory area with at least the specified size. |
67 // If passing zero, the default/minimum size buffer is allocated. | 67 // If passing zero, the default/minimum size buffer is allocated. |
68 static Address EnsureCapacity(size_t size); | 68 static Address EnsureCapacity(size_t size); |
69 | 69 |
70 // Thread local archiving. | 70 // Thread local archiving. |
71 static size_t ArchiveSpacePerThread() { return sizeof(thread_local_); } | 71 static size_t ArchiveSpacePerThread() { return sizeof(thread_local_); } |
72 static char* ArchiveStack(char* to); | 72 static char* ArchiveStack(char* to); |
73 static char* RestoreStack(char* from); | 73 static char* RestoreStack(char* from); |
74 | 74 |
75 private: | 75 private: |
76 // Artificial limit used when no memory has been allocated. | 76 // Artificial limit used when no memory has been allocated. |
77 static const uint32_t kMemoryTop = 0xffffffff; | 77 static const uintptr_t kMemoryTop = -1; |
78 | 78 |
79 // Minimal size of allocated stack area. | 79 // Minimal size of allocated stack area. |
80 static const size_t kMinimumStackSize = 1 * KB; | 80 static const size_t kMinimumStackSize = 1 * KB; |
81 | 81 |
82 // Maximal size of allocated stack area. | 82 // Maximal size of allocated stack area. |
83 static const size_t kMaximumStackSize = 64 * MB; | 83 static const size_t kMaximumStackSize = 64 * MB; |
84 | 84 |
85 // Structure holding the allocated memory, size and limit. | 85 // Structure holding the allocated memory, size and limit. |
86 struct ThreadLocal { | 86 struct ThreadLocal { |
87 ThreadLocal() | 87 ThreadLocal() |
(...skipping 10 matching lines...) Expand all Loading... |
98 // After this, the buffer is either the default size, or it is empty, so | 98 // After this, the buffer is either the default size, or it is empty, so |
99 // you have to call EnsureCapacity before using it again. | 99 // you have to call EnsureCapacity before using it again. |
100 static void Reset(); | 100 static void Reset(); |
101 | 101 |
102 static ThreadLocal thread_local_; | 102 static ThreadLocal thread_local_; |
103 }; | 103 }; |
104 | 104 |
105 }} // namespace v8::internal | 105 }} // namespace v8::internal |
106 | 106 |
107 #endif // V8_REGEXP_STACK_H_ | 107 #endif // V8_REGEXP_STACK_H_ |
OLD | NEW |