Skip to content

Commit

Permalink
[vm] Fix @pragma detection in KernelLoader.
Browse files Browse the repository at this point in the history
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 <alexmarkov@google.com>
  • Loading branch information
sjindel-google authored and commit-bot@chromium.org committed Aug 7, 2018
1 parent 0986b2b commit 1ac34f1
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 19 deletions.
10 changes: 7 additions & 3 deletions runtime/vm/clustered_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ class KernelProgramInfoSerializationCluster : public SerializationCluster {
objects_.Add(info);

RawObject** from = info->from();
RawObject** to = info->to();
RawObject** to = info->to_snapshot(s->kind());
for (RawObject** p = from; p <= to; p++) {
s->Push(*p);
}
Expand All @@ -1588,7 +1588,7 @@ class KernelProgramInfoSerializationCluster : public SerializationCluster {
for (intptr_t i = 0; i < count; i++) {
RawKernelProgramInfo* info = objects_[i];
RawObject** from = info->from();
RawObject** to = info->to();
RawObject** to = info->to_snapshot(s->kind());
for (RawObject** p = from; p <= to; p++) {
s->WriteRef(*p);
}
Expand Down Expand Up @@ -1627,10 +1627,14 @@ class KernelProgramInfoDeserializationCluster : public DeserializationCluster {
KernelProgramInfo::InstanceSize(),
is_vm_object);
RawObject** from = info->from();
RawObject** to = info->to();
RawObject** to = info->to_snapshot(d->kind());
RawObject** end = info->to();
for (RawObject** p = from; p <= to; p++) {
*p = d->ReadRef();
}
for (RawObject** p = to + 1; p <= end; p++) {
*p = Object::null();
}
}
}
};
Expand Down
39 changes: 26 additions & 13 deletions runtime/vm/kernel_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ KernelLoader::KernelLoader(Program* program)
external_name_class_(Class::Handle(Z)),
external_name_field_(Field::Handle(Z)),
potential_natives_(GrowableObjectArray::Handle(Z)),
potential_extension_libraries_(GrowableObjectArray::Handle(Z)) {
potential_extension_libraries_(GrowableObjectArray::Handle(Z)),
pragma_class_(Class::Handle(Z)) {
if (!program->is_single_program()) {
FATAL(
"Trying to load a concatenated dill file at a time where that is "
Expand Down Expand Up @@ -283,6 +284,12 @@ void KernelLoader::InitializeFields() {
Z,
reader.ExternalDataFromTo(reader.offset(), reader.offset() + end_offset));

// Create a view of the constants table. The trailing ComponentIndex is
// negligible in size.
const ExternalTypedData& constants_table = ExternalTypedData::Handle(
Z, reader.ExternalDataFromTo(program_->constant_table_offset(),
program_->kernel_data_size()));

// Copy the canonical names into the VM's heap. Encode them as unsigned, so
// the parent indexes are adjusted when extracted.
reader.set_offset(program_->name_table_offset());
Expand All @@ -303,8 +310,9 @@ void KernelLoader::InitializeFields() {
Z, reader.ExternalDataFromTo(program_->metadata_mappings_offset(),
program_->string_table_offset()));

kernel_program_info_ = KernelProgramInfo::New(
offsets, data, names, metadata_payloads, metadata_mappings, scripts);
kernel_program_info_ =
KernelProgramInfo::New(offsets, data, names, metadata_payloads,
metadata_mappings, constants_table, scripts);

H.InitFromKernelProgramInfo(kernel_program_info_);

Expand Down Expand Up @@ -335,7 +343,8 @@ KernelLoader::KernelLoader(const Script& script,
external_name_class_(Class::Handle(Z)),
external_name_field_(Field::Handle(Z)),
potential_natives_(GrowableObjectArray::Handle(Z)),
potential_extension_libraries_(GrowableObjectArray::Handle(Z)) {
potential_extension_libraries_(GrowableObjectArray::Handle(Z)),
pragma_class_(Class::Handle(Z)) {
ASSERT(T.active_class_ == &active_class_);
T.finalize_ = false;

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

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

if (program_ == nullptr) {
helper_.SkipExpression();
continue;
}
ASSERT(kernel_program_info_.constants_table() !=
ExternalTypedData::null());

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

const intptr_t offset_in_constant_table = helper_.ReadUInt();

AlternativeReadingScope scope(&helper_.reader_,
program_->constant_table_offset());
AlternativeReadingScope scope(
&helper_.reader_,
&ExternalTypedData::Handle(Z,
kernel_program_info_.constants_table()),
0);

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

// Obtain `dart:_internal::pragma`.
EnsurePragmaClassIsLookedUp();

const intptr_t constant_table_index = helper_.ReadUInt();
const Object& constant =
Object::Handle(constant_table.GetOrDie(constant_table_index));
Expand All @@ -1404,7 +1417,7 @@ void KernelLoader::ReadProcedureAnnotations(intptr_t annotation_count,
Instance::Handle(Instance::RawCast(constant.raw()));
*native_name =
String::RawCast(instance.GetField(external_name_field_));
} else if (constant.clazz() == pragma_class.raw()) {
} else if (constant.clazz() == pragma_class_.raw()) {
*has_pragma_annotation = true;
}
ASSERT(constant_table.Release().raw() == constant_table_array.raw());
Expand Down
11 changes: 11 additions & 0 deletions runtime/vm/kernel_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ class KernelLoader : public ValueObject {
}
}

void EnsurePragmaClassIsLookedUp() {
if (pragma_class_.IsNull()) {
const Library& internal_lib =
Library::Handle(zone_, dart::Library::InternalLibrary());
pragma_class_ = internal_lib.LookupClass(Symbols::Pragma());
ASSERT(!pragma_class_.IsNull());
}
}

void EnsurePotentialNatives() {
potential_natives_ = kernel_program_info_.potential_natives();
if (potential_natives_.IsNull()) {
Expand Down Expand Up @@ -317,6 +326,8 @@ class KernelLoader : public ValueObject {
GrowableObjectArray& potential_natives_;
GrowableObjectArray& potential_extension_libraries_;

Class& pragma_class_;

Mapping<Library> libraries_;
Mapping<Class> classes_;

Expand Down
7 changes: 7 additions & 0 deletions runtime/vm/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12508,6 +12508,7 @@ RawKernelProgramInfo* KernelProgramInfo::New(
const TypedData& canonical_names,
const ExternalTypedData& metadata_payloads,
const ExternalTypedData& metadata_mappings,
const ExternalTypedData& constants_table,
const Array& scripts) {
const KernelProgramInfo& info =
KernelProgramInfo::Handle(KernelProgramInfo::New());
Expand All @@ -12519,6 +12520,7 @@ RawKernelProgramInfo* KernelProgramInfo::New(
info.StorePointer(&info.raw_ptr()->metadata_mappings_,
metadata_mappings.raw());
info.StorePointer(&info.raw_ptr()->scripts_, scripts.raw());
info.StorePointer(&info.raw_ptr()->constants_table_, constants_table.raw());
return info.raw();
}

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

void KernelProgramInfo::set_constants_table(
const ExternalTypedData& value) const {
StorePointer(&raw_ptr()->constants_table_, value.raw());
}

void KernelProgramInfo::set_potential_natives(
const GrowableObjectArray& candidates) const {
StorePointer(&raw_ptr()->potential_natives_, candidates.raw());
Expand Down
7 changes: 7 additions & 0 deletions runtime/vm/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -4106,6 +4106,7 @@ class KernelProgramInfo : public Object {
const TypedData& canonical_names,
const ExternalTypedData& metadata_payload,
const ExternalTypedData& metadata_mappings,
const ExternalTypedData& constants_table,
const Array& scripts);

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

RawExternalTypedData* constants_table() const {
return raw_ptr()->constants_table_;
}

void set_constants_table(const ExternalTypedData& value) const;

RawArray* scripts() const { return raw_ptr()->scripts_; }

RawArray* constants() const { return raw_ptr()->constants_; }
Expand Down
7 changes: 6 additions & 1 deletion runtime/vm/raw_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,12 @@ class RawKernelProgramInfo : public RawObject {
RawArray* scripts_;
RawArray* constants_;
RawGrowableObjectArray* potential_natives_;
VISIT_TO(RawObject*, potential_natives_);
RawExternalTypedData* constants_table_;
VISIT_TO(RawObject*, constants_table_);

RawObject** to_snapshot(Snapshot::Kind kind) {
return reinterpret_cast<RawObject**>(&ptr()->potential_natives_);
}
};

class RawCode : public RawObject {
Expand Down
5 changes: 3 additions & 2 deletions runtime/vm/raw_object_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,8 @@ RawKernelProgramInfo* KernelProgramInfo::ReadFrom(SnapshotReader* reader,
reader->AddBackRef(object_id, &info, kIsDeserialized);

// Set all the object fields.
READ_OBJECT_FIELDS(info, info.raw()->from(), info.raw()->to(), kAsReference);
READ_OBJECT_FIELDS(info, info.raw()->from(), info.raw()->to_snapshot(kind),
kAsReference);
return info.raw();
}

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

// Write out all the object pointer fields.
SnapshotWriterVisitor visitor(writer, kAsReference);
visitor.VisitPointers(from(), to());
visitor.VisitPointers(from(), to_snapshot(kind));
}

RawCode* Code::ReadFrom(SnapshotReader* reader,
Expand Down

0 comments on commit 1ac34f1

Please sign in to comment.