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

Side by Side Diff: src/heap.h

Issue 844006: Merge changes up to V8 version 2.1.3 into the partial snapshots (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 9 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/handles.cc ('k') | src/heap.cc » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_HEAP_H_ 28 #ifndef V8_HEAP_H_
29 #define V8_HEAP_H_ 29 #define V8_HEAP_H_
30 30
31 #include <math.h> 31 #include <math.h>
32 32
33 #include "zone-inl.h" 33 #include "splay-tree-inl.h"
34 34 #include "v8-counters.h"
35 35
36 namespace v8 { 36 namespace v8 {
37 namespace internal { 37 namespace internal {
38 38
39 // Forward declarations.
40 class ZoneScopeInfo;
41
39 // Defines all the roots in Heap. 42 // Defines all the roots in Heap.
40 #define UNCONDITIONAL_STRONG_ROOT_LIST(V) \ 43 #define UNCONDITIONAL_STRONG_ROOT_LIST(V) \
41 /* Put the byte array map early. We need it to be in place by the time */ \ 44 /* Put the byte array map early. We need it to be in place by the time */ \
42 /* the deserializer hits the next page, since it wants to put a byte */ \ 45 /* the deserializer hits the next page, since it wants to put a byte */ \
43 /* array in the unused space at the end of the page. */ \ 46 /* array in the unused space at the end of the page. */ \
44 V(Map, byte_array_map, ByteArrayMap) \ 47 V(Map, byte_array_map, ByteArrayMap) \
45 V(Map, one_pointer_filler_map, OnePointerFillerMap) \ 48 V(Map, one_pointer_filler_map, OnePointerFillerMap) \
46 V(Map, two_pointer_filler_map, TwoPointerFillerMap) \ 49 V(Map, two_pointer_filler_map, TwoPointerFillerMap) \
47 /* Cluster the most popular ones in a few cache lines here at the top. */ \ 50 /* Cluster the most popular ones in a few cache lines here at the top. */ \
48 V(Smi, stack_limit, StackLimit) \ 51 V(Smi, stack_limit, StackLimit) \
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Please note this function does not perform a garbage collection. 342 // Please note this function does not perform a garbage collection.
340 static Object* AllocateMap(InstanceType instance_type, int instance_size); 343 static Object* AllocateMap(InstanceType instance_type, int instance_size);
341 344
342 // Allocates a partial map for bootstrapping. 345 // Allocates a partial map for bootstrapping.
343 static Object* AllocatePartialMap(InstanceType instance_type, 346 static Object* AllocatePartialMap(InstanceType instance_type,
344 int instance_size); 347 int instance_size);
345 348
346 // Allocate a map for the specified function 349 // Allocate a map for the specified function
347 static Object* AllocateInitialMap(JSFunction* fun); 350 static Object* AllocateInitialMap(JSFunction* fun);
348 351
352 // Allocates an empty code cache.
353 static Object* AllocateCodeCache();
354
349 // Allocates and fully initializes a String. There are two String 355 // Allocates and fully initializes a String. There are two String
350 // encodings: ASCII and two byte. One should choose between the three string 356 // encodings: ASCII and two byte. One should choose between the three string
351 // allocation functions based on the encoding of the string buffer used to 357 // allocation functions based on the encoding of the string buffer used to
352 // initialized the string. 358 // initialized the string.
353 // - ...FromAscii initializes the string from a buffer that is ASCII 359 // - ...FromAscii initializes the string from a buffer that is ASCII
354 // encoded (it does not check that the buffer is ASCII encoded) and the 360 // encoded (it does not check that the buffer is ASCII encoded) and the
355 // result will be ASCII encoded. 361 // result will be ASCII encoded.
356 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 362 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
357 // encoded. If the characters are all single-byte characters, the 363 // encoded. If the characters are all single-byte characters, the
358 // result will be ASCII encoded, otherwise it will converted to two 364 // result will be ASCII encoded, otherwise it will converted to two
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 449 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
444 // failed. 450 // failed.
445 // Please note this does not perform a garbage collection. 451 // Please note this does not perform a garbage collection.
446 static Object* AllocateJSGlobalPropertyCell(Object* value); 452 static Object* AllocateJSGlobalPropertyCell(Object* value);
447 453
448 // Allocates a fixed array initialized with undefined values 454 // Allocates a fixed array initialized with undefined values
449 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 455 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
450 // failed. 456 // failed.
451 // Please note this does not perform a garbage collection. 457 // Please note this does not perform a garbage collection.
452 static Object* AllocateFixedArray(int length, PretenureFlag pretenure); 458 static Object* AllocateFixedArray(int length, PretenureFlag pretenure);
453 // Allocate uninitialized, non-tenured fixed array with length elements. 459 // Allocates a fixed array initialized with undefined values
454 static Object* AllocateFixedArray(int length); 460 static Object* AllocateFixedArray(int length);
455 461
462 // Allocates an uninitialized fixed array. It must be filled by the caller.
463 //
464 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
465 // failed.
466 // Please note this does not perform a garbage collection.
467 static Object* AllocateUninitializedFixedArray(int length);
468
456 // Make a copy of src and return it. Returns 469 // Make a copy of src and return it. Returns
457 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. 470 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
458 static Object* CopyFixedArray(FixedArray* src); 471 static Object* CopyFixedArray(FixedArray* src);
459 472
460 // Allocates a fixed array initialized with the hole values. 473 // Allocates a fixed array initialized with the hole values.
461 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 474 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
462 // failed. 475 // failed.
463 // Please note this does not perform a garbage collection. 476 // Please note this does not perform a garbage collection.
464 static Object* AllocateFixedArrayWithHoles(int length); 477 static Object* AllocateFixedArrayWithHoles(int length);
465 478
466 // AllocateHashTable is identical to AllocateFixedArray except 479 // AllocateHashTable is identical to AllocateFixedArray except
467 // that the resulting object has hash_table_map as map. 480 // that the resulting object has hash_table_map as map.
468 static Object* AllocateHashTable(int length); 481 static Object* AllocateHashTable(int length,
482 PretenureFlag pretenure = NOT_TENURED);
469 483
470 // Allocate a global (but otherwise uninitialized) context. 484 // Allocate a global (but otherwise uninitialized) context.
471 static Object* AllocateGlobalContext(); 485 static Object* AllocateGlobalContext();
472 486
473 // Allocate a function context. 487 // Allocate a function context.
474 static Object* AllocateFunctionContext(int length, JSFunction* closure); 488 static Object* AllocateFunctionContext(int length, JSFunction* closure);
475 489
476 // Allocate a 'with' context. 490 // Allocate a 'with' context.
477 static Object* AllocateWithContext(Context* previous, 491 static Object* AllocateWithContext(Context* previous,
478 JSObject* extension, 492 JSObject* extension,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 static Object* AllocateConsString(String* first, String* second); 564 static Object* AllocateConsString(String* first, String* second);
551 565
552 // Allocates a new sub string object which is a substring of an underlying 566 // Allocates a new sub string object which is a substring of an underlying
553 // string buffer stretching from the index start (inclusive) to the index 567 // string buffer stretching from the index start (inclusive) to the index
554 // end (exclusive). 568 // end (exclusive).
555 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 569 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
556 // failed. 570 // failed.
557 // Please note this does not perform a garbage collection. 571 // Please note this does not perform a garbage collection.
558 static Object* AllocateSubString(String* buffer, 572 static Object* AllocateSubString(String* buffer,
559 int start, 573 int start,
560 int end); 574 int end,
575 PretenureFlag pretenure = NOT_TENURED);
561 576
562 // Allocate a new external string object, which is backed by a string 577 // Allocate a new external string object, which is backed by a string
563 // resource that resides outside the V8 heap. 578 // resource that resides outside the V8 heap.
564 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 579 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
565 // failed. 580 // failed.
566 // Please note this does not perform a garbage collection. 581 // Please note this does not perform a garbage collection.
567 static Object* AllocateExternalStringFromAscii( 582 static Object* AllocateExternalStringFromAscii(
568 ExternalAsciiString::Resource* resource); 583 ExternalAsciiString::Resource* resource);
569 static Object* AllocateExternalStringFromTwoByte( 584 static Object* AllocateExternalStringFromTwoByte(
570 ExternalTwoByteString::Resource* resource); 585 ExternalTwoByteString::Resource* resource);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 static void GarbageCollectionEpilogue(); 641 static void GarbageCollectionEpilogue();
627 642
628 // Performs garbage collection operation. 643 // Performs garbage collection operation.
629 // Returns whether required_space bytes are available after the collection. 644 // Returns whether required_space bytes are available after the collection.
630 static bool CollectGarbage(int required_space, AllocationSpace space); 645 static bool CollectGarbage(int required_space, AllocationSpace space);
631 646
632 // Performs a full garbage collection. Force compaction if the 647 // Performs a full garbage collection. Force compaction if the
633 // parameter is true. 648 // parameter is true.
634 static void CollectAllGarbage(bool force_compaction); 649 static void CollectAllGarbage(bool force_compaction);
635 650
636 // Performs a full garbage collection if a context has been disposed
637 // since the last time the check was performed.
638 static void CollectAllGarbageIfContextDisposed();
639
640 // Notify the heap that a context has been disposed. 651 // Notify the heap that a context has been disposed.
641 static void NotifyContextDisposed(); 652 static int NotifyContextDisposed() { return ++contexts_disposed_; }
642 653
643 // Utility to invoke the scavenger. This is needed in test code to 654 // Utility to invoke the scavenger. This is needed in test code to
644 // ensure correct callback for weak global handles. 655 // ensure correct callback for weak global handles.
645 static void PerformScavenge(); 656 static void PerformScavenge();
646 657
647 #ifdef DEBUG 658 #ifdef DEBUG
648 // Utility used with flag gc-greedy. 659 // Utility used with flag gc-greedy.
649 static bool GarbageCollectionGreedyCheck(); 660 static bool GarbageCollectionGreedyCheck();
650 #endif 661 #endif
651 662
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 // Makes a new symbol object 778 // Makes a new symbol object
768 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 779 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
769 // failed. 780 // failed.
770 // Please note this function does not perform a garbage collection. 781 // Please note this function does not perform a garbage collection.
771 static Object* CreateSymbol(const char* str, int length, int hash); 782 static Object* CreateSymbol(const char* str, int length, int hash);
772 static Object* CreateSymbol(String* str); 783 static Object* CreateSymbol(String* str);
773 784
774 // Write barrier support for address[offset] = o. 785 // Write barrier support for address[offset] = o.
775 static inline void RecordWrite(Address address, int offset); 786 static inline void RecordWrite(Address address, int offset);
776 787
788 // Write barrier support for address[start : start + len[ = o.
789 static inline void RecordWrites(Address address, int start, int len);
790
777 // Given an address occupied by a live code object, return that object. 791 // Given an address occupied by a live code object, return that object.
778 static Object* FindCodeObject(Address a); 792 static Object* FindCodeObject(Address a);
779 793
780 // Invoke Shrink on shrinkable spaces. 794 // Invoke Shrink on shrinkable spaces.
781 static void Shrink(); 795 static void Shrink();
782 796
783 enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT }; 797 enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT };
784 static inline HeapState gc_state() { return gc_state_; } 798 static inline HeapState gc_state() { return gc_state_; }
785 799
786 #ifdef DEBUG 800 #ifdef DEBUG
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 static int initial_semispace_size_; 920 static int initial_semispace_size_;
907 static int max_old_generation_size_; 921 static int max_old_generation_size_;
908 static size_t code_range_size_; 922 static size_t code_range_size_;
909 923
910 // For keeping track of how much data has survived 924 // For keeping track of how much data has survived
911 // scavenge since last new space expansion. 925 // scavenge since last new space expansion.
912 static int survived_since_last_expansion_; 926 static int survived_since_last_expansion_;
913 927
914 static int always_allocate_scope_depth_; 928 static int always_allocate_scope_depth_;
915 static int linear_allocation_scope_depth_; 929 static int linear_allocation_scope_depth_;
916 static bool context_disposed_pending_; 930
931 // For keeping track of context disposals.
932 static int contexts_disposed_;
917 933
918 #if defined(V8_TARGET_ARCH_X64) 934 #if defined(V8_TARGET_ARCH_X64)
919 static const int kMaxObjectSizeInNewSpace = 512*KB; 935 static const int kMaxObjectSizeInNewSpace = 512*KB;
920 #else 936 #else
921 static const int kMaxObjectSizeInNewSpace = 256*KB; 937 static const int kMaxObjectSizeInNewSpace = 256*KB;
922 #endif 938 #endif
923 939
924 static NewSpace new_space_; 940 static NewSpace new_space_;
925 static OldSpace* old_pointer_space_; 941 static OldSpace* old_pointer_space_;
926 static OldSpace* old_data_space_; 942 static OldSpace* old_data_space_;
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 ~DisableAssertNoAllocation() { } 1534 ~DisableAssertNoAllocation() { }
1519 }; 1535 };
1520 1536
1521 #endif 1537 #endif
1522 1538
1523 // GCTracer collects and prints ONE line after each garbage collector 1539 // GCTracer collects and prints ONE line after each garbage collector
1524 // invocation IFF --trace_gc is used. 1540 // invocation IFF --trace_gc is used.
1525 1541
1526 class GCTracer BASE_EMBEDDED { 1542 class GCTracer BASE_EMBEDDED {
1527 public: 1543 public:
1544 // Time spent while in the external scope counts towards the
1545 // external time in the tracer and will be reported separately.
1546 class ExternalScope BASE_EMBEDDED {
1547 public:
1548 explicit ExternalScope(GCTracer* tracer) : tracer_(tracer) {
1549 start_time_ = OS::TimeCurrentMillis();
1550 }
1551 ~ExternalScope() {
1552 tracer_->external_time_ += OS::TimeCurrentMillis() - start_time_;
1553 }
1554
1555 private:
1556 GCTracer* tracer_;
1557 double start_time_;
1558 };
1559
1528 GCTracer(); 1560 GCTracer();
1529
1530 ~GCTracer(); 1561 ~GCTracer();
1531 1562
1532 // Sets the collector. 1563 // Sets the collector.
1533 void set_collector(GarbageCollector collector) { collector_ = collector; } 1564 void set_collector(GarbageCollector collector) { collector_ = collector; }
1534 1565
1535 // Sets the GC count. 1566 // Sets the GC count.
1536 void set_gc_count(int count) { gc_count_ = count; } 1567 void set_gc_count(int count) { gc_count_ = count; }
1537 1568
1538 // Sets the full GC count. 1569 // Sets the full GC count.
1539 void set_full_gc_count(int count) { full_gc_count_ = count; } 1570 void set_full_gc_count(int count) { full_gc_count_ = count; }
(...skipping 13 matching lines...) Expand all
1553 1584
1554 // Returns size of object in heap (in MB). 1585 // Returns size of object in heap (in MB).
1555 double SizeOfHeapObjects() { 1586 double SizeOfHeapObjects() {
1556 return (static_cast<double>(Heap::SizeOfObjects())) / MB; 1587 return (static_cast<double>(Heap::SizeOfObjects())) / MB;
1557 } 1588 }
1558 1589
1559 double start_time_; // Timestamp set in the constructor. 1590 double start_time_; // Timestamp set in the constructor.
1560 double start_size_; // Size of objects in heap set in constructor. 1591 double start_size_; // Size of objects in heap set in constructor.
1561 GarbageCollector collector_; // Type of collector. 1592 GarbageCollector collector_; // Type of collector.
1562 1593
1594 // Keep track of the amount of time spent in external callbacks.
1595 double external_time_;
1596
1563 // A count (including this one, eg, the first collection is 1) of the 1597 // A count (including this one, eg, the first collection is 1) of the
1564 // number of garbage collections. 1598 // number of garbage collections.
1565 int gc_count_; 1599 int gc_count_;
1566 1600
1567 // A count (including this one) of the number of full garbage collections. 1601 // A count (including this one) of the number of full garbage collections.
1568 int full_gc_count_; 1602 int full_gc_count_;
1569 1603
1570 // True if the current GC is a compacting full collection, false 1604 // True if the current GC is a compacting full collection, false
1571 // otherwise. 1605 // otherwise.
1572 bool is_compacting_; 1606 bool is_compacting_;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 1746
1713 // To speed up scavenge collections new space string are kept 1747 // To speed up scavenge collections new space string are kept
1714 // separate from old space strings. 1748 // separate from old space strings.
1715 static List<Object*> new_space_strings_; 1749 static List<Object*> new_space_strings_;
1716 static List<Object*> old_space_strings_; 1750 static List<Object*> old_space_strings_;
1717 }; 1751 };
1718 1752
1719 } } // namespace v8::internal 1753 } } // namespace v8::internal
1720 1754
1721 #endif // V8_HEAP_H_ 1755 #endif // V8_HEAP_H_
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698