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

Side by Side Diff: src/type-info.cc

Issue 6263001: Expose receiver check type in call type feedback. (Closed)
Patch Set: Created 9 years, 11 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
« no previous file with comments | « src/type-info.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 : TypeInfo::Double(); 51 : TypeInfo::Double();
52 } else if (value->IsString()) { 52 } else if (value->IsString()) {
53 info = TypeInfo::String(); 53 info = TypeInfo::String();
54 } else { 54 } else {
55 info = TypeInfo::Unknown(); 55 info = TypeInfo::Unknown();
56 } 56 }
57 return info; 57 return info;
58 } 58 }
59 59
60 60
61 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code) { 61 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code,
62 Handle<Context> global_context) {
63 global_context_ = global_context;
62 Initialize(code); 64 Initialize(code);
63 } 65 }
64 66
65 67
66 void TypeFeedbackOracle::Initialize(Handle<Code> code) { 68 void TypeFeedbackOracle::Initialize(Handle<Code> code) {
67 ASSERT(map_.is_null()); // Only initialize once. 69 ASSERT(map_.is_null()); // Only initialize once.
68 map_ = Factory::NewJSObject(Top::object_function()); 70 map_ = Factory::NewJSObject(Top::object_function());
69 PopulateMap(code); 71 PopulateMap(code);
70 } 72 }
71 73
72 74
73 bool TypeFeedbackOracle::LoadIsMonomorphic(Property* expr) { 75 bool TypeFeedbackOracle::LoadIsMonomorphic(Property* expr) {
74 return IsMonomorphic(expr->position()); 76 return IsMonomorphic(expr->position());
75 } 77 }
76 78
77 79
78 bool TypeFeedbackOracle:: StoreIsMonomorphic(Assignment* expr) { 80 bool TypeFeedbackOracle:: StoreIsMonomorphic(Assignment* expr) {
79 return IsMonomorphic(expr->position()); 81 return IsMonomorphic(expr->position());
fschneider 2011/01/13 13:44:50 It seems that the private helper IsMonomorphic is
Vitaly Repeshko 2011/01/13 14:16:54 Done.
80 } 82 }
81 83
82 84
83 bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { 85 bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) {
84 return IsMonomorphic(expr->position()); 86 Handle<Object> value = GetElement(map_, expr->position());
87 return value->IsMap() || value->IsSmi();
85 } 88 }
86 89
87 90
88 Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) { 91 Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) {
89 ASSERT(LoadIsMonomorphic(expr)); 92 ASSERT(LoadIsMonomorphic(expr));
90 return Handle<Map>::cast(GetElement(map_, expr->position())); 93 return Handle<Map>::cast(GetElement(map_, expr->position()));
91 } 94 }
92 95
93 96
94 Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType(Assignment* expr) { 97 Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType(Assignment* expr) {
95 ASSERT(StoreIsMonomorphic(expr)); 98 ASSERT(StoreIsMonomorphic(expr));
96 return Handle<Map>::cast(GetElement(map_, expr->position())); 99 return Handle<Map>::cast(GetElement(map_, expr->position()));
97 } 100 }
98 101
99 102
100 Handle<Map> TypeFeedbackOracle::CallMonomorphicReceiverType(Call* expr) {
101 ASSERT(CallIsMonomorphic(expr));
102 return Handle<Map>::cast(GetElement(map_, expr->position()));
103 }
104
105
106 ZoneMapList* TypeFeedbackOracle::LoadReceiverTypes(Property* expr, 103 ZoneMapList* TypeFeedbackOracle::LoadReceiverTypes(Property* expr,
107 Handle<String> name) { 104 Handle<String> name) {
108 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, NORMAL); 105 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, NORMAL);
109 return CollectReceiverTypes(expr->position(), name, flags); 106 return CollectReceiverTypes(expr->position(), name, flags);
110 } 107 }
111 108
112 109
113 ZoneMapList* TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr, 110 ZoneMapList* TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr,
114 Handle<String> name) { 111 Handle<String> name) {
115 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, NORMAL); 112 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, NORMAL);
116 return CollectReceiverTypes(expr->position(), name, flags); 113 return CollectReceiverTypes(expr->position(), name, flags);
117 } 114 }
118 115
119 116
120 ZoneMapList* TypeFeedbackOracle::CallReceiverTypes(Call* expr, 117 ZoneMapList* TypeFeedbackOracle::CallReceiverTypes(Call* expr,
121 Handle<String> name) { 118 Handle<String> name) {
122 int arity = expr->arguments()->length(); 119 int arity = expr->arguments()->length();
123 Code::Flags flags = Code::ComputeMonomorphicFlags( 120 Code::Flags flags = Code::ComputeMonomorphicFlags(
124 Code::CALL_IC, NORMAL, OWN_MAP, NOT_IN_LOOP, arity); 121 Code::CALL_IC, NORMAL, OWN_MAP, NOT_IN_LOOP, arity);
125 return CollectReceiverTypes(expr->position(), name, flags); 122 return CollectReceiverTypes(expr->position(), name, flags);
126 } 123 }
127 124
128 125
126 CheckType TypeFeedbackOracle::GetCallCheckType(Call* expr) {
127 Handle<Object> value = GetElement(map_, expr->position());
128 if (!value->IsSmi()) return RECEIVER_MAP_CHECK;
129 CheckType check = static_cast<CheckType>(Smi::cast(*value)->value());
130 ASSERT(check != RECEIVER_MAP_CHECK);
131 return check;
132 }
133
134
135 Handle<JSObject> TypeFeedbackOracle::GetPrototypeForPrimitiveCheck(
136 CheckType check) {
137 JSFunction* function = NULL;
138 switch (check) {
139 case RECEIVER_MAP_CHECK:
140 UNREACHABLE();
141 break;
142 case STRING_CHECK:
143 function = global_context_->string_function();
144 break;
145 case NUMBER_CHECK:
146 function = global_context_->number_function();
147 break;
148 case BOOLEAN_CHECK:
149 function = global_context_->boolean_function();
150 break;
151 }
152 ASSERT(function != NULL);
153 return Handle<JSObject>(JSObject::cast(function->instance_prototype()));
154 }
155
156
129 bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { 157 bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) {
130 Handle<Object> object = GetElement(map_, expr->position()); 158 Handle<Object> object = GetElement(map_, expr->position());
131 return *object == Builtins::builtin(id); 159 return *object == Builtins::builtin(id);
132 } 160 }
133 161
134 162
135 TypeInfo TypeFeedbackOracle::CompareType(CompareOperation* expr, Side side) { 163 TypeInfo TypeFeedbackOracle::CompareType(CompareOperation* expr, Side side) {
136 Handle<Object> object = GetElement(map_, expr->position()); 164 Handle<Object> object = GetElement(map_, expr->position());
137 TypeInfo unknown = TypeInfo::Unknown(); 165 TypeInfo unknown = TypeInfo::Unknown();
138 if (!object->IsCode()) return unknown; 166 if (!object->IsCode()) return unknown;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 case TRBinaryOpIC::STRING: 241 case TRBinaryOpIC::STRING:
214 case TRBinaryOpIC::GENERIC: 242 case TRBinaryOpIC::GENERIC:
215 return unknown; 243 return unknown;
216 default: 244 default:
217 return unknown; 245 return unknown;
218 } 246 }
219 } 247 }
220 return unknown; 248 return unknown;
221 } 249 }
222 250
251
223 TypeInfo TypeFeedbackOracle::SwitchType(CaseClause* clause) { 252 TypeInfo TypeFeedbackOracle::SwitchType(CaseClause* clause) {
224 Handle<Object> object = GetElement(map_, clause->position()); 253 Handle<Object> object = GetElement(map_, clause->position());
225 TypeInfo unknown = TypeInfo::Unknown(); 254 TypeInfo unknown = TypeInfo::Unknown();
226 if (!object->IsCode()) return unknown; 255 if (!object->IsCode()) return unknown;
227 Handle<Code> code = Handle<Code>::cast(object); 256 Handle<Code> code = Handle<Code>::cast(object);
228 if (!code->is_compare_ic_stub()) return unknown; 257 if (!code->is_compare_ic_stub()) return unknown;
229 258
230 CompareIC::State state = static_cast<CompareIC::State>(code->compare_state()); 259 CompareIC::State state = static_cast<CompareIC::State>(code->compare_state());
231 switch (state) { 260 switch (state) {
232 case CompareIC::UNINITIALIZED: 261 case CompareIC::UNINITIALIZED:
233 // Uninitialized means never executed. 262 // Uninitialized means never executed.
234 // TODO(fschneider): Introduce a separate value for never-executed ICs. 263 // TODO(fschneider): Introduce a separate value for never-executed ICs.
235 return unknown; 264 return unknown;
236 case CompareIC::SMIS: 265 case CompareIC::SMIS:
237 return TypeInfo::Smi(); 266 return TypeInfo::Smi();
238 case CompareIC::HEAP_NUMBERS: 267 case CompareIC::HEAP_NUMBERS:
239 return TypeInfo::Number(); 268 return TypeInfo::Number();
240 case CompareIC::OBJECTS: 269 case CompareIC::OBJECTS:
241 // TODO(kasperl): We really need a type for JS objects here. 270 // TODO(kasperl): We really need a type for JS objects here.
242 return TypeInfo::NonPrimitive(); 271 return TypeInfo::NonPrimitive();
243 case CompareIC::GENERIC: 272 case CompareIC::GENERIC:
244 default: 273 default:
245 return unknown; 274 return unknown;
246 } 275 }
247 } 276 }
248 277
249 278
250
251 ZoneMapList* TypeFeedbackOracle::CollectReceiverTypes(int position, 279 ZoneMapList* TypeFeedbackOracle::CollectReceiverTypes(int position,
252 Handle<String> name, 280 Handle<String> name,
253 Code::Flags flags) { 281 Code::Flags flags) {
254 Handle<Object> object = GetElement(map_, position); 282 Handle<Object> object = GetElement(map_, position);
255 if (object->IsUndefined()) return NULL; 283 if (object->IsUndefined() || object->IsSmi()) return NULL;
256 284
257 if (*object == Builtins::builtin(Builtins::StoreIC_GlobalProxy)) { 285 if (*object == Builtins::builtin(Builtins::StoreIC_GlobalProxy)) {
258 // TODO(fschneider): We could collect the maps and signal that 286 // TODO(fschneider): We could collect the maps and signal that
259 // we need a generic store (or load) here. 287 // we need a generic store (or load) here.
260 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC); 288 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC);
261 return NULL; 289 return NULL;
262 } else if (object->IsMap()) { 290 } else if (object->IsMap()) {
263 ZoneMapList* types = new ZoneMapList(1); 291 ZoneMapList* types = new ZoneMapList(1);
264 types->Add(Handle<Map>::cast(object)); 292 types->Add(Handle<Map>::cast(object));
265 return types; 293 return types;
(...skipping 28 matching lines...) Expand all
294 if (kind == Code::BINARY_OP_IC || 322 if (kind == Code::BINARY_OP_IC ||
295 kind == Code::TYPE_RECORDING_BINARY_OP_IC || 323 kind == Code::TYPE_RECORDING_BINARY_OP_IC ||
296 kind == Code::COMPARE_IC) { 324 kind == Code::COMPARE_IC) {
297 // TODO(kasperl): Avoid having multiple ICs with the same 325 // TODO(kasperl): Avoid having multiple ICs with the same
298 // position by making sure that we have position information 326 // position by making sure that we have position information
299 // recorded for all binary ICs. 327 // recorded for all binary ICs.
300 if (GetElement(map_, position)->IsUndefined()) { 328 if (GetElement(map_, position)->IsUndefined()) {
301 SetElement(map_, position, target); 329 SetElement(map_, position, target);
302 } 330 }
303 } else if (state == MONOMORPHIC) { 331 } else if (state == MONOMORPHIC) {
304 Handle<Map> map = Handle<Map>(target->FindFirstMap()); 332 if (target->kind() != Code::CALL_IC ||
305 if (*map == NULL) { 333 target->check_type() == RECEIVER_MAP_CHECK) {
306 SetElement(map_, position, target); 334 Handle<Map> map = Handle<Map>(target->FindFirstMap());
335 if (*map == NULL) {
336 SetElement(map_, position, target);
337 } else {
338 SetElement(map_, position, map);
339 }
307 } else { 340 } else {
308 SetElement(map_, position, map); 341 ASSERT(target->kind() == Code::CALL_IC);
342 CheckType check = target->check_type();
343 ASSERT(check != RECEIVER_MAP_CHECK);
344 SetElement(map_, position, Handle<Object>(Smi::FromInt(check)));
345 ASSERT(Smi::cast(*GetElement(map_, position))->value() == check);
309 } 346 }
310 } else if (state == MEGAMORPHIC) { 347 } else if (state == MEGAMORPHIC) {
311 SetElement(map_, position, target); 348 SetElement(map_, position, target);
312 } 349 }
313 } 350 }
314 } 351 }
315 352
316 353
317 void TypeFeedbackOracle::CollectPositions(Code* code, 354 void TypeFeedbackOracle::CollectPositions(Code* code,
318 List<int>* code_positions, 355 List<int>* code_positions,
(...skipping 16 matching lines...) Expand all
335 if (kind == Code::BINARY_OP_IC) { 372 if (kind == Code::BINARY_OP_IC) {
336 if (target->binary_op_type() == BinaryOpIC::GENERIC) continue; 373 if (target->binary_op_type() == BinaryOpIC::GENERIC) continue;
337 } else if (kind == Code::TYPE_RECORDING_BINARY_OP_IC) { 374 } else if (kind == Code::TYPE_RECORDING_BINARY_OP_IC) {
338 if (target->type_recording_binary_op_type() == 375 if (target->type_recording_binary_op_type() ==
339 TRBinaryOpIC::GENERIC) { 376 TRBinaryOpIC::GENERIC) {
340 continue; 377 continue;
341 } 378 }
342 } else if (kind == Code::COMPARE_IC) { 379 } else if (kind == Code::COMPARE_IC) {
343 if (target->compare_state() == CompareIC::GENERIC) continue; 380 if (target->compare_state() == CompareIC::GENERIC) continue;
344 } else { 381 } else {
345 if (kind == Code::CALL_IC && state == MONOMORPHIC &&
346 target->check_type() != RECEIVER_MAP_CHECK) continue;
347 if (state != MONOMORPHIC && state != MEGAMORPHIC) continue; 382 if (state != MONOMORPHIC && state != MEGAMORPHIC) continue;
348 } 383 }
349 code_positions->Add( 384 code_positions->Add(
350 static_cast<int>(info->pc() - code->instruction_start())); 385 static_cast<int>(info->pc() - code->instruction_start()));
351 source_positions->Add(position); 386 source_positions->Add(position);
352 } 387 }
353 } else { 388 } else {
354 ASSERT(RelocInfo::IsPosition(mode)); 389 ASSERT(RelocInfo::IsPosition(mode));
355 position = static_cast<int>(info->data()); 390 position = static_cast<int>(info->data());
356 } 391 }
357 } 392 }
358 } 393 }
359 394
360 } } // namespace v8::internal 395 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/type-info.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698