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

Side by Side Diff: src/contexts.cc

Issue 2655853010: [TypeFeedbackVector] Combine the literals array and the feedback vector. (Closed)
Patch Set: more comments. Created 3 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
« no previous file with comments | « src/contexts.h ('k') | src/crankshaft/hydrogen.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/contexts.h" 5 #include "src/contexts.h"
6 6
7 #include "src/bootstrapper.h" 7 #include "src/bootstrapper.h"
8 #include "src/debug/debug.h" 8 #include "src/debug/debug.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 10
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } while (follow_context_chain); 405 } while (follow_context_chain);
406 406
407 if (FLAG_trace_contexts) { 407 if (FLAG_trace_contexts) {
408 PrintF("=> no property/slot found\n"); 408 PrintF("=> no property/slot found\n");
409 } 409 }
410 return Handle<Object>::null(); 410 return Handle<Object>::null();
411 } 411 }
412 412
413 static const int kSharedOffset = 0; 413 static const int kSharedOffset = 0;
414 static const int kCachedCodeOffset = 1; 414 static const int kCachedCodeOffset = 1;
415 static const int kLiteralsOffset = 2; 415 static const int kFeedbackVectorOffset = 2;
416 static const int kOsrAstIdOffset = 3; 416 static const int kOsrAstIdOffset = 3;
417 static const int kEntryLength = 4; 417 static const int kEntryLength = 4;
418 static const int kInitialLength = kEntryLength; 418 static const int kInitialLength = kEntryLength;
419 419
420 int Context::SearchOptimizedCodeMapEntry(SharedFunctionInfo* shared, 420 int Context::SearchOptimizedCodeMapEntry(SharedFunctionInfo* shared,
421 BailoutId osr_ast_id) { 421 BailoutId osr_ast_id) {
422 DisallowHeapAllocation no_gc; 422 DisallowHeapAllocation no_gc;
423 DCHECK(this->IsNativeContext()); 423 DCHECK(this->IsNativeContext());
424 if (!OptimizedCodeMapIsCleared()) { 424 if (!OptimizedCodeMapIsCleared()) {
425 FixedArray* optimized_code_map = this->osr_code_table(); 425 FixedArray* optimized_code_map = this->osr_code_table();
426 int length = optimized_code_map->length(); 426 int length = optimized_code_map->length();
427 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt()); 427 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt());
428 for (int i = 0; i < length; i += kEntryLength) { 428 for (int i = 0; i < length; i += kEntryLength) {
429 if (WeakCell::cast(optimized_code_map->get(i + kSharedOffset))->value() == 429 if (WeakCell::cast(optimized_code_map->get(i + kSharedOffset))->value() ==
430 shared && 430 shared &&
431 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) { 431 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) {
432 return i; 432 return i;
433 } 433 }
434 } 434 }
435 } 435 }
436 return -1; 436 return -1;
437 } 437 }
438 438
439 void Context::SearchOptimizedCodeMap(SharedFunctionInfo* shared, 439 void Context::SearchOptimizedCodeMap(SharedFunctionInfo* shared,
440 BailoutId osr_ast_id, Code** pcode, 440 BailoutId osr_ast_id, Code** pcode,
441 LiteralsArray** pliterals) { 441 TypeFeedbackVector** pvector) {
442 DCHECK(this->IsNativeContext()); 442 DCHECK(this->IsNativeContext());
443 int entry = SearchOptimizedCodeMapEntry(shared, osr_ast_id); 443 int entry = SearchOptimizedCodeMapEntry(shared, osr_ast_id);
444 if (entry != -1) { 444 if (entry != -1) {
445 FixedArray* code_map = osr_code_table(); 445 FixedArray* code_map = osr_code_table();
446 DCHECK_LE(entry + kEntryLength, code_map->length()); 446 DCHECK_LE(entry + kEntryLength, code_map->length());
447 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset)); 447 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset));
448 WeakCell* literals_cell = 448 WeakCell* vector_cell =
449 WeakCell::cast(code_map->get(entry + kLiteralsOffset)); 449 WeakCell::cast(code_map->get(entry + kFeedbackVectorOffset));
450 450
451 *pcode = cell->cleared() ? nullptr : Code::cast(cell->value()); 451 *pcode = cell->cleared() ? nullptr : Code::cast(cell->value());
452 *pliterals = literals_cell->cleared() 452 *pvector = vector_cell->cleared()
453 ? nullptr 453 ? nullptr
454 : LiteralsArray::cast(literals_cell->value()); 454 : TypeFeedbackVector::cast(vector_cell->value());
455 } else { 455 } else {
456 *pcode = nullptr; 456 *pcode = nullptr;
457 *pliterals = nullptr; 457 *pvector = nullptr;
458 } 458 }
459 } 459 }
460 460
461 void Context::AddToOptimizedCodeMap(Handle<Context> native_context, 461 void Context::AddToOptimizedCodeMap(Handle<Context> native_context,
462 Handle<SharedFunctionInfo> shared, 462 Handle<SharedFunctionInfo> shared,
463 Handle<Code> code, 463 Handle<Code> code,
464 Handle<LiteralsArray> literals, 464 Handle<TypeFeedbackVector> vector,
465 BailoutId osr_ast_id) { 465 BailoutId osr_ast_id) {
466 DCHECK(native_context->IsNativeContext()); 466 DCHECK(native_context->IsNativeContext());
467 Isolate* isolate = native_context->GetIsolate(); 467 Isolate* isolate = native_context->GetIsolate();
468 if (isolate->serializer_enabled()) return; 468 if (isolate->serializer_enabled()) return;
469 469
470 STATIC_ASSERT(kEntryLength == 4); 470 STATIC_ASSERT(kEntryLength == 4);
471 Handle<FixedArray> new_code_map; 471 Handle<FixedArray> new_code_map;
472 int entry; 472 int entry;
473 473
474 if (native_context->OptimizedCodeMapIsCleared()) { 474 if (native_context->OptimizedCodeMapIsCleared()) {
475 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED); 475 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED);
476 entry = 0; 476 entry = 0;
477 } else { 477 } else {
478 Handle<FixedArray> old_code_map(native_context->osr_code_table(), isolate); 478 Handle<FixedArray> old_code_map(native_context->osr_code_table(), isolate);
479 entry = native_context->SearchOptimizedCodeMapEntry(*shared, osr_ast_id); 479 entry = native_context->SearchOptimizedCodeMapEntry(*shared, osr_ast_id);
480 if (entry >= 0) { 480 if (entry >= 0) {
481 // Just set the code and literals of the entry. 481 // Just set the code and literals of the entry.
482 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code); 482 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code);
483 old_code_map->set(entry + kCachedCodeOffset, *code_cell); 483 old_code_map->set(entry + kCachedCodeOffset, *code_cell);
484 Handle<WeakCell> literals_cell = 484 Handle<WeakCell> vector_cell = isolate->factory()->NewWeakCell(vector);
485 isolate->factory()->NewWeakCell(literals); 485 old_code_map->set(entry + kFeedbackVectorOffset, *vector_cell);
486 old_code_map->set(entry + kLiteralsOffset, *literals_cell);
487 return; 486 return;
488 } 487 }
489 488
490 // Can we reuse an entry? 489 // Can we reuse an entry?
491 DCHECK(entry < 0); 490 DCHECK(entry < 0);
492 int length = old_code_map->length(); 491 int length = old_code_map->length();
493 for (int i = 0; i < length; i += kEntryLength) { 492 for (int i = 0; i < length; i += kEntryLength) {
494 if (WeakCell::cast(old_code_map->get(i + kSharedOffset))->cleared()) { 493 if (WeakCell::cast(old_code_map->get(i + kSharedOffset))->cleared()) {
495 new_code_map = old_code_map; 494 new_code_map = old_code_map;
496 entry = i; 495 entry = i;
497 break; 496 break;
498 } 497 }
499 } 498 }
500 499
501 if (entry < 0) { 500 if (entry < 0) {
502 // Copy old optimized code map and append one new entry. 501 // Copy old optimized code map and append one new entry.
503 new_code_map = isolate->factory()->CopyFixedArrayAndGrow( 502 new_code_map = isolate->factory()->CopyFixedArrayAndGrow(
504 old_code_map, kEntryLength, TENURED); 503 old_code_map, kEntryLength, TENURED);
505 entry = old_code_map->length(); 504 entry = old_code_map->length();
506 } 505 }
507 } 506 }
508 507
509 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code); 508 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code);
510 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals); 509 Handle<WeakCell> vector_cell = isolate->factory()->NewWeakCell(vector);
511 Handle<WeakCell> shared_cell = isolate->factory()->NewWeakCell(shared); 510 Handle<WeakCell> shared_cell = isolate->factory()->NewWeakCell(shared);
512 511
513 new_code_map->set(entry + kSharedOffset, *shared_cell); 512 new_code_map->set(entry + kSharedOffset, *shared_cell);
514 new_code_map->set(entry + kCachedCodeOffset, *code_cell); 513 new_code_map->set(entry + kCachedCodeOffset, *code_cell);
515 new_code_map->set(entry + kLiteralsOffset, *literals_cell); 514 new_code_map->set(entry + kFeedbackVectorOffset, *vector_cell);
516 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); 515 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt()));
517 516
518 #ifdef DEBUG 517 #ifdef DEBUG
519 for (int i = 0; i < new_code_map->length(); i += kEntryLength) { 518 for (int i = 0; i < new_code_map->length(); i += kEntryLength) {
520 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kSharedOffset)); 519 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kSharedOffset));
521 DCHECK(cell->cleared() || cell->value()->IsSharedFunctionInfo()); 520 DCHECK(cell->cleared() || cell->value()->IsSharedFunctionInfo());
522 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset)); 521 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset));
523 DCHECK(cell->cleared() || 522 DCHECK(cell->cleared() ||
524 (cell->value()->IsCode() && 523 (cell->value()->IsCode() &&
525 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION)); 524 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION));
526 cell = WeakCell::cast(new_code_map->get(i + kLiteralsOffset)); 525 cell = WeakCell::cast(new_code_map->get(i + kFeedbackVectorOffset));
527 DCHECK(cell->cleared() || cell->value()->IsFixedArray()); 526 DCHECK(cell->cleared() || cell->value()->IsFixedArray());
528 DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi()); 527 DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi());
529 } 528 }
530 #endif 529 #endif
531 530
532 FixedArray* old_code_map = native_context->osr_code_table(); 531 FixedArray* old_code_map = native_context->osr_code_table();
533 if (old_code_map != *new_code_map) { 532 if (old_code_map != *new_code_map) {
534 native_context->set_osr_code_table(*new_code_map); 533 native_context->set_osr_code_table(*new_code_map);
535 } 534 }
536 } 535 }
(...skipping 21 matching lines...) Expand all
558 PrintF(" (osr ast id %d)]\n", osr.ToInt()); 557 PrintF(" (osr ast id %d)]\n", osr.ToInt());
559 } 558 }
560 // Evict the src entry by not copying it to the dst entry. 559 // Evict the src entry by not copying it to the dst entry.
561 continue; 560 continue;
562 } 561 }
563 // Keep the src entry by copying it to the dst entry. 562 // Keep the src entry by copying it to the dst entry.
564 if (dst != src) { 563 if (dst != src) {
565 code_map->set(dst + kSharedOffset, code_map->get(src + kSharedOffset)); 564 code_map->set(dst + kSharedOffset, code_map->get(src + kSharedOffset));
566 code_map->set(dst + kCachedCodeOffset, 565 code_map->set(dst + kCachedCodeOffset,
567 code_map->get(src + kCachedCodeOffset)); 566 code_map->get(src + kCachedCodeOffset));
568 code_map->set(dst + kLiteralsOffset, 567 code_map->set(dst + kFeedbackVectorOffset,
569 code_map->get(src + kLiteralsOffset)); 568 code_map->get(src + kFeedbackVectorOffset));
570 code_map->set(dst + kOsrAstIdOffset, 569 code_map->set(dst + kOsrAstIdOffset,
571 code_map->get(src + kOsrAstIdOffset)); 570 code_map->get(src + kOsrAstIdOffset));
572 } 571 }
573 dst += kEntryLength; 572 dst += kEntryLength;
574 } 573 }
575 if (dst != length) { 574 if (dst != length) {
576 // Always trim even when array is cleared because of heap verifier. 575 // Always trim even when array is cleared because of heap verifier.
577 heap->RightTrimFixedArray(code_map, length - dst); 576 heap->RightTrimFixedArray(code_map, length - dst);
578 if (code_map->length() == 0) { 577 if (code_map->length() == 0) {
579 ClearOptimizedCodeMap(); 578 ClearOptimizedCodeMap();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 769
771 int previous_value = errors_thrown()->value(); 770 int previous_value = errors_thrown()->value();
772 set_errors_thrown(Smi::FromInt(previous_value + 1)); 771 set_errors_thrown(Smi::FromInt(previous_value + 1));
773 } 772 }
774 773
775 774
776 int Context::GetErrorsThrown() { return errors_thrown()->value(); } 775 int Context::GetErrorsThrown() { return errors_thrown()->value(); }
777 776
778 } // namespace internal 777 } // namespace internal
779 } // namespace v8 778 } // namespace v8
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | src/crankshaft/hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698