OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 uintptr_t NewSpaceMask() { return new_space_.mask(); } | 501 uintptr_t NewSpaceMask() { return new_space_.mask(); } |
502 Address NewSpaceTop() { return new_space_.top(); } | 502 Address NewSpaceTop() { return new_space_.top(); } |
503 | 503 |
504 NewSpace* new_space() { return &new_space_; } | 504 NewSpace* new_space() { return &new_space_; } |
505 OldSpace* old_pointer_space() { return old_pointer_space_; } | 505 OldSpace* old_pointer_space() { return old_pointer_space_; } |
506 OldSpace* old_data_space() { return old_data_space_; } | 506 OldSpace* old_data_space() { return old_data_space_; } |
507 OldSpace* code_space() { return code_space_; } | 507 OldSpace* code_space() { return code_space_; } |
508 MapSpace* map_space() { return map_space_; } | 508 MapSpace* map_space() { return map_space_; } |
509 CellSpace* cell_space() { return cell_space_; } | 509 CellSpace* cell_space() { return cell_space_; } |
510 LargeObjectSpace* lo_space() { return lo_space_; } | 510 LargeObjectSpace* lo_space() { return lo_space_; } |
511 PagedSpace* paged_space(int idx) { | |
512 switch (idx) { | |
513 case OLD_POINTER_SPACE: | |
514 return old_pointer_space(); | |
515 case OLD_DATA_SPACE: | |
516 return old_data_space(); | |
517 case MAP_SPACE: | |
518 return map_space(); | |
519 case CELL_SPACE: | |
520 return cell_space(); | |
521 case CODE_SPACE: | |
522 return code_space(); | |
523 case NEW_SPACE: | |
524 case LO_SPACE: | |
525 UNREACHABLE(); | |
526 } | |
527 return NULL; | |
528 } | |
529 | 511 |
530 bool always_allocate() { return always_allocate_scope_depth_ != 0; } | 512 bool always_allocate() { return always_allocate_scope_depth_ != 0; } |
531 Address always_allocate_scope_depth_address() { | 513 Address always_allocate_scope_depth_address() { |
532 return reinterpret_cast<Address>(&always_allocate_scope_depth_); | 514 return reinterpret_cast<Address>(&always_allocate_scope_depth_); |
533 } | 515 } |
534 bool linear_allocation() { | 516 bool linear_allocation() { |
535 return linear_allocation_scope_depth_ != 0; | 517 return linear_allocation_scope_depth_ != 0; |
536 } | 518 } |
537 | 519 |
538 Address* NewSpaceAllocationTopAddress() { | 520 Address* NewSpaceAllocationTopAddress() { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 650 |
669 // Allocates an empty TypeFeedbackInfo. | 651 // Allocates an empty TypeFeedbackInfo. |
670 MUST_USE_RESULT MaybeObject* AllocateTypeFeedbackInfo(); | 652 MUST_USE_RESULT MaybeObject* AllocateTypeFeedbackInfo(); |
671 | 653 |
672 // Allocates an AliasedArgumentsEntry. | 654 // Allocates an AliasedArgumentsEntry. |
673 MUST_USE_RESULT MaybeObject* AllocateAliasedArgumentsEntry(int slot); | 655 MUST_USE_RESULT MaybeObject* AllocateAliasedArgumentsEntry(int slot); |
674 | 656 |
675 // Clear the Instanceof cache (used when a prototype changes). | 657 // Clear the Instanceof cache (used when a prototype changes). |
676 inline void ClearInstanceofCache(); | 658 inline void ClearInstanceofCache(); |
677 | 659 |
678 // For use during bootup. | |
679 void RepairFreeListsAfterBoot(); | |
680 | |
681 // Allocates and fully initializes a String. There are two String | 660 // Allocates and fully initializes a String. There are two String |
682 // encodings: ASCII and two byte. One should choose between the three string | 661 // encodings: ASCII and two byte. One should choose between the three string |
683 // allocation functions based on the encoding of the string buffer used to | 662 // allocation functions based on the encoding of the string buffer used to |
684 // initialized the string. | 663 // initialized the string. |
685 // - ...FromAscii initializes the string from a buffer that is ASCII | 664 // - ...FromAscii initializes the string from a buffer that is ASCII |
686 // encoded (it does not check that the buffer is ASCII encoded) and the | 665 // encoded (it does not check that the buffer is ASCII encoded) and the |
687 // result will be ASCII encoded. | 666 // result will be ASCII encoded. |
688 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 | 667 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 |
689 // encoded. If the characters are all single-byte characters, the | 668 // encoded. If the characters are all single-byte characters, the |
690 // result will be ASCII encoded, otherwise it will converted to two | 669 // result will be ASCII encoded, otherwise it will converted to two |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 // Callback function passed to Heap::Iterate etc. Copies an object if | 1302 // Callback function passed to Heap::Iterate etc. Copies an object if |
1324 // necessary, the object might be promoted to an old space. The caller must | 1303 // necessary, the object might be promoted to an old space. The caller must |
1325 // ensure the precondition that the object is (a) a heap object and (b) in | 1304 // ensure the precondition that the object is (a) a heap object and (b) in |
1326 // the heap's from space. | 1305 // the heap's from space. |
1327 static inline void ScavengePointer(HeapObject** p); | 1306 static inline void ScavengePointer(HeapObject** p); |
1328 static inline void ScavengeObject(HeapObject** p, HeapObject* object); | 1307 static inline void ScavengeObject(HeapObject** p, HeapObject* object); |
1329 | 1308 |
1330 // Commits from space if it is uncommitted. | 1309 // Commits from space if it is uncommitted. |
1331 void EnsureFromSpaceIsCommitted(); | 1310 void EnsureFromSpaceIsCommitted(); |
1332 | 1311 |
1333 // Support for partial snapshots. After calling this we have a linear | 1312 // Support for partial snapshots. After calling this we can allocate a |
1334 // space to write objects in each space. | 1313 // certain number of bytes using only linear allocation (with a |
1335 void ReserveSpace(int *sizes, Address* addresses); | 1314 // LinearAllocationScope and an AlwaysAllocateScope) without using freelists |
| 1315 // or causing a GC. It returns true of space was reserved or false if a GC is |
| 1316 // needed. For paged spaces the space requested must include the space wasted |
| 1317 // at the end of each page when allocating linearly. |
| 1318 void ReserveSpace( |
| 1319 int new_space_size, |
| 1320 int pointer_space_size, |
| 1321 int data_space_size, |
| 1322 int code_space_size, |
| 1323 int map_space_size, |
| 1324 int cell_space_size, |
| 1325 int large_object_size); |
1336 | 1326 |
1337 // | 1327 // |
1338 // Support for the API. | 1328 // Support for the API. |
1339 // | 1329 // |
1340 | 1330 |
1341 bool CreateApiObjects(); | 1331 bool CreateApiObjects(); |
1342 | 1332 |
1343 // Attempt to find the number in a small cache. If we finds it, return | 1333 // Attempt to find the number in a small cache. If we finds it, return |
1344 // the string representation of the number. Otherwise return undefined. | 1334 // the string representation of the number. Otherwise return undefined. |
1345 Object* GetNumberStringCache(Object* number); | 1335 Object* GetNumberStringCache(Object* number); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 // mark or if we've already filled the bottom 1/16th of the to space, | 1482 // mark or if we've already filled the bottom 1/16th of the to space, |
1493 // we try to promote this object. | 1483 // we try to promote this object. |
1494 inline bool ShouldBePromoted(Address old_address, int object_size); | 1484 inline bool ShouldBePromoted(Address old_address, int object_size); |
1495 | 1485 |
1496 int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } | 1486 int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } |
1497 | 1487 |
1498 void ClearJSFunctionResultCaches(); | 1488 void ClearJSFunctionResultCaches(); |
1499 | 1489 |
1500 void ClearNormalizedMapCaches(); | 1490 void ClearNormalizedMapCaches(); |
1501 | 1491 |
| 1492 // Clears the cache of ICs related to this map. |
| 1493 void ClearCacheOnMap(Map* map) { |
| 1494 if (FLAG_cleanup_code_caches_at_gc) { |
| 1495 map->ClearCodeCache(this); |
| 1496 } |
| 1497 } |
| 1498 |
1502 GCTracer* tracer() { return tracer_; } | 1499 GCTracer* tracer() { return tracer_; } |
1503 | 1500 |
1504 // Returns the size of objects residing in non new spaces. | 1501 // Returns the size of objects residing in non new spaces. |
1505 intptr_t PromotedSpaceSizeOfObjects(); | 1502 intptr_t PromotedSpaceSizeOfObjects(); |
1506 | 1503 |
1507 double total_regexp_code_generated() { return total_regexp_code_generated_; } | 1504 double total_regexp_code_generated() { return total_regexp_code_generated_; } |
1508 void IncreaseTotalRegexpCodeGenerated(int size) { | 1505 void IncreaseTotalRegexpCodeGenerated(int size) { |
1509 total_regexp_code_generated_ += size; | 1506 total_regexp_code_generated_ += size; |
1510 } | 1507 } |
1511 | 1508 |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; | 2124 VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; |
2128 | 2125 |
2129 MemoryChunk* chunks_queued_for_free_; | 2126 MemoryChunk* chunks_queued_for_free_; |
2130 | 2127 |
2131 Mutex* relocation_mutex_; | 2128 Mutex* relocation_mutex_; |
2132 | 2129 |
2133 friend class Factory; | 2130 friend class Factory; |
2134 friend class GCTracer; | 2131 friend class GCTracer; |
2135 friend class DisallowAllocationFailure; | 2132 friend class DisallowAllocationFailure; |
2136 friend class AlwaysAllocateScope; | 2133 friend class AlwaysAllocateScope; |
| 2134 friend class LinearAllocationScope; |
2137 friend class Page; | 2135 friend class Page; |
2138 friend class Isolate; | 2136 friend class Isolate; |
2139 friend class MarkCompactCollector; | 2137 friend class MarkCompactCollector; |
2140 friend class MarkCompactMarkingVisitor; | 2138 friend class MarkCompactMarkingVisitor; |
2141 friend class MapCompact; | 2139 friend class MapCompact; |
2142 | 2140 |
2143 DISALLOW_COPY_AND_ASSIGN(Heap); | 2141 DISALLOW_COPY_AND_ASSIGN(Heap); |
2144 }; | 2142 }; |
2145 | 2143 |
2146 | 2144 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 public: | 2191 public: |
2194 inline AlwaysAllocateScope(); | 2192 inline AlwaysAllocateScope(); |
2195 inline ~AlwaysAllocateScope(); | 2193 inline ~AlwaysAllocateScope(); |
2196 | 2194 |
2197 private: | 2195 private: |
2198 // Implicitly disable artificial allocation failures. | 2196 // Implicitly disable artificial allocation failures. |
2199 DisallowAllocationFailure disallow_allocation_failure_; | 2197 DisallowAllocationFailure disallow_allocation_failure_; |
2200 }; | 2198 }; |
2201 | 2199 |
2202 | 2200 |
| 2201 class LinearAllocationScope { |
| 2202 public: |
| 2203 inline LinearAllocationScope(); |
| 2204 inline ~LinearAllocationScope(); |
| 2205 }; |
| 2206 |
| 2207 |
2203 #ifdef DEBUG | 2208 #ifdef DEBUG |
2204 // Visitor class to verify interior pointers in spaces that do not contain | 2209 // Visitor class to verify interior pointers in spaces that do not contain |
2205 // or care about intergenerational references. All heap object pointers have to | 2210 // or care about intergenerational references. All heap object pointers have to |
2206 // point into the heap to a location that has a map pointer at its first word. | 2211 // point into the heap to a location that has a map pointer at its first word. |
2207 // Caveat: Heap::Contains is an approximation because it can return true for | 2212 // Caveat: Heap::Contains is an approximation because it can return true for |
2208 // objects in a heap space but above the allocation pointer. | 2213 // objects in a heap space but above the allocation pointer. |
2209 class VerifyPointersVisitor: public ObjectVisitor { | 2214 class VerifyPointersVisitor: public ObjectVisitor { |
2210 public: | 2215 public: |
2211 inline void VisitPointers(Object** start, Object** end); | 2216 inline void VisitPointers(Object** start, Object** end); |
2212 }; | 2217 }; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2362 | 2367 |
2363 Key keys_[kLength]; | 2368 Key keys_[kLength]; |
2364 int field_offsets_[kLength]; | 2369 int field_offsets_[kLength]; |
2365 | 2370 |
2366 friend class ExternalReference; | 2371 friend class ExternalReference; |
2367 friend class Isolate; | 2372 friend class Isolate; |
2368 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); | 2373 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); |
2369 }; | 2374 }; |
2370 | 2375 |
2371 | 2376 |
2372 // Cache for mapping (map, property name) into descriptor index. | 2377 // Cache for mapping (array, property name) into descriptor index. |
2373 // The cache contains both positive and negative results. | 2378 // The cache contains both positive and negative results. |
2374 // Descriptor index equals kNotFound means the property is absent. | 2379 // Descriptor index equals kNotFound means the property is absent. |
2375 // Cleared at startup and prior to any gc. | 2380 // Cleared at startup and prior to any gc. |
2376 class DescriptorLookupCache { | 2381 class DescriptorLookupCache { |
2377 public: | 2382 public: |
2378 // Lookup descriptor index for (map, name). | 2383 // Lookup descriptor index for (map, name). |
2379 // If absent, kAbsent is returned. | 2384 // If absent, kAbsent is returned. |
2380 int Lookup(Map* source, String* name) { | 2385 int Lookup(DescriptorArray* array, String* name) { |
2381 if (!StringShape(name).IsSymbol()) return kAbsent; | 2386 if (!StringShape(name).IsSymbol()) return kAbsent; |
2382 int index = Hash(source, name); | 2387 int index = Hash(array, name); |
2383 Key& key = keys_[index]; | 2388 Key& key = keys_[index]; |
2384 if ((key.source == source) && (key.name == name)) return results_[index]; | 2389 if ((key.array == array) && (key.name == name)) return results_[index]; |
2385 return kAbsent; | 2390 return kAbsent; |
2386 } | 2391 } |
2387 | 2392 |
2388 // Update an element in the cache. | 2393 // Update an element in the cache. |
2389 void Update(Map* source, String* name, int result) { | 2394 void Update(DescriptorArray* array, String* name, int result) { |
2390 ASSERT(result != kAbsent); | 2395 ASSERT(result != kAbsent); |
2391 if (StringShape(name).IsSymbol()) { | 2396 if (StringShape(name).IsSymbol()) { |
2392 int index = Hash(source, name); | 2397 int index = Hash(array, name); |
2393 Key& key = keys_[index]; | 2398 Key& key = keys_[index]; |
2394 key.source = source; | 2399 key.array = array; |
2395 key.name = name; | 2400 key.name = name; |
2396 results_[index] = result; | 2401 results_[index] = result; |
2397 } | 2402 } |
2398 } | 2403 } |
2399 | 2404 |
2400 // Clear the cache. | 2405 // Clear the cache. |
2401 void Clear(); | 2406 void Clear(); |
2402 | 2407 |
2403 static const int kAbsent = -2; | 2408 static const int kAbsent = -2; |
2404 | 2409 |
2405 private: | 2410 private: |
2406 DescriptorLookupCache() { | 2411 DescriptorLookupCache() { |
2407 for (int i = 0; i < kLength; ++i) { | 2412 for (int i = 0; i < kLength; ++i) { |
2408 keys_[i].source = NULL; | 2413 keys_[i].array = NULL; |
2409 keys_[i].name = NULL; | 2414 keys_[i].name = NULL; |
2410 results_[i] = kAbsent; | 2415 results_[i] = kAbsent; |
2411 } | 2416 } |
2412 } | 2417 } |
2413 | 2418 |
2414 static int Hash(Object* source, String* name) { | 2419 static int Hash(DescriptorArray* array, String* name) { |
2415 // Uses only lower 32 bits if pointers are larger. | 2420 // Uses only lower 32 bits if pointers are larger. |
2416 uint32_t source_hash = | 2421 uint32_t array_hash = |
2417 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(source)) | 2422 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) |
2418 >> kPointerSizeLog2; | 2423 >> kPointerSizeLog2; |
2419 uint32_t name_hash = | 2424 uint32_t name_hash = |
2420 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) | 2425 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) |
2421 >> kPointerSizeLog2; | 2426 >> kPointerSizeLog2; |
2422 return (source_hash ^ name_hash) % kLength; | 2427 return (array_hash ^ name_hash) % kLength; |
2423 } | 2428 } |
2424 | 2429 |
2425 static const int kLength = 64; | 2430 static const int kLength = 64; |
2426 struct Key { | 2431 struct Key { |
2427 Map* source; | 2432 DescriptorArray* array; |
2428 String* name; | 2433 String* name; |
2429 }; | 2434 }; |
2430 | 2435 |
2431 Key keys_[kLength]; | 2436 Key keys_[kLength]; |
2432 int results_[kLength]; | 2437 int results_[kLength]; |
2433 | 2438 |
2434 friend class Isolate; | 2439 friend class Isolate; |
2435 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); | 2440 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); |
2436 }; | 2441 }; |
2437 | 2442 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2793 AssertNoAllocation no_alloc; // i.e. no gc allowed. | 2798 AssertNoAllocation no_alloc; // i.e. no gc allowed. |
2794 | 2799 |
2795 private: | 2800 private: |
2796 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2801 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2797 }; | 2802 }; |
2798 #endif // DEBUG || LIVE_OBJECT_LIST | 2803 #endif // DEBUG || LIVE_OBJECT_LIST |
2799 | 2804 |
2800 } } // namespace v8::internal | 2805 } } // namespace v8::internal |
2801 | 2806 |
2802 #endif // V8_HEAP_H_ | 2807 #endif // V8_HEAP_H_ |
OLD | NEW |