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

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

Issue 6771008: Reduce handle usage in type-info.cc PopulateMap. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add AllocScope Created 9 years, 8 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') | 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Object* result;
361 // Dictionary has been allocated with sufficient size for all elements.
362 ASSERT(maybe_result->ToObject(&result));
363 ASSERT(*dictionary_ == result);
364 }
365
366
358 void TypeFeedbackOracle::PopulateMap(Handle<Code> code) { 367 void TypeFeedbackOracle::PopulateMap(Handle<Code> code) {
359 Isolate* isolate = Isolate::Current(); 368 Isolate* isolate = Isolate::Current();
360 HandleScope scope(isolate); 369 HandleScope scope(isolate);
361 370
362 const int kInitialCapacity = 16; 371 const int kInitialCapacity = 16;
363 List<int> code_positions(kInitialCapacity); 372 List<int> code_positions(kInitialCapacity);
364 List<int> source_positions(kInitialCapacity); 373 List<int> source_positions(kInitialCapacity);
365 CollectPositions(*code, &code_positions, &source_positions); 374 CollectPositions(*code, &code_positions, &source_positions);
366 375
367 ASSERT(dictionary_.is_null()); // Only initialize once. 376 ASSERT(dictionary_.is_null()); // Only initialize once.
368 dictionary_ = isolate->factory()->NewNumberDictionary( 377 dictionary_ = isolate->factory()->NewNumberDictionary(
369 code_positions.length()); 378 code_positions.length());
370 379
371 int length = code_positions.length(); 380 int length = code_positions.length();
372 ASSERT(source_positions.length() == length); 381 ASSERT(source_positions.length() == length);
373 for (int i = 0; i < length; i++) { 382 for (int i = 0; i < length; i++) {
374 HandleScope loop_scope(isolate); 383 AssertNoAllocation no_allocation();
375 RelocInfo info(code->instruction_start() + code_positions[i], 384 RelocInfo info(code->instruction_start() + code_positions[i],
376 RelocInfo::CODE_TARGET, 0); 385 RelocInfo::CODE_TARGET, 0);
377 Handle<Code> target(Code::GetCodeFromTargetAddress(info.target_address())); 386 Code* target = Code::GetCodeFromTargetAddress(info.target_address());
378 int position = source_positions[i]; 387 int position = source_positions[i];
379 InlineCacheState state = target->ic_state(); 388 InlineCacheState state = target->ic_state();
380 Code::Kind kind = target->kind(); 389 Code::Kind kind = target->kind();
381 Handle<Object> value; 390
382 if (kind == Code::BINARY_OP_IC || 391 if (kind == Code::BINARY_OP_IC ||
383 kind == Code::TYPE_RECORDING_BINARY_OP_IC || 392 kind == Code::TYPE_RECORDING_BINARY_OP_IC ||
384 kind == Code::COMPARE_IC) { 393 kind == Code::COMPARE_IC) {
385 // TODO(kasperl): Avoid having multiple ICs with the same 394 // TODO(kasperl): Avoid having multiple ICs with the same
386 // position by making sure that we have position information 395 // position by making sure that we have position information
387 // recorded for all binary ICs. 396 // recorded for all binary ICs.
388 int entry = dictionary_->FindEntry(position); 397 int entry = dictionary_->FindEntry(position);
389 if (entry == NumberDictionary::kNotFound) { 398 if (entry == NumberDictionary::kNotFound) {
390 value = target; 399 SetInfo(position, target);
391 } 400 }
392 } else if (state == MONOMORPHIC) { 401 } else if (state == MONOMORPHIC) {
393 if (kind == Code::KEYED_EXTERNAL_ARRAY_LOAD_IC || 402 if (kind == Code::KEYED_EXTERNAL_ARRAY_LOAD_IC ||
394 kind == Code::KEYED_EXTERNAL_ARRAY_STORE_IC) { 403 kind == Code::KEYED_EXTERNAL_ARRAY_STORE_IC) {
395 value = target; 404 SetInfo(position, target);
396 } else if (target->kind() != Code::CALL_IC || 405 } else if (target->kind() != Code::CALL_IC ||
397 target->check_type() == RECEIVER_MAP_CHECK) { 406 target->check_type() == RECEIVER_MAP_CHECK) {
398 Map* map = target->FindFirstMap(); 407 Map* map = target->FindFirstMap();
399 if (map == NULL) { 408 if (map == NULL) {
400 value = target; 409 SetInfo(position, target);
401 } else { 410 } else {
402 value = Handle<Map>(map); 411 SetInfo(position, map);
403 } 412 }
404 } else { 413 } else {
405 ASSERT(target->kind() == Code::CALL_IC); 414 ASSERT(target->kind() == Code::CALL_IC);
406 CheckType check = target->check_type(); 415 CheckType check = target->check_type();
407 ASSERT(check != RECEIVER_MAP_CHECK); 416 ASSERT(check != RECEIVER_MAP_CHECK);
408 value = Handle<Object>(Smi::FromInt(check)); 417 SetInfo(position, Smi::FromInt(check));
409 } 418 }
410 } else if (state == MEGAMORPHIC) { 419 } else if (state == MEGAMORPHIC) {
411 value = target; 420 SetInfo(position, 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);
419 } 421 }
420 } 422 }
421 // Allocate handle in the parent scope. 423 // Allocate handle in the parent scope.
422 dictionary_ = scope.CloseAndEscape(dictionary_); 424 dictionary_ = scope.CloseAndEscape(dictionary_);
423 } 425 }
424 426
425 427
426 void TypeFeedbackOracle::CollectPositions(Code* code, 428 void TypeFeedbackOracle::CollectPositions(Code* code,
427 List<int>* code_positions, 429 List<int>* code_positions,
428 List<int>* source_positions) { 430 List<int>* source_positions) {
(...skipping 29 matching lines...) Expand all
458 source_positions->Add(position); 460 source_positions->Add(position);
459 } 461 }
460 } else { 462 } else {
461 ASSERT(RelocInfo::IsPosition(mode)); 463 ASSERT(RelocInfo::IsPosition(mode));
462 position = static_cast<int>(info->data()); 464 position = static_cast<int>(info->data());
463 } 465 }
464 } 466 }
465 } 467 }
466 468
467 } } // namespace v8::internal 469 } } // 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