| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 #ifndef V8_ISOLATE_H_ | 28 #ifndef V8_ISOLATE_H_ |
| 29 #define V8_ISOLATE_H_ | 29 #define V8_ISOLATE_H_ |
| 30 | 30 |
| 31 #include "apiutils.h" | 31 #include "apiutils.h" |
| 32 #include "heap.h" | 32 #include "heap.h" |
| 33 #include "execution.h" |
| 33 #include "zone.h" | 34 #include "zone.h" |
| 34 | 35 |
| 35 namespace v8 { | 36 namespace v8 { |
| 36 namespace internal { | 37 namespace internal { |
| 37 | 38 |
| 38 class Bootstrapper; | 39 class Bootstrapper; |
| 39 class Deserializer; | 40 class Deserializer; |
| 40 class HandleScopeImplementer; | 41 class HandleScopeImplementer; |
| 41 class StubCache; | 42 class StubCache; |
| 42 | 43 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 57 // Returns the single global isolate. | 58 // Returns the single global isolate. |
| 58 static Isolate* Current() { | 59 static Isolate* Current() { |
| 59 ASSERT(global_isolate != NULL); | 60 ASSERT(global_isolate != NULL); |
| 60 return global_isolate; | 61 return global_isolate; |
| 61 } | 62 } |
| 62 | 63 |
| 63 // Creates a new isolate (perhaps using a deserializer). Returns null | 64 // Creates a new isolate (perhaps using a deserializer). Returns null |
| 64 // on failure. | 65 // on failure. |
| 65 static Isolate* Create(Deserializer* des); | 66 static Isolate* Create(Deserializer* des); |
| 66 | 67 |
| 67 // Initialize process-wide state. | |
| 68 static void InitOnce(); | |
| 69 | |
| 70 #define GLOBAL_ACCESSOR(type, name, initialvalue) \ | 68 #define GLOBAL_ACCESSOR(type, name, initialvalue) \ |
| 71 type name() const { return name##_; } \ | 69 type name() const { return name##_; } \ |
| 72 void set_##name(type value) { name##_ = value; } | 70 void set_##name(type value) { name##_ = value; } |
| 73 ISOLATE_INIT_LIST(GLOBAL_ACCESSOR) | 71 ISOLATE_INIT_LIST(GLOBAL_ACCESSOR) |
| 74 #undef GLOBAL_ACCESSOR | 72 #undef GLOBAL_ACCESSOR |
| 75 | 73 |
| 76 #define GLOBAL_ARRAY_ACCESSOR(type, name, length) \ | 74 #define GLOBAL_ARRAY_ACCESSOR(type, name, length) \ |
| 77 type* name() { return &(name##_[0]); } | 75 type* name() { return &(name##_[0]); } |
| 78 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR) | 76 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR) |
| 79 #undef GLOBAL_ARRAY_ACCESSOR | 77 #undef GLOBAL_ARRAY_ACCESSOR |
| 80 | 78 |
| 79 // Debug. |
| 80 // Mutex for serializing access to break control structures. |
| 81 Mutex* break_access() { return break_access_; } |
| 82 |
| 81 // Accessors. | 83 // Accessors. |
| 82 Bootstrapper* bootstrapper() { return bootstrapper_; } | 84 Bootstrapper* bootstrapper() { return bootstrapper_; } |
| 85 StackGuard* stack_guard() { return &stack_guard_; } |
| 83 Heap* heap() { return &heap_; } | 86 Heap* heap() { return &heap_; } |
| 84 StubCache* stub_cache() { return stub_cache_; } | 87 StubCache* stub_cache() { return stub_cache_; } |
| 85 v8::ImplementationUtilities::HandleScopeData* handle_scope_data() { | 88 v8::ImplementationUtilities::HandleScopeData* handle_scope_data() { |
| 86 return &handle_scope_data_; | 89 return &handle_scope_data_; |
| 87 } | 90 } |
| 88 HandleScopeImplementer* handle_scope_implementer() { | 91 HandleScopeImplementer* handle_scope_implementer() { |
| 89 ASSERT(handle_scope_implementer_); | 92 ASSERT(handle_scope_implementer_); |
| 90 return handle_scope_implementer_; | 93 return handle_scope_implementer_; |
| 91 } | 94 } |
| 92 Zone* zone() { return &zone_; } | 95 Zone* zone() { return &zone_; } |
| 93 | 96 |
| 94 // SerializerDeserializer state. | 97 // SerializerDeserializer state. |
| 95 static const int kPartialSnapshotCacheCapacity = 1300; | 98 static const int kPartialSnapshotCacheCapacity = 1300; |
| 96 | 99 |
| 97 static int number_of_isolates() { return number_of_isolates_; } | 100 static int number_of_isolates() { return number_of_isolates_; } |
| 98 | 101 |
| 99 private: | 102 private: |
| 100 Isolate(); | 103 Isolate(); |
| 101 | 104 |
| 102 static Isolate* global_isolate; | 105 static Isolate* global_isolate; |
| 103 // TODO(isolates): Access to this global counter should be serialized. | 106 // TODO(isolates): Access to this global counter should be serialized. |
| 104 static int number_of_isolates_; | 107 static int number_of_isolates_; |
| 105 | 108 |
| 109 // Initialize process-wide state. |
| 110 static void InitOnce(); |
| 111 |
| 112 bool PreInit(); |
| 113 |
| 106 bool Init(Deserializer* des); | 114 bool Init(Deserializer* des); |
| 107 | 115 |
| 108 bool initialized_; | 116 enum State { |
| 117 UNINITIALIZED, // Some components may not have been allocated. |
| 118 PREINITIALIZED, // Components have been allocated but not initialized. |
| 119 INITIALIZED // All components are fully initialized. |
| 120 }; |
| 121 |
| 122 State state_; |
| 109 | 123 |
| 110 Bootstrapper* bootstrapper_; | 124 Bootstrapper* bootstrapper_; |
| 125 Mutex* break_access_; |
| 111 Heap heap_; | 126 Heap heap_; |
| 127 StackGuard stack_guard_; |
| 112 StubCache* stub_cache_; | 128 StubCache* stub_cache_; |
| 113 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; | 129 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; |
| 114 HandleScopeImplementer* handle_scope_implementer_; | 130 HandleScopeImplementer* handle_scope_implementer_; |
| 115 Zone zone_; | 131 Zone zone_; |
| 116 | 132 |
| 117 #define GLOBAL_BACKING_STORE(type, name, initialvalue) \ | 133 #define GLOBAL_BACKING_STORE(type, name, initialvalue) \ |
| 118 type name##_; | 134 type name##_; |
| 119 ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE) | 135 ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE) |
| 120 #undef GLOBAL_BACKING_STORE | 136 #undef GLOBAL_BACKING_STORE |
| 121 | 137 |
| 122 #define GLOBAL_ARRAY_BACKING_STORE(type, name, length) \ | 138 #define GLOBAL_ARRAY_BACKING_STORE(type, name, length) \ |
| 123 type name##_[length]; | 139 type name##_[length]; |
| 124 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE) | 140 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE) |
| 125 #undef GLOBAL_ARRAY_BACKING_STORE | 141 #undef GLOBAL_ARRAY_BACKING_STORE |
| 126 | 142 |
| 143 friend class IsolateInitializer; |
| 144 |
| 127 DISALLOW_COPY_AND_ASSIGN(Isolate); | 145 DISALLOW_COPY_AND_ASSIGN(Isolate); |
| 128 }; | 146 }; |
| 129 | 147 |
| 148 |
| 149 // Support for checking for stack-overflows in C++ code. |
| 150 class StackLimitCheck BASE_EMBEDDED { |
| 151 public: |
| 152 bool HasOverflowed() const { |
| 153 StackGuard* stack_guard = Isolate::Current()->stack_guard(); |
| 154 // Stack has overflowed in C++ code only if stack pointer exceeds the C++ |
| 155 // stack guard and the limits are not set to interrupt values. |
| 156 // TODO(214): Stack overflows are ignored if a interrupt is pending. This |
| 157 // code should probably always use the initial C++ limit. |
| 158 return (reinterpret_cast<uintptr_t>(this) < stack_guard->climit()) && |
| 159 stack_guard->IsStackOverflow(); |
| 160 } |
| 161 }; |
| 162 |
| 163 |
| 164 // Support for temporarily postponing interrupts. When the outermost |
| 165 // postpone scope is left the interrupts will be re-enabled and any |
| 166 // interrupts that occurred while in the scope will be taken into |
| 167 // account. |
| 168 class PostponeInterruptsScope BASE_EMBEDDED { |
| 169 public: |
| 170 PostponeInterruptsScope() { |
| 171 StackGuard* stack_guard = Isolate::Current()->stack_guard(); |
| 172 stack_guard->thread_local_.postpone_interrupts_nesting_++; |
| 173 stack_guard->DisableInterrupts(); |
| 174 } |
| 175 |
| 176 ~PostponeInterruptsScope() { |
| 177 StackGuard* stack_guard = Isolate::Current()->stack_guard(); |
| 178 if (--stack_guard->thread_local_.postpone_interrupts_nesting_ == 0) { |
| 179 stack_guard->EnableInterrupts(); |
| 180 } |
| 181 } |
| 182 }; |
| 183 |
| 184 |
| 130 // Temporary macros for accessing fields off the global isolate. Define these | 185 // Temporary macros for accessing fields off the global isolate. Define these |
| 131 // when reformatting code would become burdensome. | 186 // when reformatting code would become burdensome. |
| 132 #define HEAP (v8::internal::Isolate::Current()->heap()) | 187 #define HEAP (v8::internal::Isolate::Current()->heap()) |
| 133 #define ZONE (v8::internal::Isolate::Current()->zone()) | 188 #define ZONE (v8::internal::Isolate::Current()->zone()) |
| 134 | 189 |
| 135 | 190 |
| 136 // Temporary macro to be used to flag definitions that are indeed static | 191 // Temporary macro to be used to flag definitions that are indeed static |
| 137 // and not per-isolate. (It would be great to be able to grep for [static]!) | 192 // and not per-isolate. (It would be great to be able to grep for [static]!) |
| 138 #define RLYSTC static | 193 #define RLYSTC static |
| 139 | 194 |
| 140 | 195 |
| 141 // Temporary macro to be used to flag classes that should be static. | 196 // Temporary macro to be used to flag classes that should be static. |
| 142 #define STATIC_CLASS class | 197 #define STATIC_CLASS class |
| 143 | 198 |
| 144 | 199 |
| 145 // Temporary macro to be used to flag classes that are completely converted | 200 // Temporary macro to be used to flag classes that are completely converted |
| 146 // to be isolate-friendly. Their mix of static/nonstatic methods/fields is | 201 // to be isolate-friendly. Their mix of static/nonstatic methods/fields is |
| 147 // correct. | 202 // correct. |
| 148 #define ISOLATED_CLASS class | 203 #define ISOLATED_CLASS class |
| 149 | 204 |
| 150 } } // namespace v8::internal | 205 } } // namespace v8::internal |
| 151 | 206 |
| 152 #endif // V8_ISOLATE_H_ | 207 #endif // V8_ISOLATE_H_ |
| OLD | NEW |