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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 303 |
304 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { | 304 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
305 __ movq(rbx, profiling_counter_, RelocInfo::EMBEDDED_OBJECT); | 305 __ movq(rbx, profiling_counter_, RelocInfo::EMBEDDED_OBJECT); |
306 __ SmiAddConstant(FieldOperand(rbx, Cell::kValueOffset), | 306 __ SmiAddConstant(FieldOperand(rbx, Cell::kValueOffset), |
307 Smi::FromInt(-delta)); | 307 Smi::FromInt(-delta)); |
308 } | 308 } |
309 | 309 |
310 | 310 |
311 void FullCodeGenerator::EmitProfilingCounterReset() { | 311 void FullCodeGenerator::EmitProfilingCounterReset() { |
312 int reset_value = FLAG_interrupt_budget; | 312 int reset_value = FLAG_interrupt_budget; |
313 if (info_->ShouldSelfOptimize() && !FLAG_retry_self_opt) { | |
314 // Self-optimization is a one-off thing; if it fails, don't try again. | |
315 reset_value = Smi::kMaxValue; | |
316 } | |
317 __ movq(rbx, profiling_counter_, RelocInfo::EMBEDDED_OBJECT); | 313 __ movq(rbx, profiling_counter_, RelocInfo::EMBEDDED_OBJECT); |
318 __ Move(kScratchRegister, Smi::FromInt(reset_value)); | 314 __ Move(kScratchRegister, Smi::FromInt(reset_value)); |
319 __ movq(FieldOperand(rbx, Cell::kValueOffset), kScratchRegister); | 315 __ movq(FieldOperand(rbx, Cell::kValueOffset), kScratchRegister); |
320 } | 316 } |
321 | 317 |
322 | 318 |
323 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, | 319 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
324 Label* back_edge_target) { | 320 Label* back_edge_target) { |
325 Comment cmnt(masm_, "[ Back edge bookkeeping"); | 321 Comment cmnt(masm_, "[ Back edge bookkeeping"); |
326 Label ok; | 322 Label ok; |
327 | 323 |
328 int weight = 1; | 324 ASSERT(back_edge_target->is_bound()); |
329 if (FLAG_weighted_back_edges) { | 325 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
330 ASSERT(back_edge_target->is_bound()); | 326 int weight = Min(kMaxBackEdgeWeight, |
331 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); | 327 Max(1, distance / kCodeSizeMultiplier)); |
332 weight = Min(kMaxBackEdgeWeight, | |
333 Max(1, distance / kCodeSizeMultiplier)); | |
334 } | |
335 EmitProfilingCounterDecrement(weight); | 328 EmitProfilingCounterDecrement(weight); |
336 __ j(positive, &ok, Label::kNear); | 329 __ j(positive, &ok, Label::kNear); |
337 __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); | 330 __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
338 | 331 |
339 // Record a mapping of this PC offset to the OSR id. This is used to find | 332 // Record a mapping of this PC offset to the OSR id. This is used to find |
340 // the AST id from the unoptimized code in order to use it as a key into | 333 // the AST id from the unoptimized code in order to use it as a key into |
341 // the deoptimization input data found in the optimized code. | 334 // the deoptimization input data found in the optimized code. |
342 RecordBackEdge(stmt->OsrEntryId()); | 335 RecordBackEdge(stmt->OsrEntryId()); |
343 | 336 |
344 EmitProfilingCounterReset(); | 337 EmitProfilingCounterReset(); |
(...skipping 10 matching lines...) Expand all Loading... |
355 void FullCodeGenerator::EmitReturnSequence() { | 348 void FullCodeGenerator::EmitReturnSequence() { |
356 Comment cmnt(masm_, "[ Return sequence"); | 349 Comment cmnt(masm_, "[ Return sequence"); |
357 if (return_label_.is_bound()) { | 350 if (return_label_.is_bound()) { |
358 __ jmp(&return_label_); | 351 __ jmp(&return_label_); |
359 } else { | 352 } else { |
360 __ bind(&return_label_); | 353 __ bind(&return_label_); |
361 if (FLAG_trace) { | 354 if (FLAG_trace) { |
362 __ push(rax); | 355 __ push(rax); |
363 __ CallRuntime(Runtime::kTraceExit, 1); | 356 __ CallRuntime(Runtime::kTraceExit, 1); |
364 } | 357 } |
365 if (FLAG_interrupt_at_exit || FLAG_self_optimization) { | 358 // Pretend that the exit is a backwards jump to the entry. |
366 // Pretend that the exit is a backwards jump to the entry. | 359 int weight = 1; |
367 int weight = 1; | 360 if (info_->ShouldSelfOptimize()) { |
368 if (info_->ShouldSelfOptimize()) { | 361 weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
369 weight = FLAG_interrupt_budget / FLAG_self_opt_count; | 362 } else { |
370 } else if (FLAG_weighted_back_edges) { | 363 int distance = masm_->pc_offset(); |
371 int distance = masm_->pc_offset(); | 364 weight = Min(kMaxBackEdgeWeight, |
372 weight = Min(kMaxBackEdgeWeight, | 365 Max(1, distance / kCodeSizeMultiplier)); |
373 Max(1, distance / kCodeSizeMultiplier)); | |
374 } | |
375 EmitProfilingCounterDecrement(weight); | |
376 Label ok; | |
377 __ j(positive, &ok, Label::kNear); | |
378 __ push(rax); | |
379 if (info_->ShouldSelfOptimize() && FLAG_direct_self_opt) { | |
380 __ push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | |
381 __ CallRuntime(Runtime::kOptimizeFunctionOnNextCall, 1); | |
382 } else { | |
383 __ call(isolate()->builtins()->InterruptCheck(), | |
384 RelocInfo::CODE_TARGET); | |
385 } | |
386 __ pop(rax); | |
387 EmitProfilingCounterReset(); | |
388 __ bind(&ok); | |
389 } | 366 } |
| 367 EmitProfilingCounterDecrement(weight); |
| 368 Label ok; |
| 369 __ j(positive, &ok, Label::kNear); |
| 370 __ push(rax); |
| 371 __ call(isolate()->builtins()->InterruptCheck(), |
| 372 RelocInfo::CODE_TARGET); |
| 373 __ pop(rax); |
| 374 EmitProfilingCounterReset(); |
| 375 __ bind(&ok); |
390 #ifdef DEBUG | 376 #ifdef DEBUG |
391 // Add a label for checking the size of the code used for returning. | 377 // Add a label for checking the size of the code used for returning. |
392 Label check_exit_codesize; | 378 Label check_exit_codesize; |
393 masm_->bind(&check_exit_codesize); | 379 masm_->bind(&check_exit_codesize); |
394 #endif | 380 #endif |
395 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); | 381 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
396 __ RecordJSReturn(); | 382 __ RecordJSReturn(); |
397 // Do not use the leave instruction here because it is too short to | 383 // Do not use the leave instruction here because it is too short to |
398 // patch with the code required by the debugger. | 384 // patch with the code required by the debugger. |
399 __ movq(rsp, rbp); | 385 __ movq(rsp, rbp); |
(...skipping 4506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4906 | 4892 |
4907 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4893 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4908 Assembler::target_address_at(call_target_address)); | 4894 Assembler::target_address_at(call_target_address)); |
4909 return OSR_AFTER_STACK_CHECK; | 4895 return OSR_AFTER_STACK_CHECK; |
4910 } | 4896 } |
4911 | 4897 |
4912 | 4898 |
4913 } } // namespace v8::internal | 4899 } } // namespace v8::internal |
4914 | 4900 |
4915 #endif // V8_TARGET_ARCH_X64 | 4901 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |