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

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

Issue 19638014: Factor out common code from platform-specific deoptimization. Fix Deoptimizer not to need to partit… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Cleanups post-review. Created 7 years, 5 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/objects-inl.h ('k') | no next file » | 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 28 matching lines...) Expand all
39 39
40 40
41 const int Deoptimizer::table_entry_size_ = 10; 41 const int Deoptimizer::table_entry_size_ = 10;
42 42
43 43
44 int Deoptimizer::patch_size() { 44 int Deoptimizer::patch_size() {
45 return Assembler::kCallInstructionLength; 45 return Assembler::kCallInstructionLength;
46 } 46 }
47 47
48 48
49 void Deoptimizer::DeoptimizeFunctionWithPreparedFunctionList( 49 void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) {
50 JSFunction* function) {
51 Isolate* isolate = function->GetIsolate();
52 HandleScope scope(isolate);
53 DisallowHeapAllocation nha;
54
55 ASSERT(function->IsOptimized());
56 ASSERT(function->FunctionsInFunctionListShareSameCode());
57
58 // Get the optimized code.
59 Code* code = function->code();
60
61 // The optimized code is going to be patched, so we cannot use it any more.
62 function->shared()->EvictFromOptimizedCodeMap(code, "deoptimized function");
63
64 // Invalidate the relocation information, as it will become invalid by the 50 // Invalidate the relocation information, as it will become invalid by the
65 // code patching below, and is not needed any more. 51 // code patching below, and is not needed any more.
66 code->InvalidateRelocation(); 52 code->InvalidateRelocation();
67 53
68 // For each LLazyBailout instruction insert a absolute call to the 54 // For each LLazyBailout instruction insert a absolute call to the
69 // corresponding deoptimization entry, or a short call to an absolute 55 // corresponding deoptimization entry, or a short call to an absolute
70 // jump if space is short. The absolute jumps are put in a table just 56 // jump if space is short. The absolute jumps are put in a table just
71 // before the safepoint table (space was allocated there when the Code 57 // before the safepoint table (space was allocated there when the Code
72 // object was created, if necessary). 58 // object was created, if necessary).
73 59
74 Address instruction_start = function->code()->instruction_start(); 60 Address instruction_start = code->instruction_start();
75 #ifdef DEBUG 61 #ifdef DEBUG
76 Address prev_call_address = NULL; 62 Address prev_call_address = NULL;
77 #endif 63 #endif
78 DeoptimizationInputData* deopt_data = 64 DeoptimizationInputData* deopt_data =
79 DeoptimizationInputData::cast(code->deoptimization_data()); 65 DeoptimizationInputData::cast(code->deoptimization_data());
80 for (int i = 0; i < deopt_data->DeoptCount(); i++) { 66 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
81 if (deopt_data->Pc(i)->value() == -1) continue; 67 if (deopt_data->Pc(i)->value() == -1) continue;
82 // Position where Call will be patched in. 68 // Position where Call will be patched in.
83 Address call_address = instruction_start + deopt_data->Pc(i)->value(); 69 Address call_address = instruction_start + deopt_data->Pc(i)->value();
84 // There is room enough to write a long call instruction because we pad 70 // There is room enough to write a long call instruction because we pad
85 // LLazyBailout instructions with nops if necessary. 71 // LLazyBailout instructions with nops if necessary.
86 CodePatcher patcher(call_address, Assembler::kCallInstructionLength); 72 CodePatcher patcher(call_address, Assembler::kCallInstructionLength);
87 patcher.masm()->Call(GetDeoptimizationEntry(isolate, i, LAZY), 73 patcher.masm()->Call(GetDeoptimizationEntry(isolate, i, LAZY),
88 RelocInfo::NONE64); 74 RelocInfo::NONE64);
89 ASSERT(prev_call_address == NULL || 75 ASSERT(prev_call_address == NULL ||
90 call_address >= prev_call_address + patch_size()); 76 call_address >= prev_call_address + patch_size());
91 ASSERT(call_address + patch_size() <= code->instruction_end()); 77 ASSERT(call_address + patch_size() <= code->instruction_end());
92 #ifdef DEBUG 78 #ifdef DEBUG
93 prev_call_address = call_address; 79 prev_call_address = call_address;
94 #endif 80 #endif
95 } 81 }
96
97 // Add the deoptimizing code to the list.
98 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code);
99 DeoptimizerData* data = isolate->deoptimizer_data();
100 node->set_next(data->deoptimizing_code_list_);
101 data->deoptimizing_code_list_ = node;
102
103 // We might be in the middle of incremental marking with compaction.
104 // Tell collector to treat this code object in a special way and
105 // ignore all slots that might have been recorded on it.
106 isolate->heap()->mark_compact_collector()->InvalidateCode(code);
107
108 ReplaceCodeForRelatedFunctions(function, code);
109
110 if (FLAG_trace_deopt) {
111 PrintF("[forced deoptimization: ");
112 function->PrintName();
113 PrintF(" / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function));
114 }
115 } 82 }
116 83
117 84
118 static const byte kJnsInstruction = 0x79; 85 static const byte kJnsInstruction = 0x79;
119 static const byte kJnsOffset = 0x1d; 86 static const byte kJnsOffset = 0x1d;
120 static const byte kCallInstruction = 0xe8; 87 static const byte kCallInstruction = 0xe8;
121 static const byte kNopByteOne = 0x66; 88 static const byte kNopByteOne = 0x66;
122 static const byte kNopByteTwo = 0x90; 89 static const byte kNopByteTwo = 0x90;
123 90
124 // The back edge bookkeeping code matches the pattern: 91 // The back edge bookkeeping code matches the pattern:
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 576 }
610 __ bind(&done); 577 __ bind(&done);
611 } 578 }
612 579
613 #undef __ 580 #undef __
614 581
615 582
616 } } // namespace v8::internal 583 } } // namespace v8::internal
617 584
618 #endif // V8_TARGET_ARCH_X64 585 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698