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

Side by Side Diff: src/x64/deoptimizer-x64.cc

Issue 14843020: Unify deoptimizer for JavaScript frames. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/ia32/frames-ia32.cc ('k') | src/x64/frames-x64.cc » ('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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 if (FLAG_trace_osr) { 361 if (FLAG_trace_osr) {
362 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", 362 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ",
363 ok ? "finished" : "aborted", 363 ok ? "finished" : "aborted",
364 reinterpret_cast<intptr_t>(function_)); 364 reinterpret_cast<intptr_t>(function_));
365 function_->PrintName(); 365 function_->PrintName();
366 PrintF(" => pc=0x%0" V8PRIxPTR "]\n", output_[0]->GetPc()); 366 PrintF(" => pc=0x%0" V8PRIxPTR "]\n", output_[0]->GetPc());
367 } 367 }
368 } 368 }
369 369
370 370
371 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator,
372 int frame_index) {
373 BailoutId node_id = BailoutId(iterator->Next());
374 JSFunction* function;
375 if (frame_index != 0) {
376 function = JSFunction::cast(ComputeLiteral(iterator->Next()));
377 } else {
378 int closure_id = iterator->Next();
379 USE(closure_id);
380 ASSERT_EQ(Translation::kSelfLiteralId, closure_id);
381 function = function_;
382 }
383 unsigned height = iterator->Next();
384 unsigned height_in_bytes = height * kPointerSize;
385 if (trace_) {
386 PrintF(" translating ");
387 function->PrintName();
388 PrintF(" => node=%d, height=%d\n", node_id.ToInt(), height_in_bytes);
389 }
390
391 // The 'fixed' part of the frame consists of the incoming parameters and
392 // the part described by JavaScriptFrameConstants.
393 unsigned fixed_frame_size = ComputeFixedSize(function);
394 unsigned input_frame_size = input_->GetFrameSize();
395 unsigned output_frame_size = height_in_bytes + fixed_frame_size;
396
397 // Allocate and store the output frame description.
398 FrameDescription* output_frame =
399 new(output_frame_size) FrameDescription(output_frame_size, function);
400 output_frame->SetFrameType(StackFrame::JAVA_SCRIPT);
401
402 bool is_bottommost = (0 == frame_index);
403 bool is_topmost = (output_count_ - 1 == frame_index);
404 ASSERT(frame_index >= 0 && frame_index < output_count_);
405 ASSERT(output_[frame_index] == NULL);
406 output_[frame_index] = output_frame;
407
408 // The top address for the bottommost output frame can be computed from
409 // the input frame pointer and the output frame's height. For all
410 // subsequent output frames, it can be computed from the previous one's
411 // top address and the current frame's size.
412 intptr_t top_address;
413 if (is_bottommost) {
414 // 2 = context and function in the frame.
415 top_address =
416 input_->GetRegister(rbp.code()) - (2 * kPointerSize) - height_in_bytes;
417 } else {
418 top_address = output_[frame_index - 1]->GetTop() - output_frame_size;
419 }
420 output_frame->SetTop(top_address);
421
422 // Compute the incoming parameter translation.
423 int parameter_count = function->shared()->formal_parameter_count() + 1;
424 unsigned output_offset = output_frame_size;
425 unsigned input_offset = input_frame_size;
426 for (int i = 0; i < parameter_count; ++i) {
427 output_offset -= kPointerSize;
428 DoTranslateCommand(iterator, frame_index, output_offset);
429 }
430 input_offset -= (parameter_count * kPointerSize);
431
432 // There are no translation commands for the caller's pc and fp, the
433 // context, and the function. Synthesize their values and set them up
434 // explicitly.
435 //
436 // The caller's pc for the bottommost output frame is the same as in the
437 // input frame. For all subsequent output frames, it can be read from the
438 // previous one. This frame's pc can be computed from the non-optimized
439 // function code and AST id of the bailout.
440 output_offset -= kPointerSize;
441 input_offset -= kPointerSize;
442 intptr_t value;
443 if (is_bottommost) {
444 value = input_->GetFrameSlot(input_offset);
445 } else {
446 value = output_[frame_index - 1]->GetPc();
447 }
448 output_frame->SetFrameSlot(output_offset, value);
449 if (trace_) {
450 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
451 V8PRIxPTR " ; caller's pc\n",
452 top_address + output_offset, output_offset, value);
453 }
454
455 // The caller's frame pointer for the bottommost output frame is the same
456 // as in the input frame. For all subsequent output frames, it can be
457 // read from the previous one. Also compute and set this frame's frame
458 // pointer.
459 output_offset -= kPointerSize;
460 input_offset -= kPointerSize;
461 if (is_bottommost) {
462 value = input_->GetFrameSlot(input_offset);
463 } else {
464 value = output_[frame_index - 1]->GetFp();
465 }
466 output_frame->SetFrameSlot(output_offset, value);
467 intptr_t fp_value = top_address + output_offset;
468 ASSERT(!is_bottommost || input_->GetRegister(rbp.code()) == fp_value);
469 output_frame->SetFp(fp_value);
470 if (is_topmost) output_frame->SetRegister(rbp.code(), fp_value);
471 if (trace_) {
472 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
473 V8PRIxPTR " ; caller's fp\n",
474 fp_value, output_offset, value);
475 }
476
477 // For the bottommost output frame the context can be gotten from the input
478 // frame. For all subsequent output frames it can be gotten from the function
479 // so long as we don't inline functions that need local contexts.
480 output_offset -= kPointerSize;
481 input_offset -= kPointerSize;
482 if (is_bottommost) {
483 value = input_->GetFrameSlot(input_offset);
484 } else {
485 value = reinterpret_cast<intptr_t>(function->context());
486 }
487 output_frame->SetFrameSlot(output_offset, value);
488 output_frame->SetContext(value);
489 if (is_topmost) output_frame->SetRegister(rsi.code(), value);
490 if (trace_) {
491 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
492 V8PRIxPTR "; context\n",
493 top_address + output_offset, output_offset, value);
494 }
495
496 // The function was mentioned explicitly in the BEGIN_FRAME.
497 output_offset -= kPointerSize;
498 input_offset -= kPointerSize;
499 value = reinterpret_cast<intptr_t>(function);
500 // The function for the bottommost output frame should also agree with the
501 // input frame.
502 ASSERT(!is_bottommost || input_->GetFrameSlot(input_offset) == value);
503 output_frame->SetFrameSlot(output_offset, value);
504 if (trace_) {
505 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
506 V8PRIxPTR "; function\n",
507 top_address + output_offset, output_offset, value);
508 }
509
510 // Translate the rest of the frame.
511 for (unsigned i = 0; i < height; ++i) {
512 output_offset -= kPointerSize;
513 DoTranslateCommand(iterator, frame_index, output_offset);
514 }
515 ASSERT(0 == output_offset);
516
517 // Compute this frame's PC, state, and continuation.
518 Code* non_optimized_code = function->shared()->code();
519 FixedArray* raw_data = non_optimized_code->deoptimization_data();
520 DeoptimizationOutputData* data = DeoptimizationOutputData::cast(raw_data);
521 Address start = non_optimized_code->instruction_start();
522 unsigned pc_and_state = GetOutputInfo(data, node_id, function->shared());
523 unsigned pc_offset = FullCodeGenerator::PcField::decode(pc_and_state);
524 intptr_t pc_value = reinterpret_cast<intptr_t>(start + pc_offset);
525 output_frame->SetPc(pc_value);
526
527 FullCodeGenerator::State state =
528 FullCodeGenerator::StateField::decode(pc_and_state);
529 output_frame->SetState(Smi::FromInt(state));
530
531 // Set the continuation for the topmost frame.
532 if (is_topmost && bailout_type_ != DEBUGGER) {
533 Builtins* builtins = isolate_->builtins();
534 Code* continuation = builtins->builtin(Builtins::kNotifyDeoptimized);
535 if (bailout_type_ == LAZY) {
536 continuation = builtins->builtin(Builtins::kNotifyLazyDeoptimized);
537 } else if (bailout_type_ == SOFT) {
538 continuation = builtins->builtin(Builtins::kNotifySoftDeoptimized);
539 } else {
540 ASSERT(bailout_type_ == EAGER);
541 }
542 output_frame->SetContinuation(
543 reinterpret_cast<intptr_t>(continuation->entry()));
544 }
545 }
546
547
548 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { 371 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) {
549 // Set the register values. The values are not important as there are no 372 // Set the register values. The values are not important as there are no
550 // callee saved registers in JavaScript frames, so all registers are 373 // callee saved registers in JavaScript frames, so all registers are
551 // spilled. Registers rbp and rsp are set to the correct values though. 374 // spilled. Registers rbp and rsp are set to the correct values though.
552 for (int i = 0; i < Register::kNumRegisters; i++) { 375 for (int i = 0; i < Register::kNumRegisters; i++) {
553 input_->SetRegister(i, i * 4); 376 input_->SetRegister(i, i * 4);
554 } 377 }
555 input_->SetRegister(rsp.code(), reinterpret_cast<intptr_t>(frame->sp())); 378 input_->SetRegister(rsp.code(), reinterpret_cast<intptr_t>(frame->sp()));
556 input_->SetRegister(rbp.code(), reinterpret_cast<intptr_t>(frame->fp())); 379 input_->SetRegister(rbp.code(), reinterpret_cast<intptr_t>(frame->fp()));
557 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { 380 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) {
(...skipping 21 matching lines...) Expand all
579 402
580 403
581 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { 404 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) {
582 for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); ++i) { 405 for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); ++i) {
583 double double_value = input_->GetDoubleRegister(i); 406 double double_value = input_->GetDoubleRegister(i);
584 output_frame->SetDoubleRegister(i, double_value); 407 output_frame->SetDoubleRegister(i, double_value);
585 } 408 }
586 } 409 }
587 410
588 411
412 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) {
413 // There is no dynamic alignment padding on x64 in the input frame.
414 return false;
415 }
416
417
589 #define __ masm()-> 418 #define __ masm()->
590 419
591 void Deoptimizer::EntryGenerator::Generate() { 420 void Deoptimizer::EntryGenerator::Generate() {
592 GeneratePrologue(); 421 GeneratePrologue();
593 422
594 // Save all general purpose registers before messing with them. 423 // Save all general purpose registers before messing with them.
595 const int kNumberOfRegisters = Register::kNumRegisters; 424 const int kNumberOfRegisters = Register::kNumRegisters;
596 425
597 const int kDoubleRegsSize = kDoubleSize * 426 const int kDoubleRegsSize = kDoubleSize *
598 XMMRegister::NumAllocatableRegisters(); 427 XMMRegister::NumAllocatableRegisters();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 } 618 }
790 __ bind(&done); 619 __ bind(&done);
791 } 620 }
792 621
793 #undef __ 622 #undef __
794 623
795 624
796 } } // namespace v8::internal 625 } } // namespace v8::internal
797 626
798 #endif // V8_TARGET_ARCH_X64 627 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/ia32/frames-ia32.cc ('k') | src/x64/frames-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698