1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "include/v8-debug.h"
9 #include "src/allocation.h"
10 #include "src/assert-scope.h"
11 #include "src/base/atomicops.h"
12 #include "src/builtins.h"
13 #include "src/contexts.h"
15 #include "src/execution.h"
16 #include "src/frames.h"
17 #include "src/global-handles.h"
18 #include "src/handles.h"
19 #include "src/hashmap.h"
20 #include "src/heap/heap.h"
21 #include "src/optimizing-compiler-thread.h"
22 #include "src/regexp-stack.h"
23 #include "src/runtime.h"
24 #include "src/runtime-profiler.h"
30 class RandomNumberGenerator;
36 class CallInterfaceDescriptorData;
39 class CodeStubDescriptor;
41 class CompilationCache;
42 class ConsStringIteratorOp;
43 class ContextSlotCache;
47 class DeoptimizerData;
50 class ExternalCallbackScope;
51 class ExternalReferenceTable;
53 class FunctionInfoListener;
54 class HandleScopeImplementer;
58 class InlineRuntimeFunctionsTable;
59 class InnerPointerToCodeCache;
60 class MaterializedObjectStore;
61 class CodeAgingHelper;
69 class ThreadVisitor; // Defined in v8threads.h
71 template <StateTag Tag> class VMState;
73 // 'void function pointer', used to roundtrip the
74 // ExternalReference::ExternalReferenceRedirector since we can not include
75 // assembler.h, where it is defined, here.
76 typedef void* ExternalReferenceRedirectorPointer();
83 #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
84 !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
85 !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
86 !defined(__mips__) && V8_TARGET_ARCH_MIPS64
92 // Static indirection table for handles to constants. If a frame
93 // element represents a constant, the data contains an index into
94 // this table of handles to the actual constants.
95 // Static indirection table for handles to constants. If a Result
96 // represents a constant, the data contains an index into this table
97 // of handles to the actual constants.
98 typedef ZoneList<Handle<Object> > ZoneObjectList;
100 #define RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate) \
102 Isolate* __isolate__ = (isolate); \
103 if (__isolate__->has_scheduled_exception()) { \
104 return __isolate__->PromoteScheduledException(); \
108 // Macros for MaybeHandle.
110 #define RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, value) \
112 Isolate* __isolate__ = (isolate); \
113 if (__isolate__->has_scheduled_exception()) { \
114 __isolate__->PromoteScheduledException(); \
119 #define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \
120 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, MaybeHandle<T>())
122 #define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \
124 if (!(call).ToHandle(&dst)) { \
125 DCHECK((isolate)->has_pending_exception()); \
130 #define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call) \
131 ASSIGN_RETURN_ON_EXCEPTION_VALUE( \
132 isolate, dst, call, isolate->heap()->exception())
134 #define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T) \
135 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, MaybeHandle<T>())
137 #define THROW_NEW_ERROR(isolate, call, T) \
139 Handle<Object> __error__; \
140 ASSIGN_RETURN_ON_EXCEPTION(isolate, __error__, isolate->factory()->call, \
142 return isolate->Throw<T>(__error__); \
145 #define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call) \
147 Handle<Object> __error__; \
148 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, __error__, \
149 isolate->factory()->call); \
150 return isolate->Throw(*__error__); \
153 #define RETURN_ON_EXCEPTION_VALUE(isolate, call, value) \
155 if ((call).is_null()) { \
156 DCHECK((isolate)->has_pending_exception()); \
161 #define RETURN_FAILURE_ON_EXCEPTION(isolate, call) \
162 RETURN_ON_EXCEPTION_VALUE(isolate, call, isolate->heap()->exception())
164 #define RETURN_ON_EXCEPTION(isolate, call, T) \
165 RETURN_ON_EXCEPTION_VALUE(isolate, call, MaybeHandle<T>())
168 #define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \
169 C(Handler, handler) \
170 C(CEntryFP, c_entry_fp) \
171 C(Context, context) \
172 C(PendingException, pending_exception) \
173 C(ExternalCaughtException, external_caught_exception) \
174 C(JSEntrySP, js_entry_sp)
177 // Platform-independent, reliable thread identifier.
180 // Creates an invalid ThreadId.
181 ThreadId() : id_(kInvalidId) {}
183 // Returns ThreadId for current thread.
184 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); }
186 // Returns invalid ThreadId (guaranteed not to be equal to any thread).
187 static ThreadId Invalid() { return ThreadId(kInvalidId); }
189 // Compares ThreadIds for equality.
190 INLINE(bool Equals(const ThreadId& other) const) {
191 return id_ == other.id_;
194 // Checks whether this ThreadId refers to any thread.
195 INLINE(bool IsValid() const) {
196 return id_ != kInvalidId;
199 // Converts ThreadId to an integer representation
200 // (required for public API: V8::V8::GetCurrentThreadId).
201 int ToInteger() const { return id_; }
203 // Converts ThreadId to an integer representation
204 // (required for public API: V8::V8::TerminateExecution).
205 static ThreadId FromInteger(int id) { return ThreadId(id); }
208 static const int kInvalidId = -1;
210 explicit ThreadId(int id) : id_(id) {}
212 static int AllocateThreadId();
214 static int GetCurrentThreadId();
218 static base::Atomic32 highest_thread_id_;
220 friend class Isolate;
224 #define FIELD_ACCESSOR(type, name) \
225 inline void set_##name(type v) { name##_ = v; } \
226 inline type name() const { return name##_; }
229 class ThreadLocalTop BASE_EMBEDDED {
231 // Does early low-level initialization that does not depend on the
232 // isolate being present.
235 // Initialize the thread data.
238 // Get the top C++ try catch handler or NULL if none are registered.
240 // This method is not guaranteed to return an address that can be
241 // used for comparison with addresses into the JS stack. If such an
242 // address is needed, use try_catch_handler_address.
243 FIELD_ACCESSOR(v8::TryCatch*, try_catch_handler)
245 // Get the address of the top C++ try catch handler or NULL if
246 // none are registered.
248 // This method always returns an address that can be compared to
249 // pointers into the JavaScript stack. When running on actual
250 // hardware, try_catch_handler_address and TryCatchHandler return
251 // the same pointer. When running on a simulator with a separate JS
252 // stack, try_catch_handler_address returns a JS stack address that
253 // corresponds to the place on the JS stack where the C++ handler
254 // would have been if the stack were not separate.
255 Address try_catch_handler_address() {
256 return reinterpret_cast<Address>(
257 v8::TryCatch::JSStackComparableAddress(try_catch_handler()));
263 // The context where the current execution method is created and for variable
267 Object* pending_exception_;
268 bool has_pending_message_;
269 bool rethrowing_message_;
270 Object* pending_message_obj_;
271 Object* pending_message_script_;
272 int pending_message_start_pos_;
273 int pending_message_end_pos_;
274 // Use a separate value for scheduled exceptions to preserve the
275 // invariants that hold about pending_exception. We may want to
277 Object* scheduled_exception_;
278 bool external_caught_exception_;
279 SaveContext* save_context_;
280 v8::TryCatch* catcher_;
283 Address c_entry_fp_; // the frame pointer of the top c entry frame
284 Address handler_; // try-blocks are chained through the stack
286 // Throwing an exception may cause a Promise rejection. For this purpose
287 // we keep track of a stack of nested promises and the corresponding
288 // try-catch handlers.
289 PromiseOnStack* promise_on_stack_;
292 Simulator* simulator_;
295 Address js_entry_sp_; // the stack pointer of the bottom JS entry frame
296 // the external callback we're currently in
297 ExternalCallbackScope* external_callback_scope_;
298 StateTag current_vm_state_;
300 // Generated code scratch locations.
301 int32_t formal_count_;
303 // Call back function to report unsafe JS accesses.
304 v8::FailedAccessCheckCallback failed_access_check_callback_;
306 // Head of the list of live LookupResults.
307 LookupResult* top_lookup_result_;
310 void InitializeInternal();
312 v8::TryCatch* try_catch_handler_;
316 #if V8_TARGET_ARCH_ARM && !defined(__arm__) || \
317 V8_TARGET_ARCH_ARM64 && !defined(__aarch64__) || \
318 V8_TARGET_ARCH_MIPS && !defined(__mips__) || \
319 V8_TARGET_ARCH_MIPS64 && !defined(__mips__)
321 #define ISOLATE_INIT_SIMULATOR_LIST(V) \
322 V(bool, simulator_initialized, false) \
323 V(HashMap*, simulator_i_cache, NULL) \
324 V(Redirection*, simulator_redirection, NULL)
327 #define ISOLATE_INIT_SIMULATOR_LIST(V)
334 #define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) \
335 V(CommentStatistic, paged_space_comments_statistics, \
336 CommentStatistic::kMaxComments + 1) \
337 V(int, code_kind_statistics, Code::NUMBER_OF_KINDS)
340 #define ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
344 #define ISOLATE_INIT_ARRAY_LIST(V) \
345 /* SerializerDeserializer state. */ \
346 V(int32_t, jsregexp_static_offsets_vector, kJSRegexpStaticOffsetsVectorSize) \
347 V(int, bad_char_shift_table, kUC16AlphabetSize) \
348 V(int, good_suffix_shift_table, (kBMMaxShift + 1)) \
349 V(int, suffix_table, (kBMMaxShift + 1)) \
350 V(uint32_t, private_random_seed, 2) \
351 ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
353 typedef List<HeapObject*> DebugObjectCache;
355 #define ISOLATE_INIT_LIST(V) \
356 /* SerializerDeserializer state. */ \
357 V(int, serialize_partial_snapshot_cache_length, 0) \
358 V(int, serialize_partial_snapshot_cache_capacity, 0) \
359 V(Object**, serialize_partial_snapshot_cache, NULL) \
360 /* Assembler state. */ \
361 V(FatalErrorCallback, exception_behavior, NULL) \
362 V(LogEventCallback, event_logger, NULL) \
363 V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, NULL) \
364 /* To distinguish the function templates, so that we can find them in the */ \
365 /* function cache of the native context. */ \
366 V(int, next_serial_number, 0) \
367 V(ExternalReferenceRedirectorPointer*, external_reference_redirector, NULL) \
368 /* Part of the state of liveedit. */ \
369 V(FunctionInfoListener*, active_function_info_listener, NULL) \
370 /* State for Relocatable. */ \
371 V(Relocatable*, relocatable_top, NULL) \
372 V(DebugObjectCache*, string_stream_debug_object_cache, NULL) \
373 V(Object*, string_stream_current_security_token, NULL) \
374 /* Serializer state. */ \
375 V(ExternalReferenceTable*, external_reference_table, NULL) \
376 V(int, pending_microtask_count, 0) \
377 V(bool, autorun_microtasks, true) \
378 V(HStatistics*, hstatistics, NULL) \
379 V(HStatistics*, tstatistics, NULL) \
380 V(HTracer*, htracer, NULL) \
381 V(CodeTracer*, code_tracer, NULL) \
382 V(bool, fp_stubs_generated, false) \
383 V(int, max_available_threads, 0) \
384 V(uint32_t, per_isolate_assert_data, 0xFFFFFFFFu) \
385 V(InterruptCallback, api_interrupt_callback, NULL) \
386 V(void*, api_interrupt_callback_data, NULL) \
387 ISOLATE_INIT_SIMULATOR_LIST(V)
389 #define THREAD_LOCAL_TOP_ACCESSOR(type, name) \
390 inline void set_##name(type v) { thread_local_top_.name##_ = v; } \
391 inline type name() const { return thread_local_top_.name##_; }
395 // These forward declarations are required to make the friend declarations in
396 // PerIsolateThreadData work on some older versions of gcc.
397 class ThreadDataTable;
398 class EntryStackItem;
402 // A thread has a PerIsolateThreadData instance for each isolate that it has
403 // entered. That instance is allocated when the isolate is initially entered
404 // and reused on subsequent entries.
405 class PerIsolateThreadData {
407 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id)
409 thread_id_(thread_id),
412 #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
413 !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
414 !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
415 !defined(__mips__) && V8_TARGET_ARCH_MIPS64
420 ~PerIsolateThreadData();
421 Isolate* isolate() const { return isolate_; }
422 ThreadId thread_id() const { return thread_id_; }
424 FIELD_ACCESSOR(uintptr_t, stack_limit)
425 FIELD_ACCESSOR(ThreadState*, thread_state)
427 #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
428 !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
429 !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
430 !defined(__mips__) && V8_TARGET_ARCH_MIPS64
431 FIELD_ACCESSOR(Simulator*, simulator)
434 bool Matches(Isolate* isolate, ThreadId thread_id) const {
435 return isolate_ == isolate && thread_id_.Equals(thread_id);
441 uintptr_t stack_limit_;
442 ThreadState* thread_state_;
444 #if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
445 !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
446 !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
447 !defined(__mips__) && V8_TARGET_ARCH_MIPS64
448 Simulator* simulator_;
451 PerIsolateThreadData* next_;
452 PerIsolateThreadData* prev_;
454 friend class Isolate;
455 friend class ThreadDataTable;
456 friend class EntryStackItem;
458 DISALLOW_COPY_AND_ASSIGN(PerIsolateThreadData);
463 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
464 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
469 static void InitializeOncePerProcess();
471 // Returns the PerIsolateThreadData for the current thread (or NULL if one is
472 // not currently set).
473 static PerIsolateThreadData* CurrentPerIsolateThreadData() {
474 return reinterpret_cast<PerIsolateThreadData*>(
475 base::Thread::GetThreadLocal(per_isolate_thread_data_key_));
478 // Returns the isolate inside which the current thread is running.
479 INLINE(static Isolate* Current()) {
480 Isolate* isolate = reinterpret_cast<Isolate*>(
481 base::Thread::GetExistingThreadLocal(isolate_key_));
482 DCHECK(isolate != NULL);
486 INLINE(static Isolate* UncheckedCurrent()) {
487 return reinterpret_cast<Isolate*>(
488 base::Thread::GetThreadLocal(isolate_key_));
491 // Like UncheckedCurrent, but skips the check that |isolate_key_| was
492 // initialized. Callers have to ensure that themselves.
493 INLINE(static Isolate* UnsafeCurrent()) {
494 return reinterpret_cast<Isolate*>(
495 base::Thread::GetThreadLocal(isolate_key_));
498 // Usually called by Init(), but can be called early e.g. to allow
499 // testing components that require logging but not the whole
502 // Safe to call more than once.
503 void InitializeLoggingAndCounters();
505 bool Init(Deserializer* des);
507 bool IsInitialized() { return state_ == INITIALIZED; }
509 // True if at least one thread Enter'ed this isolate.
510 bool IsInUse() { return entry_stack_ != NULL; }
512 // Destroys the non-default isolates.
513 // Sets default isolate into "has_been_disposed" state rather then destroying,
514 // for legacy API reasons.
517 static void GlobalTearDown();
519 // Find the PerThread for this particular (isolate, thread) combination
520 // If one does not yet exist, return null.
521 PerIsolateThreadData* FindPerThreadDataForThisThread();
523 // Find the PerThread for given (isolate, thread) combination
524 // If one does not yet exist, return null.
525 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
527 // Returns the key used to store the pointer to the current isolate.
528 // Used internally for V8 threads that do not execute JavaScript but still
529 // are part of the domain of an isolate (like the context switcher).
530 static base::Thread::LocalStorageKey isolate_key() {
534 // Returns the key used to store process-wide thread IDs.
535 static base::Thread::LocalStorageKey thread_id_key() {
536 return thread_id_key_;
539 static base::Thread::LocalStorageKey per_isolate_thread_data_key();
541 // Mutex for serializing access to break control structures.
542 base::RecursiveMutex* break_access() { return &break_access_; }
544 Address get_address_from_id(AddressId id);
546 // Access to top context (where the current function object was created).
547 Context* context() { return thread_local_top_.context_; }
548 void set_context(Context* context) {
549 DCHECK(context == NULL || context->IsContext());
550 thread_local_top_.context_ = context;
552 Context** context_address() { return &thread_local_top_.context_; }
554 THREAD_LOCAL_TOP_ACCESSOR(SaveContext*, save_context)
556 // Access to current thread id.
557 THREAD_LOCAL_TOP_ACCESSOR(ThreadId, thread_id)
559 // Interface to pending exception.
560 Object* pending_exception() {
561 DCHECK(has_pending_exception());
562 DCHECK(!thread_local_top_.pending_exception_->IsException());
563 return thread_local_top_.pending_exception_;
566 void set_pending_exception(Object* exception_obj) {
567 DCHECK(!exception_obj->IsException());
568 thread_local_top_.pending_exception_ = exception_obj;
571 void clear_pending_exception() {
572 DCHECK(!thread_local_top_.pending_exception_->IsException());
573 thread_local_top_.pending_exception_ = heap_.the_hole_value();
576 Object** pending_exception_address() {
577 return &thread_local_top_.pending_exception_;
580 bool has_pending_exception() {
581 DCHECK(!thread_local_top_.pending_exception_->IsException());
582 return !thread_local_top_.pending_exception_->IsTheHole();
585 THREAD_LOCAL_TOP_ACCESSOR(bool, external_caught_exception)
587 void clear_pending_message() {
588 thread_local_top_.has_pending_message_ = false;
589 thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
590 thread_local_top_.pending_message_script_ = heap_.the_hole_value();
592 v8::TryCatch* try_catch_handler() {
593 return thread_local_top_.try_catch_handler();
595 Address try_catch_handler_address() {
596 return thread_local_top_.try_catch_handler_address();
598 bool* external_caught_exception_address() {
599 return &thread_local_top_.external_caught_exception_;
602 THREAD_LOCAL_TOP_ACCESSOR(v8::TryCatch*, catcher)
604 Object** scheduled_exception_address() {
605 return &thread_local_top_.scheduled_exception_;
608 Address pending_message_obj_address() {
609 return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_);
612 Address has_pending_message_address() {
613 return reinterpret_cast<Address>(&thread_local_top_.has_pending_message_);
616 Address pending_message_script_address() {
617 return reinterpret_cast<Address>(
618 &thread_local_top_.pending_message_script_);
621 Object* scheduled_exception() {
622 DCHECK(has_scheduled_exception());
623 DCHECK(!thread_local_top_.scheduled_exception_->IsException());
624 return thread_local_top_.scheduled_exception_;
626 bool has_scheduled_exception() {
627 DCHECK(!thread_local_top_.scheduled_exception_->IsException());
628 return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
630 void clear_scheduled_exception() {
631 DCHECK(!thread_local_top_.scheduled_exception_->IsException());
632 thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
635 bool HasExternalTryCatch();
636 bool IsFinallyOnTop();
638 bool is_catchable_by_javascript(Object* exception) {
639 return exception != heap()->termination_exception();
643 void PushToPartialSnapshotCache(Object* obj);
645 // JS execution stack (see frames.h).
646 static Address c_entry_fp(ThreadLocalTop* thread) {
647 return thread->c_entry_fp_;
649 static Address handler(ThreadLocalTop* thread) { return thread->handler_; }
651 inline Address* c_entry_fp_address() {
652 return &thread_local_top_.c_entry_fp_;
654 inline Address* handler_address() { return &thread_local_top_.handler_; }
657 Address js_entry_sp() {
658 return thread_local_top_.js_entry_sp_;
660 inline Address* js_entry_sp_address() {
661 return &thread_local_top_.js_entry_sp_;
664 // Generated code scratch locations.
665 void* formal_count_address() { return &thread_local_top_.formal_count_; }
667 // Returns the global object of the current context. It could be
668 // a builtin object, or a JS global object.
669 Handle<GlobalObject> global_object() {
670 return Handle<GlobalObject>(context()->global_object());
673 // Returns the global proxy object of the current context.
674 JSObject* global_proxy() {
675 return context()->global_proxy();
678 Handle<JSBuiltinsObject> js_builtins_object() {
679 return Handle<JSBuiltinsObject>(thread_local_top_.context_->builtins());
682 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); }
683 void FreeThreadResources() { thread_local_top_.Free(); }
685 // This method is called by the api after operations that may throw
686 // exceptions. If an exception was thrown and not handled by an external
687 // handler the exception is scheduled to be rethrown when we return to running
688 // JavaScript code. If an exception is scheduled true is returned.
689 bool OptionalRescheduleException(bool is_bottom_call);
691 // Push and pop a promise and the current try-catch handler.
692 void PushPromise(Handle<JSObject> promise);
694 Handle<Object> GetPromiseOnStackOnThrow();
696 class ExceptionScope {
698 explicit ExceptionScope(Isolate* isolate) :
699 // Scope currently can only be used for regular exceptions,
700 // not termination exception.
702 pending_exception_(isolate_->pending_exception(), isolate_),
703 catcher_(isolate_->catcher())
707 isolate_->set_catcher(catcher_);
708 isolate_->set_pending_exception(*pending_exception_);
713 Handle<Object> pending_exception_;
714 v8::TryCatch* catcher_;
717 void SetCaptureStackTraceForUncaughtExceptions(
720 StackTrace::StackTraceOptions options);
722 void PrintCurrentStackTrace(FILE* out);
723 void PrintStack(StringStream* accumulator);
724 void PrintStack(FILE* out);
725 Handle<String> StackTraceString();
726 NO_INLINE(void PushStackTraceAndDie(unsigned int magic,
729 unsigned int magic2));
730 Handle<JSArray> CaptureCurrentStackTrace(
732 StackTrace::StackTraceOptions options);
733 Handle<Object> CaptureSimpleStackTrace(Handle<JSObject> error_object,
734 Handle<Object> caller);
735 void CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object);
736 void CaptureAndSetSimpleStackTrace(Handle<JSObject> error_object,
737 Handle<Object> caller);
739 // Returns if the top context may access the given global object. If
740 // the result is false, the pending exception is guaranteed to be
743 bool MayNamedAccess(Handle<JSObject> receiver,
745 v8::AccessType type);
746 bool MayIndexedAccess(Handle<JSObject> receiver,
748 v8::AccessType type);
750 void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback);
751 void ReportFailedAccessCheck(Handle<JSObject> receiver, v8::AccessType type);
753 // Exception throwing support. The caller should use the result
754 // of Throw() as its return value.
755 Object* Throw(Object* exception, MessageLocation* location = NULL);
757 template <typename T>
758 MUST_USE_RESULT MaybeHandle<T> Throw(Handle<Object> exception,
759 MessageLocation* location = NULL) {
760 Throw(*exception, location);
761 return MaybeHandle<T>();
764 // Re-throw an exception. This involves no error reporting since
765 // error reporting was handled when the exception was thrown
767 Object* ReThrow(Object* exception);
768 void ScheduleThrow(Object* exception);
769 // Re-set pending message, script and positions reported to the TryCatch
770 // back to the TLS for re-use when rethrowing.
771 void RestorePendingMessageFromTryCatch(v8::TryCatch* handler);
772 // Un-schedule an exception that was caught by a TryCatch handler.
773 void CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler);
774 void ReportPendingMessages();
775 // Return pending location if any or unfilled structure.
776 MessageLocation GetMessageLocation();
777 Object* ThrowIllegalOperation();
779 // Promote a scheduled exception to pending. Asserts has_scheduled_exception.
780 Object* PromoteScheduledException();
781 void DoThrow(Object* exception, MessageLocation* location);
782 // Checks if exception should be reported and finds out if it's
783 // caught externally.
784 bool ShouldReportException(bool* can_be_caught_externally,
785 bool catchable_by_javascript);
787 // Attempts to compute the current source location, storing the
788 // result in the target out parameter.
789 void ComputeLocation(MessageLocation* target);
791 // Out of resource exception helpers.
792 Object* StackOverflow();
793 Object* TerminateExecution();
794 void CancelTerminateExecution();
796 void InvokeApiInterruptCallback();
799 void Iterate(ObjectVisitor* v);
800 void Iterate(ObjectVisitor* v, ThreadLocalTop* t);
801 char* Iterate(ObjectVisitor* v, char* t);
802 void IterateThread(ThreadVisitor* v, char* t);
805 // Returns the current native and global context.
806 Handle<Context> native_context();
807 Handle<Context> global_context();
809 // Returns the native context of the calling JavaScript code. That
810 // is, the native context of the top-most JavaScript frame.
811 Handle<Context> GetCallingNativeContext();
813 void RegisterTryCatchHandler(v8::TryCatch* that);
814 void UnregisterTryCatchHandler(v8::TryCatch* that);
816 char* ArchiveThread(char* to);
817 char* RestoreThread(char* from);
819 static const char* const kStackOverflowMessage;
821 static const int kUC16AlphabetSize = 256; // See StringSearchBase.
822 static const int kBMMaxShift = 250; // See StringSearchBase.
825 #define GLOBAL_ACCESSOR(type, name, initialvalue) \
826 inline type name() const { \
827 DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
830 inline void set_##name(type value) { \
831 DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
834 ISOLATE_INIT_LIST(GLOBAL_ACCESSOR)
835 #undef GLOBAL_ACCESSOR
837 #define GLOBAL_ARRAY_ACCESSOR(type, name, length) \
838 inline type* name() { \
839 DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
840 return &(name##_)[0]; \
842 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR)
843 #undef GLOBAL_ARRAY_ACCESSOR
845 #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \
846 Handle<type> name() { \
847 return Handle<type>(native_context()->name(), this); \
849 bool is_##name(type* value) { \
850 return native_context()->is_##name(value); \
852 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
853 #undef NATIVE_CONTEXT_FIELD_ACCESSOR
855 Bootstrapper* bootstrapper() { return bootstrapper_; }
856 Counters* counters() {
857 // Call InitializeLoggingAndCounters() if logging is needed before
858 // the isolate is fully initialized.
859 DCHECK(counters_ != NULL);
862 CodeRange* code_range() { return code_range_; }
863 RuntimeProfiler* runtime_profiler() { return runtime_profiler_; }
864 CompilationCache* compilation_cache() { return compilation_cache_; }
866 // Call InitializeLoggingAndCounters() if logging is needed before
867 // the isolate is fully initialized.
868 DCHECK(logger_ != NULL);
871 StackGuard* stack_guard() { return &stack_guard_; }
872 Heap* heap() { return &heap_; }
873 StatsTable* stats_table();
874 StubCache* stub_cache() { return stub_cache_; }
875 CodeAgingHelper* code_aging_helper() { return code_aging_helper_; }
876 DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; }
877 ThreadLocalTop* thread_local_top() { return &thread_local_top_; }
878 MaterializedObjectStore* materialized_object_store() {
879 return materialized_object_store_;
882 MemoryAllocator* memory_allocator() {
883 return memory_allocator_;
886 KeyedLookupCache* keyed_lookup_cache() {
887 return keyed_lookup_cache_;
890 ContextSlotCache* context_slot_cache() {
891 return context_slot_cache_;
894 DescriptorLookupCache* descriptor_lookup_cache() {
895 return descriptor_lookup_cache_;
898 HandleScopeData* handle_scope_data() { return &handle_scope_data_; }
900 HandleScopeImplementer* handle_scope_implementer() {
901 DCHECK(handle_scope_implementer_);
902 return handle_scope_implementer_;
904 Zone* runtime_zone() { return &runtime_zone_; }
906 UnicodeCache* unicode_cache() {
907 return unicode_cache_;
910 InnerPointerToCodeCache* inner_pointer_to_code_cache() {
911 return inner_pointer_to_code_cache_;
914 ConsStringIteratorOp* write_iterator() { return write_iterator_; }
916 GlobalHandles* global_handles() { return global_handles_; }
918 EternalHandles* eternal_handles() { return eternal_handles_; }
920 ThreadManager* thread_manager() { return thread_manager_; }
922 StringTracker* string_tracker() { return string_tracker_; }
924 unibrow::Mapping<unibrow::Ecma262UnCanonicalize>* jsregexp_uncanonicalize() {
925 return &jsregexp_uncanonicalize_;
928 unibrow::Mapping<unibrow::CanonicalizationRange>* jsregexp_canonrange() {
929 return &jsregexp_canonrange_;
932 ConsStringIteratorOp* objects_string_compare_iterator_a() {
933 return &objects_string_compare_iterator_a_;
936 ConsStringIteratorOp* objects_string_compare_iterator_b() {
937 return &objects_string_compare_iterator_b_;
940 StaticResource<ConsStringIteratorOp>* objects_string_iterator() {
941 return &objects_string_iterator_;
944 RuntimeState* runtime_state() { return &runtime_state_; }
946 Builtins* builtins() { return &builtins_; }
948 void NotifyExtensionInstalled() {
949 has_installed_extensions_ = true;
952 bool has_installed_extensions() { return has_installed_extensions_; }
954 unibrow::Mapping<unibrow::Ecma262Canonicalize>*
955 regexp_macro_assembler_canonicalize() {
956 return ®exp_macro_assembler_canonicalize_;
959 RegExpStack* regexp_stack() { return regexp_stack_; }
961 unibrow::Mapping<unibrow::Ecma262Canonicalize>*
962 interp_canonicalize_mapping() {
963 return &interp_canonicalize_mapping_;
966 Debug* debug() { return debug_; }
968 inline bool DebuggerHasBreakPoints();
970 CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
971 HeapProfiler* heap_profiler() const { return heap_profiler_; }
974 HistogramInfo* heap_histograms() { return heap_histograms_; }
976 JSObject::SpillInformation* js_spill_information() {
977 return &js_spill_information_;
981 Factory* factory() { return reinterpret_cast<Factory*>(this); }
983 static const int kJSRegexpStaticOffsetsVectorSize = 128;
985 THREAD_LOCAL_TOP_ACCESSOR(ExternalCallbackScope*, external_callback_scope)
987 THREAD_LOCAL_TOP_ACCESSOR(StateTag, current_vm_state)
989 void SetData(uint32_t slot, void* data) {
990 DCHECK(slot < Internals::kNumIsolateDataSlots);
991 embedder_data_[slot] = data;
993 void* GetData(uint32_t slot) {
994 DCHECK(slot < Internals::kNumIsolateDataSlots);
995 return embedder_data_[slot];
998 THREAD_LOCAL_TOP_ACCESSOR(LookupResult*, top_lookup_result)
1000 void enable_serializer() {
1001 // The serializer can only be enabled before the isolate init.
1002 DCHECK(state_ != INITIALIZED);
1003 serializer_enabled_ = true;
1006 bool serializer_enabled() const { return serializer_enabled_; }
1008 bool IsDead() { return has_fatal_error_; }
1009 void SignalFatalError() { has_fatal_error_ = true; }
1011 bool use_crankshaft() const;
1013 bool initialized_from_snapshot() { return initialized_from_snapshot_; }
1015 double time_millis_since_init() {
1016 return base::OS::TimeCurrentMillis() - time_millis_at_init_;
1019 DateCache* date_cache() {
1023 void set_date_cache(DateCache* date_cache) {
1024 if (date_cache != date_cache_) {
1027 date_cache_ = date_cache;
1030 Map* get_initial_js_array_map(ElementsKind kind);
1032 bool IsFastArrayConstructorPrototypeChainIntact();
1034 CallInterfaceDescriptorData* call_descriptor_data(int index);
1036 void IterateDeferredHandles(ObjectVisitor* visitor);
1037 void LinkDeferredHandles(DeferredHandles* deferred_handles);
1038 void UnlinkDeferredHandles(DeferredHandles* deferred_handles);
1041 bool IsDeferredHandle(Object** location);
1044 bool concurrent_recompilation_enabled() {
1045 // Thread is only available with flag enabled.
1046 DCHECK(optimizing_compiler_thread_ == NULL ||
1047 FLAG_concurrent_recompilation);
1048 return optimizing_compiler_thread_ != NULL;
1051 bool concurrent_osr_enabled() const {
1052 // Thread is only available with flag enabled.
1053 DCHECK(optimizing_compiler_thread_ == NULL ||
1054 FLAG_concurrent_recompilation);
1055 return optimizing_compiler_thread_ != NULL && FLAG_concurrent_osr;
1058 OptimizingCompilerThread* optimizing_compiler_thread() {
1059 return optimizing_compiler_thread_;
1062 int num_sweeper_threads() const {
1063 return num_sweeper_threads_;
1066 SweeperThread** sweeper_threads() {
1067 return sweeper_thread_;
1070 int id() const { return static_cast<int>(id_); }
1072 HStatistics* GetHStatistics();
1073 HStatistics* GetTStatistics();
1074 HTracer* GetHTracer();
1075 CodeTracer* GetCodeTracer();
1077 FunctionEntryHook function_entry_hook() { return function_entry_hook_; }
1078 void set_function_entry_hook(FunctionEntryHook function_entry_hook) {
1079 function_entry_hook_ = function_entry_hook;
1082 void* stress_deopt_count_address() { return &stress_deopt_count_; }
1084 inline base::RandomNumberGenerator* random_number_generator();
1086 // Given an address occupied by a live code object, return that object.
1087 Object* FindCodeObject(Address a);
1089 int NextOptimizationId() {
1090 int id = next_optimization_id_++;
1091 if (!Smi::IsValid(next_optimization_id_)) {
1092 next_optimization_id_ = 0;
1097 // Get (and lazily initialize) the registry for per-isolate symbols.
1098 Handle<JSObject> GetSymbolRegistry();
1100 void AddCallCompletedCallback(CallCompletedCallback callback);
1101 void RemoveCallCompletedCallback(CallCompletedCallback callback);
1102 void FireCallCompletedCallback();
1104 void EnqueueMicrotask(Handle<Object> microtask);
1105 void RunMicrotasks();
1107 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
1108 void CountUsage(v8::Isolate::UseCounterFeature feature);
1110 static Isolate* NewForTesting() { return new Isolate(); }
1115 friend struct GlobalState;
1116 friend struct InitializeGlobalState;
1119 UNINITIALIZED, // Some components may not have been allocated.
1120 INITIALIZED // All components are fully initialized.
1123 // These fields are accessed through the API, offsets must be kept in sync
1124 // with v8::internal::Internals (in include/v8.h) constants. This is also
1125 // verified in Isolate::Init() using runtime checks.
1126 void* embedder_data_[Internals::kNumIsolateDataSlots];
1128 State state_; // Will be padded to kApiPointerSize.
1130 // The per-process lock should be acquired before the ThreadDataTable is
1132 class ThreadDataTable {
1137 PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id);
1138 void Insert(PerIsolateThreadData* data);
1139 void Remove(PerIsolateThreadData* data);
1140 void RemoveAllThreads(Isolate* isolate);
1143 PerIsolateThreadData* list_;
1146 // These items form a stack synchronously with threads Enter'ing and Exit'ing
1147 // the Isolate. The top of the stack points to a thread which is currently
1148 // running the Isolate. When the stack is empty, the Isolate is considered
1149 // not entered by any thread and can be Disposed.
1150 // If the same thread enters the Isolate more then once, the entry_count_
1151 // is incremented rather then a new item pushed to the stack.
1152 class EntryStackItem {
1154 EntryStackItem(PerIsolateThreadData* previous_thread_data,
1155 Isolate* previous_isolate,
1156 EntryStackItem* previous_item)
1158 previous_thread_data(previous_thread_data),
1159 previous_isolate(previous_isolate),
1160 previous_item(previous_item) { }
1163 PerIsolateThreadData* previous_thread_data;
1164 Isolate* previous_isolate;
1165 EntryStackItem* previous_item;
1168 DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1171 static base::LazyMutex thread_data_table_mutex_;
1173 static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
1174 static base::Thread::LocalStorageKey isolate_key_;
1175 static base::Thread::LocalStorageKey thread_id_key_;
1176 static ThreadDataTable* thread_data_table_;
1178 // A global counter for all generated Isolates, might overflow.
1179 static base::Atomic32 isolate_counter_;
1183 static void SetIsolateThreadLocals(Isolate* isolate,
1184 PerIsolateThreadData* data);
1186 // Find the PerThread for this particular (isolate, thread) combination.
1187 // If one does not yet exist, allocate a new one.
1188 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread();
1190 // Initializes the current thread to run this Isolate.
1191 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1192 // at the same time, this should be prevented using external locking.
1195 // Exits the current thread. The previosuly entered Isolate is restored
1197 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1198 // at the same time, this should be prevented using external locking.
1201 void InitializeThreadLocal();
1203 void MarkCompactPrologue(bool is_compacting,
1204 ThreadLocalTop* archived_thread_data);
1205 void MarkCompactEpilogue(bool is_compacting,
1206 ThreadLocalTop* archived_thread_data);
1210 // Propagate pending exception message to the v8::TryCatch.
1211 // If there is no external try-catch or message was successfully propagated,
1212 // then return true.
1213 bool PropagatePendingExceptionToExternalTryCatch();
1215 // Traverse prototype chain to find out whether the object is derived from
1216 // the Error object.
1217 bool IsErrorObject(Handle<Object> obj);
1220 EntryStackItem* entry_stack_;
1221 int stack_trace_nesting_level_;
1222 StringStream* incomplete_message_;
1223 Address isolate_addresses_[kIsolateAddressCount + 1]; // NOLINT
1224 Bootstrapper* bootstrapper_;
1225 RuntimeProfiler* runtime_profiler_;
1226 CompilationCache* compilation_cache_;
1227 Counters* counters_;
1228 CodeRange* code_range_;
1229 base::RecursiveMutex break_access_;
1230 base::Atomic32 debugger_initialized_;
1232 StackGuard stack_guard_;
1233 StatsTable* stats_table_;
1234 StubCache* stub_cache_;
1235 CodeAgingHelper* code_aging_helper_;
1236 DeoptimizerData* deoptimizer_data_;
1237 MaterializedObjectStore* materialized_object_store_;
1238 ThreadLocalTop thread_local_top_;
1239 bool capture_stack_trace_for_uncaught_exceptions_;
1240 int stack_trace_for_uncaught_exceptions_frame_limit_;
1241 StackTrace::StackTraceOptions stack_trace_for_uncaught_exceptions_options_;
1242 MemoryAllocator* memory_allocator_;
1243 KeyedLookupCache* keyed_lookup_cache_;
1244 ContextSlotCache* context_slot_cache_;
1245 DescriptorLookupCache* descriptor_lookup_cache_;
1246 HandleScopeData handle_scope_data_;
1247 HandleScopeImplementer* handle_scope_implementer_;
1248 UnicodeCache* unicode_cache_;
1250 InnerPointerToCodeCache* inner_pointer_to_code_cache_;
1251 ConsStringIteratorOp* write_iterator_;
1252 GlobalHandles* global_handles_;
1253 EternalHandles* eternal_handles_;
1254 ThreadManager* thread_manager_;
1255 RuntimeState runtime_state_;
1257 bool has_installed_extensions_;
1258 StringTracker* string_tracker_;
1259 unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_;
1260 unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_;
1261 ConsStringIteratorOp objects_string_compare_iterator_a_;
1262 ConsStringIteratorOp objects_string_compare_iterator_b_;
1263 StaticResource<ConsStringIteratorOp> objects_string_iterator_;
1264 unibrow::Mapping<unibrow::Ecma262Canonicalize>
1265 regexp_macro_assembler_canonicalize_;
1266 RegExpStack* regexp_stack_;
1267 DateCache* date_cache_;
1268 unibrow::Mapping<unibrow::Ecma262Canonicalize> interp_canonicalize_mapping_;
1269 CallInterfaceDescriptorData* call_descriptor_data_;
1270 base::RandomNumberGenerator* random_number_generator_;
1272 // Whether the isolate has been created for snapshotting.
1273 bool serializer_enabled_;
1275 // True if fatal error has been signaled for this isolate.
1276 bool has_fatal_error_;
1278 // True if this isolate was initialized from a snapshot.
1279 bool initialized_from_snapshot_;
1281 // Time stamp at initialization.
1282 double time_millis_at_init_;
1285 // A static array of histogram info for each type.
1286 HistogramInfo heap_histograms_[LAST_TYPE + 1];
1287 JSObject::SpillInformation js_spill_information_;
1291 CpuProfiler* cpu_profiler_;
1292 HeapProfiler* heap_profiler_;
1293 FunctionEntryHook function_entry_hook_;
1295 #define GLOBAL_BACKING_STORE(type, name, initialvalue) \
1297 ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE)
1298 #undef GLOBAL_BACKING_STORE
1300 #define GLOBAL_ARRAY_BACKING_STORE(type, name, length) \
1301 type name##_[length];
1302 ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE)
1303 #undef GLOBAL_ARRAY_BACKING_STORE
1306 // This class is huge and has a number of fields controlled by
1307 // preprocessor defines. Make sure the offsets of these fields agree
1308 // between compilation units.
1309 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
1310 static const intptr_t name##_debug_offset_;
1311 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
1312 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
1313 #undef ISOLATE_FIELD_OFFSET
1316 DeferredHandles* deferred_handles_head_;
1317 OptimizingCompilerThread* optimizing_compiler_thread_;
1318 SweeperThread** sweeper_thread_;
1319 int num_sweeper_threads_;
1321 // Counts deopt points if deopt_every_n_times is enabled.
1322 unsigned int stress_deopt_count_;
1324 int next_optimization_id_;
1326 // List of callbacks when a Call completes.
1327 List<CallCompletedCallback> call_completed_callbacks_;
1329 v8::Isolate::UseCounterCallback use_counter_callback_;
1331 friend class ExecutionAccess;
1332 friend class HandleScopeImplementer;
1333 friend class IsolateInitializer;
1334 friend class OptimizingCompilerThread;
1335 friend class SweeperThread;
1336 friend class ThreadManager;
1337 friend class Simulator;
1338 friend class StackGuard;
1339 friend class ThreadId;
1340 friend class TestMemoryAllocatorScope;
1341 friend class TestCodeRangeScope;
1342 friend class v8::Isolate;
1343 friend class v8::Locker;
1344 friend class v8::Unlocker;
1346 DISALLOW_COPY_AND_ASSIGN(Isolate);
1350 #undef FIELD_ACCESSOR
1351 #undef THREAD_LOCAL_TOP_ACCESSOR
1354 class PromiseOnStack {
1356 PromiseOnStack(StackHandler* handler, Handle<JSObject> promise,
1357 PromiseOnStack* prev)
1358 : handler_(handler), promise_(promise), prev_(prev) {}
1359 StackHandler* handler() { return handler_; }
1360 Handle<JSObject> promise() { return promise_; }
1361 PromiseOnStack* prev() { return prev_; }
1364 StackHandler* handler_;
1365 Handle<JSObject> promise_;
1366 PromiseOnStack* prev_;
1370 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the
1371 // class as a work around for a bug in the generated code found with these
1372 // versions of GCC. See V8 issue 122 for details.
1373 class SaveContext BASE_EMBEDDED {
1375 inline explicit SaveContext(Isolate* isolate);
1378 isolate_->set_context(context_.is_null() ? NULL : *context_);
1379 isolate_->set_save_context(prev_);
1382 Handle<Context> context() { return context_; }
1383 SaveContext* prev() { return prev_; }
1385 // Returns true if this save context is below a given JavaScript frame.
1386 bool IsBelowFrame(JavaScriptFrame* frame) {
1387 return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp());
1392 Handle<Context> context_;
1394 Address c_entry_fp_;
1398 class AssertNoContextChange BASE_EMBEDDED {
1401 explicit AssertNoContextChange(Isolate* isolate)
1402 : isolate_(isolate),
1403 context_(isolate->context(), isolate) { }
1404 ~AssertNoContextChange() {
1405 DCHECK(isolate_->context() == *context_);
1410 Handle<Context> context_;
1413 explicit AssertNoContextChange(Isolate* isolate) { }
1418 class ExecutionAccess BASE_EMBEDDED {
1420 explicit ExecutionAccess(Isolate* isolate) : isolate_(isolate) {
1423 ~ExecutionAccess() { Unlock(isolate_); }
1425 static void Lock(Isolate* isolate) { isolate->break_access()->Lock(); }
1426 static void Unlock(Isolate* isolate) { isolate->break_access()->Unlock(); }
1428 static bool TryLock(Isolate* isolate) {
1429 return isolate->break_access()->TryLock();
1437 // Support for checking for stack-overflows.
1438 class StackLimitCheck BASE_EMBEDDED {
1440 explicit StackLimitCheck(Isolate* isolate) : isolate_(isolate) { }
1442 // Use this to check for stack-overflows in C++ code.
1443 inline bool HasOverflowed() const {
1444 StackGuard* stack_guard = isolate_->stack_guard();
1445 return GetCurrentStackPosition() < stack_guard->real_climit();
1448 // Use this to check for stack-overflow when entering runtime from JS code.
1449 bool JsHasOverflowed() const;
1456 // Support for temporarily postponing interrupts. When the outermost
1457 // postpone scope is left the interrupts will be re-enabled and any
1458 // interrupts that occurred while in the scope will be taken into
1460 class PostponeInterruptsScope BASE_EMBEDDED {
1462 PostponeInterruptsScope(Isolate* isolate,
1463 int intercept_mask = StackGuard::ALL_INTERRUPTS)
1464 : stack_guard_(isolate->stack_guard()),
1465 intercept_mask_(intercept_mask),
1466 intercepted_flags_(0) {
1467 stack_guard_->PushPostponeInterruptsScope(this);
1470 ~PostponeInterruptsScope() {
1471 stack_guard_->PopPostponeInterruptsScope();
1474 // Find the bottom-most scope that intercepts this interrupt.
1475 // Return whether the interrupt has been intercepted.
1476 bool Intercept(StackGuard::InterruptFlag flag);
1479 StackGuard* stack_guard_;
1480 int intercept_mask_;
1481 int intercepted_flags_;
1482 PostponeInterruptsScope* prev_;
1484 friend class StackGuard;
1488 class CodeTracer FINAL : public Malloced {
1490 explicit CodeTracer(int isolate_id)
1493 if (!ShouldRedirect()) {
1498 if (FLAG_redirect_code_traces_to == NULL) {
1501 base::OS::GetCurrentProcessId(),
1504 StrNCpy(filename_, FLAG_redirect_code_traces_to, filename_.length());
1507 WriteChars(filename_.start(), "", 0, false);
1512 explicit Scope(CodeTracer* tracer) : tracer_(tracer) { tracer->OpenFile(); }
1513 ~Scope() { tracer_->CloseFile(); }
1515 FILE* file() const { return tracer_->file(); }
1518 CodeTracer* tracer_;
1522 if (!ShouldRedirect()) {
1526 if (file_ == NULL) {
1527 file_ = base::OS::FOpen(filename_.start(), "a");
1534 if (!ShouldRedirect()) {
1538 if (--scope_depth_ == 0) {
1544 FILE* file() const { return file_; }
1547 static bool ShouldRedirect() {
1548 return FLAG_redirect_code_traces;
1551 EmbeddedVector<char, 128> filename_;
1556 } } // namespace v8::internal
1558 #endif // V8_ISOLATE_H_