Skip to content

Commit 76468a6

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,dyn_modules] Support reading pragmas from bytecode
TEST=vm/cc/* Change-Id: I561e23ebc758faea70c2eb72c08dc13b8326aee8 Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439061 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent 1f5fd27 commit 76468a6

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

runtime/vm/bytecode_reader.cc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,24 @@ TypeArgumentsPtr BytecodeReaderHelper::ReadTypeArguments() {
15541554
return type_arguments.Canonicalize(thread_);
15551555
}
15561556

1557+
void BytecodeReaderHelper::ReadAnnotations(const Class& cls,
1558+
const Object& declaration,
1559+
bool has_pragma) {
1560+
const intptr_t annotations_offset =
1561+
reader_.ReadUInt() + bytecode_component_->GetAnnotationsOffset();
1562+
ASSERT(annotations_offset > 0);
1563+
1564+
#if !defined(DART_PRECOMPILED_RUNTIME)
1565+
if (FLAG_enable_mirrors || has_pragma) {
1566+
AlternativeReadingScope alt(&reader_, annotations_offset);
1567+
const auto& metadata = Object::Handle(Z, ReadObject());
1568+
ASSERT(metadata.IsArray());
1569+
const auto& library = Library::Handle(Z, cls.library());
1570+
library.AddMetadata(declaration, metadata);
1571+
}
1572+
#endif // !defined(DART_PRECOMPILED_RUNTIME)
1573+
}
1574+
15571575
void BytecodeReaderHelper::ReadMembers(const Class& cls, bool discard_fields) {
15581576
ASSERT(IsolateGroup::Current()->program_lock()->IsCurrentThreadWriter());
15591577
ASSERT(cls.is_type_finalized());
@@ -1726,7 +1744,7 @@ void BytecodeReaderHelper::ReadFieldDeclarations(const Class& cls,
17261744
}
17271745

17281746
if ((flags & kHasAnnotationsFlag) != 0) {
1729-
reader_.ReadUInt(); // Skip annotations offset.
1747+
ReadAnnotations(cls, field, has_pragma);
17301748
}
17311749

17321750
if (field.is_static()) {
@@ -2003,7 +2021,7 @@ void BytecodeReaderHelper::ReadFunctionDeclarations(const Class& cls) {
20032021
}
20042022

20052023
if ((flags & kHasAnnotationsFlag) != 0) {
2006-
reader_.ReadUInt(); // Skip annotations offset.
2024+
ReadAnnotations(cls, function, has_pragma);
20072025
}
20082026

20092027
functions_->SetAt(function_index_++, function);
@@ -2122,7 +2140,7 @@ void BytecodeReaderHelper::ReadClassDeclaration(const Class& cls) {
21222140
}
21232141

21242142
if ((flags & kHasAnnotationsFlag) != 0) {
2125-
reader_.ReadUInt(); // Skip annotations offset.
2143+
ReadAnnotations(cls, cls, has_pragma);
21262144
}
21272145

21282146
const intptr_t members_offset = reader_.ReadUInt();

runtime/vm/bytecode_reader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ class BytecodeReaderHelper : public ValueObject {
349349
TypedDataPtr ReadLineStartsData(intptr_t line_starts_offset);
350350
ScriptPtr ReadSourceFile(const String& uri, intptr_t offset);
351351
TypeArgumentsPtr ReadTypeArguments();
352+
void ReadAnnotations(const Class& cls,
353+
const Object& declaration,
354+
bool has_pragma);
352355
void SetupFieldAccessorFunction(const Class& klass,
353356
const Function& function,
354357
const AbstractType& field_type);

runtime/vm/object.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14363,14 +14363,19 @@ void Library::SetLoaded() const {
1436314363

1436414364
void Library::AddMetadata(const Object& declaration,
1436514365
intptr_t kernel_offset) const {
14366+
AddMetadata(declaration, Smi::Handle(Smi::New(kernel_offset)));
14367+
}
14368+
14369+
void Library::AddMetadata(const Object& declaration,
14370+
const Object& metadata_value) const {
1436614371
#if defined(DART_PRECOMPILED_RUNTIME)
1436714372
UNREACHABLE();
1436814373
#else
1436914374
Thread* thread = Thread::Current();
1437014375
ASSERT(thread->isolate_group()->program_lock()->IsCurrentThreadWriter());
1437114376

1437214377
MetadataMap map(metadata());
14373-
map.UpdateOrInsert(declaration, Smi::Handle(Smi::New(kernel_offset)));
14378+
map.UpdateOrInsert(declaration, metadata_value);
1437414379
set_metadata(map.Release());
1437514380
#endif // defined(DART_PRECOMPILED_RUNTIME)
1437614381
}

runtime/vm/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5235,6 +5235,8 @@ class Library : public Object {
52355235
void AddExport(const Namespace& ns) const;
52365236

52375237
void AddMetadata(const Object& declaration, intptr_t kernel_offset) const;
5238+
void AddMetadata(const Object& declaration,
5239+
const Object& metadata_value) const;
52385240
ObjectPtr GetMetadata(const Object& declaration) const;
52395241

52405242
#if !defined(DART_PRECOMPILED_RUNTIME)

0 commit comments

Comments
 (0)