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 (!FindCodeInCache(&code)) { | 104 if (UseSpecialCache() |
105 ? FindCodeInSpecialCache(&code) | |
106 : FindCodeInCache(&code)) { | |
107 CHECK(IsPregenerated() == code->is_pregenerated()); | |
Kevin Millikin (Chromium)
2011/11/11 10:12:34
Maybe I'm missing a good reason for this, but plea
Rico
2011/11/15 10:12:26
Done (checked with Erik that we can actally make t
| |
108 return Handle<Code>(code); | |
109 } | |
110 | |
111 { | |
105 HandleScope scope(isolate); | 112 HandleScope scope(isolate); |
106 | 113 |
107 // Generate the new code. | 114 // Generate the new code. |
108 MacroAssembler masm(isolate, NULL, 256); | 115 MacroAssembler masm(isolate, NULL, 256); |
109 GenerateCode(&masm); | 116 GenerateCode(&masm); |
110 | 117 |
111 // Create the code object. | 118 // Create the code object. |
112 CodeDesc desc; | 119 CodeDesc desc; |
113 masm.GetCode(&desc); | 120 masm.GetCode(&desc); |
114 | 121 |
115 // Copy the generated code into a heap object. | 122 // Copy the generated code into a heap object. |
116 Code::Flags flags = Code::ComputeFlags( | 123 Code::Flags flags = Code::ComputeFlags( |
117 static_cast<Code::Kind>(GetCodeKind()), | 124 static_cast<Code::Kind>(GetCodeKind()), |
118 GetICState()); | 125 GetICState()); |
119 Handle<Code> new_object = factory->NewCode( | 126 Handle<Code> new_object = factory->NewCode( |
120 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | 127 desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
121 RecordCodeGeneration(*new_object, &masm); | 128 RecordCodeGeneration(*new_object, &masm); |
122 FinishCode(*new_object); | 129 FinishCode(*new_object); |
123 | 130 |
124 // Update the dictionary and the root in Heap. | 131 // Update the dictionary and the root in Heap. |
125 Handle<NumberDictionary> dict = | 132 |
126 factory->DictionaryAtNumberPut( | 133 if (UseSpecialCache()) { |
127 Handle<NumberDictionary>(heap->code_stubs()), | 134 CHECK(AddToSpecialCache(new_object)); |
Kevin Millikin (Chromium)
2011/11/11 10:12:34
This function can only return true, so get rid of
Rico
2011/11/15 10:12:26
Done.
| |
128 GetKey(), | 135 } else { |
129 new_object); | 136 Handle<NumberDictionary> dict = |
130 heap->public_set_code_stubs(*dict); | 137 factory->DictionaryAtNumberPut( |
138 Handle<NumberDictionary>(heap->code_stubs()), | |
139 GetKey(), | |
140 new_object); | |
141 heap->public_set_code_stubs(*dict); | |
142 } | |
131 code = *new_object; | 143 code = *new_object; |
132 Activate(code); | |
133 } else { | |
134 CHECK(IsPregenerated() == code->is_pregenerated()); | |
135 } | 144 } |
136 | 145 |
146 Activate(code); | |
137 ASSERT(!NeedsImmovableCode() || heap->lo_space()->Contains(code)); | 147 ASSERT(!NeedsImmovableCode() || heap->lo_space()->Contains(code)); |
138 return Handle<Code>(code, isolate); | 148 return Handle<Code>(code, isolate); |
139 } | 149 } |
140 | 150 |
141 | 151 |
142 const char* CodeStub::MajorName(CodeStub::Major major_key, | 152 const char* CodeStub::MajorName(CodeStub::Major major_key, |
143 bool allow_unknown_keys) { | 153 bool allow_unknown_keys) { |
144 switch (major_key) { | 154 switch (major_key) { |
145 #define DEF_CASE(name) case name: return #name "Stub"; | 155 #define DEF_CASE(name) case name: return #name "Stub"; |
146 CODE_STUB_LIST(DEF_CASE) | 156 CODE_STUB_LIST(DEF_CASE) |
147 #undef DEF_CASE | 157 #undef DEF_CASE |
148 default: | 158 default: |
149 if (!allow_unknown_keys) { | 159 if (!allow_unknown_keys) { |
150 UNREACHABLE(); | 160 UNREACHABLE(); |
151 } | 161 } |
152 return NULL; | 162 return NULL; |
153 } | 163 } |
154 } | 164 } |
155 | 165 |
156 | 166 |
157 void CodeStub::PrintName(StringStream* stream) { | 167 void CodeStub::PrintName(StringStream* stream) { |
158 stream->Add("%s", MajorName(MajorKey(), false)); | 168 stream->Add("%s", MajorName(MajorKey(), false)); |
159 } | 169 } |
160 | 170 |
161 | 171 |
172 bool ICCompareStub::AddToSpecialCache(Handle<Code> new_object) { | |
173 ASSERT(known_map_ != NULL); | |
174 Isolate* isolate = new_object->GetIsolate(); | |
Kevin Millikin (Chromium)
2011/11/11 10:12:34
I still don't fully understand why we need a separ
Rico
2011/11/15 10:12:26
I discussed with Erik and found a solution for usi
| |
175 Factory* factory = isolate->factory(); | |
176 Heap* heap = isolate->heap(); | |
177 Handle<NumberDictionary> dict = | |
178 factory->DictionaryAtNumberPut( | |
179 Handle<NumberDictionary>(heap->compare_stubs_known_objects()), | |
180 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(*known_map_)), | |
181 new_object); | |
182 heap->public_set_compare_stubs_known_objects(*dict); | |
183 return true; | |
184 } | |
185 | |
186 | |
187 bool ICCompareStub::FindCodeInSpecialCache(Code** code_out) { | |
188 ASSERT(known_map_ != NULL); | |
189 Heap* heap = Isolate::Current()->heap(); | |
190 int index = heap->compare_stubs_known_objects()->FindEntry( | |
191 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(*known_map_))); | |
192 if (index != NumberDictionary::kNotFound) { | |
193 *code_out = Code::cast(heap->compare_stubs_known_objects()->ValueAt(index)); | |
194 UNREACHABLE(); | |
Kevin Millikin (Chromium)
2011/11/11 10:12:34
Huh?
Rico
2011/11/15 10:12:26
Done.
| |
195 return true; | |
196 } | |
197 return false; | |
198 } | |
199 | |
200 | |
162 int ICCompareStub::MinorKey() { | 201 int ICCompareStub::MinorKey() { |
163 return OpField::encode(op_ - Token::EQ) | StateField::encode(state_); | 202 return OpField::encode(op_ - Token::EQ) | StateField::encode(state_); |
164 } | 203 } |
165 | 204 |
166 | 205 |
167 void ICCompareStub::Generate(MacroAssembler* masm) { | 206 void ICCompareStub::Generate(MacroAssembler* masm) { |
168 switch (state_) { | 207 switch (state_) { |
169 case CompareIC::UNINITIALIZED: | 208 case CompareIC::UNINITIALIZED: |
170 GenerateMiss(masm); | 209 GenerateMiss(masm); |
171 break; | 210 break; |
172 case CompareIC::SMIS: | 211 case CompareIC::SMIS: |
173 GenerateSmis(masm); | 212 GenerateSmis(masm); |
174 break; | 213 break; |
175 case CompareIC::HEAP_NUMBERS: | 214 case CompareIC::HEAP_NUMBERS: |
176 GenerateHeapNumbers(masm); | 215 GenerateHeapNumbers(masm); |
177 break; | 216 break; |
178 case CompareIC::STRINGS: | 217 case CompareIC::STRINGS: |
179 GenerateStrings(masm); | 218 GenerateStrings(masm); |
180 break; | 219 break; |
181 case CompareIC::SYMBOLS: | 220 case CompareIC::SYMBOLS: |
182 GenerateSymbols(masm); | 221 GenerateSymbols(masm); |
183 break; | 222 break; |
184 case CompareIC::OBJECTS: | 223 case CompareIC::OBJECTS: |
185 GenerateObjects(masm); | 224 GenerateObjects(masm); |
186 break; | 225 break; |
226 case CompareIC::KNOWN_OBJECTS: | |
227 ASSERT(known_map_ != NULL); | |
228 GenerateKnownObjects(masm, known_map_); | |
Kevin Millikin (Chromium)
2011/11/11 10:12:34
No real need to pass known_map_ here.
Rico
2011/11/15 10:12:26
Done.
| |
229 break; | |
187 default: | 230 default: |
188 UNREACHABLE(); | 231 UNREACHABLE(); |
189 } | 232 } |
190 } | 233 } |
191 | 234 |
192 | 235 |
193 void InstanceofStub::PrintName(StringStream* stream) { | 236 void InstanceofStub::PrintName(StringStream* stream) { |
194 const char* args = ""; | 237 const char* args = ""; |
195 if (HasArgsInRegisters()) { | 238 if (HasArgsInRegisters()) { |
196 args = "_REGS"; | 239 args = "_REGS"; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm, is_jsarray_); | 436 KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm, is_jsarray_); |
394 } else { | 437 } else { |
395 UNREACHABLE(); | 438 UNREACHABLE(); |
396 } | 439 } |
397 } | 440 } |
398 masm->bind(&fail); | 441 masm->bind(&fail); |
399 KeyedStoreIC::GenerateRuntimeSetProperty(masm, strict_mode_); | 442 KeyedStoreIC::GenerateRuntimeSetProperty(masm, strict_mode_); |
400 } | 443 } |
401 | 444 |
402 } } // namespace v8::internal | 445 } } // namespace v8::internal |
OLD | NEW |