Skip to content

Commit

Permalink
8198668: MemoryPoolMBean/isUsageThresholdExceeded/isexceeded001/TestD…
Browse files Browse the repository at this point in the history
…escription.java still failing

Reviewed-by: mdoerr
Backport-of: d1249aa5cbf3a3a3a24e85bcec30aecbc3e09bc0
  • Loading branch information
Amos Shi authored and GoeLin committed Dec 26, 2023
1 parent d232723 commit f308f3e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 38 deletions.
5 changes: 0 additions & 5 deletions test/hotspot/jtreg/ProblemList.txt
Expand Up @@ -222,11 +222,6 @@ serviceability/sa/TestUniverse.java#id0 8193639,8211767 solaris-all,linux-ppc64l
#############################################################################

vmTestbase/nsk/monitoring/MemoryPoolMBean/isCollectionUsageThresholdExceeded/isexceeded003/TestDescription.java 8153598 generic-all
vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded001/TestDescription.java 8198668 generic-all
vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded002/TestDescription.java 8153598 generic-all
vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded003/TestDescription.java 8198668 generic-all
vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded004/TestDescription.java 8153598 generic-all
vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded005/TestDescription.java 8153598 generic-all
vmTestbase/nsk/monitoring/ThreadMXBean/ThreadInfo/Deadlock/JavaDeadlock001/TestDescription.java 8060733 generic-all

vmTestbase/nsk/jdi/AttachingConnector/attachnosuspend/attachnosuspend001/TestDescription.java 8153613 generic-all
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -47,71 +47,99 @@ public static void main(String[] argv) {
public static int run(String[] argv, PrintStream out) {
ArgumentHandler argHandler = new ArgumentHandler(argv);
Log log = new Log(out, argHandler);
log.enableVerbose(true); // show log output

MemoryMonitor monitor = Monitor.getMemoryMonitor(log, argHandler);
List pools = monitor.getMemoryPoolMBeans();

for (int i = 0; i < pools.size(); i++) {
Object pool = pools.get(i);
log.display(i + " pool " + monitor.getName(pool));

log.display(i + " pool " + monitor.getName(pool) + " of type: " + monitor.getType(pool));
if (!monitor.isUsageThresholdSupported(pool)) {
log.display(" does not support usage thresholds");
log.display(" does not support usage thresholds: skip");
continue;
} else
log.display(" supports usage thresholds");
}

// Set a threshold that is greater than used value
MemoryUsage usage = monitor.getUsage(pool);
boolean isExceeded = monitor.isUsageThresholdExceeded(pool);
long used = usage.getUsed();
long max = usage.getMax();
long threshold = used + 1;

if ( (max > -1) && (threshold > max) ) {
// we can't test threshold - not enough memory
log.display("not enough memory for testing threshold:" +
" used=" + used +
", max = " + max );
" used=" + used + ", max=" + max + ": skip");
continue;
}

monitor.setUsageThreshold(pool, threshold);
log.display(" threshold " + threshold + " is set, used = " + used );
log.display(" used value is " + used + " max is " + max + " isExceeded = " + isExceeded);
log.display(" threshold set to " + threshold);
log.display(" threshold count " + monitor.getUsageThresholdCount(pool));

// Reset peak usage so we can use it:
monitor.resetPeakUsage(pool);
log.display(" resetting peak usage");
log.display(" peak usage = " + monitor.getPeakUsage(pool).getUsed());
isExceeded = monitor.isUsageThresholdExceeded(pool);
log.display(" reset peak usage. peak usage = " + monitor.getPeakUsage(pool).getUsed()
+ " isExceeded = " + isExceeded);

// Eat some memory - provoke usage of the pool to cross the
// threshold value
b = new byte[INCREMENT]; // Eat 100K
// Eat some memory - _may_ cause usage of the pool to cross threshold,
// but cannot assume this affects the pool we are testing.
b = new byte[INCREMENT];

boolean isExceeded = monitor.isUsageThresholdExceeded(pool);
usage = monitor.getPeakUsage(pool);
used = usage.getUsed();
isExceeded = monitor.isUsageThresholdExceeded(pool);
log.display(" Allocated heap. isExceeded = " + isExceeded);

log.display(" used value is " + used);
// Fetch usage information: use peak usage in comparisons below, in case usage went up and then down.
// Log used and peak used in case of failure.
usage = monitor.getUsage(pool);
MemoryUsage peakUsage = monitor.getPeakUsage(pool);
used = usage.getUsed();
max = usage.getMax();
long peakUsed = usage.getUsed();
long peakMax = usage.getMax();

log.display(" used value is " + used + " max is " + max + " isExceeded = " + isExceeded);
log.display("peak used value is " + peakUsed + " peak max is " + peakMax);
log.display(" threshold set to " + threshold);
long thresholdCount = monitor.getUsageThresholdCount(pool);
log.display(" threshold count " + thresholdCount);

// Test can be imprecise, particularly with CodeHeap: usage changes outside our control.
if (thresholdCount > 0 && monitor.getType(pool) != MemoryType.HEAP) {
log.display(" thresholdCount increasing outside our control for non-heap Pool: skip");
continue;
}

if (used < threshold && isExceeded) {
// There're problems with isUsageThresholdExceeded()
// If peak used value is less than threshold, then isUsageThresholdExceeded()
// is expected to return false.
if (peakUsed < threshold && isExceeded) {
// used is commonly less than threshold, but isExceeded should not be true:
log.complain("isUsageThresholdExceeded() returned "
+ "true, while threshold = " + threshold
+ " and used peak = " + used);
+ " and used peak = " + peakUsed);
isExceeded = monitor.isUsageThresholdExceeded(pool);
if (isExceeded) {
testFailed = true;
} else {
log.complain("isUsageThresholdExceeded() now says false.");
}
} else
if (used >= threshold && !isExceeded) {
// we can introduce some imprecision during pooling memory usage
// value at the Code Cache memory pool. Amount of used memory
// was changed after we'd calculated isExceeded value

if (monitor.isUsageThresholdExceeded(pool)) {
// that's mean such imprecision
log.display("isUsageThresholdExceeded() returned false,"
// If peak used value is greater or equal than threshold, then
// isUsageThresholdExceeded() is expected to return true.
if (peakUsed >= threshold && !isExceeded) {
isExceeded = monitor.isUsageThresholdExceeded(pool);
if (isExceeded) {
log.display("isUsageThresholdExceeded() returned false, then true,"
+ " while threshold = " + threshold + " and "
+ "used peak = " + used);
+ "used peak = " + peakUsed);
} else {
// some other problems with isUsageThresholdExceeded()
log.complain("isUsageThresholdExceeded() returned false,"
// Failure:
log.complain("isUsageThresholdExceeded() returned false, and is still false,"
+ " while threshold = " + threshold + " and "
+ "used peak = " + used);
+ "used peak = " + peakUsed);
testFailed = true;
}
}
Expand Down

1 comment on commit f308f3e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.