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

Side by Side Diff: src/objects.cc

Issue 15094018: Create AllocationSite objects, pointed to by AllocationSiteInfo. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Platform ports and perf bugfix Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 8844 matching lines...) Expand 10 before | Expand all | Expand 10 after
8855 AllocationSiteInfo* info = AllocationSiteInfo::cast( 8855 AllocationSiteInfo* info = AllocationSiteInfo::cast(
8856 reinterpret_cast<Object*>(ptr_end + 1)); 8856 reinterpret_cast<Object*>(ptr_end + 1));
8857 return info; 8857 return info;
8858 } 8858 }
8859 } 8859 }
8860 } 8860 }
8861 return NULL; 8861 return NULL;
8862 } 8862 }
8863 8863
8864 8864
8865 bool AllocationSiteInfo::GetElementsKindPayload(ElementsKind* kind) {
8866 ASSERT(kind != NULL);
8867 if (payload()->IsCell()) {
8868 Cell* cell = Cell::cast(payload());
8869 Object* cell_contents = cell->value();
8870 if (cell_contents->IsSmi()) {
8871 *kind = static_cast<ElementsKind>(
8872 Smi::cast(cell_contents)->value());
8873 return true;
8874 }
8875 }
8876 return false;
8877 }
8878
8879
8880 uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) { 8865 uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) {
8881 // For array indexes mix the length into the hash as an array index could 8866 // For array indexes mix the length into the hash as an array index could
8882 // be zero. 8867 // be zero.
8883 ASSERT(length > 0); 8868 ASSERT(length > 0);
8884 ASSERT(length <= String::kMaxArrayIndexSize); 8869 ASSERT(length <= String::kMaxArrayIndexSize);
8885 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < 8870 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
8886 (1 << String::kArrayIndexValueBits)); 8871 (1 << String::kArrayIndexValueBits));
8887 8872
8888 value <<= String::kHashShift; 8873 value <<= String::kHashShift;
8889 value |= length << String::kArrayIndexHashLengthShift; 8874 value |= length << String::kArrayIndexHashLengthShift;
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
10247 10232
10248 10233
10249 void Code::ClearTypeFeedbackCells(Heap* heap) { 10234 void Code::ClearTypeFeedbackCells(Heap* heap) {
10250 if (kind() != FUNCTION) return; 10235 if (kind() != FUNCTION) return;
10251 Object* raw_info = type_feedback_info(); 10236 Object* raw_info = type_feedback_info();
10252 if (raw_info->IsTypeFeedbackInfo()) { 10237 if (raw_info->IsTypeFeedbackInfo()) {
10253 TypeFeedbackCells* type_feedback_cells = 10238 TypeFeedbackCells* type_feedback_cells =
10254 TypeFeedbackInfo::cast(raw_info)->type_feedback_cells(); 10239 TypeFeedbackInfo::cast(raw_info)->type_feedback_cells();
10255 for (int i = 0; i < type_feedback_cells->CellCount(); i++) { 10240 for (int i = 0; i < type_feedback_cells->CellCount(); i++) {
10256 Cell* cell = type_feedback_cells->GetCell(i); 10241 Cell* cell = type_feedback_cells->GetCell(i);
10257 cell->set_value(TypeFeedbackCells::RawUninitializedSentinel(heap)); 10242 // Don't clear AllocationSites
10243 Object* value = cell->value();
10244 if (value == NULL || !value->IsAllocationSite()) {
10245 cell->set_value(TypeFeedbackCells::RawUninitializedSentinel(heap));
10246 }
10258 } 10247 }
10259 } 10248 }
10260 } 10249 }
10261 10250
10262 10251
10263 bool Code::allowed_in_shared_map_code_cache() { 10252 bool Code::allowed_in_shared_map_code_cache() {
10264 return is_keyed_load_stub() || is_keyed_store_stub() || 10253 return is_keyed_load_stub() || is_keyed_store_stub() ||
10265 (is_compare_ic_stub() && 10254 (is_compare_ic_stub() &&
10266 ICCompareStub::CompareState(stub_info()) == CompareIC::KNOWN_OBJECT); 10255 ICCompareStub::CompareState(stub_info()) == CompareIC::KNOWN_OBJECT);
10267 } 10256 }
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
11704 check_prototype); 11693 check_prototype);
11705 } 11694 }
11706 } 11695 }
11707 // Convert to fast double elements if appropriate. 11696 // Convert to fast double elements if appropriate.
11708 if (HasFastSmiElements() && !value->IsSmi() && value->IsNumber()) { 11697 if (HasFastSmiElements() && !value->IsSmi() && value->IsNumber()) {
11709 // Consider fixing the boilerplate as well if we have one. 11698 // Consider fixing the boilerplate as well if we have one.
11710 ElementsKind to_kind = IsHoleyElementsKind(elements_kind) 11699 ElementsKind to_kind = IsHoleyElementsKind(elements_kind)
11711 ? FAST_HOLEY_DOUBLE_ELEMENTS 11700 ? FAST_HOLEY_DOUBLE_ELEMENTS
11712 : FAST_DOUBLE_ELEMENTS; 11701 : FAST_DOUBLE_ELEMENTS;
11713 11702
11714 MaybeObject* maybe_failure = UpdateAllocationSiteInfo(to_kind); 11703 MaybeObject* maybe_failure = UpdateAllocationSite(to_kind);
11715 if (maybe_failure->IsFailure()) return maybe_failure; 11704 if (maybe_failure->IsFailure()) return maybe_failure;
11716 11705
11717 MaybeObject* maybe = 11706 MaybeObject* maybe =
11718 SetFastDoubleElementsCapacityAndLength(new_capacity, array_length); 11707 SetFastDoubleElementsCapacityAndLength(new_capacity, array_length);
11719 if (maybe->IsFailure()) return maybe; 11708 if (maybe->IsFailure()) return maybe;
11720 FixedDoubleArray::cast(elements())->set(index, value->Number()); 11709 FixedDoubleArray::cast(elements())->set(index, value->Number());
11721 ValidateElements(); 11710 ValidateElements();
11722 return value; 11711 return value;
11723 } 11712 }
11724 // Change elements kind from Smi-only to generic FAST if necessary. 11713 // Change elements kind from Smi-only to generic FAST if necessary.
11725 if (HasFastSmiElements() && !value->IsSmi()) { 11714 if (HasFastSmiElements() && !value->IsSmi()) {
11726 Map* new_map; 11715 Map* new_map;
11727 ElementsKind kind = HasFastHoleyElements() 11716 ElementsKind kind = HasFastHoleyElements()
11728 ? FAST_HOLEY_ELEMENTS 11717 ? FAST_HOLEY_ELEMENTS
11729 : FAST_ELEMENTS; 11718 : FAST_ELEMENTS;
11730 11719
11731 MaybeObject* maybe_failure = UpdateAllocationSiteInfo(kind); 11720 MaybeObject* maybe_failure = UpdateAllocationSite(kind);
11732 if (maybe_failure->IsFailure()) return maybe_failure; 11721 if (maybe_failure->IsFailure()) return maybe_failure;
11733 11722
11734 MaybeObject* maybe_new_map = GetElementsTransitionMap(GetIsolate(), 11723 MaybeObject* maybe_new_map = GetElementsTransitionMap(GetIsolate(),
11735 kind); 11724 kind);
11736 if (!maybe_new_map->To(&new_map)) return maybe_new_map; 11725 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
11737 11726
11738 set_map(new_map); 11727 set_map(new_map);
11739 } 11728 }
11740 // Increase backing store capacity if that's been decided previously. 11729 // Increase backing store capacity if that's been decided previously.
11741 if (new_capacity != capacity) { 11730 if (new_capacity != capacity) {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
12284 12273
12285 12274
12286 Handle<Object> JSObject::TransitionElementsKind(Handle<JSObject> object, 12275 Handle<Object> JSObject::TransitionElementsKind(Handle<JSObject> object,
12287 ElementsKind to_kind) { 12276 ElementsKind to_kind) {
12288 CALL_HEAP_FUNCTION(object->GetIsolate(), 12277 CALL_HEAP_FUNCTION(object->GetIsolate(),
12289 object->TransitionElementsKind(to_kind), 12278 object->TransitionElementsKind(to_kind),
12290 Object); 12279 Object);
12291 } 12280 }
12292 12281
12293 12282
12294 MaybeObject* JSObject::UpdateAllocationSiteInfo(ElementsKind to_kind) { 12283 MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) {
12295 if (!FLAG_track_allocation_sites || !IsJSArray()) { 12284 if (!FLAG_track_allocation_sites || !IsJSArray()) {
12296 return this; 12285 return this;
12297 } 12286 }
12298 12287
12299 AllocationSiteInfo* info = AllocationSiteInfo::FindForJSObject(this); 12288 AllocationSiteInfo* info = AllocationSiteInfo::FindForJSObject(this);
12300 if (info == NULL) { 12289 if (info == NULL || !info->site_is_valid()) {
12301 return this; 12290 return this;
12302 } 12291 }
12303 12292
12304 if (info->payload()->IsJSArray()) { 12293 // Walk through to the Allocation Site
12305 JSArray* payload = JSArray::cast(info->payload()); 12294 AllocationSite* site = info->allocation_site_casted();
12295 if (site->IsLiteralSite()) {
12296 JSArray* payload = JSArray::cast(site->payload());
12306 ElementsKind kind = payload->GetElementsKind(); 12297 ElementsKind kind = payload->GetElementsKind();
12307 if (AllocationSiteInfo::GetMode(kind, to_kind) == TRACK_ALLOCATION_SITE) { 12298 if (AllocationSite::GetMode(kind, to_kind) == TRACK_ALLOCATION_SITE) {
12308 // If the array is huge, it's not likely to be defined in a local 12299 // If the array is huge, it's not likely to be defined in a local
12309 // function, so we shouldn't make new instances of it very often. 12300 // function, so we shouldn't make new instances of it very often.
12310 uint32_t length = 0; 12301 uint32_t length = 0;
12311 CHECK(payload->length()->ToArrayIndex(&length)); 12302 CHECK(payload->length()->ToArrayIndex(&length));
12312 if (length <= AllocationSiteInfo::kMaximumArrayBytesToPretransition) { 12303 if (length <= AllocationSite::kMaximumArrayBytesToPretransition) {
12313 if (FLAG_trace_track_allocation_sites) { 12304 if (FLAG_trace_track_allocation_sites) {
12314 PrintF( 12305 PrintF(
12315 "AllocationSiteInfo: JSArray %p boilerplate updated %s->%s\n", 12306 "AllocationSite: JSArray %p boilerplate updated %s->%s\n",
12316 reinterpret_cast<void*>(this), 12307 reinterpret_cast<void*>(this),
12317 ElementsKindToString(kind), 12308 ElementsKindToString(kind),
12318 ElementsKindToString(to_kind)); 12309 ElementsKindToString(to_kind));
12319 } 12310 }
12320 return payload->TransitionElementsKind(to_kind); 12311 return payload->TransitionElementsKind(to_kind);
12321 } 12312 }
12322 } 12313 }
12323 } else if (info->payload()->IsCell()) { 12314 } else {
12324 Cell* cell = Cell::cast(info->payload()); 12315 ElementsKind kind = site->GetElementsKindPayload();
12325 Object* cell_contents = cell->value(); 12316 if (AllocationSite::GetMode(kind, to_kind) == TRACK_ALLOCATION_SITE) {
12326 if (cell_contents->IsSmi()) { 12317 if (FLAG_trace_track_allocation_sites) {
12327 ElementsKind kind = static_cast<ElementsKind>( 12318 PrintF("AllocationSite: JSArray %p site updated %s->%s\n",
12328 Smi::cast(cell_contents)->value()); 12319 reinterpret_cast<void*>(this),
12329 if (AllocationSiteInfo::GetMode(kind, to_kind) == TRACK_ALLOCATION_SITE) { 12320 ElementsKindToString(kind),
12330 if (FLAG_trace_track_allocation_sites) { 12321 ElementsKindToString(to_kind));
12331 PrintF("AllocationSiteInfo: JSArray %p info updated %s->%s\n",
12332 reinterpret_cast<void*>(this),
12333 ElementsKindToString(kind),
12334 ElementsKindToString(to_kind));
12335 }
12336 cell->set_value(Smi::FromInt(to_kind));
12337 } 12322 }
12323 site->set_payload(Smi::FromInt(to_kind));
12338 } 12324 }
12339 } 12325 }
12340 return this; 12326 return this;
12341 } 12327 }
12342 12328
12343 12329
12344 MaybeObject* JSObject::TransitionElementsKind(ElementsKind to_kind) { 12330 MaybeObject* JSObject::TransitionElementsKind(ElementsKind to_kind) {
12345 ASSERT(!map()->is_observed()); 12331 ASSERT(!map()->is_observed());
12346 ElementsKind from_kind = map()->elements_kind(); 12332 ElementsKind from_kind = map()->elements_kind();
12347 12333
12348 if (IsFastHoleyElementsKind(from_kind)) { 12334 if (IsFastHoleyElementsKind(from_kind)) {
12349 to_kind = GetHoleyElementsKind(to_kind); 12335 to_kind = GetHoleyElementsKind(to_kind);
12350 } 12336 }
12351 12337
12352 if (from_kind == to_kind) return this; 12338 if (from_kind == to_kind) return this;
12353 12339
12354 MaybeObject* maybe_failure = UpdateAllocationSiteInfo(to_kind); 12340 MaybeObject* maybe_failure = UpdateAllocationSite(to_kind);
12355 if (maybe_failure->IsFailure()) return maybe_failure; 12341 if (maybe_failure->IsFailure()) return maybe_failure;
12356 12342
12357 Isolate* isolate = GetIsolate(); 12343 Isolate* isolate = GetIsolate();
12358 if (elements() == isolate->heap()->empty_fixed_array() || 12344 if (elements() == isolate->heap()->empty_fixed_array() ||
12359 (IsFastSmiOrObjectElementsKind(from_kind) && 12345 (IsFastSmiOrObjectElementsKind(from_kind) &&
12360 IsFastSmiOrObjectElementsKind(to_kind)) || 12346 IsFastSmiOrObjectElementsKind(to_kind)) ||
12361 (from_kind == FAST_DOUBLE_ELEMENTS && 12347 (from_kind == FAST_DOUBLE_ELEMENTS &&
12362 to_kind == FAST_HOLEY_DOUBLE_ELEMENTS)) { 12348 to_kind == FAST_HOLEY_DOUBLE_ELEMENTS)) {
12363 ASSERT(from_kind != TERMINAL_FAST_ELEMENTS_KIND); 12349 ASSERT(from_kind != TERMINAL_FAST_ELEMENTS_KIND);
12364 // No change is needed to the elements() buffer, the transition 12350 // No change is needed to the elements() buffer, the transition
(...skipping 3454 matching lines...) Expand 10 before | Expand all | Expand 10 after
15819 15805
15820 void PropertyCell::AddDependentCode(Handle<Code> code) { 15806 void PropertyCell::AddDependentCode(Handle<Code> code) {
15821 Handle<DependentCode> codes = DependentCode::Insert( 15807 Handle<DependentCode> codes = DependentCode::Insert(
15822 Handle<DependentCode>(dependent_code()), 15808 Handle<DependentCode>(dependent_code()),
15823 DependentCode::kPropertyCellChangedGroup, code); 15809 DependentCode::kPropertyCellChangedGroup, code);
15824 if (*codes != dependent_code()) set_dependent_code(*codes); 15810 if (*codes != dependent_code()) set_dependent_code(*codes);
15825 } 15811 }
15826 15812
15827 15813
15828 } } // namespace v8::internal 15814 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698