Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
ffedaea5
Commit
ffedaea5
authored
Jan 21, 2019
by
Jan S
Committed by
skylot
Jan 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(gui): limit the spare memory to max. 512MiB (#434)
parent
aec98644
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
HeapUsageBar.java
jadx-gui/src/main/java/jadx/gui/ui/HeapUsageBar.java
+2
-1
Utils.java
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
+22
-2
No files found.
jadx-gui/src/main/java/jadx/gui/ui/HeapUsageBar.java
View file @
ffedaea5
package
jadx
.
gui
.
ui
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.Utils
;
import
javax.swing.*
;
import
java.awt.*
;
...
...
@@ -44,7 +45,7 @@ public class HeapUsageBar extends JProgressBar implements ActionListener {
setValue
(
usedKB
);
setString
(
String
.
format
(
textFormat
,
(
usedKB
/
TWO_TO_20
),
maxGB
));
if
(
used
>
r
.
maxMemory
()
*
0.8
)
{
if
(
(
used
+
Utils
.
MIN_FREE_MEMORY
)
>
r
.
maxMemory
()
)
{
setForeground
(
RED
);
}
else
{
setForeground
(
GREEN
);
...
...
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
View file @
ffedaea5
...
...
@@ -26,6 +26,16 @@ public class Utils {
public
static
final
Font
FONT_HACK
=
openFontTTF
(
"Hack-Regular"
);
/**
* The minimum about of memory in bytes we are trying to keep free, otherwise the application may run out of heap
* which ends up in a Java garbage collector running "amok" (CPU utilization 100% for each core and the UI is
* not responsive).
*
* We can calculate and store this value here as the maximum heap is fixed for each JVM instance
* and can't be changed at runtime.
*/
public
static
final
long
MIN_FREE_MEMORY
=
calculateMinFreeMemory
();
private
Utils
()
{
}
...
...
@@ -107,11 +117,21 @@ public class Utils {
return
overIcon
;
}
/**
* @return 20% of the maximum heap size limited to 512 MB (bytes)
*/
public
static
long
calculateMinFreeMemory
()
{
Runtime
runtime
=
Runtime
.
getRuntime
();
long
minFree
=
(
long
)
(
runtime
.
maxMemory
()
*
0.2
);
minFree
=
Math
.
min
(
minFree
,
512
*
1048576
);
return
minFree
;
}
public
static
boolean
isFreeMemoryAvailable
()
{
Runtime
runtime
=
Runtime
.
getRuntime
();
long
maxMemory
=
runtime
.
maxMemory
();
long
totalFree
=
runtime
.
freeMemory
()
+
maxMemory
-
runtime
.
totalMemory
(
);
return
totalFree
>
maxMemory
*
0.2
;
long
totalFree
=
runtime
.
freeMemory
()
+
(
maxMemory
-
runtime
.
totalMemory
()
);
return
totalFree
>
MIN_FREE_MEMORY
;
}
public
static
String
memoryInfo
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment