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( ...@@ -1368,8 +1368,8 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
// Cache context-specific literals. // Cache context-specific literals.
Handle<Context> native_context(context->native_context()); Handle<Context> native_context(context->native_context());
SharedFunctionInfo::AddToOptimizedCodeMap( SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context,
info, native_context, undefined_value(), literals, BailoutId::None()); literals);
} }
return result; return result;
......
...@@ -6136,6 +6136,26 @@ bool SharedFunctionInfo::OptimizedCodeMapIsCleared() const { ...@@ -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() { bool JSFunction::IsOptimized() {
return code()->kind() == Code::OPTIMIZED_FUNCTION; return code()->kind() == Code::OPTIMIZED_FUNCTION;
} }
......
...@@ -11989,7 +11989,7 @@ void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( ...@@ -11989,7 +11989,7 @@ void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap(
} }
void SharedFunctionInfo::AddToOptimizedCodeMap( void SharedFunctionInfo::AddToOptimizedCodeMapInternal(
Handle<SharedFunctionInfo> shared, Handle<Context> native_context, Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
Handle<HeapObject> code, Handle<LiteralsArray> literals, Handle<HeapObject> code, Handle<LiteralsArray> literals,
BailoutId osr_ast_id) { BailoutId osr_ast_id) {
...@@ -12013,16 +12013,19 @@ void SharedFunctionInfo::AddToOptimizedCodeMap( ...@@ -12013,16 +12013,19 @@ void SharedFunctionInfo::AddToOptimizedCodeMap(
Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate); Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate);
entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id); entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id);
if (entry > kSharedCodeIndex) { if (entry > kSharedCodeIndex) {
// Found an existing context-specific entry, it must not contain any code. // Found an existing context-specific entry. If the user provided valid
DCHECK(WeakCell::cast(old_code_map->get(entry + kCachedCodeOffset)) // code, it must not contain any code.
DCHECK(code->IsUndefined() ||
WeakCell::cast(old_code_map->get(entry + kCachedCodeOffset))
->cleared()); ->cleared());
// Just set the code and literals to the entry. // Just set the code and literals to the entry.
Handle<WeakCell> code_cell = code->IsUndefined() if (!code->IsUndefined()) {
? isolate->factory()->empty_weak_cell() Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code);
: isolate->factory()->NewWeakCell(code); old_code_map->set(entry + kCachedCodeOffset, *code_cell);
}
Handle<WeakCell> literals_cell = Handle<WeakCell> literals_cell =
isolate->factory()->NewWeakCell(literals); isolate->factory()->NewWeakCell(literals);
old_code_map->set(entry + kCachedCodeOffset, *code_cell);
old_code_map->set(entry + kLiteralsOffset, *literals_cell); old_code_map->set(entry + kLiteralsOffset, *literals_cell);
return; return;
} }
......
...@@ -6509,14 +6509,19 @@ class SharedFunctionInfo: public HeapObject { ...@@ -6509,14 +6509,19 @@ class SharedFunctionInfo: public HeapObject {
Handle<Code> code); Handle<Code> code);
// Add a new entry to the optimized code map for context-dependent 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 inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
// the entry just maps |native_context, osr_ast_id| pair to |literals| array.
static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
Handle<Context> native_context, Handle<Context> native_context,
Handle<HeapObject> code, Handle<Code> code,
Handle<LiteralsArray> literals, Handle<LiteralsArray> literals,
BailoutId osr_ast_id); 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 // Set up the link between shared function info and the script. The shared
// function info is added to the list on the script. // function info is added to the list on the script.
static void SetScript(Handle<SharedFunctionInfo> shared, static void SetScript(Handle<SharedFunctionInfo> shared,
...@@ -7123,6 +7128,13 @@ class SharedFunctionInfo: public HeapObject { ...@@ -7123,6 +7128,13 @@ class SharedFunctionInfo: public HeapObject {
int SearchOptimizedCodeMapEntry(Context* native_context, int SearchOptimizedCodeMapEntry(Context* native_context,
BailoutId osr_ast_id); 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); 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