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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 } | 89 } |
90 #endif | 90 #endif |
91 } | 91 } |
92 | 92 |
93 | 93 |
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(bool use_special_cache) { |
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 (!FindCodeInCache(&code)) { | 104 |
105 if (use_special_cache || !FindCodeInCache(&code)) { | |
Kevin Millikin (Chromium)
2011/11/10 19:08:42
I think this is a little clearer if it is somethin
Kevin Millikin (Chromium)
2011/11/10 19:11:18
And then include the compilation code starting wit
Rico
2011/11/11 08:49:11
Done and moved the pregenerated check up here
| |
106 // Using a specialized cache is delegated to code in the specific stub. | |
107 if (use_special_cache && FindCodeInSpecialCache(&code)) { | |
108 return Handle<Code>(code, isolate); | |
109 } | |
110 | |
105 HandleScope scope(isolate); | 111 HandleScope scope(isolate); |
106 | 112 |
107 // Generate the new code. | 113 // Generate the new code. |
108 MacroAssembler masm(isolate, NULL, 256); | 114 MacroAssembler masm(isolate, NULL, 256); |
109 GenerateCode(&masm); | 115 GenerateCode(&masm); |
110 | 116 |
111 // Create the code object. | 117 // Create the code object. |
112 CodeDesc desc; | 118 CodeDesc desc; |
113 masm.GetCode(&desc); | 119 masm.GetCode(&desc); |
114 | 120 |
115 // Copy the generated code into a heap object. | 121 // Copy the generated code into a heap object. |
116 Code::Flags flags = Code::ComputeFlags( | 122 Code::Flags flags = Code::ComputeFlags( |
117 static_cast<Code::Kind>(GetCodeKind()), | 123 static_cast<Code::Kind>(GetCodeKind()), |
118 GetICState()); | 124 GetICState()); |
119 Handle<Code> new_object = factory->NewCode( | 125 Handle<Code> new_object = factory->NewCode( |
120 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | 126 desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
121 RecordCodeGeneration(*new_object, &masm); | 127 RecordCodeGeneration(*new_object, &masm); |
122 FinishCode(*new_object); | 128 FinishCode(*new_object); |
123 | 129 |
124 // Update the dictionary and the root in Heap. | 130 // Update the dictionary and the root in Heap. |
125 Handle<NumberDictionary> dict = | 131 |
126 factory->DictionaryAtNumberPut( | 132 if (use_special_cache) { |
127 Handle<NumberDictionary>(heap->code_stubs()), | 133 CHECK(AddToSpecialCache(new_object)); |
128 GetKey(), | 134 } else { |
129 new_object); | 135 Handle<NumberDictionary> dict = |
130 heap->public_set_code_stubs(*dict); | 136 factory->DictionaryAtNumberPut( |
137 Handle<NumberDictionary>(heap->code_stubs()), | |
138 GetKey(), | |
139 new_object); | |
140 heap->public_set_code_stubs(*dict); | |
141 } | |
142 | |
131 code = *new_object; | 143 code = *new_object; |
132 Activate(code); | 144 Activate(code); |
133 } else { | 145 } else { |
134 CHECK(IsPregenerated() == code->is_pregenerated()); | 146 CHECK(IsPregenerated() == code->is_pregenerated()); |
135 } | 147 } |
136 | 148 |
137 ASSERT(!NeedsImmovableCode() || heap->lo_space()->Contains(code)); | 149 ASSERT(!NeedsImmovableCode() || heap->lo_space()->Contains(code)); |
138 return Handle<Code>(code, isolate); | 150 return Handle<Code>(code, isolate); |
139 } | 151 } |
140 | 152 |
(...skipping 11 matching lines...) Expand all Loading... | |
152 return NULL; | 164 return NULL; |
153 } | 165 } |
154 } | 166 } |
155 | 167 |
156 | 168 |
157 void CodeStub::PrintName(StringStream* stream) { | 169 void CodeStub::PrintName(StringStream* stream) { |
158 stream->Add("%s", MajorName(MajorKey(), false)); | 170 stream->Add("%s", MajorName(MajorKey(), false)); |
159 } | 171 } |
160 | 172 |
161 | 173 |
174 bool ICCompareStub::AddToSpecialCache(Handle<Code> new_object) { | |
175 ASSERT(known_map_ != NULL); | |
176 Isolate* isolate = Isolate::Current(); | |
Kevin Millikin (Chromium)
2011/11/10 19:08:42
If you want to avoid TLS to fetch the isolate, you
Rico
2011/11/11 08:49:11
Done.
| |
177 Factory* factory = isolate->factory(); | |
178 Heap* heap = isolate->heap(); | |
179 Handle<NumberDictionary> dict = | |
180 factory->DictionaryAtNumberPut( | |
181 Handle<NumberDictionary>(heap->compare_stubs_known_objects()), | |
182 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(known_map_)), | |
183 new_object); | |
184 heap->public_set_compare_stubs_known_objects(*dict); | |
185 return true; | |
186 } | |
187 | |
188 | |
189 bool ICCompareStub::FindCodeInSpecialCache(Code** code_out) { | |
190 ASSERT(known_map_ != NULL); | |
191 Heap* heap = Isolate::Current()->heap(); | |
192 int index = heap->compare_stubs_known_objects()->FindEntry( | |
193 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(known_map_))); | |
194 if (index != NumberDictionary::kNotFound) { | |
195 *code_out = Code::cast(heap->compare_stubs_known_objects()->ValueAt(index)); | |
196 UNREACHABLE(); | |
197 return true; | |
198 } | |
199 return false; | |
200 } | |
201 | |
202 | |
162 int ICCompareStub::MinorKey() { | 203 int ICCompareStub::MinorKey() { |
163 return OpField::encode(op_ - Token::EQ) | StateField::encode(state_); | 204 return OpField::encode(op_ - Token::EQ) | StateField::encode(state_); |
164 } | 205 } |
165 | 206 |
166 | 207 |
167 void ICCompareStub::Generate(MacroAssembler* masm) { | 208 void ICCompareStub::Generate(MacroAssembler* masm) { |
168 switch (state_) { | 209 switch (state_) { |
169 case CompareIC::UNINITIALIZED: | 210 case CompareIC::UNINITIALIZED: |
170 GenerateMiss(masm); | 211 GenerateMiss(masm); |
171 break; | 212 break; |
172 case CompareIC::SMIS: | 213 case CompareIC::SMIS: |
173 GenerateSmis(masm); | 214 GenerateSmis(masm); |
174 break; | 215 break; |
175 case CompareIC::HEAP_NUMBERS: | 216 case CompareIC::HEAP_NUMBERS: |
176 GenerateHeapNumbers(masm); | 217 GenerateHeapNumbers(masm); |
177 break; | 218 break; |
178 case CompareIC::STRINGS: | 219 case CompareIC::STRINGS: |
179 GenerateStrings(masm); | 220 GenerateStrings(masm); |
180 break; | 221 break; |
181 case CompareIC::SYMBOLS: | 222 case CompareIC::SYMBOLS: |
182 GenerateSymbols(masm); | 223 GenerateSymbols(masm); |
183 break; | 224 break; |
184 case CompareIC::OBJECTS: | 225 case CompareIC::OBJECTS: |
185 GenerateObjects(masm); | 226 GenerateObjects(masm); |
186 break; | 227 break; |
228 case CompareIC::KNOWN_OBJECTS: | |
229 ASSERT(known_map_ != NULL); | |
230 GenerateKnownObjects(masm, known_map_); | |
231 break; | |
187 default: | 232 default: |
188 UNREACHABLE(); | 233 UNREACHABLE(); |
189 } | 234 } |
190 } | 235 } |
191 | 236 |
192 | 237 |
193 void InstanceofStub::PrintName(StringStream* stream) { | 238 void InstanceofStub::PrintName(StringStream* stream) { |
194 const char* args = ""; | 239 const char* args = ""; |
195 if (HasArgsInRegisters()) { | 240 if (HasArgsInRegisters()) { |
196 args = "_REGS"; | 241 args = "_REGS"; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm, is_jsarray_); | 438 KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm, is_jsarray_); |
394 } else { | 439 } else { |
395 UNREACHABLE(); | 440 UNREACHABLE(); |
396 } | 441 } |
397 } | 442 } |
398 masm->bind(&fail); | 443 masm->bind(&fail); |
399 KeyedStoreIC::GenerateRuntimeSetProperty(masm, strict_mode_); | 444 KeyedStoreIC::GenerateRuntimeSetProperty(masm, strict_mode_); |
400 } | 445 } |
401 | 446 |
402 } } // namespace v8::internal | 447 } } // namespace v8::internal |
OLD | NEW |