Chromium Code Reviews| 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 | 501 |
| 502 | 502 |
| 503 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { | 503 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { |
| 504 HandleScope scope(isolate); | 504 HandleScope scope(isolate); |
| 505 ASSERT(args.length() == 3); | 505 ASSERT(args.length() == 3); |
| 506 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 506 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 507 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 507 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 508 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 508 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 509 | 509 |
| 510 // Check if boilerplate exists. If not, create it first. | 510 // Check if boilerplate exists. If not, create it first. |
| 511 Handle<Object> boilerplate(literals->get(literals_index), isolate); | 511 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 512 if (*boilerplate == isolate->heap()->undefined_value()) { | 512 Handle<AllocationSite> site; |
| 513 Handle<Object> boilerplate; | |
| 514 if (*literal_site == isolate->heap()->undefined_value()) { | |
| 513 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 515 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 514 boilerplate = | 516 boilerplate = |
| 515 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 517 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 516 if (boilerplate.is_null()) return Failure::Exception(); | 518 if (boilerplate.is_null()) return Failure::Exception(); |
| 519 site = isolate->factory()->NewAllocationSite(); | |
| 520 site->set_payload(*boilerplate); | |
| 517 // Update the functions literal and return the boilerplate. | 521 // Update the functions literal and return the boilerplate. |
| 518 literals->set(literals_index, *boilerplate); | 522 literals->set(literals_index, *site); |
| 523 } else { | |
| 524 site = Handle<AllocationSite>::cast(literal_site); | |
| 525 boilerplate = Handle<Object>(site->payload(), isolate); | |
| 519 } | 526 } |
| 527 | |
| 520 return JSObject::cast(*boilerplate)->DeepCopy(isolate); | 528 return JSObject::cast(*boilerplate)->DeepCopy(isolate); |
| 521 } | 529 } |
| 522 | 530 |
| 523 | 531 |
| 524 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { | 532 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { |
|
Hannes Payer (out of office)
2013/06/25 16:35:07
Can we refactor Runtime_CreateArrayLiteral and Run
mvstanton
2013/07/02 13:55:11
thanks, good advice! Done
| |
| 525 HandleScope scope(isolate); | 533 HandleScope scope(isolate); |
| 526 ASSERT(args.length() == 3); | 534 ASSERT(args.length() == 3); |
| 527 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 535 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 528 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 536 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 529 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 537 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 530 | 538 |
| 531 // Check if boilerplate exists. If not, create it first. | 539 // Check if boilerplate exists. If not, create it first. |
| 532 Handle<Object> boilerplate(literals->get(literals_index), isolate); | 540 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 533 if (*boilerplate == isolate->heap()->undefined_value()) { | 541 Handle<AllocationSite> site; |
| 542 Handle<Object> boilerplate; | |
| 543 if (*literal_site == isolate->heap()->undefined_value()) { | |
| 534 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 544 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 535 boilerplate = | 545 boilerplate = |
| 536 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 546 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 537 if (boilerplate.is_null()) return Failure::Exception(); | 547 if (boilerplate.is_null()) return Failure::Exception(); |
| 548 site = isolate->factory()->NewAllocationSite(); | |
| 549 site->set_payload(*boilerplate); | |
| 538 // Update the functions literal and return the boilerplate. | 550 // Update the functions literal and return the boilerplate. |
| 539 literals->set(literals_index, *boilerplate); | 551 literals->set(literals_index, *site); |
| 552 } else { | |
| 553 site = Handle<AllocationSite>::cast(literal_site); | |
| 554 boilerplate = Handle<Object>(site->payload(), isolate); | |
| 540 } | 555 } |
| 556 | |
| 541 if (JSObject::cast(*boilerplate)->elements()->map() == | 557 if (JSObject::cast(*boilerplate)->elements()->map() == |
| 542 isolate->heap()->fixed_cow_array_map()) { | 558 isolate->heap()->fixed_cow_array_map()) { |
| 543 isolate->counters()->cow_arrays_created_runtime()->Increment(); | 559 isolate->counters()->cow_arrays_created_runtime()->Increment(); |
| 544 } | 560 } |
| 545 | 561 |
| 546 JSObject* boilerplate_object = JSObject::cast(*boilerplate); | 562 JSObject* boilerplate_object = JSObject::cast(*boilerplate); |
| 547 AllocationSiteMode mode = AllocationSiteInfo::GetMode( | 563 AllocationSiteMode mode = AllocationSite::GetMode( |
| 548 boilerplate_object->GetElementsKind()); | 564 boilerplate_object->GetElementsKind()); |
| 549 if (mode == TRACK_ALLOCATION_SITE) { | 565 if (mode == TRACK_ALLOCATION_SITE) { |
| 550 return isolate->heap()->CopyJSObjectWithAllocationSite(boilerplate_object); | 566 return isolate->heap()->CopyJSObjectWithAllocationSite( |
| 567 boilerplate_object, *site); | |
| 551 } | 568 } |
| 552 | 569 |
| 553 return isolate->heap()->CopyJSObject(boilerplate_object); | 570 return isolate->heap()->CopyJSObject(boilerplate_object); |
| 554 } | 571 } |
| 555 | 572 |
| 556 | 573 |
| 557 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { | 574 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { |
| 558 HandleScope scope(isolate); | 575 HandleScope scope(isolate); |
| 559 ASSERT(args.length() == 1); | 576 ASSERT(args.length() == 1); |
| 560 Handle<Object> name(args[0], isolate); | 577 Handle<Object> name(args[0], isolate); |
| (...skipping 4409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4970 | 4987 |
| 4971 RUNTIME_FUNCTION(MaybeObject*, Runtime_StoreArrayLiteralElement) { | 4988 RUNTIME_FUNCTION(MaybeObject*, Runtime_StoreArrayLiteralElement) { |
| 4972 HandleScope scope(isolate); | 4989 HandleScope scope(isolate); |
| 4973 RUNTIME_ASSERT(args.length() == 5); | 4990 RUNTIME_ASSERT(args.length() == 5); |
| 4974 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 4991 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 4975 CONVERT_SMI_ARG_CHECKED(store_index, 1); | 4992 CONVERT_SMI_ARG_CHECKED(store_index, 1); |
| 4976 Handle<Object> value = args.at<Object>(2); | 4993 Handle<Object> value = args.at<Object>(2); |
| 4977 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 3); | 4994 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 3); |
| 4978 CONVERT_SMI_ARG_CHECKED(literal_index, 4); | 4995 CONVERT_SMI_ARG_CHECKED(literal_index, 4); |
| 4979 | 4996 |
| 4980 Object* raw_boilerplate_object = literals->get(literal_index); | 4997 Object* raw_literal_cell = literals->get(literal_index); |
| 4981 Handle<JSArray> boilerplate_object(JSArray::cast(raw_boilerplate_object)); | 4998 JSArray* boilerplate = NULL; |
| 4999 if (raw_literal_cell->IsAllocationSite()) { | |
| 5000 AllocationSite* site = AllocationSite::cast(raw_literal_cell); | |
| 5001 boilerplate = JSArray::cast(site->payload()); | |
| 5002 } else { | |
| 5003 boilerplate = JSArray::cast(raw_literal_cell); | |
| 5004 } | |
| 5005 Handle<JSArray> boilerplate_object(boilerplate); | |
| 4982 ElementsKind elements_kind = object->GetElementsKind(); | 5006 ElementsKind elements_kind = object->GetElementsKind(); |
| 4983 ASSERT(IsFastElementsKind(elements_kind)); | 5007 ASSERT(IsFastElementsKind(elements_kind)); |
| 4984 // Smis should never trigger transitions. | 5008 // Smis should never trigger transitions. |
| 4985 ASSERT(!value->IsSmi()); | 5009 ASSERT(!value->IsSmi()); |
| 4986 | 5010 |
| 4987 if (value->IsNumber()) { | 5011 if (value->IsNumber()) { |
| 4988 ASSERT(IsFastSmiElementsKind(elements_kind)); | 5012 ASSERT(IsFastSmiElementsKind(elements_kind)); |
| 4989 ElementsKind transitioned_kind = IsFastHoleyElementsKind(elements_kind) | 5013 ElementsKind transitioned_kind = IsFastHoleyElementsKind(elements_kind) |
| 4990 ? FAST_HOLEY_DOUBLE_ELEMENTS | 5014 ? FAST_HOLEY_DOUBLE_ELEMENTS |
| 4991 : FAST_DOUBLE_ELEMENTS; | 5015 : FAST_DOUBLE_ELEMENTS; |
| (...skipping 8476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13468 } else { | 13492 } else { |
| 13469 // Non-smi length argument produces a dictionary | 13493 // Non-smi length argument produces a dictionary |
| 13470 can_use_type_feedback = false; | 13494 can_use_type_feedback = false; |
| 13471 } | 13495 } |
| 13472 } | 13496 } |
| 13473 | 13497 |
| 13474 JSArray* array; | 13498 JSArray* array; |
| 13475 MaybeObject* maybe_array; | 13499 MaybeObject* maybe_array; |
| 13476 if (!type_info.is_null() && | 13500 if (!type_info.is_null() && |
| 13477 *type_info != isolate->heap()->undefined_value() && | 13501 *type_info != isolate->heap()->undefined_value() && |
| 13478 JSGlobalPropertyCell::cast(*type_info)->value()->IsSmi() && | 13502 AllocationSite::cast(*type_info)->payload()->IsSmi() && |
| 13479 can_use_type_feedback) { | 13503 can_use_type_feedback) { |
| 13480 JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(*type_info); | 13504 Handle<AllocationSite> site = Handle<AllocationSite>::cast(type_info); |
| 13481 Smi* smi = Smi::cast(cell->value()); | 13505 ASSERT(!site->IsLiteralSite()); |
| 13482 ElementsKind to_kind = static_cast<ElementsKind>(smi->value()); | 13506 ElementsKind to_kind = site->GetElementsKindPayload(); |
| 13483 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 13507 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| 13484 to_kind = GetHoleyElementsKind(to_kind); | 13508 to_kind = GetHoleyElementsKind(to_kind); |
| 13485 // Update the allocation site info to reflect the advice alteration. | 13509 // Update the allocation site info to reflect the advice alteration. |
| 13486 cell->set_value(Smi::FromInt(to_kind)); | 13510 site->SetElementsKindPayload(to_kind); |
| 13487 } | 13511 } |
| 13488 | 13512 |
| 13489 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( | 13513 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( |
| 13490 *constructor, type_info); | 13514 *constructor, site); |
| 13491 if (!maybe_array->To(&array)) return maybe_array; | 13515 if (!maybe_array->To(&array)) return maybe_array; |
| 13492 } else { | 13516 } else { |
| 13493 maybe_array = isolate->heap()->AllocateJSObject(*constructor); | 13517 maybe_array = isolate->heap()->AllocateJSObject(*constructor); |
| 13494 if (!maybe_array->To(&array)) return maybe_array; | 13518 if (!maybe_array->To(&array)) return maybe_array; |
| 13495 // We might need to transition to holey | 13519 // We might need to transition to holey |
| 13496 ElementsKind kind = constructor->initial_map()->elements_kind(); | 13520 ElementsKind kind = constructor->initial_map()->elements_kind(); |
| 13497 if (holey && !IsFastHoleyElementsKind(kind)) { | 13521 if (holey && !IsFastHoleyElementsKind(kind)) { |
| 13498 kind = GetHoleyElementsKind(kind); | 13522 kind = GetHoleyElementsKind(kind); |
| 13499 maybe_array = array->TransitionElementsKind(kind); | 13523 maybe_array = array->TransitionElementsKind(kind); |
| 13500 if (maybe_array->IsFailure()) return maybe_array; | 13524 if (maybe_array->IsFailure()) return maybe_array; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13629 // Handle last resort GC and make sure to allow future allocations | 13653 // Handle last resort GC and make sure to allow future allocations |
| 13630 // to grow the heap without causing GCs (if possible). | 13654 // to grow the heap without causing GCs (if possible). |
| 13631 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13655 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13632 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13656 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13633 "Runtime::PerformGC"); | 13657 "Runtime::PerformGC"); |
| 13634 } | 13658 } |
| 13635 } | 13659 } |
| 13636 | 13660 |
| 13637 | 13661 |
| 13638 } } // namespace v8::internal | 13662 } } // namespace v8::internal |
| OLD | NEW |