59 Atomic32 ThreadId::highest_thread_id_ = 0;
61 int ThreadId::AllocateThreadId() {
67 int ThreadId::GetCurrentThreadId() {
70 thread_id = AllocateThreadId();
77 ThreadLocalTop::ThreadLocalTop() {
82 ignore_out_of_memory_ =
false;
86 void ThreadLocalTop::InitializeInternal() {
93 external_callback_ =
NULL;
94 current_vm_state_ = EXTERNAL;
95 try_catch_handler_address_ =
NULL;
98 external_caught_exception_ =
false;
99 failed_access_check_callback_ =
NULL;
100 save_context_ =
NULL;
102 top_lookup_result_ =
NULL;
106 pending_exception_ =
NULL;
107 has_pending_message_ =
false;
108 pending_message_obj_ =
NULL;
109 pending_message_script_ =
NULL;
110 scheduled_exception_ =
NULL;
114 void ThreadLocalTop::Initialize() {
115 InitializeInternal();
117 #ifdef V8_TARGET_ARCH_ARM
118 simulator_ = Simulator::current(isolate_);
119 #elif V8_TARGET_ARCH_MIPS
120 simulator_ = Simulator::current(isolate_);
138 if (data_ready_semaphore_ !=
NULL) {
140 data_ready_semaphore_->
Wait();
141 delete data_ready_semaphore_;
142 data_ready_semaphore_ =
NULL;
148 if (data_ready_semaphore_ !=
NULL) {
150 data_ready_semaphore_->
Wait();
151 delete data_ready_semaphore_;
152 data_ready_semaphore_ =
NULL;
159 keep_running_ =
false;
160 wait_for_ever_semaphore_->
Signal();
165 if (data_ready_semaphore_ !=
NULL) {
166 delete data_ready_semaphore_;
167 data_ready_semaphore_ =
NULL;
170 delete wait_for_ever_semaphore_;
171 wait_for_ever_semaphore_ =
NULL;
181 OS::StrNCpy(local_buffer,
"Trace data was not generated.\n",
185 data_ = local_buffer.
start();
186 length_ = local_buffer.
length();
187 data_ready_semaphore_->
Signal();
189 while (keep_running_) {
191 wait_for_ever_semaphore_->
Wait();
196 OS::StrNCpy(local_buffer,
"PreallocatedMemoryThread shutting down.\n",
203 :
Thread(
"v8:PreallocMem"),
205 wait_for_ever_semaphore_(
OS::CreateSemaphore(0)),
206 data_ready_semaphore_(
OS::CreateSemaphore(0)),
215 Semaphore* wait_for_ever_semaphore_;
217 Semaphore* data_ready_semaphore_;
229 void Isolate::PreallocatedMemoryThreadStart() {
230 if (preallocated_memory_thread_ !=
NULL)
return;
232 preallocated_memory_thread_->
Start();
236 void Isolate::PreallocatedMemoryThreadStop() {
237 if (preallocated_memory_thread_ ==
NULL)
return;
240 delete preallocated_memory_thread_;
241 preallocated_memory_thread_ =
NULL;
246 ASSERT(free_list_.next_ == &free_list_);
247 ASSERT(free_list_.previous_ == &free_list_);
250 free_list_.next_ = free_list_.previous_ = free_chunk;
251 free_chunk->next_ = free_chunk->previous_ = &free_list_;
253 preallocated_storage_preallocated_ =
true;
258 if (!preallocated_storage_preallocated_) {
261 ASSERT(free_list_.next_ != &free_list_);
262 ASSERT(free_list_.previous_ != &free_list_);
267 storage != &free_list_;
268 storage = storage->next_) {
269 if (storage->size_ == size) {
271 storage->LinkTo(&in_use_list_);
272 return reinterpret_cast<void*
>(storage + 1);
277 storage != &free_list_;
278 storage = storage->next_) {
281 storage->LinkTo(&in_use_list_);
284 reinterpret_cast<char*
>(storage + 1) + size);
288 storage->size_ = size;
289 left_over->LinkTo(&free_list_);
290 return reinterpret_cast<void*
>(storage + 1);
304 if (!preallocated_storage_preallocated_) {
305 FreeStoreAllocationPolicy::Delete(p);
309 ASSERT(storage->next_->previous_ == storage);
310 ASSERT(storage->previous_->next_ == storage);
312 storage->LinkTo(&free_list_);
320 Isolate::ThreadDataTable* Isolate::thread_data_table_ =
NULL;
326 PerIsolateThreadData* per_thread =
new PerIsolateThreadData(
this, thread_id);
329 ASSERT(thread_data_table_->Lookup(
this, thread_id) ==
NULL);
330 thread_data_table_->Insert(per_thread);
331 ASSERT(thread_data_table_->Lookup(
this, thread_id) == per_thread);
337 Isolate::PerIsolateThreadData*
338 Isolate::FindOrAllocatePerThreadDataForThisThread() {
340 PerIsolateThreadData* per_thread =
NULL;
342 ScopedLock lock(process_wide_mutex_);
343 per_thread = thread_data_table_->Lookup(
this, thread_id);
344 if (per_thread ==
NULL) {
345 per_thread = AllocatePerIsolateThreadData(thread_id);
357 per_thread = thread_data_table_->Lookup(
this, thread_id);
365 if (default_isolate_ ==
NULL) {
369 thread_data_table_ =
new Isolate::ThreadDataTable();
370 default_isolate_ =
new Isolate();
385 #ifdef ENABLE_DEBUGGER_SUPPORT
386 Debugger* Isolate::GetDefaultIsolateDebugger() {
388 return default_isolate_->debugger();
405 if (data ==
NULL || data->
isolate() != default_isolate_) {
406 default_isolate_->Enter();
411 Isolate* Isolate::GetDefaultIsolateForLocking() {
413 return default_isolate_;
418 return isolate_addresses_[id];
423 ThreadLocalTop* thread =
reinterpret_cast<ThreadLocalTop*
>(thread_storage);
425 return thread_storage +
sizeof(ThreadLocalTop);
435 ThreadLocalTop* thread =
reinterpret_cast<ThreadLocalTop*
>(t);
445 if (thread->pending_exception_->ToObject(&pending)) {
446 v->VisitPointer(&pending);
447 thread->pending_exception_ = pending;
449 v->VisitPointer(&(thread->pending_message_obj_));
450 v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_)));
451 v->VisitPointer(BitCast<Object**>(&(thread->context_)));
453 if (thread->scheduled_exception_->ToObject(&scheduled)) {
454 v->VisitPointer(&scheduled);
455 thread->scheduled_exception_ = scheduled;
461 v->VisitPointer(BitCast<Object**>(&(block->exception_)));
462 v->VisitPointer(BitCast<Object**>(&(block->message_)));
466 for (StackFrameIterator it(
this, thread); !it.done(); it.Advance()) {
467 it.frame()->Iterate(v);
471 thread->top_lookup_result_->Iterate(v);
483 deferred = deferred->next_) {
484 deferred->Iterate(visitor);
504 reinterpret_cast<Address>(that->next_));
511 if (stack_trace_nesting_level_ == 0) {
512 stack_trace_nesting_level_++;
516 incomplete_message_ = &accumulator;
519 incomplete_message_ =
NULL;
520 stack_trace_nesting_level_ = 0;
522 }
else if (stack_trace_nesting_level_ == 1) {
523 stack_trace_nesting_level_++;
525 "\n\nAttempt to print stack while printing stack (double fault)\n");
527 "If you are lucky you may find a partial stack dump on stdout.\n\n");
529 return factory()->empty_symbol();
533 return factory()->empty_symbol();
538 void Isolate::PushStackTraceAndDie(
unsigned int magic,
541 unsigned int magic2) {
542 const int kMaxStackTraceSize = 8192;
544 char buffer[kMaxStackTraceSize];
545 int length =
Min(kMaxStackTraceSize - 1, trace->length());
547 buffer[length] =
'\0';
550 static_cast<void*>(
object), static_cast<void*>(map),
557 if (capture_stack_trace_for_uncaught_exceptions_) {
561 stack_trace_for_uncaught_exceptions_frame_limit_,
562 stack_trace_for_uncaught_exceptions_options_);
571 int limit =
Max(frame_limit, 0);
588 while (!it.done() && (frames_seen < limit)) {
594 for (
int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) {
602 int script_line_offset = script->line_offset()->value();
603 int position = frames[i].code()->SourcePosition(frames[i].
pc());
606 int relative_line_number = line_number - script_line_offset;
609 int start = (relative_line_number == 0) ? 0 :
610 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
611 int column_offset = position - start;
612 if (relative_line_number == 0) {
615 column_offset += script->column_offset()->value();
620 stack_frame, column_key,
626 stack_frame, line_key,
634 stack_frame, script_key, script_name,
NONE));
641 name_or_source_url_key);
642 ASSERT(property->IsJSFunction());
644 bool caught_exception;
646 NULL, &caught_exception);
647 if (caught_exception) {
648 result =
factory()->undefined_value();
652 stack_frame, script_name_or_source_url_key,
658 if (fun_name->ToBoolean()->IsFalse()) {
663 stack_frame, function_key, fun_name,
NONE));
667 int type =
Smi::cast(script->compilation_type())->value();
672 stack_frame, eval_key, is_eval,
NONE));
680 stack_frame, constructor_key,
681 is_constructor,
NONE));
696 if (stack_trace_nesting_level_ == 0) {
697 stack_trace_nesting_level_++;
700 if (preallocated_message_space_ ==
NULL) {
703 allocator = preallocated_message_space_;
708 incomplete_message_ = &accumulator;
713 incomplete_message_ =
NULL;
714 stack_trace_nesting_level_ = 0;
715 if (preallocated_message_space_ ==
NULL) {
719 }
else if (stack_trace_nesting_level_ == 1) {
720 stack_trace_nesting_level_++;
722 "\n\nAttempt to print stack while printing stack (double fault)\n");
724 "If you are lucky you may find a partial stack dump on stdout.\n\n");
731 StackFrame::PrintMode mode) {
732 StackFrameIterator it;
733 for (
int i = 0; !it.done(); it.Advance()) {
734 it.frame()->Print(accumulator, mode, i++);
742 "\n==== Stack trace is not available ==========================\n\n");
744 "\n==== Isolate for the thread is not initialized =============\n\n");
749 ASSERT(StringStream::IsMentionedObjectCacheClear());
755 "\n==== Stack trace ============================================\n\n");
756 PrintFrames(accumulator, StackFrame::OVERVIEW);
759 "\n==== Details ================================================\n\n");
760 PrintFrames(accumulator, StackFrame::DETAILS);
763 accumulator->
Add(
"=====================\n\n");
776 ASSERT(receiver->IsAccessCheckNeeded());
781 if (!constructor->shared()->IsApiFunction())
return;
783 constructor->shared()->get_api_func_data()->access_check_info();
784 if (data_obj == heap_.undefined_value())
return;
789 { VMState state(
this, EXTERNAL);
807 if (isolate->bootstrapper()->IsActive())
return YES;
809 if (receiver->IsJSGlobalProxy()) {
811 if (!receiver_context->IsContext())
return NO;
816 isolate->context()->global_object()->native_context();
817 if (receiver_context == native_context)
return YES;
820 native_context->security_token())
830 ASSERT(receiver->IsAccessCheckNeeded());
844 if (decision !=
UNKNOWN)
return decision ==
YES;
848 if (!constructor->shared()->IsApiFunction())
return false;
851 constructor->shared()->get_api_func_data()->access_check_info();
852 if (data_obj == heap_.undefined_value())
return false;
856 v8::ToCData<v8::NamedSecurityCallback>(fun_obj);
858 if (!callback)
return false;
864 LOG(
this, ApiNamedSecurityCheck(key));
868 VMState state(
this, EXTERNAL);
881 ASSERT(receiver->IsAccessCheckNeeded());
887 if (decision !=
UNKNOWN)
return decision ==
YES;
891 if (!constructor->shared()->IsApiFunction())
return false;
894 constructor->shared()->get_api_func_data()->access_check_info();
895 if (data_obj == heap_.undefined_value())
return false;
899 v8::ToCData<v8::IndexedSecurityCallback>(fun_obj);
901 if (!callback)
return false;
906 LOG(
this, ApiIndexedSecurityCheck(index));
910 VMState state(
this, EXTERNAL);
921 "Uncaught RangeError: Maximum call stack size exceeded";
952 bool can_be_caught_externally =
false;
961 if (exception->IsFailure())
return exception->ToFailureUnchecked();
967 return Throw(heap_.illegal_access_symbol());
995 int pos = frame->LookupCode()->SourcePosition(frame->pc());
1009 if (line->length() > 0) {
1023 Object* script = fun->shared()->script();
1024 if (script->IsScript() &&
1026 int pos = frame->LookupCode()->SourcePosition(frame->pc());
1036 bool catchable_by_javascript) {
1040 while (handler !=
NULL && !handler->is_catch()) {
1041 handler = handler->next();
1046 Address external_handler_address =
1052 *can_be_caught_externally = external_handler_address !=
NULL &&
1053 (handler ==
NULL || handler->address() > external_handler_address ||
1054 !catchable_by_javascript);
1056 if (*can_be_caught_externally) {
1061 return handler ==
NULL;
1067 if (!obj->IsJSObject())
return false;
1070 Object* error_constructor =
1073 for (
Object* prototype = *obj; !prototype->IsNull();
1074 prototype = prototype->GetPrototype()) {
1075 if (!prototype->IsJSObject())
return false;
1092 bool can_be_caught_externally =
false;
1093 bool should_report_exception =
1095 bool report_exception = catchable_by_javascript && should_report_exception;
1096 bool try_catch_needs_message =
1100 #ifdef ENABLE_DEBUGGER_SUPPORT
1102 if (catchable_by_javascript) {
1103 debugger_->OnException(exception_handle, report_exception);
1108 if (report_exception || try_catch_needs_message) {
1110 if (location ==
NULL) {
1113 location = &potential_computed_location;
1118 if (!bootstrapping) {
1122 if (capture_stack_trace_for_uncaught_exceptions_) {
1123 if (IsErrorObject(exception_handle)) {
1125 String* key =
heap()->hidden_stack_trace_symbol();
1130 if (stack_property->IsJSArray()) {
1134 if (stack_trace_object.
is_null()) {
1137 stack_trace_for_uncaught_exceptions_frame_limit_,
1138 stack_trace_for_uncaught_exceptions_options_);
1142 "uncaught_exception",
1144 HandleVector<Object>(&exception_handle, 1),
1146 stack_trace_object);
1148 if (location !=
NULL) {
1153 }
else if (location !=
NULL && !location->
script().is_null()) {
1161 if (exception->IsString()) {
1163 "Extension or internal compilation error: %s in %s at line %d.\n",
1169 "Extension or internal compilation error in %s at line %d.\n",
1204 Address external_handler_address =
1219 while (handler !=
NULL && handler->address() < external_handler_address) {
1220 ASSERT(!handler->is_catch());
1221 if (handler->is_finally())
return false;
1223 handler = handler->next();
1232 PropagatePendingExceptionToExternalTryCatch();
1241 }
else if (thread_local_top_.pending_exception_ ==
1242 heap()->termination_exception()) {
1246 if (thread_local_top_.has_pending_message_) {
1247 thread_local_top_.has_pending_message_ =
false;
1248 if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
1250 Handle<Object> message_obj(thread_local_top_.pending_message_obj_);
1251 if (thread_local_top_.pending_message_script_ !=
NULL) {
1252 Handle<Script> script(thread_local_top_.pending_message_script_);
1253 int start_pos = thread_local_top_.pending_message_start_pos_;
1254 int end_pos = thread_local_top_.pending_message_end_pos_;
1268 FLAG_trace_exception =
flag;
1274 PropagatePendingExceptionToExternalTryCatch();
1278 bool is_termination_exception =
1282 bool clear_exception = is_bottom_call;
1284 if (is_termination_exception) {
1285 if (is_bottom_call) {
1295 Address external_handler_address =
1298 if (it.done() || (it.frame()->sp() > external_handler_address)) {
1299 clear_exception =
true;
1304 if (clear_exception) {
1322 capture_stack_trace_for_uncaught_exceptions_ = capture;
1323 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit;
1324 stack_trace_for_uncaught_exceptions_options_ = options;
1359 #ifdef ENABLE_DEBUGGER_SUPPORT
1360 if (debug_->InDebugger()) {
1361 while (!it.done()) {
1371 #endif // ENABLE_DEBUGGER_SUPPORT
1384 sizeof(ThreadLocalTop));
1385 InitializeThreadLocal();
1389 return to +
sizeof(ThreadLocalTop);
1395 sizeof(ThreadLocalTop));
1398 #ifdef USE_SIMULATOR
1399 #ifdef V8_TARGET_ARCH_ARM
1401 #elif V8_TARGET_ARCH_MIPS
1409 return from +
sizeof(ThreadLocalTop);
1413 Isolate::ThreadDataTable::ThreadDataTable()
1418 Isolate::PerIsolateThreadData*
1419 Isolate::ThreadDataTable::Lookup(
Isolate* isolate,
1420 ThreadId thread_id) {
1421 for (PerIsolateThreadData* data = list_; data !=
NULL; data = data->next_) {
1422 if (data->Matches(isolate, thread_id))
return data;
1428 void Isolate::ThreadDataTable::Insert(Isolate::PerIsolateThreadData* data) {
1429 if (list_ !=
NULL) list_->prev_ = data;
1430 data->next_ = list_;
1435 void Isolate::ThreadDataTable::Remove(PerIsolateThreadData* data) {
1436 if (list_ == data) list_ = data->next_;
1437 if (data->next_ !=
NULL) data->next_->prev_ = data->prev_;
1438 if (data->prev_ !=
NULL) data->prev_->next_ = data->next_;
1443 void Isolate::ThreadDataTable::Remove(Isolate* isolate,
1444 ThreadId thread_id) {
1445 PerIsolateThreadData* data = Lookup(isolate, thread_id);
1452 void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) {
1453 PerIsolateThreadData* data = list_;
1454 while (data !=
NULL) {
1455 PerIsolateThreadData* next = data->next_;
1456 if (data->isolate() == isolate) Remove(data);
1463 #define TRACE_ISOLATE(tag) \
1465 if (FLAG_trace_isolates) { \
1466 PrintF("Isolate %p " #tag "\n", reinterpret_cast<void*>(this)); \
1470 #define TRACE_ISOLATE(tag)
1476 embedder_data_(
NULL),
1478 stack_trace_nesting_level_(0),
1479 incomplete_message_(
NULL),
1480 preallocated_memory_thread_(
NULL),
1481 preallocated_message_space_(
NULL),
1482 bootstrapper_(
NULL),
1483 runtime_profiler_(
NULL),
1484 compilation_cache_(
NULL),
1488 break_access_(OS::CreateMutex()),
1489 debugger_initialized_(
false),
1491 debugger_access_(OS::CreateMutex()),
1495 deoptimizer_data_(
NULL),
1496 capture_stack_trace_for_uncaught_exceptions_(
false),
1497 stack_trace_for_uncaught_exceptions_frame_limit_(0),
1498 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview),
1499 transcendental_cache_(
NULL),
1500 memory_allocator_(
NULL),
1501 keyed_lookup_cache_(
NULL),
1502 context_slot_cache_(
NULL),
1503 descriptor_lookup_cache_(
NULL),
1504 handle_scope_implementer_(
NULL),
1505 unicode_cache_(
NULL),
1506 runtime_zone_(this),
1509 preallocated_storage_preallocated_(
false),
1510 inner_pointer_to_code_cache_(
NULL),
1511 write_input_buffer_(
NULL),
1512 global_handles_(
NULL),
1513 context_switcher_(
NULL),
1514 thread_manager_(
NULL),
1515 fp_stubs_generated_(
false),
1516 has_installed_extensions_(
false),
1517 string_tracker_(
NULL),
1518 regexp_stack_(
NULL),
1520 context_exit_happened_(
false),
1521 deferred_handles_head_(
NULL),
1522 optimizing_compiler_thread_(this) {
1525 memset(isolate_addresses_, 0,
1526 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1));
1528 heap_.isolate_ =
this;
1529 stack_guard_.isolate_ =
this;
1533 thread_manager_ =
new ThreadManager();
1534 thread_manager_->isolate_ =
this;
1536 #if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \
1537 defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__)
1538 simulator_initialized_ =
false;
1539 simulator_i_cache_ =
NULL;
1540 simulator_redirection_ =
NULL;
1545 memset(&js_spill_information_, 0,
sizeof(js_spill_information_));
1546 memset(code_kind_statistics_, 0,
1547 sizeof(code_kind_statistics_[0]) * Code::NUMBER_OF_KINDS);
1550 #ifdef ENABLE_DEBUGGER_SUPPORT
1555 handle_scope_data_.Initialize();
1557 #define ISOLATE_INIT_EXECUTE(type, name, initial_value) \
1558 name##_ = (initial_value);
1560 #undef ISOLATE_INIT_EXECUTE
1562 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \
1563 memset(name##_, 0, sizeof(type) * length);
1565 #undef ISOLATE_INIT_ARRAY_EXECUTE
1568 void Isolate::TearDown() {
1576 Isolate* saved_isolate = UncheckedCurrent();
1577 SetIsolateThreadLocals(
this,
NULL);
1582 thread_data_table_->RemoveAllThreads(
this);
1585 if (serialize_partial_snapshot_cache_ !=
NULL) {
1586 delete[] serialize_partial_snapshot_cache_;
1587 serialize_partial_snapshot_cache_ =
NULL;
1590 if (!IsDefaultIsolate()) {
1595 SetIsolateThreadLocals(saved_isolate, saved_data);
1599 void Isolate::Deinit() {
1600 if (state_ == INITIALIZED) {
1603 if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Stop();
1605 if (FLAG_hydrogen_stats) HStatistics::Instance()->Print();
1608 logger_->EnsureTickerStopped();
1610 delete deoptimizer_data_;
1611 deoptimizer_data_ =
NULL;
1612 if (FLAG_preemption) {
1616 builtins_.TearDown();
1617 bootstrapper_->TearDown();
1620 delete preallocated_message_space_;
1621 preallocated_message_space_ =
NULL;
1622 PreallocatedMemoryThreadStop();
1624 HeapProfiler::TearDown();
1625 CpuProfiler::TearDown();
1626 if (runtime_profiler_ !=
NULL) {
1627 runtime_profiler_->TearDown();
1628 delete runtime_profiler_;
1629 runtime_profiler_ =
NULL;
1632 logger_->TearDown();
1640 void Isolate::PushToPartialSnapshotCache(
Object* obj) {
1641 int length = serialize_partial_snapshot_cache_length();
1642 int capacity = serialize_partial_snapshot_cache_capacity();
1644 if (length >= capacity) {
1645 int new_capacity =
static_cast<int>((capacity + 10) * 1.2);
1647 for (
int i = 0; i < length; i++) {
1648 new_array[i] = serialize_partial_snapshot_cache()[i];
1650 if (capacity != 0)
delete[] serialize_partial_snapshot_cache();
1651 set_serialize_partial_snapshot_cache(new_array);
1652 set_serialize_partial_snapshot_cache_capacity(new_capacity);
1655 serialize_partial_snapshot_cache()[length] = obj;
1656 set_serialize_partial_snapshot_cache_length(length + 1);
1660 void Isolate::SetIsolateThreadLocals(
Isolate* isolate,
1661 PerIsolateThreadData* data) {
1662 Thread::SetThreadLocal(isolate_key_, isolate);
1663 Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
1667 Isolate::~Isolate() {
1671 runtime_zone_.DeleteKeptSegment();
1673 delete[] assembler_spare_buffer_;
1674 assembler_spare_buffer_ =
NULL;
1676 delete unicode_cache_;
1677 unicode_cache_ =
NULL;
1682 delete regexp_stack_;
1683 regexp_stack_ =
NULL;
1685 delete descriptor_lookup_cache_;
1686 descriptor_lookup_cache_ =
NULL;
1687 delete context_slot_cache_;
1688 context_slot_cache_ =
NULL;
1689 delete keyed_lookup_cache_;
1690 keyed_lookup_cache_ =
NULL;
1692 delete transcendental_cache_;
1693 transcendental_cache_ =
NULL;
1696 delete stats_table_;
1697 stats_table_ =
NULL;
1705 delete handle_scope_implementer_;
1706 handle_scope_implementer_ =
NULL;
1707 delete break_access_;
1708 break_access_ =
NULL;
1709 delete debugger_access_;
1710 debugger_access_ =
NULL;
1712 delete compilation_cache_;
1713 compilation_cache_ =
NULL;
1714 delete bootstrapper_;
1715 bootstrapper_ =
NULL;
1716 delete inner_pointer_to_code_cache_;
1717 inner_pointer_to_code_cache_ =
NULL;
1718 delete write_input_buffer_;
1719 write_input_buffer_ =
NULL;
1721 delete context_switcher_;
1722 context_switcher_ =
NULL;
1723 delete thread_manager_;
1724 thread_manager_ =
NULL;
1726 delete string_tracker_;
1727 string_tracker_ =
NULL;
1729 delete memory_allocator_;
1730 memory_allocator_ =
NULL;
1733 delete global_handles_;
1734 global_handles_ =
NULL;
1736 delete external_reference_table_;
1737 external_reference_table_ =
NULL;
1739 #ifdef ENABLE_DEBUGGER_SUPPORT
1748 void Isolate::InitializeThreadLocal() {
1749 thread_local_top_.isolate_ =
this;
1750 thread_local_top_.Initialize();
1754 void Isolate::PropagatePendingExceptionToExternalTryCatch() {
1755 ASSERT(has_pending_exception());
1757 bool external_caught = IsExternallyCaught();
1758 thread_local_top_.external_caught_exception_ = external_caught;
1760 if (!external_caught)
return;
1762 if (thread_local_top_.pending_exception_ == Failure::OutOfMemoryException()) {
1764 }
else if (thread_local_top_.pending_exception_ ==
1765 heap()->termination_exception()) {
1766 try_catch_handler()->can_continue_ =
false;
1767 try_catch_handler()->exception_ = heap()->null_value();
1771 ASSERT(!pending_exception()->IsFailure());
1772 try_catch_handler()->can_continue_ =
true;
1773 try_catch_handler()->exception_ = pending_exception();
1774 if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
1775 try_catch_handler()->message_ = thread_local_top_.pending_message_obj_;
1781 void Isolate::InitializeLoggingAndCounters() {
1782 if (logger_ ==
NULL) {
1785 if (counters_ ==
NULL) {
1791 void Isolate::InitializeDebugger() {
1792 #ifdef ENABLE_DEBUGGER_SUPPORT
1795 InitializeLoggingAndCounters();
1796 debug_ =
new Debug(
this);
1797 debugger_ =
new Debugger(
this);
1804 ASSERT(state_ != INITIALIZED);
1805 ASSERT(Isolate::Current() ==
this);
1811 InitializeLoggingAndCounters();
1813 InitializeDebugger();
1820 heap_.SetStackLimits();
1822 #define ASSIGN_ELEMENT(CamelName, hacker_name) \
1823 isolate_addresses_[Isolate::k##CamelName##Address] = \
1824 reinterpret_cast<Address>(hacker_name##_address());
1829 string_tracker_->isolate_ =
this;
1841 stub_cache_ =
new StubCache(
this, runtime_zone());
1843 regexp_stack_->isolate_ =
this;
1849 CpuProfiler::SetUp();
1850 HeapProfiler::SetUp();
1853 #if defined(USE_SIMULATOR)
1854 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS)
1855 Simulator::Initialize(
this);
1863 ExecutionAccess lock(
this);
1864 stack_guard_.InitThread(lock);
1868 const bool create_heap_objects = (des ==
NULL);
1869 ASSERT(!heap_.HasBeenSetUp());
1870 if (!heap_.SetUp(create_heap_objects)) {
1871 V8::SetFatalError();
1875 if (create_heap_objects) {
1877 PushToPartialSnapshotCache(heap_.undefined_value());
1880 InitializeThreadLocal();
1882 bootstrapper_->Initialize(create_heap_objects);
1883 builtins_.SetUp(create_heap_objects);
1886 if (FLAG_preallocate_message_memory && preallocated_message_space_ ==
NULL) {
1888 PreallocatedMemoryThreadStart();
1889 preallocated_message_space_ =
1891 preallocated_memory_thread_->data(),
1892 preallocated_memory_thread_->length());
1893 PreallocatedStorageInit(preallocated_memory_thread_->length() / 4);
1896 if (FLAG_preemption) {
1901 #ifdef ENABLE_DEBUGGER_SUPPORT
1902 debug_->SetUp(create_heap_objects);
1906 if (!create_heap_objects) {
1909 stub_cache_->Initialize();
1912 clear_pending_exception();
1913 clear_pending_message();
1914 clear_scheduled_exception();
1918 heap_.SetStackLimits();
1921 if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value());
1925 runtime_profiler_->SetUp();
1929 if (create_heap_objects &&
1930 (FLAG_log_code || FLAG_ll_prof || logger_->is_logging_code_events())) {
1932 LOG(
this, LogCodeObjects());
1933 LOG(
this, LogCompiledFunctions());
1937 Internals::kIsolateStateOffset);
1939 Internals::kIsolateEmbedderDataOffset);
1941 Internals::kIsolateRootsOffset);
1943 state_ = INITIALIZED;
1944 time_millis_at_init_ = OS::TimeCurrentMillis();
1945 if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Start();
1953 if (stats_table_ ==
NULL) {
1956 return stats_table_;
1960 void Isolate::Enter() {
1962 PerIsolateThreadData* current_data = CurrentPerIsolateThreadData();
1963 if (current_data !=
NULL) {
1964 current_isolate = current_data->isolate_;
1966 if (current_isolate ==
this) {
1967 ASSERT(Current() ==
this);
1969 ASSERT(entry_stack_->previous_thread_data ==
NULL ||
1970 entry_stack_->previous_thread_data->thread_id().Equals(
1971 ThreadId::Current()));
1973 entry_stack_->entry_count++;
1984 if (current_isolate ==
NULL) {
1985 current_isolate = Isolate::UncheckedCurrent();
1988 PerIsolateThreadData* data = FindOrAllocatePerThreadDataForThisThread();
1990 ASSERT(data->isolate_ ==
this);
1992 EntryStackItem* item =
new EntryStackItem(current_data,
1995 entry_stack_ = item;
1997 SetIsolateThreadLocals(
this, data);
2000 set_thread_id(data->thread_id());
2004 void Isolate::Exit() {
2006 ASSERT(entry_stack_->previous_thread_data ==
NULL ||
2007 entry_stack_->previous_thread_data->thread_id().Equals(
2008 ThreadId::Current()));
2010 if (--entry_stack_->entry_count > 0)
return;
2012 ASSERT(CurrentPerIsolateThreadData() !=
NULL);
2013 ASSERT(CurrentPerIsolateThreadData()->isolate_ ==
this);
2016 EntryStackItem* item = entry_stack_;
2017 entry_stack_ = item->previous_item;
2019 PerIsolateThreadData* previous_thread_data = item->previous_thread_data;
2020 Isolate* previous_isolate = item->previous_isolate;
2025 SetIsolateThreadLocals(previous_isolate, previous_thread_data);
2030 deferred->next_ = deferred_handles_head_;
2031 if (deferred_handles_head_ !=
NULL) {
2032 deferred_handles_head_->previous_ = deferred;
2034 deferred_handles_head_ = deferred;
2042 while (deferred_iterator->previous_ !=
NULL) {
2043 deferred_iterator = deferred_iterator->previous_;
2045 ASSERT(deferred_handles_head_ == deferred_iterator);
2047 if (deferred_handles_head_ == deferred) {
2048 deferred_handles_head_ = deferred_handles_head_->next_;
2050 if (deferred->next_ !=
NULL) {
2051 deferred->next_->previous_ = deferred->previous_;
2053 if (deferred->previous_ !=
NULL) {
2054 deferred->previous_->next_ = deferred->next_;
2060 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
2061 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
2064 #undef ISOLATE_FIELD_OFFSET
void TraceException(bool flag)
#define CHECK_NOT_EMPTY_HANDLE(isolate, call)
Failure * StackOverflow()
static void * GetThreadLocal(LocalStorageKey key)
Handle< JSObject > NewJSObject(Handle< JSFunction > constructor, PretenureFlag pretenure=NOT_TENURED)
Object * function() const
#define CHECK_EQ(expected, value)
const char * ToCString(const v8::String::Utf8Value &value)
static Handle< Object > TryCall(Handle< JSFunction > func, Handle< Object > receiver, int argc, Handle< Object > argv[], bool *caught_exception)
MaybeObject * pending_exception()
static void IsolateEnteredJS(Isolate *isolate)
static String * cast(Object *obj)
void ScheduleThrow(Object *exception)
Handle< Context > GetCallingNativeContext()
StateTag current_vm_state()
static Handle< JSMessageObject > MakeMessageObject(const char *type, MessageLocation *loc, Vector< Handle< Object > > args, Handle< String > stack_trace, Handle< JSArray > stack_frames)
static Smi * FromInt(int value)
#define LOG(isolate, Call)
void ReportFailedAccessCheck(JSObject *receiver, v8::AccessType type)
Handle< JSArray > NewJSArray(int capacity, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, PretenureFlag pretenure=NOT_TENURED)
static Handle< T > cast(Handle< S > that)
bool MayNamedAccess(JSObject *receiver, Object *key, v8::AccessType type)
Address get_address_from_id(AddressId id)
static Failure * OutOfMemoryException()
void IterateDeferredHandles(ObjectVisitor *visitor)
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
void DoThrow(Object *exception, MessageLocation *location)
bool IsExternallyCaught()
void mark_out_of_memory()
Bootstrapper * bootstrapper()
static Failure * Exception()
Failure * ReThrow(MaybeObject *exception)
PerIsolateThreadData * FindPerThreadDataForThisThread()
struct v8::internal::StaticInitializer static_initializer
virtual void Summarize(List< FrameSummary > *frames)
static Address handler(ThreadLocalTop *thread)
#define ASSERT(condition)
static PerIsolateThreadData * CurrentPerIsolateThreadData()
void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback)
void PrintMentionedObjectCache()
static StackGuard * GetDefaultIsolateStackGuard()
static Script * cast(Object *obj)
void clear_pending_exception()
static Context * cast(Object *context)
#define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length)
void clear_scheduled_exception()
static void UnregisterCTryCatch()
void PreallocatedStorageInit(size_t size)
Handle< Object > GetProperty(Handle< JSReceiver > obj, const char *name)
static int GetThreadLocalInt(LocalStorageKey key)
Handle< String > LookupAsciiSymbol(Vector< const char > str)
static Handle< Object > SetHiddenProperty(Handle< JSObject > obj, Handle< String > key, Handle< Object > value)
Handle< String > ToString()
static Smi * cast(Object *object)
void(* FailedAccessCheckCallback)(Local< Object > target, AccessType type, Local< Value > data)
void clear_pending_message()
void CaptureAndSetCurrentStackTraceFor(Handle< JSObject > error_object)
StackGuard * stack_guard()
void Add(Vector< const char > format, Vector< FmtElm > elms)
Handle< Context > global_context()
bool OptionalRescheduleException(bool is_bottom_call)
Object * receiver() const
Address try_catch_handler_address()
static void EnsureDefaultIsolate()
void ReportPendingMessages()
#define ISOLATE_INIT_LIST(V)
static JSGlobalProxy * cast(Object *obj)
static Address c_entry_fp(ThreadLocalTop *thread)
#define OFFSET_OF(type, field)
v8::TryCatch * try_catch_handler()
static ThreadId Current()
Context * native_context()
static Failure * cast(MaybeObject *object)
void ComputeLocation(MessageLocation *target)
static void EnterDefaultIsolate()
MaybeObject * scheduled_exception()
static LocalStorageKey CreateThreadLocalKey()
void PrintCurrentStackTrace(FILE *out)
void Iterate(ObjectVisitor *v)
Handle< JSArray > CaptureCurrentStackTrace(int frame_limit, StackTrace::StackTraceOptions options)
Handle< JSValue > GetScriptWrapper(Handle< Script > script)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
static Handle< Object > SetLocalPropertyIgnoreAttributes(Handle< JSObject > object, Handle< String > key, Handle< Object > value, PropertyAttributes attributes)
int GetScriptLineNumberSafe(Handle< Script > script, int code_pos)
static Mutex * CreateMutex()
Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr, Atomic32 increment)
bool has_pending_exception()
void * PreallocatedStorageNew(size_t size)
void SetCaptureStackTraceForUncaughtExceptions(bool capture, int frame_limit, StackTrace::StackTraceOptions options)
Handle< JSBuiltinsObject > js_builtins_object()
Failure * Throw(Object *exception, MessageLocation *location=NULL)
Handle< Script > script() const
void Release_Store(volatile Atomic32 *ptr, Atomic32 value)
activate correct semantics for inheriting readonliness false
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
static JSArray * cast(Object *obj)
Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr)
#define ISOLATE_INIT_EXECUTE(type, name, initial_value)
int GetScriptLineNumber(Handle< Script > script, int code_pos)
Failure * PromoteScheduledException()
virtual void VisitThread(Isolate *isolate, ThreadLocalTop *top)=0
bool IsOutOfMemoryException() const
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
#define FOR_EACH_ISOLATE_ADDRESS_NAME(C)
void IterateThread(ThreadVisitor *v)
JavaScriptFrameIteratorTemp< StackFrameIterator > JavaScriptFrameIterator
static AccessCheckInfo * cast(Object *obj)
static void IsolateExitedJS(Isolate *isolate)
static void SetThreadLocal(LocalStorageKey key, void *value)
Handle< String > StackTraceString()
void set_pending_exception(MaybeObject *exception)
static void PrintError(const char *format,...)
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
#define TRACE_ISOLATE(tag)
bool MayIndexedAccess(JSObject *receiver, uint32_t index, v8::AccessType type)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
static void StrNCpy(Vector< char > dest, const char *src, size_t n)
Isolate * isolate() const
static void StartPreemption(int every_n_ms)
static FixedArray * cast(Object *obj)
void InitializeLoggingAndCounters()
void UnregisterTryCatchHandler(v8::TryCatch *that)
Failure * TerminateExecution()
char * ArchiveThread(char *to)
Object * GetHiddenProperty(String *key)
Failure * ThrowIllegalOperation()
static ThreadId Invalid()
static Handle< String > GetStackTraceLine(Handle< Object > recv, Handle< JSFunction > fun, Handle< Object > pos, Handle< Object > is_global)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
void RegisterTryCatchHandler(v8::TryCatch *that)
bool is_catchable_by_javascript(MaybeObject *exception)
static const int kMaxInliningLevels
char * RestoreThread(char *from)
static void ClearMentionedObjectCache()
bool has_scheduled_exception()
Handle< Context > native_context()
static uintptr_t RegisterCTryCatch(uintptr_t try_catch_address)
static void ReportMessage(Isolate *isolate, MessageLocation *loc, Handle< Object > message)
bool ShouldReportException(bool *can_be_caught_externally, bool catchable_by_javascript)
ThreadLocalTop * thread_local_top()
static void StopPreemption()
static const char *const kStackOverflowMessage
static void SetThreadLocalInt(LocalStorageKey key, int value)
static JSObject * cast(Object *obj)
#define ISOLATE_INIT_ARRAY_LIST(V)
void PreallocatedStorageDelete(void *p)
#define TRY_CATCH_FROM_ADDRESS(try_catch_address)
Handle< JSObject > Copy(Handle< JSObject > obj)
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset flag
#define ASSIGN_ELEMENT(CamelName, hacker_name)
static JSFunction * cast(Object *obj)