Skip to content

Commit

Permalink
8293218: serviceability/tmtools/jstat/GcNewTest.java fails with "Erro…
Browse files Browse the repository at this point in the history
…r in the percent calculation"

8293564: serviceability/tmtools/jstat/GcTest01.java fails with "Error in the percent calculation"

Reviewed-by: sspitsyn, lmesnik, dcubed
  • Loading branch information
kevinjwalls committed Sep 17, 2022
1 parent 01e7b88 commit cfd44bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
1 change: 0 additions & 1 deletion test/hotspot/jtreg/ProblemList-Xcomp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ serviceability/sa/TestJhsdbJstackMixed.java 8248675 linux-aarch64

serviceability/jvmti/VMObjectAlloc/VMObjectAllocTest.java 8288430 generic-all

serviceability/tmtools/jstat/GcNewTest.java 8293218 linux-x64,macosx-x64
gc/cslocker/TestCSLocker.java 8293289 linux-x64,macosx-x64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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 @@ -58,17 +58,34 @@ private List<Object> allocateHeap(float targetUsage) {
* This method provokes a GC
*/
public void provokeGc() {
float targetFraction = 0;
// Read sizes of eden and overall heap, to find eden size as a fraction of heap.
// Recognise if heap is changing size, and retry (heap is expected to initially shrink).
for (int i = 0; i < 3; i++) {
// One retry is expected occasionally. More "should not happen":
if (i == 2) {
throw new RuntimeException("Cannot calculate targetFraction. Heap size not stable.");
}
long heapSize0 = Pools.getHeapCommittedSize();
long edenSize = Pools.getEdenCommittedSize();
long heapSize = Pools.getHeapCommittedSize();
float targetPercent = ((float) edenSize) / (heapSize);
if ((targetPercent < 0) || (targetPercent > 1.0)) {
throw new RuntimeException("Error in the percent calculation" + " (eden size: " + edenSize + ", heap size: " + heapSize + ", calculated eden percent: " + targetPercent + ")");
if (heapSize < heapSize0) {
System.out.println("provokeGc: Heap shrinking, retry. eden: " + edenSize + ", heap0: " + heapSize0 + ", heap: " + heapSize);
System.gc();
continue;
}
targetFraction = ((float) edenSize) / (heapSize);
if ((targetFraction < 0) || (targetFraction > 1.0)) {
throw new RuntimeException("Error in fraction calculation" + " (eden size: " + edenSize + ", heap size: " + heapSize
+ ", calculated eden fraction: " + targetFraction + ")");
}
allocateHeap(targetPercent);
allocateHeap(targetPercent);
System.gc();
break; // We have found eden as a fraction of heap.
}
// Previously these allocations and GC call were in a loop.
// That appears unnecesary as the goal is simply to cause a GC:
allocateHeap(targetFraction);
allocateHeap(targetFraction);
System.gc();
}

public GcProvoker() {
Expand Down

1 comment on commit cfd44bb

@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.