Skip to content

Commit 0c32c7f

Browse files
mralephCommit Queue
authored andcommitted
Revert "[vm] Remove quadratic-time Script::FindLibrary."
This reverts commit 262efd8. Reason for revert: AOT builds in flutter-profile mode are failing with: Unexpected object (Class with illegal cid, full-aot): 0x7f0f0426d321 Library:'package:flutter/src/widgets/overflow_bar.dart' Class: :: Original change's description: > [vm] Remove quadratic-time Script::FindLibrary. > > TEST=ci > Change-Id: Ic54c6ed65ceeca7af797a70cd68f495aa6b105c4 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284548 > Commit-Queue: Ryan Macnak <[email protected]> > Reviewed-by: Ben Konyi <[email protected]> Change-Id: I2a1e824fbe31a2c9053e556a63e07c66aa3face1 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285261 Commit-Queue: Rubber Stamper <[email protected]> Auto-Submit: Slava Egorov <[email protected]> Bot-Commit: Rubber Stamper <[email protected]>
1 parent 262efd8 commit 0c32c7f

File tree

7 files changed

+46
-36
lines changed

7 files changed

+46
-36
lines changed

runtime/vm/compiler/runtime_offsets_extracted.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 12;
663663
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 20;
664664
static constexpr dart::compiler::target::word RecordType_InstanceSize = 28;
665665
static constexpr dart::compiler::target::word RegExp_InstanceSize = 60;
666-
static constexpr dart::compiler::target::word Script_InstanceSize = 56;
666+
static constexpr dart::compiler::target::word Script_InstanceSize = 48;
667667
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
668668
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 4;
669669
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -1349,7 +1349,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 24;
13491349
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 40;
13501350
static constexpr dart::compiler::target::word RecordType_InstanceSize = 56;
13511351
static constexpr dart::compiler::target::word RegExp_InstanceSize = 120;
1352-
static constexpr dart::compiler::target::word Script_InstanceSize = 88;
1352+
static constexpr dart::compiler::target::word Script_InstanceSize = 80;
13531353
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
13541354
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 8;
13551355
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -2026,7 +2026,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 12;
20262026
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 20;
20272027
static constexpr dart::compiler::target::word RecordType_InstanceSize = 28;
20282028
static constexpr dart::compiler::target::word RegExp_InstanceSize = 60;
2029-
static constexpr dart::compiler::target::word Script_InstanceSize = 56;
2029+
static constexpr dart::compiler::target::word Script_InstanceSize = 48;
20302030
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
20312031
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 4;
20322032
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -2713,7 +2713,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 24;
27132713
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 40;
27142714
static constexpr dart::compiler::target::word RecordType_InstanceSize = 56;
27152715
static constexpr dart::compiler::target::word RegExp_InstanceSize = 120;
2716-
static constexpr dart::compiler::target::word Script_InstanceSize = 88;
2716+
static constexpr dart::compiler::target::word Script_InstanceSize = 80;
27172717
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
27182718
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 8;
27192719
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -4763,7 +4763,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 12;
47634763
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 20;
47644764
static constexpr dart::compiler::target::word RecordType_InstanceSize = 28;
47654765
static constexpr dart::compiler::target::word RegExp_InstanceSize = 60;
4766-
static constexpr dart::compiler::target::word Script_InstanceSize = 56;
4766+
static constexpr dart::compiler::target::word Script_InstanceSize = 48;
47674767
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
47684768
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 4;
47694769
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -5450,7 +5450,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 24;
54505450
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 40;
54515451
static constexpr dart::compiler::target::word RecordType_InstanceSize = 56;
54525452
static constexpr dart::compiler::target::word RegExp_InstanceSize = 120;
5453-
static constexpr dart::compiler::target::word Script_InstanceSize = 88;
5453+
static constexpr dart::compiler::target::word Script_InstanceSize = 80;
54545454
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
54555455
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 8;
54565456
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -6799,7 +6799,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 24;
67996799
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 24;
68006800
static constexpr dart::compiler::target::word RecordType_InstanceSize = 56;
68016801
static constexpr dart::compiler::target::word RegExp_InstanceSize = 120;
6802-
static constexpr dart::compiler::target::word Script_InstanceSize = 88;
6802+
static constexpr dart::compiler::target::word Script_InstanceSize = 80;
68036803
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
68046804
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 8;
68056805
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -8147,7 +8147,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 24;
81478147
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 24;
81488148
static constexpr dart::compiler::target::word RecordType_InstanceSize = 56;
81498149
static constexpr dart::compiler::target::word RegExp_InstanceSize = 120;
8150-
static constexpr dart::compiler::target::word Script_InstanceSize = 88;
8150+
static constexpr dart::compiler::target::word Script_InstanceSize = 80;
81518151
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
81528152
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 8;
81538153
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -10852,7 +10852,7 @@ static constexpr dart::compiler::target::word Pointer_InstanceSize = 24;
1085210852
static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 24;
1085310853
static constexpr dart::compiler::target::word RecordType_InstanceSize = 56;
1085410854
static constexpr dart::compiler::target::word RegExp_InstanceSize = 120;
10855-
static constexpr dart::compiler::target::word Script_InstanceSize = 88;
10855+
static constexpr dart::compiler::target::word Script_InstanceSize = 80;
1085610856
static constexpr dart::compiler::target::word SendPort_InstanceSize = 24;
1085710857
static constexpr dart::compiler::target::word Sentinel_InstanceSize = 8;
1085810858
static constexpr dart::compiler::target::word SingleTargetCache_InstanceSize =
@@ -11601,7 +11601,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 12;
1160111601
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 20;
1160211602
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 28;
1160311603
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 60;
11604-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 48;
11604+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 40;
1160511605
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1160611606
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 4;
1160711607
static constexpr dart::compiler::target::word
@@ -12358,7 +12358,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 24;
1235812358
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 40;
1235912359
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 56;
1236012360
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 120;
12361-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 80;
12361+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 72;
1236212362
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1236312363
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 8;
1236412364
static constexpr dart::compiler::target::word
@@ -13119,7 +13119,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 24;
1311913119
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 40;
1312013120
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 56;
1312113121
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 120;
13122-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 80;
13122+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 72;
1312313123
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1312413124
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 8;
1312513125
static constexpr dart::compiler::target::word
@@ -15390,7 +15390,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 12;
1539015390
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 20;
1539115391
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 28;
1539215392
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 60;
15393-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 48;
15393+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 40;
1539415394
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1539515395
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 4;
1539615396
static constexpr dart::compiler::target::word
@@ -16148,7 +16148,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 24;
1614816148
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 40;
1614916149
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 56;
1615016150
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 120;
16151-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 80;
16151+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 72;
1615216152
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1615316153
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 8;
1615416154
static constexpr dart::compiler::target::word
@@ -16893,7 +16893,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 12;
1689316893
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 12;
1689416894
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 28;
1689516895
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 60;
16896-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 48;
16896+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 40;
1689716897
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1689816898
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 4;
1689916899
static constexpr dart::compiler::target::word
@@ -17641,7 +17641,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 24;
1764117641
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 24;
1764217642
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 56;
1764317643
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 120;
17644-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 80;
17644+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 72;
1764517645
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1764617646
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 8;
1764717647
static constexpr dart::compiler::target::word
@@ -18393,7 +18393,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 24;
1839318393
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 24;
1839418394
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 56;
1839518395
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 120;
18396-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 80;
18396+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 72;
1839718397
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
1839818398
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 8;
1839918399
static constexpr dart::compiler::target::word
@@ -20637,7 +20637,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 12;
2063720637
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 12;
2063820638
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 28;
2063920639
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 60;
20640-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 48;
20640+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 40;
2064120641
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
2064220642
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 4;
2064320643
static constexpr dart::compiler::target::word
@@ -21386,7 +21386,7 @@ static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 24;
2138621386
static constexpr dart::compiler::target::word AOT_ReceivePort_InstanceSize = 24;
2138721387
static constexpr dart::compiler::target::word AOT_RecordType_InstanceSize = 56;
2138821388
static constexpr dart::compiler::target::word AOT_RegExp_InstanceSize = 120;
21389-
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 80;
21389+
static constexpr dart::compiler::target::word AOT_Script_InstanceSize = 72;
2139021390
static constexpr dart::compiler::target::word AOT_SendPort_InstanceSize = 24;
2139121391
static constexpr dart::compiler::target::word AOT_Sentinel_InstanceSize = 8;
2139221392
static constexpr dart::compiler::target::word

runtime/vm/kernel_loader.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) {
974974
}
975975

976976
library_helper.ReadUntilIncluding(LibraryHelper::kSourceUriIndex);
977-
Script& script =
977+
const Script& script =
978978
Script::Handle(Z, ScriptAt(library_helper.source_uri_index_));
979979

980980
library_helper.ReadUntilExcluding(LibraryHelper::kAnnotations);
@@ -1042,17 +1042,14 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) {
10421042
}
10431043

10441044
if (register_class) {
1045-
const GrowableObjectArray& used_scripts =
1046-
GrowableObjectArray::Handle(Z, library.used_scripts());
1047-
script.set_library(library);
1048-
used_scripts.Add(script);
1049-
10501045
helper_.SetOffset(library_index.SourceReferencesOffset());
10511046
intptr_t count = helper_.ReadUInt();
1047+
const GrowableObjectArray& used_scripts =
1048+
GrowableObjectArray::Handle(library.used_scripts());
1049+
Script& script = Script::Handle(Z);
10521050
for (intptr_t i = 0; i < count; i++) {
10531051
intptr_t uri_index = helper_.ReadUInt();
10541052
script = ScriptAt(uri_index);
1055-
script.set_library(library);
10561053
used_scripts.Add(script);
10571054
}
10581055
}

