| OLD | NEW |
| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 ZoneMapList* types = new ZoneMapList(4); | 348 ZoneMapList* types = new ZoneMapList(4); |
| 349 ASSERT(object->IsCode()); | 349 ASSERT(object->IsCode()); |
| 350 isolate->stub_cache()->CollectMatchingMaps(types, *name, flags); | 350 isolate->stub_cache()->CollectMatchingMaps(types, *name, flags); |
| 351 return types->length() > 0 ? types : NULL; | 351 return types->length() > 0 ? types : NULL; |
| 352 } else { | 352 } else { |
| 353 return NULL; | 353 return NULL; |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 | 357 |
| 358 void TypeFeedbackOracle::SetInfo(int position, Object* target) { | |
| 359 MaybeObject* maybe_result = dictionary_->AtNumberPut(position, target); | |
| 360 USE(maybe_result); | |
| 361 #ifdef DEBUG | |
| 362 Object* result; | |
| 363 // Dictionary has been allocated with sufficient size for all elements. | |
| 364 ASSERT(maybe_result->ToObject(&result)); | |
| 365 ASSERT(*dictionary_ == result); | |
| 366 #endif | |
| 367 } | |
| 368 | |
| 369 | |
| 370 void TypeFeedbackOracle::PopulateMap(Handle<Code> code) { | 358 void TypeFeedbackOracle::PopulateMap(Handle<Code> code) { |
| 371 Isolate* isolate = Isolate::Current(); | 359 Isolate* isolate = Isolate::Current(); |
| 372 HandleScope scope(isolate); | 360 HandleScope scope(isolate); |
| 373 | 361 |
| 374 const int kInitialCapacity = 16; | 362 const int kInitialCapacity = 16; |
| 375 List<int> code_positions(kInitialCapacity); | 363 List<int> code_positions(kInitialCapacity); |
| 376 List<int> source_positions(kInitialCapacity); | 364 List<int> source_positions(kInitialCapacity); |
| 377 CollectPositions(*code, &code_positions, &source_positions); | 365 CollectPositions(*code, &code_positions, &source_positions); |
| 378 | 366 |
| 379 ASSERT(dictionary_.is_null()); // Only initialize once. | 367 ASSERT(dictionary_.is_null()); // Only initialize once. |
| 380 dictionary_ = isolate->factory()->NewNumberDictionary( | 368 dictionary_ = isolate->factory()->NewNumberDictionary( |
| 381 code_positions.length()); | 369 code_positions.length()); |
| 382 | 370 |
| 383 int length = code_positions.length(); | 371 int length = code_positions.length(); |
| 384 ASSERT(source_positions.length() == length); | 372 ASSERT(source_positions.length() == length); |
| 385 for (int i = 0; i < length; i++) { | 373 for (int i = 0; i < length; i++) { |
| 386 AssertNoAllocation no_allocation; | 374 HandleScope loop_scope(isolate); |
| 387 RelocInfo info(code->instruction_start() + code_positions[i], | 375 RelocInfo info(code->instruction_start() + code_positions[i], |
| 388 RelocInfo::CODE_TARGET, 0); | 376 RelocInfo::CODE_TARGET, 0); |
| 389 Code* target = Code::GetCodeFromTargetAddress(info.target_address()); | 377 Handle<Code> target(Code::GetCodeFromTargetAddress(info.target_address())); |
| 390 int position = source_positions[i]; | 378 int position = source_positions[i]; |
| 391 InlineCacheState state = target->ic_state(); | 379 InlineCacheState state = target->ic_state(); |
| 392 Code::Kind kind = target->kind(); | 380 Code::Kind kind = target->kind(); |
| 393 | 381 Handle<Object> value; |
| 394 if (kind == Code::BINARY_OP_IC || | 382 if (kind == Code::BINARY_OP_IC || |
| 395 kind == Code::TYPE_RECORDING_BINARY_OP_IC || | 383 kind == Code::TYPE_RECORDING_BINARY_OP_IC || |
| 396 kind == Code::COMPARE_IC) { | 384 kind == Code::COMPARE_IC) { |
| 397 // TODO(kasperl): Avoid having multiple ICs with the same | 385 // TODO(kasperl): Avoid having multiple ICs with the same |
| 398 // position by making sure that we have position information | 386 // position by making sure that we have position information |
| 399 // recorded for all binary ICs. | 387 // recorded for all binary ICs. |
| 400 int entry = dictionary_->FindEntry(position); | 388 int entry = dictionary_->FindEntry(position); |
| 401 if (entry == NumberDictionary::kNotFound) { | 389 if (entry == NumberDictionary::kNotFound) { |
| 402 SetInfo(position, target); | 390 value = target; |
| 403 } | 391 } |
| 404 } else if (state == MONOMORPHIC) { | 392 } else if (state == MONOMORPHIC) { |
| 405 if (kind == Code::KEYED_EXTERNAL_ARRAY_LOAD_IC || | 393 if (kind == Code::KEYED_EXTERNAL_ARRAY_LOAD_IC || |
| 406 kind == Code::KEYED_EXTERNAL_ARRAY_STORE_IC) { | 394 kind == Code::KEYED_EXTERNAL_ARRAY_STORE_IC) { |
| 407 SetInfo(position, target); | 395 value = target; |
| 408 } else if (target->kind() != Code::CALL_IC || | 396 } else if (target->kind() != Code::CALL_IC || |
| 409 target->check_type() == RECEIVER_MAP_CHECK) { | 397 target->check_type() == RECEIVER_MAP_CHECK) { |
| 410 Map* map = target->FindFirstMap(); | 398 Map* map = target->FindFirstMap(); |
| 411 if (map == NULL) { | 399 if (map == NULL) { |
| 412 SetInfo(position, target); | 400 value = target; |
| 413 } else { | 401 } else { |
| 414 SetInfo(position, map); | 402 value = Handle<Map>(map); |
| 415 } | 403 } |
| 416 } else { | 404 } else { |
| 417 ASSERT(target->kind() == Code::CALL_IC); | 405 ASSERT(target->kind() == Code::CALL_IC); |
| 418 CheckType check = target->check_type(); | 406 CheckType check = target->check_type(); |
| 419 ASSERT(check != RECEIVER_MAP_CHECK); | 407 ASSERT(check != RECEIVER_MAP_CHECK); |
| 420 SetInfo(position, Smi::FromInt(check)); | 408 value = Handle<Object>(Smi::FromInt(check)); |
| 421 } | 409 } |
| 422 } else if (state == MEGAMORPHIC) { | 410 } else if (state == MEGAMORPHIC) { |
| 423 SetInfo(position, target); | 411 value = target; |
| 412 } |
| 413 |
| 414 if (!value.is_null()) { |
| 415 Handle<NumberDictionary> new_dict = |
| 416 isolate->factory()->DictionaryAtNumberPut( |
| 417 dictionary_, position, value); |
| 418 dictionary_ = loop_scope.CloseAndEscape(new_dict); |
| 424 } | 419 } |
| 425 } | 420 } |
| 426 // Allocate handle in the parent scope. | 421 // Allocate handle in the parent scope. |
| 427 dictionary_ = scope.CloseAndEscape(dictionary_); | 422 dictionary_ = scope.CloseAndEscape(dictionary_); |
| 428 } | 423 } |
| 429 | 424 |
| 430 | 425 |
| 431 void TypeFeedbackOracle::CollectPositions(Code* code, | 426 void TypeFeedbackOracle::CollectPositions(Code* code, |
| 432 List<int>* code_positions, | 427 List<int>* code_positions, |
| 433 List<int>* source_positions) { | 428 List<int>* source_positions) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 463 source_positions->Add(position); | 458 source_positions->Add(position); |
| 464 } | 459 } |
| 465 } else { | 460 } else { |
| 466 ASSERT(RelocInfo::IsPosition(mode)); | 461 ASSERT(RelocInfo::IsPosition(mode)); |
| 467 position = static_cast<int>(info->data()); | 462 position = static_cast<int>(info->data()); |
| 468 } | 463 } |
| 469 } | 464 } |
| 470 } | 465 } |
| 471 | 466 |
| 472 } } // namespace v8::internal | 467 } } // namespace v8::internal |
| OLD | NEW |