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