Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
a668776f
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
11 个月 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a668776f
编写于
4月 14, 2023
作者:
马
马根堂
提交者:
Gitee
4月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remoteobject 内存管理优化
Signed-off-by:
N
马根堂
<
magentang4@huawei.com
>
上级
febbe275
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
17 addition
and
6 deletion
+17
-6
ipc/native/src/core/source/ipc_object_proxy.cpp
ipc/native/src/core/source/ipc_object_proxy.cpp
+1
-0
ipc/native/src/jni/source/ohos_rpc_remote_object.cpp
ipc/native/src/jni/source/ohos_rpc_remote_object.cpp
+2
-2
ipc/native/src/napi_common/include/napi_remote_object_holder.h
...ative/src/napi_common/include/napi_remote_object_holder.h
+1
-1
ipc/native/src/napi_common/source/napi_remote_object.cpp
ipc/native/src/napi_common/source/napi_remote_object.cpp
+7
-1
ipc/native/src/napi_common/source/napi_remote_object_holder.cpp
...tive/src/napi_common/source/napi_remote_object_holder.cpp
+6
-2
未找到文件。
ipc/native/src/core/source/ipc_object_proxy.cpp
浏览文件 @
a668776f
...
...
@@ -55,6 +55,7 @@ static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCObjec
IPCObjectProxy
::
IPCObjectProxy
(
int
handle
,
std
::
u16string
descriptor
,
int
proto
)
:
IRemoteObject
(
std
::
move
(
descriptor
)),
handle_
(
handle
),
proto_
(
proto
),
isFinishInit_
(
false
),
isRemoteDead_
(
false
)
{
ZLOGD
(
LABEL
,
"[mem_free]IPCObjectProxy create"
);
ExtendObjectLifetime
();
}
...
...
ipc/native/src/jni/source/ohos_rpc_remote_object.cpp
浏览文件 @
a668776f
...
...
@@ -96,7 +96,7 @@ public:
private:
std
::
mutex
mutex_
;
std
::
u16string
descriptor_
;
s
ptr
<
JRemoteObject
>
cachedObject_
;
w
ptr
<
JRemoteObject
>
cachedObject_
;
};
/*
...
...
@@ -250,7 +250,7 @@ sptr<JRemoteObject> JRemoteObjectHolder::Get(jobject object)
// so it will not be freed util this reference released.
sptr
<
JRemoteObject
>
remoteObject
=
nullptr
;
if
(
cachedObject_
!=
nullptr
)
{
remoteObject
=
cachedObject_
;
remoteObject
=
cachedObject_
.
promote
()
;
}
if
(
remoteObject
==
nullptr
)
{
...
...
ipc/native/src/napi_common/include/napi_remote_object_holder.h
浏览文件 @
a668776f
...
...
@@ -64,7 +64,7 @@ private:
std
::
mutex
mutex_
;
napi_env
env_
=
nullptr
;
std
::
u16string
descriptor_
;
s
ptr
<
NAPIRemoteObject
>
cachedObject_
;
w
ptr
<
NAPIRemoteObject
>
cachedObject_
;
napi_ref
localInterfaceRef_
;
int32_t
attachCount_
;
};
...
...
ipc/native/src/napi_common/source/napi_remote_object.cpp
浏览文件 @
a668776f
...
...
@@ -53,6 +53,7 @@ inline T *ConvertNativeValueTo(NativeValue *value)
static
void
RemoteObjectHolderFinalizeCb
(
napi_env
env
,
void
*
data
,
void
*
hint
)
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]RemoteObjectHolderFinalizeCb inter"
);
NAPIRemoteObjectHolder
*
holder
=
reinterpret_cast
<
NAPIRemoteObjectHolder
*>
(
data
);
if
(
holder
==
nullptr
)
{
ZLOGW
(
LOG_LABEL
,
"RemoteObjectHolderFinalizeCb null holder"
);
...
...
@@ -61,12 +62,14 @@ static void RemoteObjectHolderFinalizeCb(napi_env env, void *data, void *hint)
holder
->
Lock
();
int32_t
curAttachCount
=
holder
->
DecAttachCount
();
if
(
curAttachCount
==
0
)
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]RemoteObjectHolderFinalizeCb release holder"
);
delete
holder
;
}
}
static
void
*
RemoteObjectDetachCb
(
NativeEngine
*
engine
,
void
*
value
,
void
*
hint
)
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]RemoteObjectDetachCb inter"
);
(
void
)
engine
;
(
void
)
hint
;
return
value
;
...
...
@@ -74,6 +77,7 @@ static void *RemoteObjectDetachCb(NativeEngine *engine, void *value, void *hint)
static
NativeValue
*
RemoteObjectAttachCb
(
NativeEngine
*
engine
,
void
*
value
,
void
*
hint
)
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]RemoteObjectAttachCb inter"
);
(
void
)
hint
;
NAPIRemoteObjectHolder
*
holder
=
reinterpret_cast
<
NAPIRemoteObjectHolder
*>
(
value
);
if
(
holder
==
nullptr
)
{
...
...
@@ -115,6 +119,7 @@ static NativeValue *RemoteObjectAttachCb(NativeEngine *engine, void *value, void
napi_value
RemoteObject_JS_Constructor
(
napi_env
env
,
napi_callback_info
info
)
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]RemoteObject_JS_Constructor inter"
);
// new napi remote object
size_t
argc
=
2
;
size_t
expectedArgc
=
1
;
...
...
@@ -155,6 +160,7 @@ napi_value RemoteObject_JS_Constructor(napi_env env, napi_callback_info info)
NAPIRemoteObject
::
NAPIRemoteObject
(
napi_env
env
,
napi_value
thisVar
,
const
std
::
u16string
&
descriptor
)
:
IPCObjectStub
(
descriptor
)
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]NAPIRemoteObject create"
);
env_
=
env
;
thisVar_
=
thisVar
;
napi_create_reference
(
env
,
thisVar_
,
1
,
&
thisVarRef_
);
...
...
@@ -163,7 +169,7 @@ NAPIRemoteObject::NAPIRemoteObject(napi_env env, napi_value thisVar, const std::
NAPIRemoteObject
::~
NAPIRemoteObject
()
{
ZLOGI
(
LOG_LABEL
,
"NAPIRemoteObject Destructor"
);
ZLOGI
(
LOG_LABEL
,
"
[mem_free]
NAPIRemoteObject Destructor"
);
if
(
thisVarRef_
!=
nullptr
)
{
napi_status
status
=
napi_delete_reference
(
env_
,
thisVarRef_
);
NAPI_ASSERT_RETURN_VOID
(
env_
,
status
==
napi_ok
,
"failed to delete ref to js RemoteObject"
);
...
...
ipc/native/src/napi_common/source/napi_remote_object_holder.cpp
浏览文件 @
a668776f
...
...
@@ -20,10 +20,13 @@
namespace
OHOS
{
NAPIRemoteObjectHolder
::
NAPIRemoteObjectHolder
(
napi_env
env
,
const
std
::
u16string
&
descriptor
)
:
env_
(
env
),
descriptor_
(
descriptor
),
cachedObject_
(
nullptr
),
localInterfaceRef_
(
nullptr
),
attachCount_
(
1
)
{}
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]NAPIRemoteObjectHolder create"
);
}
NAPIRemoteObjectHolder
::~
NAPIRemoteObjectHolder
()
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]NAPIRemoteObjectHolder free"
);
// free the reference of object.
cachedObject_
=
nullptr
;
if
(
localInterfaceRef_
!=
nullptr
)
{
...
...
@@ -33,12 +36,13 @@ NAPIRemoteObjectHolder::~NAPIRemoteObjectHolder()
sptr
<
NAPIRemoteObject
>
NAPIRemoteObjectHolder
::
Get
(
napi_value
jsRemoteObject
)
{
ZLOGI
(
LOG_LABEL
,
"[mem_free]NAPIRemoteObjectHolder Get"
);
std
::
lock_guard
<
std
::
mutex
>
lockGuard
(
mutex_
);
// grab an strong reference to the object,
// so it will not be freed util this reference released.
sptr
<
NAPIRemoteObject
>
remoteObject
=
nullptr
;
if
(
cachedObject_
!=
nullptr
)
{
remoteObject
=
cachedObject_
;
remoteObject
=
cachedObject_
.
promote
()
;
}
if
(
remoteObject
==
nullptr
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录