Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: src/runtime.cc

Issue 8914006: Create missing boilerplate for array literals instead of deoptimizing (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/array-literal-transitions.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 boilerplate->map()->unused_property_fields()); 427 boilerplate->map()->unused_property_fields());
428 } 428 }
429 429
430 return boilerplate; 430 return boilerplate;
431 } 431 }
432 432
433 433
434 static const int kSmiOnlyLiteralMinimumLength = 1024; 434 static const int kSmiOnlyLiteralMinimumLength = 1024;
435 435
436 436
437 static Handle<Object> CreateArrayLiteralBoilerplate( 437 // static
438 Handle<Object> Runtime::CreateArrayLiteralBoilerplate(
438 Isolate* isolate, 439 Isolate* isolate,
439 Handle<FixedArray> literals, 440 Handle<FixedArray> literals,
440 Handle<FixedArray> elements) { 441 Handle<FixedArray> elements) {
441 // Create the JSArray. 442 // Create the JSArray.
442 Handle<JSFunction> constructor( 443 Handle<JSFunction> constructor(
443 JSFunction::GlobalContextFromLiterals(*literals)->array_function()); 444 JSFunction::GlobalContextFromLiterals(*literals)->array_function());
444 Handle<JSArray> object = 445 Handle<JSArray> object =
445 Handle<JSArray>::cast(isolate->factory()->NewJSObject(constructor)); 446 Handle<JSArray>::cast(isolate->factory()->NewJSObject(constructor));
446 447
447 ElementsKind constant_elements_kind = 448 ElementsKind constant_elements_kind =
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 elements, 530 elements,
530 true, 531 true,
531 kHasNoFunctionLiteral); 532 kHasNoFunctionLiteral);
532 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: 533 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS:
533 return CreateObjectLiteralBoilerplate(isolate, 534 return CreateObjectLiteralBoilerplate(isolate,
534 literals, 535 literals,
535 elements, 536 elements,
536 false, 537 false,
537 kHasNoFunctionLiteral); 538 kHasNoFunctionLiteral);
538 case CompileTimeValue::ARRAY_LITERAL: 539 case CompileTimeValue::ARRAY_LITERAL:
539 return CreateArrayLiteralBoilerplate(isolate, literals, elements); 540 return Runtime::CreateArrayLiteralBoilerplate(
541 isolate, literals, elements);
540 default: 542 default:
541 UNREACHABLE(); 543 UNREACHABLE();
542 return Handle<Object>::null(); 544 return Handle<Object>::null();
543 } 545 }
544 } 546 }
545 547
546 548
547 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateObjectLiteral) { 549 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateObjectLiteral) {
548 HandleScope scope(isolate); 550 HandleScope scope(isolate);
549 ASSERT(args.length() == 4); 551 ASSERT(args.length() == 4);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { 601 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) {
600 HandleScope scope(isolate); 602 HandleScope scope(isolate);
601 ASSERT(args.length() == 3); 603 ASSERT(args.length() == 3);
602 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 604 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
603 CONVERT_SMI_ARG_CHECKED(literals_index, 1); 605 CONVERT_SMI_ARG_CHECKED(literals_index, 1);
604 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 606 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
605 607
606 // Check if boilerplate exists. If not, create it first. 608 // Check if boilerplate exists. If not, create it first.
607 Handle<Object> boilerplate(literals->get(literals_index), isolate); 609 Handle<Object> boilerplate(literals->get(literals_index), isolate);
608 if (*boilerplate == isolate->heap()->undefined_value()) { 610 if (*boilerplate == isolate->heap()->undefined_value()) {
609 boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements); 611 boilerplate =
612 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements);
610 if (boilerplate.is_null()) return Failure::Exception(); 613 if (boilerplate.is_null()) return Failure::Exception();
611 // Update the functions literal and return the boilerplate. 614 // Update the functions literal and return the boilerplate.
612 literals->set(literals_index, *boilerplate); 615 literals->set(literals_index, *boilerplate);
613 } 616 }
614 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate)); 617 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate));
615 } 618 }
616 619
617 620
618 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { 621 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) {
619 HandleScope scope(isolate); 622 HandleScope scope(isolate);
620 ASSERT(args.length() == 3); 623 ASSERT(args.length() == 3);
621 CONVERT_ARG_CHECKED(FixedArray, literals, 0); 624 CONVERT_ARG_CHECKED(FixedArray, literals, 0);
622 CONVERT_SMI_ARG_CHECKED(literals_index, 1); 625 CONVERT_SMI_ARG_CHECKED(literals_index, 1);
623 CONVERT_ARG_CHECKED(FixedArray, elements, 2); 626 CONVERT_ARG_CHECKED(FixedArray, elements, 2);
624 627
625 // Check if boilerplate exists. If not, create it first. 628 // Check if boilerplate exists. If not, create it first.
626 Handle<Object> boilerplate(literals->get(literals_index), isolate); 629 Handle<Object> boilerplate(literals->get(literals_index), isolate);
627 if (*boilerplate == isolate->heap()->undefined_value()) { 630 if (*boilerplate == isolate->heap()->undefined_value()) {
628 ASSERT(*elements != isolate->heap()->empty_fixed_array()); 631 ASSERT(*elements != isolate->heap()->empty_fixed_array());
629 boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements); 632 boilerplate =
633 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements);
630 if (boilerplate.is_null()) return Failure::Exception(); 634 if (boilerplate.is_null()) return Failure::Exception();
631 // Update the functions literal and return the boilerplate. 635 // Update the functions literal and return the boilerplate.
632 literals->set(literals_index, *boilerplate); 636 literals->set(literals_index, *boilerplate);
633 } 637 }
634 if (JSObject::cast(*boilerplate)->elements()->map() == 638 if (JSObject::cast(*boilerplate)->elements()->map() ==
635 isolate->heap()->fixed_cow_array_map()) { 639 isolate->heap()->fixed_cow_array_map()) {
636 isolate->counters()->cow_arrays_created_runtime()->Increment(); 640 isolate->counters()->cow_arrays_created_runtime()->Increment();
637 } 641 }
638 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate)); 642 return isolate->heap()->CopyJSObject(JSObject::cast(*boilerplate));
639 } 643 }
(...skipping 12941 matching lines...) Expand 10 before | Expand all | Expand 10 after
13581 } else { 13585 } else {
13582 // Handle last resort GC and make sure to allow future allocations 13586 // Handle last resort GC and make sure to allow future allocations
13583 // to grow the heap without causing GCs (if possible). 13587 // to grow the heap without causing GCs (if possible).
13584 isolate->counters()->gc_last_resort_from_js()->Increment(); 13588 isolate->counters()->gc_last_resort_from_js()->Increment();
13585 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13589 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13586 } 13590 }
13587 } 13591 }
13588 13592
13589 13593
13590 } } // namespace v8::internal 13594 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/array-literal-transitions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698