Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/isolate.cc

Issue 7572018: Minimize malloc heap allocation on process startup. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.h ('k') | src/spaces.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 if (thread_id == 0) { 69 if (thread_id == 0) {
70 thread_id = AllocateThreadId(); 70 thread_id = AllocateThreadId();
71 Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); 71 Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id);
72 } 72 }
73 return thread_id; 73 return thread_id;
74 } 74 }
75 75
76 76
77 ThreadLocalTop::ThreadLocalTop() { 77 ThreadLocalTop::ThreadLocalTop() {
78 InitializeInternal(); 78 InitializeInternal();
79 // This flag may be set using v8::V8::IgnoreOutOfMemoryException()
80 // before an isolate is initialized. The initialize methods below do
81 // not touch it to preserve its value.
82 ignore_out_of_memory_ = false;
79 } 83 }
80 84
81 85
82 void ThreadLocalTop::InitializeInternal() { 86 void ThreadLocalTop::InitializeInternal() {
83 c_entry_fp_ = 0; 87 c_entry_fp_ = 0;
84 handler_ = 0; 88 handler_ = 0;
85 #ifdef USE_SIMULATOR 89 #ifdef USE_SIMULATOR
86 simulator_ = NULL; 90 simulator_ = NULL;
87 #endif 91 #endif
88 js_entry_sp_ = NULL; 92 js_entry_sp_ = NULL;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 thread_id_key_ = Thread::CreateThreadLocalKey(); 379 thread_id_key_ = Thread::CreateThreadLocalKey();
376 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); 380 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey();
377 thread_data_table_ = new Isolate::ThreadDataTable(); 381 thread_data_table_ = new Isolate::ThreadDataTable();
378 default_isolate_ = new Isolate(); 382 default_isolate_ = new Isolate();
379 } 383 }
380 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here 384 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here
381 // becase a non-null thread data may be already set. 385 // becase a non-null thread data may be already set.
382 if (Thread::GetThreadLocal(isolate_key_) == NULL) { 386 if (Thread::GetThreadLocal(isolate_key_) == NULL) {
383 Thread::SetThreadLocal(isolate_key_, default_isolate_); 387 Thread::SetThreadLocal(isolate_key_, default_isolate_);
384 } 388 }
385 CHECK(default_isolate_->PreInit());
386 } 389 }
387 390
388 391
389 #ifdef ENABLE_DEBUGGER_SUPPORT 392 #ifdef ENABLE_DEBUGGER_SUPPORT
390 Debugger* Isolate::GetDefaultIsolateDebugger() { 393 Debugger* Isolate::GetDefaultIsolateDebugger() {
391 EnsureDefaultIsolate(); 394 EnsureDefaultIsolate();
392 return default_isolate_->debugger(); 395 return default_isolate_->debugger();
393 } 396 }
394 #endif 397 #endif
395 398
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 Isolate::Isolate() 1371 Isolate::Isolate()
1369 : state_(UNINITIALIZED), 1372 : state_(UNINITIALIZED),
1370 entry_stack_(NULL), 1373 entry_stack_(NULL),
1371 stack_trace_nesting_level_(0), 1374 stack_trace_nesting_level_(0),
1372 incomplete_message_(NULL), 1375 incomplete_message_(NULL),
1373 preallocated_memory_thread_(NULL), 1376 preallocated_memory_thread_(NULL),
1374 preallocated_message_space_(NULL), 1377 preallocated_message_space_(NULL),
1375 bootstrapper_(NULL), 1378 bootstrapper_(NULL),
1376 runtime_profiler_(NULL), 1379 runtime_profiler_(NULL),
1377 compilation_cache_(NULL), 1380 compilation_cache_(NULL),
1378 counters_(new Counters()), 1381 counters_(NULL),
1379 code_range_(NULL), 1382 code_range_(NULL),
1383 // Must be initialized early to allow v8::SetResourceConstraints calls.
1380 break_access_(OS::CreateMutex()), 1384 break_access_(OS::CreateMutex()),
1381 logger_(new Logger()), 1385 debugger_initialized_(false),
1382 stats_table_(new StatsTable()), 1386 // Must be initialized early to allow v8::Debug calls.
1387 debugger_access_(OS::CreateMutex()),
1388 logger_(NULL),
1389 stats_table_(NULL),
1383 stub_cache_(NULL), 1390 stub_cache_(NULL),
1384 deoptimizer_data_(NULL), 1391 deoptimizer_data_(NULL),
1385 capture_stack_trace_for_uncaught_exceptions_(false), 1392 capture_stack_trace_for_uncaught_exceptions_(false),
1386 stack_trace_for_uncaught_exceptions_frame_limit_(0), 1393 stack_trace_for_uncaught_exceptions_frame_limit_(0),
1387 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), 1394 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview),
1388 transcendental_cache_(NULL), 1395 transcendental_cache_(NULL),
1389 memory_allocator_(NULL), 1396 memory_allocator_(NULL),
1390 keyed_lookup_cache_(NULL), 1397 keyed_lookup_cache_(NULL),
1391 context_slot_cache_(NULL), 1398 context_slot_cache_(NULL),
1392 descriptor_lookup_cache_(NULL), 1399 descriptor_lookup_cache_(NULL),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 CpuProfiler::TearDown(); 1510 CpuProfiler::TearDown();
1504 if (runtime_profiler_ != NULL) { 1511 if (runtime_profiler_ != NULL) {
1505 runtime_profiler_->TearDown(); 1512 runtime_profiler_->TearDown();
1506 delete runtime_profiler_; 1513 delete runtime_profiler_;
1507 runtime_profiler_ = NULL; 1514 runtime_profiler_ = NULL;
1508 } 1515 }
1509 heap_.TearDown(); 1516 heap_.TearDown();
1510 logger_->TearDown(); 1517 logger_->TearDown();
1511 1518
1512 // The default isolate is re-initializable due to legacy API. 1519 // The default isolate is re-initializable due to legacy API.
1513 state_ = PREINITIALIZED; 1520 state_ = UNINITIALIZED;
1514 } 1521 }
1515 } 1522 }
1516 1523
1517 1524
1518 void Isolate::SetIsolateThreadLocals(Isolate* isolate, 1525 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
1519 PerIsolateThreadData* data) { 1526 PerIsolateThreadData* data) {
1520 Thread::SetThreadLocal(isolate_key_, isolate); 1527 Thread::SetThreadLocal(isolate_key_, isolate);
1521 Thread::SetThreadLocal(per_isolate_thread_data_key_, data); 1528 Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
1522 } 1529 }
1523 1530
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 1592
1586 #ifdef ENABLE_DEBUGGER_SUPPORT 1593 #ifdef ENABLE_DEBUGGER_SUPPORT
1587 delete debugger_; 1594 delete debugger_;
1588 debugger_ = NULL; 1595 debugger_ = NULL;
1589 delete debug_; 1596 delete debug_;
1590 debug_ = NULL; 1597 debug_ = NULL;
1591 #endif 1598 #endif
1592 } 1599 }
1593 1600
1594 1601
1595 bool Isolate::PreInit() {
1596 if (state_ != UNINITIALIZED) return true;
1597
1598 TRACE_ISOLATE(preinit);
1599
1600 ASSERT(Isolate::Current() == this);
1601 #ifdef ENABLE_DEBUGGER_SUPPORT
1602 debug_ = new Debug(this);
1603 debugger_ = new Debugger(this);
1604 #endif
1605
1606 memory_allocator_ = new MemoryAllocator();
1607 memory_allocator_->isolate_ = this;
1608 code_range_ = new CodeRange();
1609 code_range_->isolate_ = this;
1610
1611 // Safe after setting Heap::isolate_, initializing StackGuard and
1612 // ensuring that Isolate::Current() == this.
1613 heap_.SetStackLimits();
1614
1615 #ifdef DEBUG
1616 DisallowAllocationFailure disallow_allocation_failure;
1617 #endif
1618
1619 #define C(name) isolate_addresses_[Isolate::k_##name] = \
1620 reinterpret_cast<Address>(name());
1621 ISOLATE_ADDRESS_LIST(C)
1622 #undef C
1623
1624 string_tracker_ = new StringTracker();
1625 string_tracker_->isolate_ = this;
1626 compilation_cache_ = new CompilationCache(this);
1627 transcendental_cache_ = new TranscendentalCache();
1628 keyed_lookup_cache_ = new KeyedLookupCache();
1629 context_slot_cache_ = new ContextSlotCache();
1630 descriptor_lookup_cache_ = new DescriptorLookupCache();
1631 unicode_cache_ = new UnicodeCache();
1632 pc_to_code_cache_ = new PcToCodeCache(this);
1633 write_input_buffer_ = new StringInputBuffer();
1634 global_handles_ = new GlobalHandles(this);
1635 bootstrapper_ = new Bootstrapper();
1636 handle_scope_implementer_ = new HandleScopeImplementer(this);
1637 stub_cache_ = new StubCache(this);
1638 ast_sentinels_ = new AstSentinels();
1639 regexp_stack_ = new RegExpStack();
1640 regexp_stack_->isolate_ = this;
1641
1642 state_ = PREINITIALIZED;
1643 return true;
1644 }
1645
1646
1647 void Isolate::InitializeThreadLocal() { 1602 void Isolate::InitializeThreadLocal() {
1648 thread_local_top_.isolate_ = this; 1603 thread_local_top_.isolate_ = this;
1649 thread_local_top_.Initialize(); 1604 thread_local_top_.Initialize();
1650 clear_pending_exception(); 1605 clear_pending_exception();
1651 clear_pending_message(); 1606 clear_pending_message();
1652 clear_scheduled_exception(); 1607 clear_scheduled_exception();
1653 } 1608 }
1654 1609
1655 1610
1656 void Isolate::PropagatePendingExceptionToExternalTryCatch() { 1611 void Isolate::PropagatePendingExceptionToExternalTryCatch() {
(...skipping 16 matching lines...) Expand all
1673 ASSERT(!pending_exception()->IsFailure()); 1628 ASSERT(!pending_exception()->IsFailure());
1674 try_catch_handler()->can_continue_ = true; 1629 try_catch_handler()->can_continue_ = true;
1675 try_catch_handler()->exception_ = pending_exception(); 1630 try_catch_handler()->exception_ = pending_exception();
1676 if (!thread_local_top_.pending_message_obj_->IsTheHole()) { 1631 if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
1677 try_catch_handler()->message_ = thread_local_top_.pending_message_obj_; 1632 try_catch_handler()->message_ = thread_local_top_.pending_message_obj_;
1678 } 1633 }
1679 } 1634 }
1680 } 1635 }
1681 1636
1682 1637
1638 void Isolate::InitializeLoggingAndCounters() {
1639 if (logger_ == NULL) {
1640 logger_ = new Logger;
1641 }
1642 if (counters_ == NULL) {
1643 counters_ = new Counters;
1644 }
1645 }
1646
1647
1648 void Isolate::InitializeDebugger() {
1649 #ifdef ENABLE_DEBUGGER_SUPPORT
1650 ScopedLock lock(debugger_access_);
1651 if (NoBarrier_Load(&debugger_initialized_)) return;
1652 InitializeLoggingAndCounters();
1653 debug_ = new Debug(this);
1654 debugger_ = new Debugger(this);
1655 Release_Store(&debugger_initialized_, true);
1656 #endif
1657 }
1658
1659
1683 bool Isolate::Init(Deserializer* des) { 1660 bool Isolate::Init(Deserializer* des) {
1684 ASSERT(state_ != INITIALIZED); 1661 ASSERT(state_ != INITIALIZED);
1685 1662 ASSERT(Isolate::Current() == this);
1686 TRACE_ISOLATE(init); 1663 TRACE_ISOLATE(init);
1687 1664
1688 bool create_heap_objects = des == NULL;
1689
1690 #ifdef DEBUG 1665 #ifdef DEBUG
1691 // The initialization process does not handle memory exhaustion. 1666 // The initialization process does not handle memory exhaustion.
1692 DisallowAllocationFailure disallow_allocation_failure; 1667 DisallowAllocationFailure disallow_allocation_failure;
1693 #endif 1668 #endif
1694 1669
1695 if (state_ == UNINITIALIZED && !PreInit()) return false; 1670 InitializeLoggingAndCounters();
1671
1672 InitializeDebugger();
1673
1674 memory_allocator_ = new MemoryAllocator(this);
1675 code_range_ = new CodeRange(this);
1676
1677 // Safe after setting Heap::isolate_, initializing StackGuard and
1678 // ensuring that Isolate::Current() == this.
1679 heap_.SetStackLimits();
1680
1681 #define C(name) isolate_addresses_[Isolate::k_##name] = \
1682 reinterpret_cast<Address>(name());
1683 ISOLATE_ADDRESS_LIST(C)
1684 #undef C
1685
1686 string_tracker_ = new StringTracker();
1687 string_tracker_->isolate_ = this;
1688 compilation_cache_ = new CompilationCache(this);
1689 transcendental_cache_ = new TranscendentalCache();
1690 keyed_lookup_cache_ = new KeyedLookupCache();
1691 context_slot_cache_ = new ContextSlotCache();
1692 descriptor_lookup_cache_ = new DescriptorLookupCache();
1693 unicode_cache_ = new UnicodeCache();
1694 pc_to_code_cache_ = new PcToCodeCache(this);
1695 write_input_buffer_ = new StringInputBuffer();
1696 global_handles_ = new GlobalHandles(this);
1697 bootstrapper_ = new Bootstrapper();
1698 handle_scope_implementer_ = new HandleScopeImplementer(this);
1699 stub_cache_ = new StubCache(this);
1700 ast_sentinels_ = new AstSentinels();
1701 regexp_stack_ = new RegExpStack();
1702 regexp_stack_->isolate_ = this;
1696 1703
1697 // Enable logging before setting up the heap 1704 // Enable logging before setting up the heap
1698 logger_->Setup(); 1705 logger_->Setup();
1699 1706
1700 CpuProfiler::Setup(); 1707 CpuProfiler::Setup();
1701 HeapProfiler::Setup(); 1708 HeapProfiler::Setup();
1702 1709
1703 // Initialize other runtime facilities 1710 // Initialize other runtime facilities
1704 #if defined(USE_SIMULATOR) 1711 #if defined(USE_SIMULATOR)
1705 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) 1712 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS)
1706 Simulator::Initialize(this); 1713 Simulator::Initialize(this);
1707 #endif 1714 #endif
1708 #endif 1715 #endif
1709 1716
1710 { // NOLINT 1717 { // NOLINT
1711 // Ensure that the thread has a valid stack guard. The v8::Locker object 1718 // Ensure that the thread has a valid stack guard. The v8::Locker object
1712 // will ensure this too, but we don't have to use lockers if we are only 1719 // will ensure this too, but we don't have to use lockers if we are only
1713 // using one thread. 1720 // using one thread.
1714 ExecutionAccess lock(this); 1721 ExecutionAccess lock(this);
1715 stack_guard_.InitThread(lock); 1722 stack_guard_.InitThread(lock);
1716 } 1723 }
1717 1724
1718 // Setup the object heap 1725 // Setup the object heap.
1726 const bool create_heap_objects = (des == NULL);
1719 ASSERT(!heap_.HasBeenSetup()); 1727 ASSERT(!heap_.HasBeenSetup());
1720 if (!heap_.Setup(create_heap_objects)) { 1728 if (!heap_.Setup(create_heap_objects)) {
1721 V8::SetFatalError(); 1729 V8::SetFatalError();
1722 return false; 1730 return false;
1723 } 1731 }
1724 1732
1725 InitializeThreadLocal(); 1733 InitializeThreadLocal();
1726 1734
1727 bootstrapper_->Initialize(create_heap_objects); 1735 bootstrapper_->Initialize(create_heap_objects);
1728 builtins_.Setup(create_heap_objects); 1736 builtins_.Setup(create_heap_objects);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 HandleScope scope; 1776 HandleScope scope;
1769 LOG(this, LogCodeObjects()); 1777 LOG(this, LogCodeObjects());
1770 LOG(this, LogCompiledFunctions()); 1778 LOG(this, LogCompiledFunctions());
1771 } 1779 }
1772 1780
1773 state_ = INITIALIZED; 1781 state_ = INITIALIZED;
1774 return true; 1782 return true;
1775 } 1783 }
1776 1784
1777 1785
1786 // Initialized lazily to allow early
1787 // v8::V8::SetAddHistogramSampleFunction calls.
1788 StatsTable* Isolate::stats_table() {
1789 if (stats_table_ == NULL) {
1790 stats_table_ = new StatsTable;
1791 }
1792 return stats_table_;
1793 }
1794
1795
1778 void Isolate::Enter() { 1796 void Isolate::Enter() {
1779 Isolate* current_isolate = NULL; 1797 Isolate* current_isolate = NULL;
1780 PerIsolateThreadData* current_data = CurrentPerIsolateThreadData(); 1798 PerIsolateThreadData* current_data = CurrentPerIsolateThreadData();
1781 if (current_data != NULL) { 1799 if (current_data != NULL) {
1782 current_isolate = current_data->isolate_; 1800 current_isolate = current_data->isolate_;
1783 ASSERT(current_isolate != NULL); 1801 ASSERT(current_isolate != NULL);
1784 if (current_isolate == this) { 1802 if (current_isolate == this) {
1785 ASSERT(Current() == this); 1803 ASSERT(Current() == this);
1786 ASSERT(entry_stack_ != NULL); 1804 ASSERT(entry_stack_ != NULL);
1787 ASSERT(entry_stack_->previous_thread_data == NULL || 1805 ASSERT(entry_stack_->previous_thread_data == NULL ||
(...skipping 19 matching lines...) Expand all
1807 ASSERT(data != NULL); 1825 ASSERT(data != NULL);
1808 ASSERT(data->isolate_ == this); 1826 ASSERT(data->isolate_ == this);
1809 1827
1810 EntryStackItem* item = new EntryStackItem(current_data, 1828 EntryStackItem* item = new EntryStackItem(current_data,
1811 current_isolate, 1829 current_isolate,
1812 entry_stack_); 1830 entry_stack_);
1813 entry_stack_ = item; 1831 entry_stack_ = item;
1814 1832
1815 SetIsolateThreadLocals(this, data); 1833 SetIsolateThreadLocals(this, data);
1816 1834
1817 CHECK(PreInit());
1818
1819 // In case it's the first time some thread enters the isolate. 1835 // In case it's the first time some thread enters the isolate.
1820 set_thread_id(data->thread_id()); 1836 set_thread_id(data->thread_id());
1821 } 1837 }
1822 1838
1823 1839
1824 void Isolate::Exit() { 1840 void Isolate::Exit() {
1825 ASSERT(entry_stack_ != NULL); 1841 ASSERT(entry_stack_ != NULL);
1826 ASSERT(entry_stack_->previous_thread_data == NULL || 1842 ASSERT(entry_stack_->previous_thread_data == NULL ||
1827 entry_stack_->previous_thread_data->thread_id().Equals( 1843 entry_stack_->previous_thread_data->thread_id().Equals(
1828 ThreadId::Current())); 1844 ThreadId::Current()));
(...skipping 19 matching lines...) Expand all
1848 1864
1849 #ifdef DEBUG 1865 #ifdef DEBUG
1850 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ 1866 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
1851 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); 1867 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
1852 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) 1868 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
1853 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) 1869 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
1854 #undef ISOLATE_FIELD_OFFSET 1870 #undef ISOLATE_FIELD_OFFSET
1855 #endif 1871 #endif
1856 1872
1857 } } // namespace v8::internal 1873 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698