OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 int CodeStub::GetCodeKind() { | 94 int CodeStub::GetCodeKind() { |
95 return Code::STUB; | 95 return Code::STUB; |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 Handle<Code> CodeStub::GetCode() { | 99 Handle<Code> CodeStub::GetCode() { |
100 Isolate* isolate = Isolate::Current(); | 100 Isolate* isolate = Isolate::Current(); |
101 Factory* factory = isolate->factory(); | 101 Factory* factory = isolate->factory(); |
102 Heap* heap = isolate->heap(); | 102 Heap* heap = isolate->heap(); |
103 Code* code; | 103 Code* code; |
104 if (UseSpecialCache() | 104 if (!FindCodeInCache(&code)) { |
105 ? FindCodeInSpecialCache(&code) | |
106 : FindCodeInCache(&code)) { | |
107 ASSERT(IsPregenerated() == code->is_pregenerated()); | |
108 return Handle<Code>(code); | |
109 } | |
110 | |
111 { | |
112 HandleScope scope(isolate); | 105 HandleScope scope(isolate); |
113 | 106 |
114 // Generate the new code. | 107 // Generate the new code. |
115 MacroAssembler masm(isolate, NULL, 256); | 108 MacroAssembler masm(isolate, NULL, 256); |
116 GenerateCode(&masm); | 109 GenerateCode(&masm); |
117 | 110 |
118 // Create the code object. | 111 // Create the code object. |
119 CodeDesc desc; | 112 CodeDesc desc; |
120 masm.GetCode(&desc); | 113 masm.GetCode(&desc); |
121 | 114 |
122 // Copy the generated code into a heap object. | 115 // Copy the generated code into a heap object. |
123 Code::Flags flags = Code::ComputeFlags( | 116 Code::Flags flags = Code::ComputeFlags( |
124 static_cast<Code::Kind>(GetCodeKind()), | 117 static_cast<Code::Kind>(GetCodeKind()), |
125 GetICState()); | 118 GetICState()); |
126 Handle<Code> new_object = factory->NewCode( | 119 Handle<Code> new_object = factory->NewCode( |
127 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | 120 desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
128 RecordCodeGeneration(*new_object, &masm); | 121 RecordCodeGeneration(*new_object, &masm); |
129 FinishCode(new_object); | 122 FinishCode(new_object); |
130 | 123 |
131 if (UseSpecialCache()) { | 124 // Update the dictionary and the root in Heap. |
132 AddToSpecialCache(new_object); | 125 Handle<NumberDictionary> dict = |
133 } else { | 126 factory->DictionaryAtNumberPut( |
134 // Update the dictionary and the root in Heap. | 127 Handle<NumberDictionary>(heap->code_stubs()), |
135 Handle<NumberDictionary> dict = | 128 GetKey(), |
136 factory->DictionaryAtNumberPut( | 129 new_object); |
137 Handle<NumberDictionary>(heap->code_stubs()), | 130 heap->public_set_code_stubs(*dict); |
138 GetKey(), | |
139 new_object); | |
140 heap->public_set_code_stubs(*dict); | |
141 } | |
142 code = *new_object; | 131 code = *new_object; |
| 132 Activate(code); |
| 133 } else { |
| 134 CHECK(IsPregenerated() == code->is_pregenerated()); |
143 } | 135 } |
144 | 136 |
145 Activate(code); | |
146 ASSERT(!NeedsImmovableCode() || heap->lo_space()->Contains(code)); | 137 ASSERT(!NeedsImmovableCode() || heap->lo_space()->Contains(code)); |
147 return Handle<Code>(code, isolate); | 138 return Handle<Code>(code, isolate); |
148 } | 139 } |
149 | 140 |
150 | 141 |
151 const char* CodeStub::MajorName(CodeStub::Major major_key, | 142 const char* CodeStub::MajorName(CodeStub::Major major_key, |
152 bool allow_unknown_keys) { | 143 bool allow_unknown_keys) { |
153 switch (major_key) { | 144 switch (major_key) { |
154 #define DEF_CASE(name) case name: return #name "Stub"; | 145 #define DEF_CASE(name) case name: return #name "Stub"; |
155 CODE_STUB_LIST(DEF_CASE) | 146 CODE_STUB_LIST(DEF_CASE) |
156 #undef DEF_CASE | 147 #undef DEF_CASE |
157 default: | 148 default: |
158 if (!allow_unknown_keys) { | 149 if (!allow_unknown_keys) { |
159 UNREACHABLE(); | 150 UNREACHABLE(); |
160 } | 151 } |
161 return NULL; | 152 return NULL; |
162 } | 153 } |
163 } | 154 } |
164 | 155 |
165 | 156 |
166 void CodeStub::PrintName(StringStream* stream) { | 157 void CodeStub::PrintName(StringStream* stream) { |
167 stream->Add("%s", MajorName(MajorKey(), false)); | 158 stream->Add("%s", MajorName(MajorKey(), false)); |
168 } | 159 } |
169 | 160 |
170 | 161 |
171 void ICCompareStub::AddToSpecialCache(Handle<Code> new_object) { | |
172 ASSERT(*known_map_ != NULL); | |
173 Isolate* isolate = new_object->GetIsolate(); | |
174 Factory* factory = isolate->factory(); | |
175 return Map::UpdateCodeCache(known_map_, | |
176 factory->compare_ic_symbol(), | |
177 new_object); | |
178 } | |
179 | |
180 | |
181 bool ICCompareStub::FindCodeInSpecialCache(Code** code_out) { | |
182 Isolate* isolate = known_map_->GetIsolate(); | |
183 Factory* factory = isolate->factory(); | |
184 Code::Flags flags = Code::ComputeFlags( | |
185 static_cast<Code::Kind>(GetCodeKind()), | |
186 UNINITIALIZED); | |
187 Handle<Object> probe( | |
188 known_map_->FindInCodeCache(*factory->compare_ic_symbol(), flags)); | |
189 if (probe->IsCode()) { | |
190 *code_out = Code::cast(*probe); | |
191 return true; | |
192 } | |
193 return false; | |
194 } | |
195 | |
196 | |
197 int ICCompareStub::MinorKey() { | 162 int ICCompareStub::MinorKey() { |
198 return OpField::encode(op_ - Token::EQ) | StateField::encode(state_); | 163 return OpField::encode(op_ - Token::EQ) | StateField::encode(state_); |
199 } | 164 } |
200 | 165 |
201 | 166 |
202 void ICCompareStub::Generate(MacroAssembler* masm) { | 167 void ICCompareStub::Generate(MacroAssembler* masm) { |
203 switch (state_) { | 168 switch (state_) { |
204 case CompareIC::UNINITIALIZED: | 169 case CompareIC::UNINITIALIZED: |
205 GenerateMiss(masm); | 170 GenerateMiss(masm); |
206 break; | 171 break; |
207 case CompareIC::SMIS: | 172 case CompareIC::SMIS: |
208 GenerateSmis(masm); | 173 GenerateSmis(masm); |
209 break; | 174 break; |
210 case CompareIC::HEAP_NUMBERS: | 175 case CompareIC::HEAP_NUMBERS: |
211 GenerateHeapNumbers(masm); | 176 GenerateHeapNumbers(masm); |
212 break; | 177 break; |
213 case CompareIC::STRINGS: | 178 case CompareIC::STRINGS: |
214 GenerateStrings(masm); | 179 GenerateStrings(masm); |
215 break; | 180 break; |
216 case CompareIC::SYMBOLS: | 181 case CompareIC::SYMBOLS: |
217 GenerateSymbols(masm); | 182 GenerateSymbols(masm); |
218 break; | 183 break; |
219 case CompareIC::OBJECTS: | 184 case CompareIC::OBJECTS: |
220 GenerateObjects(masm); | 185 GenerateObjects(masm); |
221 break; | 186 break; |
222 case CompareIC::KNOWN_OBJECTS: | |
223 ASSERT(*known_map_ != NULL); | |
224 GenerateKnownObjects(masm); | |
225 break; | |
226 default: | 187 default: |
227 UNREACHABLE(); | 188 UNREACHABLE(); |
228 } | 189 } |
229 } | 190 } |
230 | 191 |
231 | 192 |
232 void InstanceofStub::PrintName(StringStream* stream) { | 193 void InstanceofStub::PrintName(StringStream* stream) { |
233 const char* args = ""; | 194 const char* args = ""; |
234 if (HasArgsInRegisters()) { | 195 if (HasArgsInRegisters()) { |
235 args = "_REGS"; | 196 args = "_REGS"; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm, is_jsarray_); | 401 KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm, is_jsarray_); |
441 } else { | 402 } else { |
442 UNREACHABLE(); | 403 UNREACHABLE(); |
443 } | 404 } |
444 } | 405 } |
445 masm->bind(&fail); | 406 masm->bind(&fail); |
446 KeyedStoreIC::GenerateRuntimeSetProperty(masm, strict_mode_); | 407 KeyedStoreIC::GenerateRuntimeSetProperty(masm, strict_mode_); |
447 } | 408 } |
448 | 409 |
449 } } // namespace v8::internal | 410 } } // namespace v8::internal |
OLD | NEW |