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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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<Object> boilerplate; |
492 if (*literal_site == isolate->heap()->undefined_value()) { | 493 if (*literal_site == isolate->heap()->undefined_value()) { |
493 boilerplate = CreateObjectLiteralBoilerplate(isolate, | 494 boilerplate = CreateObjectLiteralBoilerplate(isolate, |
494 literals, | 495 literals, |
495 constant_properties, | 496 constant_properties, |
496 should_have_fast_elements, | 497 should_have_fast_elements, |
497 has_function_literal); | 498 has_function_literal); |
498 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); | 499 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); |
499 site = isolate->factory()->NewAllocationSite(); | 500 |
500 site->set_transition_info(*boilerplate); | 501 AllocationSiteContext site_context(isolate, true); |
| 502 AllocationSiteCreationScope site_scope(&site_context); |
| 503 Handle<Object> same = JSObject::DeepWalk( |
| 504 Handle<JSObject>::cast(boilerplate), &site_context); |
| 505 site_scope.RecordTransitionInfo(same); |
| 506 site = site_context.top(); |
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<Object>(site->transition_info(), isolate); |
507 } | 513 } |
508 | 514 |
509 Handle<Object> copy = JSObject::DeepCopy(Handle<JSObject>::cast(boilerplate)); | 515 AllocationSiteContext site_context(isolate, true); |
| 516 AllocationSiteUsageScope site_scope(&site_context, site, boilerplate); |
| 517 Handle<Object> copy = JSObject::DeepCopy(Handle<JSObject>::cast(boilerplate), |
| 518 &site_context); |
510 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 519 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
511 return *copy; | 520 return *copy; |
512 } | 521 } |
513 | 522 |
514 | 523 |
515 static Handle<AllocationSite> GetLiteralAllocationSite( | 524 static Handle<AllocationSite> GetLiteralAllocationSite( |
516 Isolate* isolate, | 525 Isolate* isolate, |
517 Handle<FixedArray> literals, | 526 Handle<FixedArray> literals, |
518 int literals_index, | 527 int literals_index, |
519 Handle<FixedArray> elements) { | 528 Handle<FixedArray> elements) { |
520 // Check if boilerplate exists. If not, create it first. | 529 // Check if boilerplate exists. If not, create it first. |
521 Handle<Object> literal_site(literals->get(literals_index), isolate); | 530 Handle<Object> literal_site(literals->get(literals_index), isolate); |
522 Handle<AllocationSite> site; | 531 Handle<AllocationSite> site; |
523 if (*literal_site == isolate->heap()->undefined_value()) { | 532 if (*literal_site == isolate->heap()->undefined_value()) { |
524 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 533 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
525 Handle<Object> boilerplate = | 534 Handle<Object> boilerplate = |
526 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 535 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
527 if (boilerplate.is_null()) { | 536 if (boilerplate.is_null()) return Handle<AllocationSite>::null(); |
528 ASSERT(site.is_null()); | 537 |
529 return site; | 538 AllocationSiteContext site_context(isolate, true); |
530 } | 539 AllocationSiteCreationScope site_scope(&site_context); |
531 site = isolate->factory()->NewAllocationSite(); | 540 Handle<Object> same = JSObject::DeepWalk( |
532 site->set_transition_info(*boilerplate); | 541 Handle<JSObject>::cast(boilerplate), &site_context); |
| 542 site_scope.RecordTransitionInfo(same); |
| 543 site = site_context.top(); |
| 544 |
533 literals->set(literals_index, *site); | 545 literals->set(literals_index, *site); |
534 } else { | 546 } else { |
535 site = Handle<AllocationSite>::cast(literal_site); | 547 site = Handle<AllocationSite>::cast(literal_site); |
536 } | 548 } |
537 | 549 |
538 return site; | 550 return site; |
539 } | 551 } |
540 | 552 |
541 | 553 |
542 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { | 554 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { |
543 HandleScope scope(isolate); | 555 HandleScope scope(isolate); |
544 ASSERT(args.length() == 3); | 556 ASSERT(args.length() == 3); |
545 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 557 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
546 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 558 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
547 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 559 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
548 | 560 |
549 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 561 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
550 literals_index, elements); | 562 literals_index, elements); |
551 RETURN_IF_EMPTY_HANDLE(isolate, site); | 563 RETURN_IF_EMPTY_HANDLE(isolate, site); |
552 | 564 |
553 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); | 565 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); |
554 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate); | 566 AllocationSiteContext site_context(isolate, true); |
| 567 AllocationSiteUsageScope site_scope(&site_context, site, boilerplate); |
| 568 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate, &site_context); |
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 14081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14671 | 14684 |
14672 JSArray* array; | 14685 JSArray* array; |
14673 MaybeObject* maybe_array; | 14686 MaybeObject* maybe_array; |
14674 if (!type_info.is_null() && | 14687 if (!type_info.is_null() && |
14675 *type_info != isolate->heap()->undefined_value() && | 14688 *type_info != isolate->heap()->undefined_value() && |
14676 Cell::cast(*type_info)->value()->IsAllocationSite() && | 14689 Cell::cast(*type_info)->value()->IsAllocationSite() && |
14677 can_use_type_feedback) { | 14690 can_use_type_feedback) { |
14678 Handle<Cell> cell = Handle<Cell>::cast(type_info); | 14691 Handle<Cell> cell = Handle<Cell>::cast(type_info); |
14679 Handle<AllocationSite> site = Handle<AllocationSite>( | 14692 Handle<AllocationSite> site = Handle<AllocationSite>( |
14680 AllocationSite::cast(cell->value()), isolate); | 14693 AllocationSite::cast(cell->value()), isolate); |
14681 ASSERT(!site->IsLiteralSite()); | 14694 ASSERT(!site->SitePointsToLiteral()); |
14682 ElementsKind to_kind = site->GetElementsKind(); | 14695 ElementsKind to_kind = site->GetElementsKind(); |
14683 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 14696 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
14684 to_kind = GetHoleyElementsKind(to_kind); | 14697 to_kind = GetHoleyElementsKind(to_kind); |
14685 // Update the allocation site info to reflect the advice alteration. | 14698 // Update the allocation site info to reflect the advice alteration. |
14686 site->SetElementsKind(to_kind); | 14699 site->SetElementsKind(to_kind); |
14687 } | 14700 } |
14688 | 14701 |
14689 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( | 14702 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( |
14690 *constructor, site); | 14703 *constructor, site); |
14691 if (!maybe_array->To(&array)) return maybe_array; | 14704 if (!maybe_array->To(&array)) return maybe_array; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14827 // Handle last resort GC and make sure to allow future allocations | 14840 // Handle last resort GC and make sure to allow future allocations |
14828 // to grow the heap without causing GCs (if possible). | 14841 // to grow the heap without causing GCs (if possible). |
14829 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14842 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14830 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14843 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14831 "Runtime::PerformGC"); | 14844 "Runtime::PerformGC"); |
14832 } | 14845 } |
14833 } | 14846 } |
14834 | 14847 |
14835 | 14848 |
14836 } } // namespace v8::internal | 14849 } } // namespace v8::internal |
OLD | NEW |