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 2905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2916 // Make sure that an out of memory exception is thrown if the length | 2916 // Make sure that an out of memory exception is thrown if the length |
2917 // of the new cons string is too large. | 2917 // of the new cons string is too large. |
2918 if (length > String::kMaxLength || length < 0) { | 2918 if (length > String::kMaxLength || length < 0) { |
2919 isolate()->context()->mark_out_of_memory(); | 2919 isolate()->context()->mark_out_of_memory(); |
2920 return Failure::OutOfMemoryException(); | 2920 return Failure::OutOfMemoryException(); |
2921 } | 2921 } |
2922 | 2922 |
2923 bool is_ascii_data_in_two_byte_string = false; | 2923 bool is_ascii_data_in_two_byte_string = false; |
2924 if (!is_ascii) { | 2924 if (!is_ascii) { |
2925 // At least one of the strings uses two-byte representation so we | 2925 // At least one of the strings uses two-byte representation so we |
2926 // can't use the fast case code for short ascii strings below, but | 2926 // can't use the fast case code for short ASCII strings below, but |
2927 // we can try to save memory if all chars actually fit in ascii. | 2927 // we can try to save memory if all chars actually fit in ASCII. |
2928 is_ascii_data_in_two_byte_string = | 2928 is_ascii_data_in_two_byte_string = |
2929 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars(); | 2929 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars(); |
2930 if (is_ascii_data_in_two_byte_string) { | 2930 if (is_ascii_data_in_two_byte_string) { |
2931 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); | 2931 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); |
2932 } | 2932 } |
2933 } | 2933 } |
2934 | 2934 |
2935 // If the resulting string is small make a flat string. | 2935 // If the resulting string is small make a flat string. |
2936 if (length < String::kMinNonFlatLength) { | 2936 if (length < String::kMinNonFlatLength) { |
2937 // Note that neither of the two inputs can be a slice because: | 2937 // 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... |
3628 | 3628 |
3629 | 3629 |
3630 void Heap::InitializeJSObjectFromMap(JSObject* obj, | 3630 void Heap::InitializeJSObjectFromMap(JSObject* obj, |
3631 FixedArray* properties, | 3631 FixedArray* properties, |
3632 Map* map) { | 3632 Map* map) { |
3633 obj->set_properties(properties); | 3633 obj->set_properties(properties); |
3634 obj->initialize_elements(); | 3634 obj->initialize_elements(); |
3635 // TODO(1240798): Initialize the object's body using valid initial values | 3635 // TODO(1240798): Initialize the object's body using valid initial values |
3636 // according to the object's initial map. For example, if the map's | 3636 // according to the object's initial map. For example, if the map's |
3637 // instance type is JS_ARRAY_TYPE, the length field should be initialized | 3637 // instance type is JS_ARRAY_TYPE, the length field should be initialized |
3638 // to a number (eg, Smi::FromInt(0)) and the elements initialized to a | 3638 // to a number (e.g. Smi::FromInt(0)) and the elements initialized to a |
3639 // fixed array (eg, Heap::empty_fixed_array()). Currently, the object | 3639 // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object |
3640 // verification code has to cope with (temporarily) invalid objects. See | 3640 // verification code has to cope with (temporarily) invalid objects. See |
3641 // for example, JSArray::JSArrayVerify). | 3641 // for example, JSArray::JSArrayVerify). |
3642 Object* filler; | 3642 Object* filler; |
3643 // We cannot always fill with one_pointer_filler_map because objects | 3643 // We cannot always fill with one_pointer_filler_map because objects |
3644 // created from API functions expect their internal fields to be initialized | 3644 // created from API functions expect their internal fields to be initialized |
3645 // with undefined_value. | 3645 // with undefined_value. |
3646 // Pre-allocated fields need to be initialized with undefined_value as well | 3646 // Pre-allocated fields need to be initialized with undefined_value as well |
3647 // so that object accesses before the constructor completes (e.g. in the | 3647 // so that object accesses before the constructor completes (e.g. in the |
3648 // debugger) will not cause a crash. | 3648 // debugger) will not cause a crash. |
3649 if (map->constructor()->IsJSFunction() && | 3649 if (map->constructor()->IsJSFunction() && |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4096 } | 4096 } |
4097 } | 4097 } |
4098 | 4098 |
4099 | 4099 |
4100 MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, | 4100 MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, |
4101 int chars, | 4101 int chars, |
4102 uint32_t hash_field) { | 4102 uint32_t hash_field) { |
4103 ASSERT(chars >= 0); | 4103 ASSERT(chars >= 0); |
4104 // Ensure the chars matches the number of characters in the buffer. | 4104 // Ensure the chars matches the number of characters in the buffer. |
4105 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); | 4105 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); |
4106 // Determine whether the string is ascii. | 4106 // Determine whether the string is ASCII. |
4107 bool is_ascii = true; | 4107 bool is_ascii = true; |
4108 while (buffer->has_more()) { | 4108 while (buffer->has_more()) { |
4109 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) { | 4109 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) { |
4110 is_ascii = false; | 4110 is_ascii = false; |
4111 break; | 4111 break; |
4112 } | 4112 } |
4113 } | 4113 } |
4114 buffer->Rewind(); | 4114 buffer->Rewind(); |
4115 | 4115 |
4116 // Compute map and object size. | 4116 // Compute map and object size. |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5589 bool Heap::SetUp(bool create_heap_objects) { | 5589 bool Heap::SetUp(bool create_heap_objects) { |
5590 #ifdef DEBUG | 5590 #ifdef DEBUG |
5591 allocation_timeout_ = FLAG_gc_interval; | 5591 allocation_timeout_ = FLAG_gc_interval; |
5592 debug_utils_ = new HeapDebugUtils(this); | 5592 debug_utils_ = new HeapDebugUtils(this); |
5593 #endif | 5593 #endif |
5594 | 5594 |
5595 // Initialize heap spaces and initial maps and objects. Whenever something | 5595 // Initialize heap spaces and initial maps and objects. Whenever something |
5596 // goes wrong, just return false. The caller should check the results and | 5596 // goes wrong, just return false. The caller should check the results and |
5597 // call Heap::TearDown() to release allocated memory. | 5597 // call Heap::TearDown() to release allocated memory. |
5598 // | 5598 // |
5599 // If the heap is not yet configured (eg, through the API), configure it. | 5599 // If the heap is not yet configured (e.g. through the API), configure it. |
5600 // Configuration is based on the flags new-space-size (really the semispace | 5600 // Configuration is based on the flags new-space-size (really the semispace |
5601 // size) and old-space-size if set or the initial values of semispace_size_ | 5601 // size) and old-space-size if set or the initial values of semispace_size_ |
5602 // and old_generation_size_ otherwise. | 5602 // and old_generation_size_ otherwise. |
5603 if (!configured_) { | 5603 if (!configured_) { |
5604 if (!ConfigureHeapDefault()) return false; | 5604 if (!ConfigureHeapDefault()) return false; |
5605 } | 5605 } |
5606 | 5606 |
5607 gc_initializer_mutex->Lock(); | 5607 gc_initializer_mutex->Lock(); |
5608 static bool initialized_gc = false; | 5608 static bool initialized_gc = false; |
5609 if (!initialized_gc) { | 5609 if (!initialized_gc) { |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6654 isolate_->heap()->store_buffer()->Compact(); | 6654 isolate_->heap()->store_buffer()->Compact(); |
6655 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6655 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6656 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6656 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6657 next = chunk->next_chunk(); | 6657 next = chunk->next_chunk(); |
6658 isolate_->memory_allocator()->Free(chunk); | 6658 isolate_->memory_allocator()->Free(chunk); |
6659 } | 6659 } |
6660 chunks_queued_for_free_ = NULL; | 6660 chunks_queued_for_free_ = NULL; |
6661 } | 6661 } |
6662 | 6662 |
6663 } } // namespace v8::internal | 6663 } } // namespace v8::internal |
OLD | NEW |