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

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

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

Powered by Google App Engine
This is Rietveld 408576698