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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 | 94 |
95 MacroAssembler* masm_; | 95 MacroAssembler* masm_; |
96 Label patch_site_; | 96 Label patch_site_; |
97 #ifdef DEBUG | 97 #ifdef DEBUG |
98 bool info_emitted_; | 98 bool info_emitted_; |
99 #endif | 99 #endif |
100 }; | 100 }; |
101 | 101 |
102 | 102 |
| 103 int FullCodeGenerator::self_optimization_header_size() { |
| 104 return 20; |
| 105 } |
| 106 |
| 107 |
103 // Generate code for a JS function. On entry to the function the receiver | 108 // Generate code for a JS function. On entry to the function the receiver |
104 // and arguments have been pushed on the stack left to right, with the | 109 // and arguments have been pushed on the stack left to right, with the |
105 // return address on top of them. The actual argument count matches the | 110 // return address on top of them. The actual argument count matches the |
106 // formal parameter count expected by the function. | 111 // formal parameter count expected by the function. |
107 // | 112 // |
108 // The live registers are: | 113 // The live registers are: |
109 // o rdi: the JS function object being called (i.e. ourselves) | 114 // o rdi: the JS function object being called (i.e. ourselves) |
110 // o rsi: our context | 115 // o rsi: our context |
111 // o rbp: our caller's frame pointer | 116 // o rbp: our caller's frame pointer |
112 // o rsp: stack pointer (pointing to return address) | 117 // o rsp: stack pointer (pointing to return address) |
113 // | 118 // |
114 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 119 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
115 // frames-x64.h for its layout. | 120 // frames-x64.h for its layout. |
116 void FullCodeGenerator::Generate() { | 121 void FullCodeGenerator::Generate() { |
117 CompilationInfo* info = info_; | 122 CompilationInfo* info = info_; |
118 handler_table_ = | 123 handler_table_ = |
119 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); | 124 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
120 SetFunctionPosition(function()); | 125 SetFunctionPosition(function()); |
121 Comment cmnt(masm_, "[ function compiled by full code generator"); | 126 Comment cmnt(masm_, "[ function compiled by full code generator"); |
122 | 127 |
123 #ifdef DEBUG | |
124 if (strlen(FLAG_stop_at) > 0 && | |
125 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { | |
126 __ int3(); | |
127 } | |
128 #endif | |
129 | |
130 // We can optionally optimize based on counters rather than statistical | 128 // We can optionally optimize based on counters rather than statistical |
131 // sampling. | 129 // sampling. |
132 if (info->ShouldSelfOptimize()) { | 130 if (info->ShouldSelfOptimize()) { |
133 if (FLAG_trace_opt_verbose) { | 131 if (FLAG_trace_opt_verbose) { |
134 PrintF("[adding self-optimization header to %s]\n", | 132 PrintF("[adding self-optimization header to %s]\n", |
135 *info->function()->debug_name()->ToCString()); | 133 *info->function()->debug_name()->ToCString()); |
136 } | 134 } |
| 135 has_self_optimization_header_ = true; |
137 MaybeObject* maybe_cell = isolate()->heap()->AllocateJSGlobalPropertyCell( | 136 MaybeObject* maybe_cell = isolate()->heap()->AllocateJSGlobalPropertyCell( |
138 Smi::FromInt(Compiler::kCallsUntilPrimitiveOpt)); | 137 Smi::FromInt(Compiler::kCallsUntilPrimitiveOpt)); |
139 JSGlobalPropertyCell* cell; | 138 JSGlobalPropertyCell* cell; |
140 if (maybe_cell->To(&cell)) { | 139 if (maybe_cell->To(&cell)) { |
141 __ movq(rax, Handle<JSGlobalPropertyCell>(cell), | 140 __ movq(rax, Handle<JSGlobalPropertyCell>(cell), |
142 RelocInfo::EMBEDDED_OBJECT); | 141 RelocInfo::EMBEDDED_OBJECT); |
143 __ SmiAddConstant(FieldOperand(rax, JSGlobalPropertyCell::kValueOffset), | 142 __ SmiAddConstant(FieldOperand(rax, JSGlobalPropertyCell::kValueOffset), |
144 Smi::FromInt(-1)); | 143 Smi::FromInt(-1)); |
145 Handle<Code> compile_stub( | 144 Handle<Code> compile_stub( |
146 isolate()->builtins()->builtin(Builtins::kLazyRecompile)); | 145 isolate()->builtins()->builtin(Builtins::kLazyRecompile)); |
147 __ j(zero, compile_stub, RelocInfo::CODE_TARGET); | 146 __ j(zero, compile_stub, RelocInfo::CODE_TARGET); |
| 147 ASSERT(masm_->pc_offset() == self_optimization_header_size()); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
| 151 #ifdef DEBUG |
| 152 if (strlen(FLAG_stop_at) > 0 && |
| 153 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 154 __ int3(); |
| 155 } |
| 156 #endif |
| 157 |
151 // Strict mode functions and builtins need to replace the receiver | 158 // Strict mode functions and builtins need to replace the receiver |
152 // with undefined when called as functions (without an explicit | 159 // with undefined when called as functions (without an explicit |
153 // receiver object). rcx is zero for method calls and non-zero for | 160 // receiver object). rcx is zero for method calls and non-zero for |
154 // function calls. | 161 // function calls. |
155 if (!info->is_classic_mode() || info->is_native()) { | 162 if (!info->is_classic_mode() || info->is_native()) { |
156 Label ok; | 163 Label ok; |
157 __ testq(rcx, rcx); | 164 __ testq(rcx, rcx); |
158 __ j(zero, &ok, Label::kNear); | 165 __ j(zero, &ok, Label::kNear); |
159 // +1 for return address. | 166 // +1 for return address. |
160 int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; | 167 int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
(...skipping 4184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4345 *context_length = 0; | 4352 *context_length = 0; |
4346 return previous_; | 4353 return previous_; |
4347 } | 4354 } |
4348 | 4355 |
4349 | 4356 |
4350 #undef __ | 4357 #undef __ |
4351 | 4358 |
4352 } } // namespace v8::internal | 4359 } } // namespace v8::internal |
4353 | 4360 |
4354 #endif // V8_TARGET_ARCH_X64 | 4361 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |