| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 should_have_fast_elements, | 494 should_have_fast_elements, |
| 495 has_function_literal); | 495 has_function_literal); |
| 496 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); | 496 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); |
| 497 // Update the functions literal and return the boilerplate. | 497 // Update the functions literal and return the boilerplate. |
| 498 literals->set(literals_index, *boilerplate); | 498 literals->set(literals_index, *boilerplate); |
| 499 } | 499 } |
| 500 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate)); | 500 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate)); |
| 501 } | 501 } |
| 502 | 502 |
| 503 | 503 |
| 504 static Handle<AllocationSite> GetLiteralAllocationSite( |
| 505 Isolate* isolate, |
| 506 Handle<FixedArray> literals, |
| 507 int literals_index, |
| 508 Handle<FixedArray> elements) { |
| 509 // Check if boilerplate exists. If not, create it first. |
| 510 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 511 Handle<AllocationSite> site; |
| 512 if (*literal_site == isolate->heap()->undefined_value()) { |
| 513 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 514 Handle<Object> boilerplate = |
| 515 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 516 if (boilerplate.is_null()) return site; |
| 517 site = isolate->factory()->NewAllocationSite(); |
| 518 site->set_payload(*boilerplate); |
| 519 literals->set(literals_index, *site); |
| 520 } else { |
| 521 site = Handle<AllocationSite>::cast(literal_site); |
| 522 } |
| 523 |
| 524 return site; |
| 525 } |
| 526 |
| 527 |
| 504 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { | 528 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { |
| 505 HandleScope scope(isolate); | 529 HandleScope scope(isolate); |
| 506 ASSERT(args.length() == 3); | 530 ASSERT(args.length() == 3); |
| 507 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 531 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 508 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 532 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 509 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 533 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 510 | 534 |
| 511 // Check if boilerplate exists. If not, create it first. | 535 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 512 Handle<Object> boilerplate(literals->get(literals_index), isolate); | 536 literals_index, elements); |
| 513 if (*boilerplate == isolate->heap()->undefined_value()) { | 537 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 514 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 538 |
| 515 boilerplate = | 539 JSObject* boilerplate = JSObject::cast(site->payload()); |
| 516 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 540 return boilerplate->DeepCopy(isolate); |
| 517 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); | |
| 518 // Update the functions literal and return the boilerplate. | |
| 519 literals->set(literals_index, *boilerplate); | |
| 520 } | |
| 521 return JSObject::cast(*boilerplate)->DeepCopy(isolate); | |
| 522 } | 541 } |
| 523 | 542 |
| 524 | 543 |
| 525 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { | 544 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { |
| 526 HandleScope scope(isolate); | 545 HandleScope scope(isolate); |
| 527 ASSERT(args.length() == 3); | 546 ASSERT(args.length() == 3); |
| 528 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 547 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 529 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 548 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 530 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 549 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 531 | 550 |
| 532 // Check if boilerplate exists. If not, create it first. | 551 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 533 Handle<Object> boilerplate(literals->get(literals_index), isolate); | 552 literals_index, elements); |
| 534 if (*boilerplate == isolate->heap()->undefined_value()) { | 553 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 535 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 554 |
| 536 boilerplate = | 555 JSObject* boilerplate = JSObject::cast(site->payload()); |
| 537 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 556 if (boilerplate->elements()->map() == |
| 538 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); | |
| 539 // Update the functions literal and return the boilerplate. | |
| 540 literals->set(literals_index, *boilerplate); | |
| 541 } | |
| 542 if (JSObject::cast(*boilerplate)->elements()->map() == | |
| 543 isolate->heap()->fixed_cow_array_map()) { | 557 isolate->heap()->fixed_cow_array_map()) { |
| 544 isolate->counters()->cow_arrays_created_runtime()->Increment(); | 558 isolate->counters()->cow_arrays_created_runtime()->Increment(); |
| 545 } | 559 } |
| 546 | 560 |
| 547 JSObject* boilerplate_object = JSObject::cast(*boilerplate); | 561 AllocationSiteMode mode = AllocationSite::GetMode( |
| 548 AllocationSiteMode mode = AllocationSiteInfo::GetMode( | 562 boilerplate->GetElementsKind()); |
| 549 boilerplate_object->GetElementsKind()); | |
| 550 if (mode == TRACK_ALLOCATION_SITE) { | 563 if (mode == TRACK_ALLOCATION_SITE) { |
| 551 return isolate->heap()->CopyJSObjectWithAllocationSite(boilerplate_object); | 564 return isolate->heap()->CopyJSObjectWithAllocationSite( |
| 565 boilerplate, *site); |
| 552 } | 566 } |
| 553 | 567 |
| 554 return isolate->heap()->CopyJSObject(boilerplate_object); | 568 return isolate->heap()->CopyJSObject(boilerplate); |
| 555 } | 569 } |
| 556 | 570 |
| 557 | 571 |
| 558 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { | 572 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { |
| 559 HandleScope scope(isolate); | 573 HandleScope scope(isolate); |
| 560 ASSERT(args.length() == 1); | 574 ASSERT(args.length() == 1); |
| 561 Handle<Object> name(args[0], isolate); | 575 Handle<Object> name(args[0], isolate); |
| 562 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); | 576 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); |
| 563 Symbol* symbol; | 577 Symbol* symbol; |
| 564 MaybeObject* maybe = isolate->heap()->AllocateSymbol(); | 578 MaybeObject* maybe = isolate->heap()->AllocateSymbol(); |
| (...skipping 4631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5196 | 5210 |
| 5197 RUNTIME_FUNCTION(MaybeObject*, Runtime_StoreArrayLiteralElement) { | 5211 RUNTIME_FUNCTION(MaybeObject*, Runtime_StoreArrayLiteralElement) { |
| 5198 HandleScope scope(isolate); | 5212 HandleScope scope(isolate); |
| 5199 RUNTIME_ASSERT(args.length() == 5); | 5213 RUNTIME_ASSERT(args.length() == 5); |
| 5200 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 5214 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 5201 CONVERT_SMI_ARG_CHECKED(store_index, 1); | 5215 CONVERT_SMI_ARG_CHECKED(store_index, 1); |
| 5202 Handle<Object> value = args.at<Object>(2); | 5216 Handle<Object> value = args.at<Object>(2); |
| 5203 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 3); | 5217 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 3); |
| 5204 CONVERT_SMI_ARG_CHECKED(literal_index, 4); | 5218 CONVERT_SMI_ARG_CHECKED(literal_index, 4); |
| 5205 | 5219 |
| 5206 Object* raw_boilerplate_object = literals->get(literal_index); | 5220 Object* raw_literal_cell = literals->get(literal_index); |
| 5207 Handle<JSArray> boilerplate_object(JSArray::cast(raw_boilerplate_object)); | 5221 JSArray* boilerplate = NULL; |
| 5222 if (raw_literal_cell->IsAllocationSite()) { |
| 5223 AllocationSite* site = AllocationSite::cast(raw_literal_cell); |
| 5224 boilerplate = JSArray::cast(site->payload()); |
| 5225 } else { |
| 5226 boilerplate = JSArray::cast(raw_literal_cell); |
| 5227 } |
| 5228 Handle<JSArray> boilerplate_object(boilerplate); |
| 5208 ElementsKind elements_kind = object->GetElementsKind(); | 5229 ElementsKind elements_kind = object->GetElementsKind(); |
| 5209 ASSERT(IsFastElementsKind(elements_kind)); | 5230 ASSERT(IsFastElementsKind(elements_kind)); |
| 5210 // Smis should never trigger transitions. | 5231 // Smis should never trigger transitions. |
| 5211 ASSERT(!value->IsSmi()); | 5232 ASSERT(!value->IsSmi()); |
| 5212 | 5233 |
| 5213 if (value->IsNumber()) { | 5234 if (value->IsNumber()) { |
| 5214 ASSERT(IsFastSmiElementsKind(elements_kind)); | 5235 ASSERT(IsFastSmiElementsKind(elements_kind)); |
| 5215 ElementsKind transitioned_kind = IsFastHoleyElementsKind(elements_kind) | 5236 ElementsKind transitioned_kind = IsFastHoleyElementsKind(elements_kind) |
| 5216 ? FAST_HOLEY_DOUBLE_ELEMENTS | 5237 ? FAST_HOLEY_DOUBLE_ELEMENTS |
| 5217 : FAST_DOUBLE_ELEMENTS; | 5238 : FAST_DOUBLE_ELEMENTS; |
| (...skipping 8593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13811 } else { | 13832 } else { |
| 13812 // Non-smi length argument produces a dictionary | 13833 // Non-smi length argument produces a dictionary |
| 13813 can_use_type_feedback = false; | 13834 can_use_type_feedback = false; |
| 13814 } | 13835 } |
| 13815 } | 13836 } |
| 13816 | 13837 |
| 13817 JSArray* array; | 13838 JSArray* array; |
| 13818 MaybeObject* maybe_array; | 13839 MaybeObject* maybe_array; |
| 13819 if (!type_info.is_null() && | 13840 if (!type_info.is_null() && |
| 13820 *type_info != isolate->heap()->undefined_value() && | 13841 *type_info != isolate->heap()->undefined_value() && |
| 13821 Cell::cast(*type_info)->value()->IsSmi() && | 13842 Cell::cast(*type_info)->value()->IsAllocationSite() && |
| 13822 can_use_type_feedback) { | 13843 can_use_type_feedback) { |
| 13823 Cell* cell = Cell::cast(*type_info); | 13844 Handle<Cell> cell = Handle<Cell>::cast(type_info); |
| 13824 Smi* smi = Smi::cast(cell->value()); | 13845 Handle<AllocationSite> site = Handle<AllocationSite>( |
| 13825 ElementsKind to_kind = static_cast<ElementsKind>(smi->value()); | 13846 AllocationSite::cast(cell->value()), isolate); |
| 13847 ASSERT(!site->IsLiteralSite()); |
| 13848 ElementsKind to_kind = site->GetElementsKindPayload(); |
| 13826 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 13849 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| 13827 to_kind = GetHoleyElementsKind(to_kind); | 13850 to_kind = GetHoleyElementsKind(to_kind); |
| 13828 // Update the allocation site info to reflect the advice alteration. | 13851 // Update the allocation site info to reflect the advice alteration. |
| 13829 cell->set_value(Smi::FromInt(to_kind)); | 13852 site->SetElementsKindPayload(to_kind); |
| 13830 } | 13853 } |
| 13831 | 13854 |
| 13832 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( | 13855 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( |
| 13833 *constructor, type_info); | 13856 *constructor, site); |
| 13834 if (!maybe_array->To(&array)) return maybe_array; | 13857 if (!maybe_array->To(&array)) return maybe_array; |
| 13835 } else { | 13858 } else { |
| 13836 maybe_array = isolate->heap()->AllocateJSObject(*constructor); | 13859 maybe_array = isolate->heap()->AllocateJSObject(*constructor); |
| 13837 if (!maybe_array->To(&array)) return maybe_array; | 13860 if (!maybe_array->To(&array)) return maybe_array; |
| 13838 // We might need to transition to holey | 13861 // We might need to transition to holey |
| 13839 ElementsKind kind = constructor->initial_map()->elements_kind(); | 13862 ElementsKind kind = constructor->initial_map()->elements_kind(); |
| 13840 if (holey && !IsFastHoleyElementsKind(kind)) { | 13863 if (holey && !IsFastHoleyElementsKind(kind)) { |
| 13841 kind = GetHoleyElementsKind(kind); | 13864 kind = GetHoleyElementsKind(kind); |
| 13842 maybe_array = array->TransitionElementsKind(kind); | 13865 maybe_array = array->TransitionElementsKind(kind); |
| 13843 if (maybe_array->IsFailure()) return maybe_array; | 13866 if (maybe_array->IsFailure()) return maybe_array; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13972 // Handle last resort GC and make sure to allow future allocations | 13995 // Handle last resort GC and make sure to allow future allocations |
| 13973 // to grow the heap without causing GCs (if possible). | 13996 // to grow the heap without causing GCs (if possible). |
| 13974 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13997 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13975 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13998 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13976 "Runtime::PerformGC"); | 13999 "Runtime::PerformGC"); |
| 13977 } | 14000 } |
| 13978 } | 14001 } |
| 13979 | 14002 |
| 13980 | 14003 |
| 13981 } } // namespace v8::internal | 14004 } } // namespace v8::internal |
| OLD | NEW |