rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 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 V8_ISOLATE_H_ |
| 29 | #define V8_ISOLATE_H_ |
| 30 | |
| 31 | #include "../include/v8-debug.h" |
| 32 | #include "allocation.h" |
| 33 | #include "apiutils.h" |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 34 | #include "assert-scope.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 35 | #include "atomicops.h" |
| 36 | #include "builtins.h" |
| 37 | #include "contexts.h" |
| 38 | #include "execution.h" |
| 39 | #include "frames.h" |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 40 | #include "date.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 41 | #include "global-handles.h" |
| 42 | #include "handles.h" |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 43 | #include "hashmap.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 44 | #include "heap.h" |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 45 | #include "optimizing-compiler-thread.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 46 | #include "regexp-stack.h" |
| 47 | #include "runtime-profiler.h" |
| 48 | #include "runtime.h" |
| 49 | #include "zone.h" |
| 50 | |
| 51 | namespace v8 { |
| 52 | namespace internal { |
| 53 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 54 | class Bootstrapper; |
| 55 | class CodeGenerator; |
| 56 | class CodeRange; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 57 | struct CodeStubInterfaceDescriptor; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 58 | class CompilationCache; |
| 59 | class ContextSlotCache; |
| 60 | class ContextSwitcher; |
| 61 | class Counters; |
| 62 | class CpuFeatures; |
| 63 | class CpuProfiler; |
| 64 | class DeoptimizerData; |
| 65 | class Deserializer; |
| 66 | class EmptyStatement; |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 67 | class ExternalCallbackScope; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 68 | class ExternalReferenceTable; |
| 69 | class Factory; |
| 70 | class FunctionInfoListener; |
| 71 | class HandleScopeImplementer; |
| 72 | class HeapProfiler; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 73 | class HStatistics; |
| 74 | class HTracer; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | class InlineRuntimeFunctionsTable; |
| 76 | class NoAllocationStringAllocator; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 77 | class InnerPointerToCodeCache; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 78 | class PreallocatedMemoryThread; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 79 | class RandomNumberGenerator; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 80 | class RegExpStack; |
| 81 | class SaveContext; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 82 | class UnicodeCache; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 83 | class ConsStringIteratorOp; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 84 | class StringTracker; |
| 85 | class StubCache; |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 86 | class SweeperThread; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 87 | class ThreadManager; |
| 88 | class ThreadState; |
| 89 | class ThreadVisitor; // Defined in v8threads.h |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 90 | template <StateTag Tag> class VMState; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 91 | |
| 92 | // 'void function pointer', used to roundtrip the |
| 93 | // ExternalReference::ExternalReferenceRedirector since we can not include |
| 94 | // assembler.h, where it is defined, here. |
| 95 | typedef void* ExternalReferenceRedirectorPointer(); |
| 96 | |
| 97 | |
| 98 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 99 | class Debug; |
| 100 | class Debugger; |
| 101 | class DebuggerAgent; |
| 102 | #endif |
| 103 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 104 | #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \ |
| 105 | !defined(__mips__) && V8_TARGET_ARCH_MIPS |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 106 | class Redirection; |
| 107 | class Simulator; |
| 108 | #endif |
| 109 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 110 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 111 | // Static indirection table for handles to constants. If a frame |
| 112 | // element represents a constant, the data contains an index into |
| 113 | // this table of handles to the actual constants. |
| 114 | // Static indirection table for handles to constants. If a Result |
| 115 | // represents a constant, the data contains an index into this table |
| 116 | // of handles to the actual constants. |
| 117 | typedef ZoneList<Handle<Object> > ZoneObjectList; |
| 118 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 119 | #define RETURN_IF_SCHEDULED_EXCEPTION(isolate) \ |
| 120 | do { \ |
| 121 | Isolate* __isolate__ = (isolate); \ |
| 122 | if (__isolate__->has_scheduled_exception()) { \ |
| 123 | return __isolate__->PromoteScheduledException(); \ |
| 124 | } \ |
| 125 | } while (false) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 126 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 127 | #define RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, T) \ |
| 128 | do { \ |
| 129 | Isolate* __isolate__ = (isolate); \ |
| 130 | if (__isolate__->has_scheduled_exception()) { \ |
| 131 | __isolate__->PromoteScheduledException(); \ |
| 132 | return Handle<T>::null(); \ |
| 133 | } \ |
| 134 | } while (false) |
| 135 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 136 | #define RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, value) \ |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 137 | do { \ |
| 138 | if ((call).is_null()) { \ |
| 139 | ASSERT((isolate)->has_pending_exception()); \ |
| 140 | return (value); \ |
| 141 | } \ |
| 142 | } while (false) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 143 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 144 | #define CHECK_NOT_EMPTY_HANDLE(isolate, call) \ |
| 145 | do { \ |
| 146 | ASSERT(!(isolate)->has_pending_exception()); \ |
| 147 | CHECK(!(call).is_null()); \ |
| 148 | CHECK(!(isolate)->has_pending_exception()); \ |
| 149 | } while (false) |
| 150 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 151 | #define RETURN_IF_EMPTY_HANDLE(isolate, call) \ |
| 152 | RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, Failure::Exception()) |
| 153 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 154 | #define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \ |
| 155 | C(Handler, handler) \ |
| 156 | C(CEntryFP, c_entry_fp) \ |
| 157 | C(Context, context) \ |
| 158 | C(PendingException, pending_exception) \ |
| 159 | C(ExternalCaughtException, external_caught_exception) \ |
| 160 | C(JSEntrySP, js_entry_sp) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 161 | |
| 162 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 163 | // Platform-independent, reliable thread identifier. |
| 164 | class ThreadId { |
| 165 | public: |
| 166 | // Creates an invalid ThreadId. |
| 167 | ThreadId() : id_(kInvalidId) {} |
| 168 | |
| 169 | // Returns ThreadId for current thread. |
| 170 | static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } |
| 171 | |
| 172 | // Returns invalid ThreadId (guaranteed not to be equal to any thread). |
| 173 | static ThreadId Invalid() { return ThreadId(kInvalidId); } |
| 174 | |
| 175 | // Compares ThreadIds for equality. |
| 176 | INLINE(bool Equals(const ThreadId& other) const) { |
| 177 | return id_ == other.id_; |
| 178 | } |
| 179 | |
| 180 | // Checks whether this ThreadId refers to any thread. |
| 181 | INLINE(bool IsValid() const) { |
| 182 | return id_ != kInvalidId; |
| 183 | } |
| 184 | |
| 185 | // Converts ThreadId to an integer representation |
| 186 | // (required for public API: V8::V8::GetCurrentThreadId). |
| 187 | int ToInteger() const { return id_; } |
| 188 | |
| 189 | // Converts ThreadId to an integer representation |
| 190 | // (required for public API: V8::V8::TerminateExecution). |
| 191 | static ThreadId FromInteger(int id) { return ThreadId(id); } |
| 192 | |
| 193 | private: |
| 194 | static const int kInvalidId = -1; |
| 195 | |
| 196 | explicit ThreadId(int id) : id_(id) {} |
| 197 | |
| 198 | static int AllocateThreadId(); |
| 199 | |
| 200 | static int GetCurrentThreadId(); |
| 201 | |
| 202 | int id_; |
| 203 | |
| 204 | static Atomic32 highest_thread_id_; |
| 205 | |
| 206 | friend class Isolate; |
| 207 | }; |
| 208 | |
| 209 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 210 | class ThreadLocalTop BASE_EMBEDDED { |
| 211 | public: |
vitalyr@chromium.org | 5523ec3 | 2011-04-15 21:42:52 +0000 | [diff] [blame] | 212 | // Does early low-level initialization that does not depend on the |
| 213 | // isolate being present. |
| 214 | ThreadLocalTop(); |
| 215 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 216 | // Initialize the thread data. |
| 217 | void Initialize(); |
| 218 | |
| 219 | // Get the top C++ try catch handler or NULL if none are registered. |
| 220 | // |
| 221 | // This method is not guarenteed to return an address that can be |
| 222 | // used for comparison with addresses into the JS stack. If such an |
| 223 | // address is needed, use try_catch_handler_address. |
| 224 | v8::TryCatch* TryCatchHandler(); |
| 225 | |
| 226 | // Get the address of the top C++ try catch handler or NULL if |
| 227 | // none are registered. |
| 228 | // |
| 229 | // This method always returns an address that can be compared to |
| 230 | // pointers into the JavaScript stack. When running on actual |
| 231 | // hardware, try_catch_handler_address and TryCatchHandler return |
| 232 | // the same pointer. When running on a simulator with a separate JS |
| 233 | // stack, try_catch_handler_address returns a JS stack address that |
| 234 | // corresponds to the place on the JS stack where the C++ handler |
| 235 | // would have been if the stack were not separate. |
| 236 | inline Address try_catch_handler_address() { |
| 237 | return try_catch_handler_address_; |
| 238 | } |
| 239 | |
| 240 | // Set the address of the top C++ try catch handler. |
| 241 | inline void set_try_catch_handler_address(Address address) { |
| 242 | try_catch_handler_address_ = address; |
| 243 | } |
| 244 | |
| 245 | void Free() { |
| 246 | ASSERT(!has_pending_message_); |
| 247 | ASSERT(!external_caught_exception_); |
| 248 | ASSERT(try_catch_handler_address_ == NULL); |
| 249 | } |
| 250 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 251 | Isolate* isolate_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 252 | // The context where the current execution method is created and for variable |
| 253 | // lookups. |
| 254 | Context* context_; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 255 | ThreadId thread_id_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 256 | MaybeObject* pending_exception_; |
| 257 | bool has_pending_message_; |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 258 | bool rethrowing_message_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 259 | Object* pending_message_obj_; |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 260 | Object* pending_message_script_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 261 | int pending_message_start_pos_; |
| 262 | int pending_message_end_pos_; |
| 263 | // Use a separate value for scheduled exceptions to preserve the |
| 264 | // invariants that hold about pending_exception. We may want to |
| 265 | // unify them later. |
| 266 | MaybeObject* scheduled_exception_; |
| 267 | bool external_caught_exception_; |
| 268 | SaveContext* save_context_; |
| 269 | v8::TryCatch* catcher_; |
| 270 | |
| 271 | // Stack. |
| 272 | Address c_entry_fp_; // the frame pointer of the top c entry frame |
| 273 | Address handler_; // try-blocks are chained through the stack |
| 274 | |
| 275 | #ifdef USE_SIMULATOR |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 276 | Simulator* simulator_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 277 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 278 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 279 | Address js_entry_sp_; // the stack pointer of the bottom JS entry frame |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 280 | // the external callback we're currently in |
| 281 | ExternalCallbackScope* external_callback_scope_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 282 | StateTag current_vm_state_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 283 | |
| 284 | // Generated code scratch locations. |
| 285 | int32_t formal_count_; |
| 286 | |
| 287 | // Call back function to report unsafe JS accesses. |
| 288 | v8::FailedAccessCheckCallback failed_access_check_callback_; |
| 289 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 290 | // Head of the list of live LookupResults. |
| 291 | LookupResult* top_lookup_result_; |
| 292 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 293 | // Whether out of memory exceptions should be ignored. |
| 294 | bool ignore_out_of_memory_; |
| 295 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 296 | private: |
vitalyr@chromium.org | 5523ec3 | 2011-04-15 21:42:52 +0000 | [diff] [blame] | 297 | void InitializeInternal(); |
| 298 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 299 | Address try_catch_handler_address_; |
| 300 | }; |
| 301 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 302 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 303 | class SystemThreadManager { |
| 304 | public: |
| 305 | enum ParallelSystemComponent { |
| 306 | PARALLEL_SWEEPING, |
| 307 | CONCURRENT_SWEEPING, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 308 | PARALLEL_RECOMPILATION |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | static int NumberOfParallelSystemThreads(ParallelSystemComponent type); |
| 312 | |
| 313 | static const int kMaxThreads = 4; |
| 314 | }; |
| 315 | |
| 316 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 317 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 318 | |
| 319 | #define ISOLATE_DEBUGGER_INIT_LIST(V) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 320 | V(DebuggerAgent*, debugger_agent_instance, NULL) |
| 321 | #else |
| 322 | |
| 323 | #define ISOLATE_DEBUGGER_INIT_LIST(V) |
| 324 | |
| 325 | #endif |
| 326 | |
| 327 | #ifdef DEBUG |
| 328 | |
| 329 | #define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) \ |
| 330 | V(CommentStatistic, paged_space_comments_statistics, \ |
| 331 | CommentStatistic::kMaxComments + 1) |
| 332 | #else |
| 333 | |
| 334 | #define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) |
| 335 | |
| 336 | #endif |
| 337 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 338 | #define ISOLATE_INIT_ARRAY_LIST(V) \ |
| 339 | /* SerializerDeserializer state. */ \ |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 340 | V(int32_t, jsregexp_static_offsets_vector, kJSRegexpStaticOffsetsVectorSize) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 341 | V(int, bad_char_shift_table, kUC16AlphabetSize) \ |
| 342 | V(int, good_suffix_shift_table, (kBMMaxShift + 1)) \ |
| 343 | V(int, suffix_table, (kBMMaxShift + 1)) \ |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 344 | V(uint32_t, private_random_seed, 2) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 345 | ISOLATE_INIT_DEBUG_ARRAY_LIST(V) |
| 346 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 347 | typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 348 | |
| 349 | #define ISOLATE_INIT_LIST(V) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 350 | /* SerializerDeserializer state. */ \ |
| 351 | V(int, serialize_partial_snapshot_cache_length, 0) \ |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 352 | V(int, serialize_partial_snapshot_cache_capacity, 0) \ |
| 353 | V(Object**, serialize_partial_snapshot_cache, NULL) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 354 | /* Assembler state. */ \ |
| 355 | /* A previously allocated buffer of kMinimalBufferSize bytes, or NULL. */ \ |
| 356 | V(byte*, assembler_spare_buffer, NULL) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 357 | V(FatalErrorCallback, exception_behavior, NULL) \ |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 358 | V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, NULL) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 359 | /* To distinguish the function templates, so that we can find them in the */ \ |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 360 | /* function cache of the native context. */ \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 361 | V(int, next_serial_number, 0) \ |
| 362 | V(ExternalReferenceRedirectorPointer*, external_reference_redirector, NULL) \ |
| 363 | V(bool, always_allow_natives_syntax, false) \ |
| 364 | /* Part of the state of liveedit. */ \ |
| 365 | V(FunctionInfoListener*, active_function_info_listener, NULL) \ |
| 366 | /* State for Relocatable. */ \ |
| 367 | V(Relocatable*, relocatable_top, NULL) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 368 | V(DebugObjectCache*, string_stream_debug_object_cache, NULL) \ |
| 369 | V(Object*, string_stream_current_security_token, NULL) \ |
| 370 | /* TODO(isolates): Release this on destruction? */ \ |
| 371 | V(int*, irregexp_interpreter_backtrack_stack_cache, NULL) \ |
| 372 | /* Serializer state. */ \ |
| 373 | V(ExternalReferenceTable*, external_reference_table, NULL) \ |
| 374 | /* AstNode state. */ \ |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 375 | V(int, ast_node_id, 0) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 376 | V(unsigned, ast_node_count, 0) \ |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 377 | V(bool, observer_delivery_pending, false) \ |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 378 | V(HStatistics*, hstatistics, NULL) \ |
| 379 | V(HTracer*, htracer, NULL) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 380 | ISOLATE_DEBUGGER_INIT_LIST(V) |
| 381 | |
| 382 | class Isolate { |
| 383 | // These forward declarations are required to make the friend declarations in |
| 384 | // PerIsolateThreadData work on some older versions of gcc. |
| 385 | class ThreadDataTable; |
| 386 | class EntryStackItem; |
| 387 | public: |
| 388 | ~Isolate(); |
| 389 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 390 | // A thread has a PerIsolateThreadData instance for each isolate that it has |
| 391 | // entered. That instance is allocated when the isolate is initially entered |
| 392 | // and reused on subsequent entries. |
| 393 | class PerIsolateThreadData { |
| 394 | public: |
| 395 | PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) |
| 396 | : isolate_(isolate), |
| 397 | thread_id_(thread_id), |
| 398 | stack_limit_(0), |
| 399 | thread_state_(NULL), |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 400 | #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \ |
| 401 | !defined(__mips__) && V8_TARGET_ARCH_MIPS |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 402 | simulator_(NULL), |
| 403 | #endif |
| 404 | next_(NULL), |
| 405 | prev_(NULL) { } |
| 406 | Isolate* isolate() const { return isolate_; } |
| 407 | ThreadId thread_id() const { return thread_id_; } |
| 408 | void set_stack_limit(uintptr_t value) { stack_limit_ = value; } |
| 409 | uintptr_t stack_limit() const { return stack_limit_; } |
| 410 | ThreadState* thread_state() const { return thread_state_; } |
| 411 | void set_thread_state(ThreadState* value) { thread_state_ = value; } |
| 412 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 413 | #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \ |
| 414 | !defined(__mips__) && V8_TARGET_ARCH_MIPS |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 415 | Simulator* simulator() const { return simulator_; } |
| 416 | void set_simulator(Simulator* simulator) { |
| 417 | simulator_ = simulator; |
| 418 | } |
| 419 | #endif |
| 420 | |
| 421 | bool Matches(Isolate* isolate, ThreadId thread_id) const { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 422 | return isolate_ == isolate && thread_id_.Equals(thread_id); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | private: |
| 426 | Isolate* isolate_; |
| 427 | ThreadId thread_id_; |
| 428 | uintptr_t stack_limit_; |
| 429 | ThreadState* thread_state_; |
| 430 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 431 | #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \ |
| 432 | !defined(__mips__) && V8_TARGET_ARCH_MIPS |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 433 | Simulator* simulator_; |
| 434 | #endif |
| 435 | |
| 436 | PerIsolateThreadData* next_; |
| 437 | PerIsolateThreadData* prev_; |
| 438 | |
| 439 | friend class Isolate; |
| 440 | friend class ThreadDataTable; |
| 441 | friend class EntryStackItem; |
| 442 | |
| 443 | DISALLOW_COPY_AND_ASSIGN(PerIsolateThreadData); |
| 444 | }; |
| 445 | |
| 446 | |
| 447 | enum AddressId { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 448 | #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, |
| 449 | FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 450 | #undef DECLARE_ENUM |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 451 | kIsolateAddressCount |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | // Returns the PerIsolateThreadData for the current thread (or NULL if one is |
| 455 | // not currently set). |
| 456 | static PerIsolateThreadData* CurrentPerIsolateThreadData() { |
| 457 | return reinterpret_cast<PerIsolateThreadData*>( |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 458 | Thread::GetThreadLocal(per_isolate_thread_data_key_)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | // Returns the isolate inside which the current thread is running. |
| 462 | INLINE(static Isolate* Current()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 463 | Isolate* isolate = reinterpret_cast<Isolate*>( |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 464 | Thread::GetExistingThreadLocal(isolate_key_)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 465 | ASSERT(isolate != NULL); |
| 466 | return isolate; |
| 467 | } |
| 468 | |
| 469 | INLINE(static Isolate* UncheckedCurrent()) { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 470 | return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key_)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 471 | } |
| 472 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 473 | // Usually called by Init(), but can be called early e.g. to allow |
| 474 | // testing components that require logging but not the whole |
| 475 | // isolate. |
| 476 | // |
| 477 | // Safe to call more than once. |
| 478 | void InitializeLoggingAndCounters(); |
| 479 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 480 | bool Init(Deserializer* des); |
| 481 | |
| 482 | bool IsInitialized() { return state_ == INITIALIZED; } |
| 483 | |
| 484 | // True if at least one thread Enter'ed this isolate. |
| 485 | bool IsInUse() { return entry_stack_ != NULL; } |
| 486 | |
| 487 | // Destroys the non-default isolates. |
| 488 | // Sets default isolate into "has_been_disposed" state rather then destroying, |
| 489 | // for legacy API reasons. |
| 490 | void TearDown(); |
| 491 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 492 | static void GlobalTearDown(); |
| 493 | |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 494 | bool IsDefaultIsolate() const { return this == default_isolate_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 495 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 496 | static void SetCrashIfDefaultIsolateInitialized(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 497 | // Ensures that process-wide resources and the default isolate have been |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 498 | // allocated. It is only necessary to call this method in rare cases, for |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 499 | // example if you are using V8 from within the body of a static initializer. |
| 500 | // Safe to call multiple times. |
| 501 | static void EnsureDefaultIsolate(); |
| 502 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 503 | // Find the PerThread for this particular (isolate, thread) combination |
| 504 | // If one does not yet exist, return null. |
| 505 | PerIsolateThreadData* FindPerThreadDataForThisThread(); |
| 506 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 507 | // Find the PerThread for given (isolate, thread) combination |
| 508 | // If one does not yet exist, return null. |
| 509 | PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id); |
| 510 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 511 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 512 | // Get the debugger from the default isolate. Preinitializes the |
| 513 | // default isolate if needed. |
| 514 | static Debugger* GetDefaultIsolateDebugger(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 515 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 516 | |
| 517 | // Get the stack guard from the default isolate. Preinitializes the |
| 518 | // default isolate if needed. |
| 519 | static StackGuard* GetDefaultIsolateStackGuard(); |
| 520 | |
| 521 | // Returns the key used to store the pointer to the current isolate. |
| 522 | // Used internally for V8 threads that do not execute JavaScript but still |
| 523 | // are part of the domain of an isolate (like the context switcher). |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 524 | static Thread::LocalStorageKey isolate_key() { |
| 525 | return isolate_key_; |
| 526 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 527 | |
| 528 | // Returns the key used to store process-wide thread IDs. |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 529 | static Thread::LocalStorageKey thread_id_key() { |
| 530 | return thread_id_key_; |
| 531 | } |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 532 | |
| 533 | static Thread::LocalStorageKey per_isolate_thread_data_key(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 534 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 535 | // If a client attempts to create a Locker without specifying an isolate, |
| 536 | // we assume that the client is using legacy behavior. Set up the current |
| 537 | // thread to be inside the implicit isolate (or fail a check if we have |
| 538 | // switched to non-legacy behavior). |
| 539 | static void EnterDefaultIsolate(); |
| 540 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 541 | // Mutex for serializing access to break control structures. |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 542 | RecursiveMutex* break_access() { return &break_access_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 543 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 544 | // Mutex for serializing access to debugger. |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 545 | RecursiveMutex* debugger_access() { return &debugger_access_; } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 546 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 547 | Address get_address_from_id(AddressId id); |
| 548 | |
| 549 | // Access to top context (where the current function object was created). |
| 550 | Context* context() { return thread_local_top_.context_; } |
| 551 | void set_context(Context* context) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 552 | ASSERT(context == NULL || context->IsContext()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 553 | thread_local_top_.context_ = context; |
| 554 | } |
| 555 | Context** context_address() { return &thread_local_top_.context_; } |
| 556 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 557 | SaveContext* save_context() { return thread_local_top_.save_context_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 558 | void set_save_context(SaveContext* save) { |
| 559 | thread_local_top_.save_context_ = save; |
| 560 | } |
| 561 | |
| 562 | // Access to current thread id. |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 563 | ThreadId thread_id() { return thread_local_top_.thread_id_; } |
| 564 | void set_thread_id(ThreadId id) { thread_local_top_.thread_id_ = id; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 565 | |
| 566 | // Interface to pending exception. |
| 567 | MaybeObject* pending_exception() { |
| 568 | ASSERT(has_pending_exception()); |
| 569 | return thread_local_top_.pending_exception_; |
| 570 | } |
| 571 | bool external_caught_exception() { |
| 572 | return thread_local_top_.external_caught_exception_; |
| 573 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 574 | void set_external_caught_exception(bool value) { |
| 575 | thread_local_top_.external_caught_exception_ = value; |
| 576 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 577 | void set_pending_exception(MaybeObject* exception) { |
| 578 | thread_local_top_.pending_exception_ = exception; |
| 579 | } |
| 580 | void clear_pending_exception() { |
| 581 | thread_local_top_.pending_exception_ = heap_.the_hole_value(); |
| 582 | } |
| 583 | MaybeObject** pending_exception_address() { |
| 584 | return &thread_local_top_.pending_exception_; |
| 585 | } |
| 586 | bool has_pending_exception() { |
| 587 | return !thread_local_top_.pending_exception_->IsTheHole(); |
| 588 | } |
| 589 | void clear_pending_message() { |
| 590 | thread_local_top_.has_pending_message_ = false; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 591 | thread_local_top_.pending_message_obj_ = heap_.the_hole_value(); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 592 | thread_local_top_.pending_message_script_ = heap_.the_hole_value(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 593 | } |
| 594 | v8::TryCatch* try_catch_handler() { |
| 595 | return thread_local_top_.TryCatchHandler(); |
| 596 | } |
| 597 | Address try_catch_handler_address() { |
| 598 | return thread_local_top_.try_catch_handler_address(); |
| 599 | } |
| 600 | bool* external_caught_exception_address() { |
| 601 | return &thread_local_top_.external_caught_exception_; |
| 602 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 603 | v8::TryCatch* catcher() { |
| 604 | return thread_local_top_.catcher_; |
| 605 | } |
| 606 | void set_catcher(v8::TryCatch* catcher) { |
| 607 | thread_local_top_.catcher_ = catcher; |
| 608 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 609 | |
| 610 | MaybeObject** scheduled_exception_address() { |
| 611 | return &thread_local_top_.scheduled_exception_; |
| 612 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 613 | |
| 614 | Address pending_message_obj_address() { |
| 615 | return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_); |
| 616 | } |
| 617 | |
| 618 | Address has_pending_message_address() { |
| 619 | return reinterpret_cast<Address>(&thread_local_top_.has_pending_message_); |
| 620 | } |
| 621 | |
| 622 | Address pending_message_script_address() { |
| 623 | return reinterpret_cast<Address>( |
| 624 | &thread_local_top_.pending_message_script_); |
| 625 | } |
| 626 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 627 | MaybeObject* scheduled_exception() { |
| 628 | ASSERT(has_scheduled_exception()); |
| 629 | return thread_local_top_.scheduled_exception_; |
| 630 | } |
| 631 | bool has_scheduled_exception() { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 632 | return thread_local_top_.scheduled_exception_ != heap_.the_hole_value(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 633 | } |
| 634 | void clear_scheduled_exception() { |
| 635 | thread_local_top_.scheduled_exception_ = heap_.the_hole_value(); |
| 636 | } |
| 637 | |
| 638 | bool IsExternallyCaught(); |
| 639 | |
| 640 | bool is_catchable_by_javascript(MaybeObject* exception) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 641 | return (!exception->IsOutOfMemory()) && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 642 | (exception != heap()->termination_exception()); |
| 643 | } |
| 644 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 645 | // Serializer. |
| 646 | void PushToPartialSnapshotCache(Object* obj); |
| 647 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 648 | // JS execution stack (see frames.h). |
| 649 | static Address c_entry_fp(ThreadLocalTop* thread) { |
| 650 | return thread->c_entry_fp_; |
| 651 | } |
| 652 | static Address handler(ThreadLocalTop* thread) { return thread->handler_; } |
| 653 | |
| 654 | inline Address* c_entry_fp_address() { |
| 655 | return &thread_local_top_.c_entry_fp_; |
| 656 | } |
| 657 | inline Address* handler_address() { return &thread_local_top_.handler_; } |
| 658 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 659 | // Bottom JS entry. |
| 660 | Address js_entry_sp() { |
| 661 | return thread_local_top_.js_entry_sp_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 662 | } |
| 663 | inline Address* js_entry_sp_address() { |
| 664 | return &thread_local_top_.js_entry_sp_; |
| 665 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 666 | |
| 667 | // Generated code scratch locations. |
| 668 | void* formal_count_address() { return &thread_local_top_.formal_count_; } |
| 669 | |
| 670 | // Returns the global object of the current context. It could be |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 671 | // a builtin object, or a JS global object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 672 | Handle<GlobalObject> global_object() { |
| 673 | return Handle<GlobalObject>(context()->global_object()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | // Returns the global proxy object of the current context. |
| 677 | Object* global_proxy() { |
| 678 | return context()->global_proxy(); |
| 679 | } |
| 680 | |
| 681 | Handle<JSBuiltinsObject> js_builtins_object() { |
| 682 | return Handle<JSBuiltinsObject>(thread_local_top_.context_->builtins()); |
| 683 | } |
| 684 | |
| 685 | static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); } |
| 686 | void FreeThreadResources() { thread_local_top_.Free(); } |
| 687 | |
| 688 | // This method is called by the api after operations that may throw |
| 689 | // exceptions. If an exception was thrown and not handled by an external |
| 690 | // handler the exception is scheduled to be rethrown when we return to running |
| 691 | // JavaScript code. If an exception is scheduled true is returned. |
| 692 | bool OptionalRescheduleException(bool is_bottom_call); |
| 693 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 694 | class ExceptionScope { |
| 695 | public: |
| 696 | explicit ExceptionScope(Isolate* isolate) : |
| 697 | // Scope currently can only be used for regular exceptions, not |
| 698 | // failures like OOM or termination exception. |
| 699 | isolate_(isolate), |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 700 | pending_exception_(isolate_->pending_exception()->ToObjectUnchecked(), |
| 701 | isolate_), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 702 | catcher_(isolate_->catcher()) |
| 703 | { } |
| 704 | |
| 705 | ~ExceptionScope() { |
| 706 | isolate_->set_catcher(catcher_); |
| 707 | isolate_->set_pending_exception(*pending_exception_); |
| 708 | } |
| 709 | |
| 710 | private: |
| 711 | Isolate* isolate_; |
| 712 | Handle<Object> pending_exception_; |
| 713 | v8::TryCatch* catcher_; |
| 714 | }; |
| 715 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 716 | void SetCaptureStackTraceForUncaughtExceptions( |
| 717 | bool capture, |
| 718 | int frame_limit, |
| 719 | StackTrace::StackTraceOptions options); |
| 720 | |
| 721 | // Tells whether the current context has experienced an out of memory |
| 722 | // exception. |
| 723 | bool is_out_of_memory(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 724 | bool ignore_out_of_memory() { |
| 725 | return thread_local_top_.ignore_out_of_memory_; |
| 726 | } |
| 727 | void set_ignore_out_of_memory(bool value) { |
| 728 | thread_local_top_.ignore_out_of_memory_ = value; |
| 729 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 730 | |
| 731 | void PrintCurrentStackTrace(FILE* out); |
| 732 | void PrintStackTrace(FILE* out, char* thread_data); |
| 733 | void PrintStack(StringStream* accumulator); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 734 | void PrintStack(FILE* out); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 735 | void PrintStack(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 736 | Handle<String> StackTraceString(); |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 737 | NO_INLINE(void PushStackTraceAndDie(unsigned int magic, |
| 738 | Object* object, |
| 739 | Map* map, |
| 740 | unsigned int magic2)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 741 | Handle<JSArray> CaptureCurrentStackTrace( |
| 742 | int frame_limit, |
| 743 | StackTrace::StackTraceOptions options); |
| 744 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 745 | Handle<JSArray> CaptureSimpleStackTrace(Handle<JSObject> error_object, |
| 746 | Handle<Object> caller, |
| 747 | int limit); |
| 748 | void CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object); |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 749 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 750 | // Returns if the top context may access the given global object. If |
| 751 | // the result is false, the pending exception is guaranteed to be |
| 752 | // set. |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 753 | |
| 754 | // TODO(yangguo): temporary wrappers |
| 755 | bool MayNamedAccessWrapper(Handle<JSObject> receiver, |
| 756 | Handle<Object> key, |
| 757 | v8::AccessType type) { |
| 758 | return MayNamedAccess(*receiver, *key, type); |
| 759 | } |
| 760 | bool MayIndexedAccessWrapper(Handle<JSObject> receiver, |
| 761 | uint32_t index, |
| 762 | v8::AccessType type) { |
| 763 | return MayIndexedAccess(*receiver, index, type); |
| 764 | } |
| 765 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 766 | bool MayNamedAccess(JSObject* receiver, |
| 767 | Object* key, |
| 768 | v8::AccessType type); |
| 769 | bool MayIndexedAccess(JSObject* receiver, |
| 770 | uint32_t index, |
| 771 | v8::AccessType type); |
| 772 | |
| 773 | void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback); |
| 774 | void ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type); |
| 775 | |
| 776 | // Exception throwing support. The caller should use the result |
| 777 | // of Throw() as its return value. |
| 778 | Failure* Throw(Object* exception, MessageLocation* location = NULL); |
| 779 | // Re-throw an exception. This involves no error reporting since |
| 780 | // error reporting was handled when the exception was thrown |
| 781 | // originally. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 782 | Failure* ReThrow(MaybeObject* exception); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 783 | void ScheduleThrow(Object* exception); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 784 | // Re-set pending message, script and positions reported to the TryCatch |
| 785 | // back to the TLS for re-use when rethrowing. |
| 786 | void RestorePendingMessageFromTryCatch(v8::TryCatch* handler); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 787 | void ReportPendingMessages(); |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 788 | // Return pending location if any or unfilled structure. |
| 789 | MessageLocation GetMessageLocation(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 790 | Failure* ThrowIllegalOperation(); |
| 791 | |
| 792 | // Promote a scheduled exception to pending. Asserts has_scheduled_exception. |
| 793 | Failure* PromoteScheduledException(); |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 794 | void DoThrow(Object* exception, MessageLocation* location); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 795 | // Checks if exception should be reported and finds out if it's |
| 796 | // caught externally. |
| 797 | bool ShouldReportException(bool* can_be_caught_externally, |
| 798 | bool catchable_by_javascript); |
| 799 | |
| 800 | // Attempts to compute the current source location, storing the |
| 801 | // result in the target out parameter. |
| 802 | void ComputeLocation(MessageLocation* target); |
| 803 | |
| 804 | // Override command line flag. |
| 805 | void TraceException(bool flag); |
| 806 | |
| 807 | // Out of resource exception helpers. |
| 808 | Failure* StackOverflow(); |
| 809 | Failure* TerminateExecution(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 810 | void CancelTerminateExecution(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 811 | |
| 812 | // Administration |
| 813 | void Iterate(ObjectVisitor* v); |
| 814 | void Iterate(ObjectVisitor* v, ThreadLocalTop* t); |
| 815 | char* Iterate(ObjectVisitor* v, char* t); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 816 | void IterateThread(ThreadVisitor* v, char* t); |
| 817 | |
| 818 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 819 | // Returns the current native and global context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 820 | Handle<Context> native_context(); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 821 | Handle<Context> global_context(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 822 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 823 | // Returns the native context of the calling JavaScript code. That |
| 824 | // is, the native context of the top-most JavaScript frame. |
| 825 | Handle<Context> GetCallingNativeContext(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 826 | |
| 827 | void RegisterTryCatchHandler(v8::TryCatch* that); |
| 828 | void UnregisterTryCatchHandler(v8::TryCatch* that); |
| 829 | |
| 830 | char* ArchiveThread(char* to); |
| 831 | char* RestoreThread(char* from); |
| 832 | |
| 833 | static const char* const kStackOverflowMessage; |
| 834 | |
| 835 | static const int kUC16AlphabetSize = 256; // See StringSearchBase. |
| 836 | static const int kBMMaxShift = 250; // See StringSearchBase. |
| 837 | |
| 838 | // Accessors. |
| 839 | #define GLOBAL_ACCESSOR(type, name, initialvalue) \ |
| 840 | inline type name() const { \ |
| 841 | ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \ |
| 842 | return name##_; \ |
| 843 | } \ |
| 844 | inline void set_##name(type value) { \ |
| 845 | ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \ |
| 846 | name##_ = value; \ |
| 847 | } |
| 848 | ISOLATE_INIT_LIST(GLOBAL_ACCESSOR) |
| 849 | #undef GLOBAL_ACCESSOR |
| 850 | |
| 851 | #define GLOBAL_ARRAY_ACCESSOR(type, name, length) \ |
| 852 | inline type* name() { \ |
| 853 | ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \ |
| 854 | return &(name##_)[0]; \ |
| 855 | } |
| 856 | ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR) |
| 857 | #undef GLOBAL_ARRAY_ACCESSOR |
| 858 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 859 | #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \ |
| 860 | Handle<type> name() { \ |
| 861 | return Handle<type>(context()->native_context()->name(), this); \ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 862 | } \ |
| 863 | bool is_##name(type* value) { \ |
| 864 | return context()->native_context()->is_##name(value); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 865 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 866 | NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR) |
| 867 | #undef NATIVE_CONTEXT_FIELD_ACCESSOR |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 868 | |
| 869 | Bootstrapper* bootstrapper() { return bootstrapper_; } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 870 | Counters* counters() { |
| 871 | // Call InitializeLoggingAndCounters() if logging is needed before |
| 872 | // the isolate is fully initialized. |
| 873 | ASSERT(counters_ != NULL); |
| 874 | return counters_; |
| 875 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 876 | CodeRange* code_range() { return code_range_; } |
| 877 | RuntimeProfiler* runtime_profiler() { return runtime_profiler_; } |
| 878 | CompilationCache* compilation_cache() { return compilation_cache_; } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 879 | Logger* logger() { |
| 880 | // Call InitializeLoggingAndCounters() if logging is needed before |
| 881 | // the isolate is fully initialized. |
| 882 | ASSERT(logger_ != NULL); |
| 883 | return logger_; |
| 884 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 885 | StackGuard* stack_guard() { return &stack_guard_; } |
| 886 | Heap* heap() { return &heap_; } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 887 | StatsTable* stats_table(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 888 | StubCache* stub_cache() { return stub_cache_; } |
| 889 | DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; } |
| 890 | ThreadLocalTop* thread_local_top() { return &thread_local_top_; } |
| 891 | |
| 892 | TranscendentalCache* transcendental_cache() const { |
| 893 | return transcendental_cache_; |
| 894 | } |
| 895 | |
| 896 | MemoryAllocator* memory_allocator() { |
| 897 | return memory_allocator_; |
| 898 | } |
| 899 | |
| 900 | KeyedLookupCache* keyed_lookup_cache() { |
| 901 | return keyed_lookup_cache_; |
| 902 | } |
| 903 | |
| 904 | ContextSlotCache* context_slot_cache() { |
| 905 | return context_slot_cache_; |
| 906 | } |
| 907 | |
| 908 | DescriptorLookupCache* descriptor_lookup_cache() { |
| 909 | return descriptor_lookup_cache_; |
| 910 | } |
| 911 | |
| 912 | v8::ImplementationUtilities::HandleScopeData* handle_scope_data() { |
| 913 | return &handle_scope_data_; |
| 914 | } |
| 915 | HandleScopeImplementer* handle_scope_implementer() { |
| 916 | ASSERT(handle_scope_implementer_); |
| 917 | return handle_scope_implementer_; |
| 918 | } |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 919 | Zone* runtime_zone() { return &runtime_zone_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 920 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 921 | UnicodeCache* unicode_cache() { |
| 922 | return unicode_cache_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 923 | } |
| 924 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 925 | InnerPointerToCodeCache* inner_pointer_to_code_cache() { |
| 926 | return inner_pointer_to_code_cache_; |
| 927 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 928 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 929 | ConsStringIteratorOp* write_iterator() { return write_iterator_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 930 | |
| 931 | GlobalHandles* global_handles() { return global_handles_; } |
| 932 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 933 | EternalHandles* eternal_handles() { return eternal_handles_; } |
| 934 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 935 | ThreadManager* thread_manager() { return thread_manager_; } |
| 936 | |
| 937 | ContextSwitcher* context_switcher() { return context_switcher_; } |
| 938 | |
| 939 | void set_context_switcher(ContextSwitcher* switcher) { |
| 940 | context_switcher_ = switcher; |
| 941 | } |
| 942 | |
| 943 | StringTracker* string_tracker() { return string_tracker_; } |
| 944 | |
| 945 | unibrow::Mapping<unibrow::Ecma262UnCanonicalize>* jsregexp_uncanonicalize() { |
| 946 | return &jsregexp_uncanonicalize_; |
| 947 | } |
| 948 | |
| 949 | unibrow::Mapping<unibrow::CanonicalizationRange>* jsregexp_canonrange() { |
| 950 | return &jsregexp_canonrange_; |
| 951 | } |
| 952 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 953 | ConsStringIteratorOp* objects_string_compare_iterator_a() { |
| 954 | return &objects_string_compare_iterator_a_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 955 | } |
| 956 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 957 | ConsStringIteratorOp* objects_string_compare_iterator_b() { |
| 958 | return &objects_string_compare_iterator_b_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 959 | } |
| 960 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 961 | StaticResource<ConsStringIteratorOp>* objects_string_iterator() { |
| 962 | return &objects_string_iterator_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 963 | } |
| 964 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 965 | RuntimeState* runtime_state() { return &runtime_state_; } |
| 966 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 967 | void set_fp_stubs_generated(bool value) { |
| 968 | fp_stubs_generated_ = value; |
| 969 | } |
| 970 | |
| 971 | bool fp_stubs_generated() { return fp_stubs_generated_; } |
| 972 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 973 | Builtins* builtins() { return &builtins_; } |
| 974 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 975 | void NotifyExtensionInstalled() { |
| 976 | has_installed_extensions_ = true; |
| 977 | } |
| 978 | |
| 979 | bool has_installed_extensions() { return has_installed_extensions_; } |
| 980 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 981 | unibrow::Mapping<unibrow::Ecma262Canonicalize>* |
| 982 | regexp_macro_assembler_canonicalize() { |
| 983 | return ®exp_macro_assembler_canonicalize_; |
| 984 | } |
| 985 | |
| 986 | RegExpStack* regexp_stack() { return regexp_stack_; } |
| 987 | |
| 988 | unibrow::Mapping<unibrow::Ecma262Canonicalize>* |
| 989 | interp_canonicalize_mapping() { |
| 990 | return &interp_canonicalize_mapping_; |
| 991 | } |
| 992 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 993 | void* PreallocatedStorageNew(size_t size); |
| 994 | void PreallocatedStorageDelete(void* p); |
| 995 | void PreallocatedStorageInit(size_t size); |
| 996 | |
| 997 | #ifdef ENABLE_DEBUGGER_SUPPORT |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 998 | Debugger* debugger() { |
| 999 | if (!NoBarrier_Load(&debugger_initialized_)) InitializeDebugger(); |
| 1000 | return debugger_; |
| 1001 | } |
| 1002 | Debug* debug() { |
| 1003 | if (!NoBarrier_Load(&debugger_initialized_)) InitializeDebugger(); |
| 1004 | return debug_; |
| 1005 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1006 | #endif |
| 1007 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1008 | inline bool IsDebuggerActive(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1009 | inline bool DebuggerHasBreakPoints(); |
| 1010 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1011 | CpuProfiler* cpu_profiler() const { return cpu_profiler_; } |
| 1012 | HeapProfiler* heap_profiler() const { return heap_profiler_; } |
| 1013 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1014 | #ifdef DEBUG |
| 1015 | HistogramInfo* heap_histograms() { return heap_histograms_; } |
| 1016 | |
| 1017 | JSObject::SpillInformation* js_spill_information() { |
| 1018 | return &js_spill_information_; |
| 1019 | } |
| 1020 | |
| 1021 | int* code_kind_statistics() { return code_kind_statistics_; } |
| 1022 | #endif |
| 1023 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1024 | #if V8_TARGET_ARCH_ARM && !defined(__arm__) || \ |
| 1025 | V8_TARGET_ARCH_MIPS && !defined(__mips__) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1026 | bool simulator_initialized() { return simulator_initialized_; } |
| 1027 | void set_simulator_initialized(bool initialized) { |
| 1028 | simulator_initialized_ = initialized; |
| 1029 | } |
| 1030 | |
| 1031 | HashMap* simulator_i_cache() { return simulator_i_cache_; } |
| 1032 | void set_simulator_i_cache(HashMap* hash_map) { |
| 1033 | simulator_i_cache_ = hash_map; |
| 1034 | } |
| 1035 | |
| 1036 | Redirection* simulator_redirection() { |
| 1037 | return simulator_redirection_; |
| 1038 | } |
| 1039 | void set_simulator_redirection(Redirection* redirection) { |
| 1040 | simulator_redirection_ = redirection; |
| 1041 | } |
| 1042 | #endif |
| 1043 | |
| 1044 | Factory* factory() { return reinterpret_cast<Factory*>(this); } |
| 1045 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1046 | static const int kJSRegexpStaticOffsetsVectorSize = 128; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1047 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 1048 | ExternalCallbackScope* external_callback_scope() { |
| 1049 | return thread_local_top_.external_callback_scope_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1050 | } |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 1051 | void set_external_callback_scope(ExternalCallbackScope* scope) { |
| 1052 | thread_local_top_.external_callback_scope_ = scope; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1053 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1054 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1055 | StateTag current_vm_state() { |
| 1056 | return thread_local_top_.current_vm_state_; |
| 1057 | } |
| 1058 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1059 | void set_current_vm_state(StateTag state) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1060 | thread_local_top_.current_vm_state_ = state; |
| 1061 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1062 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1063 | void SetData(void* data) { embedder_data_ = data; } |
| 1064 | void* GetData() { return embedder_data_; } |
| 1065 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1066 | LookupResult* top_lookup_result() { |
| 1067 | return thread_local_top_.top_lookup_result_; |
| 1068 | } |
| 1069 | void SetTopLookupResult(LookupResult* top) { |
| 1070 | thread_local_top_.top_lookup_result_ = top; |
| 1071 | } |
| 1072 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 1073 | bool IsDead() { return has_fatal_error_; } |
| 1074 | void SignalFatalError() { has_fatal_error_ = true; } |
| 1075 | |
| 1076 | bool use_crankshaft() const { return use_crankshaft_; } |
| 1077 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1078 | bool initialized_from_snapshot() { return initialized_from_snapshot_; } |
| 1079 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 1080 | double time_millis_since_init() { |
| 1081 | return OS::TimeCurrentMillis() - time_millis_at_init_; |
| 1082 | } |
| 1083 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1084 | DateCache* date_cache() { |
| 1085 | return date_cache_; |
| 1086 | } |
| 1087 | |
| 1088 | void set_date_cache(DateCache* date_cache) { |
| 1089 | if (date_cache != date_cache_) { |
| 1090 | delete date_cache_; |
| 1091 | } |
| 1092 | date_cache_ = date_cache; |
| 1093 | } |
| 1094 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1095 | Map* get_initial_js_array_map(ElementsKind kind); |
| 1096 | |
| 1097 | bool IsFastArrayConstructorPrototypeChainIntact(); |
| 1098 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1099 | CodeStubInterfaceDescriptor* |
| 1100 | code_stub_interface_descriptor(int index); |
| 1101 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1102 | void IterateDeferredHandles(ObjectVisitor* visitor); |
| 1103 | void LinkDeferredHandles(DeferredHandles* deferred_handles); |
| 1104 | void UnlinkDeferredHandles(DeferredHandles* deferred_handles); |
| 1105 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1106 | #ifdef DEBUG |
| 1107 | bool IsDeferredHandle(Object** location); |
| 1108 | #endif // DEBUG |
| 1109 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1110 | OptimizingCompilerThread* optimizing_compiler_thread() { |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 1111 | return optimizing_compiler_thread_; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1114 | // PreInits and returns a default isolate. Needed when a new thread tries |
| 1115 | // to create a Locker for the first time (the lock itself is in the isolate). |
| 1116 | // TODO(svenpanne) This method is on death row... |
| 1117 | static v8::Isolate* GetDefaultIsolateForLocking(); |
| 1118 | |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 1119 | SweeperThread** sweeper_threads() { |
| 1120 | return sweeper_thread_; |
| 1121 | } |
| 1122 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1123 | int id() const { return static_cast<int>(id_); } |
| 1124 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1125 | HStatistics* GetHStatistics(); |
| 1126 | HTracer* GetHTracer(); |
| 1127 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1128 | FunctionEntryHook function_entry_hook() { return function_entry_hook_; } |
| 1129 | void set_function_entry_hook(FunctionEntryHook function_entry_hook) { |
| 1130 | function_entry_hook_ = function_entry_hook; |
| 1131 | } |
| 1132 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1133 | void* stress_deopt_count_address() { return &stress_deopt_count_; } |
| 1134 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1135 | inline RandomNumberGenerator* random_number_generator(); |
| 1136 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1137 | // Given an address occupied by a live code object, return that object. |
| 1138 | Object* FindCodeObject(Address a); |
| 1139 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1140 | private: |
| 1141 | Isolate(); |
| 1142 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 1143 | friend struct GlobalState; |
| 1144 | friend struct InitializeGlobalState; |
| 1145 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1146 | enum State { |
| 1147 | UNINITIALIZED, // Some components may not have been allocated. |
| 1148 | INITIALIZED // All components are fully initialized. |
| 1149 | }; |
| 1150 | |
| 1151 | // These fields are accessed through the API, offsets must be kept in sync |
| 1152 | // with v8::internal::Internals (in include/v8.h) constants. This is also |
| 1153 | // verified in Isolate::Init() using runtime checks. |
| 1154 | State state_; // Will be padded to kApiPointerSize. |
| 1155 | void* embedder_data_; |
| 1156 | Heap heap_; |
| 1157 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1158 | // The per-process lock should be acquired before the ThreadDataTable is |
| 1159 | // modified. |
| 1160 | class ThreadDataTable { |
| 1161 | public: |
| 1162 | ThreadDataTable(); |
| 1163 | ~ThreadDataTable(); |
| 1164 | |
| 1165 | PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id); |
| 1166 | void Insert(PerIsolateThreadData* data); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1167 | void Remove(PerIsolateThreadData* data); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1168 | void RemoveAllThreads(Isolate* isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1169 | |
| 1170 | private: |
| 1171 | PerIsolateThreadData* list_; |
| 1172 | }; |
| 1173 | |
| 1174 | // These items form a stack synchronously with threads Enter'ing and Exit'ing |
| 1175 | // the Isolate. The top of the stack points to a thread which is currently |
| 1176 | // running the Isolate. When the stack is empty, the Isolate is considered |
| 1177 | // not entered by any thread and can be Disposed. |
| 1178 | // If the same thread enters the Isolate more then once, the entry_count_ |
| 1179 | // is incremented rather then a new item pushed to the stack. |
| 1180 | class EntryStackItem { |
| 1181 | public: |
| 1182 | EntryStackItem(PerIsolateThreadData* previous_thread_data, |
| 1183 | Isolate* previous_isolate, |
| 1184 | EntryStackItem* previous_item) |
| 1185 | : entry_count(1), |
| 1186 | previous_thread_data(previous_thread_data), |
| 1187 | previous_isolate(previous_isolate), |
| 1188 | previous_item(previous_item) { } |
| 1189 | |
| 1190 | int entry_count; |
| 1191 | PerIsolateThreadData* previous_thread_data; |
| 1192 | Isolate* previous_isolate; |
| 1193 | EntryStackItem* previous_item; |
| 1194 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1195 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1196 | DISALLOW_COPY_AND_ASSIGN(EntryStackItem); |
| 1197 | }; |
| 1198 | |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 1199 | // This mutex protects highest_thread_id_, thread_data_table_ and |
| 1200 | // default_isolate_. |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1201 | static Mutex process_wide_mutex_; |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 1202 | |
| 1203 | static Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 1204 | static Thread::LocalStorageKey isolate_key_; |
| 1205 | static Thread::LocalStorageKey thread_id_key_; |
| 1206 | static Isolate* default_isolate_; |
| 1207 | static ThreadDataTable* thread_data_table_; |
| 1208 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1209 | // A global counter for all generated Isolates, might overflow. |
| 1210 | static Atomic32 isolate_counter_; |
| 1211 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1212 | void Deinit(); |
| 1213 | |
| 1214 | static void SetIsolateThreadLocals(Isolate* isolate, |
| 1215 | PerIsolateThreadData* data); |
| 1216 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1217 | // Find the PerThread for this particular (isolate, thread) combination. |
| 1218 | // If one does not yet exist, allocate a new one. |
| 1219 | PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread(); |
| 1220 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1221 | // Initializes the current thread to run this Isolate. |
| 1222 | // Not thread-safe. Multiple threads should not Enter/Exit the same isolate |
| 1223 | // at the same time, this should be prevented using external locking. |
| 1224 | void Enter(); |
| 1225 | |
| 1226 | // Exits the current thread. The previosuly entered Isolate is restored |
| 1227 | // for the thread. |
| 1228 | // Not thread-safe. Multiple threads should not Enter/Exit the same isolate |
| 1229 | // at the same time, this should be prevented using external locking. |
| 1230 | void Exit(); |
| 1231 | |
| 1232 | void PreallocatedMemoryThreadStart(); |
| 1233 | void PreallocatedMemoryThreadStop(); |
| 1234 | void InitializeThreadLocal(); |
| 1235 | |
| 1236 | void PrintStackTrace(FILE* out, ThreadLocalTop* thread); |
| 1237 | void MarkCompactPrologue(bool is_compacting, |
| 1238 | ThreadLocalTop* archived_thread_data); |
| 1239 | void MarkCompactEpilogue(bool is_compacting, |
| 1240 | ThreadLocalTop* archived_thread_data); |
| 1241 | |
| 1242 | void FillCache(); |
| 1243 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1244 | void PropagatePendingExceptionToExternalTryCatch(); |
| 1245 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1246 | void InitializeDebugger(); |
| 1247 | |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1248 | // Traverse prototype chain to find out whether the object is derived from |
| 1249 | // the Error object. |
| 1250 | bool IsErrorObject(Handle<Object> obj); |
| 1251 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1252 | Atomic32 id_; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1253 | EntryStackItem* entry_stack_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1254 | int stack_trace_nesting_level_; |
| 1255 | StringStream* incomplete_message_; |
| 1256 | // The preallocated memory thread singleton. |
| 1257 | PreallocatedMemoryThread* preallocated_memory_thread_; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1258 | Address isolate_addresses_[kIsolateAddressCount + 1]; // NOLINT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1259 | NoAllocationStringAllocator* preallocated_message_space_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1260 | Bootstrapper* bootstrapper_; |
| 1261 | RuntimeProfiler* runtime_profiler_; |
| 1262 | CompilationCache* compilation_cache_; |
| 1263 | Counters* counters_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1264 | CodeRange* code_range_; |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 1265 | RecursiveMutex break_access_; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1266 | Atomic32 debugger_initialized_; |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 1267 | RecursiveMutex debugger_access_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1268 | Logger* logger_; |
| 1269 | StackGuard stack_guard_; |
| 1270 | StatsTable* stats_table_; |
| 1271 | StubCache* stub_cache_; |
| 1272 | DeoptimizerData* deoptimizer_data_; |
| 1273 | ThreadLocalTop thread_local_top_; |
| 1274 | bool capture_stack_trace_for_uncaught_exceptions_; |
| 1275 | int stack_trace_for_uncaught_exceptions_frame_limit_; |
| 1276 | StackTrace::StackTraceOptions stack_trace_for_uncaught_exceptions_options_; |
| 1277 | TranscendentalCache* transcendental_cache_; |
| 1278 | MemoryAllocator* memory_allocator_; |
| 1279 | KeyedLookupCache* keyed_lookup_cache_; |
| 1280 | ContextSlotCache* context_slot_cache_; |
| 1281 | DescriptorLookupCache* descriptor_lookup_cache_; |
| 1282 | v8::ImplementationUtilities::HandleScopeData handle_scope_data_; |
| 1283 | HandleScopeImplementer* handle_scope_implementer_; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1284 | UnicodeCache* unicode_cache_; |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 1285 | Zone runtime_zone_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1286 | PreallocatedStorage in_use_list_; |
| 1287 | PreallocatedStorage free_list_; |
| 1288 | bool preallocated_storage_preallocated_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1289 | InnerPointerToCodeCache* inner_pointer_to_code_cache_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1290 | ConsStringIteratorOp* write_iterator_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1291 | GlobalHandles* global_handles_; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1292 | EternalHandles* eternal_handles_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1293 | ContextSwitcher* context_switcher_; |
| 1294 | ThreadManager* thread_manager_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1295 | RuntimeState runtime_state_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1296 | bool fp_stubs_generated_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1297 | Builtins builtins_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1298 | bool has_installed_extensions_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1299 | StringTracker* string_tracker_; |
| 1300 | unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_; |
| 1301 | unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1302 | ConsStringIteratorOp objects_string_compare_iterator_a_; |
| 1303 | ConsStringIteratorOp objects_string_compare_iterator_b_; |
| 1304 | StaticResource<ConsStringIteratorOp> objects_string_iterator_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1305 | unibrow::Mapping<unibrow::Ecma262Canonicalize> |
| 1306 | regexp_macro_assembler_canonicalize_; |
| 1307 | RegExpStack* regexp_stack_; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1308 | DateCache* date_cache_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1309 | unibrow::Mapping<unibrow::Ecma262Canonicalize> interp_canonicalize_mapping_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1310 | CodeStubInterfaceDescriptor* code_stub_interface_descriptors_; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1311 | RandomNumberGenerator* random_number_generator_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1312 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 1313 | // True if fatal error has been signaled for this isolate. |
| 1314 | bool has_fatal_error_; |
| 1315 | |
| 1316 | // True if we are using the Crankshaft optimizing compiler. |
| 1317 | bool use_crankshaft_; |
| 1318 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1319 | // True if this isolate was initialized from a snapshot. |
| 1320 | bool initialized_from_snapshot_; |
| 1321 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 1322 | // Time stamp at initialization. |
| 1323 | double time_millis_at_init_; |
| 1324 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1325 | #if V8_TARGET_ARCH_ARM && !defined(__arm__) || \ |
| 1326 | V8_TARGET_ARCH_MIPS && !defined(__mips__) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1327 | bool simulator_initialized_; |
| 1328 | HashMap* simulator_i_cache_; |
| 1329 | Redirection* simulator_redirection_; |
| 1330 | #endif |
| 1331 | |
| 1332 | #ifdef DEBUG |
| 1333 | // A static array of histogram info for each type. |
| 1334 | HistogramInfo heap_histograms_[LAST_TYPE + 1]; |
| 1335 | JSObject::SpillInformation js_spill_information_; |
| 1336 | int code_kind_statistics_[Code::NUMBER_OF_KINDS]; |
| 1337 | #endif |
| 1338 | |
| 1339 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1340 | Debugger* debugger_; |
| 1341 | Debug* debug_; |
| 1342 | #endif |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1343 | CpuProfiler* cpu_profiler_; |
| 1344 | HeapProfiler* heap_profiler_; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1345 | FunctionEntryHook function_entry_hook_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1346 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1347 | #define GLOBAL_BACKING_STORE(type, name, initialvalue) \ |
| 1348 | type name##_; |
| 1349 | ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE) |
| 1350 | #undef GLOBAL_BACKING_STORE |
| 1351 | |
| 1352 | #define GLOBAL_ARRAY_BACKING_STORE(type, name, length) \ |
| 1353 | type name##_[length]; |
| 1354 | ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE) |
| 1355 | #undef GLOBAL_ARRAY_BACKING_STORE |
| 1356 | |
| 1357 | #ifdef DEBUG |
| 1358 | // This class is huge and has a number of fields controlled by |
| 1359 | // preprocessor defines. Make sure the offsets of these fields agree |
| 1360 | // between compilation units. |
| 1361 | #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 1362 | static const intptr_t name##_debug_offset_; |
| 1363 | ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 1364 | ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 1365 | #undef ISOLATE_FIELD_OFFSET |
| 1366 | #endif |
| 1367 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1368 | DeferredHandles* deferred_handles_head_; |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 1369 | OptimizingCompilerThread* optimizing_compiler_thread_; |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 1370 | SweeperThread** sweeper_thread_; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1371 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1372 | // Counts deopt points if deopt_every_n_times is enabled. |
| 1373 | unsigned int stress_deopt_count_; |
| 1374 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1375 | friend class ExecutionAccess; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1376 | friend class HandleScopeImplementer; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1377 | friend class IsolateInitializer; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1378 | friend class OptimizingCompilerThread; |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 1379 | friend class SweeperThread; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1380 | friend class ThreadManager; |
| 1381 | friend class Simulator; |
| 1382 | friend class StackGuard; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1383 | friend class ThreadId; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1384 | friend class TestMemoryAllocatorScope; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1385 | friend class TestCodeRangeScope; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1386 | friend class v8::Isolate; |
| 1387 | friend class v8::Locker; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1388 | friend class v8::Unlocker; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1389 | |
| 1390 | DISALLOW_COPY_AND_ASSIGN(Isolate); |
| 1391 | }; |
| 1392 | |
| 1393 | |
| 1394 | // If the GCC version is 4.1.x or 4.2.x an additional field is added to the |
| 1395 | // class as a work around for a bug in the generated code found with these |
| 1396 | // versions of GCC. See V8 issue 122 for details. |
| 1397 | class SaveContext BASE_EMBEDDED { |
| 1398 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1399 | inline explicit SaveContext(Isolate* isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1400 | |
| 1401 | ~SaveContext() { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1402 | isolate_->set_context(context_.is_null() ? NULL : *context_); |
| 1403 | isolate_->set_save_context(prev_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | Handle<Context> context() { return context_; } |
| 1407 | SaveContext* prev() { return prev_; } |
| 1408 | |
| 1409 | // Returns true if this save context is below a given JavaScript frame. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1410 | bool IsBelowFrame(JavaScriptFrame* frame) { |
| 1411 | return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | private: |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1415 | Isolate* isolate_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1416 | Handle<Context> context_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1417 | SaveContext* prev_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1418 | Address c_entry_fp_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1419 | }; |
| 1420 | |
| 1421 | |
| 1422 | class AssertNoContextChange BASE_EMBEDDED { |
| 1423 | #ifdef DEBUG |
| 1424 | public: |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1425 | explicit AssertNoContextChange(Isolate* isolate) |
| 1426 | : isolate_(isolate), |
| 1427 | context_(isolate->context(), isolate) { } |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 1428 | ~AssertNoContextChange() { |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 1429 | ASSERT(isolate_->context() == *context_); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | private: |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 1433 | Isolate* isolate_; |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 1434 | Handle<Context> context_; |
| 1435 | #else |
| 1436 | public: |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1437 | explicit AssertNoContextChange(Isolate* isolate) { } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1438 | #endif |
| 1439 | }; |
| 1440 | |
| 1441 | |
| 1442 | class ExecutionAccess BASE_EMBEDDED { |
| 1443 | public: |
| 1444 | explicit ExecutionAccess(Isolate* isolate) : isolate_(isolate) { |
| 1445 | Lock(isolate); |
| 1446 | } |
| 1447 | ~ExecutionAccess() { Unlock(isolate_); } |
| 1448 | |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 1449 | static void Lock(Isolate* isolate) { isolate->break_access()->Lock(); } |
| 1450 | static void Unlock(Isolate* isolate) { isolate->break_access()->Unlock(); } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1451 | |
| 1452 | static bool TryLock(Isolate* isolate) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 1453 | return isolate->break_access()->TryLock(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | private: |
| 1457 | Isolate* isolate_; |
| 1458 | }; |
| 1459 | |
| 1460 | |
| 1461 | // Support for checking for stack-overflows in C++ code. |
| 1462 | class StackLimitCheck BASE_EMBEDDED { |
| 1463 | public: |
| 1464 | explicit StackLimitCheck(Isolate* isolate) : isolate_(isolate) { } |
| 1465 | |
| 1466 | bool HasOverflowed() const { |
| 1467 | StackGuard* stack_guard = isolate_->stack_guard(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1468 | return (reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1469 | } |
| 1470 | private: |
| 1471 | Isolate* isolate_; |
| 1472 | }; |
| 1473 | |
| 1474 | |
| 1475 | // Support for temporarily postponing interrupts. When the outermost |
| 1476 | // postpone scope is left the interrupts will be re-enabled and any |
| 1477 | // interrupts that occurred while in the scope will be taken into |
| 1478 | // account. |
| 1479 | class PostponeInterruptsScope BASE_EMBEDDED { |
| 1480 | public: |
| 1481 | explicit PostponeInterruptsScope(Isolate* isolate) |
| 1482 | : stack_guard_(isolate->stack_guard()) { |
| 1483 | stack_guard_->thread_local_.postpone_interrupts_nesting_++; |
| 1484 | stack_guard_->DisableInterrupts(); |
| 1485 | } |
| 1486 | |
| 1487 | ~PostponeInterruptsScope() { |
| 1488 | if (--stack_guard_->thread_local_.postpone_interrupts_nesting_ == 0) { |
| 1489 | stack_guard_->EnableInterrupts(); |
| 1490 | } |
| 1491 | } |
| 1492 | private: |
| 1493 | StackGuard* stack_guard_; |
| 1494 | }; |
| 1495 | |
| 1496 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1497 | // Tells whether the native context is marked with out of memory. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1498 | inline bool Context::has_out_of_memory() { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1499 | return native_context()->out_of_memory()->IsTrue(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1503 | // Mark the native context with out of memory. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1504 | inline void Context::mark_out_of_memory() { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1505 | native_context()->set_out_of_memory(GetIsolate()->heap()->true_value()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1509 | } } // namespace v8::internal |
| 1510 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1511 | #endif // V8_ISOLATE_H_ |