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