OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 StringStream* accumulator, | 577 StringStream* accumulator, |
578 StackFrame::PrintMode mode) { | 578 StackFrame::PrintMode mode) { |
579 StackFrameIterator it(isolate); | 579 StackFrameIterator it(isolate); |
580 for (int i = 0; !it.done(); it.Advance()) { | 580 for (int i = 0; !it.done(); it.Advance()) { |
581 it.frame()->Print(accumulator, mode, i++); | 581 it.frame()->Print(accumulator, mode, i++); |
582 } | 582 } |
583 } | 583 } |
584 | 584 |
585 | 585 |
586 void Isolate::PrintStack(StringStream* accumulator) { | 586 void Isolate::PrintStack(StringStream* accumulator) { |
587 if (!IsInitialized()) { | |
588 accumulator->Add( | |
589 "\n==== JS stack trace is not available =======================\n\n"); | |
590 accumulator->Add( | |
591 "\n==== Isolate for the thread is not initialized =============\n\n"); | |
592 return; | |
593 } | |
594 // The MentionedObjectCache is not GC-proof at the moment. | 587 // The MentionedObjectCache is not GC-proof at the moment. |
595 DisallowHeapAllocation no_gc; | 588 DisallowHeapAllocation no_gc; |
596 DCHECK(StringStream::IsMentionedObjectCacheClear(this)); | 589 DCHECK(StringStream::IsMentionedObjectCacheClear(this)); |
597 | 590 |
598 // Avoid printing anything if there are no frames. | 591 // Avoid printing anything if there are no frames. |
599 if (c_entry_fp(thread_local_top()) == 0) return; | 592 if (c_entry_fp(thread_local_top()) == 0) return; |
600 | 593 |
601 accumulator->Add( | 594 accumulator->Add( |
602 "\n==== JS stack trace =========================================\n\n"); | 595 "\n==== JS stack trace =========================================\n\n"); |
603 PrintFrames(this, accumulator, StackFrame::OVERVIEW); | 596 PrintFrames(this, accumulator, StackFrame::OVERVIEW); |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 if (FLAG_trace_isolates) { \ | 1453 if (FLAG_trace_isolates) { \ |
1461 PrintF("Isolate %p (id %d)" #tag "\n", \ | 1454 PrintF("Isolate %p (id %d)" #tag "\n", \ |
1462 reinterpret_cast<void*>(this), id()); \ | 1455 reinterpret_cast<void*>(this), id()); \ |
1463 } \ | 1456 } \ |
1464 } while (false) | 1457 } while (false) |
1465 #else | 1458 #else |
1466 #define TRACE_ISOLATE(tag) | 1459 #define TRACE_ISOLATE(tag) |
1467 #endif | 1460 #endif |
1468 | 1461 |
1469 | 1462 |
1470 Isolate::Isolate() | 1463 Isolate::Isolate(bool enable_serializer) |
1471 : embedder_data_(), | 1464 : embedder_data_(), |
1472 state_(UNINITIALIZED), | |
1473 entry_stack_(NULL), | 1465 entry_stack_(NULL), |
1474 stack_trace_nesting_level_(0), | 1466 stack_trace_nesting_level_(0), |
1475 incomplete_message_(NULL), | 1467 incomplete_message_(NULL), |
1476 bootstrapper_(NULL), | 1468 bootstrapper_(NULL), |
1477 runtime_profiler_(NULL), | 1469 runtime_profiler_(NULL), |
1478 compilation_cache_(NULL), | 1470 compilation_cache_(NULL), |
1479 counters_(NULL), | 1471 counters_(NULL), |
1480 code_range_(NULL), | 1472 code_range_(NULL), |
1481 logger_(NULL), | 1473 logger_(NULL), |
1482 stats_table_(NULL), | 1474 stats_table_(NULL), |
(...skipping 17 matching lines...) Expand all Loading... |
1500 eternal_handles_(NULL), | 1492 eternal_handles_(NULL), |
1501 thread_manager_(NULL), | 1493 thread_manager_(NULL), |
1502 has_installed_extensions_(false), | 1494 has_installed_extensions_(false), |
1503 string_tracker_(NULL), | 1495 string_tracker_(NULL), |
1504 regexp_stack_(NULL), | 1496 regexp_stack_(NULL), |
1505 date_cache_(NULL), | 1497 date_cache_(NULL), |
1506 call_descriptor_data_(NULL), | 1498 call_descriptor_data_(NULL), |
1507 // TODO(bmeurer) Initialized lazily because it depends on flags; can | 1499 // TODO(bmeurer) Initialized lazily because it depends on flags; can |
1508 // be fixed once the default isolate cleanup is done. | 1500 // be fixed once the default isolate cleanup is done. |
1509 random_number_generator_(NULL), | 1501 random_number_generator_(NULL), |
1510 serializer_enabled_(false), | 1502 serializer_enabled_(enable_serializer), |
1511 has_fatal_error_(false), | 1503 has_fatal_error_(false), |
1512 initialized_from_snapshot_(false), | 1504 initialized_from_snapshot_(false), |
1513 cpu_profiler_(NULL), | 1505 cpu_profiler_(NULL), |
1514 heap_profiler_(NULL), | 1506 heap_profiler_(NULL), |
1515 function_entry_hook_(NULL), | 1507 function_entry_hook_(NULL), |
1516 deferred_handles_head_(NULL), | 1508 deferred_handles_head_(NULL), |
1517 optimizing_compiler_thread_(NULL), | 1509 optimizing_compiler_thread_(NULL), |
1518 stress_deopt_count_(0), | 1510 stress_deopt_count_(0), |
1519 next_optimization_id_(0), | 1511 next_optimization_id_(0), |
1520 use_counter_callback_(NULL), | 1512 use_counter_callback_(NULL), |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 } | 1581 } |
1590 | 1582 |
1591 | 1583 |
1592 void Isolate::GlobalTearDown() { | 1584 void Isolate::GlobalTearDown() { |
1593 delete thread_data_table_; | 1585 delete thread_data_table_; |
1594 thread_data_table_ = NULL; | 1586 thread_data_table_ = NULL; |
1595 } | 1587 } |
1596 | 1588 |
1597 | 1589 |
1598 void Isolate::Deinit() { | 1590 void Isolate::Deinit() { |
1599 if (state_ == INITIALIZED) { | 1591 TRACE_ISOLATE(deinit); |
1600 TRACE_ISOLATE(deinit); | |
1601 | 1592 |
1602 debug()->Unload(); | 1593 debug()->Unload(); |
1603 | 1594 |
1604 FreeThreadResources(); | 1595 FreeThreadResources(); |
1605 | 1596 |
1606 if (concurrent_recompilation_enabled()) { | 1597 if (concurrent_recompilation_enabled()) { |
1607 optimizing_compiler_thread_->Stop(); | 1598 optimizing_compiler_thread_->Stop(); |
1608 delete optimizing_compiler_thread_; | 1599 delete optimizing_compiler_thread_; |
1609 optimizing_compiler_thread_ = NULL; | 1600 optimizing_compiler_thread_ = NULL; |
1610 } | 1601 } |
1611 | 1602 |
1612 if (heap_.mark_compact_collector()->sweeping_in_progress()) { | 1603 if (heap_.mark_compact_collector()->sweeping_in_progress()) { |
1613 heap_.mark_compact_collector()->EnsureSweepingCompleted(); | 1604 heap_.mark_compact_collector()->EnsureSweepingCompleted(); |
1614 } | 1605 } |
1615 | 1606 |
1616 if (FLAG_turbo_stats) GetTStatistics()->Print("TurboFan"); | 1607 if (FLAG_turbo_stats) GetTStatistics()->Print("TurboFan"); |
1617 if (FLAG_hydrogen_stats) GetHStatistics()->Print("Hydrogen"); | 1608 if (FLAG_hydrogen_stats) GetHStatistics()->Print("Hydrogen"); |
1618 | 1609 |
1619 if (FLAG_print_deopt_stress) { | 1610 if (FLAG_print_deopt_stress) { |
1620 PrintF(stdout, "=== Stress deopt counter: %u\n", stress_deopt_count_); | 1611 PrintF(stdout, "=== Stress deopt counter: %u\n", stress_deopt_count_); |
1621 } | 1612 } |
1622 | 1613 |
1623 // We must stop the logger before we tear down other components. | 1614 // We must stop the logger before we tear down other components. |
1624 Sampler* sampler = logger_->sampler(); | 1615 Sampler* sampler = logger_->sampler(); |
1625 if (sampler && sampler->IsActive()) sampler->Stop(); | 1616 if (sampler && sampler->IsActive()) sampler->Stop(); |
1626 | 1617 |
1627 delete deoptimizer_data_; | 1618 delete deoptimizer_data_; |
1628 deoptimizer_data_ = NULL; | 1619 deoptimizer_data_ = NULL; |
1629 builtins_.TearDown(); | 1620 builtins_.TearDown(); |
1630 bootstrapper_->TearDown(); | 1621 bootstrapper_->TearDown(); |
1631 | 1622 |
1632 if (runtime_profiler_ != NULL) { | 1623 if (runtime_profiler_ != NULL) { |
1633 delete runtime_profiler_; | 1624 delete runtime_profiler_; |
1634 runtime_profiler_ = NULL; | 1625 runtime_profiler_ = NULL; |
1635 } | 1626 } |
1636 | 1627 |
1637 delete basic_block_profiler_; | 1628 delete basic_block_profiler_; |
1638 basic_block_profiler_ = NULL; | 1629 basic_block_profiler_ = NULL; |
1639 | 1630 |
1640 heap_.TearDown(); | 1631 heap_.TearDown(); |
1641 logger_->TearDown(); | 1632 logger_->TearDown(); |
1642 | 1633 |
1643 delete heap_profiler_; | 1634 delete heap_profiler_; |
1644 heap_profiler_ = NULL; | 1635 heap_profiler_ = NULL; |
1645 delete cpu_profiler_; | 1636 delete cpu_profiler_; |
1646 cpu_profiler_ = NULL; | 1637 cpu_profiler_ = NULL; |
1647 | |
1648 // The default isolate is re-initializable due to legacy API. | |
1649 state_ = UNINITIALIZED; | |
1650 } | |
1651 } | 1638 } |
1652 | 1639 |
1653 | 1640 |
1654 void Isolate::PushToPartialSnapshotCache(Object* obj) { | 1641 void Isolate::PushToPartialSnapshotCache(Object* obj) { |
1655 int length = serialize_partial_snapshot_cache_length(); | 1642 int length = serialize_partial_snapshot_cache_length(); |
1656 int capacity = serialize_partial_snapshot_cache_capacity(); | 1643 int capacity = serialize_partial_snapshot_cache_capacity(); |
1657 | 1644 |
1658 if (length >= capacity) { | 1645 if (length >= capacity) { |
1659 int new_capacity = static_cast<int>((capacity + 10) * 1.2); | 1646 int new_capacity = static_cast<int>((capacity + 10) * 1.2); |
1660 Object** new_array = new Object*[new_capacity]; | 1647 Object** new_array = new Object*[new_capacity]; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 if (logger_ == NULL) { | 1804 if (logger_ == NULL) { |
1818 logger_ = new Logger(this); | 1805 logger_ = new Logger(this); |
1819 } | 1806 } |
1820 if (counters_ == NULL) { | 1807 if (counters_ == NULL) { |
1821 counters_ = new Counters(this); | 1808 counters_ = new Counters(this); |
1822 } | 1809 } |
1823 } | 1810 } |
1824 | 1811 |
1825 | 1812 |
1826 bool Isolate::Init(Deserializer* des) { | 1813 bool Isolate::Init(Deserializer* des) { |
1827 DCHECK(state_ != INITIALIZED); | |
1828 TRACE_ISOLATE(init); | 1814 TRACE_ISOLATE(init); |
1829 | 1815 |
1830 stress_deopt_count_ = FLAG_deopt_every_n_times; | 1816 stress_deopt_count_ = FLAG_deopt_every_n_times; |
1831 | 1817 |
1832 has_fatal_error_ = false; | 1818 has_fatal_error_ = false; |
1833 | 1819 |
1834 if (function_entry_hook() != NULL) { | 1820 if (function_entry_hook() != NULL) { |
1835 // When function entry hooking is in effect, we have to create the code | 1821 // When function entry hooking is in effect, we have to create the code |
1836 // stubs from scratch to get entry hooks, rather than loading the previously | 1822 // stubs from scratch to get entry hooks, rather than loading the previously |
1837 // generated stubs from disk. | 1823 // generated stubs from disk. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1983 CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.roots_)), | 1969 CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.roots_)), |
1984 Internals::kIsolateRootsOffset); | 1970 Internals::kIsolateRootsOffset); |
1985 CHECK_EQ(static_cast<int>( | 1971 CHECK_EQ(static_cast<int>( |
1986 OFFSET_OF(Isolate, heap_.amount_of_external_allocated_memory_)), | 1972 OFFSET_OF(Isolate, heap_.amount_of_external_allocated_memory_)), |
1987 Internals::kAmountOfExternalAllocatedMemoryOffset); | 1973 Internals::kAmountOfExternalAllocatedMemoryOffset); |
1988 CHECK_EQ(static_cast<int>(OFFSET_OF( | 1974 CHECK_EQ(static_cast<int>(OFFSET_OF( |
1989 Isolate, | 1975 Isolate, |
1990 heap_.amount_of_external_allocated_memory_at_last_global_gc_)), | 1976 heap_.amount_of_external_allocated_memory_at_last_global_gc_)), |
1991 Internals::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset); | 1977 Internals::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset); |
1992 | 1978 |
1993 state_ = INITIALIZED; | |
1994 time_millis_at_init_ = base::OS::TimeCurrentMillis(); | 1979 time_millis_at_init_ = base::OS::TimeCurrentMillis(); |
1995 | 1980 |
| 1981 heap_.NotifyDeserializationComplete(); |
| 1982 |
1996 if (!create_heap_objects) { | 1983 if (!create_heap_objects) { |
1997 // Now that the heap is consistent, it's OK to generate the code for the | 1984 // Now that the heap is consistent, it's OK to generate the code for the |
1998 // deopt entry table that might have been referred to by optimized code in | 1985 // deopt entry table that might have been referred to by optimized code in |
1999 // the snapshot. | 1986 // the snapshot. |
2000 HandleScope scope(this); | 1987 HandleScope scope(this); |
2001 Deoptimizer::EnsureCodeForDeoptimizationEntry( | 1988 Deoptimizer::EnsureCodeForDeoptimizationEntry( |
2002 this, | 1989 this, |
2003 Deoptimizer::LAZY, | 1990 Deoptimizer::LAZY, |
2004 kDeoptTableSerializeEntryCount - 1); | 1991 kDeoptTableSerializeEntryCount - 1); |
2005 } | 1992 } |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 if (prev_ && prev_->Intercept(flag)) return true; | 2381 if (prev_ && prev_->Intercept(flag)) return true; |
2395 // Then check whether this scope intercepts. | 2382 // Then check whether this scope intercepts. |
2396 if ((flag & intercept_mask_)) { | 2383 if ((flag & intercept_mask_)) { |
2397 intercepted_flags_ |= flag; | 2384 intercepted_flags_ |= flag; |
2398 return true; | 2385 return true; |
2399 } | 2386 } |
2400 return false; | 2387 return false; |
2401 } | 2388 } |
2402 | 2389 |
2403 } } // namespace v8::internal | 2390 } } // namespace v8::internal |
OLD | NEW |