OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 object->RawFastPropertyAtPut(index, *value); | 2008 object->RawFastPropertyAtPut(index, *value); |
2009 } | 2009 } |
2010 } | 2010 } |
2011 object->synchronized_set_map(*new_map); | 2011 object->synchronized_set_map(*new_map); |
2012 return; | 2012 return; |
2013 } | 2013 } |
2014 | 2014 |
2015 DCHECK(number_of_fields == old_number_of_fields + 1); | 2015 DCHECK(number_of_fields == old_number_of_fields + 1); |
2016 // This migration is a transition from a map that has run out of property | 2016 // This migration is a transition from a map that has run out of property |
2017 // space. Therefore it could be done by extending the backing store. | 2017 // space. Therefore it could be done by extending the backing store. |
| 2018 int grow_by = external - object->properties()->length(); |
2018 Handle<FixedArray> old_storage = handle(object->properties(), isolate); | 2019 Handle<FixedArray> old_storage = handle(object->properties(), isolate); |
2019 Handle<FixedArray> new_storage = | 2020 Handle<FixedArray> new_storage = |
2020 FixedArray::CopySize(old_storage, external); | 2021 isolate->factory()->CopyFixedArrayAndGrow(old_storage, grow_by); |
2021 | 2022 |
2022 // Properly initialize newly added property. | 2023 // Properly initialize newly added property. |
2023 Handle<Object> value; | 2024 Handle<Object> value; |
2024 if (details.representation().IsDouble()) { | 2025 if (details.representation().IsDouble()) { |
2025 value = isolate->factory()->NewHeapNumber(0, MUTABLE); | 2026 value = isolate->factory()->NewHeapNumber(0, MUTABLE); |
2026 } else { | 2027 } else { |
2027 value = isolate->factory()->uninitialized_value(); | 2028 value = isolate->factory()->uninitialized_value(); |
2028 } | 2029 } |
2029 DCHECK(details.type() == DATA); | 2030 DCHECK(details.type() == DATA); |
2030 int target_index = details.field_index() - inobject; | 2031 int target_index = details.field_index() - inobject; |
(...skipping 5458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7489 // elements, reuse the space for the first of them. | 7490 // elements, reuse the space for the first of them. |
7490 if (deleted_index >= 0) { | 7491 if (deleted_index >= 0) { |
7491 cache->set(deleted_index + kCodeCacheEntryNameOffset, *name); | 7492 cache->set(deleted_index + kCodeCacheEntryNameOffset, *name); |
7492 cache->set(deleted_index + kCodeCacheEntryCodeOffset, *code); | 7493 cache->set(deleted_index + kCodeCacheEntryCodeOffset, *code); |
7493 return; | 7494 return; |
7494 } | 7495 } |
7495 } | 7496 } |
7496 | 7497 |
7497 // Extend the code cache with some new entries (at least one). Must be a | 7498 // Extend the code cache with some new entries (at least one). Must be a |
7498 // multiple of the entry size. | 7499 // multiple of the entry size. |
7499 int new_length = length + ((length >> 1)) + kCodeCacheEntrySize; | 7500 Isolate* isolate = cache->GetIsolate(); |
| 7501 int new_length = length + (length >> 1) + kCodeCacheEntrySize; |
7500 new_length = new_length - new_length % kCodeCacheEntrySize; | 7502 new_length = new_length - new_length % kCodeCacheEntrySize; |
7501 DCHECK((new_length % kCodeCacheEntrySize) == 0); | 7503 DCHECK((new_length % kCodeCacheEntrySize) == 0); |
7502 cache = FixedArray::CopySize(cache, new_length); | 7504 cache = isolate->factory()->CopyFixedArrayAndGrow(cache, new_length - length); |
7503 | 7505 |
7504 // Add the (name, code) pair to the new cache. | 7506 // Add the (name, code) pair to the new cache. |
7505 cache->set(length + kCodeCacheEntryNameOffset, *name); | 7507 cache->set(length + kCodeCacheEntryNameOffset, *name); |
7506 cache->set(length + kCodeCacheEntryCodeOffset, *code); | 7508 cache->set(length + kCodeCacheEntryCodeOffset, *code); |
7507 code_cache->set_default_cache(*cache); | 7509 code_cache->set_default_cache(*cache); |
7508 } | 7510 } |
7509 | 7511 |
7510 | 7512 |
7511 void CodeCache::UpdateNormalTypeCache( | 7513 void CodeCache::UpdateNormalTypeCache( |
7512 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code) { | 7514 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code) { |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7885 if (i == first->length()) { | 7887 if (i == first->length()) { |
7886 result->set(pos++, current); | 7888 result->set(pos++, current); |
7887 } | 7889 } |
7888 } | 7890 } |
7889 | 7891 |
7890 result->Shrink(pos); | 7892 result->Shrink(pos); |
7891 return result; | 7893 return result; |
7892 } | 7894 } |
7893 | 7895 |
7894 | 7896 |
7895 Handle<FixedArray> FixedArray::CopySize( | |
7896 Handle<FixedArray> array, int new_length, PretenureFlag pretenure) { | |
7897 Isolate* isolate = array->GetIsolate(); | |
7898 if (new_length == 0) return isolate->factory()->empty_fixed_array(); | |
7899 Handle<FixedArray> result = | |
7900 isolate->factory()->NewFixedArray(new_length, pretenure); | |
7901 // Copy the content | |
7902 DisallowHeapAllocation no_gc; | |
7903 int len = array->length(); | |
7904 if (new_length < len) len = new_length; | |
7905 // We are taking the map from the old fixed array so the map is sure to | |
7906 // be an immortal immutable object. | |
7907 result->set_map_no_write_barrier(array->map()); | |
7908 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); | |
7909 for (int i = 0; i < len; i++) { | |
7910 result->set(i, array->get(i), mode); | |
7911 } | |
7912 return result; | |
7913 } | |
7914 | |
7915 | |
7916 void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) { | 7897 void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) { |
7917 DisallowHeapAllocation no_gc; | 7898 DisallowHeapAllocation no_gc; |
7918 WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc); | 7899 WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc); |
7919 for (int index = 0; index < len; index++) { | 7900 for (int index = 0; index < len; index++) { |
7920 dest->set(dest_pos+index, get(pos+index), mode); | 7901 dest->set(dest_pos+index, get(pos+index), mode); |
7921 } | 7902 } |
7922 } | 7903 } |
7923 | 7904 |
7924 | 7905 |
7925 #ifdef DEBUG | 7906 #ifdef DEBUG |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8090 array->Set(length + 1, *obj2); | 8071 array->Set(length + 1, *obj2); |
8091 array->SetLength(length + 2); | 8072 array->SetLength(length + 2); |
8092 return array; | 8073 return array; |
8093 } | 8074 } |
8094 | 8075 |
8095 | 8076 |
8096 Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) { | 8077 Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) { |
8097 int capacity = array->length(); | 8078 int capacity = array->length(); |
8098 bool empty = (capacity == 0); | 8079 bool empty = (capacity == 0); |
8099 if (capacity < kFirstIndex + length) { | 8080 if (capacity < kFirstIndex + length) { |
8100 capacity = kFirstIndex + length; | 8081 Isolate* isolate = array->GetIsolate(); |
8101 capacity = capacity + Max(capacity / 2, 2); | 8082 int new_capacity = kFirstIndex + length; |
8102 array = Handle<ArrayList>::cast(FixedArray::CopySize(array, capacity)); | 8083 new_capacity = new_capacity + Max(new_capacity / 2, 2); |
| 8084 int grow_by = new_capacity - capacity; |
| 8085 array = Handle<ArrayList>::cast( |
| 8086 isolate->factory()->CopyFixedArrayAndGrow(array, grow_by)); |
8103 if (empty) array->SetLength(0); | 8087 if (empty) array->SetLength(0); |
8104 } | 8088 } |
8105 return array; | 8089 return array; |
8106 } | 8090 } |
8107 | 8091 |
8108 | 8092 |
8109 Handle<DescriptorArray> DescriptorArray::Allocate(Isolate* isolate, | 8093 Handle<DescriptorArray> DescriptorArray::Allocate(Isolate* isolate, |
8110 int number_of_descriptors, | 8094 int number_of_descriptors, |
8111 int slack) { | 8095 int slack) { |
8112 DCHECK(0 <= number_of_descriptors); | 8096 DCHECK(0 <= number_of_descriptors); |
(...skipping 3809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11922 | 11906 |
11923 entries->ExtendGroup(group); | 11907 entries->ExtendGroup(group); |
11924 entries->set_object_at(end, *object); | 11908 entries->set_object_at(end, *object); |
11925 entries->set_number_of_entries(group, end + 1 - start); | 11909 entries->set_number_of_entries(group, end + 1 - start); |
11926 return entries; | 11910 return entries; |
11927 } | 11911 } |
11928 | 11912 |
11929 | 11913 |
11930 Handle<DependentCode> DependentCode::EnsureSpace( | 11914 Handle<DependentCode> DependentCode::EnsureSpace( |
11931 Handle<DependentCode> entries) { | 11915 Handle<DependentCode> entries) { |
| 11916 Isolate* isolate = entries->GetIsolate(); |
11932 if (entries->length() == 0) { | 11917 if (entries->length() == 0) { |
11933 entries = Handle<DependentCode>::cast( | 11918 entries = Handle<DependentCode>::cast( |
11934 FixedArray::CopySize(entries, kCodesStartIndex + 1, TENURED)); | 11919 isolate->factory()->NewFixedArray(kCodesStartIndex + 1, TENURED)); |
11935 for (int g = 0; g < kGroupCount; g++) { | 11920 for (int g = 0; g < kGroupCount; g++) { |
11936 entries->set_number_of_entries(static_cast<DependencyGroup>(g), 0); | 11921 entries->set_number_of_entries(static_cast<DependencyGroup>(g), 0); |
11937 } | 11922 } |
11938 return entries; | 11923 return entries; |
11939 } | 11924 } |
11940 if (entries->Compact()) return entries; | 11925 if (entries->Compact()) return entries; |
11941 GroupStartIndexes starts(*entries); | 11926 GroupStartIndexes starts(*entries); |
11942 int capacity = | 11927 int capacity = |
11943 kCodesStartIndex + DependentCode::Grow(starts.number_of_entries()); | 11928 kCodesStartIndex + DependentCode::Grow(starts.number_of_entries()); |
| 11929 int grow_by = capacity - entries->length(); |
11944 return Handle<DependentCode>::cast( | 11930 return Handle<DependentCode>::cast( |
11945 FixedArray::CopySize(entries, capacity, TENURED)); | 11931 isolate->factory()->CopyFixedArrayAndGrow(entries, grow_by, TENURED)); |
11946 } | 11932 } |
11947 | 11933 |
11948 | 11934 |
11949 bool DependentCode::Compact() { | 11935 bool DependentCode::Compact() { |
11950 GroupStartIndexes starts(this); | 11936 GroupStartIndexes starts(this); |
11951 int n = 0; | 11937 int n = 0; |
11952 for (int g = 0; g < kGroupCount; g++) { | 11938 for (int g = 0; g < kGroupCount; g++) { |
11953 int start = starts.at(g); | 11939 int start = starts.at(g); |
11954 int end = starts.at(g + 1); | 11940 int end = starts.at(g + 1); |
11955 int count = 0; | 11941 int count = 0; |
(...skipping 3922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15878 if (cell->value() != *new_value) { | 15864 if (cell->value() != *new_value) { |
15879 cell->set_value(*new_value); | 15865 cell->set_value(*new_value); |
15880 Isolate* isolate = cell->GetIsolate(); | 15866 Isolate* isolate = cell->GetIsolate(); |
15881 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 15867 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
15882 isolate, DependentCode::kPropertyCellChangedGroup); | 15868 isolate, DependentCode::kPropertyCellChangedGroup); |
15883 } | 15869 } |
15884 } | 15870 } |
15885 | 15871 |
15886 } // namespace internal | 15872 } // namespace internal |
15887 } // namespace v8 | 15873 } // namespace v8 |
OLD | NEW |