blob: 6693b578f5aaaffe5396d9550a3627a4d1853234 [file] [log] [blame]
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00001// Copyright 2012 the V8 project authors. All rights reserved.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_ISOLATE_H_
29#define V8_ISOLATE_H_
30
31#include "../include/v8-debug.h"
32#include "allocation.h"
33#include "apiutils.h"
rossberg@chromium.org79e79022013-06-03 15:43:46 +000034#include "assert-scope.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000035#include "atomicops.h"
36#include "builtins.h"
37#include "contexts.h"
38#include "execution.h"
39#include "frames.h"
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +000040#include "date.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000041#include "global-handles.h"
42#include "handles.h"
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +000043#include "hashmap.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000044#include "heap.h"
yangguo@chromium.org304cc332012-07-24 07:59:48 +000045#include "optimizing-compiler-thread.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000046#include "regexp-stack.h"
47#include "runtime-profiler.h"
48#include "runtime.h"
49#include "zone.h"
50
51namespace v8 {
52namespace internal {
53
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000054class Bootstrapper;
55class CodeGenerator;
56class CodeRange;
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +000057struct CodeStubInterfaceDescriptor;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000058class CompilationCache;
59class ContextSlotCache;
60class ContextSwitcher;
61class Counters;
62class CpuFeatures;
63class CpuProfiler;
64class DeoptimizerData;
65class Deserializer;
66class EmptyStatement;
yangguo@chromium.orgc73d55b2013-07-24 08:18:28 +000067class ExternalCallbackScope;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000068class ExternalReferenceTable;
69class Factory;
70class FunctionInfoListener;
71class HandleScopeImplementer;
72class HeapProfiler;
ulan@chromium.org750145a2013-03-07 15:14:13 +000073class HStatistics;
74class HTracer;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000075class InlineRuntimeFunctionsTable;
76class NoAllocationStringAllocator;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000077class InnerPointerToCodeCache;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000078class PreallocatedMemoryThread;
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +000079class RandomNumberGenerator;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000080class RegExpStack;
81class SaveContext;
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +000082class UnicodeCache;
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +000083class ConsStringIteratorOp;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000084class StringTracker;
85class StubCache;
mstarzinger@chromium.orge3b8d0f2013-02-01 09:06:41 +000086class SweeperThread;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000087class ThreadManager;
88class ThreadState;
89class ThreadVisitor; // Defined in v8threads.h
danno@chromium.orgca29dd82013-04-26 11:59:48 +000090template <StateTag Tag> class VMState;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000091
92// 'void function pointer', used to roundtrip the
93// ExternalReference::ExternalReferenceRedirector since we can not include
94// assembler.h, where it is defined, here.
95typedef void* ExternalReferenceRedirectorPointer();
96
97
98#ifdef ENABLE_DEBUGGER_SUPPORT
99class Debug;
100class Debugger;
101class DebuggerAgent;
102#endif
103
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000104#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
105 !defined(__mips__) && V8_TARGET_ARCH_MIPS
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000106class Redirection;
107class Simulator;
108#endif
109
lrn@chromium.org7516f052011-03-30 08:52:27 +0000110
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000111// Static indirection table for handles to constants. If a frame
112// element represents a constant, the data contains an index into
113// this table of handles to the actual constants.
114// Static indirection table for handles to constants. If a Result
115// represents a constant, the data contains an index into this table
116// of handles to the actual constants.
117typedef ZoneList<Handle<Object> > ZoneObjectList;
118
rossberg@chromium.orgfab14982012-01-05 15:02:15 +0000119#define RETURN_IF_SCHEDULED_EXCEPTION(isolate) \
120 do { \
121 Isolate* __isolate__ = (isolate); \
122 if (__isolate__->has_scheduled_exception()) { \
123 return __isolate__->PromoteScheduledException(); \
124 } \
125 } while (false)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000126
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000127#define RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, T) \
128 do { \
129 Isolate* __isolate__ = (isolate); \
130 if (__isolate__->has_scheduled_exception()) { \
131 __isolate__->PromoteScheduledException(); \
132 return Handle<T>::null(); \
133 } \
134 } while (false)
135
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000136#define RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, value) \
rossberg@chromium.orgfab14982012-01-05 15:02:15 +0000137 do { \
138 if ((call).is_null()) { \
139 ASSERT((isolate)->has_pending_exception()); \
140 return (value); \
141 } \
142 } while (false)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000143
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000144#define CHECK_NOT_EMPTY_HANDLE(isolate, call) \
145 do { \
146 ASSERT(!(isolate)->has_pending_exception()); \
147 CHECK(!(call).is_null()); \
148 CHECK(!(isolate)->has_pending_exception()); \
149 } while (false)
150
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000151#define RETURN_IF_EMPTY_HANDLE(isolate, call) \
152 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, Failure::Exception())
153
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000154#define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \
155 C(Handler, handler) \
156 C(CEntryFP, c_entry_fp) \
157 C(Context, context) \
158 C(PendingException, pending_exception) \
159 C(ExternalCaughtException, external_caught_exception) \
160 C(JSEntrySP, js_entry_sp)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000161
162
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +0000163// Platform-independent, reliable thread identifier.
164class ThreadId {
165 public:
166 // Creates an invalid ThreadId.
167 ThreadId() : id_(kInvalidId) {}
168
169 // Returns ThreadId for current thread.
170 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); }
171
172 // Returns invalid ThreadId (guaranteed not to be equal to any thread).
173 static ThreadId Invalid() { return ThreadId(kInvalidId); }
174
175 // Compares ThreadIds for equality.
176 INLINE(bool Equals(const ThreadId& other) const) {
177 return id_ == other.id_;
178 }
179
180 // Checks whether this ThreadId refers to any thread.
181 INLINE(bool IsValid() const) {
182 return id_ != kInvalidId;
183 }
184
185 // Converts ThreadId to an integer representation
186 // (required for public API: V8::V8::GetCurrentThreadId).
187 int ToInteger() const { return id_; }
188
189 // Converts ThreadId to an integer representation
190 // (required for public API: V8::V8::TerminateExecution).
191 static ThreadId FromInteger(int id) { return ThreadId(id); }
192
193 private:
194 static const int kInvalidId = -1;
195
196 explicit ThreadId(int id) : id_(id) {}
197
198 static int AllocateThreadId();
199
200 static int GetCurrentThreadId();
201
202 int id_;
203
204 static Atomic32 highest_thread_id_;
205
206 friend class Isolate;
207};
208
209
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000210class ThreadLocalTop BASE_EMBEDDED {
211 public:
vitalyr@chromium.org5523ec32011-04-15 21:42:52 +0000212 // Does early low-level initialization that does not depend on the
213 // isolate being present.
214 ThreadLocalTop();
215
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000216 // Initialize the thread data.
217 void Initialize();
218
219 // Get the top C++ try catch handler or NULL if none are registered.
220 //
221 // This method is not guarenteed to return an address that can be
222 // used for comparison with addresses into the JS stack. If such an
223 // address is needed, use try_catch_handler_address.
224 v8::TryCatch* TryCatchHandler();
225
226 // Get the address of the top C++ try catch handler or NULL if
227 // none are registered.
228 //
229 // This method always returns an address that can be compared to
230 // pointers into the JavaScript stack. When running on actual
231 // hardware, try_catch_handler_address and TryCatchHandler return
232 // the same pointer. When running on a simulator with a separate JS
233 // stack, try_catch_handler_address returns a JS stack address that
234 // corresponds to the place on the JS stack where the C++ handler
235 // would have been if the stack were not separate.
236 inline Address try_catch_handler_address() {
237 return try_catch_handler_address_;
238 }
239
240 // Set the address of the top C++ try catch handler.
241 inline void set_try_catch_handler_address(Address address) {
242 try_catch_handler_address_ = address;
243 }
244
245 void Free() {
246 ASSERT(!has_pending_message_);
247 ASSERT(!external_caught_exception_);
248 ASSERT(try_catch_handler_address_ == NULL);
249 }
250
lrn@chromium.org1c092762011-05-09 09:42:16 +0000251 Isolate* isolate_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000252 // The context where the current execution method is created and for variable
253 // lookups.
254 Context* context_;
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +0000255 ThreadId thread_id_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000256 MaybeObject* pending_exception_;
257 bool has_pending_message_;
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000258 bool rethrowing_message_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000259 Object* pending_message_obj_;
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000260 Object* pending_message_script_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000261 int pending_message_start_pos_;
262 int pending_message_end_pos_;
263 // Use a separate value for scheduled exceptions to preserve the
264 // invariants that hold about pending_exception. We may want to
265 // unify them later.
266 MaybeObject* scheduled_exception_;
267 bool external_caught_exception_;
268 SaveContext* save_context_;
269 v8::TryCatch* catcher_;
270
271 // Stack.
272 Address c_entry_fp_; // the frame pointer of the top c entry frame
273 Address handler_; // try-blocks are chained through the stack
274
275#ifdef USE_SIMULATOR
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000276 Simulator* simulator_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000277#endif
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000278
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000279 Address js_entry_sp_; // the stack pointer of the bottom JS entry frame
yangguo@chromium.orgc73d55b2013-07-24 08:18:28 +0000280 // the external callback we're currently in
281 ExternalCallbackScope* external_callback_scope_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000282 StateTag current_vm_state_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000283
284 // Generated code scratch locations.
285 int32_t formal_count_;
286
287 // Call back function to report unsafe JS accesses.
288 v8::FailedAccessCheckCallback failed_access_check_callback_;
289
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000290 // Head of the list of live LookupResults.
291 LookupResult* top_lookup_result_;
292
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000293 // Whether out of memory exceptions should be ignored.
294 bool ignore_out_of_memory_;
295
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000296 private:
vitalyr@chromium.org5523ec32011-04-15 21:42:52 +0000297 void InitializeInternal();
298
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000299 Address try_catch_handler_address_;
300};
301
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000302
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000303class SystemThreadManager {
304 public:
305 enum ParallelSystemComponent {
306 PARALLEL_SWEEPING,
307 CONCURRENT_SWEEPING,
ulan@chromium.org750145a2013-03-07 15:14:13 +0000308 PARALLEL_RECOMPILATION
hpayer@chromium.org8432c912013-02-28 15:55:26 +0000309 };
310
311 static int NumberOfParallelSystemThreads(ParallelSystemComponent type);
312
313 static const int kMaxThreads = 4;
314};
315
316
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000317#ifdef ENABLE_DEBUGGER_SUPPORT
318
319#define ISOLATE_DEBUGGER_INIT_LIST(V) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000320 V(DebuggerAgent*, debugger_agent_instance, NULL)
321#else
322
323#define ISOLATE_DEBUGGER_INIT_LIST(V)
324
325#endif
326
327#ifdef DEBUG
328
329#define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) \
330 V(CommentStatistic, paged_space_comments_statistics, \
331 CommentStatistic::kMaxComments + 1)
332#else
333
334#define ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
335
336#endif
337
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000338#define ISOLATE_INIT_ARRAY_LIST(V) \
339 /* SerializerDeserializer state. */ \
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000340 V(int32_t, jsregexp_static_offsets_vector, kJSRegexpStaticOffsetsVectorSize) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000341 V(int, bad_char_shift_table, kUC16AlphabetSize) \
342 V(int, good_suffix_shift_table, (kBMMaxShift + 1)) \
343 V(int, suffix_table, (kBMMaxShift + 1)) \
ricow@chromium.org4f693d62011-07-04 14:01:31 +0000344 V(uint32_t, private_random_seed, 2) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000345 ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
346
rossberg@chromium.org400388e2012-06-06 09:29:22 +0000347typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000348
349#define ISOLATE_INIT_LIST(V) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000350 /* SerializerDeserializer state. */ \
351 V(int, serialize_partial_snapshot_cache_length, 0) \
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +0000352 V(int, serialize_partial_snapshot_cache_capacity, 0) \
353 V(Object**, serialize_partial_snapshot_cache, NULL) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000354 /* Assembler state. */ \
355 /* A previously allocated buffer of kMinimalBufferSize bytes, or NULL. */ \
356 V(byte*, assembler_spare_buffer, NULL) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000357 V(FatalErrorCallback, exception_behavior, NULL) \
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000358 V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, NULL) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000359 /* To distinguish the function templates, so that we can find them in the */ \
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000360 /* function cache of the native context. */ \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000361 V(int, next_serial_number, 0) \
362 V(ExternalReferenceRedirectorPointer*, external_reference_redirector, NULL) \
363 V(bool, always_allow_natives_syntax, false) \
364 /* Part of the state of liveedit. */ \
365 V(FunctionInfoListener*, active_function_info_listener, NULL) \
366 /* State for Relocatable. */ \
367 V(Relocatable*, relocatable_top, NULL) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000368 V(DebugObjectCache*, string_stream_debug_object_cache, NULL) \
369 V(Object*, string_stream_current_security_token, NULL) \
370 /* TODO(isolates): Release this on destruction? */ \
371 V(int*, irregexp_interpreter_backtrack_stack_cache, NULL) \
372 /* Serializer state. */ \
373 V(ExternalReferenceTable*, external_reference_table, NULL) \
374 /* AstNode state. */ \
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000375 V(int, ast_node_id, 0) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000376 V(unsigned, ast_node_count, 0) \
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000377 V(bool, observer_delivery_pending, false) \
ulan@chromium.org750145a2013-03-07 15:14:13 +0000378 V(HStatistics*, hstatistics, NULL) \
379 V(HTracer*, htracer, NULL) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000380 ISOLATE_DEBUGGER_INIT_LIST(V)
381
382class Isolate {
383 // These forward declarations are required to make the friend declarations in
384 // PerIsolateThreadData work on some older versions of gcc.
385 class ThreadDataTable;
386 class EntryStackItem;
387 public:
388 ~Isolate();
389
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000390 // A thread has a PerIsolateThreadData instance for each isolate that it has
391 // entered. That instance is allocated when the isolate is initially entered
392 // and reused on subsequent entries.
393 class PerIsolateThreadData {
394 public:
395 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id)
396 : isolate_(isolate),
397 thread_id_(thread_id),
398 stack_limit_(0),
399 thread_state_(NULL),
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000400#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
401 !defined(__mips__) && V8_TARGET_ARCH_MIPS
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000402 simulator_(NULL),
403#endif
404 next_(NULL),
405 prev_(NULL) { }
406 Isolate* isolate() const { return isolate_; }
407 ThreadId thread_id() const { return thread_id_; }
408 void set_stack_limit(uintptr_t value) { stack_limit_ = value; }
409 uintptr_t stack_limit() const { return stack_limit_; }
410 ThreadState* thread_state() const { return thread_state_; }
411 void set_thread_state(ThreadState* value) { thread_state_ = value; }
412
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000413#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
414 !defined(__mips__) && V8_TARGET_ARCH_MIPS
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000415 Simulator* simulator() const { return simulator_; }
416 void set_simulator(Simulator* simulator) {
417 simulator_ = simulator;
418 }
419#endif
420
421 bool Matches(Isolate* isolate, ThreadId thread_id) const {
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +0000422 return isolate_ == isolate && thread_id_.Equals(thread_id);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000423 }
424
425 private:
426 Isolate* isolate_;
427 ThreadId thread_id_;
428 uintptr_t stack_limit_;
429 ThreadState* thread_state_;
430
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000431#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
432 !defined(__mips__) && V8_TARGET_ARCH_MIPS
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000433 Simulator* simulator_;
434#endif
435
436 PerIsolateThreadData* next_;
437 PerIsolateThreadData* prev_;
438
439 friend class Isolate;
440 friend class ThreadDataTable;
441 friend class EntryStackItem;
442
443 DISALLOW_COPY_AND_ASSIGN(PerIsolateThreadData);
444 };
445
446
447 enum AddressId {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000448#define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
449 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +0000450#undef DECLARE_ENUM
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000451 kIsolateAddressCount
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000452 };
453
454 // Returns the PerIsolateThreadData for the current thread (or NULL if one is
455 // not currently set).
456 static PerIsolateThreadData* CurrentPerIsolateThreadData() {
457 return reinterpret_cast<PerIsolateThreadData*>(
danno@chromium.org8c0a43f2012-04-03 08:37:53 +0000458 Thread::GetThreadLocal(per_isolate_thread_data_key_));
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000459 }
460
461 // Returns the isolate inside which the current thread is running.
462 INLINE(static Isolate* Current()) {
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000463 Isolate* isolate = reinterpret_cast<Isolate*>(
danno@chromium.org8c0a43f2012-04-03 08:37:53 +0000464 Thread::GetExistingThreadLocal(isolate_key_));
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000465 ASSERT(isolate != NULL);
466 return isolate;
467 }
468
469 INLINE(static Isolate* UncheckedCurrent()) {
danno@chromium.org8c0a43f2012-04-03 08:37:53 +0000470 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key_));
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000471 }
472
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000473 // Usually called by Init(), but can be called early e.g. to allow
474 // testing components that require logging but not the whole
475 // isolate.
476 //
477 // Safe to call more than once.
478 void InitializeLoggingAndCounters();
479
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000480 bool Init(Deserializer* des);
481
482 bool IsInitialized() { return state_ == INITIALIZED; }
483
484 // True if at least one thread Enter'ed this isolate.
485 bool IsInUse() { return entry_stack_ != NULL; }
486
487 // Destroys the non-default isolates.
488 // Sets default isolate into "has_been_disposed" state rather then destroying,
489 // for legacy API reasons.
490 void TearDown();
491
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000492 static void GlobalTearDown();
493
danno@chromium.org8c0a43f2012-04-03 08:37:53 +0000494 bool IsDefaultIsolate() const { return this == default_isolate_; }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000495
machenbach@chromium.org528ce022013-09-23 14:09:36 +0000496 static void SetCrashIfDefaultIsolateInitialized();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000497 // Ensures that process-wide resources and the default isolate have been
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000498 // allocated. It is only necessary to call this method in rare cases, for
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000499 // example if you are using V8 from within the body of a static initializer.
500 // Safe to call multiple times.
501 static void EnsureDefaultIsolate();
502
lrn@chromium.org1c092762011-05-09 09:42:16 +0000503 // Find the PerThread for this particular (isolate, thread) combination
504 // If one does not yet exist, return null.
505 PerIsolateThreadData* FindPerThreadDataForThisThread();
506
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000507 // Find the PerThread for given (isolate, thread) combination
508 // If one does not yet exist, return null.
509 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
510
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000511#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000512 // Get the debugger from the default isolate. Preinitializes the
513 // default isolate if needed.
514 static Debugger* GetDefaultIsolateDebugger();
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000515#endif
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000516
517 // Get the stack guard from the default isolate. Preinitializes the
518 // default isolate if needed.
519 static StackGuard* GetDefaultIsolateStackGuard();
520
521 // Returns the key used to store the pointer to the current isolate.
522 // Used internally for V8 threads that do not execute JavaScript but still
523 // are part of the domain of an isolate (like the context switcher).
danno@chromium.org8c0a43f2012-04-03 08:37:53 +0000524 static Thread::LocalStorageKey isolate_key() {
525 return isolate_key_;
526 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000527
528 // Returns the key used to store process-wide thread IDs.
danno@chromium.org8c0a43f2012-04-03 08:37:53 +0000529 static Thread::LocalStorageKey thread_id_key() {
530 return thread_id_key_;
531 }
jkummerow@chromium.org1456e702012-03-30 08:38:13 +0000532
533 static Thread::LocalStorageKey per_isolate_thread_data_key();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000534
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000535 // If a client attempts to create a Locker without specifying an isolate,
536 // we assume that the client is using legacy behavior. Set up the current
537 // thread to be inside the implicit isolate (or fail a check if we have
538 // switched to non-legacy behavior).
539 static void EnterDefaultIsolate();
540
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000541 // Mutex for serializing access to break control structures.
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +0000542 RecursiveMutex* break_access() { return &break_access_; }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000543
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000544 // Mutex for serializing access to debugger.
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +0000545 RecursiveMutex* debugger_access() { return &debugger_access_; }
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000546
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000547 Address get_address_from_id(AddressId id);
548
549 // Access to top context (where the current function object was created).
550 Context* context() { return thread_local_top_.context_; }
551 void set_context(Context* context) {
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000552 ASSERT(context == NULL || context->IsContext());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000553 thread_local_top_.context_ = context;
554 }
555 Context** context_address() { return &thread_local_top_.context_; }
556
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +0000557 SaveContext* save_context() { return thread_local_top_.save_context_; }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000558 void set_save_context(SaveContext* save) {
559 thread_local_top_.save_context_ = save;
560 }
561
562 // Access to current thread id.
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +0000563 ThreadId thread_id() { return thread_local_top_.thread_id_; }
564 void set_thread_id(ThreadId id) { thread_local_top_.thread_id_ = id; }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000565
566 // Interface to pending exception.
567 MaybeObject* pending_exception() {
568 ASSERT(has_pending_exception());
569 return thread_local_top_.pending_exception_;
570 }
571 bool external_caught_exception() {
572 return thread_local_top_.external_caught_exception_;
573 }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000574 void set_external_caught_exception(bool value) {
575 thread_local_top_.external_caught_exception_ = value;
576 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000577 void set_pending_exception(MaybeObject* exception) {
578 thread_local_top_.pending_exception_ = exception;
579 }
580 void clear_pending_exception() {
581 thread_local_top_.pending_exception_ = heap_.the_hole_value();
582 }
583 MaybeObject** pending_exception_address() {
584 return &thread_local_top_.pending_exception_;
585 }
586 bool has_pending_exception() {
587 return !thread_local_top_.pending_exception_->IsTheHole();
588 }
589 void clear_pending_message() {
590 thread_local_top_.has_pending_message_ = false;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000591 thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000592 thread_local_top_.pending_message_script_ = heap_.the_hole_value();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000593 }
594 v8::TryCatch* try_catch_handler() {
595 return thread_local_top_.TryCatchHandler();
596 }
597 Address try_catch_handler_address() {
598 return thread_local_top_.try_catch_handler_address();
599 }
600 bool* external_caught_exception_address() {
601 return &thread_local_top_.external_caught_exception_;
602 }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000603 v8::TryCatch* catcher() {
604 return thread_local_top_.catcher_;
605 }
606 void set_catcher(v8::TryCatch* catcher) {
607 thread_local_top_.catcher_ = catcher;
608 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000609
610 MaybeObject** scheduled_exception_address() {
611 return &thread_local_top_.scheduled_exception_;
612 }
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000613
614 Address pending_message_obj_address() {
615 return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_);
616 }
617
618 Address has_pending_message_address() {
619 return reinterpret_cast<Address>(&thread_local_top_.has_pending_message_);
620 }
621
622 Address pending_message_script_address() {
623 return reinterpret_cast<Address>(
624 &thread_local_top_.pending_message_script_);
625 }
626
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000627 MaybeObject* scheduled_exception() {
628 ASSERT(has_scheduled_exception());
629 return thread_local_top_.scheduled_exception_;
630 }
631 bool has_scheduled_exception() {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000632 return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000633 }
634 void clear_scheduled_exception() {
635 thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
636 }
637
638 bool IsExternallyCaught();
639
640 bool is_catchable_by_javascript(MaybeObject* exception) {
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000641 return (!exception->IsOutOfMemory()) &&
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000642 (exception != heap()->termination_exception());
643 }
644
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +0000645 // Serializer.
646 void PushToPartialSnapshotCache(Object* obj);
647
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000648 // JS execution stack (see frames.h).
649 static Address c_entry_fp(ThreadLocalTop* thread) {
650 return thread->c_entry_fp_;
651 }
652 static Address handler(ThreadLocalTop* thread) { return thread->handler_; }
653
654 inline Address* c_entry_fp_address() {
655 return &thread_local_top_.c_entry_fp_;
656 }
657 inline Address* handler_address() { return &thread_local_top_.handler_; }
658
danno@chromium.org59400602013-08-13 17:09:37 +0000659 // Bottom JS entry.
660 Address js_entry_sp() {
661 return thread_local_top_.js_entry_sp_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000662 }
663 inline Address* js_entry_sp_address() {
664 return &thread_local_top_.js_entry_sp_;
665 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000666
667 // Generated code scratch locations.
668 void* formal_count_address() { return &thread_local_top_.formal_count_; }
669
670 // Returns the global object of the current context. It could be
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000671 // a builtin object, or a JS global object.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000672 Handle<GlobalObject> global_object() {
673 return Handle<GlobalObject>(context()->global_object());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000674 }
675
676 // Returns the global proxy object of the current context.
677 Object* global_proxy() {
678 return context()->global_proxy();
679 }
680
681 Handle<JSBuiltinsObject> js_builtins_object() {
682 return Handle<JSBuiltinsObject>(thread_local_top_.context_->builtins());
683 }
684
685 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); }
686 void FreeThreadResources() { thread_local_top_.Free(); }
687
688 // This method is called by the api after operations that may throw
689 // exceptions. If an exception was thrown and not handled by an external
690 // handler the exception is scheduled to be rethrown when we return to running
691 // JavaScript code. If an exception is scheduled true is returned.
692 bool OptionalRescheduleException(bool is_bottom_call);
693
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000694 class ExceptionScope {
695 public:
696 explicit ExceptionScope(Isolate* isolate) :
697 // Scope currently can only be used for regular exceptions, not
698 // failures like OOM or termination exception.
699 isolate_(isolate),
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000700 pending_exception_(isolate_->pending_exception()->ToObjectUnchecked(),
701 isolate_),
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000702 catcher_(isolate_->catcher())
703 { }
704
705 ~ExceptionScope() {
706 isolate_->set_catcher(catcher_);
707 isolate_->set_pending_exception(*pending_exception_);
708 }
709
710 private:
711 Isolate* isolate_;
712 Handle<Object> pending_exception_;
713 v8::TryCatch* catcher_;
714 };
715
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000716 void SetCaptureStackTraceForUncaughtExceptions(
717 bool capture,
718 int frame_limit,
719 StackTrace::StackTraceOptions options);
720
721 // Tells whether the current context has experienced an out of memory
722 // exception.
723 bool is_out_of_memory();
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000724 bool ignore_out_of_memory() {
725 return thread_local_top_.ignore_out_of_memory_;
726 }
727 void set_ignore_out_of_memory(bool value) {
728 thread_local_top_.ignore_out_of_memory_ = value;
729 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000730
731 void PrintCurrentStackTrace(FILE* out);
732 void PrintStackTrace(FILE* out, char* thread_data);
733 void PrintStack(StringStream* accumulator);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000734 void PrintStack(FILE* out);
danno@chromium.orgd3c42102013-08-01 16:58:23 +0000735 void PrintStack();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000736 Handle<String> StackTraceString();
jkummerow@chromium.org67255be2012-09-05 16:44:50 +0000737 NO_INLINE(void PushStackTraceAndDie(unsigned int magic,
738 Object* object,
739 Map* map,
740 unsigned int magic2));
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000741 Handle<JSArray> CaptureCurrentStackTrace(
742 int frame_limit,
743 StackTrace::StackTraceOptions options);
744
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +0000745 Handle<JSArray> CaptureSimpleStackTrace(Handle<JSObject> error_object,
746 Handle<Object> caller,
747 int limit);
748 void CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object);
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +0000749
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000750 // Returns if the top context may access the given global object. If
751 // the result is false, the pending exception is guaranteed to be
752 // set.
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +0000753
754 // TODO(yangguo): temporary wrappers
755 bool MayNamedAccessWrapper(Handle<JSObject> receiver,
756 Handle<Object> key,
757 v8::AccessType type) {
758 return MayNamedAccess(*receiver, *key, type);
759 }
760 bool MayIndexedAccessWrapper(Handle<JSObject> receiver,
761 uint32_t index,
762 v8::AccessType type) {
763 return MayIndexedAccess(*receiver, index, type);
764 }
765
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000766 bool MayNamedAccess(JSObject* receiver,
767 Object* key,
768 v8::AccessType type);
769 bool MayIndexedAccess(JSObject* receiver,
770 uint32_t index,
771 v8::AccessType type);
772
773 void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback);
774 void ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type);
775
776 // Exception throwing support. The caller should use the result
777 // of Throw() as its return value.
778 Failure* Throw(Object* exception, MessageLocation* location = NULL);
779 // Re-throw an exception. This involves no error reporting since
780 // error reporting was handled when the exception was thrown
781 // originally.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000782 Failure* ReThrow(MaybeObject* exception);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000783 void ScheduleThrow(Object* exception);
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +0000784 // Re-set pending message, script and positions reported to the TryCatch
785 // back to the TLS for re-use when rethrowing.
786 void RestorePendingMessageFromTryCatch(v8::TryCatch* handler);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000787 void ReportPendingMessages();
mmassi@chromium.org49a44672012-12-04 13:52:03 +0000788 // Return pending location if any or unfilled structure.
789 MessageLocation GetMessageLocation();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000790 Failure* ThrowIllegalOperation();
791
792 // Promote a scheduled exception to pending. Asserts has_scheduled_exception.
793 Failure* PromoteScheduledException();
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +0000794 void DoThrow(Object* exception, MessageLocation* location);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000795 // Checks if exception should be reported and finds out if it's
796 // caught externally.
797 bool ShouldReportException(bool* can_be_caught_externally,
798 bool catchable_by_javascript);
799
800 // Attempts to compute the current source location, storing the
801 // result in the target out parameter.
802 void ComputeLocation(MessageLocation* target);
803
804 // Override command line flag.
805 void TraceException(bool flag);
806
807 // Out of resource exception helpers.
808 Failure* StackOverflow();
809 Failure* TerminateExecution();
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000810 void CancelTerminateExecution();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000811
812 // Administration
813 void Iterate(ObjectVisitor* v);
814 void Iterate(ObjectVisitor* v, ThreadLocalTop* t);
815 char* Iterate(ObjectVisitor* v, char* t);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000816 void IterateThread(ThreadVisitor* v, char* t);
817
818
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000819 // Returns the current native and global context.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000820 Handle<Context> native_context();
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000821 Handle<Context> global_context();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000822
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000823 // Returns the native context of the calling JavaScript code. That
824 // is, the native context of the top-most JavaScript frame.
825 Handle<Context> GetCallingNativeContext();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000826
827 void RegisterTryCatchHandler(v8::TryCatch* that);
828 void UnregisterTryCatchHandler(v8::TryCatch* that);
829
830 char* ArchiveThread(char* to);
831 char* RestoreThread(char* from);
832
833 static const char* const kStackOverflowMessage;
834
835 static const int kUC16AlphabetSize = 256; // See StringSearchBase.
836 static const int kBMMaxShift = 250; // See StringSearchBase.
837
838 // Accessors.
839#define GLOBAL_ACCESSOR(type, name, initialvalue) \
840 inline type name() const { \
841 ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
842 return name##_; \
843 } \
844 inline void set_##name(type value) { \
845 ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
846 name##_ = value; \
847 }
848 ISOLATE_INIT_LIST(GLOBAL_ACCESSOR)
849#undef GLOBAL_ACCESSOR
850
851#define GLOBAL_ARRAY_ACCESSOR(type, name, length) \
852 inline type* name() { \
853 ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
854 return &(name##_)[0]; \
855 }
856 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR)
857#undef GLOBAL_ARRAY_ACCESSOR
858
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000859#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \
860 Handle<type> name() { \
861 return Handle<type>(context()->native_context()->name(), this); \
ulan@chromium.org906e2fb2013-05-14 08:14:38 +0000862 } \
863 bool is_##name(type* value) { \
864 return context()->native_context()->is_##name(value); \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000865 }
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000866 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
867#undef NATIVE_CONTEXT_FIELD_ACCESSOR
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000868
869 Bootstrapper* bootstrapper() { return bootstrapper_; }
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000870 Counters* counters() {
871 // Call InitializeLoggingAndCounters() if logging is needed before
872 // the isolate is fully initialized.
873 ASSERT(counters_ != NULL);
874 return counters_;
875 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000876 CodeRange* code_range() { return code_range_; }
877 RuntimeProfiler* runtime_profiler() { return runtime_profiler_; }
878 CompilationCache* compilation_cache() { return compilation_cache_; }
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000879 Logger* logger() {
880 // Call InitializeLoggingAndCounters() if logging is needed before
881 // the isolate is fully initialized.
882 ASSERT(logger_ != NULL);
883 return logger_;
884 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000885 StackGuard* stack_guard() { return &stack_guard_; }
886 Heap* heap() { return &heap_; }
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000887 StatsTable* stats_table();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000888 StubCache* stub_cache() { return stub_cache_; }
889 DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; }
890 ThreadLocalTop* thread_local_top() { return &thread_local_top_; }
891
892 TranscendentalCache* transcendental_cache() const {
893 return transcendental_cache_;
894 }
895
896 MemoryAllocator* memory_allocator() {
897 return memory_allocator_;
898 }
899
900 KeyedLookupCache* keyed_lookup_cache() {
901 return keyed_lookup_cache_;
902 }
903
904 ContextSlotCache* context_slot_cache() {
905 return context_slot_cache_;
906 }
907
908 DescriptorLookupCache* descriptor_lookup_cache() {
909 return descriptor_lookup_cache_;
910 }
911
912 v8::ImplementationUtilities::HandleScopeData* handle_scope_data() {
913 return &handle_scope_data_;
914 }
915 HandleScopeImplementer* handle_scope_implementer() {
916 ASSERT(handle_scope_implementer_);
917 return handle_scope_implementer_;
918 }
machenbach@chromium.orgc1789ee2013-07-05 07:09:57 +0000919 Zone* runtime_zone() { return &runtime_zone_; }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000920
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +0000921 UnicodeCache* unicode_cache() {
922 return unicode_cache_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000923 }
924
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000925 InnerPointerToCodeCache* inner_pointer_to_code_cache() {
926 return inner_pointer_to_code_cache_;
927 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000928
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000929 ConsStringIteratorOp* write_iterator() { return write_iterator_; }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000930
931 GlobalHandles* global_handles() { return global_handles_; }
932
danno@chromium.org59400602013-08-13 17:09:37 +0000933 EternalHandles* eternal_handles() { return eternal_handles_; }
934
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000935 ThreadManager* thread_manager() { return thread_manager_; }
936
937 ContextSwitcher* context_switcher() { return context_switcher_; }
938
939 void set_context_switcher(ContextSwitcher* switcher) {
940 context_switcher_ = switcher;
941 }
942
943 StringTracker* string_tracker() { return string_tracker_; }
944
945 unibrow::Mapping<unibrow::Ecma262UnCanonicalize>* jsregexp_uncanonicalize() {
946 return &jsregexp_uncanonicalize_;
947 }
948
949 unibrow::Mapping<unibrow::CanonicalizationRange>* jsregexp_canonrange() {
950 return &jsregexp_canonrange_;
951 }
952
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000953 ConsStringIteratorOp* objects_string_compare_iterator_a() {
954 return &objects_string_compare_iterator_a_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000955 }
956
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000957 ConsStringIteratorOp* objects_string_compare_iterator_b() {
958 return &objects_string_compare_iterator_b_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000959 }
960
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +0000961 StaticResource<ConsStringIteratorOp>* objects_string_iterator() {
962 return &objects_string_iterator_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000963 }
964
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000965 RuntimeState* runtime_state() { return &runtime_state_; }
966
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000967 void set_fp_stubs_generated(bool value) {
968 fp_stubs_generated_ = value;
969 }
970
971 bool fp_stubs_generated() { return fp_stubs_generated_; }
972
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000973 Builtins* builtins() { return &builtins_; }
974
ricow@chromium.org27bf2882011-11-17 08:34:43 +0000975 void NotifyExtensionInstalled() {
976 has_installed_extensions_ = true;
977 }
978
979 bool has_installed_extensions() { return has_installed_extensions_; }
980
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000981 unibrow::Mapping<unibrow::Ecma262Canonicalize>*
982 regexp_macro_assembler_canonicalize() {
983 return &regexp_macro_assembler_canonicalize_;
984 }
985
986 RegExpStack* regexp_stack() { return regexp_stack_; }
987
988 unibrow::Mapping<unibrow::Ecma262Canonicalize>*
989 interp_canonicalize_mapping() {
990 return &interp_canonicalize_mapping_;
991 }
992
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000993 void* PreallocatedStorageNew(size_t size);
994 void PreallocatedStorageDelete(void* p);
995 void PreallocatedStorageInit(size_t size);
996
997#ifdef ENABLE_DEBUGGER_SUPPORT
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000998 Debugger* debugger() {
999 if (!NoBarrier_Load(&debugger_initialized_)) InitializeDebugger();
1000 return debugger_;
1001 }
1002 Debug* debug() {
1003 if (!NoBarrier_Load(&debugger_initialized_)) InitializeDebugger();
1004 return debug_;
1005 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001006#endif
1007
danno@chromium.org88aa0582012-03-23 15:11:57 +00001008 inline bool IsDebuggerActive();
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00001009 inline bool DebuggerHasBreakPoints();
1010
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00001011 CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
1012 HeapProfiler* heap_profiler() const { return heap_profiler_; }
1013
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001014#ifdef DEBUG
1015 HistogramInfo* heap_histograms() { return heap_histograms_; }
1016
1017 JSObject::SpillInformation* js_spill_information() {
1018 return &js_spill_information_;
1019 }
1020
1021 int* code_kind_statistics() { return code_kind_statistics_; }
1022#endif
1023
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +00001024#if V8_TARGET_ARCH_ARM && !defined(__arm__) || \
1025 V8_TARGET_ARCH_MIPS && !defined(__mips__)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001026 bool simulator_initialized() { return simulator_initialized_; }
1027 void set_simulator_initialized(bool initialized) {
1028 simulator_initialized_ = initialized;
1029 }
1030
1031 HashMap* simulator_i_cache() { return simulator_i_cache_; }
1032 void set_simulator_i_cache(HashMap* hash_map) {
1033 simulator_i_cache_ = hash_map;
1034 }
1035
1036 Redirection* simulator_redirection() {
1037 return simulator_redirection_;
1038 }
1039 void set_simulator_redirection(Redirection* redirection) {
1040 simulator_redirection_ = redirection;
1041 }
1042#endif
1043
1044 Factory* factory() { return reinterpret_cast<Factory*>(this); }
1045
mstarzinger@chromium.org15613d02012-05-23 12:04:37 +00001046 static const int kJSRegexpStaticOffsetsVectorSize = 128;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001047
yangguo@chromium.orgc73d55b2013-07-24 08:18:28 +00001048 ExternalCallbackScope* external_callback_scope() {
1049 return thread_local_top_.external_callback_scope_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001050 }
yangguo@chromium.orgc73d55b2013-07-24 08:18:28 +00001051 void set_external_callback_scope(ExternalCallbackScope* scope) {
1052 thread_local_top_.external_callback_scope_ = scope;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001053 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001054
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001055 StateTag current_vm_state() {
1056 return thread_local_top_.current_vm_state_;
1057 }
1058
danno@chromium.orgca29dd82013-04-26 11:59:48 +00001059 void set_current_vm_state(StateTag state) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001060 thread_local_top_.current_vm_state_ = state;
1061 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001062
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001063 void SetData(void* data) { embedder_data_ = data; }
1064 void* GetData() { return embedder_data_; }
1065
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001066 LookupResult* top_lookup_result() {
1067 return thread_local_top_.top_lookup_result_;
1068 }
1069 void SetTopLookupResult(LookupResult* top) {
1070 thread_local_top_.top_lookup_result_ = top;
1071 }
1072
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +00001073 bool IsDead() { return has_fatal_error_; }
1074 void SignalFatalError() { has_fatal_error_ = true; }
1075
1076 bool use_crankshaft() const { return use_crankshaft_; }
1077
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001078 bool initialized_from_snapshot() { return initialized_from_snapshot_; }
1079
rossberg@chromium.org994edf62012-02-06 10:12:55 +00001080 double time_millis_since_init() {
1081 return OS::TimeCurrentMillis() - time_millis_at_init_;
1082 }
1083
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00001084 DateCache* date_cache() {
1085 return date_cache_;
1086 }
1087
1088 void set_date_cache(DateCache* date_cache) {
1089 if (date_cache != date_cache_) {
1090 delete date_cache_;
1091 }
1092 date_cache_ = date_cache;
1093 }
1094
ulan@chromium.org906e2fb2013-05-14 08:14:38 +00001095 Map* get_initial_js_array_map(ElementsKind kind);
1096
1097 bool IsFastArrayConstructorPrototypeChainIntact();
1098
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00001099 CodeStubInterfaceDescriptor*
1100 code_stub_interface_descriptor(int index);
1101
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001102 void IterateDeferredHandles(ObjectVisitor* visitor);
1103 void LinkDeferredHandles(DeferredHandles* deferred_handles);
1104 void UnlinkDeferredHandles(DeferredHandles* deferred_handles);
1105
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001106#ifdef DEBUG
1107 bool IsDeferredHandle(Object** location);
1108#endif // DEBUG
1109
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001110 OptimizingCompilerThread* optimizing_compiler_thread() {
machenbach@chromium.org8e36b5b2013-09-26 07:36:30 +00001111 return optimizing_compiler_thread_;
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001112 }
1113
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001114 // PreInits and returns a default isolate. Needed when a new thread tries
1115 // to create a Locker for the first time (the lock itself is in the isolate).
1116 // TODO(svenpanne) This method is on death row...
1117 static v8::Isolate* GetDefaultIsolateForLocking();
1118
mstarzinger@chromium.orge3b8d0f2013-02-01 09:06:41 +00001119 SweeperThread** sweeper_threads() {
1120 return sweeper_thread_;
1121 }
1122
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001123 int id() const { return static_cast<int>(id_); }
1124
ulan@chromium.org750145a2013-03-07 15:14:13 +00001125 HStatistics* GetHStatistics();
1126 HTracer* GetHTracer();
1127
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001128 FunctionEntryHook function_entry_hook() { return function_entry_hook_; }
1129 void set_function_entry_hook(FunctionEntryHook function_entry_hook) {
1130 function_entry_hook_ = function_entry_hook;
1131 }
1132
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +00001133 void* stress_deopt_count_address() { return &stress_deopt_count_; }
1134
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +00001135 inline RandomNumberGenerator* random_number_generator();
1136
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +00001137 // Given an address occupied by a live code object, return that object.
1138 Object* FindCodeObject(Address a);
1139
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001140 private:
1141 Isolate();
1142
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001143 friend struct GlobalState;
1144 friend struct InitializeGlobalState;
1145
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00001146 enum State {
1147 UNINITIALIZED, // Some components may not have been allocated.
1148 INITIALIZED // All components are fully initialized.
1149 };
1150
1151 // These fields are accessed through the API, offsets must be kept in sync
1152 // with v8::internal::Internals (in include/v8.h) constants. This is also
1153 // verified in Isolate::Init() using runtime checks.
1154 State state_; // Will be padded to kApiPointerSize.
1155 void* embedder_data_;
1156 Heap heap_;
1157
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001158 // The per-process lock should be acquired before the ThreadDataTable is
1159 // modified.
1160 class ThreadDataTable {
1161 public:
1162 ThreadDataTable();
1163 ~ThreadDataTable();
1164
1165 PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id);
1166 void Insert(PerIsolateThreadData* data);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001167 void Remove(PerIsolateThreadData* data);
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00001168 void RemoveAllThreads(Isolate* isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001169
1170 private:
1171 PerIsolateThreadData* list_;
1172 };
1173
1174 // These items form a stack synchronously with threads Enter'ing and Exit'ing
1175 // the Isolate. The top of the stack points to a thread which is currently
1176 // running the Isolate. When the stack is empty, the Isolate is considered
1177 // not entered by any thread and can be Disposed.
1178 // If the same thread enters the Isolate more then once, the entry_count_
1179 // is incremented rather then a new item pushed to the stack.
1180 class EntryStackItem {
1181 public:
1182 EntryStackItem(PerIsolateThreadData* previous_thread_data,
1183 Isolate* previous_isolate,
1184 EntryStackItem* previous_item)
1185 : entry_count(1),
1186 previous_thread_data(previous_thread_data),
1187 previous_isolate(previous_isolate),
1188 previous_item(previous_item) { }
1189
1190 int entry_count;
1191 PerIsolateThreadData* previous_thread_data;
1192 Isolate* previous_isolate;
1193 EntryStackItem* previous_item;
1194
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001195 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001196 DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1197 };
1198
danno@chromium.org8c0a43f2012-04-03 08:37:53 +00001199 // This mutex protects highest_thread_id_, thread_data_table_ and
1200 // default_isolate_.
dslomov@chromium.org639bac02013-09-09 11:58:54 +00001201 static Mutex process_wide_mutex_;
danno@chromium.org8c0a43f2012-04-03 08:37:53 +00001202
1203 static Thread::LocalStorageKey per_isolate_thread_data_key_;
1204 static Thread::LocalStorageKey isolate_key_;
1205 static Thread::LocalStorageKey thread_id_key_;
1206 static Isolate* default_isolate_;
1207 static ThreadDataTable* thread_data_table_;
1208
ulan@chromium.org750145a2013-03-07 15:14:13 +00001209 // A global counter for all generated Isolates, might overflow.
1210 static Atomic32 isolate_counter_;
1211
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001212 void Deinit();
1213
1214 static void SetIsolateThreadLocals(Isolate* isolate,
1215 PerIsolateThreadData* data);
1216
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001217 // Find the PerThread for this particular (isolate, thread) combination.
1218 // If one does not yet exist, allocate a new one.
1219 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread();
1220
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001221 // Initializes the current thread to run this Isolate.
1222 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1223 // at the same time, this should be prevented using external locking.
1224 void Enter();
1225
1226 // Exits the current thread. The previosuly entered Isolate is restored
1227 // for the thread.
1228 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1229 // at the same time, this should be prevented using external locking.
1230 void Exit();
1231
1232 void PreallocatedMemoryThreadStart();
1233 void PreallocatedMemoryThreadStop();
1234 void InitializeThreadLocal();
1235
1236 void PrintStackTrace(FILE* out, ThreadLocalTop* thread);
1237 void MarkCompactPrologue(bool is_compacting,
1238 ThreadLocalTop* archived_thread_data);
1239 void MarkCompactEpilogue(bool is_compacting,
1240 ThreadLocalTop* archived_thread_data);
1241
1242 void FillCache();
1243
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001244 void PropagatePendingExceptionToExternalTryCatch();
1245
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00001246 void InitializeDebugger();
1247
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +00001248 // Traverse prototype chain to find out whether the object is derived from
1249 // the Error object.
1250 bool IsErrorObject(Handle<Object> obj);
1251
ulan@chromium.org750145a2013-03-07 15:14:13 +00001252 Atomic32 id_;
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00001253 EntryStackItem* entry_stack_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001254 int stack_trace_nesting_level_;
1255 StringStream* incomplete_message_;
1256 // The preallocated memory thread singleton.
1257 PreallocatedMemoryThread* preallocated_memory_thread_;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00001258 Address isolate_addresses_[kIsolateAddressCount + 1]; // NOLINT
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001259 NoAllocationStringAllocator* preallocated_message_space_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001260 Bootstrapper* bootstrapper_;
1261 RuntimeProfiler* runtime_profiler_;
1262 CompilationCache* compilation_cache_;
1263 Counters* counters_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001264 CodeRange* code_range_;
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001265 RecursiveMutex break_access_;
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00001266 Atomic32 debugger_initialized_;
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001267 RecursiveMutex debugger_access_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001268 Logger* logger_;
1269 StackGuard stack_guard_;
1270 StatsTable* stats_table_;
1271 StubCache* stub_cache_;
1272 DeoptimizerData* deoptimizer_data_;
1273 ThreadLocalTop thread_local_top_;
1274 bool capture_stack_trace_for_uncaught_exceptions_;
1275 int stack_trace_for_uncaught_exceptions_frame_limit_;
1276 StackTrace::StackTraceOptions stack_trace_for_uncaught_exceptions_options_;
1277 TranscendentalCache* transcendental_cache_;
1278 MemoryAllocator* memory_allocator_;
1279 KeyedLookupCache* keyed_lookup_cache_;
1280 ContextSlotCache* context_slot_cache_;
1281 DescriptorLookupCache* descriptor_lookup_cache_;
1282 v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
1283 HandleScopeImplementer* handle_scope_implementer_;
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +00001284 UnicodeCache* unicode_cache_;
machenbach@chromium.orgc1789ee2013-07-05 07:09:57 +00001285 Zone runtime_zone_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001286 PreallocatedStorage in_use_list_;
1287 PreallocatedStorage free_list_;
1288 bool preallocated_storage_preallocated_;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001289 InnerPointerToCodeCache* inner_pointer_to_code_cache_;
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +00001290 ConsStringIteratorOp* write_iterator_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001291 GlobalHandles* global_handles_;
danno@chromium.org59400602013-08-13 17:09:37 +00001292 EternalHandles* eternal_handles_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001293 ContextSwitcher* context_switcher_;
1294 ThreadManager* thread_manager_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001295 RuntimeState runtime_state_;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001296 bool fp_stubs_generated_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001297 Builtins builtins_;
ricow@chromium.org27bf2882011-11-17 08:34:43 +00001298 bool has_installed_extensions_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001299 StringTracker* string_tracker_;
1300 unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_;
1301 unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_;
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +00001302 ConsStringIteratorOp objects_string_compare_iterator_a_;
1303 ConsStringIteratorOp objects_string_compare_iterator_b_;
1304 StaticResource<ConsStringIteratorOp> objects_string_iterator_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001305 unibrow::Mapping<unibrow::Ecma262Canonicalize>
1306 regexp_macro_assembler_canonicalize_;
1307 RegExpStack* regexp_stack_;
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00001308 DateCache* date_cache_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001309 unibrow::Mapping<unibrow::Ecma262Canonicalize> interp_canonicalize_mapping_;
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00001310 CodeStubInterfaceDescriptor* code_stub_interface_descriptors_;
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +00001311 RandomNumberGenerator* random_number_generator_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001312
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +00001313 // True if fatal error has been signaled for this isolate.
1314 bool has_fatal_error_;
1315
1316 // True if we are using the Crankshaft optimizing compiler.
1317 bool use_crankshaft_;
1318
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001319 // True if this isolate was initialized from a snapshot.
1320 bool initialized_from_snapshot_;
1321
rossberg@chromium.org994edf62012-02-06 10:12:55 +00001322 // Time stamp at initialization.
1323 double time_millis_at_init_;
1324
jkummerow@chromium.org93a47f42013-07-02 14:43:41 +00001325#if V8_TARGET_ARCH_ARM && !defined(__arm__) || \
1326 V8_TARGET_ARCH_MIPS && !defined(__mips__)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001327 bool simulator_initialized_;
1328 HashMap* simulator_i_cache_;
1329 Redirection* simulator_redirection_;
1330#endif
1331
1332#ifdef DEBUG
1333 // A static array of histogram info for each type.
1334 HistogramInfo heap_histograms_[LAST_TYPE + 1];
1335 JSObject::SpillInformation js_spill_information_;
1336 int code_kind_statistics_[Code::NUMBER_OF_KINDS];
1337#endif
1338
1339#ifdef ENABLE_DEBUGGER_SUPPORT
1340 Debugger* debugger_;
1341 Debug* debug_;
1342#endif
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00001343 CpuProfiler* cpu_profiler_;
1344 HeapProfiler* heap_profiler_;
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001345 FunctionEntryHook function_entry_hook_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001346
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001347#define GLOBAL_BACKING_STORE(type, name, initialvalue) \
1348 type name##_;
1349 ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE)
1350#undef GLOBAL_BACKING_STORE
1351
1352#define GLOBAL_ARRAY_BACKING_STORE(type, name, length) \
1353 type name##_[length];
1354 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE)
1355#undef GLOBAL_ARRAY_BACKING_STORE
1356
1357#ifdef DEBUG
1358 // This class is huge and has a number of fields controlled by
1359 // preprocessor defines. Make sure the offsets of these fields agree
1360 // between compilation units.
1361#define ISOLATE_FIELD_OFFSET(type, name, ignored) \
1362 static const intptr_t name##_debug_offset_;
1363 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
1364 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
1365#undef ISOLATE_FIELD_OFFSET
1366#endif
1367
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001368 DeferredHandles* deferred_handles_head_;
machenbach@chromium.org8e36b5b2013-09-26 07:36:30 +00001369 OptimizingCompilerThread* optimizing_compiler_thread_;
mstarzinger@chromium.orge3b8d0f2013-02-01 09:06:41 +00001370 SweeperThread** sweeper_thread_;
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001371
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +00001372 // Counts deopt points if deopt_every_n_times is enabled.
1373 unsigned int stress_deopt_count_;
1374
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001375 friend class ExecutionAccess;
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001376 friend class HandleScopeImplementer;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001377 friend class IsolateInitializer;
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001378 friend class OptimizingCompilerThread;
mstarzinger@chromium.orge3b8d0f2013-02-01 09:06:41 +00001379 friend class SweeperThread;
lrn@chromium.org1c092762011-05-09 09:42:16 +00001380 friend class ThreadManager;
1381 friend class Simulator;
1382 friend class StackGuard;
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +00001383 friend class ThreadId;
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00001384 friend class TestMemoryAllocatorScope;
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +00001385 friend class TestCodeRangeScope;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001386 friend class v8::Isolate;
1387 friend class v8::Locker;
lrn@chromium.org1c092762011-05-09 09:42:16 +00001388 friend class v8::Unlocker;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001389
1390 DISALLOW_COPY_AND_ASSIGN(Isolate);
1391};
1392
1393
1394// If the GCC version is 4.1.x or 4.2.x an additional field is added to the
1395// class as a work around for a bug in the generated code found with these
1396// versions of GCC. See V8 issue 122 for details.
1397class SaveContext BASE_EMBEDDED {
1398 public:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001399 inline explicit SaveContext(Isolate* isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001400
1401 ~SaveContext() {
jkummerow@chromium.org3d00d0a2013-09-04 13:57:32 +00001402 isolate_->set_context(context_.is_null() ? NULL : *context_);
1403 isolate_->set_save_context(prev_);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001404 }
1405
1406 Handle<Context> context() { return context_; }
1407 SaveContext* prev() { return prev_; }
1408
1409 // Returns true if this save context is below a given JavaScript frame.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001410 bool IsBelowFrame(JavaScriptFrame* frame) {
1411 return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001412 }
1413
1414 private:
jkummerow@chromium.org3d00d0a2013-09-04 13:57:32 +00001415 Isolate* isolate_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001416 Handle<Context> context_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001417 SaveContext* prev_;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001418 Address c_entry_fp_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001419};
1420
1421
1422class AssertNoContextChange BASE_EMBEDDED {
1423#ifdef DEBUG
1424 public:
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +00001425 explicit AssertNoContextChange(Isolate* isolate)
1426 : isolate_(isolate),
1427 context_(isolate->context(), isolate) { }
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001428 ~AssertNoContextChange() {
dslomov@chromium.orge97852d2013-09-12 09:02:59 +00001429 ASSERT(isolate_->context() == *context_);
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001430 }
1431
1432 private:
dslomov@chromium.orge97852d2013-09-12 09:02:59 +00001433 Isolate* isolate_;
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001434 Handle<Context> context_;
1435#else
1436 public:
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +00001437 explicit AssertNoContextChange(Isolate* isolate) { }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001438#endif
1439};
1440
1441
1442class ExecutionAccess BASE_EMBEDDED {
1443 public:
1444 explicit ExecutionAccess(Isolate* isolate) : isolate_(isolate) {
1445 Lock(isolate);
1446 }
1447 ~ExecutionAccess() { Unlock(isolate_); }
1448
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001449 static void Lock(Isolate* isolate) { isolate->break_access()->Lock(); }
1450 static void Unlock(Isolate* isolate) { isolate->break_access()->Unlock(); }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001451
1452 static bool TryLock(Isolate* isolate) {
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001453 return isolate->break_access()->TryLock();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001454 }
1455
1456 private:
1457 Isolate* isolate_;
1458};
1459
1460
1461// Support for checking for stack-overflows in C++ code.
1462class StackLimitCheck BASE_EMBEDDED {
1463 public:
1464 explicit StackLimitCheck(Isolate* isolate) : isolate_(isolate) { }
1465
1466 bool HasOverflowed() const {
1467 StackGuard* stack_guard = isolate_->stack_guard();
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00001468 return (reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001469 }
1470 private:
1471 Isolate* isolate_;
1472};
1473
1474
1475// Support for temporarily postponing interrupts. When the outermost
1476// postpone scope is left the interrupts will be re-enabled and any
1477// interrupts that occurred while in the scope will be taken into
1478// account.
1479class PostponeInterruptsScope BASE_EMBEDDED {
1480 public:
1481 explicit PostponeInterruptsScope(Isolate* isolate)
1482 : stack_guard_(isolate->stack_guard()) {
1483 stack_guard_->thread_local_.postpone_interrupts_nesting_++;
1484 stack_guard_->DisableInterrupts();
1485 }
1486
1487 ~PostponeInterruptsScope() {
1488 if (--stack_guard_->thread_local_.postpone_interrupts_nesting_ == 0) {
1489 stack_guard_->EnableInterrupts();
1490 }
1491 }
1492 private:
1493 StackGuard* stack_guard_;
1494};
1495
1496
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00001497// Tells whether the native context is marked with out of memory.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001498inline bool Context::has_out_of_memory() {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00001499 return native_context()->out_of_memory()->IsTrue();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001500}
1501
1502
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00001503// Mark the native context with out of memory.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001504inline void Context::mark_out_of_memory() {
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +00001505 native_context()->set_out_of_memory(GetIsolate()->heap()->true_value());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001506}
1507
1508
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001509} } // namespace v8::internal
1510
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001511#endif // V8_ISOLATE_H_