Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1ac34f1

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
[vm] Fix @pragma detection in KernelLoader.
Change-Id: If09f26a27f84bbed4841eb6d868aea38af564e4a Cq-Include-Trybots: luci.dart.try:vm-kernel-win-release-x64-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try Reviewed-on: https://dart-review.googlesource.com/68362 Reviewed-by: Alexander Markov <[email protected]>
1 parent 0986b2b commit 1ac34f1

7 files changed

+67
-19
lines changed

runtime/vm/clustered_snapshot.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ class KernelProgramInfoSerializationCluster : public SerializationCluster {
15671567
objects_.Add(info);
15681568

15691569
RawObject** from = info->from();
1570-
RawObject** to = info->to();
1570+
RawObject** to = info->to_snapshot(s->kind());
15711571
for (RawObject** p = from; p <= to; p++) {
15721572
s->Push(*p);
15731573
}
@@ -1588,7 +1588,7 @@ class KernelProgramInfoSerializationCluster : public SerializationCluster {
15881588
for (intptr_t i = 0; i < count; i++) {
15891589
RawKernelProgramInfo* info = objects_[i];
15901590
RawObject** from = info->from();
1591-
RawObject** to = info->to();
1591+
RawObject** to = info->to_snapshot(s->kind());
15921592
for (RawObject** p = from; p <= to; p++) {
15931593
s->WriteRef(*p);
15941594
}
@@ -1627,10 +1627,14 @@ class KernelProgramInfoDeserializationCluster : public DeserializationCluster {
16271627
KernelProgramInfo::InstanceSize(),
16281628
is_vm_object);
16291629
RawObject** from = info->from();
1630-
RawObject** to = info->to();
1630+
RawObject** to = info->to_snapshot(d->kind());
1631+
RawObject** end = info->to();
16311632
for (RawObject** p = from; p <= to; p++) {
16321633
*p = d->ReadRef();
16331634
}
1635+
for (RawObject** p = to + 1; p <= end; p++) {
1636+
*p = Object::null();
1637+
}
16341638
}
16351639
}
16361640
};

runtime/vm/kernel_loader.cc

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ KernelLoader::KernelLoader(Program* program)
182182
external_name_class_(Class::Handle(Z)),
183183
external_name_field_(Field::Handle(Z)),
184184
potential_natives_(GrowableObjectArray::Handle(Z)),
185-
potential_extension_libraries_(GrowableObjectArray::Handle(Z)) {
185+
potential_extension_libraries_(GrowableObjectArray::Handle(Z)),
186+
pragma_class_(Class::Handle(Z)) {
186187
if (!program->is_single_program()) {
187188
FATAL(
188189
"Trying to load a concatenated dill file at a time where that is "
@@ -283,6 +284,12 @@ void KernelLoader::InitializeFields() {
283284
Z,
284285
reader.ExternalDataFromTo(reader.offset(), reader.offset() + end_offset));
285286

287+
// Create a view of the constants table. The trailing ComponentIndex is
288+
// negligible in size.
289+
const ExternalTypedData& constants_table = ExternalTypedData::Handle(
290+
Z, reader.ExternalDataFromTo(program_->constant_table_offset(),
291+
program_->kernel_data_size()));
292+
286293
// Copy the canonical names into the VM's heap. Encode them as unsigned, so
287294
// the parent indexes are adjusted when extracted.
288295
reader.set_offset(program_->name_table_offset());
@@ -303,8 +310,9 @@ void KernelLoader::InitializeFields() {
303310
Z, reader.ExternalDataFromTo(program_->metadata_mappings_offset(),
304311
program_->string_table_offset()));
305312

306-
kernel_program_info_ = KernelProgramInfo::New(
307-
offsets, data, names, metadata_payloads, metadata_mappings, scripts);
313+
kernel_program_info_ =
314+
KernelProgramInfo::New(offsets, data, names, metadata_payloads,
315+
metadata_mappings, constants_table, scripts);
308316

309317
H.InitFromKernelProgramInfo(kernel_program_info_);
310318

@@ -335,7 +343,8 @@ KernelLoader::KernelLoader(const Script& script,
335343
external_name_class_(Class::Handle(Z)),
336344
external_name_field_(Field::Handle(Z)),
337345
potential_natives_(GrowableObjectArray::Handle(Z)),
338-
potential_extension_libraries_(GrowableObjectArray::Handle(Z)) {
346+
potential_extension_libraries_(GrowableObjectArray::Handle(Z)),
347+
pragma_class_(Class::Handle(Z)) {
339348
ASSERT(T.active_class_ == &active_class_);
340349
T.finalize_ = false;
341350

@@ -588,6 +597,7 @@ RawObject* KernelLoader::LoadProgram(bool process_pending_classes) {
588597
// c) update all scripts with the constants array
589598
ASSERT(kernel_program_info_.constants() == Array::null());
590599
kernel_program_info_.set_constants(constants);
600+
kernel_program_info_.set_constants_table(ExternalTypedData::Handle(Z));
591601

592602
NameIndex main = program_->main_method();
593603
if (main == -1) {
@@ -1335,7 +1345,6 @@ void KernelLoader::ReadProcedureAnnotations(intptr_t annotation_count,
13351345
*is_potential_native = false;
13361346
*has_pragma_annotation = false;
13371347
String& detected_name = String::Handle(Z);
1338-
Class& pragma_class = Class::Handle(Z, I->object_store()->pragma_class());
13391348
for (intptr_t i = 0; i < annotation_count; ++i) {
13401349
const intptr_t tag = helper_.PeekTag();
13411350
if (tag == kConstructorInvocation || tag == kConstConstructorInvocation) {
@@ -1361,10 +1370,8 @@ void KernelLoader::ReadProcedureAnnotations(intptr_t annotation_count,
13611370
// constants in the annotation list to later.
13621371
*is_potential_native = true;
13631372

1364-
if (program_ == nullptr) {
1365-
helper_.SkipExpression();
1366-
continue;
1367-
}
1373+
ASSERT(kernel_program_info_.constants_table() !=
1374+
ExternalTypedData::null());
13681375

13691376
// For pragma annotations, we seek into the constants table and peek
13701377
// into the Kernel representation of the constant.
@@ -1376,13 +1383,16 @@ void KernelLoader::ReadProcedureAnnotations(intptr_t annotation_count,
13761383

13771384
const intptr_t offset_in_constant_table = helper_.ReadUInt();
13781385

1379-
AlternativeReadingScope scope(&helper_.reader_,
1380-
program_->constant_table_offset());
1386+
AlternativeReadingScope scope(
1387+
&helper_.reader_,
1388+
&ExternalTypedData::Handle(Z,
1389+
kernel_program_info_.constants_table()),
1390+
0);
13811391

13821392
// Seek into the position within the constant table where we can inspect
13831393
// this constant's Kernel representation.
13841394
helper_.ReadUInt(); // skip constant table size
1385-
helper_.SetOffset(helper_.ReaderOffset() + offset_in_constant_table);
1395+
helper_.SkipBytes(offset_in_constant_table);
13861396
uint8_t tag = helper_.ReadTag();
13871397
if (tag == kInstanceConstant) {
13881398
*has_pragma_annotation =
@@ -1396,6 +1406,9 @@ void KernelLoader::ReadProcedureAnnotations(intptr_t annotation_count,
13961406
// Obtain `dart:_internal::ExternalName.name`.
13971407
EnsureExternalClassIsLookedUp();
13981408

1409+
// Obtain `dart:_internal::pragma`.
1410+
EnsurePragmaClassIsLookedUp();
1411+
13991412
const intptr_t constant_table_index = helper_.ReadUInt();
14001413
const Object& constant =
14011414
Object::Handle(constant_table.GetOrDie(constant_table_index));
@@ -1404,7 +1417,7 @@ void KernelLoader::ReadProcedureAnnotations(intptr_t annotation_count,
14041417
Instance::Handle(Instance::RawCast(constant.raw()));
14051418
*native_name =
14061419
String::RawCast(instance.GetField(external_name_field_));
1407-
} else if (constant.clazz() == pragma_class.raw()) {
1420+
} else if (constant.clazz() == pragma_class_.raw()) {
14081421
*has_pragma_annotation = true;
14091422
}
14101423
ASSERT(constant_table.Release().raw() == constant_table_array.raw());

runtime/vm/kernel_loader.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ class KernelLoader : public ValueObject {
273273
}
274274
}
275275

276+
void EnsurePragmaClassIsLookedUp() {
277+
if (pragma_class_.IsNull()) {
278+
const Library& internal_lib =
279+
Library::Handle(zone_, dart::Library::InternalLibrary());
280+
pragma_class_ = internal_lib.LookupClass(Symbols::Pragma());
281+
ASSERT(!pragma_class_.IsNull());
282+
}
283+
}
284+
276285
void EnsurePotentialNatives() {
277286
potential_natives_ = kernel_program_info_.potential_natives();
278287
if (potential_natives_.IsNull()) {
@@ -317,6 +326,8 @@ class KernelLoader : public ValueObject {
317326
GrowableObjectArray& potential_natives_;
318327
GrowableObjectArray& potential_extension_libraries_;
319328

329+
Class& pragma_class_;
330+
320331
Mapping<Library> libraries_;
321332
Mapping<Class> classes_;
322333

runtime/vm/object.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12508,6 +12508,7 @@ RawKernelProgramInfo* KernelProgramInfo::New(
1250812508
const TypedData& canonical_names,
1250912509
const ExternalTypedData& metadata_payloads,
1251012510
const ExternalTypedData& metadata_mappings,
12511+
const ExternalTypedData& constants_table,
1251112512
const Array& scripts) {
1251212513
const KernelProgramInfo& info =
1251312514
KernelProgramInfo::Handle(KernelProgramInfo::New());
@@ -12519,6 +12520,7 @@ RawKernelProgramInfo* KernelProgramInfo::New(
1251912520
info.StorePointer(&info.raw_ptr()->metadata_mappings_,
1252012521
metadata_mappings.raw());
1252112522
info.StorePointer(&info.raw_ptr()->scripts_, scripts.raw());
12523+
info.StorePointer(&info.raw_ptr()->constants_table_, constants_table.raw());
1252212524
return info.raw();
1252312525
}
1252412526

@@ -12536,6 +12538,11 @@ void KernelProgramInfo::set_constants(const Array& constants) const {
1253612538
StorePointer(&raw_ptr()->constants_, constants.raw());
1253712539
}
1253812540

12541+
void KernelProgramInfo::set_constants_table(
12542+
const ExternalTypedData& value) const {
12543+
StorePointer(&raw_ptr()->constants_table_, value.raw());
12544+
}
12545+
1253912546
void KernelProgramInfo::set_potential_natives(
1254012547
const GrowableObjectArray& candidates) const {
1254112548
StorePointer(&raw_ptr()->potential_natives_, candidates.raw());

runtime/vm/object.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,7 @@ class KernelProgramInfo : public Object {
41064106
const TypedData& canonical_names,
41074107
const ExternalTypedData& metadata_payload,
41084108
const ExternalTypedData& metadata_mappings,
4109+
const ExternalTypedData& constants_table,
41094110
const Array& scripts);
41104111

41114112
static intptr_t InstanceSize() {
@@ -4126,6 +4127,12 @@ class KernelProgramInfo : public Object {
41264127
return raw_ptr()->metadata_mappings_;
41274128
}
41284129

4130+
RawExternalTypedData* constants_table() const {
4131+
return raw_ptr()->constants_table_;
4132+
}
4133+
4134+
void set_constants_table(const ExternalTypedData& value) const;
4135+
41294136
RawArray* scripts() const { return raw_ptr()->scripts_; }
41304137

41314138
RawArray* constants() const { return raw_ptr()->constants_; }

runtime/vm/raw_object.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,12 @@ class RawKernelProgramInfo : public RawObject {
12391239
RawArray* scripts_;
12401240
RawArray* constants_;
12411241
RawGrowableObjectArray* potential_natives_;
1242-
VISIT_TO(RawObject*, potential_natives_);
1242+
RawExternalTypedData* constants_table_;
1243+
VISIT_TO(RawObject*, constants_table_);
1244+
1245+
RawObject** to_snapshot(Snapshot::Kind kind) {
1246+
return reinterpret_cast<RawObject**>(&ptr()->potential_natives_);
1247+
}
12431248
};
12441249

12451250
class RawCode : public RawObject {

runtime/vm/raw_object_snapshot.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,8 @@ RawKernelProgramInfo* KernelProgramInfo::ReadFrom(SnapshotReader* reader,
13341334
reader->AddBackRef(object_id, &info, kIsDeserialized);
13351335

13361336
// Set all the object fields.
1337-
READ_OBJECT_FIELDS(info, info.raw()->from(), info.raw()->to(), kAsReference);
1337+
READ_OBJECT_FIELDS(info, info.raw()->from(), info.raw()->to_snapshot(kind),
1338+
kAsReference);
13381339
return info.raw();
13391340
}
13401341

@@ -1354,7 +1355,7 @@ void RawKernelProgramInfo::WriteTo(SnapshotWriter* writer,
13541355

13551356
// Write out all the object pointer fields.
13561357
SnapshotWriterVisitor visitor(writer, kAsReference);
1357-
visitor.VisitPointers(from(), to());
1358+
visitor.VisitPointers(from(), to_snapshot(kind));
13581359
}
13591360

13601361
RawCode* Code::ReadFrom(SnapshotReader* reader,

0 commit comments

Comments
 (0)