| 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 RETURN_IF_EMPTY_HANDLE(isolate, |
| 506 JSObject::DeepWalk(boilerplate, &creation_context)); |
| 507 creation_context.ExitScope(site, boilerplate); |
| 501 | 508 |
| 502 // Update the functions literal and return the boilerplate. | 509 // Update the functions literal and return the boilerplate. |
| 503 literals->set(literals_index, *site); | 510 literals->set(literals_index, *site); |
| 504 } else { | 511 } else { |
| 505 site = Handle<AllocationSite>::cast(literal_site); | 512 site = Handle<AllocationSite>::cast(literal_site); |
| 506 boilerplate = Handle<JSObject>(JSObject::cast(site->transition_info())); | 513 boilerplate = Handle<JSObject>(JSObject::cast(site->transition_info()), |
| 514 isolate); |
| 507 } | 515 } |
| 508 | 516 |
| 509 Handle<Object> copy = JSObject::DeepCopy(Handle<JSObject>::cast(boilerplate)); | 517 AllocationSiteUsageContext usage_context(isolate, site, true); |
| 518 usage_context.EnterNewScope(); |
| 519 Handle<Object> copy = JSObject::DeepCopy(boilerplate, &usage_context); |
| 520 usage_context.ExitScope(site, boilerplate); |
| 510 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 521 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
| 511 return *copy; | 522 return *copy; |
| 512 } | 523 } |
| 513 | 524 |
| 514 | 525 |
| 515 static Handle<AllocationSite> GetLiteralAllocationSite( | 526 static Handle<AllocationSite> GetLiteralAllocationSite( |
| 516 Isolate* isolate, | 527 Isolate* isolate, |
| 517 Handle<FixedArray> literals, | 528 Handle<FixedArray> literals, |
| 518 int literals_index, | 529 int literals_index, |
| 519 Handle<FixedArray> elements) { | 530 Handle<FixedArray> elements) { |
| 520 // Check if boilerplate exists. If not, create it first. | 531 // Check if boilerplate exists. If not, create it first. |
| 521 Handle<Object> literal_site(literals->get(literals_index), isolate); | 532 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 522 Handle<AllocationSite> site; | 533 Handle<AllocationSite> site; |
| 523 if (*literal_site == isolate->heap()->undefined_value()) { | 534 if (*literal_site == isolate->heap()->undefined_value()) { |
| 524 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 535 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 525 Handle<Object> boilerplate = | 536 Handle<Object> boilerplate = |
| 526 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 537 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 527 if (boilerplate.is_null()) { | 538 if (boilerplate.is_null()) return Handle<AllocationSite>::null(); |
| 528 ASSERT(site.is_null()); | 539 |
| 529 return site; | 540 AllocationSiteCreationContext creation_context(isolate); |
| 541 site = creation_context.EnterNewScope(); |
| 542 if (JSObject::DeepWalk(Handle<JSObject>::cast(boilerplate), |
| 543 &creation_context).is_null()) { |
| 544 return Handle<AllocationSite>::null(); |
| 530 } | 545 } |
| 531 site = isolate->factory()->NewAllocationSite(); | 546 creation_context.ExitScope(site, Handle<JSObject>::cast(boilerplate)); |
| 532 site->set_transition_info(*boilerplate); | 547 |
| 533 literals->set(literals_index, *site); | 548 literals->set(literals_index, *site); |
| 534 } else { | 549 } else { |
| 535 site = Handle<AllocationSite>::cast(literal_site); | 550 site = Handle<AllocationSite>::cast(literal_site); |
| 536 } | 551 } |
| 537 | 552 |
| 538 return site; | 553 return site; |
| 539 } | 554 } |
| 540 | 555 |
| 541 | 556 |
| 542 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { | 557 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { |
| 543 HandleScope scope(isolate); | 558 HandleScope scope(isolate); |
| 544 ASSERT(args.length() == 3); | 559 ASSERT(args.length() == 3); |
| 545 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 560 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 546 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 561 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 547 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 562 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 548 | 563 |
| 549 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 564 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 550 literals_index, elements); | 565 literals_index, elements); |
| 551 RETURN_IF_EMPTY_HANDLE(isolate, site); | 566 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 552 | 567 |
| 553 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); | 568 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); |
| 554 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate); | 569 AllocationSiteUsageContext usage_context(isolate, site, true); |
| 570 usage_context.EnterNewScope(); |
| 571 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate, &usage_context); |
| 572 usage_context.ExitScope(site, boilerplate); |
| 555 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 573 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
| 556 return *copy; | 574 return *copy; |
| 557 } | 575 } |
| 558 | 576 |
| 559 | 577 |
| 560 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { | 578 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { |
| 561 HandleScope scope(isolate); | 579 HandleScope scope(isolate); |
| 562 ASSERT(args.length() == 3); | 580 ASSERT(args.length() == 3); |
| 563 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 581 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 564 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 582 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 565 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 583 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 566 | 584 |
| 567 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 585 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 568 literals_index, elements); | 586 literals_index, elements); |
| 569 RETURN_IF_EMPTY_HANDLE(isolate, site); | 587 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 570 | 588 |
| 571 JSObject* boilerplate = JSObject::cast(site->transition_info()); | 589 JSObject* boilerplate = JSObject::cast(site->transition_info()); |
| 572 if (boilerplate->elements()->map() == | 590 if (boilerplate->elements()->map() == |
| 573 isolate->heap()->fixed_cow_array_map()) { | 591 isolate->heap()->fixed_cow_array_map()) { |
| 574 isolate->counters()->cow_arrays_created_runtime()->Increment(); | 592 isolate->counters()->cow_arrays_created_runtime()->Increment(); |
| 575 } | 593 } |
| 576 | 594 |
| 577 AllocationSiteMode mode = AllocationSite::GetMode( | 595 if (AllocationSite::GetMode(boilerplate->GetElementsKind()) == |
| 578 boilerplate->GetElementsKind()); | 596 TRACK_ALLOCATION_SITE) { |
| 579 if (mode == TRACK_ALLOCATION_SITE) { | |
| 580 return isolate->heap()->CopyJSObject(boilerplate, *site); | 597 return isolate->heap()->CopyJSObject(boilerplate, *site); |
| 581 } | 598 } |
| 582 | 599 |
| 583 return isolate->heap()->CopyJSObject(boilerplate); | 600 return isolate->heap()->CopyJSObject(boilerplate); |
| 584 } | 601 } |
| 585 | 602 |
| 586 | 603 |
| 587 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { | 604 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { |
| 588 HandleScope scope(isolate); | 605 HandleScope scope(isolate); |
| 589 ASSERT(args.length() == 1); | 606 ASSERT(args.length() == 1); |
| (...skipping 14088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14678 | 14695 |
| 14679 JSArray* array; | 14696 JSArray* array; |
| 14680 MaybeObject* maybe_array; | 14697 MaybeObject* maybe_array; |
| 14681 if (!type_info.is_null() && | 14698 if (!type_info.is_null() && |
| 14682 *type_info != isolate->heap()->undefined_value() && | 14699 *type_info != isolate->heap()->undefined_value() && |
| 14683 Cell::cast(*type_info)->value()->IsAllocationSite() && | 14700 Cell::cast(*type_info)->value()->IsAllocationSite() && |
| 14684 can_use_type_feedback) { | 14701 can_use_type_feedback) { |
| 14685 Handle<Cell> cell = Handle<Cell>::cast(type_info); | 14702 Handle<Cell> cell = Handle<Cell>::cast(type_info); |
| 14686 Handle<AllocationSite> site = Handle<AllocationSite>( | 14703 Handle<AllocationSite> site = Handle<AllocationSite>( |
| 14687 AllocationSite::cast(cell->value()), isolate); | 14704 AllocationSite::cast(cell->value()), isolate); |
| 14688 ASSERT(!site->IsLiteralSite()); | 14705 ASSERT(!site->SitePointsToLiteral()); |
| 14689 ElementsKind to_kind = site->GetElementsKind(); | 14706 ElementsKind to_kind = site->GetElementsKind(); |
| 14690 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 14707 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| 14691 to_kind = GetHoleyElementsKind(to_kind); | 14708 to_kind = GetHoleyElementsKind(to_kind); |
| 14692 // Update the allocation site info to reflect the advice alteration. | 14709 // Update the allocation site info to reflect the advice alteration. |
| 14693 site->SetElementsKind(to_kind); | 14710 site->SetElementsKind(to_kind); |
| 14694 } | 14711 } |
| 14695 | 14712 |
| 14696 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( | 14713 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( |
| 14697 *constructor, site); | 14714 *constructor, site); |
| 14698 if (!maybe_array->To(&array)) return maybe_array; | 14715 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 | 14851 // Handle last resort GC and make sure to allow future allocations |
| 14835 // to grow the heap without causing GCs (if possible). | 14852 // to grow the heap without causing GCs (if possible). |
| 14836 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14853 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14837 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14854 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14838 "Runtime::PerformGC"); | 14855 "Runtime::PerformGC"); |
| 14839 } | 14856 } |
| 14840 } | 14857 } |
| 14841 | 14858 |
| 14842 | 14859 |
| 14843 } } // namespace v8::internal | 14860 } } // namespace v8::internal |
| OLD | NEW |