Skip to content

Commit 39e2d97

Browse files
LeszekSwirskiCommit Bot
authored andcommitted
[sfi] Replace start/end position with UncompiledData
Add new types for function data for SharedFunctionInfo, for uncompiled functions. UncompiledData holds start/end positions, allowing us to remove these fields from SFI. Uncompiled functions with pre-parsed scope data now hold an UncompiledDataWithScope that has a pointer to PreParsedScopeData -- this allows us to also remove the start/end pos from PreParsedScopeData. Bug: chromium:818642 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: I56f3c4e62cbf38929babac734a332709f12a8202 Reviewed-on: https://chromium-review.googlesource.com/1126381 Commit-Queue: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Reviewed-by: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/master@{#54319}
1 parent 43744b9 commit 39e2d97

30 files changed

+808
-454
lines changed

src/api.cc

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,33 @@ StartupData SnapshotCreator::CreateBlob(
742742

743743
isolate->heap()->read_only_space()->ClearStringPaddingIfNeeded();
744744

745+
if (function_code_handling == FunctionCodeHandling::kClear) {
746+
// Clear out re-compilable data from all shared function infos. Any
747+
// JSFunctions using these SFIs will have their code pointers reset by the
748+
// partial serializer.
749+
//
750+
// We have to iterate the heap and collect handles to each clearable SFI,
751+
// before we disable allocation, since we have to allocate UncompiledDatas
752+
// to be able to recompile them.
753+
i::HandleScope scope(isolate);
754+
std::vector<i::Handle<i::SharedFunctionInfo>> sfis_to_clear;
755+
756+
i::HeapIterator heap_iterator(isolate->heap());
757+
while (i::HeapObject* current_obj = heap_iterator.next()) {
758+
if (current_obj->IsSharedFunctionInfo()) {
759+
i::SharedFunctionInfo* shared =
760+
i::SharedFunctionInfo::cast(current_obj);
761+
if (shared->CanDiscardCompiled()) {
762+
sfis_to_clear.emplace_back(shared, isolate);
763+
}
764+
}
765+
}
766+
i::AllowHeapAllocation allocate_for_discard;
767+
for (i::Handle<i::SharedFunctionInfo> shared : sfis_to_clear) {
768+
i::SharedFunctionInfo::DiscardCompiled(isolate, shared);
769+
}
770+
}
771+
745772
i::DisallowHeapAllocation no_gc_from_here_on;
746773

747774
int num_contexts = num_additional_contexts + 1;
@@ -778,19 +805,12 @@ StartupData SnapshotCreator::CreateBlob(
778805
i::ReadOnlyRoots(isolate).undefined_value());
779806
fun->set_code(isolate->builtins()->builtin(i::Builtins::kCompileLazy));
780807
}
781-
}
782-
783-
// Clear out re-compilable data from all shared function infos. Any
784-
// JSFunctions using these SFIs will have their code pointers reset by the
785-
// partial serializer.
786-
if (current_obj->IsSharedFunctionInfo() &&
787-
function_code_handling == FunctionCodeHandling::kClear) {
788-
i::SharedFunctionInfo* shared = i::SharedFunctionInfo::cast(current_obj);
789-
if (shared->CanFlushCompiled()) {
790-
shared->FlushCompiled();
808+
if (function_code_handling == FunctionCodeHandling::kClear) {
809+
DCHECK(fun->shared()->HasWasmExportedFunctionData() ||
810+
fun->shared()->HasBuiltinId() ||
811+
fun->shared()->IsApiFunction() ||
812+
fun->shared()->HasUncompiledDataWithoutPreParsedScope());
791813
}
792-
DCHECK(shared->HasWasmExportedFunctionData() || shared->HasBuiltinId() ||
793-
shared->IsApiFunction());
794814
}
795815
}
796816

src/bootstrapper.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,6 @@ Handle<JSFunction> Genesis::CreateEmptyFunction() {
617617
script->set_type(Script::TYPE_NATIVE);
618618
Handle<WeakFixedArray> infos = factory()->NewWeakFixedArray(2);
619619
script->set_shared_function_infos(*infos);
620-
// TODO(cbruni): fix position information here.
621-
empty_function->shared()->set_raw_start_position(0);
622-
empty_function->shared()->set_raw_end_position(source->length());
623620
empty_function->shared()->set_scope_info(*scope_info);
624621
empty_function->shared()->set_function_literal_id(1);
625622
empty_function->shared()->DontAdaptArguments();

src/code-stub-assembler.cc

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11983,18 +11983,24 @@ TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
1198311983
TNode<Int32T> data_type = LoadInstanceType(CAST(sfi_data));
1198411984

1198511985
int32_t case_values[] = {BYTECODE_ARRAY_TYPE,
11986-
WASM_EXPORTED_FUNCTION_DATA_TYPE, FIXED_ARRAY_TYPE,
11987-
TUPLE2_TYPE, FUNCTION_TEMPLATE_INFO_TYPE};
11986+
WASM_EXPORTED_FUNCTION_DATA_TYPE,
11987+
FIXED_ARRAY_TYPE,
11988+
UNCOMPILED_DATA_WITHOUT_PRE_PARSED_SCOPE_TYPE,
11989+
UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_TYPE,
11990+
FUNCTION_TEMPLATE_INFO_TYPE};
1198811991
Label check_is_bytecode_array(this);
1198911992
Label check_is_exported_function_data(this);
1199011993
Label check_is_fixed_array(this);
11991-
Label check_is_pre_parsed_scope_data(this);
11994+
Label check_is_uncompiled_data_without_pre_parsed_scope(this);
11995+
Label check_is_uncompiled_data_with_pre_parsed_scope(this);
1199211996
Label check_is_function_template_info(this);
1199311997
Label check_is_interpreter_data(this);
11994-
Label* case_labels[] = {
11995-
&check_is_bytecode_array, &check_is_exported_function_data,
11996-
&check_is_fixed_array, &check_is_pre_parsed_scope_data,
11997-
&check_is_function_template_info};
11998+
Label* case_labels[] = {&check_is_bytecode_array,
11999+
&check_is_exported_function_data,
12000+
&check_is_fixed_array,
12001+
&check_is_uncompiled_data_without_pre_parsed_scope,
12002+
&check_is_uncompiled_data_with_pre_parsed_scope,
12003+
&check_is_function_template_info};
1199812004
STATIC_ASSERT(arraysize(case_values) == arraysize(case_labels));
1199912005
Switch(data_type, &check_is_interpreter_data, case_values, case_labels,
1200012006
arraysize(case_labels));
@@ -12017,8 +12023,11 @@ TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
1201712023
sfi_code = HeapConstant(BUILTIN_CODE(isolate(), InstantiateAsmJs));
1201812024
Goto(&done);
1201912025

12020-
// IsPreParsedScopeData: Compile lazy
12021-
BIND(&check_is_pre_parsed_scope_data);
12026+
// IsUncompiledDataWithPreParsedScope | IsUncompiledDataWithoutPreParsedScope:
12027+
// Compile lazy
12028+
BIND(&check_is_uncompiled_data_with_pre_parsed_scope);
12029+
Goto(&check_is_uncompiled_data_without_pre_parsed_scope);
12030+
BIND(&check_is_uncompiled_data_without_pre_parsed_scope);
1202212031
DCHECK(!Builtins::IsLazy(Builtins::kCompileLazy));
1202312032
sfi_code = HeapConstant(BUILTIN_CODE(isolate(), CompileLazy));
1202412033
Goto(if_compile_lazy ? if_compile_lazy : &done);

src/code-stub-assembler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
7777
V(Tuple3Map, tuple3_map, Tuple3Map) \
7878
V(ArrayBoilerplateDescriptionMap, array_boilerplate_description_map, \
7979
ArrayBoilerplateDescriptionMap) \
80+
V(UncompiledDataWithoutPreParsedScopeMap, \
81+
uncompiled_data_without_pre_parsed_scope_map, \
82+
UncompiledDataWithoutPreParsedScopeMap) \
83+
V(UncompiledDataWithPreParsedScopeMap, \
84+
uncompiled_data_with_pre_parsed_scope_map, \
85+
UncompiledDataWithPreParsedScopeMap) \
8086
V(UndefinedValue, undefined_value, Undefined) \
8187
V(WeakCellMap, weak_cell_map, WeakCellMap) \
8288
V(WeakFixedArrayMap, weak_fixed_array_map, WeakFixedArrayMap)

src/compiler.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,14 +1087,11 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
10871087
}
10881088

