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

Side by Side Diff: src/ia32/code-stubs-ia32.cc

Issue 10103035: Share optimized code for closures. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 6 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/hydrogen-instructions.h ('k') | src/ia32/deoptimizer-ia32.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Speculatively move code object into edx.
131 __ mov(edx, FieldOperand(ebx, FixedArray::kHeaderSize + kPointerSize));
132 __ cmp(ecx, FieldOperand(ebx, FixedArray::kHeaderSize));
133 __ j(equal, &install_optimized);
134
135 // Iterate through the rest of map backwards. edx holds an index as a Smi.
136 Label loop;
137 Label restore;
138 __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset));
139 __ bind(&loop);
140 // Do not double check first entry.
141 __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength)));
142 __ j(equal, &restore);
143 __ sub(edx, Immediate(Smi::FromInt(
144 SharedFunctionInfo::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 optimized code
154 // map and either unmangle them on marking or do nothing as the whole map is
155 // discarded on 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 6947 matching lines...) Expand 10 before | Expand all | Expand 10 after
7066 // ElementsTransitionGenerator::GenerateMapChangeElementTransition 7141 // ElementsTransitionGenerator::GenerateMapChangeElementTransition
7067 // and ElementsTransitionGenerator::GenerateSmiToDouble 7142 // and ElementsTransitionGenerator::GenerateSmiToDouble
7068 // and ElementsTransitionGenerator::GenerateDoubleToObject 7143 // and ElementsTransitionGenerator::GenerateDoubleToObject
7069 { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, 7144 { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET},
7070 { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, 7145 { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET},
7071 // ElementsTransitionGenerator::GenerateDoubleToObject 7146 // ElementsTransitionGenerator::GenerateDoubleToObject
7072 { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, 7147 { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET},
7073 { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, 7148 { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET},
7074 // StoreArrayLiteralElementStub::Generate 7149 // StoreArrayLiteralElementStub::Generate
7075 { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, 7150 { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET},
7151 // FastNewClosureStub
7152 { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET},
7076 // Null termination. 7153 // Null termination.
7077 { REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET} 7154 { REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET}
7078 }; 7155 };
7079 7156
7080 #undef REG 7157 #undef REG
7081 7158
7082 bool RecordWriteStub::IsPregenerated() { 7159 bool RecordWriteStub::IsPregenerated() {
7083 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; 7160 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime;
7084 !entry->object.is(no_reg); 7161 !entry->object.is(no_reg);
7085 entry++) { 7162 entry++) {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
7395 false); 7472 false);
7396 __ pop(edx); 7473 __ pop(edx);
7397 __ ret(0); 7474 __ ret(0);
7398 } 7475 }
7399 7476
7400 #undef __ 7477 #undef __
7401 7478
7402 } } // namespace v8::internal 7479 } } // namespace v8::internal
7403 7480
7404 #endif // V8_TARGET_ARCH_IA32 7481 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/deoptimizer-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698