Skip to content

Commit

Permalink
Account for max heap size set with RAM%.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgm3746 committed Sep 30, 2024
1 parent a627a63 commit f7f9d62
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/github/joa/JvmOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3746,7 +3746,7 @@ public void addAnalysis(Analysis key) {
* Do JVM options analysis.
*/
public void doAnalysis() {
if (jvmContext != null && jvmContext.getOptions() != null && !jvmContext.getOptions().isEmpty()) {
if (jvmContext != null && jvmContext.getOptions() != null && jvmContext.getOptions() != null) {
// Convenience variable
List<GarbageCollector> garbageCollectors = new ArrayList<GarbageCollector>();
// Determine collectors based on context (precedence) or JVM options.
Expand Down Expand Up @@ -4292,7 +4292,7 @@ public void doAnalysis() {
addAnalysis(Analysis.WARN_VERIFY_NONE);
}
// Check for max heap size not being explicitly set
if (maxHeapSize == null) {
if (maxHeapSize == null && maxRAMPercentage == null) {
addAnalysis(Analysis.INFO_HEAP_MAX_MISSING);
}
// Check if JVM signal handling disabled
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/org/github/joa/util/TestAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,46 @@ void testHeapDumpOnOutOfMemoryErrorPathMissing() {
Analysis.INFO_HEAP_DUMP_PATH_MISSING + " analysis not identified.");
}

@Test
void testHeapMaxDefault() {
String opts = "";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
jvmOptions.doAnalysis();
assertTrue(jvmOptions.hasAnalysis(Analysis.INFO_HEAP_MAX_MISSING.getKey()),
Analysis.INFO_HEAP_MAX_MISSING + " analysis not identified.");
}

@Test
void testHeapMaxMaxHeapSize() {
String opts = "-XX:MaxHeapSize=1234567890";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
jvmOptions.doAnalysis();
assertFalse(jvmOptions.hasAnalysis(Analysis.INFO_HEAP_MAX_MISSING.getKey()),
Analysis.INFO_HEAP_MAX_MISSING + " analysis incorrectly identified.");
}

@Test
void testHeapMaxMaxRamPercentage() {
String opts = "-XX:MaxRAMPercentage=80.0";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
jvmOptions.doAnalysis();
assertFalse(jvmOptions.hasAnalysis(Analysis.INFO_HEAP_MAX_MISSING.getKey()),
Analysis.INFO_HEAP_MAX_MISSING + " analysis incorrectly identified.");
}

@Test
void testHeapMaxXmx() {
String opts = "-Xmx2048M";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
jvmOptions.doAnalysis();
assertFalse(jvmOptions.hasAnalysis(Analysis.INFO_HEAP_MAX_MISSING.getKey()),
Analysis.INFO_HEAP_MAX_MISSING + " analysis incorrectly identified.");
}

@Test
void testIgnoreUnrecognizedVmOptions() {
String opts = "-Xss128k -XX:+IgnoreUnrecognizedVMOptions -Xms2048M";
Expand Down

0 comments on commit f7f9d62

Please sign in to comment.