OLD | NEW |
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 <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 12283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12294 if (!shared->OptimizedCodeMapIsCleared()) { | 12294 if (!shared->OptimizedCodeMapIsCleared()) { |
12295 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); | 12295 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); |
12296 // A collection may have occured and cleared the optimized code map in the | 12296 // A collection may have occured and cleared the optimized code map in the |
12297 // allocation above. | 12297 // allocation above. |
12298 if (!shared->OptimizedCodeMapIsCleared()) { | 12298 if (!shared->OptimizedCodeMapIsCleared()) { |
12299 shared->optimized_code_map()->set(kSharedCodeIndex, *cell); | 12299 shared->optimized_code_map()->set(kSharedCodeIndex, *cell); |
12300 } | 12300 } |
12301 } | 12301 } |
12302 } | 12302 } |
12303 | 12303 |
12304 | 12304 // static |
12305 void SharedFunctionInfo::AddToOptimizedCodeMapInternal( | 12305 void SharedFunctionInfo::AddToOptimizedCodeMap( |
12306 Handle<SharedFunctionInfo> shared, Handle<Context> native_context, | 12306 Handle<SharedFunctionInfo> shared, Handle<Context> native_context, |
12307 Handle<HeapObject> code, Handle<LiteralsArray> literals, | 12307 MaybeHandle<Code> code, Handle<LiteralsArray> literals, |
12308 BailoutId osr_ast_id) { | 12308 BailoutId osr_ast_id) { |
12309 Isolate* isolate = shared->GetIsolate(); | 12309 Isolate* isolate = shared->GetIsolate(); |
12310 if (isolate->serializer_enabled()) return; | 12310 if (isolate->serializer_enabled()) return; |
12311 DCHECK(*code == isolate->heap()->undefined_value() || | 12311 DCHECK(code.is_null() || |
12312 !shared->SearchOptimizedCodeMap(*native_context, osr_ast_id).code); | 12312 code.ToHandleChecked()->kind() == Code::OPTIMIZED_FUNCTION); |
12313 DCHECK(*code == isolate->heap()->undefined_value() || | |
12314 Code::cast(*code)->kind() == Code::OPTIMIZED_FUNCTION); | |
12315 DCHECK(native_context->IsNativeContext()); | 12313 DCHECK(native_context->IsNativeContext()); |
12316 STATIC_ASSERT(kEntryLength == 4); | 12314 STATIC_ASSERT(kEntryLength == 4); |
12317 Handle<FixedArray> new_code_map; | 12315 Handle<FixedArray> new_code_map; |
12318 int entry; | 12316 int entry; |
12319 | 12317 |
12320 if (shared->OptimizedCodeMapIsCleared()) { | 12318 if (shared->OptimizedCodeMapIsCleared()) { |
12321 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED); | 12319 new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED); |
12322 new_code_map->set(kSharedCodeIndex, *isolate->factory()->empty_weak_cell(), | 12320 new_code_map->set(kSharedCodeIndex, *isolate->factory()->empty_weak_cell(), |
12323 SKIP_WRITE_BARRIER); | 12321 SKIP_WRITE_BARRIER); |
12324 entry = kEntriesStart; | 12322 entry = kEntriesStart; |
12325 } else { | 12323 } else { |
12326 Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate); | 12324 Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate); |
12327 entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id); | 12325 entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id); |
12328 if (entry > kSharedCodeIndex) { | 12326 if (entry > kSharedCodeIndex) { |
12329 // Found an existing context-specific entry. If the user provided valid | 12327 // Just set the code and literals of the entry. |
12330 // code, it must not contain any code. | 12328 if (!code.is_null()) { |
12331 DCHECK(code->IsUndefined() || | 12329 Handle<WeakCell> code_cell = |
12332 WeakCell::cast(old_code_map->get(entry + kCachedCodeOffset)) | 12330 isolate->factory()->NewWeakCell(code.ToHandleChecked()); |
12333 ->cleared()); | |
12334 | |
12335 // Just set the code and literals to the entry. | |
12336 if (!code->IsUndefined()) { | |
12337 Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code); | |
12338 old_code_map->set(entry + kCachedCodeOffset, *code_cell); | 12331 old_code_map->set(entry + kCachedCodeOffset, *code_cell); |
12339 } | 12332 } |
12340 Handle<WeakCell> literals_cell = | 12333 Handle<WeakCell> literals_cell = |
12341 isolate->factory()->NewWeakCell(literals); | 12334 isolate->factory()->NewWeakCell(literals); |
12342 old_code_map->set(entry + kLiteralsOffset, *literals_cell); | 12335 old_code_map->set(entry + kLiteralsOffset, *literals_cell); |
12343 return; | 12336 return; |
12344 } | 12337 } |
12345 | 12338 |
12346 // Can we reuse an entry? | 12339 // Can we reuse an entry? |
12347 DCHECK(entry < kEntriesStart); | 12340 DCHECK(entry < kEntriesStart); |
(...skipping 12 matching lines...) Expand all Loading... |
12360 old_code_map, kEntryLength, TENURED); | 12353 old_code_map, kEntryLength, TENURED); |
12361 // TODO(mstarzinger): Temporary workaround. The allocation above might | 12354 // TODO(mstarzinger): Temporary workaround. The allocation above might |
12362 // have flushed the optimized code map and the copy we created is full of | 12355 // have flushed the optimized code map and the copy we created is full of |
12363 // holes. For now we just give up on adding the entry and pretend it got | 12356 // holes. For now we just give up on adding the entry and pretend it got |
12364 // flushed. | 12357 // flushed. |
12365 if (shared->OptimizedCodeMapIsCleared()) return; | 12358 if (shared->OptimizedCodeMapIsCleared()) return; |
12366 entry = old_code_map->length(); | 12359 entry = old_code_map->length(); |
12367 } | 12360 } |
12368 } | 12361 } |
12369 | 12362 |
12370 Handle<WeakCell> code_cell = code->IsUndefined() | 12363 Handle<WeakCell> code_cell = |
12371 ? isolate->factory()->empty_weak_cell() | 12364 code.is_null() ? isolate->factory()->empty_weak_cell() |
12372 : isolate->factory()->NewWeakCell(code); | 12365 : isolate->factory()->NewWeakCell(code.ToHandleChecked()); |
12373 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals); | 12366 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals); |
12374 WeakCell* context_cell = native_context->self_weak_cell(); | 12367 WeakCell* context_cell = native_context->self_weak_cell(); |
12375 | 12368 |
12376 new_code_map->set(entry + kContextOffset, context_cell); | 12369 new_code_map->set(entry + kContextOffset, context_cell); |
12377 new_code_map->set(entry + kCachedCodeOffset, *code_cell); | 12370 new_code_map->set(entry + kCachedCodeOffset, *code_cell); |
12378 new_code_map->set(entry + kLiteralsOffset, *literals_cell); | 12371 new_code_map->set(entry + kLiteralsOffset, *literals_cell); |
12379 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); | 12372 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); |
12380 | 12373 |
12381 #ifdef DEBUG | 12374 #ifdef DEBUG |
12382 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { | 12375 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { |
(...skipping 7394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19777 if (cell->value() != *new_value) { | 19770 if (cell->value() != *new_value) { |
19778 cell->set_value(*new_value); | 19771 cell->set_value(*new_value); |
19779 Isolate* isolate = cell->GetIsolate(); | 19772 Isolate* isolate = cell->GetIsolate(); |
19780 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19773 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19781 isolate, DependentCode::kPropertyCellChangedGroup); | 19774 isolate, DependentCode::kPropertyCellChangedGroup); |
19782 } | 19775 } |
19783 } | 19776 } |
19784 | 19777 |
19785 } // namespace internal | 19778 } // namespace internal |
19786 } // namespace v8 | 19779 } // namespace v8 |
OLD | NEW |