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);
496 reinterpret_cast<Address>(that->next_));
503 if (stack_trace_nesting_level_ == 0) {
504 stack_trace_nesting_level_++;
508 incomplete_message_ = &accumulator;
511 incomplete_message_ =
NULL;
512 stack_trace_nesting_level_ = 0;
514 }
else if (stack_trace_nesting_level_ == 1) {
515 stack_trace_nesting_level_++;
517 "\n\nAttempt to print stack while printing stack (double fault)\n");
519 "If you are lucky you may find a partial stack dump on stdout.\n\n");
521 return factory()->empty_symbol();
525 return factory()->empty_symbol();
531 if (capture_stack_trace_for_uncaught_exceptions_) {
535 stack_trace_for_uncaught_exceptions_frame_limit_,
536 stack_trace_for_uncaught_exceptions_options_);
545 int limit =
Max(frame_limit, 0);
562 while (!it.done() && (frames_seen < limit)) {
568 for (
int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) {
576 int script_line_offset = script->line_offset()->value();
577 int position = frames[i].code()->SourcePosition(frames[i].
pc());
580 int relative_line_number = line_number - script_line_offset;
583 int start = (relative_line_number == 0) ? 0 :
584 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
585 int column_offset = position - start;
586 if (relative_line_number == 0) {
589 column_offset += script->column_offset()->value();
594 stack_frame, column_key,
600 stack_frame, line_key,
608 stack_frame, script_key, script_name,
NONE));
615 name_or_source_url_key);
616 ASSERT(property->IsJSFunction());
618 bool caught_exception;
620 NULL, &caught_exception);
621 if (caught_exception) {
622 result =
factory()->undefined_value();
626 stack_frame, script_name_or_source_url_key,
632 if (fun_name->ToBoolean()->IsFalse()) {
637 stack_frame, function_key, fun_name,
NONE));
646 stack_frame, eval_key, is_eval,
NONE));
654 stack_frame, constructor_key,
655 is_constructor,
NONE));
670 if (stack_trace_nesting_level_ == 0) {
671 stack_trace_nesting_level_++;
674 if (preallocated_message_space_ ==
NULL) {
677 allocator = preallocated_message_space_;
682 incomplete_message_ = &accumulator;
687 incomplete_message_ =
NULL;
688 stack_trace_nesting_level_ = 0;
689 if (preallocated_message_space_ ==
NULL) {
693 }
else if (stack_trace_nesting_level_ == 1) {
694 stack_trace_nesting_level_++;
696 "\n\nAttempt to print stack while printing stack (double fault)\n");
698 "If you are lucky you may find a partial stack dump on stdout.\n\n");
705 StackFrame::PrintMode mode) {
706 StackFrameIterator it;
707 for (
int i = 0; !it.done(); it.Advance()) {
708 it.frame()->Print(accumulator, mode, i++);
716 "\n==== Stack trace is not available ==========================\n\n");
718 "\n==== Isolate for the thread is not initialized =============\n\n");
723 ASSERT(StringStream::IsMentionedObjectCacheClear());
729 "\n==== Stack trace ============================================\n\n");
730 PrintFrames(accumulator, StackFrame::OVERVIEW);
733 "\n==== Details ================================================\n\n");
734 PrintFrames(accumulator, StackFrame::DETAILS);
737 accumulator->
Add(
"=====================\n\n");
750 ASSERT(receiver->IsAccessCheckNeeded());
755 if (!constructor->shared()->IsApiFunction())
return;
757 constructor->shared()->get_api_func_data()->access_check_info();
758 if (data_obj == heap_.undefined_value())
return;
763 { VMState state(
this, EXTERNAL);
781 if (isolate->bootstrapper()->IsActive())
return YES;
783 if (receiver->IsJSGlobalProxy()) {
785 if (!receiver_context->IsContext())
return NO;
789 Context* global_context = isolate->context()->global()->global_context();
790 if (receiver_context == global_context)
return YES;
793 global_context->security_token())
803 ASSERT(receiver->IsAccessCheckNeeded());
817 if (decision !=
UNKNOWN)
return decision ==
YES;
821 if (!constructor->shared()->IsApiFunction())
return false;
824 constructor->shared()->get_api_func_data()->access_check_info();
825 if (data_obj == heap_.undefined_value())
return false;
829 v8::ToCData<v8::NamedSecurityCallback>(fun_obj);
831 if (!callback)
return false;
837 LOG(
this, ApiNamedSecurityCheck(key));
841 VMState state(
this, EXTERNAL);
854 ASSERT(receiver->IsAccessCheckNeeded());
860 if (decision !=
UNKNOWN)
return decision ==
YES;
864 if (!constructor->shared()->IsApiFunction())
return false;
867 constructor->shared()->get_api_func_data()->access_check_info();
868 if (data_obj == heap_.undefined_value())
return false;
872 v8::ToCData<v8::IndexedSecurityCallback>(fun_obj);
874 if (!callback)
return false;
879 LOG(
this, ApiIndexedSecurityCheck(index));
883 VMState state(
this, EXTERNAL);
894 "Uncaught RangeError: Maximum call stack size exceeded";
925 bool can_be_caught_externally =
false;
934 if (exception->IsFailure())
return exception->ToFailureUnchecked();
940 return Throw(heap_.illegal_access_symbol());
968 int pos = frame->LookupCode()->SourcePosition(frame->pc());
982 if (line->length() > 0) {
996 Object* script = fun->shared()->script();
997 if (script->IsScript() &&
999 int pos = frame->LookupCode()->SourcePosition(frame->pc());
1009 bool catchable_by_javascript) {
1013 while (handler !=
NULL && !handler->is_catch()) {
1014 handler = handler->next();
1019 Address external_handler_address =
1025 *can_be_caught_externally = external_handler_address !=
NULL &&
1026 (handler ==
NULL || handler->
address() > external_handler_address ||
1027 !catchable_by_javascript);
1029 if (*can_be_caught_externally) {
1034 return handler ==
NULL;
1040 if (!obj->IsJSObject())
return false;
1043 Object* error_constructor =
1046 for (
Object* prototype = *obj; !prototype->IsNull();
1047 prototype = prototype->GetPrototype()) {
1048 if (!prototype->IsJSObject())
return false;
1065 bool can_be_caught_externally =
false;
1066 bool should_report_exception =
1068 bool report_exception = catchable_by_javascript && should_report_exception;
1069 bool try_catch_needs_message =
1073 #ifdef ENABLE_DEBUGGER_SUPPORT
1075 if (catchable_by_javascript) {
1076 debugger_->OnException(exception_handle, report_exception);
1081 if (report_exception || try_catch_needs_message) {
1083 if (location ==
NULL) {
1086 location = &potential_computed_location;
1091 if (!bootstrapping) {
1095 if (capture_stack_trace_for_uncaught_exceptions_) {
1096 if (IsErrorObject(exception_handle)) {
1098 String* key =
heap()->hidden_stack_trace_symbol();
1103 if (stack_property->IsJSArray()) {
1107 if (stack_trace_object.
is_null()) {
1110 stack_trace_for_uncaught_exceptions_frame_limit_,
1111 stack_trace_for_uncaught_exceptions_options_);
1115 "uncaught_exception",
1117 HandleVector<Object>(&exception_handle, 1),
1119 stack_trace_object);
1121 if (location !=
NULL) {
1126 }
else if (location !=
NULL && !location->
script().is_null()) {
1134 if (exception->IsString()) {
1136 "Extension or internal compilation error: %s in %s at line %d.\n",
1142 "Extension or internal compilation error in %s at line %d.\n",
1177 Address external_handler_address =
1192 while (handler !=
NULL && handler->
address() < external_handler_address) {
1193 ASSERT(!handler->is_catch());
1194 if (handler->is_finally())
return false;
1196 handler = handler->next();
1205 PropagatePendingExceptionToExternalTryCatch();
1214 }
else if (thread_local_top_.pending_exception_ ==
1215 heap()->termination_exception()) {
1219 if (thread_local_top_.has_pending_message_) {
1220 thread_local_top_.has_pending_message_ =
false;
1221 if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
1223 Handle<Object> message_obj(thread_local_top_.pending_message_obj_);
1224 if (thread_local_top_.pending_message_script_ !=
NULL) {
1225 Handle<Script> script(thread_local_top_.pending_message_script_);
1226 int start_pos = thread_local_top_.pending_message_start_pos_;
1227 int end_pos = thread_local_top_.pending_message_end_pos_;
1241 FLAG_trace_exception =
flag;
1247 PropagatePendingExceptionToExternalTryCatch();
1251 bool is_termination_exception =
1255 bool clear_exception = is_bottom_call;
1257 if (is_termination_exception) {
1258 if (is_bottom_call) {
1268 Address external_handler_address =
1271 if (it.done() || (it.frame()->sp() > external_handler_address)) {
1272 clear_exception =
true;
1277 if (clear_exception) {
1295 capture_stack_trace_for_uncaught_exceptions_ = capture;
1296 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit;
1297 stack_trace_for_uncaught_exceptions_options_ = options;
1326 #ifdef ENABLE_DEBUGGER_SUPPORT
1327 if (debug_->InDebugger()) {
1328 while (!it.done()) {
1338 #endif // ENABLE_DEBUGGER_SUPPORT
1351 sizeof(ThreadLocalTop));
1352 InitializeThreadLocal();
1356 return to +
sizeof(ThreadLocalTop);
1362 sizeof(ThreadLocalTop));
1365 #ifdef USE_SIMULATOR
1366 #ifdef V8_TARGET_ARCH_ARM
1368 #elif V8_TARGET_ARCH_MIPS
1376 return from +
sizeof(ThreadLocalTop);
1380 Isolate::ThreadDataTable::ThreadDataTable()
1385 Isolate::PerIsolateThreadData*
1386 Isolate::ThreadDataTable::Lookup(
Isolate* isolate,
1387 ThreadId thread_id) {
1388 for (PerIsolateThreadData* data = list_; data !=
NULL; data = data->next_) {
1389 if (data->Matches(isolate, thread_id))
return data;
1395 void Isolate::ThreadDataTable::Insert(Isolate::PerIsolateThreadData* data) {
1396 if (list_ !=
NULL) list_->prev_ = data;
1397 data->next_ = list_;
1402 void Isolate::ThreadDataTable::Remove(PerIsolateThreadData* data) {
1403 if (list_ == data) list_ = data->next_;
1404 if (data->next_ !=
NULL) data->next_->prev_ = data->prev_;
1405 if (data->prev_ !=
NULL) data->prev_->next_ = data->next_;
1410 void Isolate::ThreadDataTable::Remove(Isolate* isolate,
1411 ThreadId thread_id) {
1412 PerIsolateThreadData* data = Lookup(isolate, thread_id);
1419 void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) {
1420 PerIsolateThreadData* data = list_;
1421 while (data !=
NULL) {
1422 PerIsolateThreadData* next = data->next_;
1423 if (data->isolate() == isolate) Remove(data);
1430 #define TRACE_ISOLATE(tag) \
1432 if (FLAG_trace_isolates) { \
1433 PrintF("Isolate %p " #tag "\n", reinterpret_cast<void*>(this)); \
1437 #define TRACE_ISOLATE(tag)
1443 embedder_data_(
NULL),
1445 stack_trace_nesting_level_(0),
1446 incomplete_message_(
NULL),
1447 preallocated_memory_thread_(
NULL),
1448 preallocated_message_space_(
NULL),
1449 bootstrapper_(
NULL),
1450 runtime_profiler_(
NULL),
1451 compilation_cache_(
NULL),
1455 break_access_(OS::CreateMutex()),
1456 debugger_initialized_(
false),
1458 debugger_access_(OS::CreateMutex()),
1462 deoptimizer_data_(
NULL),
1463 capture_stack_trace_for_uncaught_exceptions_(
false),
1464 stack_trace_for_uncaught_exceptions_frame_limit_(0),
1465 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview),
1466 transcendental_cache_(
NULL),
1467 memory_allocator_(
NULL),
1468 keyed_lookup_cache_(
NULL),
1469 context_slot_cache_(
NULL),
1470 descriptor_lookup_cache_(
NULL),
1471 handle_scope_implementer_(
NULL),
1472 unicode_cache_(
NULL),
1475 preallocated_storage_preallocated_(
false),
1476 inner_pointer_to_code_cache_(
NULL),
1477 write_input_buffer_(
NULL),
1478 global_handles_(
NULL),
1479 context_switcher_(
NULL),
1480 thread_manager_(
NULL),
1481 fp_stubs_generated_(
false),
1482 has_installed_extensions_(
false),
1483 string_tracker_(
NULL),
1484 regexp_stack_(
NULL),
1486 context_exit_happened_(
false) {
1489 memset(isolate_addresses_, 0,
1490 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1));
1492 heap_.isolate_ =
this;
1493 zone_.isolate_ =
this;
1494 stack_guard_.isolate_ =
this;
1498 thread_manager_ =
new ThreadManager();
1499 thread_manager_->isolate_ =
this;
1501 #if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \
1502 defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__)
1503 simulator_initialized_ =
false;
1504 simulator_i_cache_ =
NULL;
1505 simulator_redirection_ =
NULL;
1510 memset(&js_spill_information_, 0,
sizeof(js_spill_information_));
1511 memset(code_kind_statistics_, 0,
1512 sizeof(code_kind_statistics_[0]) * Code::NUMBER_OF_KINDS);
1515 #ifdef ENABLE_DEBUGGER_SUPPORT
1520 handle_scope_data_.Initialize();
1522 #define ISOLATE_INIT_EXECUTE(type, name, initial_value) \
1523 name##_ = (initial_value);
1525 #undef ISOLATE_INIT_EXECUTE
1527 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \
1528 memset(name##_, 0, sizeof(type) * length);
1530 #undef ISOLATE_INIT_ARRAY_EXECUTE
1533 void Isolate::TearDown() {
1541 Isolate* saved_isolate = UncheckedCurrent();
1542 SetIsolateThreadLocals(
this,
NULL);
1547 thread_data_table_->RemoveAllThreads(
this);
1550 if (!IsDefaultIsolate()) {
1555 SetIsolateThreadLocals(saved_isolate, saved_data);
1559 void Isolate::Deinit() {
1560 if (state_ == INITIALIZED) {
1563 if (FLAG_hydrogen_stats) HStatistics::Instance()->Print();
1566 logger_->EnsureTickerStopped();
1568 delete deoptimizer_data_;
1569 deoptimizer_data_ =
NULL;
1570 if (FLAG_preemption) {
1574 builtins_.TearDown();
1575 bootstrapper_->TearDown();
1578 delete preallocated_message_space_;
1579 preallocated_message_space_ =
NULL;
1580 PreallocatedMemoryThreadStop();
1582 HeapProfiler::TearDown();
1583 CpuProfiler::TearDown();
1584 if (runtime_profiler_ !=
NULL) {
1585 runtime_profiler_->TearDown();
1586 delete runtime_profiler_;
1587 runtime_profiler_ =
NULL;
1590 logger_->TearDown();
1598 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
1599 PerIsolateThreadData* data) {
1600 Thread::SetThreadLocal(isolate_key_, isolate);
1601 Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
1605 Isolate::~Isolate() {
1609 zone_.DeleteKeptSegment();
1611 delete[] assembler_spare_buffer_;
1612 assembler_spare_buffer_ =
NULL;
1614 delete unicode_cache_;
1615 unicode_cache_ =
NULL;
1620 delete regexp_stack_;
1621 regexp_stack_ =
NULL;
1623 delete descriptor_lookup_cache_;
1624 descriptor_lookup_cache_ =
NULL;
1625 delete context_slot_cache_;
1626 context_slot_cache_ =
NULL;
1627 delete keyed_lookup_cache_;
1628 keyed_lookup_cache_ =
NULL;
1630 delete transcendental_cache_;
1631 transcendental_cache_ =
NULL;
1634 delete stats_table_;
1635 stats_table_ =
NULL;
1643 delete handle_scope_implementer_;
1644 handle_scope_implementer_ =
NULL;
1645 delete break_access_;
1646 break_access_ =
NULL;
1647 delete debugger_access_;
1648 debugger_access_ =
NULL;
1650 delete compilation_cache_;
1651 compilation_cache_ =
NULL;
1652 delete bootstrapper_;
1653 bootstrapper_ =
NULL;
1654 delete inner_pointer_to_code_cache_;
1655 inner_pointer_to_code_cache_ =
NULL;
1656 delete write_input_buffer_;
1657 write_input_buffer_ =
NULL;
1659 delete context_switcher_;
1660 context_switcher_ =
NULL;
1661 delete thread_manager_;
1662 thread_manager_ =
NULL;
1664 delete string_tracker_;
1665 string_tracker_ =
NULL;
1667 delete memory_allocator_;
1668 memory_allocator_ =
NULL;
1671 delete global_handles_;
1672 global_handles_ =
NULL;
1674 delete external_reference_table_;
1675 external_reference_table_ =
NULL;
1677 #ifdef ENABLE_DEBUGGER_SUPPORT
1686 void Isolate::InitializeThreadLocal() {
1687 thread_local_top_.isolate_ =
this;
1688 thread_local_top_.Initialize();
1692 void Isolate::PropagatePendingExceptionToExternalTryCatch() {
1693 ASSERT(has_pending_exception());
1695 bool external_caught = IsExternallyCaught();
1696 thread_local_top_.external_caught_exception_ = external_caught;
1698 if (!external_caught)
return;
1700 if (thread_local_top_.pending_exception_ == Failure::OutOfMemoryException()) {
1702 }
else if (thread_local_top_.pending_exception_ ==
1703 heap()->termination_exception()) {
1704 try_catch_handler()->can_continue_ =
false;
1705 try_catch_handler()->exception_ = heap()->null_value();
1709 ASSERT(!pending_exception()->IsFailure());
1710 try_catch_handler()->can_continue_ =
true;
1711 try_catch_handler()->exception_ = pending_exception();
1712 if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
1713 try_catch_handler()->message_ = thread_local_top_.pending_message_obj_;
1719 void Isolate::InitializeLoggingAndCounters() {
1720 if (logger_ ==
NULL) {
1723 if (counters_ ==
NULL) {
1729 void Isolate::InitializeDebugger() {
1730 #ifdef ENABLE_DEBUGGER_SUPPORT
1733 InitializeLoggingAndCounters();
1734 debug_ =
new Debug(
this);
1735 debugger_ =
new Debugger(
this);
1742 ASSERT(state_ != INITIALIZED);
1743 ASSERT(Isolate::Current() ==
this);
1748 DisallowAllocationFailure disallow_allocation_failure;
1751 InitializeLoggingAndCounters();
1753 InitializeDebugger();
1760 heap_.SetStackLimits();
1762 #define ASSIGN_ELEMENT(CamelName, hacker_name) \
1763 isolate_addresses_[Isolate::k##CamelName##Address] = \
1764 reinterpret_cast<Address>(hacker_name##_address());
1769 string_tracker_->isolate_ =
this;
1781 stub_cache_ =
new StubCache(
this, zone());
1783 regexp_stack_->isolate_ =
this;
1789 CpuProfiler::SetUp();
1790 HeapProfiler::SetUp();
1793 #if defined(USE_SIMULATOR)
1794 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS)
1795 Simulator::Initialize(
this);
1803 ExecutionAccess lock(
this);
1804 stack_guard_.InitThread(lock);
1808 const bool create_heap_objects = (des ==
NULL);
1809 ASSERT(!heap_.HasBeenSetUp());
1810 if (!heap_.SetUp(create_heap_objects)) {
1811 V8::SetFatalError();
1815 InitializeThreadLocal();
1817 bootstrapper_->Initialize(create_heap_objects);
1818 builtins_.SetUp(create_heap_objects);
1821 if (FLAG_preallocate_message_memory && preallocated_message_space_ ==
NULL) {
1823 PreallocatedMemoryThreadStart();
1824 preallocated_message_space_ =
1826 preallocated_memory_thread_->data(),
1827 preallocated_memory_thread_->length());
1828 PreallocatedStorageInit(preallocated_memory_thread_->length() / 4);
1831 if (FLAG_preemption) {
1836 #ifdef ENABLE_DEBUGGER_SUPPORT
1837 debug_->SetUp(create_heap_objects);
1844 stub_cache_->Initialize();
1847 clear_pending_exception();
1848 clear_pending_message();
1849 clear_scheduled_exception();
1853 heap_.SetStackLimits();
1856 if (des !=
NULL) Assembler::QuietNaN(heap_.nan_value());
1860 runtime_profiler_->SetUp();
1864 if (des !=
NULL && (FLAG_log_code || FLAG_ll_prof)) {
1866 LOG(
this, LogCodeObjects());
1867 LOG(
this, LogCompiledFunctions());
1871 Internals::kIsolateStateOffset);
1873 Internals::kIsolateEmbedderDataOffset);
1875 Internals::kIsolateRootsOffset);
1877 state_ = INITIALIZED;
1878 time_millis_at_init_ = OS::TimeCurrentMillis();
1886 if (stats_table_ ==
NULL) {
1889 return stats_table_;
1893 void Isolate::Enter() {
1895 PerIsolateThreadData* current_data = CurrentPerIsolateThreadData();
1896 if (current_data !=
NULL) {
1897 current_isolate = current_data->isolate_;
1899 if (current_isolate ==
this) {
1900 ASSERT(Current() ==
this);
1902 ASSERT(entry_stack_->previous_thread_data ==
NULL ||
1903 entry_stack_->previous_thread_data->thread_id().Equals(
1904 ThreadId::Current()));
1906 entry_stack_->entry_count++;
1917 if (current_isolate ==
NULL) {
1918 current_isolate = Isolate::UncheckedCurrent();
1921 PerIsolateThreadData* data = FindOrAllocatePerThreadDataForThisThread();
1923 ASSERT(data->isolate_ ==
this);
1925 EntryStackItem* item =
new EntryStackItem(current_data,
1928 entry_stack_ = item;
1930 SetIsolateThreadLocals(
this, data);
1933 set_thread_id(data->thread_id());
1937 void Isolate::Exit() {
1939 ASSERT(entry_stack_->previous_thread_data ==
NULL ||
1940 entry_stack_->previous_thread_data->thread_id().Equals(
1941 ThreadId::Current()));
1943 if (--entry_stack_->entry_count > 0)
return;
1945 ASSERT(CurrentPerIsolateThreadData() !=
NULL);
1946 ASSERT(CurrentPerIsolateThreadData()->isolate_ ==
this);
1949 EntryStackItem* item = entry_stack_;
1950 entry_stack_ = item->previous_item;
1952 PerIsolateThreadData* previous_thread_data = item->previous_thread_data;
1953 Isolate* previous_isolate = item->previous_isolate;
1958 SetIsolateThreadLocals(previous_isolate, previous_thread_data);
1963 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
1964 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
1967 #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)
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()
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)
Context * global_context()
#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()
static Failure * cast(MaybeObject *object)
void ComputeLocation(MessageLocation *target)
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 trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt 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 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
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)
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
#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,...)
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kThisPropertyAssignmentsOffset flag
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
#define TRACE_ISOLATE(tag)
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 trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt 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 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
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 true
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)
Handle< Context > GetCallingGlobalContext()
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()
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)
Handle< GlobalObject > global()
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)
#define ASSIGN_ELEMENT(CamelName, hacker_name)
static JSFunction * cast(Object *obj)