| OLD | NEW |
| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 312 |
| 313 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { | 313 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 314 __ mov(ebx, Immediate(profiling_counter_)); | 314 __ mov(ebx, Immediate(profiling_counter_)); |
| 315 __ sub(FieldOperand(ebx, Cell::kValueOffset), | 315 __ sub(FieldOperand(ebx, Cell::kValueOffset), |
| 316 Immediate(Smi::FromInt(delta))); | 316 Immediate(Smi::FromInt(delta))); |
| 317 } | 317 } |
| 318 | 318 |
| 319 | 319 |
| 320 void FullCodeGenerator::EmitProfilingCounterReset() { | 320 void FullCodeGenerator::EmitProfilingCounterReset() { |
| 321 int reset_value = FLAG_interrupt_budget; | 321 int reset_value = FLAG_interrupt_budget; |
| 322 if (info_->ShouldSelfOptimize() && !FLAG_retry_self_opt) { | |
| 323 // Self-optimization is a one-off thing: if it fails, don't try again. | |
| 324 reset_value = Smi::kMaxValue; | |
| 325 } | |
| 326 __ mov(ebx, Immediate(profiling_counter_)); | 322 __ mov(ebx, Immediate(profiling_counter_)); |
| 327 __ mov(FieldOperand(ebx, Cell::kValueOffset), | 323 __ mov(FieldOperand(ebx, Cell::kValueOffset), |
| 328 Immediate(Smi::FromInt(reset_value))); | 324 Immediate(Smi::FromInt(reset_value))); |
| 329 } | 325 } |
| 330 | 326 |
| 331 | 327 |
| 332 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, | 328 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 333 Label* back_edge_target) { | 329 Label* back_edge_target) { |
| 334 Comment cmnt(masm_, "[ Back edge bookkeeping"); | 330 Comment cmnt(masm_, "[ Back edge bookkeeping"); |
| 335 Label ok; | 331 Label ok; |
| 336 | 332 |
| 337 int weight = 1; | 333 ASSERT(back_edge_target->is_bound()); |
| 338 if (FLAG_weighted_back_edges) { | 334 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
| 339 ASSERT(back_edge_target->is_bound()); | 335 int weight = Min(kMaxBackEdgeWeight, |
| 340 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); | 336 Max(1, distance / kCodeSizeMultiplier)); |
| 341 weight = Min(kMaxBackEdgeWeight, | |
| 342 Max(1, distance / kCodeSizeMultiplier)); | |
| 343 } | |
| 344 EmitProfilingCounterDecrement(weight); | 337 EmitProfilingCounterDecrement(weight); |
| 345 __ j(positive, &ok, Label::kNear); | 338 __ j(positive, &ok, Label::kNear); |
| 346 __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); | 339 __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
| 347 | 340 |
| 348 // Record a mapping of this PC offset to the OSR id. This is used to find | 341 // Record a mapping of this PC offset to the OSR id. This is used to find |
| 349 // the AST id from the unoptimized code in order to use it as a key into | 342 // the AST id from the unoptimized code in order to use it as a key into |
| 350 // the deoptimization input data found in the optimized code. | 343 // the deoptimization input data found in the optimized code. |
| 351 RecordBackEdge(stmt->OsrEntryId()); | 344 RecordBackEdge(stmt->OsrEntryId()); |
| 352 | 345 |
| 353 EmitProfilingCounterReset(); | 346 EmitProfilingCounterReset(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 365 Comment cmnt(masm_, "[ Return sequence"); | 358 Comment cmnt(masm_, "[ Return sequence"); |
| 366 if (return_label_.is_bound()) { | 359 if (return_label_.is_bound()) { |
| 367 __ jmp(&return_label_); | 360 __ jmp(&return_label_); |
| 368 } else { | 361 } else { |
| 369 // Common return label | 362 // Common return label |
| 370 __ bind(&return_label_); | 363 __ bind(&return_label_); |
| 371 if (FLAG_trace) { | 364 if (FLAG_trace) { |
| 372 __ push(eax); | 365 __ push(eax); |
| 373 __ CallRuntime(Runtime::kTraceExit, 1); | 366 __ CallRuntime(Runtime::kTraceExit, 1); |
| 374 } | 367 } |
| 375 if (FLAG_interrupt_at_exit || FLAG_self_optimization) { | 368 // Pretend that the exit is a backwards jump to the entry. |
| 376 // Pretend that the exit is a backwards jump to the entry. | 369 int weight = 1; |
| 377 int weight = 1; | 370 if (info_->ShouldSelfOptimize()) { |
| 378 if (info_->ShouldSelfOptimize()) { | 371 weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 379 weight = FLAG_interrupt_budget / FLAG_self_opt_count; | 372 } else { |
| 380 } else if (FLAG_weighted_back_edges) { | 373 int distance = masm_->pc_offset(); |
| 381 int distance = masm_->pc_offset(); | 374 weight = Min(kMaxBackEdgeWeight, |
| 382 weight = Min(kMaxBackEdgeWeight, | 375 Max(1, distance / kCodeSizeMultiplier)); |
| 383 Max(1, distance / kCodeSizeMultiplier)); | |
| 384 } | |
| 385 EmitProfilingCounterDecrement(weight); | |
| 386 Label ok; | |
| 387 __ j(positive, &ok, Label::kNear); | |
| 388 __ push(eax); | |
| 389 if (info_->ShouldSelfOptimize() && FLAG_direct_self_opt) { | |
| 390 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
| 391 __ CallRuntime(Runtime::kOptimizeFunctionOnNextCall, 1); | |
| 392 } else { | |
| 393 __ call(isolate()->builtins()->InterruptCheck(), | |
| 394 RelocInfo::CODE_TARGET); | |
| 395 } | |
| 396 __ pop(eax); | |
| 397 EmitProfilingCounterReset(); | |
| 398 __ bind(&ok); | |
| 399 } | 376 } |
| 377 EmitProfilingCounterDecrement(weight); |
| 378 Label ok; |
| 379 __ j(positive, &ok, Label::kNear); |
| 380 __ push(eax); |
| 381 __ call(isolate()->builtins()->InterruptCheck(), |
| 382 RelocInfo::CODE_TARGET); |
| 383 __ pop(eax); |
| 384 EmitProfilingCounterReset(); |
| 385 __ bind(&ok); |
| 400 #ifdef DEBUG | 386 #ifdef DEBUG |
| 401 // Add a label for checking the size of the code used for returning. | 387 // Add a label for checking the size of the code used for returning. |
| 402 Label check_exit_codesize; | 388 Label check_exit_codesize; |
| 403 masm_->bind(&check_exit_codesize); | 389 masm_->bind(&check_exit_codesize); |
| 404 #endif | 390 #endif |
| 405 SetSourcePosition(function()->end_position() - 1); | 391 SetSourcePosition(function()->end_position() - 1); |
| 406 __ RecordJSReturn(); | 392 __ RecordJSReturn(); |
| 407 // Do not use the leave instruction here because it is too short to | 393 // Do not use the leave instruction here because it is too short to |
| 408 // patch with the code required by the debugger. | 394 // patch with the code required by the debugger. |
| 409 __ mov(esp, ebp); | 395 __ mov(esp, ebp); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 __ Drop(1); // Switch value is no longer needed. | 970 __ Drop(1); // Switch value is no longer needed. |
| 985 __ jmp(clause->body_target()); | 971 __ jmp(clause->body_target()); |
| 986 __ bind(&slow_case); | 972 __ bind(&slow_case); |
| 987 } | 973 } |
| 988 | 974 |
| 989 // Record position before stub call for type feedback. | 975 // Record position before stub call for type feedback. |
| 990 SetSourcePosition(clause->position()); | 976 SetSourcePosition(clause->position()); |
| 991 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); | 977 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); |
| 992 CallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId()); | 978 CallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId()); |
| 993 patch_site.EmitPatchInfo(); | 979 patch_site.EmitPatchInfo(); |
| 980 |
| 981 Label skip; |
| 982 __ jmp(&skip, Label::kNear); |
| 983 PrepareForBailout(clause, TOS_REG); |
| 984 __ cmp(eax, isolate()->factory()->true_value()); |
| 985 __ j(not_equal, &next_test); |
| 986 __ Drop(1); |
| 987 __ jmp(clause->body_target()); |
| 988 __ bind(&skip); |
| 989 |
| 994 __ test(eax, eax); | 990 __ test(eax, eax); |
| 995 __ j(not_equal, &next_test); | 991 __ j(not_equal, &next_test); |
| 996 __ Drop(1); // Switch value is no longer needed. | 992 __ Drop(1); // Switch value is no longer needed. |
| 997 __ jmp(clause->body_target()); | 993 __ jmp(clause->body_target()); |
| 998 } | 994 } |
| 999 | 995 |
| 1000 // Discard the test value and jump to the default if present, otherwise to | 996 // Discard the test value and jump to the default if present, otherwise to |
| 1001 // the end of the statement. | 997 // the end of the statement. |
| 1002 __ bind(&next_test); | 998 __ bind(&next_test); |
| 1003 __ Drop(1); // Switch value is no longer needed. | 999 __ Drop(1); // Switch value is no longer needed. |
| (...skipping 2663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3667 VisitForStackValue(args->at(0)); | 3663 VisitForStackValue(args->at(0)); |
| 3668 VisitForStackValue(args->at(1)); | 3664 VisitForStackValue(args->at(1)); |
| 3669 | 3665 |
| 3670 StringCompareStub stub; | 3666 StringCompareStub stub; |
| 3671 __ CallStub(&stub); | 3667 __ CallStub(&stub); |
| 3672 context()->Plug(eax); | 3668 context()->Plug(eax); |
| 3673 } | 3669 } |
| 3674 | 3670 |
| 3675 | 3671 |
| 3676 void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { | 3672 void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { |
| 3677 // Load the argument on the stack and call the stub. | 3673 // Load the argument on the stack and call the runtime function. |
| 3678 TranscendentalCacheStub stub(TranscendentalCache::LOG, | |
| 3679 TranscendentalCacheStub::TAGGED); | |
| 3680 ZoneList<Expression*>* args = expr->arguments(); | 3674 ZoneList<Expression*>* args = expr->arguments(); |
| 3681 ASSERT(args->length() == 1); | 3675 ASSERT(args->length() == 1); |
| 3682 VisitForStackValue(args->at(0)); | 3676 VisitForStackValue(args->at(0)); |
| 3683 __ CallStub(&stub); | 3677 __ CallRuntime(Runtime::kMath_log, 1); |
| 3684 context()->Plug(eax); | 3678 context()->Plug(eax); |
| 3685 } | 3679 } |
| 3686 | 3680 |
| 3687 | 3681 |
| 3688 void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) { | 3682 void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) { |
| 3689 // Load the argument on the stack and call the runtime function. | 3683 // Load the argument on the stack and call the runtime function. |
| 3690 ZoneList<Expression*>* args = expr->arguments(); | 3684 ZoneList<Expression*>* args = expr->arguments(); |
| 3691 ASSERT(args->length() == 1); | 3685 ASSERT(args->length() == 1); |
| 3692 VisitForStackValue(args->at(0)); | 3686 VisitForStackValue(args->at(0)); |
| 3693 __ CallRuntime(Runtime::kMath_sqrt, 1); | 3687 __ CallRuntime(Runtime::kMath_sqrt, 1); |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4840 *stack_depth = 0; | 4834 *stack_depth = 0; |
| 4841 *context_length = 0; | 4835 *context_length = 0; |
| 4842 return previous_; | 4836 return previous_; |
| 4843 } | 4837 } |
| 4844 | 4838 |
| 4845 #undef __ | 4839 #undef __ |
| 4846 | 4840 |
| 4847 | 4841 |
| 4848 static const byte kJnsInstruction = 0x79; | 4842 static const byte kJnsInstruction = 0x79; |
| 4849 static const byte kJnsOffset = 0x11; | 4843 static const byte kJnsOffset = 0x11; |
| 4850 static const byte kCallInstruction = 0xe8; | |
| 4851 static const byte kNopByteOne = 0x66; | 4844 static const byte kNopByteOne = 0x66; |
| 4852 static const byte kNopByteTwo = 0x90; | 4845 static const byte kNopByteTwo = 0x90; |
| 4846 #ifdef DEBUG |
| 4847 static const byte kCallInstruction = 0xe8; |
| 4848 #endif |
| 4853 | 4849 |
| 4854 | 4850 |
| 4855 void BackEdgeTable::PatchAt(Code* unoptimized_code, | 4851 void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 4856 Address pc, | 4852 Address pc, |
| 4857 BackEdgeState target_state, | 4853 BackEdgeState target_state, |
| 4858 Code* replacement_code) { | 4854 Code* replacement_code) { |
| 4859 Address call_target_address = pc - kIntSize; | 4855 Address call_target_address = pc - kIntSize; |
| 4860 Address jns_instr_address = call_target_address - 3; | 4856 Address jns_instr_address = call_target_address - 3; |
| 4861 Address jns_offset_address = call_target_address - 2; | 4857 Address jns_offset_address = call_target_address - 2; |
| 4862 | 4858 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4913 | 4909 |
| 4914 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4910 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 4915 Assembler::target_address_at(call_target_address)); | 4911 Assembler::target_address_at(call_target_address)); |
| 4916 return OSR_AFTER_STACK_CHECK; | 4912 return OSR_AFTER_STACK_CHECK; |
| 4917 } | 4913 } |
| 4918 | 4914 |
| 4919 | 4915 |
| 4920 } } // namespace v8::internal | 4916 } } // namespace v8::internal |
| 4921 | 4917 |
| 4922 #endif // V8_TARGET_ARCH_IA32 | 4918 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |