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

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 112863002: Merge bleeding_edge 18021:18297 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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/x64/codegen-x64.cc ('k') | src/x64/ic-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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 } else { 1705 } else {
1720 context()->Plug(rax); 1706 context()->Plug(rax);
1721 } 1707 }
1722 } 1708 }
1723 1709
1724 1710
1725 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { 1711 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1726 Comment cmnt(masm_, "[ ArrayLiteral"); 1712 Comment cmnt(masm_, "[ ArrayLiteral");
1727 1713
1728 expr->BuildConstantElements(isolate()); 1714 expr->BuildConstantElements(isolate());
1715 int flags = expr->depth() == 1
1716 ? ArrayLiteral::kShallowElements
1717 : ArrayLiteral::kNoFlags;
1718
1729 ZoneList<Expression*>* subexprs = expr->values(); 1719 ZoneList<Expression*>* subexprs = expr->values();
1730 int length = subexprs->length(); 1720 int length = subexprs->length();
1731 Handle<FixedArray> constant_elements = expr->constant_elements(); 1721 Handle<FixedArray> constant_elements = expr->constant_elements();
1732 ASSERT_EQ(2, constant_elements->length()); 1722 ASSERT_EQ(2, constant_elements->length());
1733 ElementsKind constant_elements_kind = 1723 ElementsKind constant_elements_kind =
1734 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); 1724 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value());
1735 bool has_constant_fast_elements = 1725 bool has_constant_fast_elements =
1736 IsFastObjectElementsKind(constant_elements_kind); 1726 IsFastObjectElementsKind(constant_elements_kind);
1737 Handle<FixedArrayBase> constant_elements_values( 1727 Handle<FixedArrayBase> constant_elements_values(
1738 FixedArrayBase::cast(constant_elements->get(1))); 1728 FixedArrayBase::cast(constant_elements->get(1)));
1739 1729
1730 AllocationSiteMode allocation_site_mode = FLAG_track_allocation_sites
1731 ? TRACK_ALLOCATION_SITE : DONT_TRACK_ALLOCATION_SITE;
1732 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) {
1733 // If the only customer of allocation sites is transitioning, then
1734 // we can turn it off if we don't have anywhere else to transition to.
1735 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1736 }
1737
1740 Heap* heap = isolate()->heap(); 1738 Heap* heap = isolate()->heap();
1741 if (has_constant_fast_elements && 1739 if (has_constant_fast_elements &&
1742 constant_elements_values->map() == heap->fixed_cow_array_map()) { 1740 constant_elements_values->map() == heap->fixed_cow_array_map()) {
1743 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot 1741 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot
1744 // change, so it's possible to specialize the stub in advance. 1742 // change, so it's possible to specialize the stub in advance.
1745 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); 1743 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1);
1746 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1744 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1747 __ movq(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset)); 1745 __ movq(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset));
1748 __ Move(rbx, Smi::FromInt(expr->literal_index())); 1746 __ Move(rbx, Smi::FromInt(expr->literal_index()));
1749 __ Move(rcx, constant_elements); 1747 __ Move(rcx, constant_elements);
1750 FastCloneShallowArrayStub stub( 1748 FastCloneShallowArrayStub stub(
1751 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, 1749 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS,
1752 DONT_TRACK_ALLOCATION_SITE, 1750 allocation_site_mode,
1753 length); 1751 length);
1754 __ CallStub(&stub); 1752 __ CallStub(&stub);
1755 } else if (expr->depth() > 1 || Serializer::enabled() || 1753 } else if (expr->depth() > 1 || Serializer::enabled() ||
1756 length > FastCloneShallowArrayStub::kMaximumClonedLength) { 1754 length > FastCloneShallowArrayStub::kMaximumClonedLength) {
1757 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1755 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1758 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); 1756 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset));
1759 __ Push(Smi::FromInt(expr->literal_index())); 1757 __ Push(Smi::FromInt(expr->literal_index()));
1760 __ Push(constant_elements); 1758 __ Push(constant_elements);
1761 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); 1759 __ Push(Smi::FromInt(flags));
1760 __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
1762 } else { 1761 } else {
1763 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || 1762 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) ||
1764 FLAG_smi_only_arrays); 1763 FLAG_smi_only_arrays);
1765 FastCloneShallowArrayStub::Mode mode = 1764 FastCloneShallowArrayStub::Mode mode =
1766 FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; 1765 FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS;
1767 AllocationSiteMode allocation_site_mode = FLAG_track_allocation_sites
1768 ? TRACK_ALLOCATION_SITE : DONT_TRACK_ALLOCATION_SITE;
1769 1766
1770 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot 1767 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot
1771 // change, so it's possible to specialize the stub in advance. 1768 // change, so it's possible to specialize the stub in advance.
1772 if (has_constant_fast_elements) { 1769 if (has_constant_fast_elements) {
1773 mode = FastCloneShallowArrayStub::CLONE_ELEMENTS; 1770 mode = FastCloneShallowArrayStub::CLONE_ELEMENTS;
1774 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1775 } 1771 }
1776 1772
1777 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1773 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1778 __ movq(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset)); 1774 __ movq(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset));
1779 __ Move(rbx, Smi::FromInt(expr->literal_index())); 1775 __ Move(rbx, Smi::FromInt(expr->literal_index()));
1780 __ Move(rcx, constant_elements); 1776 __ Move(rcx, constant_elements);
1781 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); 1777 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length);
1782 __ CallStub(&stub); 1778 __ CallStub(&stub);
1783 } 1779 }
1784 1780
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 // rcx to make the shifts easier. 2247 // rcx to make the shifts easier.
2252 Label done, stub_call, smi_case; 2248 Label done, stub_call, smi_case;
2253 __ pop(rdx); 2249 __ pop(rdx);
2254 __ movq(rcx, rax); 2250 __ movq(rcx, rax);
2255 __ or_(rax, rdx); 2251 __ or_(rax, rdx);
2256 JumpPatchSite patch_site(masm_); 2252 JumpPatchSite patch_site(masm_);
2257 patch_site.EmitJumpIfSmi(rax, &smi_case, Label::kNear); 2253 patch_site.EmitJumpIfSmi(rax, &smi_case, Label::kNear);
2258 2254
2259 __ bind(&stub_call); 2255 __ bind(&stub_call);
2260 __ movq(rax, rcx); 2256 __ movq(rax, rcx);
2261 BinaryOpStub stub(op, mode); 2257 BinaryOpICStub stub(op, mode);
2262 CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, 2258 CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET,
2263 expr->BinaryOperationFeedbackId()); 2259 expr->BinaryOperationFeedbackId());
2264 patch_site.EmitPatchInfo(); 2260 patch_site.EmitPatchInfo();
2265 __ jmp(&done, Label::kNear); 2261 __ jmp(&done, Label::kNear);
2266 2262
2267 __ bind(&smi_case); 2263 __ bind(&smi_case);
2268 switch (op) { 2264 switch (op) {
2269 case Token::SAR: 2265 case Token::SAR:
2270 __ SmiShiftArithmeticRight(rax, rdx, rcx); 2266 __ SmiShiftArithmeticRight(rax, rdx, rcx);
2271 break; 2267 break;
(...skipping 28 matching lines...) Expand all
2300 2296
2301 __ bind(&done); 2297 __ bind(&done);
2302 context()->Plug(rax); 2298 context()->Plug(rax);
2303 } 2299 }
2304 2300
2305 2301
2306 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, 2302 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr,
2307 Token::Value op, 2303 Token::Value op,
2308 OverwriteMode mode) { 2304 OverwriteMode mode) {
2309 __ pop(rdx); 2305 __ pop(rdx);
2310 BinaryOpStub stub(op, mode); 2306 BinaryOpICStub stub(op, mode);
2311 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. 2307 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code.
2312 CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, 2308 CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET,
2313 expr->BinaryOperationFeedbackId()); 2309 expr->BinaryOperationFeedbackId());
2314 patch_site.EmitPatchInfo(); 2310 patch_site.EmitPatchInfo();
2315 context()->Plug(rax); 2311 context()->Plug(rax);
2316 } 2312 }
2317 2313
2318 2314
2319 void FullCodeGenerator::EmitAssignment(Expression* expr) { 2315 void FullCodeGenerator::EmitAssignment(Expression* expr) {
2320 // Invalid left-hand sides are rewritten by the parser to have a 'throw 2316 // Invalid left-hand sides are rewritten by the parser to have a 'throw
(...skipping 2067 matching lines...) Expand 10 before | Expand all | Expand 10 after
4388 } 4384 }
4389 } 4385 }
4390 4386
4391 // Record position before stub call. 4387 // Record position before stub call.
4392 SetSourcePosition(expr->position()); 4388 SetSourcePosition(expr->position());
4393 4389
4394 // Call stub for +1/-1. 4390 // Call stub for +1/-1.
4395 __ bind(&stub_call); 4391 __ bind(&stub_call);
4396 __ movq(rdx, rax); 4392 __ movq(rdx, rax);
4397 __ Move(rax, Smi::FromInt(1)); 4393 __ Move(rax, Smi::FromInt(1));
4398 BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE); 4394 BinaryOpICStub stub(expr->binary_op(), NO_OVERWRITE);
4399 CallIC(stub.GetCode(isolate()), 4395 CallIC(stub.GetCode(isolate()),
4400 RelocInfo::CODE_TARGET, 4396 RelocInfo::CODE_TARGET,
4401 expr->CountBinOpFeedbackId()); 4397 expr->CountBinOpFeedbackId());
4402 patch_site.EmitPatchInfo(); 4398 patch_site.EmitPatchInfo();
4403 __ bind(&done); 4399 __ bind(&done);
4404 4400
4405 // Store the value returned in rax. 4401 // Store the value returned in rax.
4406 switch (assign_type) { 4402 switch (assign_type) {
4407 case VARIABLE: 4403 case VARIABLE:
4408 if (expr->is_postfix()) { 4404 if (expr->is_postfix()) {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4823 *context_length = 0; 4819 *context_length = 0;
4824 return previous_; 4820 return previous_;
4825 } 4821 }
4826 4822
4827 4823
4828 #undef __ 4824 #undef __
4829 4825
4830 4826
4831 static const byte kJnsInstruction = 0x79; 4827 static const byte kJnsInstruction = 0x79;
4832 static const byte kJnsOffset = 0x1d; 4828 static const byte kJnsOffset = 0x1d;
4833 static const byte kCallInstruction = 0xe8;
4834 static const byte kNopByteOne = 0x66; 4829 static const byte kNopByteOne = 0x66;
4835 static const byte kNopByteTwo = 0x90; 4830 static const byte kNopByteTwo = 0x90;
4831 #ifdef DEBUG
4832 static const byte kCallInstruction = 0xe8;
4833 #endif
4836 4834
4837 4835
4838 void BackEdgeTable::PatchAt(Code* unoptimized_code, 4836 void BackEdgeTable::PatchAt(Code* unoptimized_code,
4839 Address pc, 4837 Address pc,
4840 BackEdgeState target_state, 4838 BackEdgeState target_state,
4841 Code* replacement_code) { 4839 Code* replacement_code) {
4842 Address call_target_address = pc - kIntSize; 4840 Address call_target_address = pc - kIntSize;
4843 Address jns_instr_address = call_target_address - 3; 4841 Address jns_instr_address = call_target_address - 3;
4844 Address jns_offset_address = call_target_address - 2; 4842 Address jns_offset_address = call_target_address - 2;
4845 4843
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4896 4894
4897 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 4895 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
4898 Assembler::target_address_at(call_target_address)); 4896 Assembler::target_address_at(call_target_address));
4899 return OSR_AFTER_STACK_CHECK; 4897 return OSR_AFTER_STACK_CHECK;
4900 } 4898 }
4901 4899
4902 4900
4903 } } // namespace v8::internal 4901 } } // namespace v8::internal
4904 4902
4905 #endif // V8_TARGET_ARCH_X64 4903 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/codegen-x64.cc ('k') | src/x64/ic-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698