Commit 9fd5261d authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[interpreter] Make optimized code map more flexible.

This relaxes the constraints of the optimized code map in order to be
able to update existing entries. It also simplifies the interface a
little bit. We can now insert an entry for a newly allocated literals
array together with previously cached context-independent code.

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/1753213002

Cr-Commit-Position: refs/heads/master@{#34427}
parent ca6d0b1e
......@@ -1373,9 +1373,11 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
result->set_literals(*literals);
// Cache context-specific literals.
MaybeHandle<Code> code;
if (cached.code != nullptr) code = handle(cached.code);
Handle<Context> native_context(context->native_context());
SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context,
literals);
SharedFunctionInfo::AddToOptimizedCodeMap(info, native_context, code,
literals, BailoutId::None());
}
return result;
......
......@@ -6019,26 +6019,6 @@ bool SharedFunctionInfo::OptimizedCodeMapIsCleared() const {
}
// static
void SharedFunctionInfo::AddToOptimizedCodeMap(
Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
Handle<Code> code, Handle<LiteralsArray> literals, BailoutId osr_ast_id) {
AddToOptimizedCodeMapInternal(shared, native_context, code, literals,
osr_ast_id);
}
// static
void SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(
Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
Handle<LiteralsArray> literals) {
Isolate* isolate = shared->GetIsolate();
Handle<Oddball> undefined = isolate->factory()->undefined_value();
AddToOptimizedCodeMapInternal(shared, native_context, undefined, literals,
BailoutId::None());
}
bool JSFunction::IsOptimized() {
return code()->kind() == Code::OPTIMIZED_FUNCTION;
}
......
......@@ -12301,17 +12301,15 @@ void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap(
}
}
void SharedFunctionInfo::AddToOptimizedCodeMapInternal(
// static
void SharedFunctionInfo::AddToOptimizedCodeMap(
Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
Handle<HeapObject> code, Handle<LiteralsArray> literals,
MaybeHandle<Code> code, Handle<LiteralsArray> literals,
BailoutId osr_ast_id) {
Isolate* isolate = shared->GetIsolate();
if (isolate->serializer_enabled()) return;
DCHECK(*code == isolate->heap()->undefined_value() ||
!shared->SearchOptimizedCodeMap(*native_context, osr_ast_id).code);
DCHECK(*code == isolate->heap()->undefined_value() ||
Code::cast(*code)->kind() == Code::OPTIMIZED_FUNCTION);
DCHECK(code.is_null() ||
code.ToHandleChecked()->kind() == Code::OPTIMIZED_FUNCTION);
DCHECK(native_context->IsNativeContext());
STATIC_ASSERT(kEntryLength == 4);
Handle<FixedArray> new_code_map;
......@@ -12326,15 +12324,10 @@ void SharedFunctionInfo::AddToOptimizedCodeMapInternal(
Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate);
entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id);
if (entry > kSharedCodeIndex) {
// Found an existing context-specific entry. If the user provided valid
// code, it must not contain any code.
DCHECK(code->IsUndefined() ||
WeakCell::cast(old_code_map->get(entry + kCachedCodeOffset))
->cleared());
// Just set the code and literals to the entry.
if (!code->IsUndefined()) {
Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code);
// Just set the code and literals of the entry.
if (!code.is_null()) {
Handle<WeakCell> code_cell =
isolate->factory()->NewWeakCell(code.ToHandleChecked());
old_code_map->set(entry + kCachedCodeOffset, *code_cell);
}
Handle<WeakCell> literals_cell =
......@@ -12367,9 +12360,9 @@ void SharedFunctionInfo::AddToOptimizedCodeMapInternal(
}
}
Handle<WeakCell> code_cell = code->IsUndefined()
? isolate->factory()->empty_weak_cell()
: isolate->factory()->NewWeakCell(code);
Handle<WeakCell> code_cell =
code.is_null() ? isolate->factory()->empty_weak_cell()
: isolate->factory()->NewWeakCell(code.ToHandleChecked());
Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals);
WeakCell* context_cell = native_context->self_weak_cell();
......
......@@ -6661,22 +6661,17 @@ class SharedFunctionInfo: public HeapObject {
// Trims the optimized code map after entries have been removed.
void TrimOptimizedCodeMap(int shrink_by);
// Add a new entry to the optimized code map for context-independent code.
// Add or update entry in the optimized code map for context-independent code.
static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
Handle<Code> code);
// Add a new entry to the optimized code map for context-dependent code.
inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
Handle<Context> native_context,
Handle<Code> code,
Handle<LiteralsArray> literals,
BailoutId osr_ast_id);
// We may already have cached the code, but want to store literals in the
// cache.
inline static void AddLiteralsToOptimizedCodeMap(
Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
Handle<LiteralsArray> literals);
// Add or update entry in the optimized code map for context-dependent code.
// If {code} is not given, then an existing entry's code won't be overwritten.
static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
Handle<Context> native_context,
MaybeHandle<Code> code,
Handle<LiteralsArray> literals,
BailoutId osr_ast_id);
// Set up the link between shared function info and the script. The shared
// function info is added to the list on the script.
......@@ -7288,13 +7283,6 @@ class SharedFunctionInfo: public HeapObject {
int SearchOptimizedCodeMapEntry(Context* native_context,
BailoutId osr_ast_id);
// If code is undefined, then existing code won't be overwritten.
static void AddToOptimizedCodeMapInternal(Handle<SharedFunctionInfo> shared,
Handle<Context> native_context,
Handle<HeapObject> code,
Handle<LiteralsArray> literals,
BailoutId osr_ast_id);
DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
};
......
......@@ -547,10 +547,6 @@
'test-heap/TestCodeFlushingIncremental': [FAIL],
'test-heap/TestCodeFlushingIncrementalAbort': [PASS, ['mode == debug or dcheck_always_on == True', FAIL]],
# TODO(rmcilroy,4680): Check failed: fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft().
'test-compiler/OptimizedCodeSharing2': [FAIL],
'test-compiler/OptimizedCodeSharing3': [FAIL],
# TODO(rmcilroy,4689): Stack trace line number failures.
'test-run-jsexceptions/ThrowMessagePosition': [FAIL],
'test-api/TryCatchMixedNesting': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment