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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 __ pop(ecx); // Pop return address. | 59 __ pop(ecx); // Pop return address. |
60 __ push(eax); | 60 __ push(eax); |
61 __ push(ecx); // Push return address. | 61 __ push(ecx); // Push return address. |
62 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); | 62 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
63 } | 63 } |
64 | 64 |
65 | 65 |
66 void FastNewClosureStub::Generate(MacroAssembler* masm) { | 66 void FastNewClosureStub::Generate(MacroAssembler* masm) { |
67 // Create a new closure from the given function info in new | 67 // Create a new closure from the given function info in new |
68 // space. Set the context to the current context in esi. | 68 // space. Set the context to the current context in esi. |
69 Counters* counters = masm->isolate()->counters(); | |
70 | |
69 Label gc; | 71 Label gc; |
70 __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); | 72 __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
71 | 73 |
74 __ IncrementCounter(counters->fast_new_closure_total(), 1); | |
75 | |
72 // Get the function info from the stack. | 76 // Get the function info from the stack. |
73 __ mov(edx, Operand(esp, 1 * kPointerSize)); | 77 __ mov(edx, Operand(esp, 1 * kPointerSize)); |
74 | 78 |
75 int map_index = (language_mode_ == CLASSIC_MODE) | 79 int map_index = (language_mode_ == CLASSIC_MODE) |
76 ? Context::FUNCTION_MAP_INDEX | 80 ? Context::FUNCTION_MAP_INDEX |
77 : Context::STRICT_MODE_FUNCTION_MAP_INDEX; | 81 : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
78 | 82 |
79 // Compute the function map in the current global context and set that | 83 // Compute the function map in the current global context and set that |
80 // as the map of the allocated object. | 84 // as the map of the allocated object. |
81 __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); | 85 __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
82 __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); | 86 __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); |
83 __ mov(ecx, Operand(ecx, Context::SlotOffset(map_index))); | 87 __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
84 __ mov(FieldOperand(eax, JSObject::kMapOffset), ecx); | 88 __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
85 | 89 |
86 // Initialize the rest of the function. We don't have to update the | 90 // Initialize the rest of the function. We don't have to update the |
87 // write barrier because the allocated object is in new space. | 91 // write barrier because the allocated object is in new space. |
88 Factory* factory = masm->isolate()->factory(); | 92 Factory* factory = masm->isolate()->factory(); |
89 __ mov(ebx, Immediate(factory->empty_fixed_array())); | 93 __ mov(ebx, Immediate(factory->empty_fixed_array())); |
90 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); | 94 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
91 __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); | 95 __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
92 __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), | 96 __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
93 Immediate(factory->the_hole_value())); | 97 Immediate(factory->the_hole_value())); |
94 __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); | 98 __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
95 __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); | 99 __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
96 __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); | 100 __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
97 __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), | |
98 Immediate(factory->undefined_value())); | |
99 | 101 |
100 // Initialize the code pointer in the function to be the one | 102 // Initialize the code pointer in the function to be the one |
101 // found in the shared function info object. | 103 // found in the shared function info object. |
104 // But first check if there is an optimized version for our context. | |
105 Label check_optimized; | |
106 Label install_unoptimized; | |
107 if (FLAG_cache_optimized_code) { | |
108 __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); | |
109 __ test(ebx, ebx); | |
110 __ j(not_zero, &check_optimized, Label::kNear); | |
111 } | |
112 __ bind(&install_unoptimized); | |
113 __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), | |
114 Immediate(factory->undefined_value())); | |
102 __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); | 115 __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
103 __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); | 116 __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
104 __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); | 117 __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
105 | 118 |
106 // Return and remove the on-stack parameter. | 119 // Return and remove the on-stack parameter. |
107 __ ret(1 * kPointerSize); | 120 __ ret(1 * kPointerSize); |
108 | 121 |
122 __ bind(&check_optimized); | |
123 | |
124 __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); | |
125 | |
126 // ecx holds global context, ebx points to fixed array of 3-element entries | |
127 // (global context, optimized code, literals). | |
128 // Map must never be empty, so check the first elements. | |
129 Label install_optimized; | |
130 const int kEntryLength = 3; | |
Michael Starzinger
2012/05/23 11:16:29
Again, having this constant in SharedFunctionInfo
fschneider
2012/06/14 11:08:23
Done.
| |
131 // Speculatively move code object into edx. | |
132 __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize)); | |
133 __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize)); | |
134 __ j(equal, &install_optimized); | |
135 | |
136 // Iterate through the rest of map backwards. edx holds an index as a Smi. | |
137 Label loop; | |
138 Label restore; | |
139 __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); | |
140 __ bind(&loop); | |
141 // Do not double check first entry. | |
142 __ cmp(edx, Immediate(Smi::FromInt(kEntryLength))); | |
143 __ j(equal, &restore); | |
144 __ sub(edx, Immediate(Smi::FromInt(kEntryLength))); // Skip an entry. | |
145 __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); | |
146 __ j(not_equal, &loop, Label::kNear); | |
147 // Hit: fetch the optimized code. | |
148 __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); | |
149 | |
150 __ bind(&install_optimized); | |
151 __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); | |
152 | |
153 // TODO(fschneider): Idea: store proper code pointers in the map and either | |
154 // unmangle them on marking or do nothing as the whole map is discarded on | |
155 // major GC anyway. | |
156 __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); | |
157 __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); | |
158 | |
159 // Now link a function into a list of optimized functions. | |
160 __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); | |
161 | |
162 __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); | |
163 // No need for write barrier as JSFunction (eax) is in the new space. | |
164 | |
165 __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); | |
166 // Store JSFunction (eax) into edx before issuing write barrier as | |
167 // it clobbers all the registers passed. | |
168 __ mov(edx, eax); | |
169 __ RecordWriteContextSlot( | |
170 ecx, | |
171 Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), | |
172 edx, | |
173 ebx, | |
174 kDontSaveFPRegs); | |
175 | |
176 // Return and remove the on-stack parameter. | |
177 __ ret(1 * kPointerSize); | |
178 | |
179 __ bind(&restore); | |
180 // Restore SharedFunctionInfo into edx. | |
181 __ mov(edx, Operand(esp, 1 * kPointerSize)); | |
182 __ jmp(&install_unoptimized); | |
183 | |
109 // Create a new closure through the slower runtime call. | 184 // Create a new closure through the slower runtime call. |
110 __ bind(&gc); | 185 __ bind(&gc); |
111 __ pop(ecx); // Temporarily remove return address. | 186 __ pop(ecx); // Temporarily remove return address. |
112 __ pop(edx); | 187 __ pop(edx); |
113 __ push(esi); | 188 __ push(esi); |
114 __ push(edx); | 189 __ push(edx); |
115 __ push(Immediate(factory->false_value())); | 190 __ push(Immediate(factory->false_value())); |
116 __ push(ecx); // Restore return address. | 191 __ push(ecx); // Restore return address. |
117 __ TailCallRuntime(Runtime::kNewClosure, 3, 1); | 192 __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
118 } | 193 } |
(...skipping 6941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7060 // ElementsTransitionGenerator::GenerateSmiOnlyToObject | 7135 // ElementsTransitionGenerator::GenerateSmiOnlyToObject |
7061 // and ElementsTransitionGenerator::GenerateSmiOnlyToDouble | 7136 // and ElementsTransitionGenerator::GenerateSmiOnlyToDouble |
7062 // and ElementsTransitionGenerator::GenerateDoubleToObject | 7137 // and ElementsTransitionGenerator::GenerateDoubleToObject |
7063 { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, | 7138 { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
7064 { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, | 7139 { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
7065 // ElementsTransitionGenerator::GenerateDoubleToObject | 7140 // ElementsTransitionGenerator::GenerateDoubleToObject |
7066 { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, | 7141 { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
7067 { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, | 7142 { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
7068 // StoreArrayLiteralElementStub::Generate | 7143 // StoreArrayLiteralElementStub::Generate |
7069 { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, | 7144 { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
7145 // FastNewClosureStub | |
7146 { ecx, edx, ebx, EMIT_REMEMBERED_SET}, | |
Michael Starzinger
2012/05/23 11:16:29
Use the REG macro as well.
fschneider
2012/06/14 11:08:23
Done.
| |
7070 // Null termination. | 7147 // Null termination. |
7071 { REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET} | 7148 { REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET} |
7072 }; | 7149 }; |
7073 | 7150 |
7074 #undef REG | 7151 #undef REG |
7075 | 7152 |
7076 bool RecordWriteStub::IsPregenerated() { | 7153 bool RecordWriteStub::IsPregenerated() { |
7077 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; | 7154 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
7078 !entry->object.is(no_reg); | 7155 !entry->object.is(no_reg); |
7079 entry++) { | 7156 entry++) { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7389 false); | 7466 false); |
7390 __ pop(edx); | 7467 __ pop(edx); |
7391 __ ret(0); | 7468 __ ret(0); |
7392 } | 7469 } |
7393 | 7470 |
7394 #undef __ | 7471 #undef __ |
7395 | 7472 |
7396 } } // namespace v8::internal | 7473 } } // namespace v8::internal |
7397 | 7474 |
7398 #endif // V8_TARGET_ARCH_IA32 | 7475 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |