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

Side by Side Diff: src/objects.cc

Issue 2562623003: Revert of Store OSR'd optimized code on the native context. (patchset #8 id:140001 of https://coder… (Closed)
Patch Set: Created 4 years 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/objects.h ('k') | test/cctest/interpreter/bytecode_expectations/CallRuntime.golden » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 12386 matching lines...) Expand 10 before | Expand all | Expand 10 after
12397 // static 12397 // static
12398 void SharedFunctionInfo::AddToOptimizedCodeMap( 12398 void SharedFunctionInfo::AddToOptimizedCodeMap(
12399 Handle<SharedFunctionInfo> shared, Handle<Context> native_context, 12399 Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
12400 MaybeHandle<Code> code, Handle<LiteralsArray> literals, 12400 MaybeHandle<Code> code, Handle<LiteralsArray> literals,
12401 BailoutId osr_ast_id) { 12401 BailoutId osr_ast_id) {
12402 Isolate* isolate = shared->GetIsolate(); 12402 Isolate* isolate = shared->GetIsolate();
12403 if (isolate->serializer_enabled()) return; 12403 if (isolate->serializer_enabled()) return;
12404 DCHECK(code.is_null() || 12404 DCHECK(code.is_null() ||
12405 code.ToHandleChecked()->kind() == Code::OPTIMIZED_FUNCTION); 12405 code.ToHandleChecked()->kind() == Code::OPTIMIZED_FUNCTION);
12406 DCHECK(native_context->IsNativeContext()); 12406 DCHECK(native_context->IsNativeContext());
12407 STATIC_ASSERT(kEntryLength == 3); 12407 STATIC_ASSERT(kEntryLength == 4);
12408 Handle<FixedArray> new_code_map; 12408 Handle<FixedArray> new_code_map;
12409 int entry; 12409 int entry;
12410 12410
12411 if (!osr_ast_id.IsNone()) {
12412 Context::AddToOptimizedCodeMap(
12413 native_context, shared, code.ToHandleChecked(), literals, osr_ast_id);
12414 return;
12415 }
12416
12417 DCHECK(osr_ast_id.IsNone());
12418 if (shared->OptimizedCodeMapIsCleared()) { 12411 if (shared->OptimizedCodeMapIsCleared()) {
12419 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED); 12412 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED);
12420 entry = kEntriesStart; 12413 entry = kEntriesStart;
12421 } else { 12414 } else {
12422 Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate); 12415 Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate);
12423 entry = shared->SearchOptimizedCodeMapEntry(*native_context); 12416 entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id);
12424 if (entry >= kEntriesStart) { 12417 if (entry >= kEntriesStart) {
12425 // Just set the code and literals of the entry. 12418 // Just set the code and literals of the entry.
12426 if (!code.is_null()) { 12419 if (!code.is_null()) {
12427 Handle<WeakCell> code_cell = 12420 Handle<WeakCell> code_cell =
12428 isolate->factory()->NewWeakCell(code.ToHandleChecked()); 12421 isolate->factory()->NewWeakCell(code.ToHandleChecked());
12429 old_code_map->set(entry + kCachedCodeOffset, *code_cell); 12422 old_code_map->set(entry + kCachedCodeOffset, *code_cell);
12430 } 12423 }
12431 Handle<WeakCell> literals_cell = 12424 Handle<WeakCell> literals_cell =
12432 isolate->factory()->NewWeakCell(literals); 12425 isolate->factory()->NewWeakCell(literals);
12433 old_code_map->set(entry + kLiteralsOffset, *literals_cell); 12426 old_code_map->set(entry + kLiteralsOffset, *literals_cell);
(...skipping 26 matching lines...) Expand all
12460 12453
12461 Handle<WeakCell> code_cell = 12454 Handle<WeakCell> code_cell =
12462 code.is_null() ? isolate->factory()->empty_weak_cell() 12455 code.is_null() ? isolate->factory()->empty_weak_cell()
12463 : isolate->factory()->NewWeakCell(code.ToHandleChecked()); 12456 : isolate->factory()->NewWeakCell(code.ToHandleChecked());
12464 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals); 12457 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals);
12465 WeakCell* context_cell = native_context->self_weak_cell(); 12458 WeakCell* context_cell = native_context->self_weak_cell();
12466 12459
12467 new_code_map->set(entry + kContextOffset, context_cell); 12460 new_code_map->set(entry + kContextOffset, context_cell);
12468 new_code_map->set(entry + kCachedCodeOffset, *code_cell); 12461 new_code_map->set(entry + kCachedCodeOffset, *code_cell);
12469 new_code_map->set(entry + kLiteralsOffset, *literals_cell); 12462 new_code_map->set(entry + kLiteralsOffset, *literals_cell);
12463 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt()));
12470 12464
12471 #ifdef DEBUG 12465 #ifdef DEBUG
12472 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { 12466 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) {
12473 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kContextOffset)); 12467 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kContextOffset));
12474 DCHECK(cell->cleared() || cell->value()->IsNativeContext()); 12468 DCHECK(cell->cleared() || cell->value()->IsNativeContext());
12475 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset)); 12469 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset));
12476 DCHECK(cell->cleared() || 12470 DCHECK(cell->cleared() ||
12477 (cell->value()->IsCode() && 12471 (cell->value()->IsCode() &&
12478 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION)); 12472 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION));
12479 cell = WeakCell::cast(new_code_map->get(i + kLiteralsOffset)); 12473 cell = WeakCell::cast(new_code_map->get(i + kLiteralsOffset));
12480 DCHECK(cell->cleared() || cell->value()->IsFixedArray()); 12474 DCHECK(cell->cleared() || cell->value()->IsFixedArray());
12475 DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi());
12481 } 12476 }
12482 #endif 12477 #endif
12483 12478
12484 FixedArray* old_code_map = shared->optimized_code_map(); 12479 FixedArray* old_code_map = shared->optimized_code_map();
12485 if (old_code_map != *new_code_map) { 12480 if (old_code_map != *new_code_map) {
12486 shared->set_optimized_code_map(*new_code_map); 12481 shared->set_optimized_code_map(*new_code_map);
12487 } 12482 }
12488 } 12483 }
12489 12484
12490 12485
12491 void SharedFunctionInfo::ClearOptimizedCodeMap() { 12486 void SharedFunctionInfo::ClearOptimizedCodeMap() {
12492 FixedArray* empty_fixed_array = GetHeap()->empty_fixed_array(); 12487 FixedArray* empty_fixed_array = GetHeap()->empty_fixed_array();
12493 set_optimized_code_map(empty_fixed_array, SKIP_WRITE_BARRIER); 12488 set_optimized_code_map(empty_fixed_array, SKIP_WRITE_BARRIER);
12494 } 12489 }
12495 12490
12496 12491
12497 void SharedFunctionInfo::EvictFromOptimizedCodeMap(Code* optimized_code, 12492 void SharedFunctionInfo::EvictFromOptimizedCodeMap(Code* optimized_code,
12498 const char* reason) { 12493 const char* reason) {
12499 DisallowHeapAllocation no_gc; 12494 DisallowHeapAllocation no_gc;
12500 if (OptimizedCodeMapIsCleared()) return; 12495 if (OptimizedCodeMapIsCleared()) return;
12501 12496
12502 Isolate* isolate = GetIsolate(); 12497 Heap* heap = GetHeap();
12503 Heap* heap = isolate->heap();
12504 FixedArray* code_map = optimized_code_map(); 12498 FixedArray* code_map = optimized_code_map();
12499 int dst = kEntriesStart;
12505 int length = code_map->length(); 12500 int length = code_map->length();
12506 bool found = false;
12507 for (int src = kEntriesStart; src < length; src += kEntryLength) { 12501 for (int src = kEntriesStart; src < length; src += kEntryLength) {
12508 DCHECK(WeakCell::cast(code_map->get(src))->cleared() || 12502 DCHECK(WeakCell::cast(code_map->get(src))->cleared() ||
12509 WeakCell::cast(code_map->get(src))->value()->IsNativeContext()); 12503 WeakCell::cast(code_map->get(src))->value()->IsNativeContext());
12510 found = WeakCell::cast(code_map->get(src + kCachedCodeOffset))->value() == 12504 if (WeakCell::cast(code_map->get(src + kCachedCodeOffset))->value() ==
12511 optimized_code; 12505 optimized_code) {
12512 if (found) { 12506 BailoutId osr(Smi::cast(code_map->get(src + kOsrAstIdOffset))->value());
12513 if (FLAG_trace_opt) { 12507 if (FLAG_trace_opt) {
12514 PrintF("[evicting entry from optimizing code map (%s) for ", reason); 12508 PrintF("[evicting entry from optimizing code map (%s) for ", reason);
12515 ShortPrint(); 12509 ShortPrint();
12516 PrintF("]\n"); 12510 if (osr.IsNone()) {
12511 PrintF("]\n");
12512 } else {
12513 PrintF(" (osr ast id %d)]\n", osr.ToInt());
12514 }
12517 } 12515 }
12518 // Just clear the code in order to continue sharing literals. 12516 if (!osr.IsNone()) {
12517 // Evict the src entry by not copying it to the dst entry.
12518 continue;
12519 }
12520 // In case of non-OSR entry just clear the code in order to proceed
12521 // sharing literals.
12519 code_map->set(src + kCachedCodeOffset, heap->empty_weak_cell(), 12522 code_map->set(src + kCachedCodeOffset, heap->empty_weak_cell(),
12520 SKIP_WRITE_BARRIER); 12523 SKIP_WRITE_BARRIER);
12521 } 12524 }
12525
12526 // Keep the src entry by copying it to the dst entry.
12527 if (dst != src) {
12528 code_map->set(dst + kContextOffset, code_map->get(src + kContextOffset));
12529 code_map->set(dst + kCachedCodeOffset,
12530 code_map->get(src + kCachedCodeOffset));
12531 code_map->set(dst + kLiteralsOffset,
12532 code_map->get(src + kLiteralsOffset));
12533 code_map->set(dst + kOsrAstIdOffset,
12534 code_map->get(src + kOsrAstIdOffset));
12535 }
12536 dst += kEntryLength;
12522 } 12537 }
12523 12538 if (dst != length) {
12524 if (!found) { 12539 // Always trim even when array is cleared because of heap verifier.
12525 // We didn't find the code in here. It must be osr'd code. 12540 heap->RightTrimFixedArray(code_map, length - dst);
12526 isolate->EvictOSROptimizedCode(optimized_code, reason); 12541 if (code_map->length() == kEntriesStart) {
12542 ClearOptimizedCodeMap();
12543 }
12527 } 12544 }
12528 } 12545 }
12529 12546
12530 // static 12547 // static
12531 void JSFunction::EnsureLiterals(Handle<JSFunction> function) { 12548 void JSFunction::EnsureLiterals(Handle<JSFunction> function) {
12532 Handle<SharedFunctionInfo> shared(function->shared()); 12549 Handle<SharedFunctionInfo> shared(function->shared());
12533 Handle<Context> native_context(function->context()->native_context()); 12550 Handle<Context> native_context(function->context()->native_context());
12534 if (function->literals() == 12551 if (function->literals() ==
12535 function->GetIsolate()->heap()->empty_literals_array()) { 12552 function->GetIsolate()->heap()->empty_literals_array()) {
12536 Handle<LiteralsArray> literals = 12553 Handle<LiteralsArray> literals =
(...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after
14053 set_profiler_ticks(0); 14070 set_profiler_ticks(0);
14054 if (optimization_disabled() && opt_count() >= FLAG_max_opt_count) { 14071 if (optimization_disabled() && opt_count() >= FLAG_max_opt_count) {
14055 // Re-enable optimizations if they were disabled due to opt_count limit. 14072 // Re-enable optimizations if they were disabled due to opt_count limit.
14056 set_optimization_disabled(false); 14073 set_optimization_disabled(false);
14057 } 14074 }
14058 set_opt_count(0); 14075 set_opt_count(0);
14059 set_deopt_count(0); 14076 set_deopt_count(0);
14060 } 14077 }
14061 } 14078 }
14062 14079
14063 int SharedFunctionInfo::SearchOptimizedCodeMapEntry(Context* native_context) { 14080 int SharedFunctionInfo::SearchOptimizedCodeMapEntry(Context* native_context,
14081 BailoutId osr_ast_id) {
14064 DisallowHeapAllocation no_gc; 14082 DisallowHeapAllocation no_gc;
14065 DCHECK(native_context->IsNativeContext()); 14083 DCHECK(native_context->IsNativeContext());
14066 if (!OptimizedCodeMapIsCleared()) { 14084 if (!OptimizedCodeMapIsCleared()) {
14067 FixedArray* optimized_code_map = this->optimized_code_map(); 14085 FixedArray* optimized_code_map = this->optimized_code_map();
14068 int length = optimized_code_map->length(); 14086 int length = optimized_code_map->length();
14087 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt());
14069 for (int i = kEntriesStart; i < length; i += kEntryLength) { 14088 for (int i = kEntriesStart; i < length; i += kEntryLength) {
14070 if (WeakCell::cast(optimized_code_map->get(i + kContextOffset)) 14089 if (WeakCell::cast(optimized_code_map->get(i + kContextOffset))
14071 ->value() == native_context) { 14090 ->value() == native_context &&
14091 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) {
14072 return i; 14092 return i;
14073 } 14093 }
14074 } 14094 }
14075 } 14095 }
14076 return -1; 14096 return -1;
14077 } 14097 }
14078 14098
14079 void SharedFunctionInfo::ClearCodeFromOptimizedCodeMap() { 14099 void SharedFunctionInfo::ClearCodeFromOptimizedCodeMap() {
14080 if (!OptimizedCodeMapIsCleared()) { 14100 if (!OptimizedCodeMapIsCleared()) {
14081 FixedArray* optimized_code_map = this->optimized_code_map(); 14101 FixedArray* optimized_code_map = this->optimized_code_map();
14082 int length = optimized_code_map->length(); 14102 int length = optimized_code_map->length();
14083 WeakCell* empty_weak_cell = GetHeap()->empty_weak_cell(); 14103 WeakCell* empty_weak_cell = GetHeap()->empty_weak_cell();
14084 for (int i = kEntriesStart; i < length; i += kEntryLength) { 14104 for (int i = kEntriesStart; i < length; i += kEntryLength) {
14085 optimized_code_map->set(i + kCachedCodeOffset, empty_weak_cell, 14105 optimized_code_map->set(i + kCachedCodeOffset, empty_weak_cell,
14086 SKIP_WRITE_BARRIER); 14106 SKIP_WRITE_BARRIER);
14087 } 14107 }
14088 } 14108 }
14089 } 14109 }
14090 14110
14091 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( 14111 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap(
14092 Context* native_context, BailoutId osr_ast_id) { 14112 Context* native_context, BailoutId osr_ast_id) {
14093 CodeAndLiterals result = {nullptr, nullptr}; 14113 CodeAndLiterals result = {nullptr, nullptr};
14094 if (!osr_ast_id.IsNone()) { 14114 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id);
14095 Code* code;
14096 LiteralsArray* literals;
14097 native_context->SearchOptimizedCodeMap(this, osr_ast_id, &code, &literals);
14098 result = {code, literals};
14099 return result;
14100 }
14101
14102 DCHECK(osr_ast_id.IsNone());
14103 int entry = SearchOptimizedCodeMapEntry(native_context);
14104 if (entry != kNotFound) { 14115 if (entry != kNotFound) {
14105 FixedArray* code_map = optimized_code_map(); 14116 FixedArray* code_map = optimized_code_map();
14106 DCHECK_LE(entry + kEntryLength, code_map->length()); 14117 DCHECK_LE(entry + kEntryLength, code_map->length());
14107 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset)); 14118 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset));
14108 WeakCell* literals_cell = 14119 WeakCell* literals_cell =
14109 WeakCell::cast(code_map->get(entry + kLiteralsOffset)); 14120 WeakCell::cast(code_map->get(entry + kLiteralsOffset));
14110 14121
14111 result = {cell->cleared() ? nullptr : Code::cast(cell->value()), 14122 result = {cell->cleared() ? nullptr : Code::cast(cell->value()),
14112 literals_cell->cleared() ? nullptr : LiteralsArray::cast( 14123 literals_cell->cleared() ? nullptr : LiteralsArray::cast(
14113 literals_cell->value())}; 14124 literals_cell->value())};
(...skipping 6298 matching lines...) Expand 10 before | Expand all | Expand 10 after
20412 // depend on this. 20423 // depend on this.
20413 return DICTIONARY_ELEMENTS; 20424 return DICTIONARY_ELEMENTS;
20414 } 20425 }
20415 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 20426 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
20416 return kind; 20427 return kind;
20417 } 20428 }
20418 } 20429 }
20419 20430
20420 } // namespace internal 20431 } // namespace internal
20421 } // namespace v8 20432 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/cctest/interpreter/bytecode_expectations/CallRuntime.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698