Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
4f6462bc
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
未验证
提交
4f6462bc
编写于
4月 13, 2021
作者:
G
gaaclarke
提交者:
GitHub
4月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Made sure not to delete handles of dart objects if the isolate has been deleted (#25506)
上级
dade70a0
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
124 addition
and
9 deletion
+124
-9
runtime/dart_isolate.cc
runtime/dart_isolate.cc
+9
-1
runtime/dart_isolate.h
runtime/dart_isolate.h
+4
-0
runtime/dart_isolate_unittests.cc
runtime/dart_isolate_unittests.cc
+1
-0
testing/dart_isolate_runner.cc
testing/dart_isolate_runner.cc
+14
-1
testing/dart_isolate_runner.h
testing/dart_isolate_runner.h
+2
-0
third_party/tonic/dart_persistent_value.cc
third_party/tonic/dart_persistent_value.cc
+12
-5
third_party/tonic/tests/BUILD.gn
third_party/tonic/tests/BUILD.gn
+1
-0
third_party/tonic/tests/dart_persistent_handle_unittest.cc
third_party/tonic/tests/dart_persistent_handle_unittest.cc
+77
-0
third_party/tonic/tests/dart_weak_persistent_handle_unittest.cc
...party/tonic/tests/dart_weak_persistent_handle_unittest.cc
+4
-2
未找到文件。
runtime/dart_isolate.cc
浏览文件 @
4f6462bc
...
@@ -203,6 +203,12 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
...
@@ -203,6 +203,12 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
return
isolate
;
return
isolate
;
}
}
void
DartIsolate
::
SpawnIsolateShutdownCallback
(
std
::
shared_ptr
<
DartIsolateGroupData
>*
isolate_group_data
,
std
::
shared_ptr
<
DartIsolate
>*
isolate_data
)
{
DartIsolate
::
DartIsolateShutdownCallback
(
isolate_group_data
,
isolate_data
);
}
std
::
weak_ptr
<
DartIsolate
>
DartIsolate
::
CreateRootIsolate
(
std
::
weak_ptr
<
DartIsolate
>
DartIsolate
::
CreateRootIsolate
(
const
Settings
&
settings
,
const
Settings
&
settings
,
fml
::
RefPtr
<
const
DartSnapshot
>
isolate_snapshot
,
fml
::
RefPtr
<
const
DartSnapshot
>
isolate_snapshot
,
...
@@ -267,7 +273,9 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
...
@@ -267,7 +273,9 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
return
Dart_CreateIsolateInGroup
(
return
Dart_CreateIsolateInGroup
(
/*group_member=*/
spawning_isolate
->
isolate
(),
/*group_member=*/
spawning_isolate
->
isolate
(),
/*name=*/
(
*
isolate_group_data
)
->
GetAdvisoryScriptEntrypoint
().
c_str
(),
/*name=*/
(
*
isolate_group_data
)
->
GetAdvisoryScriptEntrypoint
().
c_str
(),
/*shutdown_callback=*/
nullptr
,
/*shutdown_callback=*/
reinterpret_cast
<
Dart_IsolateShutdownCallback
>
(
DartIsolate
::
SpawnIsolateShutdownCallback
),
/*cleanup_callback=*/
nullptr
,
/*cleanup_callback=*/
nullptr
,
/*child_isolate_data=*/
isolate_data
,
/*child_isolate_data=*/
isolate_data
,
/*error=*/
error
);
/*error=*/
error
);
...
...
runtime/dart_isolate.h
浏览文件 @
4f6462bc
...
@@ -552,6 +552,10 @@ class DartIsolate : public UIDartState {
...
@@ -552,6 +552,10 @@ class DartIsolate : public UIDartState {
// |Dart_DeferredLoadHandler|
// |Dart_DeferredLoadHandler|
static
Dart_Handle
OnDartLoadLibrary
(
intptr_t
loading_unit_id
);
static
Dart_Handle
OnDartLoadLibrary
(
intptr_t
loading_unit_id
);
static
void
SpawnIsolateShutdownCallback
(
std
::
shared_ptr
<
DartIsolateGroupData
>*
isolate_group_data
,
std
::
shared_ptr
<
DartIsolate
>*
isolate_data
);
FML_DISALLOW_COPY_AND_ASSIGN
(
DartIsolate
);
FML_DISALLOW_COPY_AND_ASSIGN
(
DartIsolate
);
};
};
...
...
runtime/dart_isolate_unittests.cc
浏览文件 @
4f6462bc
...
@@ -153,6 +153,7 @@ TEST_F(DartIsolateTest, SpawnIsolate) {
...
@@ -153,6 +153,7 @@ TEST_F(DartIsolateTest, SpawnIsolate) {
}
}
ASSERT_TRUE
(
spawn
->
Shutdown
());
ASSERT_TRUE
(
spawn
->
Shutdown
());
ASSERT_TRUE
(
spawn
->
IsShuttingDown
());
ASSERT_TRUE
(
root_isolate
->
Shutdown
());
ASSERT_TRUE
(
root_isolate
->
Shutdown
());
}
}
...
...
testing/dart_isolate_runner.cc
浏览文件 @
4f6462bc
...
@@ -13,12 +13,25 @@ AutoIsolateShutdown::AutoIsolateShutdown(std::shared_ptr<DartIsolate> isolate,
...
@@ -13,12 +13,25 @@ AutoIsolateShutdown::AutoIsolateShutdown(std::shared_ptr<DartIsolate> isolate,
:
isolate_
(
std
::
move
(
isolate
)),
runner_
(
std
::
move
(
runner
))
{}
:
isolate_
(
std
::
move
(
isolate
)),
runner_
(
std
::
move
(
runner
))
{}
AutoIsolateShutdown
::~
AutoIsolateShutdown
()
{
AutoIsolateShutdown
::~
AutoIsolateShutdown
()
{
if
(
!
isolate_
->
IsShuttingDown
())
{
Shutdown
();
}
fml
::
AutoResetWaitableEvent
latch
;
fml
::
TaskRunner
::
RunNowOrPostTask
(
runner_
,
[
isolate
=
std
::
move
(
isolate_
),
&
latch
]()
{
// Delete isolate on thread.
latch
.
Signal
();
});
latch
.
Wait
();
}
void
AutoIsolateShutdown
::
Shutdown
()
{
if
(
!
IsValid
())
{
if
(
!
IsValid
())
{
return
;
return
;
}
}
fml
::
AutoResetWaitableEvent
latch
;
fml
::
AutoResetWaitableEvent
latch
;
fml
::
TaskRunner
::
RunNowOrPostTask
(
fml
::
TaskRunner
::
RunNowOrPostTask
(
runner_
,
[
isolate
=
std
::
move
(
isolate_
),
&
latch
]()
{
runner_
,
[
isolate
=
isolate_
.
get
(
),
&
latch
]()
{
if
(
!
isolate
->
Shutdown
())
{
if
(
!
isolate
->
Shutdown
())
{
FML_LOG
(
ERROR
)
<<
"Could not shutdown isolate."
;
FML_LOG
(
ERROR
)
<<
"Could not shutdown isolate."
;
FML_CHECK
(
false
);
FML_CHECK
(
false
);
...
...
testing/dart_isolate_runner.h
浏览文件 @
4f6462bc
...
@@ -30,6 +30,8 @@ class AutoIsolateShutdown {
...
@@ -30,6 +30,8 @@ class AutoIsolateShutdown {
[[
nodiscard
]]
bool
RunInIsolateScope
(
std
::
function
<
bool
(
void
)
>
closure
);
[[
nodiscard
]]
bool
RunInIsolateScope
(
std
::
function
<
bool
(
void
)
>
closure
);
void
Shutdown
();
DartIsolate
*
get
()
{
DartIsolate
*
get
()
{
FML_CHECK
(
isolate_
);
FML_CHECK
(
isolate_
);
return
isolate_
.
get
();
return
isolate_
.
get
();
...
...
third_party/tonic/dart_persistent_value.cc
浏览文件 @
4f6462bc
...
@@ -43,12 +43,19 @@ void DartPersistentValue::Clear() {
...
@@ -43,12 +43,19 @@ void DartPersistentValue::Clear() {
return
;
return
;
}
}
if
(
Dart_CurrentIsolateGroup
())
{
/// TODO(80155): Remove the handle even if the isolate is shutting down. This
Dart_DeletePersistentHandle
(
value_
);
/// may cause memory to stick around until the isolate group is destroyed.
}
else
{
/// Without this branch, if DartState::IsShuttingDown == true, this code will
DartIsolateScope
scope
(
dart_state
->
isolate
());
/// crash when binding the isolate.
Dart_DeletePersistentHandle
(
value_
);
if
(
!
dart_state
->
IsShuttingDown
())
{
if
(
Dart_CurrentIsolateGroup
())
{
Dart_DeletePersistentHandle
(
value_
);
}
else
{
DartIsolateScope
scope
(
dart_state
->
isolate
());
Dart_DeletePersistentHandle
(
value_
);
}
}
}
dart_state_
.
reset
();
dart_state_
.
reset
();
value_
=
nullptr
;
value_
=
nullptr
;
}
}
...
...
third_party/tonic/tests/BUILD.gn
浏览文件 @
4f6462bc
...
@@ -15,6 +15,7 @@ executable("tonic_unittests") {
...
@@ -15,6 +15,7 @@ executable("tonic_unittests") {
public_configs = [ "//flutter:export_dynamic_symbols" ]
public_configs = [ "//flutter:export_dynamic_symbols" ]
sources = [
sources = [
"dart_persistent_handle_unittest.cc",
"dart_state_unittest.cc",
"dart_state_unittest.cc",
"dart_weak_persistent_handle_unittest.cc",
"dart_weak_persistent_handle_unittest.cc",
]
]
...
...
third_party/tonic/tests/dart_persistent_handle_unittest.cc
0 → 100644
浏览文件 @
4f6462bc
// 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/testing/dart_isolate_runner.h"
#include "flutter/testing/fixture_test.h"
namespace
flutter
{
namespace
testing
{
class
DartPersistentHandleTest
:
public
FixtureTest
{
public:
DartPersistentHandleTest
()
:
settings_
(
CreateSettingsForFixture
()),
vm_
(
DartVMRef
::
Create
(
settings_
)),
thread_
(
CreateNewThread
()),
task_runners_
(
GetCurrentTestName
(),
thread_
,
thread_
,
thread_
,
thread_
)
{}
~
DartPersistentHandleTest
()
=
default
;
[[
nodiscard
]]
bool
RunWithEntrypoint
(
const
std
::
string
&
entrypoint
)
{
if
(
running_isolate_
)
{
return
false
;
}
auto
isolate
=
RunDartCodeInIsolate
(
vm_
,
settings_
,
task_runners_
,
entrypoint
,
{},
GetFixturesPath
());
if
(
!
isolate
||
isolate
->
get
()
->
GetPhase
()
!=
DartIsolate
::
Phase
::
Running
)
{
return
false
;
}
running_isolate_
=
std
::
move
(
isolate
);
return
true
;
}
protected:
Settings
settings_
;
DartVMRef
vm_
;
std
::
unique_ptr
<
AutoIsolateShutdown
>
running_isolate_
;
fml
::
RefPtr
<
fml
::
TaskRunner
>
thread_
;
TaskRunners
task_runners_
;
FML_DISALLOW_COPY_AND_ASSIGN
(
DartPersistentHandleTest
);
};
TEST_F
(
DartPersistentHandleTest
,
ClearAfterShutdown
)
{
auto
persistent_value
=
tonic
::
DartPersistentValue
();
fml
::
AutoResetWaitableEvent
event
;
AddNativeCallback
(
"GiveObjectToNative"
,
CREATE_NATIVE_ENTRY
([
&
](
Dart_NativeArguments
args
)
{
auto
handle
=
Dart_GetNativeArgument
(
args
,
0
);
auto
dart_state
=
tonic
::
DartState
::
Current
();
ASSERT_TRUE
(
dart_state
);
ASSERT_TRUE
(
tonic
::
DartState
::
Current
());
persistent_value
.
Set
(
dart_state
,
handle
);
event
.
Signal
();
}));
ASSERT_TRUE
(
RunWithEntrypoint
(
"callGiveObjectToNative"
));
event
.
Wait
();
running_isolate_
->
Shutdown
();
fml
::
AutoResetWaitableEvent
clear
;
task_runners_
.
GetUITaskRunner
()
->
PostTask
([
&
]
{
persistent_value
.
Clear
();
clear
.
Signal
();
});
clear
.
Wait
();
}
}
// namespace testing
}
// namespace flutter
third_party/tonic/tests/dart_weak_persistent_handle_unittest.cc
浏览文件 @
4f6462bc
...
@@ -8,6 +8,10 @@
...
@@ -8,6 +8,10 @@
namespace
flutter
{
namespace
flutter
{
namespace
testing
{
namespace
testing
{
namespace
{
void
NopFinalizer
(
void
*
isolate_callback_data
,
void
*
peer
)
{}
}
// namespace
class
DartWeakPersistentHandle
:
public
FixtureTest
{
class
DartWeakPersistentHandle
:
public
FixtureTest
{
public:
public:
DartWeakPersistentHandle
()
DartWeakPersistentHandle
()
...
@@ -45,8 +49,6 @@ class DartWeakPersistentHandle : public FixtureTest {
...
@@ -45,8 +49,6 @@ class DartWeakPersistentHandle : public FixtureTest {
FML_DISALLOW_COPY_AND_ASSIGN
(
DartWeakPersistentHandle
);
FML_DISALLOW_COPY_AND_ASSIGN
(
DartWeakPersistentHandle
);
};
};
void
NopFinalizer
(
void
*
isolate_callback_data
,
void
*
peer
)
{}
TEST_F
(
DartWeakPersistentHandle
,
ClearImmediately
)
{
TEST_F
(
DartWeakPersistentHandle
,
ClearImmediately
)
{
auto
weak_persistent_value
=
tonic
::
DartWeakPersistentValue
();
auto
weak_persistent_value
=
tonic
::
DartWeakPersistentValue
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录