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