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

#include <dfe.h>

Public Member Functions

 DFE ()
 
 ~DFE ()
 
void Init ()
 
char * frontend_filename () const
 
void set_frontend_filename (const char *name)
 
void set_use_dfe (bool value=true)
 
bool UseDartFrontend () const
 
void set_use_incremental_compiler (bool value)
 
bool use_incremental_compiler () const
 
void set_verbosity (Dart_KernelCompilationVerbosityLevel verbosity)
 
Dart_KernelCompilationVerbosityLevel verbosity () const
 
const char * GetPlatformBinaryFilename ()
 
void set_application_kernel_buffer (uint8_t *buffer, intptr_t size)
 
void application_kernel_buffer (const uint8_t **buffer, intptr_t *size) const
 
Dart_KernelCompilationResult CompileScript (const char *script_uri, bool incremental, const char *package_config, bool for_snapshot, bool embedd_sources)
 
void CompileAndReadScript (const char *script_uri, uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, char **error, int *exit_code, const char *package_config, bool for_snapshot, bool embed_sources)
 
void ReadScript (const char *script_uri, const AppSnapshot *app_snapshot, uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, bool decode_uri=true, std::shared_ptr< uint8_t > *kernel_blob_ptr=nullptr)
 
bool KernelServiceDillAvailable () const
 
bool TryReadKernelFile (const char *script_uri, const AppSnapshot *app_snapshot, uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, bool decode_uri=true, std::shared_ptr< uint8_t > *kernel_blob_ptr=nullptr)
 
bool CanUseDartFrontend () const
 
void LoadPlatform (const uint8_t **kernel_buffer, intptr_t *kernel_buffer_size)
 
void LoadKernelService (const uint8_t **kernel_service_buffer, intptr_t *kernel_service_buffer_size)
 