runtime/vm/object.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12651,10 +12651,6 @@ TokenPosition Script::MaxPosition() const {
1265112651
return TokenPosition::kNoSource;
1265212652
}
1265312653

12654-
void Script::set_library(const Library& value) const {
12655-
untag()->set_library(value.ptr());
12656-
}
12657-
1265812654
void Script::set_url(const String& value) const {
1265912655
untag()->set_url(value.ptr());
1266012656
}
@@ -12967,6 +12963,26 @@ const char* Script::ToCString() const {
1296712963
return OS::SCreate(Thread::Current()->zone(), "Script(%s)", name.ToCString());
1296812964
}
1296912965

12966+
LibraryPtr Script::FindLibrary() const {
12967+
Thread* thread = Thread::Current();
12968+
Zone* zone = thread->zone();
12969+
auto isolate_group = thread->isolate_group();
12970+
const GrowableObjectArray& libs = GrowableObjectArray::Handle(
12971+
zone, isolate_group->object_store()->libraries());
12972+
Library& lib = Library::Handle(zone);
12973+
Array& scripts = Array::Handle(zone);
12974+
for (intptr_t i = 0; i < libs.Length(); i++) {
12975+
lib ^= libs.At(i);
12976+
scripts = lib.LoadedScripts();
12977+
for (intptr_t j = 0; j < scripts.Length(); j++) {
12978+
if (scripts.At(j) == ptr()) {
12979+
return lib.ptr();
12980+
}
12981+
}
12982+
}
12983+
return Library::null();
12984+
}
12985+
1297012986
DictionaryIterator::DictionaryIterator(const Library& library)
1297112987
: array_(Array::Handle(library.dictionary())),
1297212988
// Last element in array is a Smi indicating the number of entries used.

runtime/vm/object.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4611,9 +4611,6 @@ class Field : public Object {
46114611

46124612
class Script : public Object {
46134613
public:
4614-
LibraryPtr library() const { return untag()->library(); }
4615-
void set_library(const Library& value) const;
4616-
46174614
StringPtr url() const { return untag()->url(); }
46184615
void set_url(const String& value) const;
46194616

@@ -4661,6 +4658,7 @@ class Script : public Object {
46614658

46624659
void set_debug_positions(const Array& value) const;
46634660

4661+
LibraryPtr FindLibrary() const;
46644662
StringPtr GetLine(intptr_t line_number, Heap::Space space = Heap::kNew) const;
46654663
StringPtr GetSnippet(intptr_t from_line,
46664664
intptr_t from_column,

runtime/vm/object_service.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ void Script::PrintJSONImpl(JSONStream* stream, bool ref) const {
499499
const String& uri = String::Handle(url());
500500
ASSERT(!uri.IsNull());
501501
const char* encoded_uri = String::EncodeIRI(uri);
502-
const Library& lib = Library::Handle(library());
502+
const Library& lib = Library::Handle(FindLibrary());
503503
if (lib.IsNull()) {
504504
jsobj.AddServiceId(*this);
505505
} else {

runtime/vm/raw_object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,6 @@ class alignas(8) UntaggedScript : public UntaggedObject {
15101510

15111511
COMPRESSED_POINTER_FIELD(StringPtr, url)
15121512
VISIT_FROM(url)
1513-
COMPRESSED_POINTER_FIELD(LibraryPtr, library)
15141513
COMPRESSED_POINTER_FIELD(StringPtr, resolved_url)
15151514
COMPRESSED_POINTER_FIELD(TypedDataPtr, line_starts)
15161515
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)

runtime/vm/source_report.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ bool SourceReport::ShouldFiltersIncludeScript(const Script& script) {
216216
if (library_filters_.IsNull()) return true;
217217
String& url = String::Handle(zone(), script.url());
218218
if (ShouldFiltersIncludeUrl(url)) return true;
219-
const Library& lib = Library::Handle(zone(), script.library());
219+
const Library& lib = Library::Handle(zone(), script.FindLibrary());
220220
url ^= lib.url();
221221
return ShouldFiltersIncludeUrl(url);
222222
}

0 commit comments

Comments
 (0)