8267311: vmTestbase/gc/gctests/StringInternGC/StringInternGC.java eventually OOMEs
8267311: vmTestbase/gc/gctests/StringInternGC/StringInternGC.java eventually OOMEs Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org> Reviewed-by: tschatzl
This commit is contained in:
parent
5aa45f2edf
commit
a98e476c0a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2021, 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
|
||||
@ -31,7 +31,7 @@
|
||||
*
|
||||
* @library /vmTestbase
|
||||
* /test/lib
|
||||
* @run main/othervm gc.gctests.StringInternGC.StringInternGC
|
||||
* @run main/othervm -XX:+ExplicitGCInvokesConcurrent gc.gctests.StringInternGC.StringInternGC
|
||||
*/
|
||||
|
||||
package gc.gctests.StringInternGC;
|
||||
@ -46,13 +46,19 @@ import nsk.share.gc.*;
|
||||
* String pool should not overflow.
|
||||
*/
|
||||
public class StringInternGC extends ThreadedGCTest {
|
||||
private int maxLength = 1000;
|
||||
private int maxLength = 1000; // Maximum number of characters to add per operation.
|
||||
private int maxTotalLength = 128 * 1024; // Total maximum length of the string until a new StringBuffer will be allocated.
|
||||
private long lastTime = System.currentTimeMillis();
|
||||
|
||||
private class StringGenerator implements Runnable {
|
||||
private StringBuffer sb = new StringBuffer();
|
||||
|
||||
private String generateString() {
|
||||
int length = LocalRandom.nextInt(maxLength);
|
||||
if (sb.length() > maxTotalLength) {
|
||||
sb = new StringBuffer();
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
sb.append((char) LocalRandom.nextInt(Integer.MAX_VALUE));
|
||||
return sb.toString();
|
||||
@ -60,6 +66,12 @@ public class StringInternGC extends ThreadedGCTest {
|
||||
|
||||
|
||||
public void run() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime - lastTime > 5000) { // Cause a full gc every 5s.
|
||||
lastTime = currentTime;
|
||||
System.gc();
|
||||
}
|
||||
|
||||
generateString().intern();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user