Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
905ddb6c
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
905ddb6c
编写于
4月 18, 2019
作者:
C
Chinmay Garde
提交者:
GitHub
4月 18, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove DartSnapshotBuffer and dry up snapshot resolution logic. (#8640)
Fixes
https://github.com/flutter/flutter/issues/26782
.
上级
3e597e1d
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
191 addition
and
315 deletion
+191
-315
ci/licenses_golden/licenses_flutter
ci/licenses_golden/licenses_flutter
+0
-2
fml/mapping.cc
fml/mapping.cc
+41
-0
fml/mapping.h
fml/mapping.h
+30
-3
runtime/BUILD.gn
runtime/BUILD.gn
+0
-2
runtime/dart_isolate.cc
runtime/dart_isolate.cc
+5
-8
runtime/dart_snapshot.cc
runtime/dart_snapshot.cc
+107
-139
runtime/dart_snapshot.h
runtime/dart_snapshot.h
+6
-11
runtime/dart_snapshot_buffer.cc
runtime/dart_snapshot_buffer.cc
+0
-102
runtime/dart_snapshot_buffer.h
runtime/dart_snapshot_buffer.h
+0
-45
runtime/dart_vm.cc
runtime/dart_vm.cc
+2
-3
未找到文件。
ci/licenses_golden/licenses_flutter
浏览文件 @
905ddb6c
...
...
@@ -383,8 +383,6 @@ FILE: ../../../flutter/runtime/dart_service_isolate.h
FILE: ../../../flutter/runtime/dart_service_isolate_unittests.cc
FILE: ../../../flutter/runtime/dart_snapshot.cc
FILE: ../../../flutter/runtime/dart_snapshot.h
FILE: ../../../flutter/runtime/dart_snapshot_buffer.cc
FILE: ../../../flutter/runtime/dart_snapshot_buffer.h
FILE: ../../../flutter/runtime/dart_vm.cc
FILE: ../../../flutter/runtime/dart_vm.h
FILE: ../../../flutter/runtime/dart_vm_data.cc
...
...
fml/mapping.cc
浏览文件 @
905ddb6c
...
...
@@ -4,12 +4,18 @@
#include "flutter/fml/mapping.h"
#include <sstream>
namespace
fml
{
// FileMapping
uint8_t
*
FileMapping
::
GetMutableMapping
()
{
return
mutable_mapping_
;
}
// Data Mapping
DataMapping
::
DataMapping
(
std
::
vector
<
uint8_t
>
data
)
:
data_
(
std
::
move
(
data
))
{}
DataMapping
::~
DataMapping
()
=
default
;
...
...
@@ -22,6 +28,8 @@ const uint8_t* DataMapping::GetMapping() const {
return
data_
.
data
();
}
// NonOwnedMapping
size_t
NonOwnedMapping
::
GetSize
()
const
{
return
size_
;
}
...
...
@@ -30,4 +38,37 @@ const uint8_t* NonOwnedMapping::GetMapping() const {
return
data_
;
}
// Symbol Mapping
SymbolMapping
::
SymbolMapping
(
fml
::
RefPtr
<
fml
::
NativeLibrary
>
native_library
,
const
char
*
symbol_name
)
:
native_library_
(
std
::
move
(
native_library
))
{
if
(
native_library_
&&
symbol_name
!=
nullptr
)
{
mapping_
=
native_library_
->
ResolveSymbol
(
symbol_name
);
if
(
mapping_
==
nullptr
)
{
// Apparently, dart_bootstrap seems to account for the Mac behavior of
// requiring the underscore prefixed symbol name on non-Mac platforms as
// well. As a fallback, check the underscore prefixed variant of the
// symbol name and allow callers to not have handle this on a per platform
// toolchain quirk basis.
std
::
stringstream
underscore_symbol_name
;
underscore_symbol_name
<<
"_"
<<
symbol_name
;
mapping_
=
native_library_
->
ResolveSymbol
(
underscore_symbol_name
.
str
().
c_str
());
}
}
}
SymbolMapping
::~
SymbolMapping
()
=
default
;
size_t
SymbolMapping
::
GetSize
()
const
{
return
0
;
}
const
uint8_t
*
SymbolMapping
::
GetMapping
()
const
{
return
mapping_
;
}
}
// namespace fml
fml/mapping.h
浏览文件 @
905ddb6c
...
...
@@ -13,6 +13,7 @@
#include "flutter/fml/build_config.h"
#include "flutter/fml/file.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/native_library.h"
#include "flutter/fml/unique_fd.h"
namespace
fml
{
...
...
@@ -31,7 +32,7 @@ class Mapping {
FML_DISALLOW_COPY_AND_ASSIGN
(
Mapping
);
};
class
FileMapping
:
public
Mapping
{
class
FileMapping
final
:
public
Mapping
{
public:
enum
class
Protection
{
kRead
,
...
...
@@ -45,8 +46,10 @@ class FileMapping : public Mapping {
~
FileMapping
()
override
;
// |Mapping|
size_t
GetSize
()
const
override
;
// |Mapping|
const
uint8_t
*
GetMapping
()
const
override
;
uint8_t
*
GetMutableMapping
();
...
...
@@ -63,14 +66,16 @@ class FileMapping : public Mapping {
FML_DISALLOW_COPY_AND_ASSIGN
(
FileMapping
);
};
class
DataMapping
:
public
Mapping
{
class
DataMapping
final
:
public
Mapping
{
public:
DataMapping
(
std
::
vector
<
uint8_t
>
data
);
~
DataMapping
()
override
;
// |Mapping|
size_t
GetSize
()
const
override
;
// |Mapping|
const
uint8_t
*
GetMapping
()
const
override
;
private:
...
...
@@ -79,13 +84,15 @@ class DataMapping : public Mapping {
FML_DISALLOW_COPY_AND_ASSIGN
(
DataMapping
);
};
class
NonOwnedMapping
:
public
Mapping
{
class
NonOwnedMapping
final
:
public
Mapping
{
public:
NonOwnedMapping
(
const
uint8_t
*
data
,
size_t
size
)
:
data_
(
data
),
size_
(
size
)
{}
// |Mapping|
size_t
GetSize
()
const
override
;
// |Mapping|
const
uint8_t
*
GetMapping
()
const
override
;
private:
...
...
@@ -95,6 +102,26 @@ class NonOwnedMapping : public Mapping {
FML_DISALLOW_COPY_AND_ASSIGN
(
NonOwnedMapping
);
};
class
SymbolMapping
final
:
public
Mapping
{
public:
SymbolMapping
(
fml
::
RefPtr
<
fml
::
NativeLibrary
>
native_library
,
const
char
*
symbol_name
);
~
SymbolMapping
()
override
;
// |Mapping|
size_t
GetSize
()
const
override
;
// |Mapping|
const
uint8_t
*
GetMapping
()
const
override
;
private:
fml
::
RefPtr
<
fml
::
NativeLibrary
>
native_library_
;
const
uint8_t
*
mapping_
=
nullptr
;
FML_DISALLOW_COPY_AND_ASSIGN
(
SymbolMapping
);
};
}
// namespace fml
#endif // FLUTTER_FML_MAPPING_H_
runtime/BUILD.gn
浏览文件 @
905ddb6c
...
...
@@ -46,8 +46,6 @@ source_set("runtime") {
"dart_service_isolate.h",
"dart_snapshot.cc",
"dart_snapshot.h",
"dart_snapshot_buffer.cc",
"dart_snapshot_buffer.h",
"dart_vm.cc",
"dart_vm.h",
"dart_vm_data.cc",
...
...
runtime/dart_isolate.cc
浏览文件 @
905ddb6c
...
...
@@ -679,14 +679,11 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair(
Dart_Isolate
isolate
=
Dart_CreateIsolate
(
advisory_script_uri
,
//
advisory_script_entrypoint
,
//
(
*
embedder_isolate
)
->
GetIsolateSnapshot
()
->
GetData
()
->
GetSnapshotPointer
(),
(
*
embedder_isolate
)
->
GetIsolateSnapshot
()
->
GetInstructionsIfPresent
(),
(
*
embedder_isolate
)
->
GetSharedSnapshot
()
->
GetDataIfPresent
(),
(
*
embedder_isolate
)
->
GetSharedSnapshot
()
->
GetInstructionsIfPresent
(),
flags
,
embedder_isolate
.
get
(),
error
);
(
*
embedder_isolate
)
->
GetIsolateSnapshot
()
->
GetDataMapping
(),
(
*
embedder_isolate
)
->
GetIsolateSnapshot
()
->
GetInstructionsMapping
(),
(
*
embedder_isolate
)
->
GetSharedSnapshot
()
->
GetDataMapping
(),
(
*
embedder_isolate
)
->
GetSharedSnapshot
()
->
GetInstructionsMapping
(),
flags
,
embedder_isolate
.
get
(),
error
);
if
(
isolate
==
nullptr
)
{
FML_DLOG
(
ERROR
)
<<
*
error
;
...
...
runtime/dart_snapshot.cc
浏览文件 @
905ddb6c
...
...
@@ -10,7 +10,6 @@
#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
#include "flutter/lib/snapshot/snapshot.h"
#include "flutter/runtime/dart_snapshot_buffer.h"
#include "flutter/runtime/dart_vm.h"
namespace
flutter
{
...
...
@@ -21,151 +20,137 @@ const char* DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData";
const
char
*
DartSnapshot
::
kIsolateInstructionsSymbol
=
"kDartIsolateSnapshotInstructions"
;
#if defined(OS_ANDROID)
// When assembling the .S file of the application, dart_bootstrap will prefix
// symbols via an `_` to ensure Mac's `dlsym()` can find it (Mac ABI prefixes C
// symbols with underscores).
// But Linux ABI does not prefix C symbols with underscores, so we have to
// explicitly look up the prefixed version.
#define SYMBOL_PREFIX "_"
#else
#define SYMBOL_PREFIX ""
#endif
static
const
char
*
kVMDataSymbolSo
=
SYMBOL_PREFIX
"kDartVmSnapshotData"
;
static
const
char
*
kVMInstructionsSymbolSo
=
SYMBOL_PREFIX
"kDartVmSnapshotInstructions"
;
static
const
char
*
kIsolateDataSymbolSo
=
SYMBOL_PREFIX
"kDartIsolateSnapshotData"
;
static
const
char
*
kIsolateInstructionsSymbolSo
=
SYMBOL_PREFIX
"kDartIsolateSnapshotInstructions"
;
std
::
unique_ptr
<
DartSnapshotBuffer
>
ResolveVMData
(
const
Settings
&
settings
)
{
if
(
settings
.
vm_snapshot_data
)
{
return
DartSnapshotBuffer
::
CreateWithMapping
(
settings
.
vm_snapshot_data
());
static
std
::
unique_ptr
<
const
fml
::
Mapping
>
GetFileMapping
(
const
std
::
string
path
,
bool
executable
)
{
fml
::
UniqueFD
file
=
fml
::
OpenFile
(
path
.
c_str
(),
// file path
false
,
// create file if necessary
fml
::
FilePermission
::
kRead
// file permissions
);
if
(
!
file
.
is_valid
())
{
return
nullptr
;
}
if
(
settings
.
vm_snapshot_data_path
.
size
()
>
0
)
{
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithContentsOfFile
(
fml
::
OpenFile
(
settings
.
vm_snapshot_data_path
.
c_str
(),
false
,
fml
::
FilePermission
::
kRead
),
{
fml
::
FileMapping
::
Protection
::
kRead
}))
{
return
source
;
}
using
Prot
=
fml
::
FileMapping
::
Protection
;
std
::
unique_ptr
<
fml
::
FileMapping
>
mapping
;
if
(
executable
)
{
mapping
=
std
::
make_unique
<
fml
::
FileMapping
>
(
file
,
std
::
initializer_list
<
Prot
>
{
Prot
::
kRead
,
Prot
::
kExecute
});
}
else
{
mapping
=
std
::
make_unique
<
fml
::
FileMapping
>
(
file
,
std
::
initializer_list
<
Prot
>
{
Prot
::
kRead
});
}
if
(
settings
.
application_library_path
.
size
()
>
0
)
{
auto
shared_library
=
fml
::
NativeLibrary
::
Create
(
settings
.
application_library_path
.
c_str
());
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
shared_library
,
kVMDataSymbolSo
))
{
return
source
;
}
if
(
mapping
->
GetSize
()
==
0
||
mapping
->
GetMapping
()
==
nullptr
)
{
return
nullptr
;
}
auto
loaded_process
=
fml
::
NativeLibrary
::
CreateForCurrentProcess
();
return
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
loaded_process
,
DartSnapshot
::
kVMDataSymbol
);
return
mapping
;
}
std
::
unique_ptr
<
DartSnapshotBuffer
>
ResolveVMInstructions
(
const
Settings
&
settings
)
{
if
(
settings
.
vm_snapshot_instr
)
{
return
DartSnapshotBuffer
::
CreateWithMapping
(
settings
.
vm_snapshot_instr
());
// The first party embedders don't yet use the stable embedder API and depend on
// the engine figuring out the locations of the various heap and instructions
// buffers. Consequently, the engine had baked in opinions about where these
// buffers would reside and how they would be packaged (examples, in an external
// dylib, in the same dylib, at a path, at a path relative to and FD, etc..). As
// the needs of the platforms changed, the lack of an API meant that the engine
// had to be patched to look for new fields in the settings object. This grew
// untenable and with the addition of the new Fuchsia embedder and the generic C
// embedder API, embedders could specify the mapping directly. Once everyone
// moves to the embedder API, this method can effectively be reduced to just
// invoking the embedder_mapping_callback directly.
static
std
::
shared_ptr
<
const
fml
::
Mapping
>
SearchMapping
(
MappingCallback
embedder_mapping_callback
,
const
std
::
string
&
file_path
,
const
std
::
string
&
native_library_path
,
const
char
*
native_library_symbol_name
,
bool
is_executable
)
{
// Ask the embedder. There is no fallback as we expect the embedders (via
// their embedding APIs) to just specify the mappings directly.
if
(
embedder_mapping_callback
)
{
return
embedder_mapping_callback
();
}
if
(
settings
.
vm_snapshot_instr_path
.
size
()
>
0
)
{
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithContentsOfFile
(
fml
::
OpenFile
(
settings
.
vm_snapshot_instr_path
.
c_str
(),
false
,
fml
::
FilePermission
::
kRead
),
{
fml
::
FileMapping
::
Protection
::
kExecute
}))
{
return
source
;
// Attempt to open file at path specified.
if
(
file_path
.
size
()
>
0
)
{
if
(
auto
file_mapping
=
GetFileMapping
(
file_path
,
is_executable
))
{
return
file_mapping
;
}
}
if
(
settings
.
application_library_path
.
size
()
>
0
)
{
auto
library
=
fml
::
NativeLibrary
::
Create
(
settings
.
application_library_path
.
c_str
());
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
library
,
kVMInstructionsSymbolSo
))
{
return
source
;
// Look in application specified native library if specified.
if
(
native_library_path
.
size
()
>
0
)
{
auto
native_library
=
fml
::
NativeLibrary
::
Create
(
native_library_path
.
c_str
());
auto
symbol_mapping
=
std
::
make_unique
<
const
fml
::
SymbolMapping
>
(
native_library
,
native_library_symbol_name
);
if
(
symbol_mapping
->
GetMapping
()
!=
nullptr
)
{
return
symbol_mapping
;
}
}
auto
loaded_process
=
fml
::
NativeLibrary
::
CreateForCurrentProcess
();
return
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
loaded_process
,
DartSnapshot
::
kVMInstructionsSymbol
);
}
std
::
unique_ptr
<
DartSnapshotBuffer
>
ResolveIsolateData
(
const
Settings
&
settings
)
{
if
(
settings
.
isolate_snapshot_data
)
{
return
DartSnapshotBuffer
::
CreateWithMapping
(
settings
.
isolate_snapshot_data
());
}
if
(
settings
.
isolate_snapshot_data_path
.
size
()
>
0
)
{
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithContentsOfFile
(
fml
::
OpenFile
(
settings
.
isolate_snapshot_data_path
.
c_str
(),
false
,
fml
::
FilePermission
::
kRead
),
{
fml
::
FileMapping
::
Protection
::
kRead
}))
{
return
source
;
// Look inside the currently loaded process.
{
auto
loaded_process
=
fml
::
NativeLibrary
::
CreateForCurrentProcess
();
auto
symbol_mapping
=
std
::
make_unique
<
const
fml
::
SymbolMapping
>
(
loaded_process
,
native_library_symbol_name
);
if
(
symbol_mapping
->
GetMapping
()
!=
nullptr
)
{
return
symbol_mapping
;
}
}
if
(
settings
.
application_library_path
.
size
()
>
0
)
{
auto
library
=
fml
::
NativeLibrary
::
Create
(
settings
.
application_library_path
.
c_str
());
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
library
,
kIsolateDataSymbolSo
))
{
return
source
;
}
}
auto
loaded_process
=
fml
::
NativeLibrary
::
CreateForCurrentProcess
();
return
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
loaded_process
,
DartSnapshot
::
kIsolateDataSymbol
);
return
nullptr
;
}
st
d
::
unique_ptr
<
DartSnapshotBuffer
>
ResolveIsolateInstructions
(
st
atic
std
::
shared_ptr
<
const
fml
::
Mapping
>
ResolveVMData
(
const
Settings
&
settings
)
{
if
(
settings
.
isolate_snapshot_data
)
{
return
DartSnapshotBuffer
::
CreateWithMapping
(
settings
.
isolate_snapshot_instr
());
}
return
SearchMapping
(
settings
.
vm_snapshot_data
,
// embedder_mapping_callback
settings
.
vm_snapshot_data_path
,
// file_path
settings
.
application_library_path
,
// native_library_path
DartSnapshot
::
kVMDataSymbol
,
// native_library_symbol_name
false
// is_executable
);
}
if
(
settings
.
isolate_snapshot_instr_path
.
size
()
>
0
)
{
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithContentsOfFile
(
fml
::
OpenFile
(
settings
.
isolate_snapshot_instr_path
.
c_str
(),
false
,
fml
::
FilePermission
::
kRead
),
{
fml
::
FileMapping
::
Protection
::
kExecute
}))
{
return
source
;
}
}
static
std
::
shared_ptr
<
const
fml
::
Mapping
>
ResolveVMInstructions
(
const
Settings
&
settings
)
{
return
SearchMapping
(
settings
.
vm_snapshot_instr
,
// embedder_mapping_callback
settings
.
vm_snapshot_instr_path
,
// file_path
settings
.
application_library_path
,
// native_library_path
DartSnapshot
::
kVMInstructionsSymbol
,
// native_library_symbol_name
true
// is_executable
);
}
if
(
settings
.
application_library_path
.
size
()
>
0
)
{
auto
library
=
fml
::
NativeLibrary
::
Create
(
settings
.
application_library_path
.
c_str
());
if
(
auto
source
=
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
library
,
kIsolateInstructionsSymbolSo
))
{
return
source
;
}
}
static
std
::
shared_ptr
<
const
fml
::
Mapping
>
ResolveIsolateData
(
const
Settings
&
settings
)
{
return
SearchMapping
(
settings
.
isolate_snapshot_data
,
// embedder_mapping_callback
settings
.
isolate_snapshot_data_path
,
// file_path
settings
.
application_library_path
,
// native_library_path
DartSnapshot
::
kIsolateDataSymbol
,
// native_library_symbol_name
false
// is_executable
);
}
auto
loaded_process
=
fml
::
NativeLibrary
::
CreateForCurrentProcess
();
return
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
loaded_process
,
DartSnapshot
::
kIsolateInstructionsSymbol
);
static
std
::
shared_ptr
<
const
fml
::
Mapping
>
ResolveIsolateInstructions
(
const
Settings
&
settings
)
{
return
SearchMapping
(
settings
.
isolate_snapshot_instr
,
// embedder_mapping_callback
settings
.
isolate_snapshot_instr_path
,
// file_path
settings
.
application_library_path
,
// native_library_path
DartSnapshot
::
kIsolateInstructionsSymbol
,
// native_library_symbol_name
true
// is_executable
);
}
fml
::
RefPtr
<
DartSnapshot
>
DartSnapshot
::
VMSnapshotFromSettings
(
const
Settings
&
settings
)
{
TRACE_EVENT0
(
"flutter"
,
"DartSnapshot::VMSnapshotFromSettings"
);
#if OS_WIN
return
fml
::
MakeRefCounted
<
DartSnapshot
>
(
DartSnapshotBuffer
::
CreateWithUnmanagedAllocation
(
kDartVmSnapshotData
),
DartSnapshotBuffer
::
CreateWithUnmanagedAllocation
(
kDartVmSnapshotInstructions
));
#else // OS_WIN
auto
snapshot
=
fml
::
MakeRefCounted
<
DartSnapshot
>
(
ResolveVMData
(
settings
),
//
ResolveVMInstructions
(
settings
)
//
...
...
@@ -174,19 +159,11 @@ fml::RefPtr<DartSnapshot> DartSnapshot::VMSnapshotFromSettings(
return
snapshot
;
}
return
nullptr
;
#endif // OS_WIN
}
fml
::
RefPtr
<
DartSnapshot
>
DartSnapshot
::
IsolateSnapshotFromSettings
(
const
Settings
&
settings
)
{
TRACE_EVENT0
(
"flutter"
,
"DartSnapshot::IsolateSnapshotFromSettings"
);
#if OS_WIN
return
fml
::
MakeRefCounted
<
DartSnapshot
>
(
DartSnapshotBuffer
::
CreateWithUnmanagedAllocation
(
kDartIsolateSnapshotData
),
DartSnapshotBuffer
::
CreateWithUnmanagedAllocation
(
kDartIsolateSnapshotInstructions
));
#else // OS_WIN
auto
snapshot
=
fml
::
MakeRefCounted
<
DartSnapshot
>
(
ResolveIsolateData
(
settings
),
//
ResolveIsolateInstructions
(
settings
)
//
...
...
@@ -195,15 +172,14 @@ fml::RefPtr<DartSnapshot> DartSnapshot::IsolateSnapshotFromSettings(
return
snapshot
;
}
return
nullptr
;
#endif
}
fml
::
RefPtr
<
DartSnapshot
>
DartSnapshot
::
Empty
()
{
return
fml
::
MakeRefCounted
<
DartSnapshot
>
(
nullptr
,
nullptr
);
}
DartSnapshot
::
DartSnapshot
(
std
::
unique_ptr
<
DartSnapshotBuffer
>
data
,
std
::
unique_ptr
<
DartSnapshotBuffer
>
instructions
)
DartSnapshot
::
DartSnapshot
(
std
::
shared_ptr
<
const
fml
::
Mapping
>
data
,
std
::
shared_ptr
<
const
fml
::
Mapping
>
instructions
)
:
data_
(
std
::
move
(
data
)),
instructions_
(
std
::
move
(
instructions
))
{}
DartSnapshot
::~
DartSnapshot
()
=
default
;
...
...
@@ -216,20 +192,12 @@ bool DartSnapshot::IsValidForAOT() const {
return
data_
&&
instructions_
;
}
const
DartSnapshotBuffer
*
DartSnapshot
::
GetData
()
const
{
return
data_
.
get
();
}
const
DartSnapshotBuffer
*
DartSnapshot
::
GetInstructions
()
const
{
return
instructions_
.
get
();
}
const
uint8_t
*
DartSnapshot
::
GetDataIfPresent
()
const
{
return
data_
?
data_
->
GetSnapshotPointer
()
:
nullptr
;
const
uint8_t
*
DartSnapshot
::
GetDataMapping
()
const
{
return
data_
?
data_
->
GetMapping
()
:
nullptr
;
}
const
uint8_t
*
DartSnapshot
::
GetInstructions
IfPresent
()
const
{
return
instructions_
?
instructions_
->
Get
SnapshotPointer
()
:
nullptr
;
const
uint8_t
*
DartSnapshot
::
GetInstructions
Mapping
()
const
{
return
instructions_
?
instructions_
->
Get
Mapping
()
:
nullptr
;
}
}
// namespace flutter
runtime/dart_snapshot.h
浏览文件 @
905ddb6c
...
...
@@ -11,7 +11,6 @@
#include "flutter/common/settings.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/runtime/dart_snapshot_buffer.h"
namespace
flutter
{
...
...
@@ -34,20 +33,16 @@ class DartSnapshot : public fml::RefCountedThreadSafe<DartSnapshot> {
bool
IsValidForAOT
()
const
;
const
DartSnapshotBuffer
*
GetData
()
const
;
const
uint8_t
*
GetDataMapping
()
const
;
const
DartSnapshotBuffer
*
GetInstructions
()
const
;
const
uint8_t
*
GetDataIfPresent
()
const
;
const
uint8_t
*
GetInstructionsIfPresent
()
const
;
const
uint8_t
*
GetInstructionsMapping
()
const
;
private:
std
::
unique_ptr
<
DartSnapshotBuffer
>
data_
;
std
::
unique_ptr
<
DartSnapshotBuffer
>
instructions_
;
std
::
shared_ptr
<
const
fml
::
Mapping
>
data_
;
std
::
shared_ptr
<
const
fml
::
Mapping
>
instructions_
;
DartSnapshot
(
std
::
unique_ptr
<
DartSnapshotBuffer
>
data
,
std
::
unique_ptr
<
DartSnapshotBuffer
>
instructions
);
DartSnapshot
(
std
::
shared_ptr
<
const
fml
::
Mapping
>
data
,
std
::
shared_ptr
<
const
fml
::
Mapping
>
instructions
);
~
DartSnapshot
();
...
...
runtime/dart_snapshot_buffer.cc
已删除
100644 → 0
浏览文件 @
3e597e1d
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/runtime/dart_snapshot_buffer.h"
#include <utility>
#include "flutter/fml/mapping.h"
namespace
flutter
{
class
NativeLibrarySnapshotBuffer
final
:
public
DartSnapshotBuffer
{
public:
NativeLibrarySnapshotBuffer
(
fml
::
RefPtr
<
fml
::
NativeLibrary
>
library
,
const
char
*
symbol_name
)
:
library_
(
std
::
move
(
library
))
{
if
(
library_
)
{
symbol_
=
library_
->
ResolveSymbol
(
symbol_name
);
}
}
const
uint8_t
*
GetSnapshotPointer
()
const
override
{
return
symbol_
;
}
size_t
GetSnapshotSize
()
const
override
{
return
0
;
}
private:
fml
::
RefPtr
<
fml
::
NativeLibrary
>
library_
;
const
uint8_t
*
symbol_
=
nullptr
;
FML_DISALLOW_COPY_AND_ASSIGN
(
NativeLibrarySnapshotBuffer
);
};
class
MappingBuffer
final
:
public
DartSnapshotBuffer
{
public:
MappingBuffer
(
std
::
unique_ptr
<
fml
::
Mapping
>
mapping
)
:
mapping_
(
std
::
move
(
mapping
))
{
FML_DCHECK
(
mapping_
);
}
const
uint8_t
*
GetSnapshotPointer
()
const
override
{
return
mapping_
->
GetMapping
();
}
size_t
GetSnapshotSize
()
const
override
{
return
mapping_
->
GetSize
();
}
private:
std
::
unique_ptr
<
fml
::
Mapping
>
mapping_
;
FML_DISALLOW_COPY_AND_ASSIGN
(
MappingBuffer
);
};
class
UnmanagedAllocation
final
:
public
DartSnapshotBuffer
{
public:
UnmanagedAllocation
(
const
uint8_t
*
allocation
)
:
allocation_
(
allocation
)
{}
const
uint8_t
*
GetSnapshotPointer
()
const
override
{
return
allocation_
;
}
size_t
GetSnapshotSize
()
const
override
{
return
0
;
}
private:
const
uint8_t
*
allocation_
;
FML_DISALLOW_COPY_AND_ASSIGN
(
UnmanagedAllocation
);
};
std
::
unique_ptr
<
DartSnapshotBuffer
>
DartSnapshotBuffer
::
CreateWithSymbolInLibrary
(
fml
::
RefPtr
<
fml
::
NativeLibrary
>
library
,
const
char
*
symbol_name
)
{
auto
source
=
std
::
make_unique
<
NativeLibrarySnapshotBuffer
>
(
std
::
move
(
library
),
symbol_name
);
return
source
->
GetSnapshotPointer
()
==
nullptr
?
nullptr
:
std
::
move
(
source
);
}
std
::
unique_ptr
<
DartSnapshotBuffer
>
DartSnapshotBuffer
::
CreateWithContentsOfFile
(
const
fml
::
UniqueFD
&
fd
,
std
::
initializer_list
<
fml
::
FileMapping
::
Protection
>
protection
)
{
return
CreateWithMapping
(
std
::
make_unique
<
fml
::
FileMapping
>
(
fd
,
protection
));
}
std
::
unique_ptr
<
DartSnapshotBuffer
>
DartSnapshotBuffer
::
CreateWithMapping
(
std
::
unique_ptr
<
fml
::
Mapping
>
mapping
)
{
if
(
mapping
==
nullptr
||
mapping
->
GetSize
()
==
0
||
mapping
->
GetMapping
()
==
nullptr
)
{
return
nullptr
;
}
return
std
::
make_unique
<
MappingBuffer
>
(
std
::
move
(
mapping
));
}
std
::
unique_ptr
<
DartSnapshotBuffer
>
DartSnapshotBuffer
::
CreateWithUnmanagedAllocation
(
const
uint8_t
*
allocation
)
{
if
(
allocation
==
nullptr
)
{
return
nullptr
;
}
return
std
::
make_unique
<
UnmanagedAllocation
>
(
allocation
);
}
DartSnapshotBuffer
::~
DartSnapshotBuffer
()
=
default
;
}
// namespace flutter
runtime/dart_snapshot_buffer.h
已删除
100644 → 0
浏览文件 @
3e597e1d
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_
#define FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_
#include <initializer_list>
#include <memory>
#include "flutter/fml/file.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/native_library.h"
namespace
flutter
{
// TODO(chinmaygarde): Replace this with just |fml::Mapping|.
// https://github.com/flutter/flutter/issues/26782
class
DartSnapshotBuffer
{
public:
static
std
::
unique_ptr
<
DartSnapshotBuffer
>
CreateWithSymbolInLibrary
(
fml
::
RefPtr
<
fml
::
NativeLibrary
>
library
,
const
char
*
symbol_name
);
static
std
::
unique_ptr
<
DartSnapshotBuffer
>
CreateWithContentsOfFile
(
const
fml
::
UniqueFD
&
fd
,
std
::
initializer_list
<
fml
::
FileMapping
::
Protection
>
protection
);
static
std
::
unique_ptr
<
DartSnapshotBuffer
>
CreateWithUnmanagedAllocation
(
const
uint8_t
*
allocation
);
static
std
::
unique_ptr
<
DartSnapshotBuffer
>
CreateWithMapping
(
std
::
unique_ptr
<
fml
::
Mapping
>
mapping
);
virtual
~
DartSnapshotBuffer
();
virtual
const
uint8_t
*
GetSnapshotPointer
()
const
=
0
;
virtual
size_t
GetSnapshotSize
()
const
=
0
;
};
}
// namespace flutter
#endif // FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_
runtime/dart_vm.cc
浏览文件 @
905ddb6c
...
...
@@ -371,10 +371,9 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
TRACE_EVENT0
(
"flutter"
,
"Dart_Initialize"
);
Dart_InitializeParams
params
=
{};
params
.
version
=
DART_INITIALIZE_PARAMS_CURRENT_VERSION
;
params
.
vm_snapshot_data
=
vm_data_
->
GetVMSnapshot
().
GetData
()
->
GetSnapshotPointer
();
params
.
vm_snapshot_data
=
vm_data_
->
GetVMSnapshot
().
GetDataMapping
();
params
.
vm_snapshot_instructions
=
vm_data_
->
GetVMSnapshot
().
GetInstructions
IfPresent
();
vm_data_
->
GetVMSnapshot
().
GetInstructions
Mapping
();
params
.
create
=
reinterpret_cast
<
decltype
(
params
.
create
)
>
(
DartIsolate
::
DartIsolateCreateCallback
);
params
.
shutdown
=
reinterpret_cast
<
decltype
(
params
.
shutdown
)
>
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录