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