| OLD | NEW |
| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 if (FLAG_trace_osr) { | 342 if (FLAG_trace_osr) { |
| 343 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", | 343 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", |
| 344 ok ? "finished" : "aborted", | 344 ok ? "finished" : "aborted", |
| 345 reinterpret_cast<intptr_t>(function_)); | 345 reinterpret_cast<intptr_t>(function_)); |
| 346 function_->PrintName(); | 346 function_->PrintName(); |
| 347 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); | 347 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 | 350 |
| 351 | 351 |
| 352 void Deoptimizer::DoCompiledStubFrame(TranslationIterator* iterator, | 352 void Deoptimizer::DoComputeCompiledStubFrame(TranslationIterator* iterator, |
| 353 int frame_index) { | 353 int frame_index) { |
| 354 // | 354 // |
| 355 // FROM TO | 355 // FROM TO |
| 356 // | .... | | .... | | 356 // | .... | | .... | |
| 357 // +-------------------------+ +-------------------------+ | 357 // +-------------------------+ +-------------------------+ |
| 358 // | JSFunction continuation | | JSFunction continuation | | 358 // | JSFunction continuation | | JSFunction continuation | |
| 359 // +-------------------------+ +-------------------------+ | 359 // +-------------------------+ +-------------------------+ |
| 360 // | | saved frame (fp) | | saved frame (fp) | | 360 // | | saved frame (fp) | | saved frame (fp) | |
| 361 // | +=========================+<-fp +=========================+<-fp | 361 // | +=========================+<-fp +=========================+<-fp |
| 362 // | | JSFunction context | | JSFunction context | | 362 // | | JSFunction context | | JSFunction context | |
| 363 // v +-------------------------+ +-------------------------| | 363 // v +-------------------------+ +-------------------------| |
| 364 // | COMPILED_STUB marker | | STUB_FAILURE marker | | 364 // | COMPILED_STUB marker | | STUB_FAILURE marker | |
| 365 // +-------------------------+ +-------------------------+ | 365 // +-------------------------+ +-------------------------+ |
| 366 // | | | caller args.length_ | | 366 // | | | caller args.arguments_ | |
| 367 // | ... | +-------------------------+ | 367 // | ... | +-------------------------+ |
| 368 // | | | caller args.arguments_ | | 368 // | | | caller args.length_ | |
| 369 // |-------------------------|<-sp +-------------------------+ | 369 // |-------------------------|<-sp +-------------------------+ |
| 370 // | caller args pointer | | 370 // | caller args pointer | |
| 371 // +-------------------------+ | 371 // +-------------------------+ |
| 372 // | caller stack param 1 | | 372 // | caller stack param 1 | |
| 373 // parameters in registers +-------------------------+ | 373 // parameters in registers +-------------------------+ |
| 374 // and spilled to stack | .... | | 374 // and spilled to stack | .... | |
| 375 // +-------------------------+ | 375 // +-------------------------+ |
| 376 // | caller stack param n | | 376 // | caller stack param n | |
| 377 // +-------------------------+<-sp | 377 // +-------------------------+<-sp |
| 378 // s0-s1 = number of parameters | 378 // s0-s1 = number of parameters |
| 379 // s2 = failure handler address | 379 // s2 = failure handler address |
| 380 // fp = saved frame | 380 // fp = saved frame |
| 381 // cp = JSFunction context | 381 // cp = JSFunction context |
| 382 // | 382 // |
| 383 | 383 |
| 384 ASSERT(compiled_code_->kind() == Code::COMPILED_STUB); | 384 ASSERT(compiled_code_->kind() == Code::COMPILED_STUB); |
| 385 int major_key = compiled_code_->major_key(); | 385 int major_key = compiled_code_->major_key(); |
| 386 CodeStubInterfaceDescriptor* descriptor = | 386 CodeStubInterfaceDescriptor* descriptor = |
| 387 isolate_->code_stub_interface_descriptor(major_key); | 387 isolate_->code_stub_interface_descriptor(major_key); |
| 388 | 388 |
| 389 // The output frame must have room for all pushed register parameters | 389 // The output frame must have room for all pushed register parameters |
| 390 // and the standard stack frame slots. | 390 // and the standard stack frame slots. Include space for an argument |
| 391 int output_frame_size = StandardFrameConstants::kFixedFrameSize + | 391 // object to the callee and optionally the space to pass the argument |
| 392 kPointerSize * descriptor->register_param_count_; | 392 // object to the stub failure handler. |
| 393 int height_in_bytes = kPointerSize * descriptor->register_param_count_ + |
| 394 sizeof(Arguments) + kPointerSize; |
| 395 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; |
| 396 int input_frame_size = input_->GetFrameSize(); |
| 397 int output_frame_size = height_in_bytes + fixed_frame_size; |
| 398 if (trace_) { |
| 399 PrintF(" translating %s => StubFailureTrampolineStub, height=%d\n", |
| 400 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), |
| 401 height_in_bytes); |
| 402 } |
| 393 | 403 |
| 394 // Include space for an argument object to the callee and optionally | 404 // The stub failure trampoline is a single frame. |
| 395 // the space to pass the argument object to the stub failure handler. | |
| 396 output_frame_size += sizeof(Arguments) + kPointerSize; | |
| 397 | 405 |
| 398 FrameDescription* output_frame = | 406 FrameDescription* output_frame = |
| 399 new(output_frame_size) FrameDescription(output_frame_size, 0); | 407 new(output_frame_size) FrameDescription(output_frame_size, NULL); |
| 408 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 400 ASSERT(frame_index == 0); | 409 ASSERT(frame_index == 0); |
| 401 output_[frame_index] = output_frame; | 410 output_[frame_index] = output_frame; |
| 402 Code* notify_failure = | 411 // The top address for the output frame can be computed from the input |
| 403 isolate_->builtins()->builtin(Builtins::kNotifyStubFailure); | 412 // frame pointer and the output frame's height. Subtract space for the |
| 404 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); | 413 // context and function slots. |
| 405 output_frame->SetContinuation( | 414 intptr_t top_address = input_->GetRegister(fp.code()) - (2 * kPointerSize) - |
| 406 reinterpret_cast<intptr_t>(notify_failure->entry())); | 415 height_in_bytes; |
| 416 output_frame->SetTop(top_address); |
| 407 | 417 |
| 408 Code* trampoline = NULL; | 418 // Read caller's PC (JSFunction continuation) from the input frame. |
| 409 int extra = descriptor->extra_expression_stack_count_; | |
| 410 StubFailureTrampolineStub(extra).FindCodeInCache(&trampoline, isolate_); | |
| 411 ASSERT(trampoline != NULL); | |
| 412 output_frame->SetPc(reinterpret_cast<intptr_t>( | |
| 413 trampoline->instruction_start())); | |
| 414 unsigned input_frame_size = input_->GetFrameSize(); | |
| 415 | |
| 416 intptr_t frame_ptr = input_->GetRegister(fp.code()); | |
| 417 | |
| 418 // JSFunction continuation | |
| 419 intptr_t input_frame_offset = input_frame_size - kPointerSize; | 419 intptr_t input_frame_offset = input_frame_size - kPointerSize; |
| 420 intptr_t output_frame_offset = output_frame_size - kPointerSize; | 420 intptr_t output_frame_offset = output_frame_size - kPointerSize; |
| 421 intptr_t value = input_->GetFrameSlot(input_frame_offset); | 421 intptr_t value = input_->GetFrameSlot(input_frame_offset); |
| 422 output_frame->SetFrameSlot(output_frame_offset, value); | 422 output_frame->SetFrameSlot(output_frame_offset, value); |
| 423 if (trace_) { |
| 424 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n", |
| 425 top_address + output_frame_offset, output_frame_offset, value); |
| 426 } |
| 423 | 427 |
| 424 // saved frame ptr | 428 // Read caller's FP from the input frame, and set this frame's FP. |
| 425 input_frame_offset -= kPointerSize; | 429 input_frame_offset -= kPointerSize; |
| 426 value = input_->GetFrameSlot(input_frame_offset); | 430 value = input_->GetFrameSlot(input_frame_offset); |
| 427 output_frame_offset -= kPointerSize; | 431 output_frame_offset -= kPointerSize; |
| 428 output_frame->SetFrameSlot(output_frame_offset, value); | 432 output_frame->SetFrameSlot(output_frame_offset, value); |
| 433 intptr_t frame_ptr = input_->GetRegister(fp.code()); |
| 434 output_frame->SetRegister(fp.code(), frame_ptr); |
| 435 output_frame->SetFp(frame_ptr); |
| 436 if (trace_) { |
| 437 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's fp\n", |
| 438 top_address + output_frame_offset, output_frame_offset, value); |
| 439 } |
| 429 | 440 |
| 430 // Restore context | 441 // The context can be gotten from the input frame. |
| 431 input_frame_offset -= kPointerSize; | 442 input_frame_offset -= kPointerSize; |
| 432 value = input_->GetFrameSlot(input_frame_offset); | 443 value = input_->GetFrameSlot(input_frame_offset); |
| 433 output_frame->SetRegister(cp.code(), value); | 444 output_frame->SetRegister(cp.code(), value); |
| 434 output_frame_offset -= kPointerSize; | 445 output_frame_offset -= kPointerSize; |
| 435 output_frame->SetFrameSlot(output_frame_offset, value); | 446 output_frame->SetFrameSlot(output_frame_offset, value); |
| 447 if (trace_) { |
| 448 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; context\n", |
| 449 top_address + output_frame_offset, output_frame_offset, value); |
| 450 } |
| 436 | 451 |
| 437 // Internal frame markers | 452 // A marker value is used in place of the function. |
| 438 output_frame_offset -= kPointerSize; | 453 output_frame_offset -= kPointerSize; |
| 439 value = reinterpret_cast<intptr_t>( | 454 value = reinterpret_cast<intptr_t>( |
| 440 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); | 455 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); |
| 441 output_frame->SetFrameSlot(output_frame_offset, value); | 456 output_frame->SetFrameSlot(output_frame_offset, value); |
| 457 if (trace_) { |
| 458 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function (stub fail sentinel)\n", |
| 459 top_address + output_frame_offset, output_frame_offset, value); |
| 460 } |
| 442 | 461 |
| 443 int caller_arg_count = 0; | 462 int caller_arg_count = 0; |
| 444 if (descriptor->stack_parameter_count_ != NULL) { | 463 if (descriptor->stack_parameter_count_ != NULL) { |
| 445 caller_arg_count = | 464 caller_arg_count = |
| 446 input_->GetRegister(descriptor->stack_parameter_count_->code()); | 465 input_->GetRegister(descriptor->stack_parameter_count_->code()); |
| 447 } | 466 } |
| 448 | 467 |
| 449 // Build the Arguments object for the caller's parameters and a pointer to it. | 468 // Build the Arguments object for the caller's parameters and a pointer to it. |
| 450 output_frame_offset -= kPointerSize; | 469 output_frame_offset -= kPointerSize; |
| 451 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + | 470 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + |
| 452 (caller_arg_count - 1) * kPointerSize; | 471 (caller_arg_count - 1) * kPointerSize; |
| 453 output_frame->SetFrameSlot(output_frame_offset, value); | 472 output_frame->SetFrameSlot(output_frame_offset, value); |
| 473 if (trace_) { |
| 474 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args.arguments\n", |
| 475 top_address + output_frame_offset, output_frame_offset, value); |
| 476 } |
| 454 | 477 |
| 478 output_frame_offset -= kPointerSize; |
| 479 value = caller_arg_count; |
| 455 output_frame->SetFrameSlot(output_frame_offset, value); | 480 output_frame->SetFrameSlot(output_frame_offset, value); |
| 481 if (trace_) { |
| 482 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args.length\n", |
| 483 top_address + output_frame_offset, output_frame_offset, value); |
| 484 } |
| 485 |
| 456 output_frame_offset -= kPointerSize; | 486 output_frame_offset -= kPointerSize; |
| 457 output_frame->SetFrameSlot(output_frame_offset, caller_arg_count); | |
| 458 | |
| 459 value = frame_ptr - (output_frame_size - output_frame_offset) - | 487 value = frame_ptr - (output_frame_size - output_frame_offset) - |
| 460 StandardFrameConstants::kMarkerOffset; | 488 StandardFrameConstants::kMarkerOffset + kPointerSize; |
| 461 output_frame_offset -= kPointerSize; | |
| 462 output_frame->SetFrameSlot(output_frame_offset, value); | 489 output_frame->SetFrameSlot(output_frame_offset, value); |
| 490 if (trace_) { |
| 491 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args*\n", |
| 492 top_address + output_frame_offset, output_frame_offset, value); |
| 493 } |
| 463 | 494 |
| 464 // Copy the register parameters to the failure frame. | 495 // Copy the register parameters to the failure frame. |
| 465 for (int i = 0; i < descriptor->register_param_count_; ++i) { | 496 for (int i = 0; i < descriptor->register_param_count_; ++i) { |
| 466 output_frame_offset -= kPointerSize; | 497 output_frame_offset -= kPointerSize; |
| 467 DoTranslateCommand(iterator, 0, output_frame_offset); | 498 DoTranslateCommand(iterator, 0, output_frame_offset); |
| 468 } | 499 } |
| 469 | 500 |
| 501 ASSERT(0 == output_frame_offset); |
| 502 |
| 470 for (int i = 0; i < DoubleRegister::kMaxNumRegisters; ++i) { | 503 for (int i = 0; i < DoubleRegister::kMaxNumRegisters; ++i) { |
| 471 double double_value = input_->GetDoubleRegister(i); | 504 double double_value = input_->GetDoubleRegister(i); |
| 472 output_frame->SetDoubleRegister(i, double_value); | 505 output_frame->SetDoubleRegister(i, double_value); |
| 473 } | 506 } |
| 474 | 507 |
| 475 output_frame->SetRegister(fp.code(), frame_ptr); | |
| 476 output_frame->SetFp(frame_ptr); | |
| 477 | |
| 478 ApiFunction function(descriptor->deoptimization_handler_); | 508 ApiFunction function(descriptor->deoptimization_handler_); |
| 479 ExternalReference xref(&function, ExternalReference::BUILTIN_CALL, isolate_); | 509 ExternalReference xref(&function, ExternalReference::BUILTIN_CALL, isolate_); |
| 480 intptr_t handler = reinterpret_cast<intptr_t>(xref.address()); | 510 intptr_t handler = reinterpret_cast<intptr_t>(xref.address()); |
| 481 int params = descriptor->register_param_count_; | 511 int params = descriptor->register_param_count_; |
| 482 if (descriptor->stack_parameter_count_ != NULL) { | 512 if (descriptor->stack_parameter_count_ != NULL) { |
| 483 params++; | 513 params++; |
| 484 } | 514 } |
| 485 output_frame->SetRegister(s0.code(), params); | 515 output_frame->SetRegister(s0.code(), params); |
| 486 output_frame->SetRegister(s1.code(), (params - 1) * kPointerSize); | 516 output_frame->SetRegister(s1.code(), (params - 1) * kPointerSize); |
| 487 output_frame->SetRegister(s2.code(), handler); | 517 output_frame->SetRegister(s2.code(), handler); |
| 518 |
| 519 // Compute this frame's PC, state, and continuation. |
| 520 Code* trampoline = NULL; |
| 521 int extra = descriptor->extra_expression_stack_count_; |
| 522 StubFailureTrampolineStub(extra).FindCodeInCache(&trampoline, isolate_); |
| 523 ASSERT(trampoline != NULL); |
| 524 output_frame->SetPc(reinterpret_cast<intptr_t>( |
| 525 trampoline->instruction_start())); |
| 526 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); |
| 527 Code* notify_failure = |
| 528 isolate_->builtins()->builtin(Builtins::kNotifyStubFailure); |
| 529 output_frame->SetContinuation( |
| 530 reinterpret_cast<intptr_t>(notify_failure->entry())); |
| 488 } | 531 } |
| 489 | 532 |
| 490 | 533 |
| 491 void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator, | 534 void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator, |
| 492 int frame_index) { | 535 int frame_index) { |
| 493 Builtins* builtins = isolate_->builtins(); | 536 Builtins* builtins = isolate_->builtins(); |
| 494 Code* construct_stub = builtins->builtin(Builtins::kJSConstructStubGeneric); | 537 Code* construct_stub = builtins->builtin(Builtins::kJSConstructStubGeneric); |
| 495 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next())); | 538 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
| 496 unsigned height = iterator->Next(); | 539 unsigned height = iterator->Next(); |
| 497 unsigned height_in_bytes = height * kPointerSize; | 540 unsigned height_in_bytes = height * kPointerSize; |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 } | 1111 } |
| 1069 | 1112 |
| 1070 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), | 1113 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), |
| 1071 count() * table_entry_size_); | 1114 count() * table_entry_size_); |
| 1072 } | 1115 } |
| 1073 | 1116 |
| 1074 #undef __ | 1117 #undef __ |
| 1075 | 1118 |
| 1076 | 1119 |
| 1077 } } // namespace v8::internal | 1120 } } // namespace v8::internal |
| OLD | NEW |