Commit 909f93d0 authored by mvstanton's avatar mvstanton Committed by Commit bot

Tighten the interface to the optimized code map

We either want to add code+literals to the map, or just literals.
A recent change in the structure of the map (it now uses WeakCells)
meant that we have to be more clear about what we want to do the right
thing.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#32761}
parent aa4a1abd
......@@ -1368,8 +1368,8 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
// Cache context-specific literals.
Handle<Context> native_context(context->native_context());
SharedFunctionInfo::AddToOptimizedCodeMap(
info, native_context, undefined_value(), literals, BailoutId::None());
SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context,
literals);
}
return result;
......
......@@ -6136,6 +6136,26 @@ 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;
}
......
......@@ -11989,7 +11989,7 @@ void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap(
}
void SharedFunctionInfo::AddToOptimizedCodeMap(
void SharedFunctionInfo::AddToOptimizedCodeMapInternal(
Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
Handle<HeapObject> code, Handle<LiteralsArray> literals,
BailoutId osr_ast_id) {
......@@ -12013,16 +12013,19 @@ void SharedFunctionInfo::AddToOptimizedCodeMap(
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, it must not contain any code.
DCHECK(WeakCell::cast(old_code_map->get(entry + kCachedCodeOffset))
// 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.
Handle<WeakCell> code_cell = code->IsUndefined()
? isolate->factory()->empty_weak_cell()
: isolate->factory()->NewWeakCell(code);
if (!code->IsUndefined()) {
Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code);
old_code_map->set(entry + kCachedCodeOffset, *code_cell);
}
Handle<WeakCell> literals_cell =
isolate->factory()->NewWeakCell(literals);
old_code_map->set(entry + kCachedCodeOffset, *code_cell);
old_code_map->set(entry + kLiteralsOffset, *literals_cell);
return;
}
......
......@@ -6509,14 +6509,19 @@ class SharedFunctionInfo: public HeapObject {
Handle<Code> code);
// Add a new entry to the optimized code map for context-dependent code.
// |code| is either a code object or an undefined value. In the latter case
// the entry just maps |native_context, osr_ast_id| pair to |literals| array.
static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
Handle<Context> native_context,
Handle<HeapObject> code,
Handle<LiteralsArray> literals,
BailoutId osr_ast_id);
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);
public:
// Set up the link between shared function info and the script. The shared
// function info is added to the list on the script.
static void SetScript(Handle<SharedFunctionInfo> shared,
......@@ -7123,6 +7128,13 @@ 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);
};
......
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