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

Side by Side Diff: src/objects.cc

Issue 893073006: Add map-based read barrier to WeakCell Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
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 <sstream> 5 #include <sstream>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/allocation-site-scopes.h" 10 #include "src/allocation-site-scopes.h"
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 HeapStringAllocator allocator; 1392 HeapStringAllocator allocator;
1393 StringStream accumulator(&allocator); 1393 StringStream accumulator(&allocator);
1394 PropertyCell::cast(this)->value()->ShortPrint(&accumulator); 1394 PropertyCell::cast(this)->value()->ShortPrint(&accumulator);
1395 os << accumulator.ToCString().get(); 1395 os << accumulator.ToCString().get();
1396 break; 1396 break;
1397 } 1397 }
1398 case WEAK_CELL_TYPE: { 1398 case WEAK_CELL_TYPE: {
1399 os << "WeakCell for "; 1399 os << "WeakCell for ";
1400 HeapStringAllocator allocator; 1400 HeapStringAllocator allocator;
1401 StringStream accumulator(&allocator); 1401 StringStream accumulator(&allocator);
1402 WeakCell::cast(this)->value()->ShortPrint(&accumulator); 1402 WeakCell::cast(this)->value(heap)->ShortPrint(&accumulator);
1403 os << accumulator.ToCString().get(); 1403 os << accumulator.ToCString().get();
1404 break; 1404 break;
1405 } 1405 }
1406 default: 1406 default:
1407 os << "<Other heap object (" << map()->instance_type() << ")>"; 1407 os << "<Other heap object (" << map()->instance_type() << ")>";
1408 break; 1408 break;
1409 } 1409 }
1410 } 1410 }
1411 1411
1412 1412
(...skipping 6632 matching lines...) Expand 10 before | Expand all | Expand 10 after
8045 Handle<WeakFixedArray> WeakFixedArray::Add( 8045 Handle<WeakFixedArray> WeakFixedArray::Add(
8046 Handle<Object> maybe_array, Handle<HeapObject> value, 8046 Handle<Object> maybe_array, Handle<HeapObject> value,
8047 SearchForDuplicates search_for_duplicates) { 8047 SearchForDuplicates search_for_duplicates) {
8048 Handle<WeakFixedArray> array = 8048 Handle<WeakFixedArray> array =
8049 (maybe_array.is_null() || !maybe_array->IsWeakFixedArray()) 8049 (maybe_array.is_null() || !maybe_array->IsWeakFixedArray())
8050 ? Allocate(value->GetIsolate(), 1, Handle<WeakFixedArray>::null()) 8050 ? Allocate(value->GetIsolate(), 1, Handle<WeakFixedArray>::null())
8051 : Handle<WeakFixedArray>::cast(maybe_array); 8051 : Handle<WeakFixedArray>::cast(maybe_array);
8052 8052
8053 if (search_for_duplicates == kAddIfNotFound) { 8053 if (search_for_duplicates == kAddIfNotFound) {
8054 for (int i = 0; i < array->Length(); ++i) { 8054 for (int i = 0; i < array->Length(); ++i) {
8055 if (array->Get(i) == *value) return array; 8055 if (array->EqualAt(i, *value)) return array;
8056 } 8056 }
8057 } else { 8057 } else {
8058 #ifdef DEBUG 8058 #ifdef DEBUG
8059 for (int i = 0; i < array->Length(); ++i) { 8059 for (int i = 0; i < array->Length(); ++i) {
8060 DCHECK_NE(*value, array->Get(i)); 8060 DCHECK(!array->EqualAt(i, *value));
8061 } 8061 }
8062 #endif 8062 #endif
8063 } 8063 }
8064 8064
8065 // Try to store the new entry if there's room. Optimize for consecutive 8065 // Try to store the new entry if there's room. Optimize for consecutive
8066 // accesses. 8066 // accesses.
8067 int first_index = array->last_used_index(); 8067 int first_index = array->last_used_index();
8068 for (int i = first_index;;) { 8068 for (int i = first_index;;) {
8069 if (array->IsEmptySlot((i))) { 8069 if (array->IsEmptySlot((i))) {
8070 WeakFixedArray::Set(array, i, value); 8070 WeakFixedArray::Set(array, i, value);
(...skipping 15 matching lines...) Expand all
8086 } 8086 }
8087 WeakFixedArray::Set(new_array, array->Length(), value); 8087 WeakFixedArray::Set(new_array, array->Length(), value);
8088 return new_array; 8088 return new_array;
8089 } 8089 }
8090 8090
8091 8091
8092 void WeakFixedArray::Remove(Handle<HeapObject> value) { 8092 void WeakFixedArray::Remove(Handle<HeapObject> value) {
8093 // Optimize for the most recently added element to be removed again. 8093 // Optimize for the most recently added element to be removed again.
8094 int first_index = last_used_index(); 8094 int first_index = last_used_index();
8095 for (int i = first_index;;) { 8095 for (int i = first_index;;) {
8096 if (Get(i) == *value) { 8096 if (EqualAt(i, *value)) {
8097 clear(i); 8097 clear(i);
8098 // Users of WeakFixedArray should make sure that there are no duplicates, 8098 // Users of WeakFixedArray should make sure that there are no duplicates,
8099 // they can use Add(..., kAddIfNotFound) if necessary. 8099 // they can use Add(..., kAddIfNotFound) if necessary.
8100 return; 8100 return;
8101 } 8101 }
8102 i = (i + 1) % Length(); 8102 i = (i + 1) % Length();
8103 if (i == first_index) break; 8103 if (i == first_index) break;
8104 } 8104 }
8105 } 8105 }
8106 8106
(...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after
10149 return result; 10149 return result;
10150 } 10150 }
10151 10151
10152 10152
10153 Handle<JSObject> Script::GetWrapper(Handle<Script> script) { 10153 Handle<JSObject> Script::GetWrapper(Handle<Script> script) {
10154 Isolate* isolate = script->GetIsolate(); 10154 Isolate* isolate = script->GetIsolate();
10155 if (!script->wrapper()->IsUndefined()) { 10155 if (!script->wrapper()->IsUndefined()) {
10156 Handle<WeakCell> cell(WeakCell::cast(script->wrapper())); 10156 Handle<WeakCell> cell(WeakCell::cast(script->wrapper()));
10157 if (!cell->cleared()) { 10157 if (!cell->cleared()) {
10158 // Return a handle for the existing script wrapper from the cache. 10158 // Return a handle for the existing script wrapper from the cache.
10159 return handle(JSObject::cast(cell->value())); 10159 return handle(JSObject::cast(cell->value(isolate->heap())));
10160 } 10160 }
10161 // If we found an empty WeakCell, that means the script wrapper was 10161 // If we found an empty WeakCell, that means the script wrapper was
10162 // GCed. We are not notified directly of that, so we decrement here 10162 // GCed. We are not notified directly of that, so we decrement here
10163 // so that we at least don't count double for any given script. 10163 // so that we at least don't count double for any given script.
10164 isolate->counters()->script_wrappers()->Decrement(); 10164 isolate->counters()->script_wrappers()->Decrement();
10165 } 10165 }
10166 // Construct a new script wrapper. 10166 // Construct a new script wrapper.
10167 isolate->counters()->script_wrappers()->Increment(); 10167 isolate->counters()->script_wrappers()->Increment();
10168 Handle<JSFunction> constructor = isolate->script_function(); 10168 Handle<JSFunction> constructor = isolate->script_function();
10169 Handle<JSValue> result = 10169 Handle<JSValue> result =
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
10652 } 10652 }
10653 10653
10654 10654
10655 Object* Code::FindNthObject(int n, Map* match_map) { 10655 Object* Code::FindNthObject(int n, Map* match_map) {
10656 DCHECK(is_inline_cache_stub()); 10656 DCHECK(is_inline_cache_stub());
10657 DisallowHeapAllocation no_allocation; 10657 DisallowHeapAllocation no_allocation;
10658 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); 10658 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
10659 for (RelocIterator it(this, mask); !it.done(); it.next()) { 10659 for (RelocIterator it(this, mask); !it.done(); it.next()) {
10660 RelocInfo* info = it.rinfo(); 10660 RelocInfo* info = it.rinfo();
10661 Object* object = info->target_object(); 10661 Object* object = info->target_object();
10662 if (object->IsWeakCell()) object = WeakCell::cast(object)->value(); 10662 Object* original_object = object;
10663 if (object->IsWeakCell())
10664 object = WeakCell::cast(object)->ValueNoReadBarrier();
10663 if (object->IsHeapObject()) { 10665 if (object->IsHeapObject()) {
10664 if (HeapObject::cast(object)->map() == match_map) { 10666 if (HeapObject::cast(object)->map() == match_map) {
10665 if (--n == 0) return object; 10667 if (--n == 0) {
10668 WeakCell::TriggerReadBarrier(original_object);
10669 return object;
10670 }
10666 } 10671 }
10667 } 10672 }
10668 } 10673 }
10669 return NULL; 10674 return NULL;
10670 } 10675 }
10671 10676
10672 10677
10673 AllocationSite* Code::FindFirstAllocationSite() { 10678 AllocationSite* Code::FindFirstAllocationSite() {
10674 Object* result = FindNthObject(1, GetHeap()->allocation_site_map()); 10679 Object* result = FindNthObject(1, GetHeap()->allocation_site_map());
10675 return (result != NULL) ? AllocationSite::cast(result) : NULL; 10680 return (result != NULL) ? AllocationSite::cast(result) : NULL;
10676 } 10681 }
10677 10682
10678 10683
10679 Map* Code::FindFirstMap() { 10684 Map* Code::FindFirstMap() {
10680 Object* result = FindNthObject(1, GetHeap()->meta_map()); 10685 Object* result = FindNthObject(1, GetHeap()->meta_map());
10681 return (result != NULL) ? Map::cast(result) : NULL; 10686 return (result != NULL) ? Map::cast(result) : NULL;
10682 } 10687 }
10683 10688
10684 10689
10685 void Code::FindAndReplace(const FindAndReplacePattern& pattern) { 10690 void Code::FindAndReplace(const FindAndReplacePattern& pattern) {
10686 DCHECK(is_inline_cache_stub() || is_handler()); 10691 DCHECK(is_inline_cache_stub() || is_handler());
10687 DisallowHeapAllocation no_allocation; 10692 DisallowHeapAllocation no_allocation;
10688 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); 10693 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
10689 STATIC_ASSERT(FindAndReplacePattern::kMaxCount < 32); 10694 STATIC_ASSERT(FindAndReplacePattern::kMaxCount < 32);
10690 int current_pattern = 0; 10695 int current_pattern = 0;
10691 for (RelocIterator it(this, mask); !it.done(); it.next()) { 10696 for (RelocIterator it(this, mask); !it.done(); it.next()) {
10692 RelocInfo* info = it.rinfo(); 10697 RelocInfo* info = it.rinfo();
10693 Object* object = info->target_object(); 10698 Object* object = info->target_object();
10699 Object* original_object = object;
10700 if (object->IsWeakCell())
10701 object = WeakCell::cast(object)->ValueNoReadBarrier();
10694 if (object->IsHeapObject()) { 10702 if (object->IsHeapObject()) {
10695 if (object->IsWeakCell()) {
10696 object = HeapObject::cast(WeakCell::cast(object)->value());
10697 }
10698 Map* map = HeapObject::cast(object)->map(); 10703 Map* map = HeapObject::cast(object)->map();
10699 if (map == *pattern.find_[current_pattern]) { 10704 if (map == *pattern.find_[current_pattern]) {
10705 WeakCell::TriggerReadBarrier(original_object);
10700 info->set_target_object(*pattern.replace_[current_pattern]); 10706 info->set_target_object(*pattern.replace_[current_pattern]);
10701 if (++current_pattern == pattern.count_) return; 10707 if (++current_pattern == pattern.count_) return;
10702 } 10708 }
10703 } 10709 }
10704 } 10710 }
10705 UNREACHABLE(); 10711 UNREACHABLE();
10706 } 10712 }
10707 10713
10708 10714
10709 void Code::FindAllMaps(MapHandleList* maps) { 10715 void Code::FindAllMaps(MapHandleList* maps) {
10710 DCHECK(is_inline_cache_stub()); 10716 DCHECK(is_inline_cache_stub());
10711 DisallowHeapAllocation no_allocation; 10717 DisallowHeapAllocation no_allocation;
10712 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); 10718 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
10713 for (RelocIterator it(this, mask); !it.done(); it.next()) { 10719 for (RelocIterator it(this, mask); !it.done(); it.next()) {
10714 RelocInfo* info = it.rinfo(); 10720 RelocInfo* info = it.rinfo();
10715 Object* object = info->target_object(); 10721 Object* object = info->target_object();
10716 if (object->IsWeakCell()) object = WeakCell::cast(object)->value(); 10722 Object* original_object = object;
10717 if (object->IsMap()) maps->Add(handle(Map::cast(object))); 10723 if (object->IsWeakCell())
10724 object = WeakCell::cast(object)->ValueNoReadBarrier();
10725 if (object->IsMap()) {
10726 WeakCell::TriggerReadBarrier(original_object);
10727 maps->Add(handle(Map::cast(object)));
10728 }
10718 } 10729 }
10719 } 10730 }
10720 10731
10721 10732
10722 Code* Code::FindFirstHandler() { 10733 Code* Code::FindFirstHandler() {
10723 DCHECK(is_inline_cache_stub()); 10734 DCHECK(is_inline_cache_stub());
10724 DisallowHeapAllocation no_allocation; 10735 DisallowHeapAllocation no_allocation;
10725 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | 10736 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
10726 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); 10737 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
10727 bool skip_next_handler = false; 10738 bool skip_next_handler = false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
10773 10784
10774 MaybeHandle<Code> Code::FindHandlerForMap(Map* map) { 10785 MaybeHandle<Code> Code::FindHandlerForMap(Map* map) {
10775 DCHECK(is_inline_cache_stub()); 10786 DCHECK(is_inline_cache_stub());
10776 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | 10787 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
10777 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); 10788 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
10778 bool return_next = false; 10789 bool return_next = false;
10779 for (RelocIterator it(this, mask); !it.done(); it.next()) { 10790 for (RelocIterator it(this, mask); !it.done(); it.next()) {
10780 RelocInfo* info = it.rinfo(); 10791 RelocInfo* info = it.rinfo();
10781 if (info->rmode() == RelocInfo::EMBEDDED_OBJECT) { 10792 if (info->rmode() == RelocInfo::EMBEDDED_OBJECT) {
10782 Object* object = info->target_object(); 10793 Object* object = info->target_object();
10783 if (object->IsWeakCell()) object = WeakCell::cast(object)->value(); 10794 Object* original_object = object;
10784 if (object == map) return_next = true; 10795 if (object->IsWeakCell())
10796 object = WeakCell::cast(object)->ValueNoReadBarrier();
10797 if (object == map) {
10798 WeakCell::TriggerReadBarrier(original_object);
10799 return_next = true;
10800 }
10785 } else if (return_next) { 10801 } else if (return_next) {
10786 Code* code = Code::GetCodeFromTargetAddress(info->target_address()); 10802 Code* code = Code::GetCodeFromTargetAddress(info->target_address());
10787 DCHECK(code->kind() == Code::HANDLER); 10803 DCHECK(code->kind() == Code::HANDLER);
10788 return handle(code); 10804 return handle(code);
10789 } 10805 }
10790 } 10806 }
10791 return MaybeHandle<Code>(); 10807 return MaybeHandle<Code>();
10792 } 10808 }
10793 10809
10794 10810
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
11062 ->SetWeakCellCache(*cell); 11078 ->SetWeakCellCache(*cell);
11063 return cell; 11079 return cell;
11064 } 11080 }
11065 11081
11066 11082
11067 WeakCell* Code::CachedWeakCell() { 11083 WeakCell* Code::CachedWeakCell() {
11068 DCHECK(kind() == OPTIMIZED_FUNCTION); 11084 DCHECK(kind() == OPTIMIZED_FUNCTION);
11069 Object* weak_cell_cache = 11085 Object* weak_cell_cache =
11070 DeoptimizationInputData::cast(deoptimization_data())->WeakCellCache(); 11086 DeoptimizationInputData::cast(deoptimization_data())->WeakCellCache();
11071 if (weak_cell_cache->IsWeakCell()) { 11087 if (weak_cell_cache->IsWeakCell()) {
11072 DCHECK(this == WeakCell::cast(weak_cell_cache)->value()); 11088 DCHECK(this == WeakCell::cast(weak_cell_cache)->ValueNoReadBarrier());
11073 return WeakCell::cast(weak_cell_cache); 11089 return WeakCell::cast(weak_cell_cache);
11074 } 11090 }
11075 return NULL; 11091 return NULL;
11076 } 11092 }
11077 11093
11078 11094
11079 #ifdef ENABLE_DISASSEMBLER 11095 #ifdef ENABLE_DISASSEMBLER
11080 11096
11081 void DeoptimizationInputData::DeoptimizationInputDataPrint( 11097 void DeoptimizationInputData::DeoptimizationInputDataPrint(
11082 std::ostream& os) { // NOLINT 11098 std::ostream& os) { // NOLINT
(...skipping 5805 matching lines...) Expand 10 before | Expand all | Expand 10 after
16888 Handle<DependentCode> codes = 16904 Handle<DependentCode> codes =
16889 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), 16905 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()),
16890 DependentCode::kPropertyCellChangedGroup, 16906 DependentCode::kPropertyCellChangedGroup,
16891 info->object_wrapper()); 16907 info->object_wrapper());
16892 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); 16908 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes);
16893 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( 16909 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add(
16894 cell, info->zone()); 16910 cell, info->zone());
16895 } 16911 }
16896 16912
16897 } } // namespace v8::internal 16913 } } // namespace v8::internal
OLDNEW
« src/ic/ia32/ic-compiler-ia32.cc ('K') | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698