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

Side by Side Diff: src/contexts.cc

Issue 2620753003: [TypeFeedbackVector] Root literal arrays in function literals slots (Closed)
Patch Set: GCSTRESS fix. Created 3 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/contexts.h ('k') | src/debug/liveedit.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 kOsrAstIdOffset = 2;
416 static const int kOsrAstIdOffset = 3; 416 static const int kEntryLength = 3;
417 static const int kEntryLength = 4;
418 static const int kInitialLength = kEntryLength; 417 static const int kInitialLength = kEntryLength;
419 418
420 int Context::SearchOptimizedCodeMapEntry(SharedFunctionInfo* shared, 419 int Context::SearchOptimizedCodeMapEntry(SharedFunctionInfo* shared,
421 BailoutId osr_ast_id) { 420 BailoutId osr_ast_id) {
422 DisallowHeapAllocation no_gc; 421 DisallowHeapAllocation no_gc;
423 DCHECK(this->IsNativeContext()); 422 DCHECK(this->IsNativeContext());
424 if (!OptimizedCodeMapIsCleared()) { 423 if (!OptimizedCodeMapIsCleared()) {
425 FixedArray* optimized_code_map = this->osr_code_table(); 424 FixedArray* optimized_code_map = this->osr_code_table();
426 int length = optimized_code_map->length(); 425 int length = optimized_code_map->length();
427 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt()); 426 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt());
428 for (int i = 0; i < length; i += kEntryLength) { 427 for (int i = 0; i < length; i += kEntryLength) {
429 if (WeakCell::cast(optimized_code_map->get(i + kSharedOffset))->value() == 428 if (WeakCell::cast(optimized_code_map->get(i + kSharedOffset))->value() ==
430 shared && 429 shared &&
431 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) { 430 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) {
432 return i; 431 return i;
433 } 432 }
434 } 433 }
435 } 434 }
436 return -1; 435 return -1;
437 } 436 }
438 437
439 void Context::SearchOptimizedCodeMap(SharedFunctionInfo* shared, 438 Code* Context::SearchOptimizedCodeMap(SharedFunctionInfo* shared,
440 BailoutId osr_ast_id, Code** pcode, 439 BailoutId osr_ast_id) {
441 LiteralsArray** pliterals) {
442 DCHECK(this->IsNativeContext()); 440 DCHECK(this->IsNativeContext());
443 int entry = SearchOptimizedCodeMapEntry(shared, osr_ast_id); 441 int entry = SearchOptimizedCodeMapEntry(shared, osr_ast_id);
444 if (entry != -1) { 442 if (entry != -1) {
445 FixedArray* code_map = osr_code_table(); 443 FixedArray* code_map = osr_code_table();
446 DCHECK_LE(entry + kEntryLength, code_map->length()); 444 DCHECK_LE(entry + kEntryLength, code_map->length());
447 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset)); 445 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset));
448 WeakCell* literals_cell =
449 WeakCell::cast(code_map->get(entry + kLiteralsOffset));
450 446
451 *pcode = cell->cleared() ? nullptr : Code::cast(cell->value()); 447 return cell->cleared() ? nullptr : Code::cast(cell->value());
452 *pliterals = literals_cell->cleared()
453 ? nullptr
454 : LiteralsArray::cast(literals_cell->value());
455 } else {
456 *pcode = nullptr;
457 *pliterals = nullptr;
458 } 448 }
449 return nullptr;
459 } 450 }
460 451
461 void Context::AddToOptimizedCodeMap(Handle<Context> native_context, 452 void Context::AddToOptimizedCodeMap(Handle<Context> native_context,
462 Handle<SharedFunctionInfo> shared, 453 Handle<SharedFunctionInfo> shared,
463 Handle<Code> code, 454 Handle<Code> code,
464 Handle<LiteralsArray> literals,
465 BailoutId osr_ast_id) { 455 BailoutId osr_ast_id) {
466 DCHECK(native_context->IsNativeContext()); 456 DCHECK(native_context->IsNativeContext());
467 Isolate* isolate = native_context->GetIsolate(); 457 Isolate* isolate = native_context->GetIsolate();
468 if (isolate->serializer_enabled()) return; 458 if (isolate->serializer_enabled()) return;
469 459
470 STATIC_ASSERT(kEntryLength == 4); 460 STATIC_ASSERT(kEntryLength == 3);
471 Handle<FixedArray> new_code_map; 461 Handle<FixedArray> new_code_map;
472 int entry; 462 int entry;
473 463
474 if (native_context->OptimizedCodeMapIsCleared()) { 464 if (native_context->OptimizedCodeMapIsCleared()) {
475 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED); 465 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED);
476 entry = 0; 466 entry = 0;
477 } else { 467 } else {
478 Handle<FixedArray> old_code_map(native_context->osr_code_table(), isolate); 468 Handle<FixedArray> old_code_map(native_context->osr_code_table(), isolate);
479 entry = native_context->SearchOptimizedCodeMapEntry(*shared, osr_ast_id); 469 entry = native_context->SearchOptimizedCodeMapEntry(*shared, osr_ast_id);
480 if (entry >= 0) { 470 if (entry >= 0) {
481 // Just set the code and literals of the entry. 471 // Just set the code of the entry.
482 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code); 472 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code);
483 old_code_map->set(entry + kCachedCodeOffset, *code_cell); 473 old_code_map->set(entry + kCachedCodeOffset, *code_cell);
484 Handle<WeakCell> literals_cell =
485 isolate->factory()->NewWeakCell(literals);
486 old_code_map->set(entry + kLiteralsOffset, *literals_cell);
487 return; 474 return;
488 } 475 }
489 476
490 // Can we reuse an entry? 477 // Can we reuse an entry?
491 DCHECK(entry < 0); 478 DCHECK(entry < 0);
492 int length = old_code_map->length(); 479 int length = old_code_map->length();
493 for (int i = 0; i < length; i += kEntryLength) { 480 for (int i = 0; i < length; i += kEntryLength) {
494 if (WeakCell::cast(old_code_map->get(i + kSharedOffset))->cleared()) { 481 if (WeakCell::cast(old_code_map->get(i + kSharedOffset))->cleared()) {
495 new_code_map = old_code_map; 482 new_code_map = old_code_map;
496 entry = i; 483 entry = i;
497 break; 484 break;
498 } 485 }
499 } 486 }
500 487
501 if (entry < 0) { 488 if (entry < 0) {
502 // Copy old optimized code map and append one new entry. 489 // Copy old optimized code map and append one new entry.
503 new_code_map = isolate->factory()->CopyFixedArrayAndGrow( 490 new_code_map = isolate->factory()->CopyFixedArrayAndGrow(
504 old_code_map, kEntryLength, TENURED); 491 old_code_map, kEntryLength, TENURED);
505 entry = old_code_map->length(); 492 entry = old_code_map->length();
506 } 493 }
507 } 494 }
508 495
509 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code); 496 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code);
510 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals);
511 Handle<WeakCell> shared_cell = isolate->factory()->NewWeakCell(shared); 497 Handle<WeakCell> shared_cell = isolate->factory()->NewWeakCell(shared);
512 498
513 new_code_map->set(entry + kSharedOffset, *shared_cell); 499 new_code_map->set(entry + kSharedOffset, *shared_cell);
514 new_code_map->set(entry + kCachedCodeOffset, *code_cell); 500 new_code_map->set(entry + kCachedCodeOffset, *code_cell);
515 new_code_map->set(entry + kLiteralsOffset, *literals_cell);
516 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); 501 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt()));
517 502
518 #ifdef DEBUG 503 #ifdef DEBUG
519 for (int i = 0; i < new_code_map->length(); i += kEntryLength) { 504 for (int i = 0; i < new_code_map->length(); i += kEntryLength) {
520 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kSharedOffset)); 505 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kSharedOffset));
521 DCHECK(cell->cleared() || cell->value()->IsSharedFunctionInfo()); 506 DCHECK(cell->cleared() || cell->value()->IsSharedFunctionInfo());
522 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset)); 507 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset));
523 DCHECK(cell->cleared() || 508 DCHECK(cell->cleared() ||
524 (cell->value()->IsCode() && 509 (cell->value()->IsCode() &&
525 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION)); 510 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION));
526 cell = WeakCell::cast(new_code_map->get(i + kLiteralsOffset));
527 DCHECK(cell->cleared() || cell->value()->IsFixedArray());
528 DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi()); 511 DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi());
529 } 512 }
530 #endif 513 #endif
531 514
532 FixedArray* old_code_map = native_context->osr_code_table(); 515 FixedArray* old_code_map = native_context->osr_code_table();
533 if (old_code_map != *new_code_map) { 516 if (old_code_map != *new_code_map) {
534 native_context->set_osr_code_table(*new_code_map); 517 native_context->set_osr_code_table(*new_code_map);
535 } 518 }
536 } 519 }
537 520
(...skipping 20 matching lines...) Expand all
558 PrintF(" (osr ast id %d)]\n", osr.ToInt()); 541 PrintF(" (osr ast id %d)]\n", osr.ToInt());
559 } 542 }
560 // Evict the src entry by not copying it to the dst entry. 543 // Evict the src entry by not copying it to the dst entry.
561 continue; 544 continue;
562 } 545 }
563 // Keep the src entry by copying it to the dst entry. 546 // Keep the src entry by copying it to the dst entry.
564 if (dst != src) { 547 if (dst != src) {
565 code_map->set(dst + kSharedOffset, code_map->get(src + kSharedOffset)); 548 code_map->set(dst + kSharedOffset, code_map->get(src + kSharedOffset));
566 code_map->set(dst + kCachedCodeOffset, 549 code_map->set(dst + kCachedCodeOffset,
567 code_map->get(src + kCachedCodeOffset)); 550 code_map->get(src + kCachedCodeOffset));
568 code_map->set(dst + kLiteralsOffset,
569 code_map->get(src + kLiteralsOffset));
570 code_map->set(dst + kOsrAstIdOffset, 551 code_map->set(dst + kOsrAstIdOffset,
571 code_map->get(src + kOsrAstIdOffset)); 552 code_map->get(src + kOsrAstIdOffset));
572 } 553 }
573 dst += kEntryLength; 554 dst += kEntryLength;
574 } 555 }
575 if (dst != length) { 556 if (dst != length) {
576 // Always trim even when array is cleared because of heap verifier. 557 // Always trim even when array is cleared because of heap verifier.
577 heap->RightTrimFixedArray(code_map, length - dst); 558 heap->RightTrimFixedArray(code_map, length - dst);
578 if (code_map->length() == 0) { 559 if (code_map->length() == 0) {
579 ClearOptimizedCodeMap(); 560 ClearOptimizedCodeMap();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 751
771 int previous_value = errors_thrown()->value(); 752 int previous_value = errors_thrown()->value();
772 set_errors_thrown(Smi::FromInt(previous_value + 1)); 753 set_errors_thrown(Smi::FromInt(previous_value + 1));
773 } 754 }
774 755
775 756
776 int Context::GetErrorsThrown() { return errors_thrown()->value(); } 757 int Context::GetErrorsThrown() { return errors_thrown()->value(); }
777 758
778 } // namespace internal 759 } // namespace internal
779 } // namespace v8 760 } // namespace v8
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | src/debug/liveedit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698