Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::FullSnapshotReader Class Reference

#include <app_snapshot.h>

Public Member Functions

 FullSnapshotReader (const Snapshot *snapshot, const uint8_t *instructions_buffer, Thread *thread)
 
 ~FullSnapshotReader ()
 
ApiErrorPtr ReadVMSnapshot ()
 
ApiErrorPtr ReadProgramSnapshot ()
 
ApiErrorPtr ReadUnitSnapshot (const LoadingUnit &unit)
 

Detailed Description

Definition at line 163 of file app_snapshot.h.

Constructor & Destructor Documentation

◆ FullSnapshotReader()

dart::FullSnapshotReader::FullSnapshotReader ( const Snapshot snapshot,
const uint8_t *  instructions_buffer,
Thread thread 
)

Definition at line 9828 of file app_snapshot.cc.

9831 : kind_(snapshot->kind()),
9832 thread_(thread),
9833 buffer_(snapshot->Addr()),
9834 size_(snapshot->length()),
9835 data_image_(snapshot->DataImage()),
9836 instructions_image_(instructions_buffer) {}

◆ ~FullSnapshotReader()

dart::FullSnapshotReader::~FullSnapshotReader ( )
inline

Definition at line 168 of file app_snapshot.h.

168{}

Member Function Documentation

◆ ReadProgramSnapshot()

ApiErrorPtr dart::FullSnapshotReader::ReadProgramSnapshot ( )

Definition at line 9985 of file app_snapshot.cc.

9985 {
9986 SnapshotHeaderReader header_reader(kind_, buffer_, size_);
9987 header_reader.SetCoverageFromSnapshotFeatures(thread_->isolate_group());
9988 intptr_t offset = 0;
9989 char* error =
9990 header_reader.VerifyVersionAndFeatures(thread_->isolate_group(), &offset);
9991 if (error != nullptr) {
9992 return ConvertToApiError(error);
9993 }
9994
9995 // Even though there's no concurrent threads we have to guard agains, some
9996 // logic we do in deserialization triggers common code that asserts the
9997 // program lock is held.
9998 SafepointWriteRwLocker ml(thread_, isolate_group()->program_lock());
9999
10000 Deserializer deserializer(thread_, kind_, buffer_, size_, data_image_,
10001 instructions_image_, /*is_non_root_unit=*/false,
10002 offset);
10003 ApiErrorPtr api_error = deserializer.VerifyImageAlignment();
10004 if (api_error != ApiError::null()) {
10005 return api_error;
10006 }
10007
10008 if (Snapshot::IncludesCode(kind_)) {
10009 ASSERT(data_image_ != nullptr);
10010 thread_->isolate_group()->SetupImagePage(data_image_,
10011 /* is_executable */ false);
10012 ASSERT(instructions_image_ != nullptr);
10013 thread_->isolate_group()->SetupImagePage(instructions_image_,
10014 /* is_executable */ true);
10015 }
10016
10017 ProgramDeserializationRoots roots(thread_->isolate_group()->object_store());
10018 deserializer.Deserialize(&roots);
10019
10020 if (Snapshot::IncludesCode(kind_)) {
10021 const auto& units = Array::Handle(
10022 thread_->isolate_group()->object_store()->loading_units());
10023 if (!units.IsNull()) {
10024 const auto& unit = LoadingUnit::Handle(
10026 // Unlike other units, we don't explicitly load the root loading unit,
10027 // so we mark it as loaded here, setting the instructions image as well.
10028 unit.set_load_outstanding();
10029 unit.set_instructions_image(instructions_image_);
10030 unit.set_loaded(true);
10031 }
10032 }
10033
10034 InitializeBSS();
10035
10036 return ApiError::null();
10037}
ObjectStore * object_store() const
Definition: isolate.h:510
void SetupImagePage(const uint8_t *snapshot_buffer, bool is_executable)
Definition: isolate.cc:1953
static constexpr intptr_t kRootId
Definition: object.h:7969
static ObjectPtr null()
Definition: object.h:433
static Object & Handle()
Definition: object.h:407
static ObjectPtr RawCast(ObjectPtr obj)
Definition: object.h:325
static bool IncludesCode(Kind kind)
Definition: snapshot.h:67
IsolateGroup * isolate_group() const
Definition: thread.h:541
#define ASSERT(E)
const uint8_t uint32_t uint32_t GError ** error
SeparatedVector2 offset

◆ ReadUnitSnapshot()

ApiErrorPtr dart::FullSnapshotReader::ReadUnitSnapshot ( const LoadingUnit unit)

Definition at line 10039 of file app_snapshot.cc.

10039 {
10040 SnapshotHeaderReader header_reader(kind_, buffer_, size_);
10041 intptr_t offset = 0;
10042 char* error =
10043 header_reader.VerifyVersionAndFeatures(thread_->isolate_group(), &offset);
10044 if (error != nullptr) {
10045 return ConvertToApiError(error);
10046 }
10047
10048 Deserializer deserializer(
10049 thread_, kind_, buffer_, size_, data_image_, instructions_image_,
10050 /*is_non_root_unit=*/unit.id() != LoadingUnit::kRootId, offset);
10051 ApiErrorPtr api_error = deserializer.VerifyImageAlignment();
10052 if (api_error != ApiError::null()) {
10053 return api_error;
10054 }
10055 {
10056 Array& units =
10057 Array::Handle(isolate_group()->object_store()->loading_units());
10058 uint32_t main_program_hash = Smi::Value(Smi::RawCast(units.At(0)));
10059 uint32_t unit_program_hash = deserializer.Read<uint32_t>();
10060 if (main_program_hash != unit_program_hash) {
10061 return ApiError::New(String::Handle(
10062 String::New("Deferred loading unit is from a different "
10063 "program than the main loading unit")));
10064 }
10065 }
10066
10067 if (Snapshot::IncludesCode(kind_)) {
10068 ASSERT(data_image_ != nullptr);
10069 thread_->isolate_group()->SetupImagePage(data_image_,
10070 /* is_executable */ false);
10071 ASSERT(instructions_image_ != nullptr);
10072 thread_->isolate_group()->SetupImagePage(instructions_image_,
10073 /* is_executable */ true);
10074 unit.set_instructions_image(instructions_image_);
10075 }
10076
10077 UnitDeserializationRoots roots(unit);
10078 deserializer.Deserialize(&roots);
10079
10080 InitializeBSS();
10081
10082 return ApiError::null();
10083}
intptr_t Value() const
Definition: object.h:9990
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698

◆ ReadVMSnapshot()

ApiErrorPtr dart::FullSnapshotReader::ReadVMSnapshot ( )

Definition at line 9938 of file app_snapshot.cc.

9938 {
9939 SnapshotHeaderReader header_reader(kind_, buffer_, size_);
9940
9941 intptr_t offset = 0;
9942 char* error = header_reader.VerifyVersionAndFeatures(
9943 /*isolate_group=*/nullptr, &offset);
9944 if (error != nullptr) {
9945 return ConvertToApiError(error);
9946 }
9947
9948 // Even though there's no concurrent threads we have to guard agains, some
9949 // logic we do in deserialization triggers common code that asserts the
9950 // program lock is held.
9951 SafepointWriteRwLocker ml(thread_, isolate_group()->program_lock());
9952
9953 Deserializer deserializer(thread_, kind_, buffer_, size_, data_image_,
9954 instructions_image_, /*is_non_root_unit=*/false,
9955 offset);
9956 ApiErrorPtr api_error = deserializer.VerifyImageAlignment();
9957 if (api_error != ApiError::null()) {
9958 return api_error;
9959 }
9960
9961 if (Snapshot::IncludesCode(kind_)) {
9962 ASSERT(data_image_ != nullptr);
9963 thread_->isolate_group()->SetupImagePage(data_image_,
9964 /* is_executable */ false);
9965 ASSERT(instructions_image_ != nullptr);
9966 thread_->isolate_group()->SetupImagePage(instructions_image_,
9967 /* is_executable */ true);
9968 }
9969
9970 VMDeserializationRoots roots;
9971 deserializer.Deserialize(&roots);
9972
9973#if defined(DART_PRECOMPILED_RUNTIME)
9974 // Initialize entries in the VM portion of the BSS segment.
9976 Image image(instructions_image_);
9977 if (auto const bss = image.bss()) {
9978 BSS::Initialize(thread_, bss, /*vm=*/true);
9979 }
9980#endif // defined(DART_PRECOMPILED_RUNTIME)
9981
9982 return ApiError::null();
9983}
static void Initialize(Thread *current, uword *bss, bool vm)
Definition: bss_relocs.cc:30
sk_sp< const SkImage > image
Definition: SkRecords.h:269
CanvasImage Image
Definition: dart_ui.cc:55

The documentation for this class was generated from the following files: