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

Side by Side Diff: src/deoptimizer.cc

Issue 2692753004: [turbofan] escape analysis supports arguments object and rest elements (Closed)
Patch Set: replaced obscure for-loop Created 3 years, 10 months 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/deoptimizer.h" 5 #include "src/deoptimizer.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/ast/prettyprinter.h" 10 #include "src/ast/prettyprinter.h"
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 701
702 BailoutId node_id = input_data->AstId(bailout_id_); 702 BailoutId node_id = input_data->AstId(bailout_id_);
703 ByteArray* translations = input_data->TranslationByteArray(); 703 ByteArray* translations = input_data->TranslationByteArray();
704 unsigned translation_index = 704 unsigned translation_index =
705 input_data->TranslationIndex(bailout_id_)->value(); 705 input_data->TranslationIndex(bailout_id_)->value();
706 706
707 TranslationIterator state_iterator(translations, translation_index); 707 TranslationIterator state_iterator(translations, translation_index);
708 translated_state_.Init( 708 translated_state_.Init(
709 input_->GetFramePointerAddress(), &state_iterator, 709 input_->GetFramePointerAddress(), &state_iterator,
710 input_data->LiteralArray(), input_->GetRegisterValues(), 710 input_data->LiteralArray(), input_->GetRegisterValues(),
711 trace_scope_ == nullptr ? nullptr : trace_scope_->file()); 711 trace_scope_ == nullptr ? nullptr : trace_scope_->file(),
712 function_ ? function_->shared()->internal_formal_parameter_count() : 0);
712 713
713 // Do the input frame to output frame(s) translation. 714 // Do the input frame to output frame(s) translation.
714 size_t count = translated_state_.frames().size(); 715 size_t count = translated_state_.frames().size();
715 // If we are supposed to go to the catch handler, find the catching frame 716 // If we are supposed to go to the catch handler, find the catching frame
716 // for the catch and make sure we only deoptimize upto that frame. 717 // for the catch and make sure we only deoptimize upto that frame.
717 if (deoptimizing_throw_) { 718 if (deoptimizing_throw_) {
718 size_t catch_handler_frame_index = count; 719 size_t catch_handler_frame_index = count;
719 for (size_t i = count; i-- > 0;) { 720 for (size_t i = count; i-- > 0;) {
720 catch_handler_pc_offset_ = LookupCatchHandler( 721 catch_handler_pc_offset_ = LookupCatchHandler(
721 &(translated_state_.frames()[i]), &catch_handler_data_); 722 &(translated_state_.frames()[i]), &catch_handler_data_);
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 buffer_->Add(COMPILED_STUB_FRAME); 2395 buffer_->Add(COMPILED_STUB_FRAME);
2395 buffer_->Add(height); 2396 buffer_->Add(height);
2396 } 2397 }
2397 2398
2398 2399
2399 void Translation::BeginArgumentsObject(int args_length) { 2400 void Translation::BeginArgumentsObject(int args_length) {
2400 buffer_->Add(ARGUMENTS_OBJECT); 2401 buffer_->Add(ARGUMENTS_OBJECT);
2401 buffer_->Add(args_length); 2402 buffer_->Add(args_length);
2402 } 2403 }
2403 2404
2405 void Translation::ArgumentsElements(int skip) {
2406 buffer_->Add(ARGUMENTS_ELEMENTS);
2407 buffer_->Add(skip);
2408 }
2404 2409
2405 void Translation::BeginCapturedObject(int length) { 2410 void Translation::BeginCapturedObject(int length) {
2406 buffer_->Add(CAPTURED_OBJECT); 2411 buffer_->Add(CAPTURED_OBJECT);
2407 buffer_->Add(length); 2412 buffer_->Add(length);
2408 } 2413 }
2409 2414
2410 2415
2411 void Translation::DuplicateObject(int object_index) { 2416 void Translation::DuplicateObject(int object_index) {
2412 buffer_->Add(DUPLICATED_OBJECT); 2417 buffer_->Add(DUPLICATED_OBJECT);
2413 buffer_->Add(object_index); 2418 buffer_->Add(object_index);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 case COMPILED_STUB_FRAME: 2532 case COMPILED_STUB_FRAME:
2528 case TAIL_CALLER_FRAME: 2533 case TAIL_CALLER_FRAME:
2529 return 1; 2534 return 1;
2530 case BEGIN: 2535 case BEGIN:
2531 case ARGUMENTS_ADAPTOR_FRAME: 2536 case ARGUMENTS_ADAPTOR_FRAME:
2532 return 2; 2537 return 2;
2533 case JS_FRAME: 2538 case JS_FRAME:
2534 case INTERPRETED_FRAME: 2539 case INTERPRETED_FRAME:
2535 case CONSTRUCT_STUB_FRAME: 2540 case CONSTRUCT_STUB_FRAME:
2536 return 3; 2541 return 3;
2542 case ARGUMENTS_ELEMENTS:
2543 return 1;
2537 } 2544 }
2538 FATAL("Unexpected translation type"); 2545 FATAL("Unexpected translation type");
2539 return -1; 2546 return -1;
2540 } 2547 }
2541 2548
2542 2549
2543 #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) 2550 #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
2544 2551
2545 const char* Translation::StringFor(Opcode opcode) { 2552 const char* Translation::StringFor(Opcode opcode) {
2546 #define TRANSLATION_OPCODE_CASE(item) case item: return #item; 2553 #define TRANSLATION_OPCODE_CASE(item) case item: return #item;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 2792
2786 // static 2793 // static
2787 TranslatedValue TranslatedValue::NewArgumentsObject(TranslatedState* container, 2794 TranslatedValue TranslatedValue::NewArgumentsObject(TranslatedState* container,
2788 int length, 2795 int length,
2789 int object_index) { 2796 int object_index) {
2790 TranslatedValue slot(container, kArgumentsObject); 2797 TranslatedValue slot(container, kArgumentsObject);
2791 slot.materialization_info_ = {object_index, length}; 2798 slot.materialization_info_ = {object_index, length};
2792 return slot; 2799 return slot;
2793 } 2800 }
2794 2801
2795
2796 // static 2802 // static
2797 TranslatedValue TranslatedValue::NewDeferredObject(TranslatedState* container, 2803 TranslatedValue TranslatedValue::NewDeferredObject(TranslatedState* container,
2798 int length, 2804 int length,
2799 int object_index) { 2805 int object_index) {
2800 TranslatedValue slot(container, kCapturedObject); 2806 TranslatedValue slot(container, kCapturedObject);
2801 slot.materialization_info_ = {object_index, length}; 2807 slot.materialization_info_ = {object_index, length};
2802 return slot; 2808 return slot;
2803 } 2809 }
2804 2810
2805 2811
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 PrintF(trace_file, 3301 PrintF(trace_file,
3296 " reading compiler stub frame => height=%d; inputs:\n", height); 3302 " reading compiler stub frame => height=%d; inputs:\n", height);
3297 } 3303 }
3298 return TranslatedFrame::CompiledStubFrame(height, 3304 return TranslatedFrame::CompiledStubFrame(height,
3299 literal_array->GetIsolate()); 3305 literal_array->GetIsolate());
3300 } 3306 }
3301 3307
3302 case Translation::BEGIN: 3308 case Translation::BEGIN:
3303 case Translation::DUPLICATED_OBJECT: 3309 case Translation::DUPLICATED_OBJECT:
3304 case Translation::ARGUMENTS_OBJECT: 3310 case Translation::ARGUMENTS_OBJECT:
3311 case Translation::ARGUMENTS_ELEMENTS:
3305 case Translation::CAPTURED_OBJECT: 3312 case Translation::CAPTURED_OBJECT:
3306 case Translation::REGISTER: 3313 case Translation::REGISTER:
3307 case Translation::INT32_REGISTER: 3314 case Translation::INT32_REGISTER:
3308 case Translation::UINT32_REGISTER: 3315 case Translation::UINT32_REGISTER:
3309 case Translation::BOOL_REGISTER: 3316 case Translation::BOOL_REGISTER:
3310 case Translation::FLOAT_REGISTER: 3317 case Translation::FLOAT_REGISTER:
3311 case Translation::DOUBLE_REGISTER: 3318 case Translation::DOUBLE_REGISTER:
3312 case Translation::STACK_SLOT: 3319 case Translation::STACK_SLOT:
3313 case Translation::INT32_STACK_SLOT: 3320 case Translation::INT32_STACK_SLOT:
3314 case Translation::UINT32_STACK_SLOT: 3321 case Translation::UINT32_STACK_SLOT:
(...skipping 15 matching lines...) Expand all
3330 while (values_to_skip > 0) { 3337 while (values_to_skip > 0) {
3331 // Consume the current element. 3338 // Consume the current element.
3332 values_to_skip--; 3339 values_to_skip--;
3333 // Add all the children. 3340 // Add all the children.
3334 values_to_skip += (*iter)->GetChildrenCount(); 3341 values_to_skip += (*iter)->GetChildrenCount();
3335 3342
3336 (*iter)++; 3343 (*iter)++;
3337 } 3344 }
3338 } 3345 }
3339 3346
3347 void TranslatedState::CreateArgumentsElementsTranslatedValues(
3348 int frame_index, Address input_frame_pointer, int skip) {
3349 CHECK(0 <= skip && skip <= formal_parameter_count_);
3350 TranslatedFrame& frame = frames_[frame_index];
3351
3352 Address parent_frame_pointer = *reinterpret_cast<Address*>(
3353 input_frame_pointer + StandardFrameConstants::kCallerFPOffset);
3354 Object* parent_frame_type = *reinterpret_cast<Object**>(
3355 parent_frame_pointer + CommonFrameConstants::kContextOrFrameTypeOffset);
3356 int length;
3357 Address arguments_frame;
3358 if (parent_frame_type == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)) {
3359 length = Smi::cast(*reinterpret_cast<Object**>(
3360 parent_frame_pointer +
3361 ArgumentsAdaptorFrameConstants::kLengthOffset))
3362 ->value();
3363 arguments_frame = parent_frame_pointer;
3364 } else {
3365 length = formal_parameter_count_;
3366 arguments_frame = input_frame_pointer;
3367 }
3368
3369 length = std::max(0, length - skip);
Jarin 2017/02/15 16:17:15 This needs explanation.
3370
3371 int object_index = static_cast<int>(object_positions_.size());
3372 int value_index = static_cast<int>(frame.values_.size());
3373 object_positions_.push_back({
3374 frame_index,
Jarin 2017/02/15 16:17:15 Missing value_index.
3375 });
3376 static_assert(FixedArray::kHeaderSize / kPointerSize == 2, "");
3377 frame.Add(TranslatedValue::NewDeferredObject(this, length + 2, object_index));
3378
3379 frame.Add(
3380 TranslatedValue::NewTagged(this, isolate_->heap()->fixed_array_map()));
3381 frame.Add(TranslatedValue::NewInt32(this, length));
3382
3383 for (int i = length - 1; i >= 0; --i) {
3384 Address argument_slot = arguments_frame +
3385 CommonFrameConstants::kFixedFrameSizeAboveFp +
3386 i * kPointerSize;
3387 frame.Add(TranslatedValue::NewTagged(
3388 this, *reinterpret_cast<Object**>(argument_slot)));
3389 }
3390 }
3340 3391
3341 // We can't intermix stack decoding and allocations because 3392 // We can't intermix stack decoding and allocations because
3342 // deoptimization infrastracture is not GC safe. 3393 // deoptimization infrastracture is not GC safe.
3343 // Thus we build a temporary structure in malloced space. 3394 // Thus we build a temporary structure in malloced space.
Jarin 2017/02/15 16:17:15 Add a line that explains what is the return value.
3344 TranslatedValue TranslatedState::CreateNextTranslatedValue( 3395 int TranslatedState::CreateNextTranslatedValue(
3345 int frame_index, int value_index, TranslationIterator* iterator, 3396 int frame_index, TranslationIterator* iterator, FixedArray* literal_array,
3346 FixedArray* literal_array, Address fp, RegisterValues* registers, 3397 Address fp, RegisterValues* registers, Address input_frame_pointer,
3347 FILE* trace_file) { 3398 FILE* trace_file) {
3348 disasm::NameConverter converter; 3399 disasm::NameConverter converter;
3349 3400
3401 TranslatedFrame& frame = frames_[frame_index];
3402 int value_index = static_cast<int>(frame.values_.size());
3403
3350 Translation::Opcode opcode = 3404 Translation::Opcode opcode =
3351 static_cast<Translation::Opcode>(iterator->Next()); 3405 static_cast<Translation::Opcode>(iterator->Next());
3352 switch (opcode) { 3406 switch (opcode) {
3353 case Translation::BEGIN: 3407 case Translation::BEGIN:
3354 case Translation::JS_FRAME: 3408 case Translation::JS_FRAME:
3355 case Translation::INTERPRETED_FRAME: 3409 case Translation::INTERPRETED_FRAME:
3356 case Translation::ARGUMENTS_ADAPTOR_FRAME: 3410 case Translation::ARGUMENTS_ADAPTOR_FRAME:
3357 case Translation::TAIL_CALLER_FRAME: 3411 case Translation::TAIL_CALLER_FRAME:
3358 case Translation::CONSTRUCT_STUB_FRAME: 3412 case Translation::CONSTRUCT_STUB_FRAME:
3359 case Translation::GETTER_STUB_FRAME: 3413 case Translation::GETTER_STUB_FRAME:
3360 case Translation::SETTER_STUB_FRAME: 3414 case Translation::SETTER_STUB_FRAME:
3361 case Translation::COMPILED_STUB_FRAME: 3415 case Translation::COMPILED_STUB_FRAME:
3362 // Peeled off before getting here. 3416 // Peeled off before getting here.
3363 break; 3417 break;
3364 3418
3365 case Translation::DUPLICATED_OBJECT: { 3419 case Translation::DUPLICATED_OBJECT: {
3366 int object_id = iterator->Next(); 3420 int object_id = iterator->Next();
3367 if (trace_file != nullptr) { 3421 if (trace_file != nullptr) {
3368 PrintF(trace_file, "duplicated object #%d", object_id); 3422 PrintF(trace_file, "duplicated object #%d", object_id);
3369 } 3423 }
3370 object_positions_.push_back(object_positions_[object_id]); 3424 object_positions_.push_back(object_positions_[object_id]);
3371 return TranslatedValue::NewDuplicateObject(this, object_id); 3425 TranslatedValue translated_value =
3426 TranslatedValue::NewDuplicateObject(this, object_id);
3427 frame.Add(translated_value);
3428 return translated_value.GetChildrenCount();
3372 } 3429 }
3373 3430
3374 case Translation::ARGUMENTS_OBJECT: { 3431 case Translation::ARGUMENTS_OBJECT: {
3375 int arg_count = iterator->Next(); 3432 int arg_count = iterator->Next();
3376 int object_index = static_cast<int>(object_positions_.size()); 3433 int object_index = static_cast<int>(object_positions_.size());
3377 if (trace_file != nullptr) { 3434 if (trace_file != nullptr) {
3378 PrintF(trace_file, "argumets object #%d (length = %d)", object_index, 3435 PrintF(trace_file, "arguments object #%d (length = %d)", object_index,
3379 arg_count); 3436 arg_count);
3380 } 3437 }
3381 object_positions_.push_back({frame_index, value_index}); 3438 object_positions_.push_back({frame_index, value_index});
3382 return TranslatedValue::NewArgumentsObject(this, arg_count, object_index); 3439 TranslatedValue translated_value =
3440 TranslatedValue::NewArgumentsObject(this, arg_count, object_index);
3441 frame.Add(translated_value);
3442 return translated_value.GetChildrenCount();
3443 }
3444
3445 case Translation::ARGUMENTS_ELEMENTS: {
3446 int skip = iterator->Next();
3447 CreateArgumentsElementsTranslatedValues(frame_index, input_frame_pointer,
3448 skip);
3449 return 0;
3383 } 3450 }
3384 3451
3385 case Translation::CAPTURED_OBJECT: { 3452 case Translation::CAPTURED_OBJECT: {
3386 int field_count = iterator->Next(); 3453 int field_count = iterator->Next();
3387 int object_index = static_cast<int>(object_positions_.size()); 3454 int object_index = static_cast<int>(object_positions_.size());
3388 if (trace_file != nullptr) { 3455 if (trace_file != nullptr) {
3389 PrintF(trace_file, "captured object #%d (length = %d)", object_index, 3456 PrintF(trace_file, "captured object #%d (length = %d)", object_index,
3390 field_count); 3457 field_count);
3391 } 3458 }
3392 object_positions_.push_back({frame_index, value_index}); 3459 object_positions_.push_back({frame_index, value_index});
3393 return TranslatedValue::NewDeferredObject(this, field_count, 3460 TranslatedValue translated_value =
3394 object_index); 3461 TranslatedValue::NewDeferredObject(this, field_count, object_index);
3462 frame.Add(translated_value);
3463 return translated_value.GetChildrenCount();
Jarin 2017/02/15 16:17:14 The amount of boilerplate here and below is unfort
3395 } 3464 }
3396 3465
3397 case Translation::REGISTER: { 3466 case Translation::REGISTER: {
3398 int input_reg = iterator->Next(); 3467 int input_reg = iterator->Next();
3399 if (registers == nullptr) return TranslatedValue::NewInvalid(this); 3468 if (registers == nullptr) {
3469 TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
3470 frame.Add(translated_value);
3471 return translated_value.GetChildrenCount();
3472 }
3400 intptr_t value = registers->GetRegister(input_reg); 3473 intptr_t value = registers->GetRegister(input_reg);
3401 if (trace_file != nullptr) { 3474 if (trace_file != nullptr) {
3402 PrintF(trace_file, "0x%08" V8PRIxPTR " ; %s ", value, 3475 PrintF(trace_file, "0x%08" V8PRIxPTR " ; %s ", value,
3403 converter.NameOfCPURegister(input_reg)); 3476 converter.NameOfCPURegister(input_reg));
3404 reinterpret_cast<Object*>(value)->ShortPrint(trace_file); 3477 reinterpret_cast<Object*>(value)->ShortPrint(trace_file);
3405 } 3478 }
3406 return TranslatedValue::NewTagged(this, reinterpret_cast<Object*>(value)); 3479 TranslatedValue translated_value =
3480 TranslatedValue::NewTagged(this, reinterpret_cast<Object*>(value));
3481 frame.Add(translated_value);
3482 return translated_value.GetChildrenCount();
3407 } 3483 }
3408 3484
3409 case Translation::INT32_REGISTER: { 3485 case Translation::INT32_REGISTER: {
3410 int input_reg = iterator->Next(); 3486 int input_reg = iterator->Next();
3411 if (registers == nullptr) return TranslatedValue::NewInvalid(this); 3487 if (registers == nullptr) {
3488 TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
3489 frame.Add(translated_value);
3490 return translated_value.GetChildrenCount();
3491 }
3412 intptr_t value = registers->GetRegister(input_reg); 3492 intptr_t value = registers->GetRegister(input_reg);
3413 if (trace_file != nullptr) { 3493 if (trace_file != nullptr) {
3414 PrintF(trace_file, "%" V8PRIdPTR " ; %s ", value, 3494 PrintF(trace_file, "%" V8PRIdPTR " ; %s ", value,
3415 converter.NameOfCPURegister(input_reg)); 3495 converter.NameOfCPURegister(input_reg));
3416 } 3496 }
3417 return TranslatedValue::NewInt32(this, static_cast<int32_t>(value)); 3497 TranslatedValue translated_value =
3498 TranslatedValue::NewInt32(this, static_cast<int32_t>(value));
3499 frame.Add(translated_value);
3500 return translated_value.GetChildrenCount();
3418 } 3501 }
3419 3502
3420 case Translation::UINT32_REGISTER: { 3503 case Translation::UINT32_REGISTER: {
3421 int input_reg = iterator->Next(); 3504 int input_reg = iterator->Next();
3422 if (registers == nullptr) return TranslatedValue::NewInvalid(this); 3505 if (registers == nullptr) {
3506 TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
3507 frame.Add(translated_value);
3508 return translated_value.GetChildrenCount();
3509 }
3423 intptr_t value = registers->GetRegister(input_reg); 3510 intptr_t value = registers->GetRegister(input_reg);
3424 if (trace_file != nullptr) { 3511 if (trace_file != nullptr) {
3425 PrintF(trace_file, "%" V8PRIuPTR " ; %s (uint)", value, 3512 PrintF(trace_file, "%" V8PRIuPTR " ; %s (uint)", value,
3426 converter.NameOfCPURegister(input_reg)); 3513 converter.NameOfCPURegister(input_reg));
3427 reinterpret_cast<Object*>(value)->ShortPrint(trace_file); 3514 reinterpret_cast<Object*>(value)->ShortPrint(trace_file);
3428 } 3515 }
3429 return TranslatedValue::NewUInt32(this, static_cast<uint32_t>(value)); 3516 TranslatedValue translated_value =
3517 TranslatedValue::NewUInt32(this, static_cast<uint32_t>(value));
3518 frame.Add(translated_value);
3519 return translated_value.GetChildrenCount();
3430 } 3520 }
3431 3521
3432 case Translation::BOOL_REGISTER: { 3522 case Translation::BOOL_REGISTER: {
3433 int input_reg = iterator->Next(); 3523 int input_reg = iterator->Next();
3434 if (registers == nullptr) return TranslatedValue::NewInvalid(this); 3524 if (registers == nullptr) {
3525 TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
3526 frame.Add(translated_value);
3527 return translated_value.GetChildrenCount();
3528 }
3435 intptr_t value = registers->GetRegister(input_reg); 3529 intptr_t value = registers->GetRegister(input_reg);
3436 if (trace_file != nullptr) { 3530 if (trace_file != nullptr) {
3437 PrintF(trace_file, "%" V8PRIdPTR " ; %s (bool)", value, 3531 PrintF(trace_file, "%" V8PRIdPTR " ; %s (bool)", value,
3438 converter.NameOfCPURegister(input_reg)); 3532 converter.NameOfCPURegister(input_reg));
3439 } 3533 }
3440 return TranslatedValue::NewBool(this, static_cast<uint32_t>(value)); 3534 TranslatedValue translated_value =
3535 TranslatedValue::NewBool(this, static_cast<uint32_t>(value));
3536 frame.Add(translated_value);
3537 return translated_value.GetChildrenCount();
3441 } 3538 }
3442 3539
3443 case Translation::FLOAT_REGISTER: { 3540 case Translation::FLOAT_REGISTER: {
3444 int input_reg = iterator->Next(); 3541 int input_reg = iterator->Next();
3445 if (registers == nullptr) return TranslatedValue::NewInvalid(this); 3542 if (registers == nullptr) {
3543 TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
3544 frame.Add(translated_value);
3545 return translated_value.GetChildrenCount();
3546 }
3446 Float32 value = registers->GetFloatRegister(input_reg); 3547 Float32 value = registers->GetFloatRegister(input_reg);
3447 if (trace_file != nullptr) { 3548 if (trace_file != nullptr) {
3448 PrintF(trace_file, "%e ; %s (float)", value.get_scalar(), 3549 PrintF(trace_file, "%e ; %s (float)", value.get_scalar(),
3449 RegisterConfiguration::Crankshaft()->GetFloatRegisterName( 3550 RegisterConfiguration::Crankshaft()->GetFloatRegisterName(
3450 input_reg)); 3551 input_reg));
3451 } 3552 }
3452 return TranslatedValue::NewFloat(this, value); 3553 TranslatedValue translated_value = TranslatedValue::NewFloat(this, value);
3554 frame.Add(translated_value);
3555 return translated_value.GetChildrenCount();
3453 } 3556 }
3454 3557
3455 case Translation::DOUBLE_REGISTER: { 3558 case Translation::DOUBLE_REGISTER: {
3456 int input_reg = iterator->Next(); 3559 int input_reg = iterator->Next();
3457 if (registers == nullptr) return TranslatedValue::NewInvalid(this); 3560 if (registers == nullptr) {
3561 TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
3562 frame.Add(translated_value);
3563 return translated_value.GetChildrenCount();
3564 }
3458 Float64 value = registers->GetDoubleRegister(input_reg); 3565 Float64 value = registers->GetDoubleRegister(input_reg);
3459 if (trace_file != nullptr) { 3566 if (trace_file != nullptr) {
3460 PrintF(trace_file, "%e ; %s (double)", value.get_scalar(), 3567 PrintF(trace_file, "%e ; %s (double)", value.get_scalar(),
3461 RegisterConfiguration::Crankshaft()->GetDoubleRegisterName( 3568 RegisterConfiguration::Crankshaft()->GetDoubleRegisterName(
3462 input_reg)); 3569 input_reg));
3463 } 3570 }
3464 return TranslatedValue::NewDouble(this, value); 3571 TranslatedValue translated_value =
3572 TranslatedValue::NewDouble(this, value);
3573 frame.Add(translated_value);
3574 return translated_value.GetChildrenCount();
3465 } 3575 }
3466 3576
3467 case Translation::STACK_SLOT: { 3577 case Translation::STACK_SLOT: {
3468 int slot_offset = 3578 int slot_offset =
3469 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next()); 3579 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next());
3470 intptr_t value = *(reinterpret_cast<intptr_t*>(fp + slot_offset)); 3580 intptr_t value = *(reinterpret_cast<intptr_t*>(fp + slot_offset));
3471 if (trace_file != nullptr) { 3581 if (trace_file != nullptr) {
3472 PrintF(trace_file, "0x%08" V8PRIxPTR " ; [fp %c %d] ", value, 3582 PrintF(trace_file, "0x%08" V8PRIxPTR " ; [fp %c %d] ", value,
3473 slot_offset < 0 ? '-' : '+', std::abs(slot_offset)); 3583 slot_offset < 0 ? '-' : '+', std::abs(slot_offset));
3474 reinterpret_cast<Object*>(value)->ShortPrint(trace_file); 3584 reinterpret_cast<Object*>(value)->ShortPrint(trace_file);
3475 } 3585 }
3476 return TranslatedValue::NewTagged(this, reinterpret_cast<Object*>(value)); 3586 TranslatedValue translated_value =
3587 TranslatedValue::NewTagged(this, reinterpret_cast<Object*>(value));
3588 frame.Add(translated_value);
3589 return translated_value.GetChildrenCount();
3477 } 3590 }
3478 3591
3479 case Translation::INT32_STACK_SLOT: { 3592 case Translation::INT32_STACK_SLOT: {
3480 int slot_offset = 3593 int slot_offset =
3481 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next()); 3594 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next());
3482 uint32_t value = GetUInt32Slot(fp, slot_offset); 3595 uint32_t value = GetUInt32Slot(fp, slot_offset);
3483 if (trace_file != nullptr) { 3596 if (trace_file != nullptr) {
3484 PrintF(trace_file, "%d ; (int) [fp %c %d] ", 3597 PrintF(trace_file, "%d ; (int) [fp %c %d] ",
3485 static_cast<int32_t>(value), slot_offset < 0 ? '-' : '+', 3598 static_cast<int32_t>(value), slot_offset < 0 ? '-' : '+',
3486 std::abs(slot_offset)); 3599 std::abs(slot_offset));
3487 } 3600 }
3488 return TranslatedValue::NewInt32(this, value); 3601 TranslatedValue translated_value = TranslatedValue::NewInt32(this, value);
3602 frame.Add(translated_value);
3603 return translated_value.GetChildrenCount();
3489 } 3604 }
3490 3605
3491 case Translation::UINT32_STACK_SLOT: { 3606 case Translation::UINT32_STACK_SLOT: {
3492 int slot_offset = 3607 int slot_offset =
3493 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next()); 3608 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next());
3494 uint32_t value = GetUInt32Slot(fp, slot_offset); 3609 uint32_t value = GetUInt32Slot(fp, slot_offset);
3495 if (trace_file != nullptr) { 3610 if (trace_file != nullptr) {
3496 PrintF(trace_file, "%u ; (uint) [fp %c %d] ", value, 3611 PrintF(trace_file, "%u ; (uint) [fp %c %d] ", value,
3497 slot_offset < 0 ? '-' : '+', std::abs(slot_offset)); 3612 slot_offset < 0 ? '-' : '+', std::abs(slot_offset));
3498 } 3613 }
3499 return TranslatedValue::NewUInt32(this, value); 3614 TranslatedValue translated_value =
3615 TranslatedValue::NewUInt32(this, value);
3616 frame.Add(translated_value);
3617 return translated_value.GetChildrenCount();
3500 } 3618 }
3501 3619
3502 case Translation::BOOL_STACK_SLOT: { 3620 case Translation::BOOL_STACK_SLOT: {
3503 int slot_offset = 3621 int slot_offset =
3504 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next()); 3622 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next());
3505 uint32_t value = GetUInt32Slot(fp, slot_offset); 3623 uint32_t value = GetUInt32Slot(fp, slot_offset);
3506 if (trace_file != nullptr) { 3624 if (trace_file != nullptr) {
3507 PrintF(trace_file, "%u ; (bool) [fp %c %d] ", value, 3625 PrintF(trace_file, "%u ; (bool) [fp %c %d] ", value,
3508 slot_offset < 0 ? '-' : '+', std::abs(slot_offset)); 3626 slot_offset < 0 ? '-' : '+', std::abs(slot_offset));
3509 } 3627 }
3510 return TranslatedValue::NewBool(this, value); 3628 TranslatedValue translated_value = TranslatedValue::NewBool(this, value);
3629 frame.Add(translated_value);
3630 return translated_value.GetChildrenCount();
3511 } 3631 }
3512 3632
3513 case Translation::FLOAT_STACK_SLOT: { 3633 case Translation::FLOAT_STACK_SLOT: {
3514 int slot_offset = 3634 int slot_offset =
3515 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next()); 3635 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next());
3516 Float32 value = GetFloatSlot(fp, slot_offset); 3636 Float32 value = GetFloatSlot(fp, slot_offset);
3517 if (trace_file != nullptr) { 3637 if (trace_file != nullptr) {
3518 PrintF(trace_file, "%e ; (float) [fp %c %d] ", value.get_scalar(), 3638 PrintF(trace_file, "%e ; (float) [fp %c %d] ", value.get_scalar(),
3519 slot_offset < 0 ? '-' : '+', std::abs(slot_offset)); 3639 slot_offset < 0 ? '-' : '+', std::abs(slot_offset));
3520 } 3640 }
3521 return TranslatedValue::NewFloat(this, value); 3641 TranslatedValue translated_value = TranslatedValue::NewFloat(this, value);
3642 frame.Add(translated_value);
3643 return translated_value.GetChildrenCount();
3522 } 3644 }
3523 3645
3524 case Translation::DOUBLE_STACK_SLOT: { 3646 case Translation::DOUBLE_STACK_SLOT: {
3525 int slot_offset = 3647 int slot_offset =
3526 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next()); 3648 OptimizedFrame::StackSlotOffsetRelativeToFp(iterator->Next());
3527 Float64 value = GetDoubleSlot(fp, slot_offset); 3649 Float64 value = GetDoubleSlot(fp, slot_offset);
3528 if (trace_file != nullptr) { 3650 if (trace_file != nullptr) {
3529 PrintF(trace_file, "%e ; (double) [fp %c %d] ", value.get_scalar(), 3651 PrintF(trace_file, "%e ; (double) [fp %c %d] ", value.get_scalar(),
3530 slot_offset < 0 ? '-' : '+', std::abs(slot_offset)); 3652 slot_offset < 0 ? '-' : '+', std::abs(slot_offset));
3531 } 3653 }
3532 return TranslatedValue::NewDouble(this, value); 3654 TranslatedValue translated_value =
3655 TranslatedValue::NewDouble(this, value);
3656 frame.Add(translated_value);
3657 return translated_value.GetChildrenCount();
3533 } 3658 }
3534 3659
3535 case Translation::LITERAL: { 3660 case Translation::LITERAL: {
3536 int literal_index = iterator->Next(); 3661 int literal_index = iterator->Next();
3537 Object* value = literal_array->get(literal_index); 3662 Object* value = literal_array->get(literal_index);
3538 if (trace_file != nullptr) { 3663 if (trace_file != nullptr) {
3539 PrintF(trace_file, "0x%08" V8PRIxPTR " ; (literal %d) ", 3664 PrintF(trace_file, "0x%08" V8PRIxPTR " ; (literal %d) ",
3540 reinterpret_cast<intptr_t>(value), literal_index); 3665 reinterpret_cast<intptr_t>(value), literal_index);
3541 reinterpret_cast<Object*>(value)->ShortPrint(trace_file); 3666 reinterpret_cast<Object*>(value)->ShortPrint(trace_file);
3542 } 3667 }
3543 3668
3544 return TranslatedValue::NewTagged(this, value); 3669 TranslatedValue translated_value =
3670 TranslatedValue::NewTagged(this, value);
3671 frame.Add(translated_value);
3672 return translated_value.GetChildrenCount();
3545 } 3673 }
3546 } 3674 }
3547 3675
3548 FATAL("We should never get here - unexpected deopt info."); 3676 FATAL("We should never get here - unexpected deopt info.");
3549 return TranslatedValue(nullptr, TranslatedValue::kInvalid); 3677 TranslatedValue translated_value =
3678 TranslatedValue(nullptr, TranslatedValue::kInvalid);
3679 frame.Add(translated_value);
3680 return translated_value.GetChildrenCount();
3550 } 3681 }
3551 3682
3552 3683
3553 TranslatedState::TranslatedState(JavaScriptFrame* frame) 3684 TranslatedState::TranslatedState(JavaScriptFrame* frame)
3554 : isolate_(nullptr), 3685 : isolate_(nullptr),
3555 stack_frame_pointer_(nullptr), 3686 stack_frame_pointer_(nullptr),
3556 has_adapted_arguments_(false) { 3687 has_adapted_arguments_(false) {
3557 int deopt_index = Safepoint::kNoDeoptimizationIndex; 3688 int deopt_index = Safepoint::kNoDeoptimizationIndex;
3558 DeoptimizationInputData* data = 3689 DeoptimizationInputData* data =
3559 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index); 3690 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index);
3560 DCHECK(data != nullptr && deopt_index != Safepoint::kNoDeoptimizationIndex); 3691 DCHECK(data != nullptr && deopt_index != Safepoint::kNoDeoptimizationIndex);
3561 TranslationIterator it(data->TranslationByteArray(), 3692 TranslationIterator it(data->TranslationByteArray(),
3562 data->TranslationIndex(deopt_index)->value()); 3693 data->TranslationIndex(deopt_index)->value());
3563 Init(frame->fp(), &it, data->LiteralArray(), nullptr /* registers */, 3694 Init(frame->fp(), &it, data->LiteralArray(), nullptr /* registers */,
3564 nullptr /* trace file */); 3695 nullptr /* trace file */,
3696 frame->function()->shared()->internal_formal_parameter_count());
3565 } 3697 }
3566 3698
3567 3699
3568 TranslatedState::TranslatedState() 3700 TranslatedState::TranslatedState()
3569 : isolate_(nullptr), 3701 : isolate_(nullptr),
3570 stack_frame_pointer_(nullptr), 3702 stack_frame_pointer_(nullptr),
3571 has_adapted_arguments_(false) {} 3703 has_adapted_arguments_(false) {}
3572 3704
3573
3574 void TranslatedState::Init(Address input_frame_pointer, 3705 void TranslatedState::Init(Address input_frame_pointer,
3575 TranslationIterator* iterator, 3706 TranslationIterator* iterator,
3576 FixedArray* literal_array, RegisterValues* registers, 3707 FixedArray* literal_array, RegisterValues* registers,
3577 FILE* trace_file) { 3708 FILE* trace_file, int formal_parameter_count) {
3578 DCHECK(frames_.empty()); 3709 DCHECK(frames_.empty());
3579 3710
3711 formal_parameter_count_ = formal_parameter_count;
3712
3580 isolate_ = literal_array->GetIsolate(); 3713 isolate_ = literal_array->GetIsolate();
3581 // Read out the 'header' translation. 3714 // Read out the 'header' translation.
3582 Translation::Opcode opcode = 3715 Translation::Opcode opcode =
3583 static_cast<Translation::Opcode>(iterator->Next()); 3716 static_cast<Translation::Opcode>(iterator->Next());
3584 CHECK(opcode == Translation::BEGIN); 3717 CHECK(opcode == Translation::BEGIN);
3585 3718
3586 int count = iterator->Next(); 3719 int count = iterator->Next();
3587 iterator->Next(); // Drop JS frames count. 3720 iterator->Next(); // Drop JS frames count.
3588 3721
3589 frames_.reserve(count); 3722 frames_.reserve(count);
3590 3723
3591 std::stack<int> nested_counts; 3724 std::stack<int> nested_counts;
3592 3725
3593 // Read the frames 3726 // Read the frames
3594 for (int i = 0; i < count; i++) { 3727 for (int frame_index = 0; frame_index < count; frame_index++) {
3595 // Read the frame descriptor. 3728 // Read the frame descriptor.
3596 frames_.push_back(CreateNextTranslatedFrame( 3729 frames_.push_back(CreateNextTranslatedFrame(
3597 iterator, literal_array, input_frame_pointer, trace_file)); 3730 iterator, literal_array, input_frame_pointer, trace_file));
3598 TranslatedFrame& frame = frames_.back(); 3731 TranslatedFrame& frame = frames_.back();
3599 3732
3600 // Read the values. 3733 // Read the values.
3601 int values_to_process = frame.GetValueCount(); 3734 int values_to_process = frame.GetValueCount();
3602 while (values_to_process > 0 || !nested_counts.empty()) { 3735 while (values_to_process > 0 || !nested_counts.empty()) {
3603 if (trace_file != nullptr) { 3736 if (trace_file != nullptr) {
3604 if (nested_counts.empty()) { 3737 if (nested_counts.empty()) {
3605 // For top level values, print the value number. 3738 // For top level values, print the value number.
3606 PrintF(trace_file, " %3i: ", 3739 PrintF(trace_file, " %3i: ",
3607 frame.GetValueCount() - values_to_process); 3740 frame.GetValueCount() - values_to_process);
3608 } else { 3741 } else {
3609 // Take care of indenting for nested values. 3742 // Take care of indenting for nested values.
3610 PrintF(trace_file, " "); 3743 PrintF(trace_file, " ");
3611 for (size_t j = 0; j < nested_counts.size(); j++) { 3744 for (size_t j = 0; j < nested_counts.size(); j++) {
3612 PrintF(trace_file, " "); 3745 PrintF(trace_file, " ");
3613 } 3746 }
3614 } 3747 }
3615 } 3748 }
3616 3749
3617 TranslatedValue value = CreateNextTranslatedValue( 3750 int children_count = CreateNextTranslatedValue(
Jarin 2017/02/15 16:17:15 children_count -> nested_count (it is not children
3618 i, static_cast<int>(frame.values_.size()), iterator, literal_array, 3751 frame_index, iterator, literal_array, input_frame_pointer, registers,
3619 input_frame_pointer, registers, trace_file); 3752 input_frame_pointer, trace_file);
Jarin 2017/02/15 16:17:15 Why is the frame pointer passed twice here?
3620 frame.Add(value);
3621 3753
3622 if (trace_file != nullptr) { 3754 if (trace_file != nullptr) {
3623 PrintF(trace_file, "\n"); 3755 PrintF(trace_file, "\n");
3624 } 3756 }
3625 3757
3626 // Update the value count and resolve the nesting. 3758 // Update the value count and resolve the nesting.
3627 values_to_process--; 3759 values_to_process--;
3628 int children_count = value.GetChildrenCount();
3629 if (children_count > 0) { 3760 if (children_count > 0) {
3630 nested_counts.push(values_to_process); 3761 nested_counts.push(values_to_process);
3631 values_to_process = children_count; 3762 values_to_process = children_count;
3632 } else { 3763 } else {
3633 while (values_to_process == 0 && !nested_counts.empty()) { 3764 while (values_to_process == 0 && !nested_counts.empty()) {
3634 values_to_process = nested_counts.top(); 3765 values_to_process = nested_counts.top();
3635 nested_counts.pop(); 3766 nested_counts.pop();
3636 } 3767 }
3637 } 3768 }
3638 } 3769 }
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
4228 CHECK(value_info->IsMaterializedObject()); 4359 CHECK(value_info->IsMaterializedObject());
4229 4360
4230 value_info->value_ = 4361 value_info->value_ =
4231 Handle<Object>(previously_materialized_objects->get(i), isolate_); 4362 Handle<Object>(previously_materialized_objects->get(i), isolate_);
4232 } 4363 }
4233 } 4364 }
4234 } 4365 }
4235 4366
4236 } // namespace internal 4367 } // namespace internal
4237 } // namespace v8 4368 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698