Make isexceeded001.java more robust

XMLWordPrintable

    • b02

        In `test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded001.java`, the relevant logic is roughly:

        ```
        monitor.resetPeakUsage(pool);

        isExceeded = monitor.isUsageThresholdExceeded(pool);

        b = new byte[INCREMENT];

        isExceeded = monitor.isUsageThresholdExceeded(pool);

        if (peakUsed >= threshold && !isExceeded) {
            isExceeded = monitor.isUsageThresholdExceeded(pool);
            if (isExceeded) {
                // OK
            } else {
                // failure
            }
        }
        ```

        The intention of this test is to verify that when `peakUsed` exceeds the threshold, the result of `isUsageThresholdExceeded` should be consistent.

        However, `isUsageThresholdExceeded` checks the **current usage**, not the peak usage. The `new byte[INCREMENT]` allocation may trigger a GC, which can reduce the current memory usage. As a result, the second assignment to `isExceeded` can overwrite a previously observed `true` value with `false`.

        One possible fix is to avoid losing the "exceeded" observation by combining the results:

        ```
        isExceeded = isExceeded || monitor.isUsageThresholdExceeded(pool);
        ```

        This ensures that once the threshold is observed as exceeded, a later GC-induced drop in current usage will not mask it.

              Assignee:
              Albert Yang
              Reporter:
              Albert Yang
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: