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

Side by Side Diff: src/lithium.cc

Issue 93803003: Fixed Lithium environment generation bug for captured objects (created (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Move common code from LChunkBuilder into a (new) base class Created 7 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/lithium.h ('k') | src/mips/lithium-mips.h » ('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 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 spill_slot_count_ += 2; 456 spill_slot_count_ += 2;
457 } else { 457 } else {
458 spill_slot_count_++; 458 spill_slot_count_++;
459 } 459 }
460 } 460 }
461 iterator.Advance(); 461 iterator.Advance();
462 } 462 }
463 } 463 }
464 464
465 465
466 LEnvironment* LChunkBuilderBase::CreateEnvironment(
467 HEnvironment* hydrogen_env,
468 int* argument_index_accumulator,
469 ZoneList<HValue*>* objects_to_materialize) {
470 if (hydrogen_env == NULL) return NULL;
471
472 LEnvironment* outer = CreateEnvironment(hydrogen_env->outer(),
473 argument_index_accumulator,
474 objects_to_materialize);
475 BailoutId ast_id = hydrogen_env->ast_id();
476 ASSERT(!ast_id.IsNone() ||
477 hydrogen_env->frame_type() != JS_FUNCTION);
478 int value_count = hydrogen_env->length() - hydrogen_env->specials_count();
479 LEnvironment* result =
480 new(zone()) LEnvironment(hydrogen_env->closure(),
481 hydrogen_env->frame_type(),
482 ast_id,
483 hydrogen_env->parameter_count(),
484 argument_count_,
485 value_count,
486 outer,
487 hydrogen_env->entry(),
488 zone());
489 int argument_index = *argument_index_accumulator;
490
491 // Store the environment description into the environment
492 // (with holes for nested objects)
493 for (int i = 0; i < hydrogen_env->length(); ++i) {
494 if (hydrogen_env->is_special_index(i)) continue;
495
496 LOperand* op;
497 HValue* value = hydrogen_env->values()->at(i);
498 if (value->IsArgumentsObject() || value->IsCapturedObject()) {
499 op = LEnvironment::materialization_marker();
500 } else if (value->IsPushArgument()) {
501 op = new(zone()) LArgument(argument_index++);
502 } else {
503 op = UseAny(value);
504 }
505 result->AddValue(op,
506 value->representation(),
507 value->CheckFlag(HInstruction::kUint32));
508 }
509
510 // Recursively store the nested objects into the environment
511 for (int i = 0; i < hydrogen_env->length(); ++i) {
512 if (hydrogen_env->is_special_index(i)) continue;
513
514 HValue* value = hydrogen_env->values()->at(i);
515 if (value->IsArgumentsObject() || value->IsCapturedObject()) {
516 AddObjectToMaterialize(value, objects_to_materialize, result);
517 }
518 }
519
520 if (hydrogen_env->frame_type() == JS_FUNCTION) {
521 *argument_index_accumulator = argument_index;
522 }
523
524 return result;
525 }
526
527
528 // Add an object to the supplied environment and object materialization list.
529 //
530 // Notes:
531 //
532 // We are building three lists here:
533 //
534 // 1. In the result->object_mapping_ list (added to by the
535 // LEnvironment::Add*Object methods), we store the lengths (number
Michael Starzinger 2014/01/07 14:38:35 nit: Indentation of comments is off.
536 // of fields) of the captured objects in depth-first traversal order, or
537 // in case of duplicated objects, we store the index to the duplicate object
538 // (with a tag to differentiate between captured and duplicated objects).
539 //
540 // 2. The object fields are stored in the result->values_ list
541 // (added to by the LEnvironment.AddValue method) sequentially as lists
542 // of fields with holes for nested objects (the holes will be expanded
543 // later by LCodegen::AddToTranslation according to the
544 // LEnvironment.object_mapping_ list).
545 //
546 // 3. The auxiliary objects_to_materialize array stores the hydrogen values
547 // in the same order as result->object_mapping_ list. This is used
548 // to detect duplicate values and calculate the corresponding object index.
549 void LChunkBuilderBase::AddObjectToMaterialize(HValue* value,
550 ZoneList<HValue*>* objects_to_materialize, LEnvironment* result) {
551 int object_index = objects_to_materialize->length();
552 // Store the hydrogen value into the de-duplication array
553 objects_to_materialize->Add(value, zone());
554 // Find out whether we are storing a duplicated value
555 int previously_materialized_object = -1;
556 for (int prev = 0; prev < object_index; ++prev) {
557 if (objects_to_materialize->at(prev) == value) {
558 previously_materialized_object = prev;
559 break;
560 }
561 }
562 // Store the captured object length (or duplicated object index)
563 // into the environment. For duplicated objects, we stop here.
564 int length = value->OperandCount();
565 bool is_arguments = value->IsArgumentsObject();
566 if (previously_materialized_object >= 0) {
567 result->AddDuplicateObject(previously_materialized_object);
568 return;
569 } else {
570 result->AddNewObject(is_arguments ? length - 1 : length, is_arguments);
571 }
572 // Store the captured object's fields into the environment
573 for (int i = is_arguments ? 1 : 0; i < length; ++i) {
574 LOperand* op;
575 HValue* arg_value = value->OperandAt(i);
576 if (arg_value->IsArgumentsObject() || arg_value->IsCapturedObject()) {
577 // Insert a hole for nested objects
578 op = LEnvironment::materialization_marker();
579 } else {
580 ASSERT(!arg_value->IsPushArgument());
581 // For ordinary values, tell the register allocator we need the value
582 // to be alive here
583 op = UseAny(arg_value);
584 }
585 result->AddValue(op,
586 arg_value->representation(),
587 arg_value->CheckFlag(HInstruction::kUint32));
588 }
589 // Recursively store all the nested captured objects into the environment
590 for (int i = is_arguments ? 1 : 0; i < length; ++i) {
591 HValue* arg_value = value->OperandAt(i);
592 if (arg_value->IsArgumentsObject() || arg_value->IsCapturedObject()) {
593 AddObjectToMaterialize(arg_value, objects_to_materialize, result);
594 }
595 }
596 }
597
598
466 LInstruction* LChunkBuilder::CheckElideControlInstruction( 599 LInstruction* LChunkBuilder::CheckElideControlInstruction(
467 HControlInstruction* instr) { 600 HControlInstruction* instr) {
468 HBasicBlock* successor; 601 HBasicBlock* successor;
469 if (!instr->KnownSuccessorBlock(&successor)) return NULL; 602 if (!instr->KnownSuccessorBlock(&successor)) return NULL;
470 return new(zone()) LGoto(successor); 603 return new(zone()) LGoto(successor);
471 } 604 }
472 605
473 606
474 LPhase::~LPhase() { 607 LPhase::~LPhase() {
475 if (ShouldProduceTraceOutput()) { 608 if (ShouldProduceTraceOutput()) {
476 isolate()->GetHTracer()->TraceLithium(name(), chunk_); 609 isolate()->GetHTracer()->TraceLithium(name(), chunk_);
477 } 610 }
478 } 611 }
479 612
480 613
481 } } // namespace v8::internal 614 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/lithium.h ('k') | src/mips/lithium-mips.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698