const char * RegisterKernelBlob (const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
 
std::shared_ptr< uint8_t > TryFindKernelBlob (const char *uri, intptr_t *kernel_length)
 
void UnregisterKernelBlob (const char *uri)
 

Detailed Description

Definition at line 23 of file dfe.h.

Constructor & Destructor Documentation

◆ DFE()

dart::bin::DFE::DFE ( )

Definition at line 65 of file dfe.cc.

66 : use_dfe_(false),
67 use_incremental_compiler_(false),
68 frontend_filename_(nullptr),
69 application_kernel_buffer_(nullptr),
70 application_kernel_buffer_size_(0),
71 kernel_blobs_(&SimpleHashMap::SameStringValue, 4),
72 kernel_blobs_lock_() {}
static bool SameStringValue(void *key1, void *key2)
Definition: hashmap.h:41

◆ ~DFE()

dart::bin::DFE::~DFE ( )

Definition at line 74 of file dfe.cc.

74 {
75 if (frontend_filename_ != nullptr) {
76 free(frontend_filename_);
77 }
78 frontend_filename_ = nullptr;
79
80 free(application_kernel_buffer_);
81 application_kernel_buffer_ = nullptr;
82 application_kernel_buffer_size_ = 0;
83
84 kernel_blobs_.Clear(
85 [](void* value) { delete reinterpret_cast<KernelBlob*>(value); });
86}
void Clear(ClearFun clear=nullptr)
Definition: hashmap.cc:111
uint8_t value

Member Function Documentation

◆ application_kernel_buffer()

void dart::bin::DFE::application_kernel_buffer ( const uint8_t **  buffer,
intptr_t *  size 
) const
inline

Definition at line 64 of file dfe.h.

64 {
65 *buffer = application_kernel_buffer_;
66 *size = application_kernel_buffer_size_;
67 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ CanUseDartFrontend()

bool dart::bin::DFE::CanUseDartFrontend ( ) const

Definition at line 143 of file dfe.cc.

143 {
144 return (platform_strong_dill != nullptr) &&
145 (KernelServiceDillAvailable() || (frontend_filename() != nullptr));
146}
bool KernelServiceDillAvailable() const
Definition: dfe.cc:127
char * frontend_filename() const
Definition: dfe.h:32
const uint8_t * platform_strong_dill
Definition: dfe.cc:54

◆ CompileAndReadScript()

void dart::bin::DFE::CompileAndReadScript ( const char *  script_uri,
uint8_t **  kernel_buffer,
intptr_t *  kernel_buffer_size,
char **  error,
int exit_code,
const char *  package_config,
bool  for_snapshot,
bool  embed_sources 
)

Definition at line 204 of file dfe.cc.

211 {
213 CompileScript(script_uri, use_incremental_compiler(), package_config,
214 for_snapshot, embed_sources);
215 switch (result.status) {
217 *kernel_buffer = result.kernel;
218 *kernel_buffer_size = result.kernel_size;
219 *error = nullptr;
220 *exit_code = 0;
221 break;
223 free(result.kernel);
224 *error = result.error; // Copy error message.
225 *exit_code = kCompilationErrorExitCode;
226 break;
228 free(result.kernel);
229 *error = result.error; // Copy error message.
230 *exit_code = kDartFrontendErrorExitCode;
231 break;
234 free(result.kernel);
235 *error = result.error; // Copy error message.
236 *exit_code = kErrorExitCode;
237 break;
238 }
239}
bool use_incremental_compiler() const
Definition: dfe.h:47
Dart_KernelCompilationResult CompileScript(const char *script_uri, bool incremental, const char *package_config, bool for_snapshot, bool embedd_sources)
Definition: dfe.cc:189
@ Dart_KernelCompilationStatus_MsgFailed
Definition: dart_api.h:3788
@ Dart_KernelCompilationStatus_Error
Definition: dart_api.h:3786
@ Dart_KernelCompilationStatus_Crash
Definition: dart_api.h:3787
@ Dart_KernelCompilationStatus_Unknown
Definition: dart_api.h:3784
@ Dart_KernelCompilationStatus_Ok
Definition: dart_api.h:3785
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
constexpr int kCompilationErrorExitCode
Definition: error_exit.h:16
constexpr int kErrorExitCode
Definition: error_exit.h:18
constexpr int kDartFrontendErrorExitCode
Definition: error_exit.h:12

◆ CompileScript()

Dart_KernelCompilationResult dart::bin::DFE::CompileScript ( const char *  script_uri,
bool  incremental,
const char *  package_config,
bool  for_snapshot,
bool  embedd_sources 
)

Definition at line 189 of file dfe.cc.

193 {
194 // TODO(aam): When Frontend is ready, VM should be passing vm_outline.dill
195 // instead of vm_platform.dill to Frontend for compilation.
196 PathSanitizer path_sanitizer(script_uri);
197 const char* sanitized_uri = path_sanitizer.sanitized_uri();
198
201 incremental, for_snapshot, embed_sources, package_config, verbosity());
202}
Dart_KernelCompilationVerbosityLevel verbosity() const
Definition: dfe.h:52
const intptr_t platform_strong_dill_size
Definition: dfe.cc:55
DART_EXPORT Dart_KernelCompilationResult Dart_CompileToKernel(const char *script_uri, const uint8_t *platform_kernel, intptr_t platform_kernel_size, bool incremental_compile, bool for_snapshot, bool embed_sources, const char *package_config, Dart_KernelCompilationVerbosityLevel verbosity)

◆ frontend_filename()

char * dart::bin::DFE::frontend_filename ( ) const
inline

Definition at line 32 of file dfe.h.

32{ return frontend_filename_; }

◆ GetPlatformBinaryFilename()

const char * dart::bin::DFE::GetPlatformBinaryFilename ( )

◆ Init()

void dart::bin::DFE::Init ( )

Definition at line 88 of file dfe.cc.

88 {
89 if (platform_strong_dill == nullptr) {
90 return;
91 }
92
93 InitKernelServiceAndPlatformDills();
96}
DART_EXPORT void Dart_SetDartLibrarySourcesKernel(const uint8_t *platform_kernel, const intptr_t platform_kernel_size)

◆ KernelServiceDillAvailable()

bool dart::bin::DFE::KernelServiceDillAvailable ( ) const

Definition at line 127 of file dfe.cc.

127 {
128 return kernel_service_dill != nullptr;
129}
const uint8_t * kernel_service_dill
Definition: dfe.cc:46

◆ LoadKernelService()

void dart::bin::DFE::LoadKernelService ( const uint8_t **  kernel_service_buffer,
intptr_t *  kernel_service_buffer_size 
)

Definition at line 131 of file dfe.cc.

132 {
133 *kernel_service_buffer = kernel_service_dill;
134 *kernel_service_buffer_size = kernel_service_dill_size;
135}
const intptr_t kernel_service_dill_size
Definition: dfe.cc:47

◆ LoadPlatform()

void dart::bin::DFE::LoadPlatform ( const uint8_t **  kernel_buffer,
intptr_t *  kernel_buffer_size 
)

Definition at line 137 of file dfe.cc.

138 {
139 *kernel_buffer = platform_strong_dill;
140 *kernel_buffer_size = platform_strong_dill_size;
141}

◆ ReadScript()

void dart::bin::DFE::ReadScript ( const char *  script_uri,
const AppSnapshot app_snapshot,
uint8_t **  kernel_buffer,
intptr_t *  kernel_buffer_size,
bool  decode_uri = true,
std::shared_ptr< uint8_t > *  kernel_blob_ptr = nullptr 
)

Definition at line 241 of file dfe.cc.

246 {
247 int64_t start = Dart_TimelineGetMicros();
248 if (!TryReadKernelFile(script_uri, app_snapshot, kernel_buffer,
249 kernel_buffer_size, decode_uri, kernel_blob_ptr)) {
250 return;
251 }
252 if (!Dart_IsKernel(*kernel_buffer, *kernel_buffer_size)) {
253 if (kernel_blob_ptr != nullptr && *kernel_blob_ptr) {
254 *kernel_blob_ptr = nullptr;
255 } else {
256 free(*kernel_buffer);
257 }
258 *kernel_buffer = nullptr;
259 *kernel_buffer_size = -1;
260 }
261 int64_t end = Dart_TimelineGetMicros();
262 Dart_RecordTimelineEvent("DFE::ReadScript", start, end, /*flow_id_count=*/0,
264 /*argument_count=*/0, nullptr, nullptr);
265}
bool TryReadKernelFile(const char *script_uri, const AppSnapshot *app_snapshot, uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, bool decode_uri=true, std::shared_ptr< uint8_t > *kernel_blob_ptr=nullptr)
Definition: dfe.cc:437
@ Dart_Timeline_Event_Duration
glong glong end
DART_EXPORT bool Dart_IsKernel(const uint8_t *buffer, intptr_t buffer_size)
DART_EXPORT void Dart_RecordTimelineEvent(const char *label, int64_t timestamp0, int64_t timestamp1_or_id, intptr_t flow_id_count, const int64_t *flow_ids, Dart_Timeline_Event_Type type, intptr_t argument_count, const char **argument_names, const char **argument_values)
DART_EXPORT int64_t Dart_TimelineGetMicros()

◆ RegisterKernelBlob()

const char * dart::bin::DFE::RegisterKernelBlob ( const uint8_t *  kernel_buffer,
intptr_t  kernel_buffer_size 
)

Definition at line 482 of file dfe.cc.

483 {
484 ASSERT(DartUtils::SniffForMagicNumber(kernel_buffer, kernel_buffer_size) ==
486 uint8_t* buffer_copy = reinterpret_cast<uint8_t*>(malloc(kernel_buffer_size));
487 if (buffer_copy == nullptr) {
488 return nullptr;
489 }
490 memmove(buffer_copy, kernel_buffer, kernel_buffer_size);
491
492 MutexLocker ml(&kernel_blobs_lock_);
493 ++kernel_blob_counter_;
494 char* uri =
495 Utils::SCreate("dart-kernel-blob://blob%" Pd, kernel_blob_counter_);
496 KernelBlob* blob = new KernelBlob(uri, buffer_copy, kernel_buffer_size);
497
498 const uint32_t hash = SimpleHashMap::StringHash(uri);
499 SimpleHashMap::Entry* entry =
500 kernel_blobs_.Lookup(uri, hash, /*insert=*/true);
501 ASSERT(entry != nullptr);
502 ASSERT(entry->value == nullptr);
503 entry->value = blob;
504
505 return uri;
506}
static uint32_t hash(const SkShaderBase::GradientInfo &v)
Entry * Lookup(void *key, uint32_t hash, bool insert)
Definition: hashmap.cc:20
static uint32_t StringHash(const char *key)
Definition: hashmap.h:26
static char * SCreate(const char *format,...) PRINTF_ATTRIBUTE(1
Definition: utils.cc:231
static MagicNumber SniffForMagicNumber(const char *filename)
Definition: dartutils.cc:403
#define ASSERT(E)
void * malloc(size_t size)
Definition: allocation.cc:19
#define Pd
Definition: globals.h:408

◆ set_application_kernel_buffer()

void dart::bin::DFE::set_application_kernel_buffer ( uint8_t *  buffer,
intptr_t  size 
)
inline

Definition at line 60 of file dfe.h.

60 {
61 application_kernel_buffer_ = buffer;
62 application_kernel_buffer_size_ = size;
63 }

◆ set_frontend_filename()

void dart::bin::DFE::set_frontend_filename ( const char *  name)
inline

Definition at line 34 of file dfe.h.

34 {
35 if (frontend_filename_ != nullptr) {
36 free(frontend_filename_);
37 }
38 frontend_filename_ = Utils::StrDup(name);
40 }
static char * StrDup(const char *s)
void set_use_dfe(bool value=true)
Definition: dfe.h:41
const char *const name

◆ set_use_dfe()

void dart::bin::DFE::set_use_dfe ( bool  value = true)
inline

Definition at line 41 of file dfe.h.

41{ use_dfe_ = value; }

◆ set_use_incremental_compiler()

void dart::bin::DFE::set_use_incremental_compiler ( bool  value)
inline

Definition at line 44 of file dfe.h.

44 {
45 use_incremental_compiler_ = value;
46 }

◆ set_verbosity()

void dart::bin::DFE::set_verbosity ( Dart_KernelCompilationVerbosityLevel  verbosity)
inline

Definition at line 49 of file dfe.h.

49 {
50 verbosity_ = verbosity;
51 }

◆ TryFindKernelBlob()

std::shared_ptr< uint8_t > dart::bin::DFE::TryFindKernelBlob ( const char *  uri,
intptr_t *  kernel_length 
)

Definition at line 508 of file dfe.cc.

509 {
510 *kernel_length = -1;
511
512 MutexLocker ml(&kernel_blobs_lock_);
513 if (kernel_blob_counter_ == 0) {
514 return nullptr;
515 }
516
517 // This const_cast is safe as this 'key' is only used to find entry, not add.
518 void* key = const_cast<char*>(uri);
519 const uint32_t hash = SimpleHashMap::StringHash(uri);
520 SimpleHashMap::Entry* entry =
521 kernel_blobs_.Lookup(key, hash, /*insert=*/false);
522 if (entry == nullptr) {
523 return nullptr;
524 }
525
526 KernelBlob* blob = reinterpret_cast<KernelBlob*>(entry->value);
527 *kernel_length = blob->size();
528 return blob->buffer();
529}

◆ TryReadKernelFile()

bool dart::bin::DFE::TryReadKernelFile ( const char *  script_uri,
const AppSnapshot app_snapshot,
uint8_t **  kernel_buffer,
intptr_t *  kernel_buffer_size,
bool  decode_uri = true,
std::shared_ptr< uint8_t > *  kernel_blob_ptr = nullptr 
)

Definition at line 437 of file dfe.cc.

442 {
443 *kernel_ir = nullptr;
444 *kernel_ir_size = -1;
445
446 if (decode_uri && kernel_blob_ptr != nullptr) {
447 *kernel_blob_ptr = TryFindKernelBlob(script_uri, kernel_ir_size);
448 if (*kernel_blob_ptr) {
449 *kernel_ir = kernel_blob_ptr->get();
450 ASSERT(DartUtils::SniffForMagicNumber(*kernel_ir, *kernel_ir_size) ==
452 return true;
453 }
454 }
455 if (app_snapshot == nullptr || app_snapshot->IsKernel() ||
456 app_snapshot->IsKernelList()) {
457 uint8_t* buffer;
458 if (!TryReadFile(script_uri, &buffer, kernel_ir_size, decode_uri)) {
459 return false;
460 }
461 auto magic_number = DartUtils::kUnknownMagicNumber;
462 if (app_snapshot == nullptr) {
463 magic_number = DartUtils::SniffForMagicNumber(buffer, *kernel_ir_size);
464 } else if (app_snapshot->IsKernel()) {
465 magic_number = DartUtils::kKernelMagicNumber;
466 ASSERT(DartUtils::SniffForMagicNumber(buffer, *kernel_ir_size) ==
468 } else {
470 ASSERT(DartUtils::SniffForMagicNumber(buffer, *kernel_ir_size) ==
472 }
473 if (magic_number == DartUtils::kKernelListMagicNumber) {
474 return TryReadKernelListBuffer(script_uri, buffer, *kernel_ir_size,
475 kernel_ir, kernel_ir_size);
476 }
477 return TryReadSimpleKernelBuffer(buffer, kernel_ir, kernel_ir_size);
478 }
479 return false;
480}
std::shared_ptr< uint8_t > TryFindKernelBlob(const char *uri, intptr_t *kernel_length)
Definition: dfe.cc:508
static bool TryReadKernelListBuffer(const char *script_uri, uint8_t *buffer, intptr_t buffer_size, uint8_t **kernel_ir, intptr_t *kernel_ir_size)
Definition: dfe.cc:385
static bool TryReadSimpleKernelBuffer(uint8_t *buffer, uint8_t **p_kernel_ir, intptr_t *p_kernel_ir_size)
Definition: dfe.cc:272
static bool TryReadFile(const char *script_uri, uint8_t **buffer, intptr_t *size, bool decode_uri=true)
Definition: dfe.cc:295

◆ UnregisterKernelBlob()

void dart::bin::DFE::UnregisterKernelBlob ( const char *  uri)

Definition at line 531 of file dfe.cc.

531 {
532 MutexLocker ml(&kernel_blobs_lock_);
533
534 // This const_cast is safe as this 'key' is only used to find entry, not add.
535 void* key = const_cast<char*>(uri);
536 const uint32_t hash = SimpleHashMap::StringHash(uri);
537 SimpleHashMap::Entry* entry =
538 kernel_blobs_.Lookup(key, hash, /*insert=*/false);
539 if (entry == nullptr) {
540 return;
541 }
542
543 KernelBlob* blob = reinterpret_cast<KernelBlob*>(entry->value);
544 entry->value = nullptr;
545 kernel_blobs_.Remove(key, hash);
546 delete blob;
547}
void Remove(void *key, uint32_t hash)
Definition: hashmap.cc:49

◆ use_incremental_compiler()

bool dart::bin::DFE::use_incremental_compiler ( ) const
inline

Definition at line 47 of file dfe.h.

47{ return use_incremental_compiler_; }

◆ UseDartFrontend()

bool dart::bin::DFE::UseDartFrontend ( ) const
inline

Definition at line 42 of file dfe.h.

42{ return use_dfe_; }

◆ verbosity()

Dart_KernelCompilationVerbosityLevel dart::bin::DFE::verbosity ( ) const
inline

Definition at line 52 of file dfe.h.

52{ return verbosity_; }

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