Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 7493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7505 AllocationSiteInfo* info = AllocationSiteInfo::cast( | 7505 AllocationSiteInfo* info = AllocationSiteInfo::cast( |
| 7506 reinterpret_cast<Object*>(ptr_end + 1)); | 7506 reinterpret_cast<Object*>(ptr_end + 1)); |
| 7507 return info; | 7507 return info; |
| 7508 } | 7508 } |
| 7509 } | 7509 } |
| 7510 } | 7510 } |
| 7511 return NULL; | 7511 return NULL; |
| 7512 } | 7512 } |
| 7513 | 7513 |
| 7514 | 7514 |
| 7515 bool AllocationSiteInfo::GetElementsKindPayload(ElementsKind* kind) { | |
| 7516 ASSERT(kind != NULL); | |
| 7517 if (payload()->IsJSGlobalPropertyCell()) { | |
| 7518 JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(payload()); | |
| 7519 Object* cell_contents = cell->value(); | |
| 7520 if (cell_contents->IsSmi()) { | |
| 7521 *kind = static_cast<ElementsKind>( | |
| 7522 Smi::cast(cell_contents)->value()); | |
| 7523 return true; | |
| 7524 } | |
| 7525 } | |
| 7526 return false; | |
| 7527 } | |
| 7528 | |
| 7529 | |
| 7515 // Heuristic: We only need to create allocation site info if the boilerplate | 7530 // Heuristic: We only need to create allocation site info if the boilerplate |
| 7516 // elements kind is the initial elements kind. | 7531 // elements kind is the initial elements kind. |
| 7517 AllocationSiteMode AllocationSiteInfo::GetMode( | 7532 AllocationSiteMode AllocationSiteInfo::GetMode( |
| 7518 ElementsKind boilerplate_elements_kind) { | 7533 ElementsKind boilerplate_elements_kind) { |
| 7519 if (FLAG_track_allocation_sites && | 7534 if (FLAG_track_allocation_sites && |
| 7520 IsFastSmiElementsKind(boilerplate_elements_kind)) { | 7535 IsFastSmiElementsKind(boilerplate_elements_kind)) { |
| 7521 return TRACK_ALLOCATION_SITE; | 7536 return TRACK_ALLOCATION_SITE; |
| 7522 } | 7537 } |
| 7523 | 7538 |
| 7524 return DONT_TRACK_ALLOCATION_SITE; | 7539 return DONT_TRACK_ALLOCATION_SITE; |
| (...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9329 } | 9344 } |
| 9330 | 9345 |
| 9331 return this; | 9346 return this; |
| 9332 } | 9347 } |
| 9333 | 9348 |
| 9334 | 9349 |
| 9335 MaybeObject* JSArray::Initialize(int capacity) { | 9350 MaybeObject* JSArray::Initialize(int capacity) { |
| 9336 Heap* heap = GetHeap(); | 9351 Heap* heap = GetHeap(); |
| 9337 ASSERT(capacity >= 0); | 9352 ASSERT(capacity >= 0); |
| 9338 set_length(Smi::FromInt(0)); | 9353 set_length(Smi::FromInt(0)); |
| 9339 FixedArray* new_elements; | 9354 FixedArrayBase* new_elements; |
| 9340 if (capacity == 0) { | 9355 if (capacity == 0) { |
| 9341 new_elements = heap->empty_fixed_array(); | 9356 new_elements = heap->empty_fixed_array(); |
| 9342 } else { | 9357 } else { |
| 9343 MaybeObject* maybe_obj = heap->AllocateFixedArrayWithHoles(capacity); | 9358 ElementsKind elements_kind = GetElementsKind(); |
| 9359 MaybeObject* maybe_obj; | |
| 9360 if (IsFastDoubleElementsKind(elements_kind)) { | |
| 9361 maybe_obj = heap->AllocateFixedDoubleArrayWithHoles(capacity); | |
| 9362 } else { | |
| 9363 maybe_obj = heap->AllocateFixedArrayWithHoles(capacity); | |
| 9364 } | |
|
Toon Verwaest
2013/02/13 15:14:51
Seems like this is overlapping with AllocateJSArra
mvstanton
2013/02/19 11:04:08
Done.
| |
| 9344 if (!maybe_obj->To(&new_elements)) return maybe_obj; | 9365 if (!maybe_obj->To(&new_elements)) return maybe_obj; |
| 9345 } | 9366 } |
| 9346 set_elements(new_elements); | 9367 set_elements(new_elements); |
| 9347 return this; | 9368 return this; |
| 9348 } | 9369 } |
| 9349 | 9370 |
| 9350 | 9371 |
| 9351 void JSArray::Expand(int required_size) { | 9372 void JSArray::Expand(int required_size) { |
| 9352 GetIsolate()->factory()->SetElementsCapacityAndLength( | 9373 GetIsolate()->factory()->SetElementsCapacityAndLength( |
| 9353 Handle<JSArray>(this), required_size, required_size); | 9374 Handle<JSArray>(this), required_size, required_size); |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10523 | 10544 |
| 10524 | 10545 |
| 10525 Handle<Object> JSObject::TransitionElementsKind(Handle<JSObject> object, | 10546 Handle<Object> JSObject::TransitionElementsKind(Handle<JSObject> object, |
| 10526 ElementsKind to_kind) { | 10547 ElementsKind to_kind) { |
| 10527 CALL_HEAP_FUNCTION(object->GetIsolate(), | 10548 CALL_HEAP_FUNCTION(object->GetIsolate(), |
| 10528 object->TransitionElementsKind(to_kind), | 10549 object->TransitionElementsKind(to_kind), |
| 10529 Object); | 10550 Object); |
| 10530 } | 10551 } |
| 10531 | 10552 |
| 10532 | 10553 |
| 10554 // TODO(mvstanton): rename this method to reflect what it actually does. | |
| 10555 // If a boilerplate object is discovered, then it will transition it. | |
| 10556 // If instead there is a elements kind, then update it as long as the | |
| 10557 // to_kind variable is more general than what we find, but don't | |
| 10558 // ever take the double->fastobject transition (that represents poisoning), | |
| 10559 // just ignore that case. | |
| 10533 MaybeObject* JSObject::PossiblyTransitionArrayBoilerplate( | 10560 MaybeObject* JSObject::PossiblyTransitionArrayBoilerplate( |
| 10534 ElementsKind to_kind) { | 10561 ElementsKind to_kind) { |
| 10535 MaybeObject* ret = NULL; | 10562 MaybeObject* ret = NULL; |
|
Toon Verwaest
2013/02/13 15:14:51
Seems like you don't need this variable. Below you
mvstanton
2013/02/19 11:04:08
Done. And I addressed my TODO above, renaming the
| |
| 10536 if (!FLAG_track_allocation_sites || !IsJSArray()) { | 10563 if (!FLAG_track_allocation_sites || !IsJSArray()) { |
| 10537 return ret; | 10564 return ret; |
| 10538 } | 10565 } |
| 10539 | 10566 |
| 10540 AllocationSiteInfo* info = AllocationSiteInfo::FindForJSObject(this); | 10567 AllocationSiteInfo* info = AllocationSiteInfo::FindForJSObject(this); |
| 10541 if (info == NULL) { | 10568 if (info == NULL) { |
| 10542 return ret; | 10569 return ret; |
| 10543 } | 10570 } |
| 10544 | 10571 |
| 10545 ASSERT(info->payload()->IsJSArray()); | 10572 if (info->payload()->IsJSArray()) { |
| 10546 JSArray* payload = JSArray::cast(info->payload()); | 10573 JSArray* payload = JSArray::cast(info->payload()); |
| 10547 ElementsKind kind = payload->GetElementsKind(); | 10574 ElementsKind kind = payload->GetElementsKind(); |
| 10548 if (IsMoreGeneralElementsKindTransition(kind, to_kind)) { | 10575 if (IsMoreGeneralElementsKindTransition(kind, to_kind)) { |
| 10549 // If the array is huge, it's not likely to be defined in a local | 10576 // If the array is huge, it's not likely to be defined in a local |
| 10550 // function, so we shouldn't make new instances of it very often. | 10577 // function, so we shouldn't make new instances of it very often. |
| 10551 uint32_t length = 0; | 10578 uint32_t length = 0; |
| 10552 CHECK(payload->length()->ToArrayIndex(&length)); | 10579 CHECK(payload->length()->ToArrayIndex(&length)); |
| 10553 if (length <= 8 * 1024) { | 10580 if (length <= 8*1024) { |
|
Toon Verwaest
2013/02/13 15:14:51
Define a constant.
mvstanton
2013/02/19 11:04:08
Done.
| |
| 10554 ret = payload->TransitionElementsKind(to_kind); | 10581 ret = payload->TransitionElementsKind(to_kind); |
| 10555 if (FLAG_trace_track_allocation_sites) { | 10582 if (FLAG_trace_track_allocation_sites) { |
| 10556 PrintF( | 10583 PrintF( |
| 10557 "AllocationSiteInfo: JSArray %p boilerplate updated %s->%s\n", | 10584 "AllocationSiteInfo: JSArray %p boilerplate updated %s->%s\n", |
| 10558 reinterpret_cast<void*>(this), | 10585 reinterpret_cast<void*>(this), |
| 10559 ElementsKindToString(kind), | 10586 ElementsKindToString(kind), |
| 10560 ElementsKindToString(to_kind)); | 10587 ElementsKindToString(to_kind)); |
| 10588 } | |
| 10589 } | |
| 10590 } | |
| 10591 } else if (info->payload()->IsJSGlobalPropertyCell()) { | |
| 10592 JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(info->payload()); | |
| 10593 Object* cell_contents = cell->value(); | |
| 10594 if (cell_contents->IsSmi()) { | |
| 10595 ElementsKind kind = static_cast<ElementsKind>( | |
| 10596 Smi::cast(cell_contents)->value()); | |
| 10597 // Specifically exclude DOUBLE(HOLEY) -> FAST(HOLEY) | |
| 10598 bool double_to_fast = IsFastDoubleElementsKind(kind) && | |
| 10599 IsFastObjectElementsKind(to_kind); | |
|
Toon Verwaest
2013/02/13 15:14:51
This heuristic seems very buried away. Can we make
mvstanton
2013/02/19 11:04:08
Yep, I just didn't revisit this code in a while, t
mvstanton
2013/02/19 11:04:08
Done.
| |
| 10600 if (IsMoreGeneralElementsKindTransition(kind, to_kind) && | |
| 10601 !double_to_fast) { | |
| 10602 if (FLAG_trace_track_allocation_sites) { | |
| 10603 PrintF("AllocationSiteInfo: JSArray %p info updated %s->%s\n", | |
| 10604 reinterpret_cast<void*>(this), | |
| 10605 ElementsKindToString(kind), | |
| 10606 ElementsKindToString(to_kind)); | |
| 10607 } | |
| 10608 cell->set_value(Smi::FromInt(to_kind)); | |
| 10561 } | 10609 } |
| 10562 } | 10610 } |
| 10563 } | 10611 } |
| 10564 return ret; | 10612 return ret; |
| 10565 } | 10613 } |
| 10566 | 10614 |
| 10567 | 10615 |
| 10568 MaybeObject* JSObject::TransitionElementsKind(ElementsKind to_kind) { | 10616 MaybeObject* JSObject::TransitionElementsKind(ElementsKind to_kind) { |
| 10569 ASSERT(!map()->is_observed()); | 10617 ASSERT(!map()->is_observed()); |
| 10570 ElementsKind from_kind = map()->elements_kind(); | 10618 ElementsKind from_kind = map()->elements_kind(); |
| (...skipping 3351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13922 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13970 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
| 13923 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13971 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
| 13924 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13972 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
| 13925 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13973 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
| 13926 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13974 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
| 13927 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13975 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
| 13928 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13976 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
| 13929 } | 13977 } |
| 13930 | 13978 |
| 13931 } } // namespace v8::internal | 13979 } } // namespace v8::internal |
| OLD | NEW |