Commit 15b4804c authored by mvstanton's avatar mvstanton Committed by Commit bot

Add non-script SharedFunctionInfos to the Iterator.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#31597}
parent c9ab3606
......@@ -2161,6 +2161,11 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
share->set_compiler_hints(0);
share->set_opt_count_and_bailout_reason(0);
// Link into the list.
Handle<Object> new_noscript_list =
WeakFixedArray::Add(noscript_shared_function_infos(), share);
isolate()->heap()->set_noscript_shared_function_infos(*new_noscript_list);
return share;
}
......
......@@ -2808,6 +2808,8 @@ void Heap::CreateInitialObjects() {
set_weak_stack_trace_list(Smi::FromInt(0));
set_noscript_shared_function_infos(Smi::FromInt(0));
// Will be filled in by Interpreter::Initialize().
set_interpreter_table(
*interpreter::Interpreter::CreateUninitializedInterpreterTable(
......@@ -2850,6 +2852,7 @@ bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) {
case kDetachedContextsRootIndex:
case kWeakObjectToCodeTableRootIndex:
case kRetainedMapsRootIndex:
case kNoScriptSharedFunctionInfosRootIndex:
case kWeakStackTraceListRootIndex:
// Smi values
#define SMI_ENTRY(type, name, Name) case k##Name##RootIndex:
......
......@@ -187,6 +187,7 @@ namespace internal {
V(Object, weak_stack_trace_list, WeakStackTraceList) \
V(Object, code_stub_context, CodeStubContext) \
V(JSObject, code_stub_exports_object, CodeStubExportsObject) \
V(Object, noscript_shared_function_infos, NoScriptSharedFunctionInfos) \
V(FixedArray, interpreter_table, InterpreterTable) \
V(Map, bytecode_array_map, BytecodeArrayMap) \
V(BytecodeArray, empty_bytecode_array, EmptyBytecodeArray)
......@@ -1164,6 +1165,10 @@ class Heap {
roots_[kStringTableRootIndex] = value;
}
void SetRootNoScriptSharedFunctionInfos(Object* value) {
roots_[kNoScriptSharedFunctionInfosRootIndex] = value;
}
// Set the stack limit in the roots_ array. Some architectures generate
// code that looks here, because it is faster than loading from the static
// jslimit_/real_jslimit_ variable in the StackGuard.
......
......@@ -12102,9 +12102,8 @@ Script* Script::Iterator::Next() { return iterator_.Next<Script>(); }
SharedFunctionInfo::Iterator::Iterator(Isolate* isolate)
: script_iterator_(isolate), sfi_iterator_(NULL) {
NextScript();
}
: script_iterator_(isolate),
sfi_iterator_(isolate->heap()->noscript_shared_function_infos()) {}
bool SharedFunctionInfo::Iterator::NextScript() {
......@@ -12127,6 +12126,38 @@ SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() {
void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
Handle<Object> script_object) {
if (shared->script() == *script_object) return;
Isolate* isolate = shared->GetIsolate();
// Add shared function info to new script's list. If a collection occurs,
// the shared function info may be temporarily in two lists.
// This is okay because the gc-time processing of these lists can tolerate
// duplicates.
Handle<Object> list;
if (script_object->IsScript()) {
Handle<Script> script = Handle<Script>::cast(script_object);
list = handle(script->shared_function_infos(), isolate);
} else {
list = isolate->factory()->noscript_shared_function_infos();
}
#ifdef DEBUG
{
WeakFixedArray::Iterator iterator(*list);
SharedFunctionInfo* next;
while ((next = iterator.Next<SharedFunctionInfo>())) {
DCHECK_NE(next, *shared);
}
}
#endif // DEBUG
list = WeakFixedArray::Add(list, shared);
if (script_object->IsScript()) {
Handle<Script> script = Handle<Script>::cast(script_object);
script->set_shared_function_infos(*list);
} else {
isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list);
}
// Remove shared function info from old script's list.
if (shared->script()->IsScript()) {
Script* old_script = Script::cast(shared->script());
......@@ -12135,23 +12166,12 @@ void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
WeakFixedArray::cast(old_script->shared_function_infos());
list->Remove(shared);
}
} else {
// Remove shared function info from root array.
Object* list = isolate->heap()->noscript_shared_function_infos();
CHECK(WeakFixedArray::cast(list)->Remove(shared));
}
// Add shared function info to new script's list.
if (script_object->IsScript()) {
Handle<Script> script = Handle<Script>::cast(script_object);
Handle<Object> list(script->shared_function_infos(), shared->GetIsolate());
#ifdef DEBUG
{
WeakFixedArray::Iterator iterator(*list);
SharedFunctionInfo* next;
while ((next = iterator.Next<SharedFunctionInfo>())) {
DCHECK_NE(next, *shared);
}
}
#endif // DEBUG
list = WeakFixedArray::Add(list, shared);
script->set_shared_function_infos(*list);
}
// Finally set new script.
shared->set_script(*script_object);
}
......
......@@ -6855,9 +6855,7 @@ class SharedFunctionInfo: public HeapObject {
void ResetForNewContext(int new_ic_age);
// Iterate over all shared function infos that are created from a script.
// That excludes shared function infos created for API functions and C++
// builtins.
// Iterate over all shared function infos.
class Iterator {
public:
explicit Iterator(Isolate* isolate);
......
......@@ -6227,18 +6227,7 @@ TEST(SharedFunctionInfoIterator) {
HeapIterator it(heap);
for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) {
if (!obj->IsSharedFunctionInfo()) continue;
// Shared function infos without a script (API functions or C++ builtins)
// are not returned by the iterator because they are not created from a
// script. They are not interesting for type feedback vector anyways.
// TODO(mvstanton): There are builtins that use type feedback vectors,
// consider adding these to the iterator.
SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
if (shared->script()->IsUndefined()) {
CHECK(shared->native() || shared->feedback_vector()->is_empty());
} else {
sfi_count++;
}
sfi_count++;
}
}
......
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