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/heap.cc

Issue 6529032: Merge 6168:6800 from bleeding_edge to experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 10 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/heap.h ('k') | src/heap-inl.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 17 matching lines...) Expand all
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "accessors.h" 30 #include "accessors.h"
31 #include "api.h" 31 #include "api.h"
32 #include "bootstrapper.h" 32 #include "bootstrapper.h"
33 #include "codegen-inl.h" 33 #include "codegen-inl.h"
34 #include "compilation-cache.h" 34 #include "compilation-cache.h"
35 #include "debug.h" 35 #include "debug.h"
36 #include "heap-profiler.h" 36 #include "heap-profiler.h"
37 #include "global-handles.h" 37 #include "global-handles.h"
38 #include "liveobjectlist-inl.h"
38 #include "mark-compact.h" 39 #include "mark-compact.h"
39 #include "natives.h" 40 #include "natives.h"
40 #include "objects-visiting.h" 41 #include "objects-visiting.h"
41 #include "runtime-profiler.h" 42 #include "runtime-profiler.h"
42 #include "scanner-base.h" 43 #include "scanner-base.h"
43 #include "scopeinfo.h" 44 #include "scopeinfo.h"
44 #include "snapshot.h" 45 #include "snapshot.h"
45 #include "store-buffer.h" 46 #include "store-buffer.h"
46 #include "v8threads.h" 47 #include "v8threads.h"
47 #include "vm-state-inl.h" 48 #include "vm-state-inl.h"
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 if (FLAG_verify_heap) { 373 if (FLAG_verify_heap) {
373 Verify(); 374 Verify();
374 } 375 }
375 376
376 if (FLAG_gc_verbose) Print(); 377 if (FLAG_gc_verbose) Print();
377 #endif 378 #endif
378 379
379 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) 380 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
380 ReportStatisticsBeforeGC(); 381 ReportStatisticsBeforeGC();
381 #endif 382 #endif
383
384 LiveObjectList::GCPrologue();
382 } 385 }
383 386
384 intptr_t Heap::SizeOfObjects() { 387 intptr_t Heap::SizeOfObjects() {
385 intptr_t total = 0; 388 intptr_t total = 0;
386 AllSpaces spaces; 389 AllSpaces spaces;
387 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { 390 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) {
388 total += space->SizeOfObjects(); 391 total += space->SizeOfObjects();
389 } 392 }
390 return total; 393 return total;
391 } 394 }
392 395
393 void Heap::GarbageCollectionEpilogue() { 396 void Heap::GarbageCollectionEpilogue() {
397 LiveObjectList::GCEpilogue();
394 #ifdef DEBUG 398 #ifdef DEBUG
395 allow_allocation(true); 399 allow_allocation(true);
396 ZapFromSpace(); 400 ZapFromSpace();
397 401
398 if (FLAG_verify_heap) { 402 if (FLAG_verify_heap) {
399 Verify(); 403 Verify();
400 } 404 }
401 405
402 if (FLAG_print_global_handles) GlobalHandles::Print(); 406 if (FLAG_print_global_handles) GlobalHandles::Print();
403 if (FLAG_print_handles) PrintHandles(); 407 if (FLAG_print_handles) PrintHandles();
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 int sampler_window_size = RuntimeProfiler::SamplerWindowSize(); 1009 int sampler_window_size = RuntimeProfiler::SamplerWindowSize();
1006 scavenge_visitor.VisitPointers( 1010 scavenge_visitor.VisitPointers(
1007 sampler_window_address, 1011 sampler_window_address,
1008 sampler_window_address + sampler_window_size); 1012 sampler_window_address + sampler_window_size);
1009 1013
1010 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1014 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
1011 1015
1012 UpdateNewSpaceReferencesInExternalStringTable( 1016 UpdateNewSpaceReferencesInExternalStringTable(
1013 &UpdateNewSpaceReferenceInExternalStringTableEntry); 1017 &UpdateNewSpaceReferenceInExternalStringTableEntry);
1014 1018
1019 LiveObjectList::UpdateReferencesForScavengeGC();
1020
1015 ASSERT(new_space_front == new_space_.top()); 1021 ASSERT(new_space_front == new_space_.top());
1016 1022
1017 // Set age mark. 1023 // Set age mark.
1018 new_space_.set_age_mark(new_space_.top()); 1024 new_space_.set_age_mark(new_space_.top());
1019 1025
1020 // Update how much has survived scavenge. 1026 // Update how much has survived scavenge.
1021 IncrementYoungSurvivorsCounter(static_cast<int>( 1027 IncrementYoungSurvivorsCounter(static_cast<int>(
1022 (PromotedSpaceSize() - survived_watermark) + new_space_.Size())); 1028 (PromotedSpaceSize() - survived_watermark) + new_space_.Size()));
1023 1029
1024 LOG(ResourceEvent("scavenge", "end")); 1030 LOG(ResourceEvent("scavenge", "end"));
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 Map* global_context_map = Map::cast(obj); 1772 Map* global_context_map = Map::cast(obj);
1767 global_context_map->set_visitor_id(StaticVisitorBase::kVisitGlobalContext); 1773 global_context_map->set_visitor_id(StaticVisitorBase::kVisitGlobalContext);
1768 set_global_context_map(global_context_map); 1774 set_global_context_map(global_context_map);
1769 1775
1770 { MaybeObject* maybe_obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE, 1776 { MaybeObject* maybe_obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE,
1771 SharedFunctionInfo::kAlignedSize); 1777 SharedFunctionInfo::kAlignedSize);
1772 if (!maybe_obj->ToObject(&obj)) return false; 1778 if (!maybe_obj->ToObject(&obj)) return false;
1773 } 1779 }
1774 set_shared_function_info_map(Map::cast(obj)); 1780 set_shared_function_info_map(Map::cast(obj));
1775 1781
1782 { MaybeObject* maybe_obj = AllocateMap(JS_MESSAGE_OBJECT_TYPE,
1783 JSMessageObject::kSize);
1784 if (!maybe_obj->ToObject(&obj)) return false;
1785 }
1786 set_message_object_map(Map::cast(obj));
1787
1776 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); 1788 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array()));
1777 return true; 1789 return true;
1778 } 1790 }
1779 1791
1780 1792
1781 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 1793 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
1782 // Statically ensure that it is safe to allocate heap numbers in paged 1794 // Statically ensure that it is safe to allocate heap numbers in paged
1783 // spaces. 1795 // spaces.
1784 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1796 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1785 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1797 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 set_js_entry_code(*stub.GetCode()); 1889 set_js_entry_code(*stub.GetCode());
1878 } 1890 }
1879 1891
1880 1892
1881 void Heap::CreateJSConstructEntryStub() { 1893 void Heap::CreateJSConstructEntryStub() {
1882 JSConstructEntryStub stub; 1894 JSConstructEntryStub stub;
1883 set_js_construct_entry_code(*stub.GetCode()); 1895 set_js_construct_entry_code(*stub.GetCode());
1884 } 1896 }
1885 1897
1886 1898
1899 #if V8_TARGET_ARCH_ARM
1900 void Heap::CreateDirectCEntryStub() {
1901 DirectCEntryStub stub;
1902 set_direct_c_entry_code(*stub.GetCode());
1903 }
1904 #endif
1905
1906
1887 void Heap::CreateFixedStubs() { 1907 void Heap::CreateFixedStubs() {
1888 // Here we create roots for fixed stubs. They are needed at GC 1908 // Here we create roots for fixed stubs. They are needed at GC
1889 // for cooking and uncooking (check out frames.cc). 1909 // for cooking and uncooking (check out frames.cc).
1890 // The eliminates the need for doing dictionary lookup in the 1910 // The eliminates the need for doing dictionary lookup in the
1891 // stub cache for these stubs. 1911 // stub cache for these stubs.
1892 HandleScope scope; 1912 HandleScope scope;
1893 // gcc-4.4 has problem generating correct code of following snippet: 1913 // gcc-4.4 has problem generating correct code of following snippet:
1894 // { CEntryStub stub; 1914 // { CEntryStub stub;
1895 // c_entry_code_ = *stub.GetCode(); 1915 // c_entry_code_ = *stub.GetCode();
1896 // } 1916 // }
1897 // { DebuggerStatementStub stub; 1917 // { DebuggerStatementStub stub;
1898 // debugger_statement_code_ = *stub.GetCode(); 1918 // debugger_statement_code_ = *stub.GetCode();
1899 // } 1919 // }
1900 // To workaround the problem, make separate functions without inlining. 1920 // To workaround the problem, make separate functions without inlining.
1901 Heap::CreateCEntryStub(); 1921 Heap::CreateCEntryStub();
1902 Heap::CreateJSEntryStub(); 1922 Heap::CreateJSEntryStub();
1903 Heap::CreateJSConstructEntryStub(); 1923 Heap::CreateJSConstructEntryStub();
1904 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP 1924 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP
1905 Heap::CreateRegExpCEntryStub(); 1925 Heap::CreateRegExpCEntryStub();
1906 #endif 1926 #endif
1927 #if V8_TARGET_ARCH_ARM
1928 Heap::CreateDirectCEntryStub();
1929 #endif
1907 } 1930 }
1908 1931
1909 1932
1910 bool Heap::CreateInitialObjects() { 1933 bool Heap::CreateInitialObjects() {
1911 Object* obj; 1934 Object* obj;
1912 1935
1913 // The -0 value must be set before NumberFromDouble works. 1936 // The -0 value must be set before NumberFromDouble works.
1914 { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED); 1937 { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED);
1915 if (!maybe_obj->ToObject(&obj)) return false; 1938 if (!maybe_obj->ToObject(&obj)) return false;
1916 } 1939 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 { MaybeObject* maybe_obj = CreateOddball("false", Smi::FromInt(0)); 1980 { MaybeObject* maybe_obj = CreateOddball("false", Smi::FromInt(0));
1958 if (!maybe_obj->ToObject(&obj)) return false; 1981 if (!maybe_obj->ToObject(&obj)) return false;
1959 } 1982 }
1960 set_false_value(obj); 1983 set_false_value(obj);
1961 1984
1962 { MaybeObject* maybe_obj = CreateOddball("hole", Smi::FromInt(-1)); 1985 { MaybeObject* maybe_obj = CreateOddball("hole", Smi::FromInt(-1));
1963 if (!maybe_obj->ToObject(&obj)) return false; 1986 if (!maybe_obj->ToObject(&obj)) return false;
1964 } 1987 }
1965 set_the_hole_value(obj); 1988 set_the_hole_value(obj);
1966 1989
1990 { MaybeObject* maybe_obj = CreateOddball("arguments_marker",
1991 Smi::FromInt(-4));
1992 if (!maybe_obj->ToObject(&obj)) return false;
1993 }
1994 set_arguments_marker(obj);
1995
1967 { MaybeObject* maybe_obj = 1996 { MaybeObject* maybe_obj =
1968 CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2)); 1997 CreateOddball("no_interceptor_result_sentinel", Smi::FromInt(-2));
1969 if (!maybe_obj->ToObject(&obj)) return false; 1998 if (!maybe_obj->ToObject(&obj)) return false;
1970 } 1999 }
1971 set_no_interceptor_result_sentinel(obj); 2000 set_no_interceptor_result_sentinel(obj);
1972 2001
1973 { MaybeObject* maybe_obj = 2002 { MaybeObject* maybe_obj =
1974 CreateOddball("termination_exception", Smi::FromInt(-3)); 2003 CreateOddball("termination_exception", Smi::FromInt(-3));
1975 if (!maybe_obj->ToObject(&obj)) return false; 2004 if (!maybe_obj->ToObject(&obj)) return false;
1976 } 2005 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 share->set_this_property_assignments_count(0); 2292 share->set_this_property_assignments_count(0);
2264 share->set_this_property_assignments(undefined_value()); 2293 share->set_this_property_assignments(undefined_value());
2265 share->set_opt_count(0); 2294 share->set_opt_count(0);
2266 share->set_num_literals(0); 2295 share->set_num_literals(0);
2267 share->set_end_position(0); 2296 share->set_end_position(0);
2268 share->set_function_token_position(0); 2297 share->set_function_token_position(0);
2269 return result; 2298 return result;
2270 } 2299 }
2271 2300
2272 2301
2302 MaybeObject* Heap::AllocateJSMessageObject(String* type,
2303 JSArray* arguments,
2304 int start_position,
2305 int end_position,
2306 Object* script,
2307 Object* stack_trace,
2308 Object* stack_frames) {
2309 Object* result;
2310 { MaybeObject* maybe_result = Allocate(message_object_map(), NEW_SPACE);
2311 if (!maybe_result->ToObject(&result)) return maybe_result;
2312 }
2313 JSMessageObject* message = JSMessageObject::cast(result);
2314 message->set_properties(Heap::empty_fixed_array());
2315 message->set_elements(Heap::empty_fixed_array());
2316 message->set_type(type);
2317 message->set_arguments(arguments);
2318 message->set_start_position(start_position);
2319 message->set_end_position(end_position);
2320 message->set_script(script);
2321 message->set_stack_trace(stack_trace);
2322 message->set_stack_frames(stack_frames);
2323 return result;
2324 }
2325
2326
2327
2273 // Returns true for a character in a range. Both limits are inclusive. 2328 // Returns true for a character in a range. Both limits are inclusive.
2274 static inline bool Between(uint32_t character, uint32_t from, uint32_t to) { 2329 static inline bool Between(uint32_t character, uint32_t from, uint32_t to) {
2275 // This makes uses of the the unsigned wraparound. 2330 // This makes uses of the the unsigned wraparound.
2276 return character - from <= to - from; 2331 return character - from <= to - from;
2277 } 2332 }
2278 2333
2279 2334
2280 MUST_USE_RESULT static inline MaybeObject* MakeOrFindTwoCharacterString( 2335 MUST_USE_RESULT static inline MaybeObject* MakeOrFindTwoCharacterString(
2281 uint32_t c1, 2336 uint32_t c1,
2282 uint32_t c2) { 2337 uint32_t c2) {
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 Object* result; 2719 Object* result;
2665 if (!maybe_result->ToObject(&result)) return maybe_result; 2720 if (!maybe_result->ToObject(&result)) return maybe_result;
2666 2721
2667 // Initialize the object 2722 // Initialize the object
2668 HeapObject::cast(result)->set_map(code_map()); 2723 HeapObject::cast(result)->set_map(code_map());
2669 Code* code = Code::cast(result); 2724 Code* code = Code::cast(result);
2670 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); 2725 ASSERT(!CodeRange::exists() || CodeRange::contains(code->address()));
2671 code->set_instruction_size(desc.instr_size); 2726 code->set_instruction_size(desc.instr_size);
2672 code->set_relocation_info(ByteArray::cast(reloc_info)); 2727 code->set_relocation_info(ByteArray::cast(reloc_info));
2673 code->set_flags(flags); 2728 code->set_flags(flags);
2729 if (code->is_call_stub() || code->is_keyed_call_stub()) {
2730 code->set_check_type(RECEIVER_MAP_CHECK);
2731 }
2674 code->set_deoptimization_data(empty_fixed_array()); 2732 code->set_deoptimization_data(empty_fixed_array());
2675 // Allow self references to created code object by patching the handle to 2733 // Allow self references to created code object by patching the handle to
2676 // point to the newly allocated Code object. 2734 // point to the newly allocated Code object.
2677 if (!self_reference.is_null()) { 2735 if (!self_reference.is_null()) {
2678 *(self_reference.location()) = code; 2736 *(self_reference.location()) = code;
2679 } 2737 }
2680 // Migrate generated code. 2738 // Migrate generated code.
2681 // The generated code can contain Object** values (typically from handles) 2739 // The generated code can contain Object** values (typically from handles)
2682 // that are dereferenced during the copy to point directly to the actual heap 2740 // that are dereferenced during the copy to point directly to the actual heap
2683 // objects. These pointers can include references to the code object itself, 2741 // objects. These pointers can include references to the code object itself,
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
4016 if (string->IsSymbol()) { 4074 if (string->IsSymbol()) {
4017 *symbol = string; 4075 *symbol = string;
4018 return true; 4076 return true;
4019 } 4077 }
4020 return symbol_table()->LookupSymbolIfExists(string, symbol); 4078 return symbol_table()->LookupSymbolIfExists(string, symbol);
4021 } 4079 }
4022 4080
4023 4081
4024 #ifdef DEBUG 4082 #ifdef DEBUG
4025 void Heap::ZapFromSpace() { 4083 void Heap::ZapFromSpace() {
4026 ASSERT(reinterpret_cast<Object*>(kFromSpaceZapValue)->IsHeapObject()); 4084 ASSERT(reinterpret_cast<Object*>(kFromSpaceZapValue)->IsFailure());
4027 for (Address a = new_space_.FromSpaceLow(); 4085 for (Address a = new_space_.FromSpaceLow();
4028 a < new_space_.FromSpaceHigh(); 4086 a < new_space_.FromSpaceHigh();
4029 a += kPointerSize) { 4087 a += kPointerSize) {
4030 Memory::Address_at(a) = kFromSpaceZapValue; 4088 Memory::Address_at(a) = kFromSpaceZapValue;
4031 } 4089 }
4032 } 4090 }
4033 #endif // DEBUG 4091 #endif // DEBUG
4034 4092
4035 4093
4036 void Heap::IteratePointersToNewSpace(Address start, 4094 void Heap::IteratePointersToNewSpace(Address start,
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
4996 }; 5054 };
4997 5055
4998 void MarkUnreachableObjects() { 5056 void MarkUnreachableObjects() {
4999 HeapIterator iterator; 5057 HeapIterator iterator;
5000 for (HeapObject* obj = iterator.next(); 5058 for (HeapObject* obj = iterator.next();
5001 obj != NULL; 5059 obj != NULL;
5002 obj = iterator.next()) { 5060 obj = iterator.next()) {
5003 IntrusiveMarking::SetMark(obj); 5061 IntrusiveMarking::SetMark(obj);
5004 } 5062 }
5005 UnmarkingVisitor visitor; 5063 UnmarkingVisitor visitor;
5006 Heap::IterateRoots(&visitor, VISIT_ONLY_STRONG); 5064 Heap::IterateRoots(&visitor, VISIT_ALL);
5007 while (visitor.can_process()) 5065 while (visitor.can_process())
5008 visitor.ProcessNext(); 5066 visitor.ProcessNext();
5009 } 5067 }
5010 5068
5011 AssertNoAllocation no_alloc; 5069 AssertNoAllocation no_alloc;
5012 }; 5070 };
5013 5071
5014 5072
5015 HeapIterator::HeapIterator() 5073 HeapIterator::HeapIterator()
5016 : filtering_(HeapIterator::kNoFiltering), 5074 : filtering_(HeapIterator::kNoFiltering),
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
5509 void ExternalStringTable::TearDown() { 5567 void ExternalStringTable::TearDown() {
5510 new_space_strings_.Free(); 5568 new_space_strings_.Free();
5511 old_space_strings_.Free(); 5569 old_space_strings_.Free();
5512 } 5570 }
5513 5571
5514 5572
5515 List<Object*> ExternalStringTable::new_space_strings_; 5573 List<Object*> ExternalStringTable::new_space_strings_;
5516 List<Object*> ExternalStringTable::old_space_strings_; 5574 List<Object*> ExternalStringTable::old_space_strings_;
5517 5575
5518 } } // namespace v8::internal 5576 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698