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 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 HandleScope scope(isolate); | 480 HandleScope scope(isolate); |
| 480 ASSERT(args.length() == 4); | 481 ASSERT(args.length() == 4); |
| 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> boilerplate(literals->get(literals_index), isolate); | 490 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 490 if (*boilerplate == isolate->heap()->undefined_value()) { | 491 Handle<AllocationSite> site; |
| 492 Handle<Object> boilerplate; | |
| 493 if (*literal_site == isolate->heap()->undefined_value()) { | |
| 491 boilerplate = CreateObjectLiteralBoilerplate(isolate, | 494 boilerplate = CreateObjectLiteralBoilerplate(isolate, |
| 492 literals, | 495 literals, |
| 493 constant_properties, | 496 constant_properties, |
| 494 should_have_fast_elements, | 497 should_have_fast_elements, |
| 495 has_function_literal); | 498 has_function_literal); |
| 496 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); | 499 RETURN_IF_EMPTY_HANDLE(isolate, boilerplate); |
| 500 | |
| 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(); | |
| 507 | |
| 497 // Update the functions literal and return the boilerplate. | 508 // Update the functions literal and return the boilerplate. |
| 498 literals->set(literals_index, *boilerplate); | 509 literals->set(literals_index, *site); |
| 510 } else { | |
| 511 site = Handle<AllocationSite>::cast(literal_site); | |
| 512 boilerplate = Handle<Object>(site->transition_info(), isolate); | |
| 499 } | 513 } |
| 500 | 514 |
| 501 Handle<Object> copy = JSObject::DeepCopy(Handle<JSObject>::cast(boilerplate)); | 515 AllocationSiteContext site_context(isolate, true); |
| 516 AllocationSiteUsageScope site_scope(&site_context, site, boilerplate); | |
|
Hannes Payer (out of office)
2013/10/11 12:55:44
As discussed offline, right now we would emit meme
mvstanton
2013/10/11 13:41:47
Good catch. I added this TODO in HOptimizedGraphBu
| |
| 517 Handle<Object> copy = JSObject::DeepCopy(Handle<JSObject>::cast(boilerplate), | |
| 518 &site_context); | |
| 502 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 519 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
| 503 return *copy; | 520 return *copy; |
| 504 } | 521 } |
| 505 | 522 |
| 506 | 523 |
| 507 static Handle<AllocationSite> GetLiteralAllocationSite( | 524 static Handle<AllocationSite> GetLiteralAllocationSite( |
| 508 Isolate* isolate, | 525 Isolate* isolate, |
| 509 Handle<FixedArray> literals, | 526 Handle<FixedArray> literals, |
| 510 int literals_index, | 527 int literals_index, |
| 511 Handle<FixedArray> elements) { | 528 Handle<FixedArray> elements) { |
| 512 // Check if boilerplate exists. If not, create it first. | 529 // Check if boilerplate exists. If not, create it first. |
| 513 Handle<Object> literal_site(literals->get(literals_index), isolate); | 530 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 514 Handle<AllocationSite> site; | 531 Handle<AllocationSite> site; |
| 515 if (*literal_site == isolate->heap()->undefined_value()) { | 532 if (*literal_site == isolate->heap()->undefined_value()) { |
| 516 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 533 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 517 Handle<Object> boilerplate = | 534 Handle<Object> boilerplate = |
| 518 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 535 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 519 if (boilerplate.is_null()) { | 536 if (boilerplate.is_null()) return Handle<AllocationSite>::null(); |
| 520 ASSERT(site.is_null()); | 537 |
| 521 return site; | 538 AllocationSiteContext site_context(isolate, true); |
| 522 } | 539 AllocationSiteCreationScope site_scope(&site_context); |
| 523 site = isolate->factory()->NewAllocationSite(); | 540 Handle<Object> same = JSObject::DeepWalk( |
| 524 site->set_transition_info(*boilerplate); | 541 Handle<JSObject>::cast(boilerplate), &site_context); |
| 542 site_scope.RecordTransitionInfo(same); | |
| 543 site = site_context.top(); | |
| 544 | |
| 525 literals->set(literals_index, *site); | 545 literals->set(literals_index, *site); |
| 526 } else { | 546 } else { |
| 527 site = Handle<AllocationSite>::cast(literal_site); | 547 site = Handle<AllocationSite>::cast(literal_site); |
| 528 } | 548 } |
| 529 | 549 |
| 530 return site; | 550 return site; |
| 531 } | 551 } |
| 532 | 552 |
| 533 | 553 |
| 534 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { | 554 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { |
| 535 HandleScope scope(isolate); | 555 HandleScope scope(isolate); |
| 536 ASSERT(args.length() == 3); | 556 ASSERT(args.length() == 3); |
| 537 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 557 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 538 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 558 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 539 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 559 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 540 | 560 |
| 541 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 561 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 542 literals_index, elements); | 562 literals_index, elements); |
| 543 RETURN_IF_EMPTY_HANDLE(isolate, site); | 563 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 544 | 564 |
| 545 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); | 565 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); |
| 546 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); | |
| 547 RETURN_IF_EMPTY_HANDLE(isolate, copy); | 569 RETURN_IF_EMPTY_HANDLE(isolate, copy); |
| 548 return *copy; | 570 return *copy; |
| 549 } | 571 } |
| 550 | 572 |
| 551 | 573 |
| 552 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { | 574 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { |
| 553 HandleScope scope(isolate); | 575 HandleScope scope(isolate); |
| 554 ASSERT(args.length() == 3); | 576 ASSERT(args.length() == 3); |
| 555 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 577 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 556 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 578 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 557 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 579 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 558 | 580 |
| 559 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, | 581 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, |
| 560 literals_index, elements); | 582 literals_index, elements); |
| 561 RETURN_IF_EMPTY_HANDLE(isolate, site); | 583 RETURN_IF_EMPTY_HANDLE(isolate, site); |
| 562 | 584 |
| 563 JSObject* boilerplate = JSObject::cast(site->transition_info()); | 585 JSObject* boilerplate = JSObject::cast(site->transition_info()); |
| 564 if (boilerplate->elements()->map() == | 586 if (boilerplate->elements()->map() == |
| 565 isolate->heap()->fixed_cow_array_map()) { | 587 isolate->heap()->fixed_cow_array_map()) { |
| 566 isolate->counters()->cow_arrays_created_runtime()->Increment(); | 588 isolate->counters()->cow_arrays_created_runtime()->Increment(); |
| 567 } | 589 } |
| 568 | 590 |
| 569 AllocationSiteMode mode = AllocationSite::GetMode( | 591 if (AllocationSite::GetMode(boilerplate->GetElementsKind()) == |
| 570 boilerplate->GetElementsKind()); | 592 TRACK_ALLOCATION_SITE) { |
| 571 if (mode == TRACK_ALLOCATION_SITE) { | |
| 572 return isolate->heap()->CopyJSObject(boilerplate, *site); | 593 return isolate->heap()->CopyJSObject(boilerplate, *site); |
| 573 } | 594 } |
| 574 | 595 |
| 575 return isolate->heap()->CopyJSObject(boilerplate); | 596 return isolate->heap()->CopyJSObject(boilerplate); |
| 576 } | 597 } |
| 577 | 598 |
| 578 | 599 |
| 579 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { | 600 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { |
| 580 HandleScope scope(isolate); | 601 HandleScope scope(isolate); |
| 581 ASSERT(args.length() == 1); | 602 ASSERT(args.length() == 1); |
| (...skipping 14227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14809 // Handle last resort GC and make sure to allow future allocations | 14830 // Handle last resort GC and make sure to allow future allocations |
| 14810 // to grow the heap without causing GCs (if possible). | 14831 // to grow the heap without causing GCs (if possible). |
| 14811 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14832 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14812 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14833 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14813 "Runtime::PerformGC"); | 14834 "Runtime::PerformGC"); |
| 14814 } | 14835 } |
| 14815 } | 14836 } |
| 14816 | 14837 |
| 14817 | 14838 |
| 14818 } } // namespace v8::internal | 14839 } } // namespace v8::internal |
| OLD | NEW |