OLD | NEW |
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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 int map_space_size, | 575 int map_space_size, |
576 int cell_space_size, | 576 int cell_space_size, |
577 int large_object_size) { | 577 int large_object_size) { |
578 NewSpace* new_space = Heap::new_space(); | 578 NewSpace* new_space = Heap::new_space(); |
579 PagedSpace* old_pointer_space = Heap::old_pointer_space(); | 579 PagedSpace* old_pointer_space = Heap::old_pointer_space(); |
580 PagedSpace* old_data_space = Heap::old_data_space(); | 580 PagedSpace* old_data_space = Heap::old_data_space(); |
581 PagedSpace* code_space = Heap::code_space(); | 581 PagedSpace* code_space = Heap::code_space(); |
582 PagedSpace* map_space = Heap::map_space(); | 582 PagedSpace* map_space = Heap::map_space(); |
583 PagedSpace* cell_space = Heap::cell_space(); | 583 PagedSpace* cell_space = Heap::cell_space(); |
584 LargeObjectSpace* lo_space = Heap::lo_space(); | 584 LargeObjectSpace* lo_space = Heap::lo_space(); |
| 585 bool one_old_space_gc_has_been_performed = false; |
585 bool gc_performed = true; | 586 bool gc_performed = true; |
| 587 bool old_space_gc_performed; |
586 while (gc_performed) { | 588 while (gc_performed) { |
| 589 old_space_gc_performed = false; |
587 gc_performed = false; | 590 gc_performed = false; |
588 if (!new_space->ReserveSpace(new_space_size)) { | 591 if (!new_space->ReserveSpace(new_space_size)) { |
589 Heap::CollectGarbage(NEW_SPACE); | 592 Heap::CollectGarbage(NEW_SPACE); |
590 gc_performed = true; | 593 gc_performed = true; |
591 } | 594 } |
592 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { | 595 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { |
593 Heap::CollectGarbage(OLD_POINTER_SPACE); | 596 Heap::CollectGarbage(OLD_POINTER_SPACE); |
594 gc_performed = true; | 597 gc_performed = true; |
| 598 old_space_gc_performed = true; |
595 } | 599 } |
596 if (!(old_data_space->ReserveSpace(data_space_size))) { | 600 if (!(old_data_space->ReserveSpace(data_space_size))) { |
597 Heap::CollectGarbage(OLD_DATA_SPACE); | 601 Heap::CollectGarbage(OLD_DATA_SPACE); |
598 gc_performed = true; | 602 gc_performed = true; |
| 603 old_space_gc_performed = true; |
599 } | 604 } |
600 if (!(code_space->ReserveSpace(code_space_size))) { | 605 if (!(code_space->ReserveSpace(code_space_size))) { |
601 Heap::CollectGarbage(CODE_SPACE); | 606 Heap::CollectGarbage(CODE_SPACE); |
602 gc_performed = true; | 607 gc_performed = true; |
| 608 old_space_gc_performed = true; |
603 } | 609 } |
604 if (!(map_space->ReserveSpace(map_space_size))) { | 610 if (!(map_space->ReserveSpace(map_space_size))) { |
605 Heap::CollectGarbage(MAP_SPACE); | 611 Heap::CollectGarbage(MAP_SPACE); |
606 gc_performed = true; | 612 gc_performed = true; |
| 613 old_space_gc_performed = true; |
607 } | 614 } |
608 if (!(cell_space->ReserveSpace(cell_space_size))) { | 615 if (!(cell_space->ReserveSpace(cell_space_size))) { |
609 Heap::CollectGarbage(CELL_SPACE); | 616 Heap::CollectGarbage(CELL_SPACE); |
610 gc_performed = true; | 617 gc_performed = true; |
| 618 old_space_gc_performed = true; |
611 } | 619 } |
612 // We add a slack-factor of 2 in order to have space for a series of | 620 // We add a slack-factor of 2 in order to have space for a series of |
613 // large-object allocations that are only just larger than the page size. | 621 // large-object allocations that are only just larger than the page size. |
614 large_object_size *= 2; | 622 large_object_size *= 2; |
615 // The ReserveSpace method on the large object space checks how much | 623 // The ReserveSpace method on the large object space checks how much |
616 // we can expand the old generation. This includes expansion caused by | 624 // we can expand the old generation. This includes expansion caused by |
617 // allocation in the other spaces. | 625 // allocation in the other spaces. |
618 large_object_size += cell_space_size + map_space_size + code_space_size + | 626 large_object_size += cell_space_size + map_space_size + code_space_size + |
619 data_space_size + pointer_space_size; | 627 data_space_size + pointer_space_size; |
620 if (!(lo_space->ReserveSpace(large_object_size))) { | 628 |
| 629 // If we already did one GC in order to make space in old space, there is |
| 630 // no sense in doing another one. We will attempt to force through the |
| 631 // large object space allocation, which comes directly from the OS, |
| 632 // regardless of any soft limit. |
| 633 if (!one_old_space_gc_has_been_performed && |
| 634 !(lo_space->ReserveSpace(large_object_size))) { |
621 Heap::CollectGarbage(LO_SPACE); | 635 Heap::CollectGarbage(LO_SPACE); |
622 gc_performed = true; | 636 gc_performed = true; |
623 } | 637 } |
| 638 if (old_space_gc_performed) one_old_space_gc_has_been_performed = true; |
624 } | 639 } |
625 } | 640 } |
626 | 641 |
627 | 642 |
628 void Heap::EnsureFromSpaceIsCommitted() { | 643 void Heap::EnsureFromSpaceIsCommitted() { |
629 if (new_space_.CommitFromSpaceIfNeeded()) return; | 644 if (new_space_.CommitFromSpaceIfNeeded()) return; |
630 | 645 |
631 // Committing memory to from space failed. | 646 // Committing memory to from space failed. |
632 // Try shrinking and try again. | 647 // Try shrinking and try again. |
633 Shrink(); | 648 Shrink(); |
(...skipping 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2881 // Make sure that an out of memory exception is thrown if the length | 2896 // Make sure that an out of memory exception is thrown if the length |
2882 // of the new cons string is too large. | 2897 // of the new cons string is too large. |
2883 if (length > String::kMaxLength || length < 0) { | 2898 if (length > String::kMaxLength || length < 0) { |
2884 isolate()->context()->mark_out_of_memory(); | 2899 isolate()->context()->mark_out_of_memory(); |
2885 return Failure::OutOfMemoryException(); | 2900 return Failure::OutOfMemoryException(); |
2886 } | 2901 } |
2887 | 2902 |
2888 bool is_ascii_data_in_two_byte_string = false; | 2903 bool is_ascii_data_in_two_byte_string = false; |
2889 if (!is_ascii) { | 2904 if (!is_ascii) { |
2890 // At least one of the strings uses two-byte representation so we | 2905 // At least one of the strings uses two-byte representation so we |
2891 // can't use the fast case code for short ascii strings below, but | 2906 // can't use the fast case code for short ASCII strings below, but |
2892 // we can try to save memory if all chars actually fit in ascii. | 2907 // we can try to save memory if all chars actually fit in ASCII. |
2893 is_ascii_data_in_two_byte_string = | 2908 is_ascii_data_in_two_byte_string = |
2894 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars(); | 2909 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars(); |
2895 if (is_ascii_data_in_two_byte_string) { | 2910 if (is_ascii_data_in_two_byte_string) { |
2896 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); | 2911 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); |
2897 } | 2912 } |
2898 } | 2913 } |
2899 | 2914 |
2900 // If the resulting string is small make a flat string. | 2915 // If the resulting string is small make a flat string. |
2901 if (length < String::kMinNonFlatLength) { | 2916 if (length < String::kMinNonFlatLength) { |
2902 // Note that neither of the two inputs can be a slice because: | 2917 // Note that neither of the two inputs can be a slice because: |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3593 | 3608 |
3594 | 3609 |
3595 void Heap::InitializeJSObjectFromMap(JSObject* obj, | 3610 void Heap::InitializeJSObjectFromMap(JSObject* obj, |
3596 FixedArray* properties, | 3611 FixedArray* properties, |
3597 Map* map) { | 3612 Map* map) { |
3598 obj->set_properties(properties); | 3613 obj->set_properties(properties); |
3599 obj->initialize_elements(); | 3614 obj->initialize_elements(); |
3600 // TODO(1240798): Initialize the object's body using valid initial values | 3615 // TODO(1240798): Initialize the object's body using valid initial values |
3601 // according to the object's initial map. For example, if the map's | 3616 // according to the object's initial map. For example, if the map's |
3602 // instance type is JS_ARRAY_TYPE, the length field should be initialized | 3617 // instance type is JS_ARRAY_TYPE, the length field should be initialized |
3603 // to a number (eg, Smi::FromInt(0)) and the elements initialized to a | 3618 // to a number (e.g. Smi::FromInt(0)) and the elements initialized to a |
3604 // fixed array (eg, Heap::empty_fixed_array()). Currently, the object | 3619 // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object |
3605 // verification code has to cope with (temporarily) invalid objects. See | 3620 // verification code has to cope with (temporarily) invalid objects. See |
3606 // for example, JSArray::JSArrayVerify). | 3621 // for example, JSArray::JSArrayVerify). |
3607 Object* filler; | 3622 Object* filler; |
3608 // We cannot always fill with one_pointer_filler_map because objects | 3623 // We cannot always fill with one_pointer_filler_map because objects |
3609 // created from API functions expect their internal fields to be initialized | 3624 // created from API functions expect their internal fields to be initialized |
3610 // with undefined_value. | 3625 // with undefined_value. |
3611 // Pre-allocated fields need to be initialized with undefined_value as well | 3626 // Pre-allocated fields need to be initialized with undefined_value as well |
3612 // so that object accesses before the constructor completes (e.g. in the | 3627 // so that object accesses before the constructor completes (e.g. in the |
3613 // debugger) will not cause a crash. | 3628 // debugger) will not cause a crash. |
3614 if (map->constructor()->IsJSFunction() && | 3629 if (map->constructor()->IsJSFunction() && |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4061 } | 4076 } |
4062 } | 4077 } |
4063 | 4078 |
4064 | 4079 |
4065 MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, | 4080 MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, |
4066 int chars, | 4081 int chars, |
4067 uint32_t hash_field) { | 4082 uint32_t hash_field) { |
4068 ASSERT(chars >= 0); | 4083 ASSERT(chars >= 0); |
4069 // Ensure the chars matches the number of characters in the buffer. | 4084 // Ensure the chars matches the number of characters in the buffer. |
4070 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); | 4085 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); |
4071 // Determine whether the string is ascii. | 4086 // Determine whether the string is ASCII. |
4072 bool is_ascii = true; | 4087 bool is_ascii = true; |
4073 while (buffer->has_more()) { | 4088 while (buffer->has_more()) { |
4074 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) { | 4089 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) { |
4075 is_ascii = false; | 4090 is_ascii = false; |
4076 break; | 4091 break; |
4077 } | 4092 } |
4078 } | 4093 } |
4079 buffer->Rewind(); | 4094 buffer->Rewind(); |
4080 | 4095 |
4081 // Compute map and object size. | 4096 // Compute map and object size. |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5554 bool Heap::Setup(bool create_heap_objects) { | 5569 bool Heap::Setup(bool create_heap_objects) { |
5555 #ifdef DEBUG | 5570 #ifdef DEBUG |
5556 allocation_timeout_ = FLAG_gc_interval; | 5571 allocation_timeout_ = FLAG_gc_interval; |
5557 debug_utils_ = new HeapDebugUtils(this); | 5572 debug_utils_ = new HeapDebugUtils(this); |
5558 #endif | 5573 #endif |
5559 | 5574 |
5560 // Initialize heap spaces and initial maps and objects. Whenever something | 5575 // Initialize heap spaces and initial maps and objects. Whenever something |
5561 // goes wrong, just return false. The caller should check the results and | 5576 // goes wrong, just return false. The caller should check the results and |
5562 // call Heap::TearDown() to release allocated memory. | 5577 // call Heap::TearDown() to release allocated memory. |
5563 // | 5578 // |
5564 // If the heap is not yet configured (eg, through the API), configure it. | 5579 // If the heap is not yet configured (e.g. through the API), configure it. |
5565 // Configuration is based on the flags new-space-size (really the semispace | 5580 // Configuration is based on the flags new-space-size (really the semispace |
5566 // size) and old-space-size if set or the initial values of semispace_size_ | 5581 // size) and old-space-size if set or the initial values of semispace_size_ |
5567 // and old_generation_size_ otherwise. | 5582 // and old_generation_size_ otherwise. |
5568 if (!configured_) { | 5583 if (!configured_) { |
5569 if (!ConfigureHeapDefault()) return false; | 5584 if (!ConfigureHeapDefault()) return false; |
5570 } | 5585 } |
5571 | 5586 |
5572 gc_initializer_mutex->Lock(); | 5587 gc_initializer_mutex->Lock(); |
5573 static bool initialized_gc = false; | 5588 static bool initialized_gc = false; |
5574 if (!initialized_gc) { | 5589 if (!initialized_gc) { |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6618 } | 6633 } |
6619 isolate_->heap()->store_buffer()->Compact(); | 6634 isolate_->heap()->store_buffer()->Compact(); |
6620 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6635 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6621 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6636 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6622 next = chunk->next_chunk(); | 6637 next = chunk->next_chunk(); |
6623 isolate_->memory_allocator()->Free(chunk); | 6638 isolate_->memory_allocator()->Free(chunk); |
6624 } | 6639 } |
6625 chunks_queued_for_free_ = NULL; | 6640 chunks_queued_for_free_ = NULL; |
6626 } | 6641 } |
6627 | 6642 |
| 6643 |
| 6644 void AboutToGoWrong() { |
| 6645 printf("About to go wrong\n"); |
| 6646 } |
| 6647 |
6628 } } // namespace v8::internal | 6648 } } // namespace v8::internal |
OLD | NEW |