-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathisolate.h
1687 lines (1341 loc) · 57.2 KB
/
isolate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_ISOLATE_H_
#define V8_ISOLATE_H_
#include <memory>
#include <queue>
#include "include/v8-debug.h"
#include "src/allocation.h"
#include "src/base/atomicops.h"
#include "src/builtins/builtins.h"
#include "src/contexts.h"
#include "src/date.h"
#include "src/execution.h"
#include "src/frames.h"
#include "src/futex-emulation.h"
#include "src/global-handles.h"
#include "src/handles.h"
#include "src/heap/heap.h"
#include "src/messages.h"
#include "src/regexp/regexp-stack.h"
#include "src/runtime/runtime.h"
#include "src/zone/zone.h"
namespace v8 {
namespace base {
class RandomNumberGenerator;
}
namespace internal {
class AccessCompilerData;
class BasicBlockProfiler;
class Bootstrapper;
class CancelableTaskManager;
class CallInterfaceDescriptorData;
class CodeAgingHelper;
class CodeEventDispatcher;
class CodeGenerator;
class CodeRange;
class CodeStubDescriptor;
class CodeTracer;
class CompilationCache;
class CompilerDispatcherTracer;
class CompilationStatistics;
class ContextSlotCache;
class Counters;
class CpuFeatures;
class CpuProfiler;
class DeoptimizerData;
class DescriptorLookupCache;
class Deserializer;
class EmptyStatement;
class ExternalCallbackScope;
class ExternalReferenceTable;
class Factory;
class HandleScopeImplementer;
class HeapProfiler;
class HStatistics;
class HTracer;
class InlineRuntimeFunctionsTable;
class InnerPointerToCodeCache;
class Logger;
class MaterializedObjectStore;
class OptimizingCompileDispatcher;
class RegExpStack;
class RuntimeProfiler;
class SaveContext;
class StatsTable;
class StringTracker;
class StubCache;
class SweeperThread;
class ThreadManager;
class ThreadState;
class ThreadVisitor; // Defined in v8threads.h
class UnicodeCache;
template <StateTag Tag> class VMState;
// 'void function pointer', used to roundtrip the
// ExternalReference::ExternalReferenceRedirector since we can not include
// assembler.h, where it is defined, here.
typedef void* ExternalReferenceRedirectorPointer();
class Debug;
class PromiseOnStack;
class Redirection;
class Simulator;
namespace interpreter {
class Interpreter;
}
#define RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate) \
do { \
Isolate* __isolate__ = (isolate); \
if (__isolate__->has_scheduled_exception()) { \
return __isolate__->PromoteScheduledException(); \
} \
} while (false)
// Macros for MaybeHandle.
#define RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, value) \
do { \
Isolate* __isolate__ = (isolate); \
if (__isolate__->has_scheduled_exception()) { \
__isolate__->PromoteScheduledException(); \
return value; \
} \
} while (false)
#define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \
RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, MaybeHandle<T>())
#define RETURN_RESULT_OR_FAILURE(isolate, call) \
do { \
Handle<Object> __result__; \
Isolate* __isolate__ = (isolate); \
if (!(call).ToHandle(&__result__)) { \
DCHECK(__isolate__->has_pending_exception()); \
return __isolate__->heap()->exception(); \
} \
return *__result__; \
} while (false)
#define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \
do { \
if (!(call).ToHandle(&dst)) { \
DCHECK((isolate)->has_pending_exception()); \
return value; \
} \
} while (false)
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call) \
do { \
Isolate* __isolate__ = (isolate); \
ASSIGN_RETURN_ON_EXCEPTION_VALUE(__isolate__, dst, call, \
__isolate__->heap()->exception()); \
} while (false)
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T) \
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, MaybeHandle<T>())
#define THROW_NEW_ERROR(isolate, call, T) \
do { \
Isolate* __isolate__ = (isolate); \
return __isolate__->Throw<T>(__isolate__->factory()->call); \
} while (false)
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call) \
do { \
Isolate* __isolate__ = (isolate); \
return __isolate__->Throw(*__isolate__->factory()->call); \
} while (false)
#define RETURN_ON_EXCEPTION_VALUE(isolate, call, value) \
do { \
if ((call).is_null()) { \
DCHECK((isolate)->has_pending_exception()); \
return value; \
} \
} while (false)
#define RETURN_FAILURE_ON_EXCEPTION(isolate, call) \
do { \
Isolate* __isolate__ = (isolate); \
RETURN_ON_EXCEPTION_VALUE(__isolate__, call, \
__isolate__->heap()->exception()); \
} while (false);
#define RETURN_ON_EXCEPTION(isolate, call, T) \
RETURN_ON_EXCEPTION_VALUE(isolate, call, MaybeHandle<T>())
#define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \
C(Handler, handler) \
C(CEntryFP, c_entry_fp) \
C(CFunction, c_function) \
C(Context, context) \
C(PendingException, pending_exception) \
C(PendingHandlerContext, pending_handler_context) \
C(PendingHandlerCode, pending_handler_code) \
C(PendingHandlerOffset, pending_handler_offset) \
C(PendingHandlerFP, pending_handler_fp) \
C(PendingHandlerSP, pending_handler_sp) \
C(ExternalCaughtException, external_caught_exception) \
C(JSEntrySP, js_entry_sp)
#define FOR_WITH_HANDLE_SCOPE(isolate, loop_var_type, init, loop_var, \
limit_check, increment, body) \
do { \
loop_var_type init; \
loop_var_type for_with_handle_limit = loop_var; \
Isolate* for_with_handle_isolate = isolate; \
while (limit_check) { \
for_with_handle_limit += 1024; \
HandleScope loop_scope(for_with_handle_isolate); \
for (; limit_check && loop_var < for_with_handle_limit; increment) { \
body \
} \
} \
} while (false)
// Platform-independent, reliable thread identifier.
class ThreadId {
public:
// Creates an invalid ThreadId.
ThreadId() { base::NoBarrier_Store(&id_, kInvalidId); }
ThreadId& operator=(const ThreadId& other) {
base::NoBarrier_Store(&id_, base::NoBarrier_Load(&other.id_));
return *this;
}
// Returns ThreadId for current thread.
static ThreadId Current() { return ThreadId(GetCurrentThreadId()); }
// Returns invalid ThreadId (guaranteed not to be equal to any thread).
static ThreadId Invalid() { return ThreadId(kInvalidId); }
// Compares ThreadIds for equality.
INLINE(bool Equals(const ThreadId& other) const) {
return base::NoBarrier_Load(&id_) == base::NoBarrier_Load(&other.id_);
}
// Checks whether this ThreadId refers to any thread.
INLINE(bool IsValid() const) {
return base::NoBarrier_Load(&id_) != kInvalidId;
}
// Converts ThreadId to an integer representation
// (required for public API: V8::V8::GetCurrentThreadId).
int ToInteger() const { return static_cast<int>(base::NoBarrier_Load(&id_)); }
// Converts ThreadId to an integer representation
// (required for public API: V8::V8::TerminateExecution).
static ThreadId FromInteger(int id) { return ThreadId(id); }
private:
static const int kInvalidId = -1;
explicit ThreadId(int id) { base::NoBarrier_Store(&id_, id); }
static int AllocateThreadId();
static int GetCurrentThreadId();
base::Atomic32 id_;
static base::Atomic32 highest_thread_id_;
friend class Isolate;
};
#define FIELD_ACCESSOR(type, name) \
inline void set_##name(type v) { name##_ = v; } \
inline type name() const { return name##_; }
class ThreadLocalTop BASE_EMBEDDED {
public:
// Does early low-level initialization that does not depend on the
// isolate being present.
ThreadLocalTop();
// Initialize the thread data.
void Initialize();
// Get the top C++ try catch handler or NULL if none are registered.
//
// This method is not guaranteed to return an address that can be
// used for comparison with addresses into the JS stack. If such an
// address is needed, use try_catch_handler_address.
FIELD_ACCESSOR(v8::TryCatch*, try_catch_handler)
// Get the address of the top C++ try catch handler or NULL if
// none are registered.
//
// This method always returns an address that can be compared to
// pointers into the JavaScript stack. When running on actual
// hardware, try_catch_handler_address and TryCatchHandler return
// the same pointer. When running on a simulator with a separate JS
// stack, try_catch_handler_address returns a JS stack address that
// corresponds to the place on the JS stack where the C++ handler
// would have been if the stack were not separate.
Address try_catch_handler_address() {
return reinterpret_cast<Address>(
v8::TryCatch::JSStackComparableAddress(try_catch_handler()));
}
void Free();
Isolate* isolate_;
// The context where the current execution method is created and for variable
// lookups.
Context* context_;
ThreadId thread_id_;
Object* pending_exception_;
// Communication channel between Isolate::FindHandler and the CEntryStub.
Context* pending_handler_context_;
Code* pending_handler_code_;
intptr_t pending_handler_offset_;
Address pending_handler_fp_;
Address pending_handler_sp_;
// Communication channel between Isolate::Throw and message consumers.
bool rethrowing_message_;
Object* pending_message_obj_;
// Use a separate value for scheduled exceptions to preserve the
// invariants that hold about pending_exception. We may want to
// unify them later.
Object* scheduled_exception_;
bool external_caught_exception_;
SaveContext* save_context_;
// Stack.
Address c_entry_fp_; // the frame pointer of the top c entry frame
Address handler_; // try-blocks are chained through the stack
Address c_function_; // C function that was called at c entry.
// Throwing an exception may cause a Promise rejection. For this purpose
// we keep track of a stack of nested promises and the corresponding
// try-catch handlers.
PromiseOnStack* promise_on_stack_;
#ifdef USE_SIMULATOR
Simulator* simulator_;
#endif
Address js_entry_sp_; // the stack pointer of the bottom JS entry frame
// the external callback we're currently in
ExternalCallbackScope* external_callback_scope_;
StateTag current_vm_state_;
// Call back function to report unsafe JS accesses.
v8::FailedAccessCheckCallback failed_access_check_callback_;
private:
void InitializeInternal();
v8::TryCatch* try_catch_handler_;
};
#if USE_SIMULATOR
#define ISOLATE_INIT_SIMULATOR_LIST(V) \
V(bool, simulator_initialized, false) \
V(base::CustomMatcherHashMap*, simulator_i_cache, NULL) \
V(Redirection*, simulator_redirection, NULL)
#else
#define ISOLATE_INIT_SIMULATOR_LIST(V)
#endif
#ifdef DEBUG
#define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) \
V(CommentStatistic, paged_space_comments_statistics, \
CommentStatistic::kMaxComments + 1) \
V(int, code_kind_statistics, AbstractCode::NUMBER_OF_KINDS)
#else
#define ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
#endif
#define ISOLATE_INIT_ARRAY_LIST(V) \
/* SerializerDeserializer state. */ \
V(int32_t, jsregexp_static_offsets_vector, kJSRegexpStaticOffsetsVectorSize) \
V(int, bad_char_shift_table, kUC16AlphabetSize) \
V(int, good_suffix_shift_table, (kBMMaxShift + 1)) \
V(int, suffix_table, (kBMMaxShift + 1)) \
V(uint32_t, private_random_seed, 2) \
ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
typedef List<HeapObject*> DebugObjectCache;
#define ISOLATE_INIT_LIST(V) \
/* Assembler state. */ \
V(FatalErrorCallback, exception_behavior, nullptr) \
V(OOMErrorCallback, oom_behavior, nullptr) \
V(LogEventCallback, event_logger, nullptr) \
V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, nullptr) \
V(ExternalReferenceRedirectorPointer*, external_reference_redirector, \
nullptr) \
/* State for Relocatable. */ \
V(Relocatable*, relocatable_top, nullptr) \
V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \
V(Object*, string_stream_current_security_token, nullptr) \
V(ExternalReferenceTable*, external_reference_table, nullptr) \
V(intptr_t*, api_external_references, nullptr) \
V(base::HashMap*, external_reference_map, nullptr) \
V(base::HashMap*, root_index_map, nullptr) \
V(int, pending_microtask_count, 0) \
V(int, debug_microtask_count, 0) \
V(HStatistics*, hstatistics, nullptr) \
V(CompilationStatistics*, turbo_statistics, nullptr) \
V(HTracer*, htracer, nullptr) \
V(CodeTracer*, code_tracer, nullptr) \
V(bool, fp_stubs_generated, false) \
V(uint32_t, per_isolate_assert_data, 0xFFFFFFFFu) \
V(PromiseRejectCallback, promise_reject_callback, nullptr) \
V(const v8::StartupData*, snapshot_blob, nullptr) \
V(int, code_and_metadata_size, 0) \
V(int, bytecode_and_metadata_size, 0) \
/* true if being profiled. Causes collection of extra compile info. */ \
V(bool, is_profiling, false) \
/* true if a trace is being formatted through Error.prepareStackTrace. */ \
V(bool, formatting_stack_trace, false) \
ISOLATE_INIT_SIMULATOR_LIST(V)
#define THREAD_LOCAL_TOP_ACCESSOR(type, name) \
inline void set_##name(type v) { thread_local_top_.name##_ = v; } \
inline type name() const { return thread_local_top_.name##_; }
#define THREAD_LOCAL_TOP_ADDRESS(type, name) \
type* name##_address() { return &thread_local_top_.name##_; }
class Isolate {
// These forward declarations are required to make the friend declarations in
// PerIsolateThreadData work on some older versions of gcc.
class ThreadDataTable;
class EntryStackItem;
public:
~Isolate();
// A thread has a PerIsolateThreadData instance for each isolate that it has
// entered. That instance is allocated when the isolate is initially entered
// and reused on subsequent entries.
class PerIsolateThreadData {
public:
PerIsolateThreadData(Isolate* isolate, ThreadId thread_id)
: isolate_(isolate),
thread_id_(thread_id),
stack_limit_(0),
thread_state_(NULL),
#if USE_SIMULATOR
simulator_(NULL),
#endif
next_(NULL),
prev_(NULL) { }
~PerIsolateThreadData();
Isolate* isolate() const { return isolate_; }
ThreadId thread_id() const { return thread_id_; }
FIELD_ACCESSOR(uintptr_t, stack_limit)
FIELD_ACCESSOR(ThreadState*, thread_state)
#if USE_SIMULATOR
FIELD_ACCESSOR(Simulator*, simulator)
#endif
bool Matches(Isolate* isolate, ThreadId thread_id) const {
return isolate_ == isolate && thread_id_.Equals(thread_id);
}
private:
Isolate* isolate_;
ThreadId thread_id_;
uintptr_t stack_limit_;
ThreadState* thread_state_;
#if USE_SIMULATOR
Simulator* simulator_;
#endif
PerIsolateThreadData* next_;
PerIsolateThreadData* prev_;
friend class Isolate;
friend class ThreadDataTable;
friend class EntryStackItem;
DISALLOW_COPY_AND_ASSIGN(PerIsolateThreadData);
};
enum AddressId {
#define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
#undef DECLARE_ENUM
kIsolateAddressCount
};
static void InitializeOncePerProcess();
// Returns the PerIsolateThreadData for the current thread (or NULL if one is
// not currently set).
static PerIsolateThreadData* CurrentPerIsolateThreadData() {
return reinterpret_cast<PerIsolateThreadData*>(
base::Thread::GetThreadLocal(per_isolate_thread_data_key_));
}
// Returns the isolate inside which the current thread is running.
INLINE(static Isolate* Current()) {
DCHECK(base::NoBarrier_Load(&isolate_key_created_) == 1);
Isolate* isolate = reinterpret_cast<Isolate*>(
base::Thread::GetExistingThreadLocal(isolate_key_));
DCHECK(isolate != NULL);
return isolate;
}
// Usually called by Init(), but can be called early e.g. to allow
// testing components that require logging but not the whole
// isolate.
//
// Safe to call more than once.
void InitializeLoggingAndCounters();
bool Init(Deserializer* des);
// True if at least one thread Enter'ed this isolate.
bool IsInUse() { return entry_stack_ != NULL; }
// Destroys the non-default isolates.
// Sets default isolate into "has_been_disposed" state rather then destroying,
// for legacy API reasons.
void TearDown();
static void GlobalTearDown();
void ClearSerializerData();
// Find the PerThread for this particular (isolate, thread) combination
// If one does not yet exist, return null.
PerIsolateThreadData* FindPerThreadDataForThisThread();
// Find the PerThread for given (isolate, thread) combination
// If one does not yet exist, return null.
PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
// Discard the PerThread for this particular (isolate, thread) combination
// If one does not yet exist, no-op.
void DiscardPerThreadDataForThisThread();
// Returns the key used to store the pointer to the current isolate.
// Used internally for V8 threads that do not execute JavaScript but still
// are part of the domain of an isolate (like the context switcher).
static base::Thread::LocalStorageKey isolate_key() {
return isolate_key_;
}
// Returns the key used to store process-wide thread IDs.
static base::Thread::LocalStorageKey thread_id_key() {
return thread_id_key_;
}
static base::Thread::LocalStorageKey per_isolate_thread_data_key();
// Mutex for serializing access to break control structures.
base::RecursiveMutex* break_access() { return &break_access_; }
Address get_address_from_id(AddressId id);
// Access to top context (where the current function object was created).
Context* context() { return thread_local_top_.context_; }
inline void set_context(Context* context);
Context** context_address() { return &thread_local_top_.context_; }
THREAD_LOCAL_TOP_ACCESSOR(SaveContext*, save_context)
// Access to current thread id.
THREAD_LOCAL_TOP_ACCESSOR(ThreadId, thread_id)
// Interface to pending exception.
inline Object* pending_exception();
inline void set_pending_exception(Object* exception_obj);
inline void clear_pending_exception();
THREAD_LOCAL_TOP_ADDRESS(Object*, pending_exception)
inline bool has_pending_exception();
THREAD_LOCAL_TOP_ADDRESS(Context*, pending_handler_context)
THREAD_LOCAL_TOP_ADDRESS(Code*, pending_handler_code)
THREAD_LOCAL_TOP_ADDRESS(intptr_t, pending_handler_offset)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_fp)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_sp)
THREAD_LOCAL_TOP_ACCESSOR(bool, external_caught_exception)
v8::TryCatch* try_catch_handler() {
return thread_local_top_.try_catch_handler();
}
bool* external_caught_exception_address() {
return &thread_local_top_.external_caught_exception_;
}
THREAD_LOCAL_TOP_ADDRESS(Object*, scheduled_exception)
inline void clear_pending_message();
Address pending_message_obj_address() {
return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_);
}
inline Object* scheduled_exception();
inline bool has_scheduled_exception();
inline void clear_scheduled_exception();
bool IsJavaScriptHandlerOnTop(Object* exception);
bool IsExternalHandlerOnTop(Object* exception);
inline bool is_catchable_by_javascript(Object* exception);
inline bool is_catchable_by_wasm(Object* exception);
// JS execution stack (see frames.h).
static Address c_entry_fp(ThreadLocalTop* thread) {
return thread->c_entry_fp_;
}
static Address handler(ThreadLocalTop* thread) { return thread->handler_; }
Address c_function() { return thread_local_top_.c_function_; }
inline Address* c_entry_fp_address() {
return &thread_local_top_.c_entry_fp_;
}
inline Address* handler_address() { return &thread_local_top_.handler_; }
inline Address* c_function_address() {
return &thread_local_top_.c_function_;
}
// Bottom JS entry.
Address js_entry_sp() {
return thread_local_top_.js_entry_sp_;
}
inline Address* js_entry_sp_address() {
return &thread_local_top_.js_entry_sp_;
}
// Returns the global object of the current context. It could be
// a builtin object, or a JS global object.
inline Handle<JSGlobalObject> global_object();
// Returns the global proxy object of the current context.
inline Handle<JSObject> global_proxy();
static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); }
void FreeThreadResources() { thread_local_top_.Free(); }
// This method is called by the api after operations that may throw
// exceptions. If an exception was thrown and not handled by an external
// handler the exception is scheduled to be rethrown when we return to running
// JavaScript code. If an exception is scheduled true is returned.
bool OptionalRescheduleException(bool is_bottom_call);
// Push and pop a promise and the current try-catch handler.
void PushPromise(Handle<JSObject> promise);
void PopPromise();
// Return the relevant Promise that a throw/rejection pertains to, based
// on the contents of the Promise stack
Handle<Object> GetPromiseOnStackOnThrow();
// Heuristically guess whether a Promise is handled by user catch handler
bool PromiseHasUserDefinedRejectHandler(Handle<Object> promise);
class ExceptionScope {
public:
// Scope currently can only be used for regular exceptions,
// not termination exception.
inline explicit ExceptionScope(Isolate* isolate);
inline ~ExceptionScope();
private:
Isolate* isolate_;
Handle<Object> pending_exception_;
};
void SetCaptureStackTraceForUncaughtExceptions(
bool capture,
int frame_limit,
StackTrace::StackTraceOptions options);
void SetAbortOnUncaughtExceptionCallback(
v8::Isolate::AbortOnUncaughtExceptionCallback callback);
enum PrintStackMode { kPrintStackConcise, kPrintStackVerbose };
void PrintCurrentStackTrace(FILE* out);
void PrintStack(StringStream* accumulator,
PrintStackMode mode = kPrintStackVerbose);
void PrintStack(FILE* out, PrintStackMode mode = kPrintStackVerbose);
Handle<String> StackTraceString();
NO_INLINE(void PushStackTraceAndDie(unsigned int magic, void* ptr1,
void* ptr2, unsigned int magic2));
Handle<JSArray> CaptureCurrentStackTrace(
int frame_limit,
StackTrace::StackTraceOptions options);
Handle<Object> CaptureSimpleStackTrace(Handle<JSReceiver> error_object,
FrameSkipMode mode,
Handle<Object> caller);
MaybeHandle<JSReceiver> CaptureAndSetDetailedStackTrace(
Handle<JSReceiver> error_object);
MaybeHandle<JSReceiver> CaptureAndSetSimpleStackTrace(
Handle<JSReceiver> error_object, FrameSkipMode mode,
Handle<Object> caller);
Handle<JSArray> GetDetailedStackTrace(Handle<JSObject> error_object);
// Returns if the given context may access the given global object. If
// the result is false, the pending exception is guaranteed to be
// set.
bool MayAccess(Handle<Context> accessing_context, Handle<JSObject> receiver);
void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback);
void ReportFailedAccessCheck(Handle<JSObject> receiver);
// Exception throwing support. The caller should use the result
// of Throw() as its return value.
Object* Throw(Object* exception, MessageLocation* location = NULL);
Object* ThrowIllegalOperation();
template <typename T>
MUST_USE_RESULT MaybeHandle<T> Throw(Handle<Object> exception,
MessageLocation* location = NULL) {
Throw(*exception, location);
return MaybeHandle<T>();
}
// Re-throw an exception. This involves no error reporting since error
// reporting was handled when the exception was thrown originally.
Object* ReThrow(Object* exception);
// Find the correct handler for the current pending exception. This also
// clears and returns the current pending exception.
Object* UnwindAndFindHandler();
// Tries to predict whether an exception will be caught. Note that this can
// only produce an estimate, because it is undecidable whether a finally
// clause will consume or re-throw an exception.
enum CatchType {
NOT_CAUGHT,
CAUGHT_BY_JAVASCRIPT,
CAUGHT_BY_EXTERNAL,
CAUGHT_BY_DESUGARING,
CAUGHT_BY_PROMISE,
CAUGHT_BY_ASYNC_AWAIT
};
CatchType PredictExceptionCatcher();
void ScheduleThrow(Object* exception);
// Re-set pending message, script and positions reported to the TryCatch
// back to the TLS for re-use when rethrowing.
void RestorePendingMessageFromTryCatch(v8::TryCatch* handler);
// Un-schedule an exception that was caught by a TryCatch handler.
void CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler);
void ReportPendingMessages();
// Return pending location if any or unfilled structure.
MessageLocation GetMessageLocation();
// Promote a scheduled exception to pending. Asserts has_scheduled_exception.
Object* PromoteScheduledException();
// Attempts to compute the current source location, storing the
// result in the target out parameter.
bool ComputeLocation(MessageLocation* target);
bool ComputeLocationFromException(MessageLocation* target,
Handle<Object> exception);
bool ComputeLocationFromStackTrace(MessageLocation* target,
Handle<Object> exception);
Handle<JSMessageObject> CreateMessage(Handle<Object> exception,
MessageLocation* location);
// Out of resource exception helpers.
Object* StackOverflow();
Object* TerminateExecution();
void CancelTerminateExecution();
void RequestInterrupt(InterruptCallback callback, void* data);
void InvokeApiInterruptCallbacks();
// Administration
void Iterate(ObjectVisitor* v);
void Iterate(ObjectVisitor* v, ThreadLocalTop* t);
char* Iterate(ObjectVisitor* v, char* t);
void IterateThread(ThreadVisitor* v, char* t);
// Returns the current native context.
inline Handle<Context> native_context();
inline Context* raw_native_context();
// Returns the native context of the calling JavaScript code. That
// is, the native context of the top-most JavaScript frame.
Handle<Context> GetCallingNativeContext();
void RegisterTryCatchHandler(v8::TryCatch* that);
void UnregisterTryCatchHandler(v8::TryCatch* that);
char* ArchiveThread(char* to);
char* RestoreThread(char* from);
static const int kUC16AlphabetSize = 256; // See StringSearchBase.
static const int kBMMaxShift = 250; // See StringSearchBase.
// Accessors.
#define GLOBAL_ACCESSOR(type, name, initialvalue) \
inline type name() const { \
DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
return name##_; \
} \
inline void set_##name(type value) { \
DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
name##_ = value; \
}
ISOLATE_INIT_LIST(GLOBAL_ACCESSOR)
#undef GLOBAL_ACCESSOR
#define GLOBAL_ARRAY_ACCESSOR(type, name, length) \
inline type* name() { \
DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_); \
return &(name##_)[0]; \
}
ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR)
#undef GLOBAL_ARRAY_ACCESSOR
#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \
inline Handle<type> name(); \
inline bool is_##name(type* value);
NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
#undef NATIVE_CONTEXT_FIELD_ACCESSOR
Bootstrapper* bootstrapper() { return bootstrapper_; }
Counters* counters() {
// Call InitializeLoggingAndCounters() if logging is needed before
// the isolate is fully initialized.
DCHECK(counters_ != NULL);
return counters_;
}
RuntimeProfiler* runtime_profiler() { return runtime_profiler_; }
CompilationCache* compilation_cache() { return compilation_cache_; }
Logger* logger() {
// Call InitializeLoggingAndCounters() if logging is needed before
// the isolate is fully initialized.
DCHECK(logger_ != NULL);
return logger_;
}
StackGuard* stack_guard() { return &stack_guard_; }
Heap* heap() { return &heap_; }
StatsTable* stats_table();
StubCache* load_stub_cache() { return load_stub_cache_; }
StubCache* store_stub_cache() { return store_stub_cache_; }
CodeAgingHelper* code_aging_helper() { return code_aging_helper_; }
DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; }
bool deoptimizer_lazy_throw() const { return deoptimizer_lazy_throw_; }
void set_deoptimizer_lazy_throw(bool value) {
deoptimizer_lazy_throw_ = value;
}
ThreadLocalTop* thread_local_top() { return &thread_local_top_; }
MaterializedObjectStore* materialized_object_store() {
return materialized_object_store_;
}
ContextSlotCache* context_slot_cache() {
return context_slot_cache_;
}
DescriptorLookupCache* descriptor_lookup_cache() {
return descriptor_lookup_cache_;
}
HandleScopeData* handle_scope_data() { return &handle_scope_data_; }
HandleScopeImplementer* handle_scope_implementer() {
DCHECK(handle_scope_implementer_);
return handle_scope_implementer_;
}
UnicodeCache* unicode_cache() {
return unicode_cache_;
}
InnerPointerToCodeCache* inner_pointer_to_code_cache() {
return inner_pointer_to_code_cache_;
}
GlobalHandles* global_handles() { return global_handles_; }
EternalHandles* eternal_handles() { return eternal_handles_; }
ThreadManager* thread_manager() { return thread_manager_; }
unibrow::Mapping<unibrow::Ecma262UnCanonicalize>* jsregexp_uncanonicalize() {
return &jsregexp_uncanonicalize_;
}
unibrow::Mapping<unibrow::CanonicalizationRange>* jsregexp_canonrange() {
return &jsregexp_canonrange_;
}
RuntimeState* runtime_state() { return &runtime_state_; }
Builtins* builtins() { return &builtins_; }
void NotifyExtensionInstalled() {
has_installed_extensions_ = true;
}
bool has_installed_extensions() { return has_installed_extensions_; }
unibrow::Mapping<unibrow::Ecma262Canonicalize>*
regexp_macro_assembler_canonicalize() {
return ®exp_macro_assembler_canonicalize_;
}
RegExpStack* regexp_stack() { return regexp_stack_; }
List<int>* regexp_indices() { return ®exp_indices_; }
unibrow::Mapping<unibrow::Ecma262Canonicalize>*
interp_canonicalize_mapping() {
return ®exp_macro_assembler_canonicalize_;
}
Debug* debug() { return debug_; }
bool* is_profiling_address() { return &is_profiling_; }
CodeEventDispatcher* code_event_dispatcher() const {
return code_event_dispatcher_.get();
}
HeapProfiler* heap_profiler() const { return heap_profiler_; }
#ifdef DEBUG
HistogramInfo* heap_histograms() { return heap_histograms_; }
JSObject::SpillInformation* js_spill_information() {
return &js_spill_information_;
}
#endif
Factory* factory() { return reinterpret_cast<Factory*>(this); }
static const int kJSRegexpStaticOffsetsVectorSize = 128;
THREAD_LOCAL_TOP_ACCESSOR(ExternalCallbackScope*, external_callback_scope)
THREAD_LOCAL_TOP_ACCESSOR(StateTag, current_vm_state)
void SetData(uint32_t slot, void* data) {
DCHECK(slot < Internals::kNumIsolateDataSlots);
embedder_data_[slot] = data;
}
void* GetData(uint32_t slot) {
DCHECK(slot < Internals::kNumIsolateDataSlots);
return embedder_data_[slot];
}
bool serializer_enabled() const { return serializer_enabled_; }
bool snapshot_available() const {
return snapshot_blob_ != NULL && snapshot_blob_->raw_size != 0;
}
bool IsDead() { return has_fatal_error_; }
void SignalFatalError() { has_fatal_error_ = true; }
bool use_crankshaft() const;
bool initialized_from_snapshot() { return initialized_from_snapshot_; }
double time_millis_since_init() {
return heap_.MonotonicallyIncreasingTimeInMs() - time_millis_at_init_;
}
DateCache* date_cache() {
return date_cache_;
}
void set_date_cache(DateCache* date_cache) {
if (date_cache != date_cache_) {
delete date_cache_;
}
date_cache_ = date_cache;
}
Map* get_initial_js_array_map(ElementsKind kind);
static const int kArrayProtectorValid = 1;
static const int kArrayProtectorInvalid = 0;
bool IsFastArrayConstructorPrototypeChainIntact();
inline bool IsArraySpeciesLookupChainIntact();
inline bool IsHasInstanceLookupChainIntact();
bool IsIsConcatSpreadableLookupChainIntact();
bool IsIsConcatSpreadableLookupChainIntact(JSReceiver* receiver);
inline bool IsStringLengthOverflowIntact();
// On intent to set an element in object, make sure that appropriate
// notifications occur if the set is on the elements of the array or
// object prototype. Also ensure that changes to prototype chain between
// Array and Object fire notifications.
void UpdateArrayProtectorOnSetElement(Handle<JSObject> object);