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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } else if (value->IsString()) { | 53 } else if (value->IsString()) { |
54 info = TypeInfo::String(); | 54 info = TypeInfo::String(); |
55 } else { | 55 } else { |
56 info = TypeInfo::Unknown(); | 56 info = TypeInfo::Unknown(); |
57 } | 57 } |
58 return info; | 58 return info; |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, | 62 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, |
63 Handle<Context> global_context) { | 63 Handle<Context> global_context, |
| 64 Isolate* isolate) { |
64 global_context_ = global_context; | 65 global_context_ = global_context; |
| 66 isolate_ = isolate; |
65 BuildDictionary(code); | 67 BuildDictionary(code); |
66 ASSERT(reinterpret_cast<Address>(*dictionary_.location()) != kHandleZapValue); | 68 ASSERT(reinterpret_cast<Address>(*dictionary_.location()) != kHandleZapValue); |
67 } | 69 } |
68 | 70 |
69 | 71 |
70 Handle<Object> TypeFeedbackOracle::GetInfo(unsigned ast_id) { | 72 Handle<Object> TypeFeedbackOracle::GetInfo(unsigned ast_id) { |
71 int entry = dictionary_->FindEntry(ast_id); | 73 int entry = dictionary_->FindEntry(ast_id); |
72 return entry != NumberDictionary::kNotFound | 74 return entry != NumberDictionary::kNotFound |
73 ? Handle<Object>(dictionary_->ValueAt(entry)) | 75 ? Handle<Object>(dictionary_->ValueAt(entry)) |
74 : Isolate::Current()->factory()->undefined_value(); | 76 : Handle<Object>::cast(isolate_->factory()->undefined_value()); |
75 } | 77 } |
76 | 78 |
77 | 79 |
78 bool TypeFeedbackOracle::LoadIsMonomorphicNormal(Property* expr) { | 80 bool TypeFeedbackOracle::LoadIsMonomorphicNormal(Property* expr) { |
79 Handle<Object> map_or_code = GetInfo(expr->id()); | 81 Handle<Object> map_or_code = GetInfo(expr->id()); |
80 if (map_or_code->IsMap()) return true; | 82 if (map_or_code->IsMap()) return true; |
81 if (map_or_code->IsCode()) { | 83 if (map_or_code->IsCode()) { |
82 Handle<Code> code = Handle<Code>::cast(map_or_code); | 84 Handle<Code> code = Handle<Code>::cast(map_or_code); |
83 return code->is_keyed_load_stub() && | 85 return code->is_keyed_load_stub() && |
84 code->ic_state() == MONOMORPHIC && | 86 code->ic_state() == MONOMORPHIC && |
85 Code::ExtractTypeFromFlags(code->flags()) == NORMAL && | 87 Code::ExtractTypeFromFlags(code->flags()) == NORMAL && |
86 code->FindFirstMap() != NULL; | 88 code->FindFirstMap() != NULL; |
87 } | 89 } |
88 return false; | 90 return false; |
89 } | 91 } |
90 | 92 |
91 | 93 |
92 bool TypeFeedbackOracle::LoadIsMegamorphicWithTypeInfo(Property* expr) { | 94 bool TypeFeedbackOracle::LoadIsMegamorphicWithTypeInfo(Property* expr) { |
93 Handle<Object> map_or_code = GetInfo(expr->id()); | 95 Handle<Object> map_or_code = GetInfo(expr->id()); |
94 if (map_or_code->IsCode()) { | 96 if (map_or_code->IsCode()) { |
95 Handle<Code> code = Handle<Code>::cast(map_or_code); | 97 Handle<Code> code = Handle<Code>::cast(map_or_code); |
96 Builtins* builtins = Isolate::Current()->builtins(); | 98 Builtins* builtins = isolate_->builtins(); |
97 return code->is_keyed_load_stub() && | 99 return code->is_keyed_load_stub() && |
98 *code != builtins->builtin(Builtins::kKeyedLoadIC_Generic) && | 100 *code != builtins->builtin(Builtins::kKeyedLoadIC_Generic) && |
99 code->ic_state() == MEGAMORPHIC; | 101 code->ic_state() == MEGAMORPHIC; |
100 } | 102 } |
101 return false; | 103 return false; |
102 } | 104 } |
103 | 105 |
104 | 106 |
105 bool TypeFeedbackOracle::StoreIsMonomorphicNormal(Expression* expr) { | 107 bool TypeFeedbackOracle::StoreIsMonomorphicNormal(Expression* expr) { |
106 Handle<Object> map_or_code = GetInfo(expr->id()); | 108 Handle<Object> map_or_code = GetInfo(expr->id()); |
107 if (map_or_code->IsMap()) return true; | 109 if (map_or_code->IsMap()) return true; |
108 if (map_or_code->IsCode()) { | 110 if (map_or_code->IsCode()) { |
109 Handle<Code> code = Handle<Code>::cast(map_or_code); | 111 Handle<Code> code = Handle<Code>::cast(map_or_code); |
110 return code->is_keyed_store_stub() && | 112 return code->is_keyed_store_stub() && |
111 code->ic_state() == MONOMORPHIC && | 113 code->ic_state() == MONOMORPHIC && |
112 Code::ExtractTypeFromFlags(code->flags()) == NORMAL; | 114 Code::ExtractTypeFromFlags(code->flags()) == NORMAL; |
113 } | 115 } |
114 return false; | 116 return false; |
115 } | 117 } |
116 | 118 |
117 | 119 |
118 bool TypeFeedbackOracle::StoreIsMegamorphicWithTypeInfo(Expression* expr) { | 120 bool TypeFeedbackOracle::StoreIsMegamorphicWithTypeInfo(Expression* expr) { |
119 Handle<Object> map_or_code = GetInfo(expr->id()); | 121 Handle<Object> map_or_code = GetInfo(expr->id()); |
120 if (map_or_code->IsCode()) { | 122 if (map_or_code->IsCode()) { |
121 Handle<Code> code = Handle<Code>::cast(map_or_code); | 123 Handle<Code> code = Handle<Code>::cast(map_or_code); |
122 Builtins* builtins = Isolate::Current()->builtins(); | 124 Builtins* builtins = isolate_->builtins(); |
123 return code->is_keyed_store_stub() && | 125 return code->is_keyed_store_stub() && |
124 *code != builtins->builtin(Builtins::kKeyedStoreIC_Generic) && | 126 *code != builtins->builtin(Builtins::kKeyedStoreIC_Generic) && |
125 *code != builtins->builtin(Builtins::kKeyedStoreIC_Generic_Strict) && | 127 *code != builtins->builtin(Builtins::kKeyedStoreIC_Generic_Strict) && |
126 code->ic_state() == MEGAMORPHIC; | 128 code->ic_state() == MEGAMORPHIC; |
127 } | 129 } |
128 return false; | 130 return false; |
129 } | 131 } |
130 | 132 |
131 | 133 |
132 bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { | 134 bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 228 } |
227 | 229 |
228 | 230 |
229 Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(Call* expr) { | 231 Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(Call* expr) { |
230 return Handle<JSFunction>::cast(GetInfo(expr->id())); | 232 return Handle<JSFunction>::cast(GetInfo(expr->id())); |
231 } | 233 } |
232 | 234 |
233 | 235 |
234 bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { | 236 bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { |
235 return *GetInfo(expr->id()) == | 237 return *GetInfo(expr->id()) == |
236 Isolate::Current()->builtins()->builtin(id); | 238 isolate_->builtins()->builtin(id); |
237 } | 239 } |
238 | 240 |
239 | 241 |
240 TypeInfo TypeFeedbackOracle::CompareType(CompareOperation* expr) { | 242 TypeInfo TypeFeedbackOracle::CompareType(CompareOperation* expr) { |
241 Handle<Object> object = GetInfo(expr->id()); | 243 Handle<Object> object = GetInfo(expr->id()); |
242 TypeInfo unknown = TypeInfo::Unknown(); | 244 TypeInfo unknown = TypeInfo::Unknown(); |
243 if (!object->IsCode()) return unknown; | 245 if (!object->IsCode()) return unknown; |
244 Handle<Code> code = Handle<Code>::cast(object); | 246 Handle<Code> code = Handle<Code>::cast(object); |
245 if (!code->is_compare_ic_stub()) return unknown; | 247 if (!code->is_compare_ic_stub()) return unknown; |
246 | 248 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 398 } |
397 UNREACHABLE(); | 399 UNREACHABLE(); |
398 return unknown; | 400 return unknown; |
399 } | 401 } |
400 | 402 |
401 | 403 |
402 void TypeFeedbackOracle::CollectReceiverTypes(unsigned ast_id, | 404 void TypeFeedbackOracle::CollectReceiverTypes(unsigned ast_id, |
403 Handle<String> name, | 405 Handle<String> name, |
404 Code::Flags flags, | 406 Code::Flags flags, |
405 SmallMapList* types) { | 407 SmallMapList* types) { |
406 Isolate* isolate = Isolate::Current(); | |
407 Handle<Object> object = GetInfo(ast_id); | 408 Handle<Object> object = GetInfo(ast_id); |
408 if (object->IsUndefined() || object->IsSmi()) return; | 409 if (object->IsUndefined() || object->IsSmi()) return; |
409 | 410 |
410 if (*object == isolate->builtins()->builtin(Builtins::kStoreIC_GlobalProxy)) { | 411 if (*object == isolate_->builtins()->builtin(Builtins::kStoreIC_GlobalProxy))
{ |
411 // TODO(fschneider): We could collect the maps and signal that | 412 // TODO(fschneider): We could collect the maps and signal that |
412 // we need a generic store (or load) here. | 413 // we need a generic store (or load) here. |
413 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC); | 414 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC); |
414 } else if (object->IsMap()) { | 415 } else if (object->IsMap()) { |
415 types->Add(Handle<Map>::cast(object)); | 416 types->Add(Handle<Map>::cast(object)); |
416 } else if (Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) { | 417 } else if (Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) { |
417 types->Reserve(4); | 418 types->Reserve(4); |
418 ASSERT(object->IsCode()); | 419 ASSERT(object->IsCode()); |
419 isolate->stub_cache()->CollectMatchingMaps(types, *name, flags); | 420 isolate_->stub_cache()->CollectMatchingMaps(types, *name, flags); |
420 } | 421 } |
421 } | 422 } |
422 | 423 |
423 | 424 |
424 void TypeFeedbackOracle::CollectKeyedReceiverTypes(unsigned ast_id, | 425 void TypeFeedbackOracle::CollectKeyedReceiverTypes(unsigned ast_id, |
425 SmallMapList* types) { | 426 SmallMapList* types) { |
426 Handle<Object> object = GetInfo(ast_id); | 427 Handle<Object> object = GetInfo(ast_id); |
427 if (!object->IsCode()) return; | 428 if (!object->IsCode()) return; |
428 Handle<Code> code = Handle<Code>::cast(object); | 429 Handle<Code> code = Handle<Code>::cast(object); |
429 if (code->kind() == Code::KEYED_LOAD_IC || | 430 if (code->kind() == Code::KEYED_LOAD_IC || |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 USE(maybe_result); | 560 USE(maybe_result); |
560 #ifdef DEBUG | 561 #ifdef DEBUG |
561 Object* result = NULL; | 562 Object* result = NULL; |
562 // Dictionary has been allocated with sufficient size for all elements. | 563 // Dictionary has been allocated with sufficient size for all elements. |
563 ASSERT(maybe_result->ToObject(&result)); | 564 ASSERT(maybe_result->ToObject(&result)); |
564 ASSERT(*dictionary_ == result); | 565 ASSERT(*dictionary_ == result); |
565 #endif | 566 #endif |
566 } | 567 } |
567 | 568 |
568 } } // namespace v8::internal | 569 } } // namespace v8::internal |
OLD | NEW |