Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_ISOLATE_H_ |
| 6 | #define V8_ISOLATE_H_ |
| 7 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include <queue> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include <set> |
| 10 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "include/v8-debug.h" |
| 12 | #include "src/allocation.h" |
| 13 | #include "src/assert-scope.h" |
| 14 | #include "src/base/atomicops.h" |
| 15 | #include "src/builtins.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 16 | #include "src/cancelable-task.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | #include "src/contexts.h" |
| 18 | #include "src/date.h" |
| 19 | #include "src/execution.h" |
| 20 | #include "src/frames.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 21 | #include "src/futex-emulation.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | #include "src/global-handles.h" |
| 23 | #include "src/handles.h" |
| 24 | #include "src/hashmap.h" |
| 25 | #include "src/heap/heap.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | #include "src/messages.h" |
| 27 | #include "src/optimizing-compile-dispatcher.h" |
| 28 | #include "src/regexp/regexp-stack.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 29 | #include "src/runtime/runtime.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 30 | #include "src/runtime-profiler.h" |
| 31 | #include "src/zone.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 32 | |
| 33 | namespace v8 { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 34 | |
| 35 | namespace base { |
| 36 | class RandomNumberGenerator; |
| 37 | } |
| 38 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 39 | namespace internal { |
| 40 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 41 | class BasicBlockProfiler; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 42 | class Bootstrapper; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 43 | class CallInterfaceDescriptorData; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 44 | class CodeGenerator; |
| 45 | class CodeRange; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 46 | class CodeStubDescriptor; |
| 47 | class CodeTracer; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 48 | class CompilationCache; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 49 | class CompilationStatistics; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 50 | class ContextSlotCache; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 51 | class Counters; |
| 52 | class CpuFeatures; |
| 53 | class CpuProfiler; |
| 54 | class DeoptimizerData; |
| 55 | class Deserializer; |
| 56 | class EmptyStatement; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | class ExternalCallbackScope; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 58 | class ExternalReferenceTable; |
| 59 | class Factory; |
| 60 | class FunctionInfoListener; |
| 61 | class HandleScopeImplementer; |
| 62 | class HeapProfiler; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | class HStatistics; |
| 64 | class HTracer; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 65 | class InlineRuntimeFunctionsTable; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 66 | class InnerPointerToCodeCache; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 67 | class Logger; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | class MaterializedObjectStore; |
| 69 | class CodeAgingHelper; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 70 | class RegExpStack; |
| 71 | class SaveContext; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 72 | class StatsTable; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 73 | class StringTracker; |
| 74 | class StubCache; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 75 | class SweeperThread; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 76 | class ThreadManager; |
| 77 | class ThreadState; |
| 78 | class ThreadVisitor; // Defined in v8threads.h |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | class UnicodeCache; |
| 80 | template <StateTag Tag> class VMState; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 81 | |
| 82 | // 'void function pointer', used to roundtrip the |
| 83 | // ExternalReference::ExternalReferenceRedirector since we can not include |
| 84 | // assembler.h, where it is defined, here. |
| 85 | typedef void* ExternalReferenceRedirectorPointer(); |
| 86 | |
| 87 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 88 | class Debug; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | class PromiseOnStack; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 90 | class Redirection; |
| 91 | class Simulator; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 92 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 93 | namespace interpreter { |
| 94 | class Interpreter; |
| 95 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 96 | |
| 97 | // Static indirection table for handles to constants. If a frame |
| 98 | // element represents a constant, the data contains an index into |
| 99 | // this table of handles to the actual constants. |
| 100 | // Static indirection table for handles to constants. If a Result |
| 101 | // represents a constant, the data contains an index into this table |
| 102 | // of handles to the actual constants. |
| 103 | typedef ZoneList<Handle<Object> > ZoneObjectList; |
| 104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | #define RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate) \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 106 | do { \ |
| 107 | Isolate* __isolate__ = (isolate); \ |
| 108 | if (__isolate__->has_scheduled_exception()) { \ |
| 109 | return __isolate__->PromoteScheduledException(); \ |
| 110 | } \ |
| 111 | } while (false) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 112 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | // Macros for MaybeHandle. |
| 114 | |
| 115 | #define RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, value) \ |
| 116 | do { \ |
| 117 | Isolate* __isolate__ = (isolate); \ |
| 118 | if (__isolate__->has_scheduled_exception()) { \ |
| 119 | __isolate__->PromoteScheduledException(); \ |
| 120 | return value; \ |
| 121 | } \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 122 | } while (false) |
| 123 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | #define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \ |
| 125 | RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, MaybeHandle<T>()) |
| 126 | |
| 127 | #define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \ |
| 128 | do { \ |
| 129 | if (!(call).ToHandle(&dst)) { \ |
| 130 | DCHECK((isolate)->has_pending_exception()); \ |
| 131 | return value; \ |
| 132 | } \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 133 | } while (false) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 134 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 135 | #define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call) \ |
| 136 | ASSIGN_RETURN_ON_EXCEPTION_VALUE( \ |
| 137 | isolate, dst, call, isolate->heap()->exception()) |
| 138 | |
| 139 | #define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T) \ |
| 140 | ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, MaybeHandle<T>()) |
| 141 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 142 | #define THROW_NEW_ERROR(isolate, call, T) \ |
| 143 | do { \ |
| 144 | return isolate->Throw<T>(isolate->factory()->call); \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 145 | } while (false) |
| 146 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | #define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call) \ |
| 148 | do { \ |
| 149 | return isolate->Throw(*isolate->factory()->call); \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | } while (false) |
| 151 | |
| 152 | #define RETURN_ON_EXCEPTION_VALUE(isolate, call, value) \ |
| 153 | do { \ |
| 154 | if ((call).is_null()) { \ |
| 155 | DCHECK((isolate)->has_pending_exception()); \ |
| 156 | return value; \ |
| 157 | } \ |
| 158 | } while (false) |
| 159 | |
| 160 | #define RETURN_FAILURE_ON_EXCEPTION(isolate, call) \ |
| 161 | RETURN_ON_EXCEPTION_VALUE(isolate, call, isolate->heap()->exception()) |
| 162 | |
| 163 | #define RETURN_ON_EXCEPTION(isolate, call, T) \ |
| 164 | RETURN_ON_EXCEPTION_VALUE(isolate, call, MaybeHandle<T>()) |
| 165 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 166 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 167 | #define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \ |
| 168 | C(Handler, handler) \ |
| 169 | C(CEntryFP, c_entry_fp) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 170 | C(CFunction, c_function) \ |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 171 | C(Context, context) \ |
| 172 | C(PendingException, pending_exception) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 173 | C(PendingHandlerContext, pending_handler_context) \ |
| 174 | C(PendingHandlerCode, pending_handler_code) \ |
| 175 | C(PendingHandlerOffset, pending_handler_offset) \ |
| 176 | C(PendingHandlerFP, pending_handler_fp) \ |
| 177 | C(PendingHandlerSP, pending_handler_sp) \ |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 178 | C(ExternalCaughtException, external_caught_exception) \ |
| 179 | C(JSEntrySP, js_entry_sp) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 180 | |
| 181 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 182 | // Platform-independent, reliable thread identifier. |
| 183 | class ThreadId { |
| 184 | public: |
| 185 | // Creates an invalid ThreadId. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 186 | ThreadId() { base::NoBarrier_Store(&id_, kInvalidId); } |
| 187 | |
| 188 | ThreadId& operator=(const ThreadId& other) { |
| 189 | base::NoBarrier_Store(&id_, base::NoBarrier_Load(&other.id_)); |
| 190 | return *this; |
| 191 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 192 | |
| 193 | // Returns ThreadId for current thread. |
| 194 | static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } |
| 195 | |
| 196 | // Returns invalid ThreadId (guaranteed not to be equal to any thread). |
| 197 | static ThreadId Invalid() { return ThreadId(kInvalidId); } |
| 198 | |
| 199 | // Compares ThreadIds for equality. |
| 200 | INLINE(bool Equals(const ThreadId& other) const) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 201 | return base::NoBarrier_Load(&id_) == base::NoBarrier_Load(&other.id_); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | // Checks whether this ThreadId refers to any thread. |
| 205 | INLINE(bool IsValid() const) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 206 | return base::NoBarrier_Load(&id_) != kInvalidId; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | // Converts ThreadId to an integer representation |
| 210 | // (required for public API: V8::V8::GetCurrentThreadId). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 211 | int ToInteger() const { return static_cast<int>(base::NoBarrier_Load(&id_)); } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 212 | |
| 213 | // Converts ThreadId to an integer representation |
| 214 | // (required for public API: V8::V8::TerminateExecution). |
| 215 | static ThreadId FromInteger(int id) { return ThreadId(id); } |
| 216 | |
| 217 | private: |
| 218 | static const int kInvalidId = -1; |
| 219 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 220 | explicit ThreadId(int id) { base::NoBarrier_Store(&id_, id); } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 221 | |
| 222 | static int AllocateThreadId(); |
| 223 | |
| 224 | static int GetCurrentThreadId(); |
| 225 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 226 | base::Atomic32 id_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 227 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 228 | static base::Atomic32 highest_thread_id_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 229 | |
| 230 | friend class Isolate; |
| 231 | }; |
| 232 | |
| 233 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | #define FIELD_ACCESSOR(type, name) \ |
| 235 | inline void set_##name(type v) { name##_ = v; } \ |
| 236 | inline type name() const { return name##_; } |
| 237 | |
| 238 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 239 | class ThreadLocalTop BASE_EMBEDDED { |
| 240 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 241 | // Does early low-level initialization that does not depend on the |
| 242 | // isolate being present. |
| 243 | ThreadLocalTop(); |
| 244 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 245 | // Initialize the thread data. |
| 246 | void Initialize(); |
| 247 | |
| 248 | // Get the top C++ try catch handler or NULL if none are registered. |
| 249 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 250 | // This method is not guaranteed to return an address that can be |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 251 | // used for comparison with addresses into the JS stack. If such an |
| 252 | // address is needed, use try_catch_handler_address. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 253 | FIELD_ACCESSOR(v8::TryCatch*, try_catch_handler) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 254 | |
| 255 | // Get the address of the top C++ try catch handler or NULL if |
| 256 | // none are registered. |
| 257 | // |
| 258 | // This method always returns an address that can be compared to |
| 259 | // pointers into the JavaScript stack. When running on actual |
| 260 | // hardware, try_catch_handler_address and TryCatchHandler return |
| 261 | // the same pointer. When running on a simulator with a separate JS |
| 262 | // stack, try_catch_handler_address returns a JS stack address that |
| 263 | // corresponds to the place on the JS stack where the C++ handler |
| 264 | // would have been if the stack were not separate. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | Address try_catch_handler_address() { |
| 266 | return reinterpret_cast<Address>( |
| 267 | v8::TryCatch::JSStackComparableAddress(try_catch_handler())); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 270 | void Free(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 271 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 272 | Isolate* isolate_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 273 | // The context where the current execution method is created and for variable |
| 274 | // lookups. |
| 275 | Context* context_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 276 | ThreadId thread_id_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 277 | Object* pending_exception_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 278 | |
| 279 | // Communication channel between Isolate::FindHandler and the CEntryStub. |
| 280 | Context* pending_handler_context_; |
| 281 | Code* pending_handler_code_; |
| 282 | intptr_t pending_handler_offset_; |
| 283 | Address pending_handler_fp_; |
| 284 | Address pending_handler_sp_; |
| 285 | |
| 286 | // Communication channel between Isolate::Throw and message consumers. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 287 | bool rethrowing_message_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 288 | Object* pending_message_obj_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 289 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 290 | // Use a separate value for scheduled exceptions to preserve the |
| 291 | // invariants that hold about pending_exception. We may want to |
| 292 | // unify them later. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 293 | Object* scheduled_exception_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 294 | bool external_caught_exception_; |
| 295 | SaveContext* save_context_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 296 | |
| 297 | // Stack. |
| 298 | Address c_entry_fp_; // the frame pointer of the top c entry frame |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 299 | Address handler_; // try-blocks are chained through the stack |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 300 | Address c_function_; // C function that was called at c entry. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 301 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 302 | // Throwing an exception may cause a Promise rejection. For this purpose |
| 303 | // we keep track of a stack of nested promises and the corresponding |
| 304 | // try-catch handlers. |
| 305 | PromiseOnStack* promise_on_stack_; |
| 306 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 307 | #ifdef USE_SIMULATOR |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 308 | Simulator* simulator_; |
| 309 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 310 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 311 | Address js_entry_sp_; // the stack pointer of the bottom JS entry frame |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 312 | // the external callback we're currently in |
| 313 | ExternalCallbackScope* external_callback_scope_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 314 | StateTag current_vm_state_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 315 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 316 | // Call back function to report unsafe JS accesses. |
| 317 | v8::FailedAccessCheckCallback failed_access_check_callback_; |
| 318 | |
| 319 | private: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 320 | void InitializeInternal(); |
| 321 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 322 | v8::TryCatch* try_catch_handler_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 323 | }; |
| 324 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 325 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 326 | #if USE_SIMULATOR |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 327 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 328 | #define ISOLATE_INIT_SIMULATOR_LIST(V) \ |
| 329 | V(bool, simulator_initialized, false) \ |
| 330 | V(HashMap*, simulator_i_cache, NULL) \ |
| 331 | V(Redirection*, simulator_redirection, NULL) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 332 | #else |
| 333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 334 | #define ISOLATE_INIT_SIMULATOR_LIST(V) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 335 | |
| 336 | #endif |
| 337 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 338 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 339 | #ifdef DEBUG |
| 340 | |
| 341 | #define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) \ |
| 342 | V(CommentStatistic, paged_space_comments_statistics, \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 343 | CommentStatistic::kMaxComments + 1) \ |
| 344 | V(int, code_kind_statistics, Code::NUMBER_OF_KINDS) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 345 | #else |
| 346 | |
| 347 | #define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) |
| 348 | |
| 349 | #endif |
| 350 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 351 | #define ISOLATE_INIT_ARRAY_LIST(V) \ |
| 352 | /* SerializerDeserializer state. */ \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 353 | V(int32_t, jsregexp_static_offsets_vector, kJSRegexpStaticOffsetsVectorSize) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 354 | V(int, bad_char_shift_table, kUC16AlphabetSize) \ |
| 355 | V(int, good_suffix_shift_table, (kBMMaxShift + 1)) \ |
| 356 | V(int, suffix_table, (kBMMaxShift + 1)) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 357 | V(uint32_t, private_random_seed, 2) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 358 | ISOLATE_INIT_DEBUG_ARRAY_LIST(V) |
| 359 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 360 | typedef List<HeapObject*> DebugObjectCache; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 361 | |
| 362 | #define ISOLATE_INIT_LIST(V) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 363 | /* Assembler state. */ \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 364 | V(FatalErrorCallback, exception_behavior, NULL) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 365 | V(LogEventCallback, event_logger, NULL) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 366 | V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, NULL) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 367 | /* To distinguish the function templates, so that we can find them in the */ \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 368 | /* function cache of the native context. */ \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 369 | V(int, next_serial_number, 0) \ |
| 370 | V(ExternalReferenceRedirectorPointer*, external_reference_redirector, NULL) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 371 | /* Part of the state of liveedit. */ \ |
| 372 | V(FunctionInfoListener*, active_function_info_listener, NULL) \ |
| 373 | /* State for Relocatable. */ \ |
| 374 | V(Relocatable*, relocatable_top, NULL) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 375 | V(DebugObjectCache*, string_stream_debug_object_cache, NULL) \ |
| 376 | V(Object*, string_stream_current_security_token, NULL) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 377 | V(ExternalReferenceTable*, external_reference_table, NULL) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 378 | V(HashMap*, external_reference_map, NULL) \ |
| 379 | V(HashMap*, root_index_map, NULL) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 380 | V(int, pending_microtask_count, 0) \ |
| 381 | V(bool, autorun_microtasks, true) \ |
| 382 | V(HStatistics*, hstatistics, NULL) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 383 | V(CompilationStatistics*, turbo_statistics, NULL) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 384 | V(HTracer*, htracer, NULL) \ |
| 385 | V(CodeTracer*, code_tracer, NULL) \ |
| 386 | V(bool, fp_stubs_generated, false) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | V(uint32_t, per_isolate_assert_data, 0xFFFFFFFFu) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 388 | V(PromiseRejectCallback, promise_reject_callback, NULL) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 389 | V(const v8::StartupData*, snapshot_blob, NULL) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 390 | ISOLATE_INIT_SIMULATOR_LIST(V) |
| 391 | |
| 392 | #define THREAD_LOCAL_TOP_ACCESSOR(type, name) \ |
| 393 | inline void set_##name(type v) { thread_local_top_.name##_ = v; } \ |
| 394 | inline type name() const { return thread_local_top_.name##_; } |
| 395 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 396 | #define THREAD_LOCAL_TOP_ADDRESS(type, name) \ |
| 397 | type* name##_address() { return &thread_local_top_.name##_; } |
| 398 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 399 | |
| 400 | class Isolate { |
| 401 | // These forward declarations are required to make the friend declarations in |
| 402 | // PerIsolateThreadData work on some older versions of gcc. |
| 403 | class ThreadDataTable; |
| 404 | class EntryStackItem; |
| 405 | public: |
| 406 | ~Isolate(); |
| 407 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 408 | // A thread has a PerIsolateThreadData instance for each isolate that it has |
| 409 | // entered. That instance is allocated when the isolate is initially entered |
| 410 | // and reused on subsequent entries. |
| 411 | class PerIsolateThreadData { |
| 412 | public: |
| 413 | PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) |
| 414 | : isolate_(isolate), |
| 415 | thread_id_(thread_id), |
| 416 | stack_limit_(0), |
| 417 | thread_state_(NULL), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 418 | #if USE_SIMULATOR |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 419 | simulator_(NULL), |
| 420 | #endif |
| 421 | next_(NULL), |
| 422 | prev_(NULL) { } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 423 | ~PerIsolateThreadData(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 424 | Isolate* isolate() const { return isolate_; } |
| 425 | ThreadId thread_id() const { return thread_id_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 426 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | FIELD_ACCESSOR(uintptr_t, stack_limit) |
| 428 | FIELD_ACCESSOR(ThreadState*, thread_state) |
| 429 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 430 | #if USE_SIMULATOR |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 431 | FIELD_ACCESSOR(Simulator*, simulator) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 432 | #endif |
| 433 | |
| 434 | bool Matches(Isolate* isolate, ThreadId thread_id) const { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 435 | return isolate_ == isolate && thread_id_.Equals(thread_id); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | private: |
| 439 | Isolate* isolate_; |
| 440 | ThreadId thread_id_; |
| 441 | uintptr_t stack_limit_; |
| 442 | ThreadState* thread_state_; |
| 443 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 444 | #if USE_SIMULATOR |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 445 | Simulator* simulator_; |
| 446 | #endif |
| 447 | |
| 448 | PerIsolateThreadData* next_; |
| 449 | PerIsolateThreadData* prev_; |
| 450 | |
| 451 | friend class Isolate; |
| 452 | friend class ThreadDataTable; |
| 453 | friend class EntryStackItem; |
| 454 | |
| 455 | DISALLOW_COPY_AND_ASSIGN(PerIsolateThreadData); |
| 456 | }; |
| 457 | |
| 458 | |
| 459 | enum AddressId { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 460 | #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, |
| 461 | FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 462 | #undef DECLARE_ENUM |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 463 | kIsolateAddressCount |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 464 | }; |
| 465 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 466 | static void InitializeOncePerProcess(); |
| 467 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 468 | // Returns the PerIsolateThreadData for the current thread (or NULL if one is |
| 469 | // not currently set). |
| 470 | static PerIsolateThreadData* CurrentPerIsolateThreadData() { |
| 471 | return reinterpret_cast<PerIsolateThreadData*>( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 472 | base::Thread::GetThreadLocal(per_isolate_thread_data_key_)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | // Returns the isolate inside which the current thread is running. |
| 476 | INLINE(static Isolate* Current()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 477 | DCHECK(base::NoBarrier_Load(&isolate_key_created_) == 1); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 478 | Isolate* isolate = reinterpret_cast<Isolate*>( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 479 | base::Thread::GetExistingThreadLocal(isolate_key_)); |
| 480 | DCHECK(isolate != NULL); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 481 | return isolate; |
| 482 | } |
| 483 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 484 | // Like Current, but skips the check that |isolate_key_| was initialized. |
| 485 | // Callers have to ensure that themselves. |
| 486 | // DO NOT USE. The only remaining callsite will be deleted soon. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 487 | INLINE(static Isolate* UnsafeCurrent()) { |
| 488 | return reinterpret_cast<Isolate*>( |
| 489 | base::Thread::GetThreadLocal(isolate_key_)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 490 | } |
| 491 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 492 | // Usually called by Init(), but can be called early e.g. to allow |
| 493 | // testing components that require logging but not the whole |
| 494 | // isolate. |
| 495 | // |
| 496 | // Safe to call more than once. |
| 497 | void InitializeLoggingAndCounters(); |
| 498 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 499 | bool Init(Deserializer* des); |
| 500 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 501 | // True if at least one thread Enter'ed this isolate. |
| 502 | bool IsInUse() { return entry_stack_ != NULL; } |
| 503 | |
| 504 | // Destroys the non-default isolates. |
| 505 | // Sets default isolate into "has_been_disposed" state rather then destroying, |
| 506 | // for legacy API reasons. |
| 507 | void TearDown(); |
| 508 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 509 | static void GlobalTearDown(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 510 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 511 | void ClearSerializerData(); |
| 512 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 513 | // Find the PerThread for this particular (isolate, thread) combination |
| 514 | // If one does not yet exist, return null. |
| 515 | PerIsolateThreadData* FindPerThreadDataForThisThread(); |
| 516 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 517 | // Find the PerThread for given (isolate, thread) combination |
| 518 | // If one does not yet exist, return null. |
| 519 | PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 520 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 521 | // Discard the PerThread for this particular (isolate, thread) combination |
| 522 | // If one does not yet exist, no-op. |
| 523 | void DiscardPerThreadDataForThisThread(); |
| 524 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 525 | // Returns the key used to store the pointer to the current isolate. |
| 526 | // Used internally for V8 threads that do not execute JavaScript but still |
| 527 | // are part of the domain of an isolate (like the context switcher). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 528 | static base::Thread::LocalStorageKey isolate_key() { |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 529 | return isolate_key_; |
| 530 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 531 | |
| 532 | // Returns the key used to store process-wide thread IDs. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 533 | static base::Thread::LocalStorageKey thread_id_key() { |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 534 | return thread_id_key_; |
| 535 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 536 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 537 | static base::Thread::LocalStorageKey per_isolate_thread_data_key(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 538 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 539 | // Mutex for serializing access to break control structures. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 540 | base::RecursiveMutex* break_access() { return &break_access_; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 541 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 542 | Address get_address_from_id(AddressId id); |
| 543 | |
| 544 | // Access to top context (where the current function object was created). |
| 545 | Context* context() { return thread_local_top_.context_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 546 | inline void set_context(Context* context); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 547 | Context** context_address() { return &thread_local_top_.context_; } |
| 548 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 549 | THREAD_LOCAL_TOP_ACCESSOR(SaveContext*, save_context) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 550 | |
| 551 | // Access to current thread id. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 552 | THREAD_LOCAL_TOP_ACCESSOR(ThreadId, thread_id) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 553 | |
| 554 | // Interface to pending exception. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 555 | inline Object* pending_exception(); |
| 556 | inline void set_pending_exception(Object* exception_obj); |
| 557 | inline void clear_pending_exception(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 558 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 559 | THREAD_LOCAL_TOP_ADDRESS(Object*, pending_exception) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 560 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 561 | inline bool has_pending_exception(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 562 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 563 | THREAD_LOCAL_TOP_ADDRESS(Context*, pending_handler_context) |
| 564 | THREAD_LOCAL_TOP_ADDRESS(Code*, pending_handler_code) |
| 565 | THREAD_LOCAL_TOP_ADDRESS(intptr_t, pending_handler_offset) |
| 566 | THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_fp) |
| 567 | THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_sp) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 568 | |
| 569 | THREAD_LOCAL_TOP_ACCESSOR(bool, external_caught_exception) |
| 570 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 571 | v8::TryCatch* try_catch_handler() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 572 | return thread_local_top_.try_catch_handler(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 573 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 574 | bool* external_caught_exception_address() { |
| 575 | return &thread_local_top_.external_caught_exception_; |
| 576 | } |
| 577 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 578 | THREAD_LOCAL_TOP_ADDRESS(Object*, scheduled_exception) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 579 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 580 | inline void clear_pending_message(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 581 | Address pending_message_obj_address() { |
| 582 | return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_); |
| 583 | } |
| 584 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 585 | inline Object* scheduled_exception(); |
| 586 | inline bool has_scheduled_exception(); |
| 587 | inline void clear_scheduled_exception(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 588 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 589 | bool IsJavaScriptHandlerOnTop(Object* exception); |
| 590 | bool IsExternalHandlerOnTop(Object* exception); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 591 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 592 | inline bool is_catchable_by_javascript(Object* exception); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 593 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 594 | // JS execution stack (see frames.h). |
| 595 | static Address c_entry_fp(ThreadLocalTop* thread) { |
| 596 | return thread->c_entry_fp_; |
| 597 | } |
| 598 | static Address handler(ThreadLocalTop* thread) { return thread->handler_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 599 | Address c_function() { return thread_local_top_.c_function_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 600 | |
| 601 | inline Address* c_entry_fp_address() { |
| 602 | return &thread_local_top_.c_entry_fp_; |
| 603 | } |
| 604 | inline Address* handler_address() { return &thread_local_top_.handler_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 605 | inline Address* c_function_address() { |
| 606 | return &thread_local_top_.c_function_; |
| 607 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 608 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 609 | // Bottom JS entry. |
| 610 | Address js_entry_sp() { |
| 611 | return thread_local_top_.js_entry_sp_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 612 | } |
| 613 | inline Address* js_entry_sp_address() { |
| 614 | return &thread_local_top_.js_entry_sp_; |
| 615 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 616 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 617 | // Returns the global object of the current context. It could be |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 618 | // a builtin object, or a JS global object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 619 | inline Handle<JSGlobalObject> global_object(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 620 | |
| 621 | // Returns the global proxy object of the current context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 622 | JSObject* global_proxy() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 623 | return context()->global_proxy(); |
| 624 | } |
| 625 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 626 | static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); } |
| 627 | void FreeThreadResources() { thread_local_top_.Free(); } |
| 628 | |
| 629 | // This method is called by the api after operations that may throw |
| 630 | // exceptions. If an exception was thrown and not handled by an external |
| 631 | // handler the exception is scheduled to be rethrown when we return to running |
| 632 | // JavaScript code. If an exception is scheduled true is returned. |
| 633 | bool OptionalRescheduleException(bool is_bottom_call); |
| 634 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 635 | // Push and pop a promise and the current try-catch handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 636 | void PushPromise(Handle<JSObject> promise, Handle<JSFunction> function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 637 | void PopPromise(); |
| 638 | Handle<Object> GetPromiseOnStackOnThrow(); |
| 639 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 640 | class ExceptionScope { |
| 641 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 642 | // Scope currently can only be used for regular exceptions, |
| 643 | // not termination exception. |
| 644 | inline explicit ExceptionScope(Isolate* isolate); |
| 645 | inline ~ExceptionScope(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 646 | |
| 647 | private: |
| 648 | Isolate* isolate_; |
| 649 | Handle<Object> pending_exception_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 650 | }; |
| 651 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 652 | void SetCaptureStackTraceForUncaughtExceptions( |
| 653 | bool capture, |
| 654 | int frame_limit, |
| 655 | StackTrace::StackTraceOptions options); |
| 656 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 657 | void SetAbortOnUncaughtExceptionCallback( |
| 658 | v8::Isolate::AbortOnUncaughtExceptionCallback callback); |
| 659 | |
| 660 | enum PrintStackMode { kPrintStackConcise, kPrintStackVerbose }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 661 | void PrintCurrentStackTrace(FILE* out); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 662 | void PrintStack(StringStream* accumulator, |
| 663 | PrintStackMode mode = kPrintStackVerbose); |
| 664 | void PrintStack(FILE* out, PrintStackMode mode = kPrintStackVerbose); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 665 | Handle<String> StackTraceString(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 666 | NO_INLINE(void PushStackTraceAndDie(unsigned int magic, void* ptr1, |
| 667 | void* ptr2, unsigned int magic2)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 668 | Handle<JSArray> CaptureCurrentStackTrace( |
| 669 | int frame_limit, |
| 670 | StackTrace::StackTraceOptions options); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 671 | Handle<Object> CaptureSimpleStackTrace(Handle<JSObject> error_object, |
| 672 | Handle<Object> caller); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 673 | MaybeHandle<JSObject> CaptureAndSetDetailedStackTrace( |
| 674 | Handle<JSObject> error_object); |
| 675 | MaybeHandle<JSObject> CaptureAndSetSimpleStackTrace( |
| 676 | Handle<JSObject> error_object, Handle<Object> caller); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 677 | Handle<JSArray> GetDetailedStackTrace(Handle<JSObject> error_object); |
| 678 | Handle<JSArray> GetDetailedFromSimpleStackTrace( |
| 679 | Handle<JSObject> error_object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 680 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 681 | // Returns if the given context may access the given global object. If |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 682 | // the result is false, the pending exception is guaranteed to be |
| 683 | // set. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 684 | bool MayAccess(Handle<Context> accessing_context, Handle<JSObject> receiver); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 685 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 686 | void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 687 | void ReportFailedAccessCheck(Handle<JSObject> receiver); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 688 | |
| 689 | // Exception throwing support. The caller should use the result |
| 690 | // of Throw() as its return value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 691 | Object* Throw(Object* exception, MessageLocation* location = NULL); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 692 | Object* ThrowIllegalOperation(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 693 | |
| 694 | template <typename T> |
| 695 | MUST_USE_RESULT MaybeHandle<T> Throw(Handle<Object> exception, |
| 696 | MessageLocation* location = NULL) { |
| 697 | Throw(*exception, location); |
| 698 | return MaybeHandle<T>(); |
| 699 | } |
| 700 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 701 | // Re-throw an exception. This involves no error reporting since error |
| 702 | // reporting was handled when the exception was thrown originally. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 703 | Object* ReThrow(Object* exception); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 704 | |
| 705 | // Find the correct handler for the current pending exception. This also |
| 706 | // clears and returns the current pending exception. |
| 707 | Object* UnwindAndFindHandler(); |
| 708 | |
| 709 | // Tries to predict whether an exception will be caught. Note that this can |
| 710 | // only produce an estimate, because it is undecidable whether a finally |
| 711 | // clause will consume or re-throw an exception. We conservatively assume any |
| 712 | // finally clause will behave as if the exception were consumed. |
| 713 | enum CatchType { NOT_CAUGHT, CAUGHT_BY_JAVASCRIPT, CAUGHT_BY_EXTERNAL }; |
| 714 | CatchType PredictExceptionCatcher(); |
| 715 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 716 | void ScheduleThrow(Object* exception); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 717 | // Re-set pending message, script and positions reported to the TryCatch |
| 718 | // back to the TLS for re-use when rethrowing. |
| 719 | void RestorePendingMessageFromTryCatch(v8::TryCatch* handler); |
| 720 | // Un-schedule an exception that was caught by a TryCatch handler. |
| 721 | void CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 722 | void ReportPendingMessages(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 723 | // Return pending location if any or unfilled structure. |
| 724 | MessageLocation GetMessageLocation(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 725 | |
| 726 | // Promote a scheduled exception to pending. Asserts has_scheduled_exception. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 727 | Object* PromoteScheduledException(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 728 | |
| 729 | // Attempts to compute the current source location, storing the |
| 730 | // result in the target out parameter. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 731 | bool ComputeLocation(MessageLocation* target); |
| 732 | bool ComputeLocationFromException(MessageLocation* target, |
| 733 | Handle<Object> exception); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 734 | bool ComputeLocationFromStackTrace(MessageLocation* target, |
| 735 | Handle<Object> exception); |
| 736 | |
| 737 | Handle<JSMessageObject> CreateMessage(Handle<Object> exception, |
| 738 | MessageLocation* location); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 739 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 740 | // Out of resource exception helpers. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 741 | Object* StackOverflow(); |
| 742 | Object* TerminateExecution(); |
| 743 | void CancelTerminateExecution(); |
| 744 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 745 | void RequestInterrupt(InterruptCallback callback, void* data); |
| 746 | void InvokeApiInterruptCallbacks(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 747 | |
| 748 | // Administration |
| 749 | void Iterate(ObjectVisitor* v); |
| 750 | void Iterate(ObjectVisitor* v, ThreadLocalTop* t); |
| 751 | char* Iterate(ObjectVisitor* v, char* t); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 752 | void IterateThread(ThreadVisitor* v, char* t); |
| 753 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 754 | // Returns the current native context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 755 | Handle<Context> native_context(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 756 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 757 | // Returns the native context of the calling JavaScript code. That |
| 758 | // is, the native context of the top-most JavaScript frame. |
| 759 | Handle<Context> GetCallingNativeContext(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 760 | |
| 761 | void RegisterTryCatchHandler(v8::TryCatch* that); |
| 762 | void UnregisterTryCatchHandler(v8::TryCatch* that); |
| 763 | |
| 764 | char* ArchiveThread(char* to); |
| 765 | char* RestoreThread(char* from); |
| 766 | |
| 767 | static const char* const kStackOverflowMessage; |
| 768 | |
| 769 | static const int kUC16AlphabetSize = 256; // See StringSearchBase. |
| 770 | static const int kBMMaxShift = 250; // See StringSearchBase. |
| 771 | |
| 772 | // Accessors. |
| 773 | #define GLOBAL_ACCESSOR(type, name, initialvalue) \ |
| 774 | inline type name() const { \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 775 | DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 776 | return name##_; \ |
| 777 | } \ |
| 778 | inline void set_##name(type value) { \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 779 | DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 780 | name##_ = value; \ |
| 781 | } |
| 782 | ISOLATE_INIT_LIST(GLOBAL_ACCESSOR) |
| 783 | #undef GLOBAL_ACCESSOR |
| 784 | |
| 785 | #define GLOBAL_ARRAY_ACCESSOR(type, name, length) \ |
| 786 | inline type* name() { \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 787 | DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 788 | return &(name##_)[0]; \ |
| 789 | } |
| 790 | ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR) |
| 791 | #undef GLOBAL_ARRAY_ACCESSOR |
| 792 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 793 | #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \ |
| 794 | inline Handle<type> name(); \ |
| 795 | inline bool is_##name(type* value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 796 | NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR) |
| 797 | #undef NATIVE_CONTEXT_FIELD_ACCESSOR |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 798 | |
| 799 | Bootstrapper* bootstrapper() { return bootstrapper_; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 800 | Counters* counters() { |
| 801 | // Call InitializeLoggingAndCounters() if logging is needed before |
| 802 | // the isolate is fully initialized. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 803 | DCHECK(counters_ != NULL); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 804 | return counters_; |
| 805 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 806 | CodeRange* code_range() { return code_range_; } |
| 807 | RuntimeProfiler* runtime_profiler() { return runtime_profiler_; } |
| 808 | CompilationCache* compilation_cache() { return compilation_cache_; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 809 | Logger* logger() { |
| 810 | // Call InitializeLoggingAndCounters() if logging is needed before |
| 811 | // the isolate is fully initialized. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 812 | DCHECK(logger_ != NULL); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 813 | return logger_; |
| 814 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 815 | StackGuard* stack_guard() { return &stack_guard_; } |
| 816 | Heap* heap() { return &heap_; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 817 | StatsTable* stats_table(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 818 | StubCache* stub_cache() { return stub_cache_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 819 | CodeAgingHelper* code_aging_helper() { return code_aging_helper_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 820 | DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 821 | bool deoptimizer_lazy_throw() const { return deoptimizer_lazy_throw_; } |
| 822 | void set_deoptimizer_lazy_throw(bool value) { |
| 823 | deoptimizer_lazy_throw_ = value; |
| 824 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 825 | ThreadLocalTop* thread_local_top() { return &thread_local_top_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 826 | MaterializedObjectStore* materialized_object_store() { |
| 827 | return materialized_object_store_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | MemoryAllocator* memory_allocator() { |
| 831 | return memory_allocator_; |
| 832 | } |
| 833 | |
| 834 | KeyedLookupCache* keyed_lookup_cache() { |
| 835 | return keyed_lookup_cache_; |
| 836 | } |
| 837 | |
| 838 | ContextSlotCache* context_slot_cache() { |
| 839 | return context_slot_cache_; |
| 840 | } |
| 841 | |
| 842 | DescriptorLookupCache* descriptor_lookup_cache() { |
| 843 | return descriptor_lookup_cache_; |
| 844 | } |
| 845 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 846 | HandleScopeData* handle_scope_data() { return &handle_scope_data_; } |
| 847 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 848 | HandleScopeImplementer* handle_scope_implementer() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 849 | DCHECK(handle_scope_implementer_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 850 | return handle_scope_implementer_; |
| 851 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 852 | Zone* runtime_zone() { return &runtime_zone_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 853 | Zone* interface_descriptor_zone() { return &interface_descriptor_zone_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 854 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 855 | UnicodeCache* unicode_cache() { |
| 856 | return unicode_cache_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 857 | } |
| 858 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 859 | InnerPointerToCodeCache* inner_pointer_to_code_cache() { |
| 860 | return inner_pointer_to_code_cache_; |
| 861 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 862 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 863 | GlobalHandles* global_handles() { return global_handles_; } |
| 864 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 865 | EternalHandles* eternal_handles() { return eternal_handles_; } |
| 866 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 867 | ThreadManager* thread_manager() { return thread_manager_; } |
| 868 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 869 | unibrow::Mapping<unibrow::Ecma262UnCanonicalize>* jsregexp_uncanonicalize() { |
| 870 | return &jsregexp_uncanonicalize_; |
| 871 | } |
| 872 | |
| 873 | unibrow::Mapping<unibrow::CanonicalizationRange>* jsregexp_canonrange() { |
| 874 | return &jsregexp_canonrange_; |
| 875 | } |
| 876 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 877 | RuntimeState* runtime_state() { return &runtime_state_; } |
| 878 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 879 | Builtins* builtins() { return &builtins_; } |
| 880 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 881 | void NotifyExtensionInstalled() { |
| 882 | has_installed_extensions_ = true; |
| 883 | } |
| 884 | |
| 885 | bool has_installed_extensions() { return has_installed_extensions_; } |
| 886 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 887 | unibrow::Mapping<unibrow::Ecma262Canonicalize>* |
| 888 | regexp_macro_assembler_canonicalize() { |
| 889 | return ®exp_macro_assembler_canonicalize_; |
| 890 | } |
| 891 | |
| 892 | RegExpStack* regexp_stack() { return regexp_stack_; } |
| 893 | |
| 894 | unibrow::Mapping<unibrow::Ecma262Canonicalize>* |
| 895 | interp_canonicalize_mapping() { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 896 | return ®exp_macro_assembler_canonicalize_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 897 | } |
| 898 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 899 | Debug* debug() { return debug_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 900 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 901 | CpuProfiler* cpu_profiler() const { return cpu_profiler_; } |
| 902 | HeapProfiler* heap_profiler() const { return heap_profiler_; } |
| 903 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 904 | #ifdef DEBUG |
| 905 | HistogramInfo* heap_histograms() { return heap_histograms_; } |
| 906 | |
| 907 | JSObject::SpillInformation* js_spill_information() { |
| 908 | return &js_spill_information_; |
| 909 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 910 | #endif |
| 911 | |
| 912 | Factory* factory() { return reinterpret_cast<Factory*>(this); } |
| 913 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 914 | static const int kJSRegexpStaticOffsetsVectorSize = 128; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 915 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 916 | THREAD_LOCAL_TOP_ACCESSOR(ExternalCallbackScope*, external_callback_scope) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 917 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 918 | THREAD_LOCAL_TOP_ACCESSOR(StateTag, current_vm_state) |
| 919 | |
| 920 | void SetData(uint32_t slot, void* data) { |
| 921 | DCHECK(slot < Internals::kNumIsolateDataSlots); |
| 922 | embedder_data_[slot] = data; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 923 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 924 | void* GetData(uint32_t slot) { |
| 925 | DCHECK(slot < Internals::kNumIsolateDataSlots); |
| 926 | return embedder_data_[slot]; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 927 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 928 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 929 | bool serializer_enabled() const { return serializer_enabled_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 930 | bool snapshot_available() const { |
| 931 | return snapshot_blob_ != NULL && snapshot_blob_->raw_size != 0; |
| 932 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 933 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 934 | bool IsDead() { return has_fatal_error_; } |
| 935 | void SignalFatalError() { has_fatal_error_ = true; } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 936 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 937 | bool use_crankshaft() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 938 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 939 | bool initialized_from_snapshot() { return initialized_from_snapshot_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 940 | |
| 941 | double time_millis_since_init() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 942 | return heap_.MonotonicallyIncreasingTimeInMs() - time_millis_at_init_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | DateCache* date_cache() { |
| 946 | return date_cache_; |
| 947 | } |
| 948 | |
| 949 | void set_date_cache(DateCache* date_cache) { |
| 950 | if (date_cache != date_cache_) { |
| 951 | delete date_cache_; |
| 952 | } |
| 953 | date_cache_ = date_cache; |
| 954 | } |
| 955 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 956 | Map* get_initial_js_array_map(ElementsKind kind, |
| 957 | Strength strength = Strength::WEAK); |
| 958 | |
| 959 | static const int kArrayProtectorValid = 1; |
| 960 | static const int kArrayProtectorInvalid = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 961 | |
| 962 | bool IsFastArrayConstructorPrototypeChainIntact(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 963 | bool IsArraySpeciesLookupChainIntact(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 964 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 965 | // On intent to set an element in object, make sure that appropriate |
| 966 | // notifications occur if the set is on the elements of the array or |
| 967 | // object prototype. Also ensure that changes to prototype chain between |
| 968 | // Array and Object fire notifications. |
| 969 | void UpdateArrayProtectorOnSetElement(Handle<JSObject> object); |
| 970 | void UpdateArrayProtectorOnSetLength(Handle<JSObject> object) { |
| 971 | UpdateArrayProtectorOnSetElement(object); |
| 972 | } |
| 973 | void UpdateArrayProtectorOnSetPrototype(Handle<JSObject> object) { |
| 974 | UpdateArrayProtectorOnSetElement(object); |
| 975 | } |
| 976 | void UpdateArrayProtectorOnNormalizeElements(Handle<JSObject> object) { |
| 977 | UpdateArrayProtectorOnSetElement(object); |
| 978 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 979 | void InvalidateArraySpeciesProtector(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 980 | |
| 981 | // Returns true if array is the initial array prototype in any native context. |
| 982 | bool IsAnyInitialArrayPrototype(Handle<JSArray> array); |
| 983 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 984 | CallInterfaceDescriptorData* call_descriptor_data(int index); |
| 985 | |
| 986 | void IterateDeferredHandles(ObjectVisitor* visitor); |
| 987 | void LinkDeferredHandles(DeferredHandles* deferred_handles); |
| 988 | void UnlinkDeferredHandles(DeferredHandles* deferred_handles); |
| 989 | |
| 990 | #ifdef DEBUG |
| 991 | bool IsDeferredHandle(Object** location); |
| 992 | #endif // DEBUG |
| 993 | |
| 994 | bool concurrent_recompilation_enabled() { |
| 995 | // Thread is only available with flag enabled. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 996 | DCHECK(optimizing_compile_dispatcher_ == NULL || |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 997 | FLAG_concurrent_recompilation); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 998 | return optimizing_compile_dispatcher_ != NULL; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | bool concurrent_osr_enabled() const { |
| 1002 | // Thread is only available with flag enabled. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1003 | DCHECK(optimizing_compile_dispatcher_ == NULL || |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1004 | FLAG_concurrent_recompilation); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1005 | return optimizing_compile_dispatcher_ != NULL && FLAG_concurrent_osr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1008 | OptimizingCompileDispatcher* optimizing_compile_dispatcher() { |
| 1009 | return optimizing_compile_dispatcher_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1012 | int id() const { return static_cast<int>(id_); } |
| 1013 | |
| 1014 | HStatistics* GetHStatistics(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1015 | CompilationStatistics* GetTurboStatistics(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1016 | HTracer* GetHTracer(); |
| 1017 | CodeTracer* GetCodeTracer(); |
| 1018 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1019 | void DumpAndResetCompilationStats(); |
| 1020 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1021 | FunctionEntryHook function_entry_hook() { return function_entry_hook_; } |
| 1022 | void set_function_entry_hook(FunctionEntryHook function_entry_hook) { |
| 1023 | function_entry_hook_ = function_entry_hook; |
| 1024 | } |
| 1025 | |
| 1026 | void* stress_deopt_count_address() { return &stress_deopt_count_; } |
| 1027 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1028 | void* virtual_handler_register_address() { |
| 1029 | return &virtual_handler_register_; |
| 1030 | } |
| 1031 | |
| 1032 | void* virtual_slot_register_address() { return &virtual_slot_register_; } |
| 1033 | |
| 1034 | base::RandomNumberGenerator* random_number_generator(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1035 | |
| 1036 | // Given an address occupied by a live code object, return that object. |
| 1037 | Object* FindCodeObject(Address a); |
| 1038 | |
| 1039 | int NextOptimizationId() { |
| 1040 | int id = next_optimization_id_++; |
| 1041 | if (!Smi::IsValid(next_optimization_id_)) { |
| 1042 | next_optimization_id_ = 0; |
| 1043 | } |
| 1044 | return id; |
| 1045 | } |
| 1046 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1047 | void IncrementJsCallsFromApiCounter() { ++js_calls_from_api_counter_; } |
| 1048 | |
| 1049 | unsigned int js_calls_from_api_counter() { |
| 1050 | return js_calls_from_api_counter_; |
| 1051 | } |
| 1052 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1053 | // Get (and lazily initialize) the registry for per-isolate symbols. |
| 1054 | Handle<JSObject> GetSymbolRegistry(); |
| 1055 | |
| 1056 | void AddCallCompletedCallback(CallCompletedCallback callback); |
| 1057 | void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 1058 | void FireCallCompletedCallback(); |
| 1059 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1060 | void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback); |
| 1061 | void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback); |
| 1062 | void FireBeforeCallEnteredCallback(); |
| 1063 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1064 | void SetPromiseRejectCallback(PromiseRejectCallback callback); |
| 1065 | void ReportPromiseReject(Handle<JSObject> promise, Handle<Object> value, |
| 1066 | v8::PromiseRejectEvent event); |
| 1067 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1068 | void EnqueueMicrotask(Handle<Object> microtask); |
| 1069 | void RunMicrotasks(); |
| 1070 | |
| 1071 | void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); |
| 1072 | void CountUsage(v8::Isolate::UseCounterFeature feature); |
| 1073 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1074 | BasicBlockProfiler* GetOrCreateBasicBlockProfiler(); |
| 1075 | BasicBlockProfiler* basic_block_profiler() { return basic_block_profiler_; } |
| 1076 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1077 | std::string GetTurboCfgFileName(); |
| 1078 | |
| 1079 | #if TRACE_MAPS |
| 1080 | int GetNextUniqueSharedFunctionInfoId() { return next_unique_sfi_id_++; } |
| 1081 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1082 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1083 | |
| 1084 | void AddDetachedContext(Handle<Context> context); |
| 1085 | void CheckDetachedContextsAfterGC(); |
| 1086 | |
| 1087 | List<Object*>* partial_snapshot_cache() { return &partial_snapshot_cache_; } |
| 1088 | |
| 1089 | void set_array_buffer_allocator(v8::ArrayBuffer::Allocator* allocator) { |
| 1090 | array_buffer_allocator_ = allocator; |
| 1091 | } |
| 1092 | v8::ArrayBuffer::Allocator* array_buffer_allocator() const { |
| 1093 | return array_buffer_allocator_; |
| 1094 | } |
| 1095 | |
| 1096 | FutexWaitListNode* futex_wait_list_node() { return &futex_wait_list_node_; } |
| 1097 | |
| 1098 | CancelableTaskManager* cancelable_task_manager() { |
| 1099 | return cancelable_task_manager_; |
| 1100 | } |
| 1101 | |
| 1102 | interpreter::Interpreter* interpreter() const { return interpreter_; } |
| 1103 | |
| 1104 | protected: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1105 | explicit Isolate(bool enable_serializer); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1106 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1107 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1108 | friend struct GlobalState; |
| 1109 | friend struct InitializeGlobalState; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1110 | Handle<JSObject> SetUpSubregistry(Handle<JSObject> registry, Handle<Map> map, |
| 1111 | const char* name); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1112 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1113 | // These fields are accessed through the API, offsets must be kept in sync |
| 1114 | // with v8::internal::Internals (in include/v8.h) constants. This is also |
| 1115 | // verified in Isolate::Init() using runtime checks. |
| 1116 | void* embedder_data_[Internals::kNumIsolateDataSlots]; |
| 1117 | Heap heap_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1118 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1119 | // The per-process lock should be acquired before the ThreadDataTable is |
| 1120 | // modified. |
| 1121 | class ThreadDataTable { |
| 1122 | public: |
| 1123 | ThreadDataTable(); |
| 1124 | ~ThreadDataTable(); |
| 1125 | |
| 1126 | PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id); |
| 1127 | void Insert(PerIsolateThreadData* data); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1128 | void Remove(PerIsolateThreadData* data); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1129 | void RemoveAllThreads(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1130 | |
| 1131 | private: |
| 1132 | PerIsolateThreadData* list_; |
| 1133 | }; |
| 1134 | |
| 1135 | // These items form a stack synchronously with threads Enter'ing and Exit'ing |
| 1136 | // the Isolate. The top of the stack points to a thread which is currently |
| 1137 | // running the Isolate. When the stack is empty, the Isolate is considered |
| 1138 | // not entered by any thread and can be Disposed. |
| 1139 | // If the same thread enters the Isolate more then once, the entry_count_ |
| 1140 | // is incremented rather then a new item pushed to the stack. |
| 1141 | class EntryStackItem { |
| 1142 | public: |
| 1143 | EntryStackItem(PerIsolateThreadData* previous_thread_data, |
| 1144 | Isolate* previous_isolate, |
| 1145 | EntryStackItem* previous_item) |
| 1146 | : entry_count(1), |
| 1147 | previous_thread_data(previous_thread_data), |
| 1148 | previous_isolate(previous_isolate), |
| 1149 | previous_item(previous_item) { } |
| 1150 | |
| 1151 | int entry_count; |
| 1152 | PerIsolateThreadData* previous_thread_data; |
| 1153 | Isolate* previous_isolate; |
| 1154 | EntryStackItem* previous_item; |
| 1155 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1156 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1157 | DISALLOW_COPY_AND_ASSIGN(EntryStackItem); |
| 1158 | }; |
| 1159 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1160 | static base::LazyMutex thread_data_table_mutex_; |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1161 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1162 | static base::Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 1163 | static base::Thread::LocalStorageKey isolate_key_; |
| 1164 | static base::Thread::LocalStorageKey thread_id_key_; |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1165 | static ThreadDataTable* thread_data_table_; |
| 1166 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1167 | // A global counter for all generated Isolates, might overflow. |
| 1168 | static base::Atomic32 isolate_counter_; |
| 1169 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1170 | #if DEBUG |
| 1171 | static base::Atomic32 isolate_key_created_; |
| 1172 | #endif |
| 1173 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1174 | void Deinit(); |
| 1175 | |
| 1176 | static void SetIsolateThreadLocals(Isolate* isolate, |
| 1177 | PerIsolateThreadData* data); |
| 1178 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1179 | // Find the PerThread for this particular (isolate, thread) combination. |
| 1180 | // If one does not yet exist, allocate a new one. |
| 1181 | PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread(); |
| 1182 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1183 | // Initializes the current thread to run this Isolate. |
| 1184 | // Not thread-safe. Multiple threads should not Enter/Exit the same isolate |
| 1185 | // at the same time, this should be prevented using external locking. |
| 1186 | void Enter(); |
| 1187 | |
| 1188 | // Exits the current thread. The previosuly entered Isolate is restored |
| 1189 | // for the thread. |
| 1190 | // Not thread-safe. Multiple threads should not Enter/Exit the same isolate |
| 1191 | // at the same time, this should be prevented using external locking. |
| 1192 | void Exit(); |
| 1193 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1194 | void InitializeThreadLocal(); |
| 1195 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1196 | void MarkCompactPrologue(bool is_compacting, |
| 1197 | ThreadLocalTop* archived_thread_data); |
| 1198 | void MarkCompactEpilogue(bool is_compacting, |
| 1199 | ThreadLocalTop* archived_thread_data); |
| 1200 | |
| 1201 | void FillCache(); |
| 1202 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1203 | // Propagate pending exception message to the v8::TryCatch. |
| 1204 | // If there is no external try-catch or message was successfully propagated, |
| 1205 | // then return true. |
| 1206 | bool PropagatePendingExceptionToExternalTryCatch(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1207 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1208 | // Remove per-frame stored materialized objects when we are unwinding |
| 1209 | // the frame. |
| 1210 | void RemoveMaterializedObjectsOnUnwind(StackFrame* frame); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1211 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1212 | base::Atomic32 id_; |
| 1213 | EntryStackItem* entry_stack_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1214 | int stack_trace_nesting_level_; |
| 1215 | StringStream* incomplete_message_; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1216 | Address isolate_addresses_[kIsolateAddressCount + 1]; // NOLINT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1217 | Bootstrapper* bootstrapper_; |
| 1218 | RuntimeProfiler* runtime_profiler_; |
| 1219 | CompilationCache* compilation_cache_; |
| 1220 | Counters* counters_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1221 | CodeRange* code_range_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1222 | base::RecursiveMutex break_access_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1223 | Logger* logger_; |
| 1224 | StackGuard stack_guard_; |
| 1225 | StatsTable* stats_table_; |
| 1226 | StubCache* stub_cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1227 | CodeAgingHelper* code_aging_helper_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1228 | DeoptimizerData* deoptimizer_data_; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1229 | bool deoptimizer_lazy_throw_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1230 | MaterializedObjectStore* materialized_object_store_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1231 | ThreadLocalTop thread_local_top_; |
| 1232 | bool capture_stack_trace_for_uncaught_exceptions_; |
| 1233 | int stack_trace_for_uncaught_exceptions_frame_limit_; |
| 1234 | StackTrace::StackTraceOptions stack_trace_for_uncaught_exceptions_options_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1235 | MemoryAllocator* memory_allocator_; |
| 1236 | KeyedLookupCache* keyed_lookup_cache_; |
| 1237 | ContextSlotCache* context_slot_cache_; |
| 1238 | DescriptorLookupCache* descriptor_lookup_cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1239 | HandleScopeData handle_scope_data_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1240 | HandleScopeImplementer* handle_scope_implementer_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1241 | UnicodeCache* unicode_cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1242 | Zone runtime_zone_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1243 | Zone interface_descriptor_zone_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1244 | InnerPointerToCodeCache* inner_pointer_to_code_cache_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1245 | GlobalHandles* global_handles_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1246 | EternalHandles* eternal_handles_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1247 | ThreadManager* thread_manager_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1248 | RuntimeState runtime_state_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1249 | Builtins builtins_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1250 | bool has_installed_extensions_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1251 | unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_; |
| 1252 | unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1253 | unibrow::Mapping<unibrow::Ecma262Canonicalize> |
| 1254 | regexp_macro_assembler_canonicalize_; |
| 1255 | RegExpStack* regexp_stack_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1256 | DateCache* date_cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1257 | CallInterfaceDescriptorData* call_descriptor_data_; |
| 1258 | base::RandomNumberGenerator* random_number_generator_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1259 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1260 | // Whether the isolate has been created for snapshotting. |
| 1261 | bool serializer_enabled_; |
| 1262 | |
| 1263 | // True if fatal error has been signaled for this isolate. |
| 1264 | bool has_fatal_error_; |
| 1265 | |
| 1266 | // True if this isolate was initialized from a snapshot. |
| 1267 | bool initialized_from_snapshot_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1268 | |
| 1269 | // Time stamp at initialization. |
| 1270 | double time_millis_at_init_; |
| 1271 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1272 | #ifdef DEBUG |
| 1273 | // A static array of histogram info for each type. |
| 1274 | HistogramInfo heap_histograms_[LAST_TYPE + 1]; |
| 1275 | JSObject::SpillInformation js_spill_information_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1276 | #endif |
| 1277 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1278 | Debug* debug_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1279 | CpuProfiler* cpu_profiler_; |
| 1280 | HeapProfiler* heap_profiler_; |
| 1281 | FunctionEntryHook function_entry_hook_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1282 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1283 | interpreter::Interpreter* interpreter_; |
| 1284 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1285 | typedef std::pair<InterruptCallback, void*> InterruptEntry; |
| 1286 | std::queue<InterruptEntry> api_interrupts_queue_; |
| 1287 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1288 | #define GLOBAL_BACKING_STORE(type, name, initialvalue) \ |
| 1289 | type name##_; |
| 1290 | ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE) |
| 1291 | #undef GLOBAL_BACKING_STORE |
| 1292 | |
| 1293 | #define GLOBAL_ARRAY_BACKING_STORE(type, name, length) \ |
| 1294 | type name##_[length]; |
| 1295 | ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE) |
| 1296 | #undef GLOBAL_ARRAY_BACKING_STORE |
| 1297 | |
| 1298 | #ifdef DEBUG |
| 1299 | // This class is huge and has a number of fields controlled by |
| 1300 | // preprocessor defines. Make sure the offsets of these fields agree |
| 1301 | // between compilation units. |
| 1302 | #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 1303 | static const intptr_t name##_debug_offset_; |
| 1304 | ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 1305 | ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 1306 | #undef ISOLATE_FIELD_OFFSET |
| 1307 | #endif |
| 1308 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1309 | DeferredHandles* deferred_handles_head_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1310 | OptimizingCompileDispatcher* optimizing_compile_dispatcher_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1311 | |
| 1312 | // Counts deopt points if deopt_every_n_times is enabled. |
| 1313 | unsigned int stress_deopt_count_; |
| 1314 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1315 | Address virtual_handler_register_; |
| 1316 | Address virtual_slot_register_; |
| 1317 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1318 | int next_optimization_id_; |
| 1319 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1320 | // Counts javascript calls from the API. Wraps around on overflow. |
| 1321 | unsigned int js_calls_from_api_counter_; |
| 1322 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1323 | #if TRACE_MAPS |
| 1324 | int next_unique_sfi_id_; |
| 1325 | #endif |
| 1326 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1327 | // List of callbacks before a Call starts execution. |
| 1328 | List<BeforeCallEnteredCallback> before_call_entered_callbacks_; |
| 1329 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1330 | // List of callbacks when a Call completes. |
| 1331 | List<CallCompletedCallback> call_completed_callbacks_; |
| 1332 | |
| 1333 | v8::Isolate::UseCounterCallback use_counter_callback_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1334 | BasicBlockProfiler* basic_block_profiler_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1335 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1336 | List<Object*> partial_snapshot_cache_; |
| 1337 | |
| 1338 | v8::ArrayBuffer::Allocator* array_buffer_allocator_; |
| 1339 | |
| 1340 | FutexWaitListNode futex_wait_list_node_; |
| 1341 | |
| 1342 | CancelableTaskManager* cancelable_task_manager_; |
| 1343 | |
| 1344 | v8::Isolate::AbortOnUncaughtExceptionCallback |
| 1345 | abort_on_uncaught_exception_callback_; |
| 1346 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1347 | friend class ExecutionAccess; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1348 | friend class HandleScopeImplementer; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1349 | friend class OptimizingCompileDispatcher; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1350 | friend class SweeperThread; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1351 | friend class ThreadManager; |
| 1352 | friend class Simulator; |
| 1353 | friend class StackGuard; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1354 | friend class ThreadId; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1355 | friend class TestMemoryAllocatorScope; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1356 | friend class TestCodeRangeScope; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1357 | friend class v8::Isolate; |
| 1358 | friend class v8::Locker; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1359 | friend class v8::Unlocker; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1360 | friend v8::StartupData v8::V8::CreateSnapshotDataBlob(const char*); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1361 | |
| 1362 | DISALLOW_COPY_AND_ASSIGN(Isolate); |
| 1363 | }; |
| 1364 | |
| 1365 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1366 | #undef FIELD_ACCESSOR |
| 1367 | #undef THREAD_LOCAL_TOP_ACCESSOR |
| 1368 | |
| 1369 | |
| 1370 | class PromiseOnStack { |
| 1371 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1372 | PromiseOnStack(Handle<JSFunction> function, Handle<JSObject> promise, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1373 | PromiseOnStack* prev) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1374 | : function_(function), promise_(promise), prev_(prev) {} |
| 1375 | Handle<JSFunction> function() { return function_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1376 | Handle<JSObject> promise() { return promise_; } |
| 1377 | PromiseOnStack* prev() { return prev_; } |
| 1378 | |
| 1379 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1380 | Handle<JSFunction> function_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1381 | Handle<JSObject> promise_; |
| 1382 | PromiseOnStack* prev_; |
| 1383 | }; |
| 1384 | |
| 1385 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1386 | // If the GCC version is 4.1.x or 4.2.x an additional field is added to the |
| 1387 | // class as a work around for a bug in the generated code found with these |
| 1388 | // versions of GCC. See V8 issue 122 for details. |
| 1389 | class SaveContext BASE_EMBEDDED { |
| 1390 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1391 | explicit SaveContext(Isolate* isolate); |
| 1392 | ~SaveContext(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1393 | |
| 1394 | Handle<Context> context() { return context_; } |
| 1395 | SaveContext* prev() { return prev_; } |
| 1396 | |
| 1397 | // Returns true if this save context is below a given JavaScript frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1398 | bool IsBelowFrame(JavaScriptFrame* frame) { |
| 1399 | return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1403 | Isolate* isolate_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1404 | Handle<Context> context_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1405 | SaveContext* prev_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1406 | Address c_entry_fp_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1407 | }; |
| 1408 | |
| 1409 | |
| 1410 | class AssertNoContextChange BASE_EMBEDDED { |
| 1411 | #ifdef DEBUG |
| 1412 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1413 | explicit AssertNoContextChange(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1414 | ~AssertNoContextChange() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1415 | DCHECK(isolate_->context() == *context_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1419 | Isolate* isolate_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1420 | Handle<Context> context_; |
| 1421 | #else |
| 1422 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1423 | explicit AssertNoContextChange(Isolate* isolate) { } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1424 | #endif |
| 1425 | }; |
| 1426 | |
| 1427 | |
| 1428 | class ExecutionAccess BASE_EMBEDDED { |
| 1429 | public: |
| 1430 | explicit ExecutionAccess(Isolate* isolate) : isolate_(isolate) { |
| 1431 | Lock(isolate); |
| 1432 | } |
| 1433 | ~ExecutionAccess() { Unlock(isolate_); } |
| 1434 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1435 | static void Lock(Isolate* isolate) { isolate->break_access()->Lock(); } |
| 1436 | static void Unlock(Isolate* isolate) { isolate->break_access()->Unlock(); } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1437 | |
| 1438 | static bool TryLock(Isolate* isolate) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1439 | return isolate->break_access()->TryLock(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | private: |
| 1443 | Isolate* isolate_; |
| 1444 | }; |
| 1445 | |
| 1446 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1447 | // Support for checking for stack-overflows. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1448 | class StackLimitCheck BASE_EMBEDDED { |
| 1449 | public: |
| 1450 | explicit StackLimitCheck(Isolate* isolate) : isolate_(isolate) { } |
| 1451 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1452 | // Use this to check for stack-overflows in C++ code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1453 | bool HasOverflowed() const { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1454 | StackGuard* stack_guard = isolate_->stack_guard(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1455 | return GetCurrentStackPosition() < stack_guard->real_climit(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1456 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1457 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1458 | // Use this to check for interrupt request in C++ code. |
| 1459 | bool InterruptRequested() { |
| 1460 | StackGuard* stack_guard = isolate_->stack_guard(); |
| 1461 | return GetCurrentStackPosition() < stack_guard->climit(); |
| 1462 | } |
| 1463 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1464 | // Use this to check for stack-overflow when entering runtime from JS code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1465 | bool JsHasOverflowed(uintptr_t gap = 0) const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1466 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1467 | private: |
| 1468 | Isolate* isolate_; |
| 1469 | }; |
| 1470 | |
| 1471 | |
| 1472 | // Support for temporarily postponing interrupts. When the outermost |
| 1473 | // postpone scope is left the interrupts will be re-enabled and any |
| 1474 | // interrupts that occurred while in the scope will be taken into |
| 1475 | // account. |
| 1476 | class PostponeInterruptsScope BASE_EMBEDDED { |
| 1477 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1478 | PostponeInterruptsScope(Isolate* isolate, |
| 1479 | int intercept_mask = StackGuard::ALL_INTERRUPTS) |
| 1480 | : stack_guard_(isolate->stack_guard()), |
| 1481 | intercept_mask_(intercept_mask), |
| 1482 | intercepted_flags_(0) { |
| 1483 | stack_guard_->PushPostponeInterruptsScope(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | ~PostponeInterruptsScope() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1487 | stack_guard_->PopPostponeInterruptsScope(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1488 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1489 | |
| 1490 | // Find the bottom-most scope that intercepts this interrupt. |
| 1491 | // Return whether the interrupt has been intercepted. |
| 1492 | bool Intercept(StackGuard::InterruptFlag flag); |
| 1493 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1494 | private: |
| 1495 | StackGuard* stack_guard_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1496 | int intercept_mask_; |
| 1497 | int intercepted_flags_; |
| 1498 | PostponeInterruptsScope* prev_; |
| 1499 | |
| 1500 | friend class StackGuard; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1501 | }; |
| 1502 | |
| 1503 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1504 | class CodeTracer final : public Malloced { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1505 | public: |
| 1506 | explicit CodeTracer(int isolate_id) |
| 1507 | : file_(NULL), |
| 1508 | scope_depth_(0) { |
| 1509 | if (!ShouldRedirect()) { |
| 1510 | file_ = stdout; |
| 1511 | return; |
| 1512 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1513 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1514 | if (FLAG_redirect_code_traces_to == NULL) { |
| 1515 | SNPrintF(filename_, |
| 1516 | "code-%d-%d.asm", |
| 1517 | base::OS::GetCurrentProcessId(), |
| 1518 | isolate_id); |
| 1519 | } else { |
| 1520 | StrNCpy(filename_, FLAG_redirect_code_traces_to, filename_.length()); |
| 1521 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1522 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1523 | WriteChars(filename_.start(), "", 0, false); |
| 1524 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1525 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1526 | class Scope { |
| 1527 | public: |
| 1528 | explicit Scope(CodeTracer* tracer) : tracer_(tracer) { tracer->OpenFile(); } |
| 1529 | ~Scope() { tracer_->CloseFile(); } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1530 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1531 | FILE* file() const { return tracer_->file(); } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1532 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1533 | private: |
| 1534 | CodeTracer* tracer_; |
| 1535 | }; |
| 1536 | |
| 1537 | void OpenFile() { |
| 1538 | if (!ShouldRedirect()) { |
| 1539 | return; |
| 1540 | } |
| 1541 | |
| 1542 | if (file_ == NULL) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1543 | file_ = base::OS::FOpen(filename_.start(), "ab"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | scope_depth_++; |
| 1547 | } |
| 1548 | |
| 1549 | void CloseFile() { |
| 1550 | if (!ShouldRedirect()) { |
| 1551 | return; |
| 1552 | } |
| 1553 | |
| 1554 | if (--scope_depth_ == 0) { |
| 1555 | fclose(file_); |
| 1556 | file_ = NULL; |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | FILE* file() const { return file_; } |
| 1561 | |
| 1562 | private: |
| 1563 | static bool ShouldRedirect() { |
| 1564 | return FLAG_redirect_code_traces; |
| 1565 | } |
| 1566 | |
| 1567 | EmbeddedVector<char, 128> filename_; |
| 1568 | FILE* file_; |
| 1569 | int scope_depth_; |
| 1570 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1571 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1572 | } // namespace internal |
| 1573 | } // namespace v8 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1574 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1575 | #endif // V8_ISOLATE_H_ |