| 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 #include <limits> | 29 #include <limits> |
| 30 | 30 |
| 31 #include "v8.h" | 31 #include "v8.h" |
| 32 | 32 |
| 33 #include "accessors.h" | 33 #include "accessors.h" |
| 34 #include "allocation-site-scopes.h" |
| 34 #include "api.h" | 35 #include "api.h" |
| 35 #include "arguments.h" | 36 #include "arguments.h" |
| 36 #include "bootstrapper.h" | 37 #include "bootstrapper.h" |
| 37 #include "codegen.h" | 38 #include "codegen.h" |
| 38 #include "compilation-cache.h" | 39 #include "compilation-cache.h" |
| 39 #include "compiler.h" | 40 #include "compiler.h" |
| 40 #include "cpu.h" | 41 #include "cpu.h" |
| 41 #include "cpu-profiler.h" | 42 #include "cpu-profiler.h" |
| 42 #include "dateparser-inl.h" | 43 #include "dateparser-inl.h" |
| 43 #include "debug.h" | 44 #include "debug.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 482 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 482 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 483 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 483 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); | 484 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); |
| 484 CONVERT_SMI_ARG_CHECKED(flags, 3); | 485 CONVERT_SMI_ARG_CHECKED(flags, 3); |
| 485 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; | 486 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; |
| 486 bool has_function_literal = (flags & ObjectLiteral::kHasFunction) != 0; | 487 bool has_function_literal = (flags & ObjectLiteral::kHasFunction) != 0; |
| 487 | 488 |
| 488 // Check if boilerplate exists. If not, create it first. | 489 // Check if boilerplate exists. If not, create it first. |
| 489 Handle<Object> literal_site(literals->get(literals_index), isolate); | 490 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 490 Handle<AllocationSite> site; | 491 Handle<AllocationSite> site; |
| 491 Handle<Object> boilerplate; | 492 Handle<JSObject> boilerplate; |
| 492 if (*literal_site == isolate->heap()->undefined_value()) { | 493 if (*literal_site == isolate->heap()->undefined_value()) { |
| 493 boilerplate = CreateObjectLiteralBoilerplate(isolate, | 494 Handle<Object> raw_boilerplate = CreateObjectLiteralBoilerplate( |
| 494 literals, | 495 isolate, |
| 495 constant_properties, | 496 literals, |
| 496 should_have_fast_elements, | 497 constant_properties, |
| 497 has_function_literal); | 498 should_have_fast_elements, |
| 498 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); | 499 has_function_literal); |
| 499 site = isolate->factory()->NewAllocationSite(); | 500 RETURN_IF_EMPTY_HANDLE(isolate, raw_boilerplate); |
| 500 site->set_transition_info(*boilerplate); | 501 boilerplate = Handle<JSObject>::cast(raw_boilerplate); |
| 502 |
| 503 AllocationSiteCreationContext creation_context(isolate); |
| 504 site = creation_context.EnterNewScope(); |
| 505 JSObject::DeepWalk(boilerplate, &creation_context); |
| 506 creation_context.ExitScope(site, boilerplate); |
| 501 | 507 |
| 502 // Update the functions literal and return the boilerplate. | 508 // Update the functions literal and return the boilerplate. |
| 503 literals->set(literals_index, *site); | 509 literals->set(literals_index, *site); |
| 504 } else { | 510 } else { |
| 505 site = Handle<AllocationSite>::cast(literal_site); | 511 site = Handle<AllocationSite>::cast(literal_site); |
| 506 boilerplate = Handle<JSObject>(JSObject::cast(site->transition_info())); | 512 boilerplate = Handle<JSObject>(JSObject::cast(site->transition_info()), |
| 513 isolate); |
| 507 } | 514 } |
| 508 | 515 |
| 509 Handle<Object> copy = JSObject::DeepCopy(Handle<JSObject>::cast(boilerplate)); | 516 AllocationSiteUsageContext usage_context(isolate, site, true); |
| 517 usage_context.EnterNewScope(); |
| 518 Handle<Object> copy = JSObject::DeepCopy(boilerplate, &usage_context); |
| 519 usage_context.ExitScope(site, boilerplate); |
| 510 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 520 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
| 511 return *copy; | 521 return *copy; |
| 512 } | 522 } |
| 513 | 523 |
| 514 | 524 |
| 515 static Handle<AllocationSite> GetLiteralAllocationSite( | 525 static Handle<AllocationSite> GetLiteralAllocationSite( |
| 516 Isolate* isolate, | 526 Isolate* isolate, |
| 517 Handle<FixedArray> literals, | 527 Handle<FixedArray> literals, |
| 518 int literals_index, | 528 int literals_index, |
| 519 Handle<FixedArray> elements) { | 529 Handle<FixedArray> elements) { |
| 520 // Check if boilerplate exists. If not, create it first. | 530 // Check if boilerplate exists. If not, create it first. |
| 521 Handle<Object> literal_site(literals->get(literals_index), isolate); | 531 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 522 Handle<AllocationSite> site; | 532 Handle<AllocationSite> site; |
| 523 if (*literal_site == isolate->heap()->undefined_value()) { | 533 if (*literal_site == isolate->heap()->undefined_value()) { |
| 524 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 534 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 525 Handle<Object> boilerplate = | 535 Handle<Object> boilerplate = |
| 526 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 536 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 527 if (boilerplate.is_null()) { | 537 if (boilerplate.is_null()) return Handle<AllocationSite>::null(); |
| 528 ASSERT(site.is_null()); | 538 |
| 529 return site; | 539 AllocationSiteCreationContext creation_context(isolate); |
| 530 } | 540 site = creation_context.EnterNewScope(); |
| 531 site = isolate->factory()->NewAllocationSite(); | 541 JSObject::DeepWalk(Handle<JSObject>::cast(boilerplate), &creation_context); |
| 532 site->set_transition_info(*boilerplate); | 542 creation_context.ExitScope(site, Handle<JSObject>::cast(boilerplate)); |
| 543 |
| 533 literals->set(literals_index, *site); | 544 literals->set(literals_index, *site); |
| 534 } else { | 545 } else { |
| 535 site = Handle<AllocationSite>::cast(literal_site); | 546 site = Handle<AllocationSite>::cast(literal_site); |
| 536 } | 547 } |
| 537 | 548 |
| 538 return site; | 549 return site; |
| 539 } | 550 } |
| 540 | 551 |
| 541 | 552 |
| 542 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { | 553 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { |
| 543 HandleScope scope(isolate); | 554 HandleScope scope(isolate); |
| 544 ASSERT(args.length() == 3); | 555 ASSERT(args.length() == 3); |
| 545 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 556 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 546 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 557 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 547 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 558 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 548 | 559 |
| 549 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 560 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 550 literals_index, elements); | 561 literals_index, elements); |
| 551 RETURN_IF_EMPTY_HANDLE(isolate, site); | 562 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 552 | 563 |
| 553 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); | 564 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); |
| 554 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate); | 565 AllocationSiteUsageContext usage_context(isolate, site, true); |
| 566 usage_context.EnterNewScope(); |
| 567 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate, &usage_context); |
| 568 usage_context.ExitScope(site, boilerplate); |
| 555 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 569 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
| 556 return *copy; | 570 return *copy; |
| 557 } | 571 } |
| 558 | 572 |
| 559 | 573 |
| 560 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { | 574 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { |
| 561 HandleScope scope(isolate); | 575 HandleScope scope(isolate); |
| 562 ASSERT(args.length() == 3); | 576 ASSERT(args.length() == 3); |
| 563 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 577 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 564 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 578 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 565 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 579 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 566 | 580 |
| 567 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 581 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 568 literals_index, elements); | 582 literals_index, elements); |
| 569 RETURN_IF_EMPTY_HANDLE(isolate, site); | 583 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 570 | 584 |
| 571 JSObject* boilerplate = JSObject::cast(site->transition_info()); | 585 JSObject* boilerplate = JSObject::cast(site->transition_info()); |
| 572 if (boilerplate->elements()->map() == | 586 if (boilerplate->elements()->map() == |
| 573 isolate->heap()->fixed_cow_array_map()) { | 587 isolate->heap()->fixed_cow_array_map()) { |
| 574 isolate->counters()->cow_arrays_created_runtime()->Increment(); | 588 isolate->counters()->cow_arrays_created_runtime()->Increment(); |
| 575 } | 589 } |
| 576 | 590 |
| 577 AllocationSiteMode mode = AllocationSite::GetMode( | 591 if (AllocationSite::GetMode(boilerplate->GetElementsKind()) == |
| 578 boilerplate->GetElementsKind()); | 592 TRACK_ALLOCATION_SITE) { |
| 579 if (mode == TRACK_ALLOCATION_SITE) { | |
| 580 return isolate->heap()->CopyJSObject(boilerplate, *site); | 593 return isolate->heap()->CopyJSObject(boilerplate, *site); |
| 581 } | 594 } |
| 582 | 595 |
| 583 return isolate->heap()->CopyJSObject(boilerplate); | 596 return isolate->heap()->CopyJSObject(boilerplate); |
| 584 } | 597 } |
| 585 | 598 |
| 586 | 599 |
| 587 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { | 600 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { |
| 588 HandleScope scope(isolate); | 601 HandleScope scope(isolate); |
| 589 ASSERT(args.length() == 1); | 602 ASSERT(args.length() == 1); |
| (...skipping 14088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14678 | 14691 |
| 14679 JSArray* array; | 14692 JSArray* array; |
| 14680 MaybeObject* maybe_array; | 14693 MaybeObject* maybe_array; |
| 14681 if (!type_info.is_null() && | 14694 if (!type_info.is_null() && |
| 14682 *type_info != isolate->heap()->undefined_value() && | 14695 *type_info != isolate->heap()->undefined_value() && |
| 14683 Cell::cast(*type_info)->value()->IsAllocationSite() && | 14696 Cell::cast(*type_info)->value()->IsAllocationSite() && |
| 14684 can_use_type_feedback) { | 14697 can_use_type_feedback) { |
| 14685 Handle<Cell> cell = Handle<Cell>::cast(type_info); | 14698 Handle<Cell> cell = Handle<Cell>::cast(type_info); |
| 14686 Handle<AllocationSite> site = Handle<AllocationSite>( | 14699 Handle<AllocationSite> site = Handle<AllocationSite>( |
| 14687 AllocationSite::cast(cell->value()), isolate); | 14700 AllocationSite::cast(cell->value()), isolate); |
| 14688 ASSERT(!site->IsLiteralSite()); | 14701 ASSERT(!site->SitePointsToLiteral()); |
| 14689 ElementsKind to_kind = site->GetElementsKind(); | 14702 ElementsKind to_kind = site->GetElementsKind(); |
| 14690 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 14703 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| 14691 to_kind = GetHoleyElementsKind(to_kind); | 14704 to_kind = GetHoleyElementsKind(to_kind); |
| 14692 // Update the allocation site info to reflect the advice alteration. | 14705 // Update the allocation site info to reflect the advice alteration. |
| 14693 site->SetElementsKind(to_kind); | 14706 site->SetElementsKind(to_kind); |
| 14694 } | 14707 } |
| 14695 | 14708 |
| 14696 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( | 14709 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( |
| 14697 *constructor, site); | 14710 *constructor, site); |
| 14698 if (!maybe_array->To(&array)) return maybe_array; | 14711 if (!maybe_array->To(&array)) return maybe_array; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14834 // Handle last resort GC and make sure to allow future allocations | 14847 // Handle last resort GC and make sure to allow future allocations |
| 14835 // to grow the heap without causing GCs (if possible). | 14848 // to grow the heap without causing GCs (if possible). |
| 14836 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14849 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14837 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14850 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14838 "Runtime::PerformGC"); | 14851 "Runtime::PerformGC"); |
| 14839 } | 14852 } |
| 14840 } | 14853 } |
| 14841 | 14854 |
| 14842 | 14855 |
| 14843 } } // namespace v8::internal | 14856 } } // namespace v8::internal |
| OLD | NEW |