Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 45394c49185dea8b4b32cc4a60e343e70c4eba9e..bd115de23c1e23252b7f5d0e1ae6546dbadf4446 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -12403,16 +12403,23 @@ void SharedFunctionInfo::AddToOptimizedCodeMap( |
DCHECK(code.is_null() || |
code.ToHandleChecked()->kind() == Code::OPTIMIZED_FUNCTION); |
DCHECK(native_context->IsNativeContext()); |
- STATIC_ASSERT(kEntryLength == 4); |
+ STATIC_ASSERT(kEntryLength == 3); |
Handle<FixedArray> new_code_map; |
int entry; |
+ if (!osr_ast_id.IsNone()) { |
+ Context::AddToOptimizedCodeMap( |
+ native_context, shared, code.ToHandleChecked(), literals, osr_ast_id); |
+ return; |
+ } |
+ |
+ DCHECK(osr_ast_id.IsNone()); |
if (shared->OptimizedCodeMapIsCleared()) { |
new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED); |
entry = kEntriesStart; |
} else { |
Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate); |
- entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id); |
+ entry = shared->SearchOptimizedCodeMapEntry(*native_context); |
if (entry >= kEntriesStart) { |
// Just set the code and literals of the entry. |
if (!code.is_null()) { |
@@ -12459,7 +12466,6 @@ void SharedFunctionInfo::AddToOptimizedCodeMap( |
new_code_map->set(entry + kContextOffset, context_cell); |
new_code_map->set(entry + kCachedCodeOffset, *code_cell); |
new_code_map->set(entry + kLiteralsOffset, *literals_cell); |
- new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); |
#ifdef DEBUG |
for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { |
@@ -12471,7 +12477,6 @@ void SharedFunctionInfo::AddToOptimizedCodeMap( |
Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION)); |
cell = WeakCell::cast(new_code_map->get(i + kLiteralsOffset)); |
DCHECK(cell->cleared() || cell->value()->IsFixedArray()); |
- DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi()); |
} |
#endif |
@@ -12493,53 +12498,31 @@ void SharedFunctionInfo::EvictFromOptimizedCodeMap(Code* optimized_code, |
DisallowHeapAllocation no_gc; |
if (OptimizedCodeMapIsCleared()) return; |
- Heap* heap = GetHeap(); |
+ Isolate* isolate = GetIsolate(); |
+ Heap* heap = isolate->heap(); |
FixedArray* code_map = optimized_code_map(); |
- int dst = kEntriesStart; |
int length = code_map->length(); |
+ bool found = false; |
for (int src = kEntriesStart; src < length; src += kEntryLength) { |
DCHECK(WeakCell::cast(code_map->get(src))->cleared() || |
WeakCell::cast(code_map->get(src))->value()->IsNativeContext()); |
- if (WeakCell::cast(code_map->get(src + kCachedCodeOffset))->value() == |
- optimized_code) { |
- BailoutId osr(Smi::cast(code_map->get(src + kOsrAstIdOffset))->value()); |
+ found = WeakCell::cast(code_map->get(src + kCachedCodeOffset))->value() == |
+ optimized_code; |
+ if (found) { |
if (FLAG_trace_opt) { |
PrintF("[evicting entry from optimizing code map (%s) for ", reason); |
ShortPrint(); |
- if (osr.IsNone()) { |
- PrintF("]\n"); |
- } else { |
- PrintF(" (osr ast id %d)]\n", osr.ToInt()); |
- } |
- } |
- if (!osr.IsNone()) { |
- // Evict the src entry by not copying it to the dst entry. |
- continue; |
+ PrintF("]\n"); |
} |
- // In case of non-OSR entry just clear the code in order to proceed |
- // sharing literals. |
+ // Just clear the code in order to continue sharing literals. |
code_map->set(src + kCachedCodeOffset, heap->empty_weak_cell(), |
SKIP_WRITE_BARRIER); |
} |
- |
- // Keep the src entry by copying it to the dst entry. |
- if (dst != src) { |
- code_map->set(dst + kContextOffset, code_map->get(src + kContextOffset)); |
- code_map->set(dst + kCachedCodeOffset, |
- code_map->get(src + kCachedCodeOffset)); |
- code_map->set(dst + kLiteralsOffset, |
- code_map->get(src + kLiteralsOffset)); |
- code_map->set(dst + kOsrAstIdOffset, |
- code_map->get(src + kOsrAstIdOffset)); |
- } |
- dst += kEntryLength; |
} |
- if (dst != length) { |
- // Always trim even when array is cleared because of heap verifier. |
- heap->RightTrimFixedArray(code_map, length - dst); |
- if (code_map->length() == kEntriesStart) { |
- ClearOptimizedCodeMap(); |
- } |
+ |
+ if (!found) { |
+ // We didn't find the code in here. It must be osr'd code. |
+ isolate->EvictOSROptimizedCode(optimized_code, reason); |
} |
} |
@@ -14076,19 +14059,15 @@ void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { |
} |
} |
- |
-int SharedFunctionInfo::SearchOptimizedCodeMapEntry(Context* native_context, |
- BailoutId osr_ast_id) { |
+int SharedFunctionInfo::SearchOptimizedCodeMapEntry(Context* native_context) { |
DisallowHeapAllocation no_gc; |
DCHECK(native_context->IsNativeContext()); |
if (!OptimizedCodeMapIsCleared()) { |
FixedArray* optimized_code_map = this->optimized_code_map(); |
int length = optimized_code_map->length(); |
- Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt()); |
for (int i = kEntriesStart; i < length; i += kEntryLength) { |
if (WeakCell::cast(optimized_code_map->get(i + kContextOffset)) |
- ->value() == native_context && |
- optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) { |
+ ->value() == native_context) { |
return i; |
} |
} |
@@ -14111,7 +14090,16 @@ void SharedFunctionInfo::ClearCodeFromOptimizedCodeMap() { |
CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( |
Context* native_context, BailoutId osr_ast_id) { |
CodeAndLiterals result = {nullptr, nullptr}; |
- int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); |
+ if (!osr_ast_id.IsNone()) { |
+ Code* code; |
+ LiteralsArray* literals; |
+ native_context->SearchOptimizedCodeMap(this, osr_ast_id, &code, &literals); |
+ result = {code, literals}; |
+ return result; |
+ } |
+ |
+ DCHECK(osr_ast_id.IsNone()); |
+ int entry = SearchOptimizedCodeMapEntry(native_context); |
if (entry != kNotFound) { |
FixedArray* code_map = optimized_code_map(); |
DCHECK_LE(entry + kEntryLength, code_map->length()); |