Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
a61ebaaa
J
jadx
项目概览
keyescgm
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a61ebaaa
编写于
2月 11, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: sum only sub dependencies in batches build (#1376)
上级
7a5a2fcd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
39 deletion
+51
-39
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
+4
-0
jadx-core/src/main/java/jadx/core/utils/DecompilerScheduler.java
...re/src/main/java/jadx/core/utils/DecompilerScheduler.java
+47
-39
未找到文件。
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
浏览文件 @
a61ebaaa
...
...
@@ -758,6 +758,10 @@ public class ClassNode extends NotificationAttrNode implements ILoadable, ICodeN
this
.
codegenDeps
=
codegenDeps
;
}
public
int
getTotalDepsCount
()
{
return
dependencies
.
size
()
+
codegenDeps
.
size
();
}
public
List
<
ClassNode
>
getUseIn
()
{
return
useIn
;
}
...
...
jadx-core/src/main/java/jadx/core/utils/DecompilerScheduler.java
浏览文件 @
a61ebaaa
...
...
@@ -3,11 +3,10 @@ package jadx.core.utils;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.jetbrains.annotations.NotNull
;
import
org.slf4j.Logger
;
...
...
@@ -33,16 +32,21 @@ public class DecompilerScheduler implements IDecompileScheduler {
@Override
public
List
<
List
<
JavaClass
>>
buildBatches
(
List
<
JavaClass
>
classes
)
{
long
start
=
System
.
currentTimeMillis
();
List
<
List
<
ClassNode
>>
batches
=
internalBatches
(
Utils
.
collectionMap
(
classes
,
JavaClass:
:
getClassNode
));
List
<
List
<
JavaClass
>>
result
=
Utils
.
collectionMap
(
batches
,
l
->
Utils
.
collectionMapNoNull
(
l
,
decompiler:
:
getJavaClassByNode
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Build decompilation batches in {}ms"
,
System
.
currentTimeMillis
()
-
start
);
}
if
(
DEBUG_BATCHES
)
{
check
(
result
,
classes
);
try
{
long
start
=
System
.
currentTimeMillis
();
List
<
List
<
ClassNode
>>
batches
=
internalBatches
(
Utils
.
collectionMap
(
classes
,
JavaClass:
:
getClassNode
));
List
<
List
<
JavaClass
>>
result
=
Utils
.
collectionMap
(
batches
,
l
->
Utils
.
collectionMapNoNull
(
l
,
decompiler:
:
getJavaClassByNode
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Build decompilation batches in {}ms"
,
System
.
currentTimeMillis
()
-
start
);
}
if
(
DEBUG_BATCHES
)
{
check
(
result
,
classes
);
}
return
result
;
}
catch
(
Throwable
e
)
{
LOG
.
warn
(
"Build batches failed (continue with fallback)"
,
e
);
return
buildFallback
(
classes
);
}
return
result
;
}
/**
...
...
@@ -50,17 +54,9 @@ public class DecompilerScheduler implements IDecompileScheduler {
* Build batches for dependencies of single class to avoid locking from another thread.
*/
public
List
<
List
<
ClassNode
>>
internalBatches
(
List
<
ClassNode
>
classes
)
{
Map
<
ClassNode
,
DepInfo
>
depsMap
=
new
HashMap
<>(
classes
.
size
());
Set
<
ClassNode
>
visited
=
new
HashSet
<>();
for
(
ClassNode
classNode
:
classes
)
{
visited
.
clear
();
sumDeps
(
classNode
,
depsMap
,
visited
);
}
List
<
DepInfo
>
deps
=
new
ArrayList
<>(
depsMap
.
values
());
Collections
.
sort
(
deps
);
List
<
DepInfo
>
deps
=
sumDependencies
(
classes
);
Set
<
ClassNode
>
added
=
new
HashSet
<>(
classes
.
size
());
Comparator
<
ClassNode
>
cmpDepSize
=
Comparator
.
comparingInt
(
c
->
c
.
getDependencies
().
size
()
);
Comparator
<
ClassNode
>
cmpDepSize
=
Comparator
.
comparingInt
(
ClassNode:
:
getTotalDepsCount
);
List
<
List
<
ClassNode
>>
result
=
new
ArrayList
<>();
List
<
ClassNode
>
mergedBatch
=
new
ArrayList
<>(
MERGED_BATCH_SIZE
);
for
(
DepInfo
depInfo
:
deps
)
{
...
...
@@ -68,7 +64,7 @@ public class DecompilerScheduler implements IDecompileScheduler {
if
(!
added
.
add
(
cls
))
{
continue
;
}
int
depsSize
=
cls
.
get
Dependencies
().
size
();
int
depsSize
=
cls
.
get
TotalDepsCount
();
if
(
depsSize
==
0
)
{
// add classes without dependencies in merged batch
mergedBatch
.
add
(
cls
);
...
...
@@ -99,21 +95,17 @@ public class DecompilerScheduler implements IDecompileScheduler {
return
result
;
}
public
int
sumDeps
(
ClassNode
cls
,
Map
<
ClassNode
,
DepInfo
>
depsMap
,
Set
<
ClassNode
>
visited
)
{
visited
.
add
(
cls
);
DepInfo
depInfo
=
depsMap
.
get
(
cls
);
if
(
depInfo
!=
null
)
{
return
depInfo
.
getDepsCount
();
}
List
<
ClassNode
>
deps
=
cls
.
getDependencies
();
int
count
=
deps
.
size
();
for
(
ClassNode
dep
:
deps
)
{
if
(!
visited
.
contains
(
dep
))
{
count
+=
sumDeps
(
dep
,
depsMap
,
visited
);
private
static
List
<
DepInfo
>
sumDependencies
(
List
<
ClassNode
>
classes
)
{
List
<
DepInfo
>
deps
=
new
ArrayList
<>(
classes
.
size
());
for
(
ClassNode
cls
:
classes
)
{
int
count
=
0
;
for
(
ClassNode
dep
:
cls
.
getDependencies
())
{
count
+=
1
+
dep
.
getTotalDepsCount
();
}
deps
.
add
(
new
DepInfo
(
cls
,
count
));
}
depsMap
.
put
(
cls
,
new
DepInfo
(
cls
,
count
)
);
return
count
;
Collections
.
sort
(
deps
);
return
deps
;
}
private
static
final
class
DepInfo
implements
Comparable
<
DepInfo
>
{
...
...
@@ -135,20 +127,36 @@ public class DecompilerScheduler implements IDecompileScheduler {
@Override
public
int
compareTo
(
@NotNull
DecompilerScheduler
.
DepInfo
o
)
{
return
Integer
.
compare
(
depsCount
,
o
.
depsCount
);
int
deps
=
Integer
.
compare
(
depsCount
,
o
.
depsCount
);
if
(
deps
==
0
)
{
return
cls
.
compareTo
(
o
.
cls
);
}
return
deps
;
}
@Override
public
String
toString
()
{
return
cls
+
":"
+
depsCount
;
}
}
private
static
List
<
List
<
JavaClass
>>
buildFallback
(
List
<
JavaClass
>
classes
)
{
return
classes
.
stream
()
.
sorted
(
Comparator
.
comparingInt
(
c
->
c
.
getClassNode
().
getTotalDepsCount
()))
.
map
(
Collections:
:
singletonList
)
.
collect
(
Collectors
.
toList
());
}
private
void
dumpBatchesStats
(
List
<
ClassNode
>
classes
,
List
<
List
<
ClassNode
>>
result
,
List
<
DepInfo
>
deps
)
{
double
avg
=
result
.
stream
().
mapToInt
(
List:
:
size
).
average
().
orElse
(-
1
);
int
maxSingleDeps
=
classes
.
stream
().
mapToInt
(
c
->
c
.
getDependencies
().
size
()
).
max
().
orElse
(-
1
);
int
max
Recursive
Deps
=
deps
.
stream
().
mapToInt
(
DepInfo:
:
getDepsCount
).
max
().
orElse
(-
1
);
int
maxSingleDeps
=
classes
.
stream
().
mapToInt
(
ClassNode:
:
getTotalDepsCount
).
max
().
orElse
(-
1
);
int
max
Sub
Deps
=
deps
.
stream
().
mapToInt
(
DepInfo:
:
getDepsCount
).
max
().
orElse
(-
1
);
LOG
.
info
(
"Batches stats:"
+
"\n input classes: "
+
classes
.
size
()
+
",\n batches: "
+
result
.
size
()
+
",\n average batch size: "
+
String
.
format
(
"%.2f"
,
avg
)
+
",\n max single deps count: "
+
maxSingleDeps
+
",\n max
recursive deps count: "
+
maxRecursive
Deps
);
+
",\n max
sub deps count: "
+
maxSub
Deps
);
}
private
static
void
check
(
List
<
List
<
JavaClass
>>
result
,
List
<
JavaClass
>
classes
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录