10891089
if (FLAG_preparser_scope_analysis) {
1090-
if (shared_info->HasPreParsedScopeData()) {
1091-
Handle<PreParsedScopeData> data(
1092-
PreParsedScopeData::cast(shared_info->preparsed_scope_data()),
1093-
isolate);
1094-
parse_info.consumed_preparsed_scope_data()->SetData(isolate, data);
1095-
// After we've compiled the function, we don't need data about its
1096-
// skippable functions any more.
1097-
shared_info->ClearPreParsedScopeData();
1090+
if (shared_info->HasUncompiledDataWithPreParsedScope()) {
1091+
parse_info.consumed_preparsed_scope_data()->SetData(
1092+
isolate, handle(shared_info->uncompiled_data_with_pre_parsed_scope()
1093+
->pre_parsed_scope_data(),
1094+
isolate));
10981095
}
10991096
}
11001097

src/compiler/types.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ Type::bitset BitsetType::Lub(HeapObjectType const& type) {
295295
case MODULE_TYPE:
296296
case MODULE_INFO_ENTRY_TYPE:
297297
case CELL_TYPE:
298+
case UNCOMPILED_DATA_WITHOUT_PRE_PARSED_SCOPE_TYPE:
299+
case UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_TYPE:
298300
return kOtherInternal;
299301

300302
// Remaining instance types are unsupported for now. If any of them do

src/debug/liveedit.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,9 @@ void UpdatePositions(Isolate* isolate, Handle<SharedFunctionInfo> sfi,
974974
int new_end_position = LiveEdit::TranslatePosition(diffs, sfi->EndPosition());
975975
int new_function_token_position =
976976
LiveEdit::TranslatePosition(diffs, sfi->function_token_position());
977-
978-
sfi->set_raw_start_position(new_start_position);
979-
sfi->set_raw_end_position(new_end_position);
980-
if (sfi->scope_info()->HasPositionInfo()) {
981-
sfi->scope_info()->SetPositionInfo(new_start_position, new_end_position);
982-
}
983-
sfi->SetFunctionTokenPosition(new_function_token_position);
977+
sfi->SetPosition(new_start_position, new_end_position);
978+
sfi->SetFunctionTokenPosition(new_function_token_position,
979+
new_start_position);
984980
if (sfi->HasBytecodeArray()) {
985981
TranslateSourcePositionTable(handle(sfi->GetBytecodeArray(), isolate),
986982
diffs);
@@ -1066,7 +1062,9 @@ void LiveEdit::PatchScript(Isolate* isolate, Handle<Script> script,
10661062
new_script_sfis->Set(mapping.second->function_literal_id(),
10671063
HeapObjectReference::Weak(*sfi));
10681064

1069-
if (sfi->HasPreParsedScopeData()) sfi->ClearPreParsedScopeData();
1065+
if (sfi->HasUncompiledDataWithPreParsedScope()) {
1066+
sfi->ClearPreParsedScopeData();
1067+
}
10701068

10711069
for (auto& js_function : data->js_functions) {
10721070
js_function->set_feedback_cell(*isolate->factory()->many_closures_cell());

src/heap/factory.cc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,32 @@ Handle<PreParsedScopeData> Factory::NewPreParsedScopeData() {
24952495
return result;
24962496
}
24972497

2498+
Handle<UncompiledDataWithoutPreParsedScope>
2499+
Factory::NewUncompiledDataWithoutPreParsedScope(int32_t start_position,
2500+
int32_t end_position) {
2501+
Handle<UncompiledDataWithoutPreParsedScope> result(
2502+
UncompiledDataWithoutPreParsedScope::cast(
2503+
New(uncompiled_data_without_pre_parsed_scope_map(), TENURED)),
2504+
isolate());
2505+
result->set_start_position(start_position);
2506+
result->set_end_position(end_position);
2507+
return result;
2508+
}
2509+
2510+
Handle<UncompiledDataWithPreParsedScope>
2511+
Factory::NewUncompiledDataWithPreParsedScope(
2512+
int32_t start_position, int32_t end_position,
2513+
Handle<PreParsedScopeData> pre_parsed_scope_data) {
2514+
Handle<UncompiledDataWithPreParsedScope> result(
2515+
UncompiledDataWithPreParsedScope::cast(
2516+
New(uncompiled_data_with_pre_parsed_scope_map(), TENURED)),
2517+
isolate());
2518+
result->set_start_position(start_position);
2519+
result->set_end_position(end_position);
2520+
result->set_pre_parsed_scope_data(*pre_parsed_scope_data);
2521+
return result;
2522+
}
2523+
24982524
Handle<JSObject> Factory::NewExternal(void* value) {
24992525
Handle<Foreign> foreign = NewForeign(reinterpret_cast<Address>(value));
25002526
Handle<JSObject> external = NewJSObjectFromMap(external_map());
@@ -3470,8 +3496,6 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
34703496
share->set_length(0);
34713497
share->set_internal_formal_parameter_count(0);
34723498
share->set_expected_nof_properties(0);
3473-
share->set_raw_start_position_and_type(0);
3474-
share->set_raw_end_position(0);
34753499
share->set_raw_function_token_offset(0);
34763500
// All flags default to false or 0.
34773501
share->set_flags(0);

src/heap/factory.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class RegExpMatchInfo;
5151
class ScriptContextTable;
5252
class StoreHandler;
5353
class TemplateObjectDescription;
54+
class UncompiledDataWithoutPreParsedScope;
55+
class UncompiledDataWithPreParsedScope;
5456
class WasmExportedFunctionData;
5557
struct SourceRange;
5658
template <typename T>
@@ -717,6 +719,13 @@ class V8_EXPORT_PRIVATE Factory {
717719

718720
Handle<PreParsedScopeData> NewPreParsedScopeData();
719721

722+
Handle<UncompiledDataWithoutPreParsedScope>
723+
NewUncompiledDataWithoutPreParsedScope(int32_t start_position,
724+
int32_t end_position);
725+
726+
Handle<UncompiledDataWithPreParsedScope> NewUncompiledDataWithPreParsedScope(
727+
int32_t start_position, int32_t end_position, Handle<PreParsedScopeData>);
728+
720729
// Create an External object for V8's external API.
721730
Handle<JSObject> NewExternal(void* value);
722731

0 commit comments

Comments
 (0)