8199370: [TESTBUG] Open source vm testbase GC tests
Reviewed-by: erikj, ihse, ehelin
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/AllocateWithoutOomTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/AllocateWithoutOomTest.java
new file mode 100644
index 0000000..96385e0
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/AllocateWithoutOomTest.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/AllocateWithoutOomTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Small stress test that should be able to run for a specified
+ * time without hitting an OOM.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.AllocateWithoutOomTest.AllocateWithoutOomTest
+ */
+
+package gc.gctests.AllocateWithoutOomTest;
+
+import java.util.ArrayList;
+import java.util.Random;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+import nsk.share.test.Stresser;
+
+/**
+ * Small stress test that should be able to run for a specified
+ * time without hitting an OOM.
+ */
+public class AllocateWithoutOomTest extends GCTestBase {
+
+ /**
+ * Small stress test that allocates objects in a certain interval
+ * and runs for a specified time. It should not throw any OOM during
+ * the execution.
+ *
+ * @return success if the test runs for the specified time without
+ * and exceptions being thrown.
+ */
+ @Override
+ public void run() {
+ int minSize;
+ int maxSize;
+
+
+
+ minSize = 2048;
+ maxSize = 32768;
+
+
+ ArrayList placeholder = new ArrayList();
+ long multiplier = maxSize - minSize;
+ Random rndGenerator = new Random(runParams.getSeed());
+
+ long memoryUpperLimit = runParams.getTestMemory();
+ long memoryLowerLimit = runParams.getTestMemory() / 3;
+ long memoryAllocatedLowerLimit = memoryUpperLimit
+ - memoryLowerLimit;
+
+
+ long totalAllocatedMemory = 0;
+ long totalAllocatedObjects = 0;
+ int allocationSize = -1;
+ long roundCounter = 1;
+
+ try {
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(0);
+ while (stresser.continueExecution()) {
+ while (totalAllocatedMemory < memoryUpperLimit) {
+ allocationSize = ((int) (rndGenerator.nextDouble()
+ * multiplier)) + minSize;
+ byte[] tmp = new byte[allocationSize];
+ totalAllocatedMemory += allocationSize;
+ totalAllocatedObjects++;
+ placeholder.add(tmp);
+ tmp = null;
+ }
+
+ // NOTE: Start on index 1 to make sure we don't remove to many
+ // consecutive objects in the beginning
+ int indexToRemove = 1;
+
+ while (totalAllocatedMemory > memoryAllocatedLowerLimit) {
+ // NOTE: Terminate if we only have zero objects left
+ if (placeholder.size() == 0) {
+ throw new TestFailure("No more objects to free, "
+ + "so we can't continue");
+ }
+
+ if (indexToRemove >= placeholder.size()) {
+ indexToRemove = (placeholder.size() == 1) ? 0 : 1;
+ }
+
+ byte[] tmp = (byte[]) placeholder.remove(indexToRemove);
+
+ totalAllocatedMemory -= tmp.length;
+ totalAllocatedObjects--;
+
+ tmp = null;
+ // NOTE: Since we removed one object, we only need to
+ // increment index by 1 to move two steps. We want to
+ // remove every other object to create fragmentation
+ indexToRemove++;
+ }
+
+ roundCounter++;
+ }
+ placeholder = null;
+ log.info("Passed. Completed " + roundCounter
+ + " rounds during the test");
+ } catch (OutOfMemoryError oome) {
+ placeholder = null;
+ throw new TestFailure("OOM thrown when allocating an object of size "
+ + allocationSize, oome);
+ } finally {
+ placeholder = null;
+ }
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new AllocateWithoutOomTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/BigChains/BigChains.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/BigChains/BigChains.java
new file mode 100644
index 0000000..655b51c
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/BigChains/BigChains.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/BigChains.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Creates big chains of allocated objects, with a mix of objects
+ * with and without finalizers.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.BigChains.BigChains
+ */
+
+package gc.gctests.BigChains;
+
+import nsk.share.gc.GC;
+import nsk.share.gc.ThreadedGCTest;
+
+/**
+ * Test ported from dev test suite. Creates big chains of
+ * allocated objects, with a mix of objects with and without
+ * finalizers.
+ */
+public class BigChains extends ThreadedGCTest {
+
+ public static void main(String[] args) {
+ GC.runTest(new BigChains(), args);
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+
+ return new Runnable() {
+
+ /**
+ * Create a big chain of mixed objects and make sure nothing
+ * crashes.
+ *
+ * @return success if the program test could run without any
+ * problems.
+ */
+ public void run() {
+
+ createChain(100000, true);
+
+
+ int i = 0;
+
+ while (i++ < 100) {
+ createChain(10000, false);
+ }
+ }
+
+ private void createChain(int noof, boolean firstIsFinalizable) {
+ BaseClass first;
+
+ if (firstIsFinalizable) {
+ first = new FinalizerYes();
+ } else {
+ first = new FinalizerNo();
+ }
+
+ BaseClass current = first;
+
+ for (int i = 0; i < noof; i++) {
+ current.next = new FinalizerNo();
+ current = current.next;
+ }
+
+ current.next = first;
+ }
+ };
+ }
+}
+
+/**
+ * Helper base class for the BigChains test.
+ */
+class BaseClass {
+
+ /**
+ * Base class.
+ */
+ public BaseClass next;
+}
+
+/**
+ * Helper class withfinalizer and counter for number of
+ * calls to the finalize() method.
+ */
+class FinalizerYes extends BaseClass {
+
+ private static int noOfFinalized = 0;
+
+ /**
+ * Finalizer for the help class, that increments a counter
+ * for each call to this method.
+ */
+ public final void finalize() {
+ synchronized (this.getClass()) {
+ FinalizerYes.noOfFinalized++;
+ }
+ }
+}
+
+/**
+ * Helper class without finalizer.
+ */
+class FinalizerNo extends BaseClass {
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/BigChains/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/BigChains/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/BigChains/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC01/CallGC01.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC01/CallGC01.java
new file mode 100644
index 0000000..466a5fc
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC01/CallGC01.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/CallGC/CallGC01.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.CallGC.CallGC01.CallGC01 -t 100
+ */
+
+package gc.gctests.CallGC.CallGC01;
+
+import nsk.share.gc.*;
+import nsk.share.runner.*;
+
+/**
+ * This test starts a number of threads that do System.gc() and
+ * System.runFinalization() and checks that there are no crashes.
+ */
+public class CallGC01 extends ThreadedGCTest {
+ protected Runnable createRunnable(int i) {
+ if (i % 2 == 0)
+ return new GCRunner();
+ else
+ return new FinRunner();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new CallGC01(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC01/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC01/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC01/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC02/CallGC02.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC02/CallGC02.java
new file mode 100644
index 0000000..60f46fa
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC02/CallGC02.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/CallGC/CallGC02.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.CallGC.CallGC02.CallGC02 -t 100 -gp random(arrays)
+ */
+
+package gc.gctests.CallGC.CallGC02;
+
+import nsk.share.gc.*;
+import nsk.share.gc.gp.*;
+import nsk.share.runner.*;
+
+/**
+ * This test starts a number of threads that do System.gc() and
+ * System.runFinalization() and checks that there are no crashes.
+ *
+ * There is also a thread that produces garbage.
+ */
+public class CallGC02 extends ThreadedGCTest implements GarbageProducerAware {
+ private GarbageProducer garbageProducer;
+ private final int objectSize = 100;
+
+ private class GarbageProduction implements Runnable {
+ public void run() {
+ garbageProducer.create(objectSize);
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ if (i == 0)
+ return new GarbageProduction();
+ else if (i % 2 == 0)
+ return new GCRunner();
+ else
+ return new FinRunner();
+ }
+
+ public final void setGarbageProducer(GarbageProducer garbageProducer) {
+ this.garbageProducer = garbageProducer;
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new CallGC02(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC02/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC02/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/CallGC/CallGC02/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ClassDeallocGC/ClassDeallocGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/ClassDeallocGC/ClassDeallocGC.java
new file mode 100644
index 0000000..632b84b
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ClassDeallocGC/ClassDeallocGC.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/ClassDeallocGC.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * This test is a slightly modified version of a test taken from a research paper
+ * by CE McDowell of UCSC titled 'No so static "static fields"'.
+ * To quote from the paper :
+ * " In this paper we have identified a problem with the Java Language
+ * Specification with regard to class unloading and static fields. We have
+ * provided an example that demonstrates how the current implementation of
+ * class unloading can result in a static field being reinitialized resulting
+ * in a program that changes its behavior depending upon when garbage collection occurs."
+ * In this test, the creation of the object first assigned to
+ * class_one_object (actually an instance of ClassOne) also creates an instance
+ * of ClassTwo which contains a static field. Once the references to the ClassOne
+ * object and the Class object are set to null, a call to the garbage
+ * collector results in both ClassOne and ClassTwo being unloaded. When
+ * the final assignment to class_one_object occurs, creating a new instance of ClassOne
+ * and a new instance of ClassTwo, the program should print out the value of counter in
+ * ClassTwo as 2. This would mean that class was not unloaded and the static field
+ * was not reinitialized. If the test prints out 1, the test has failed as the static
+ * field was reinitilized.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.ClassDeallocGC.ClassDeallocGC
+ */
+
+package gc.gctests.ClassDeallocGC;
+
+import nsk.share.TestFailure;
+
+public class ClassDeallocGC
+{
+ public static void main(String[] args)
+ throws java.io.IOException, ClassNotFoundException,
+ IllegalAccessException, InstantiationException
+ {
+ int count = 0, counter;
+ ClassOne class_one_object;
+
+ /* load the class ClassOne and instantiate an instance of it */
+ /* ClassOne uses ClassTwo which will thus get loaded also */
+ Class theClass = Class.forName("gc.gctests.ClassDeallocGC.ClassOne");
+ class_one_object = (ClassOne)theClass.newInstance();
+
+ /* remove all references to the class and the instance */
+ class_one_object = null;
+ theClass = null;
+
+ System.gc(); /* force garbage collection which also unloads classes */
+
+ /*loads and instantiates ClassOne again. ClassTwo also gets reloaded*/
+ class_one_object = (ClassOne) new ClassOne();
+ if ( (counter = class_one_object.getCounter()) == 2 ) {
+ System.out.println("Test Passed.");
+ } else {
+ throw new TestFailure("Test failed. counter = " + counter + ", should be 2.");
+ }
+ }
+}
+
+class ClassOne {
+ ClassTwo class_two;
+ public ClassOne(){
+ class_two = new ClassTwo();
+ }
+ public int getCounter() {
+ return class_two.getCounter();
+ }
+}
+
+
+class ClassTwo {
+ static int counter = 0;
+ public ClassTwo(){
+ counter++;
+ }
+ public int getCounter() {
+ return counter;
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest01/FinalizeTest01.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest01/FinalizeTest01.java
new file mode 100644
index 0000000..7236cad
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest01/FinalizeTest01.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/FinalizeTest01.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, monitoring]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.FinalizeTest01.FinalizeTest01
+ */
+
+package gc.gctests.FinalizeTest01;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import nsk.share.gc.*;
+import nsk.share.TestFailure;
+import nsk.share.test.ExecutionController;
+import nsk.share.test.Stresser;
+
+/**
+ * Tests that GC works correctly with finalizers.
+ *
+ * Create a number of objects, some of which register their
+ * creation/finalization. Then try to eat available memory
+ * which forces garbage collection of created objects.
+ * Garbage collector should try to collect the garbage and thus
+ * call finalizers. The test checks that all finalizers have been called.
+ */
+
+/*
+Reworked original test (4933478). Original comment:
+
+Tests that objects w/finalizers will eventually finalize
+(and by the way, the system doesn't crash!).
+
+Returns exit code 0 on success, and 1 on failure.
+
+ */
+/**
+ * Class with finalizer that throws Exception.
+ * Used for FinalizeTest02
+ */
+class FinExceptMemoryObject extends FinMemoryObject {
+
+ public FinExceptMemoryObject(int size) {
+ super(size);
+ }
+
+ protected void finalize() {
+ super.finalize();
+ throw new RuntimeException("Exception in finalizer");
+ }
+}
+
+public class FinalizeTest01 extends GCTestBase {
+
+ private final int allocRatio = 5;
+ private final int size = 1024 * 2;
+ private int count = 1000;
+ private static boolean throwExceptions = false;
+ private ExecutionController stresser;
+
+ private void runOne() {
+ Object o;
+ for (int i = 0; i < count; i++) {
+ if (i % allocRatio == 0) {
+ if (throwExceptions) {
+ o = new FinExceptMemoryObject(size);
+ } else {
+ o = new FinMemoryObject(size);
+ }
+ } else {
+ o = new byte[size - Memory.getObjectExtraSize()];
+ }
+ }
+ o = null;
+
+ MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
+ long finalizationMaxTime = 1000 * 60; // 1min
+
+ /* Provoke GC to start finalization. */
+ Algorithms.eatMemory(stresser);
+ if (!stresser.continueExecution()) {
+ // we did not eat all memory
+ return;
+ }
+ long waitTime = System.currentTimeMillis() + finalizationMaxTime;
+
+ /*
+ * Before we force finalization it is needed to check that we have
+ * any object pending for finazlization. If not then is a GC bug.
+ */
+ while (FinMemoryObject.getFinalizedCount()
+ + mbean.getObjectPendingFinalizationCount() == 0
+ && (System.currentTimeMillis() < waitTime)) {
+ System.out.println("No objects are found in the finalization queue. Waiting..");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ }
+ }
+ if (FinMemoryObject.getFinalizedCount()
+ + mbean.getObjectPendingFinalizationCount() == 0) {
+ throw new TestFailure("Test failed. (No objects were not queued for finalization during 1min)");
+ }
+
+ /* force finalization and wait for it finishs */
+ Runtime.getRuntime().runFinalization();
+
+ boolean error = (FinMemoryObject.getLiveCount() != 0);
+
+ /*
+ * The runFinalization() starts the second finalization thread and wait until it finishs.
+ * However it is a very little probability (less then 1%) that not all object are finalized yet.
+ * Possibly the regular Finalizer thread have not finished its work when we check getLiveCount()
+ * or GC is still clearing memory and adding objects to the queue.
+ */
+ waitTime = System.currentTimeMillis() + finalizationMaxTime;
+ while (error && (System.currentTimeMillis() < waitTime)) {
+ // wait 1 sec (it could be less due to potential InterruptedException)
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ }
+ error = (FinMemoryObject.getLiveCount() != 0);
+ }
+
+ if (error) {
+ throw new TestFailure("Test failed (objects were not finalized during 1min)");
+ }
+
+
+ System.out.println("Allocated: " + FinMemoryObject.getAllocatedCount());
+ System.out.println("Finalized: " + FinMemoryObject.getFinalizedCount());
+ error = (FinMemoryObject.getLiveCount() != 0);
+ if (error) {
+ throw new TestFailure("Test failed.");
+ }
+ }
+
+ public void run() {
+ stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(runParams.getIterations());
+ count = (int) Math.min(runParams.getTestMemory() / size, Integer.MAX_VALUE);
+ System.out.println("Allocating " + count
+ + " objects. 1 out of " + allocRatio
+ + " will have a finalizer.");
+ System.out.flush();
+ runOne();
+ }
+
+ public static void main(String[] args) {
+ for (int i = 0; i < args.length; ++i) {
+ if (args[i].equals("-throwExceptions")) {
+ throwExceptions = true;
+ }
+ }
+ GC.runTest(new FinalizeTest01(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest01/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest01/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest01/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest02/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest02/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest02/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest02/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest02/TestDescription.java
new file mode 100644
index 0000000..3c3913b
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest02/TestDescription.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/FinalizeTest02.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, monitoring]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.FinalizeTest01.FinalizeTest01
+ * -throwExceptions
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest04/FinalizeTest04.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest04/FinalizeTest04.java
new file mode 100644
index 0000000..5794076
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest04/FinalizeTest04.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/FinalizeTest04.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.FinalizeTest04.FinalizeTest04
+ */
+
+package gc.gctests.FinalizeTest04;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+
+/**
+ * Test that synchronization between GC and finalizer thread
+ * (if any) is correct.
+ *
+ * This test creates objects that do GC-related work in finalizer,
+ * e.g. call System.gc(), System.runFinalization(), Algorithms.eatMemory().
+ *
+ * @see nsk.share.gc.Algorithms#eatMemory()
+ * @see java.lang.System#gc()
+ * @see java.lang.System#runFinalization()
+ */
+public class FinalizeTest04 extends GCTestBase {
+
+ private int objectSize = 100;
+ private int objectCount = 100;
+ private ExecutionController stresser;
+
+ private class FinMemoryObject2 extends FinMemoryObject {
+
+ public FinMemoryObject2(int size) {
+ super(size);
+ }
+
+ protected void finalize() {
+ super.finalize();
+ System.gc();
+ Algorithms.eatMemory(stresser);
+ System.runFinalization();
+ System.gc();
+ Algorithms.eatMemory(stresser);
+ System.gc();
+ }
+ }
+
+ public void run() {
+ stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(runParams.getIterations());
+ for (int i = 0; i < objectCount; ++i) {
+ new FinMemoryObject2(objectSize);
+ }
+ Algorithms.eatMemory(stresser);
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new FinalizeTest04(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest04/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest04/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest04/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest05/FinalizeTest05.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest05/FinalizeTest05.java
new file mode 100644
index 0000000..dcc1159
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest05/FinalizeTest05.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2009, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/FinalizeTest05.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.FinalizeTest05.FinalizeTest05
+ */
+
+package gc.gctests.FinalizeTest05;
+
+import nsk.share.gc.*;
+import java.util.*;
+import nsk.share.TestFailure;
+import nsk.share.test.ExecutionController;
+import nsk.share.test.Stresser;
+
+/**
+ */
+public class FinalizeTest05 extends GCTestBase {
+
+ private final int allocRatio = 5;
+ private final int size = 1024 * 2;
+ private int count = 1000;
+ private ExecutionController stresser;
+
+ private void runOne() {
+ ArrayList objs = new ArrayList(count);
+ Object o;
+ for (int i = 0; i < count; i++) {
+ if (i % allocRatio == 0) {
+ o = new FinMemoryObject(size);
+ objs.add(o);
+ } else {
+ o = new byte[size - Memory.getObjectExtraSize()];
+ }
+ }
+ FinMemoryObject.dumpStatistics();
+ o = null;
+
+ /* force finalization */
+ Algorithms.eatMemory(stresser);
+ System.gc();
+ Runtime.getRuntime().runFinalization();
+ System.gc();
+ Runtime.getRuntime().runFinalization();
+
+ FinMemoryObject.dumpStatistics();
+
+ boolean error;
+ System.out.println("Allocated: " + FinMemoryObject.getAllocatedCount());
+ System.out.println("Finalized: " + FinMemoryObject.getFinalizedCount());
+ error = (FinMemoryObject.getFinalizedCount() != 0);
+
+ // Just hit the objs array to do say VM that we use this object
+ // and it should be alive in this point.
+ objs.clear();
+ if (error) {
+ throw new TestFailure("Test failed.");
+ }
+ }
+
+ public void run() {
+ stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(runParams.getIterations());
+ count = (int) Math.min(runParams.getTestMemory() / size, Integer.MAX_VALUE);
+ System.out.println("Allocating " + count
+ + " objects. 1 out of " + allocRatio
+ + " will have a finalizer.");
+ System.out.flush();
+ runOne();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new FinalizeTest05(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest05/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest05/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest05/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC01/FinalizerGC01.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC01/FinalizerGC01.java
new file mode 100644
index 0000000..ce12ad5
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC01/FinalizerGC01.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/FinalizerGC01.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * This rather contrived test checks the interplay of garbage collection
+ * and finalizers. Just before a 0.5 Meg linked list is garbage collected,
+ * the finalizer generates more garbage . The test fails if an OutOfMemoryError
+ * is thrown.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.FinalizerGC01.FinalizerGC01
+ */
+
+package gc.gctests.FinalizerGC01;
+
+import nsk.share.TestFailure;
+
+class node {
+ byte [] arr;
+ node next;
+ node prev;
+ node(int info){ arr = new byte[128]; }
+}
+
+class CircularLinkedList{
+ private void addElement(int info) {
+ node newnode;
+ newnode = new node(info);
+ if (Root == null){
+ Root = newnode;
+ Root.next = Root;
+ Root.prev = Root;
+ } else{
+ newnode.next = Root.next;
+ Root.next.prev = newnode;
+ Root.next = newnode;
+ newnode.prev = Root;
+ }
+ }
+ int elementCount() {
+ node p;
+ int count;
+ p = Root;
+ count = 0;
+ do {
+ p = p.prev;
+ count++;
+ }while(p != Root);
+ return count;
+ }
+ public void build1MegList() {
+ for (int i = 0 ; i < NELEMENTS ; i++)
+ addElement(i);
+ }
+ node Root=null;
+ static final int NELEMENTS=4096;
+}
+class CircularLinkedListFinal extends CircularLinkedList {
+ protected void finalize () {
+ CircularLinkedList cl = null;
+ // generate 1.5Meg more garbage
+ int i = 0;
+ int gcFails=0;
+ while (i < 3){
+ Root = null;
+ gcFails=0;
+ while (gcFails < NGCFAILS) {
+ try {
+ cl = new CircularLinkedList();
+ cl.build1MegList();
+ cl = null;
+ break;
+ }
+ catch (OutOfMemoryError e) {
+ System.gc();
+ gcFails++;
+ }
+ }
+ if (gcFails >= NGCFAILS) break;
+ i++;
+ }
+ if (i < 3) throw new OutOfMemoryError();
+ }
+ private static final int NGCFAILS=10;
+}
+
+public class FinalizerGC01 {
+ public static void main(String args[]) {
+ int count = 0;
+ int gcFails = 0;
+ CircularLinkedListFinal cl = null;
+ while (count < 64) {
+ gcFails = 0;
+ while (gcFails<NGCFAILS) {
+ try {
+ cl = new CircularLinkedListFinal();
+ cl.build1MegList();
+ doComputation();
+ cl = null;
+ break;
+ } catch (OutOfMemoryError e) {
+ gcFails++;
+ System.gc();
+ }
+ }
+ if (gcFails >= NGCFAILS) break;
+ count++;
+ }
+ if (count < 64)
+ throw new TestFailure("Test failed on " + count + " iteration");
+ else
+ System.out.println("Test Passed");
+ }
+ static void doComputation(){
+ long i = 0;
+ while ( i < 1000000L) { i++; }
+ }
+ private static final int NGCFAILS=10;
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC02/FinalizerGC02.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC02/FinalizerGC02.java
new file mode 100644
index 0000000..722599c
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC02/FinalizerGC02.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/FinalizerGC02.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * In this contrived test, the finalizer creates more garbage. As the finalizer
+ * is invoked prior to garbage collection, this puts more stress on the
+ * garbage collector.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.FinalizerGC02.FinalizerGC02
+ */
+
+package gc.gctests.FinalizerGC02;
+
+import nsk.share.TestFailure;
+
+class node {
+ byte [] arr;
+ node next;
+ node prev;
+ node(int info){ arr = new byte[100]; }
+}
+
+class CircularLinkedList{
+ node Root;
+
+ private void addElement(int info) {
+ node newnode;
+
+ newnode = new node(info);
+ if (Root == null){
+ Root = newnode;
+ Root.next = Root;
+ Root.prev = Root;
+ } else {
+ newnode.next = Root.next;
+ Root.next.prev = newnode;
+ Root.next = newnode;
+ newnode.prev = Root;
+ }
+ }
+
+ int elementCount() {
+ node p;
+ int count;
+
+ p = Root;
+ count = 0;
+
+ do {
+ p = p.prev;
+ count++;
+ }while(p != Root);
+ return count;
+ }
+
+ public void buildNMegList(int N) {
+ for (int i = 0 ; i < N*10000 ; i++)
+ addElement(i);
+ }
+
+ protected void finalize () {
+ // generate 1Meg more garbage
+ FinalizerGC02.listHolder = new CircularLinkedList();
+ FinalizerGC02.listHolder.buildNMegList(1);
+ }
+}
+
+
+public class FinalizerGC02 {
+
+ static CircularLinkedList listHolder;
+ static int count;
+ static int returnCount() { return count; }
+
+ public static void main(String args[]) {
+ int memory_reserve[] = new int [1000];
+
+ listHolder = new CircularLinkedList();
+ listHolder.buildNMegList(1);
+
+ try {
+ while (count < 5) {
+ listHolder = new CircularLinkedList();
+ listHolder.buildNMegList(1);
+ count ++;
+ }
+ } catch (OutOfMemoryError e) {
+ memory_reserve = null;
+ System.gc();
+ throw new TestFailure("Test failed at " + count +"th iteration.");
+ }
+ System.out.println("Test Passed");
+ }
+
+ static void doComputation(){
+ long i = 0;
+ while ( i < 1000000) {
+ i ++;
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/GcPointerCheckTest/GcPointerCheckTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/GcPointerCheckTest/GcPointerCheckTest.java
new file mode 100644
index 0000000..70265df
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/GcPointerCheckTest/GcPointerCheckTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/GcPointerCheckTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Test that no pointers are broken.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.GcPointerCheckTest.GcPointerCheckTest
+ */
+
+package gc.gctests.GcPointerCheckTest;
+
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.ThreadedGCTest;
+import nsk.share.test.ExecutionController;
+
+/**
+ * Test that no pointers are broken.
+ */
+public class GcPointerCheckTest extends ThreadedGCTest {
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Test();
+ }
+
+ class Test implements Runnable {
+
+ /**
+ * Helper class for linking objects together.
+ */
+ private class PointerHelper {
+
+ public PointerHelper next;
+ }
+ private PointerHelper first;
+ ExecutionController stresser;
+
+ @Override
+ public void run() {
+ if (stresser == null) {
+ stresser = getExecutionController();
+ }
+ while (stresser.continueExecution()) {
+ testGcPointers();
+ }
+ }
+
+ /**
+ * Create a lot of objects and link them together, then verify
+ * that the pointers are pointing to the correct type of objects.
+ *
+ * @return success if all references points to the correct type
+ * of object.
+ */
+ public void testGcPointers() {
+
+ int innerIters = 1;
+ int outerIters = 200;
+
+ PointerHelper tmp1;
+ PointerHelper tmp2;
+
+ while (outerIters > 0) {
+ int i = 0;
+ tmp1 = new PointerHelper();
+ this.first = tmp1;
+
+ while (i != innerIters) {
+ i++;
+ tmp2 = new PointerHelper();
+ tmp1.next = tmp2;
+ tmp1 = tmp2;
+ tmp2 = new PointerHelper();
+ }
+
+ outerIters--;
+
+ if (!checkRefs()) {
+ throw new TestFailure("Some references were bad");
+ }
+ }
+ }
+
+ private boolean checkRefs() {
+ PointerHelper iter = this.first;
+
+ for (int i = 0; iter != null; iter = iter.next) {
+ i++;
+
+ if (iter.getClass() != PointerHelper.class) {
+ //("GC causer bad ref on " + i);
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new GcPointerCheckTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/GcPointerCheckTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/GcPointerCheckTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/GcPointerCheckTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/HeapUsageTest/HeapUsageTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/HeapUsageTest/HeapUsageTest.java
new file mode 100644
index 0000000..f3a4cbd
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/HeapUsageTest/HeapUsageTest.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/HeapUsageTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Originally it was Micro benchmark that tests the heap usage.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.HeapUsageTest.HeapUsageTest
+ */
+
+package gc.gctests.HeapUsageTest;
+
+import java.util.ArrayList;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+import nsk.share.test.Stresser;
+
+/**
+ * Micro benchmark that tests the heap usage.
+ */
+public class HeapUsageTest extends GCTestBase {
+
+ /**
+ * Helper class to store allocation size and iterations for the
+ * HeapUsageTest heap usage test program
+ */
+ private class TestValue {
+
+ private int allocationSize;
+ private int allocationIterations;
+
+ TestValue(int allocSize, int allocIters) {
+ allocationSize = allocSize;
+ allocationIterations = allocIters;
+ }
+
+ final int getSize() {
+ return allocationSize;
+ }
+
+ final int getIterations() {
+ return allocationIterations;
+ }
+ }
+
+ /**
+ * Simple micro benchmark for testing heap usage. Returns a percentage
+ * that tells how much of the total heap size the test was able to
+ * allocate.
+ *
+ * @return success if test could run until OOME was thrown, and was
+ * able to determine the heap usage in percent without any other
+ * exceptions being thrown.
+ */
+ public void run() {
+
+ try {
+ int[] testParams =
+ new int[]{512, 5, 2048, 3, 3145728, 2};
+
+
+ TestValue[] values = new TestValue[testParams.length / 2];
+ for (int i = 0; i < testParams.length / 2; i++) {
+ values[i] = new TestValue(testParams[i * 2],
+ testParams[i * 2 + 1]);
+ }
+
+ // NOTE: The call to Runtime might not look like it does anything
+ // here, but it codegens the class, so it will not OOM later on
+ // due to low-mem sitation for codegen.
+ Runtime r = Runtime.getRuntime();
+ // NOTE: Codegen freeMemory() and maxMemory() so this
+ // doesn't cause OOM in a OOM situation
+ ArrayList holdObjects = new ArrayList();
+ long currentAllocatedSize = 0;
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(0);
+ try {
+ long loopCount;
+ int nrOfLoops = 0;
+
+ for (int i = 0; i < values.length; i++) {
+ if (values[i].getIterations() > nrOfLoops) {
+ nrOfLoops = values[i].getIterations();
+ }
+ }
+
+ for (loopCount = 0;; loopCount++) {
+ for (int i = 0; i < nrOfLoops; i++) {
+ for (int k = 0; k < values.length; k++) {
+ if (i < values[k].getIterations()) {
+ if (!stresser.continueExecution()) {
+ // no time to eat all heap
+ return;
+ }
+ byte[] tmp = new byte[values[k].getSize()];
+ holdObjects.add(tmp);
+ currentAllocatedSize += (long) values[k].getSize();
+ }
+ }
+ }
+ }
+ } catch (OutOfMemoryError oome) {
+ long oomMaxMemory = r.maxMemory();
+
+ holdObjects = null;
+
+ double myPercentUsed =
+ (((double) (currentAllocatedSize))
+ / oomMaxMemory) * 100;
+
+ log.info("Heap usage percentage ( "
+ + myPercentUsed + " %) " + myPercentUsed);
+ } finally {
+ // NOTE: In case OOM wasn't hit, release references
+ // and cleanup by calling System.gc();
+ holdObjects = null;
+ }
+ } catch (OutOfMemoryError oome2) {
+ throw new TestFailure("OutOfMemoryError thrown even though it shouldn't. "
+ + "Please investigate.", oome2);
+ }
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new HeapUsageTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/HeapUsageTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/HeapUsageTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/HeapUsageTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/InterruptGC/InterruptGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/InterruptGC/InterruptGC.java
new file mode 100644
index 0000000..7e1175b
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/InterruptGC/InterruptGC.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/InterruptGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * In this test, threads perform garbage collection while constantly
+ * interrupting each other. Another thread generates the garbage.
+ * The test runs for approximately one minute (see nsk.share.runner.ThreadsRunner
+ * and nsk.share.runner.RunParams). The test passes if no exceptions are generated.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.InterruptGC.InterruptGC -gp random(arrays) -ms low
+ */
+
+package gc.gctests.InterruptGC;
+
+import nsk.share.gc.*;
+import nsk.share.test.*;
+import nsk.share.gc.gp.*;
+
+import java.util.*;
+
+/**
+ * The test starts one thread which generates garbage and several other
+ * thread which continuously do System.gc() and interrupt each other.
+ */
+public class InterruptGC extends ThreadedGCTest implements GarbageProducerAware, MemoryStrategyAware {
+ private GarbageProducer garbageProducer;
+ private MemoryStrategy memoryStrategy;
+ private List<Interrupter> interrupters = new ArrayList<Interrupter>();
+ private int count;
+ private long size;
+
+ private class GarbageCreator implements Runnable {
+ public void run() {
+ Object[] arr = new Object[count];
+ for (int i = 0; i < count && getExecutionController().continueExecution(); ++i)
+ arr[i] = garbageProducer.create(size);
+ }
+ }
+
+ private class Interrupter implements Runnable {
+ private Thread thread;
+
+ public void run() {
+ if (thread == null)
+ thread = Thread.currentThread();
+ Interrupter interrupter = interrupters.get(LocalRandom.nextInt(interrupters.size()));
+ Thread thread = interrupter.getThread();
+ if (thread != null)
+ thread.interrupt();
+ System.gc();
+ }
+
+ public Thread getThread() {
+ return thread;
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ switch (i) {
+ case 0:
+ return new GarbageCreator();
+ default:
+ Interrupter interrupter = new Interrupter();
+ interrupters.add(interrupter);
+ return interrupter;
+ }
+ }
+
+ public void run() {
+ size = GarbageUtils.getArraySize(runParams.getTestMemory(), memoryStrategy);
+ count = GarbageUtils.getArrayCount(runParams.getTestMemory(), memoryStrategy);
+ super.run();
+ }
+
+ public void setGarbageProducer(GarbageProducer garbageProducer) {
+ this.garbageProducer = garbageProducer;
+ }
+
+ public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
+ this.memoryStrategy = memoryStrategy;
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new InterruptGC(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/InterruptGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/InterruptGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/InterruptGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/JumbleGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/JumbleGC.java
new file mode 100644
index 0000000..a5b5171
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/JumbleGC.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/JumbleGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * A vector of 10 elements is filled up with references to
+ * CicrcularLinkedList and Binary Trees of 0.1 Meg. Once this
+ * entire structure has been built, all elements in the Vecor are set to null
+ * creating 1Meg of garbage. The Vector is repopulated once again.
+ * With ineffective garbage collection, the heap will soon fill up.
+ * If an OutofMemoryError is thrown, the test fails.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.JumbleGC.JumbleGC
+ */
+
+package gc.gctests.JumbleGC;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import java.util.Vector;
+
+public class JumbleGC extends TestBase {
+ public void run() {
+ int TreeSize = 1000;
+ int gc_count;
+ int randNum;
+ int num = 0;
+
+ Vector v = new Vector(10);
+
+ // Build a tree containing 100 treeNodes occupying about
+ // 1Meg of heap space.
+
+ gc_count = 0;
+ try {
+ for(int i = 0; i < 10 ; i++) {
+ if ( i % 2 == 0 )
+ v.addElement(buildCircularLinkedList());
+ else
+ v.addElement(buildTree());
+ }
+
+ while (gc_count < 10) {
+
+ for (int i = 0; i < 10 ; i++)
+ v.setElementAt(null, i);
+
+ for (int i = 0; i < 10 ; i++) {
+ if ( i % 2 == 0 )
+ v.setElementAt(buildCircularLinkedList(),i);
+ else
+ v.setElementAt(buildTree(),i);
+ }
+ gc_count ++;
+ log.info("Finished iteration # " + gc_count);
+ }
+
+ } catch (OutOfMemoryError e) {
+ log.error("Test Failed.");
+ setFailed(true);
+ }
+ log.info("Test Passed.");
+ }
+
+ public static void main(String args[]){
+ GC.runTest(new JumbleGC(), args);
+ }
+
+ // build a binary tree of 0.1 Meg.(100 treeNodes in the three, each of 100 bytes
+
+ private Tree buildTree() {
+ int i, randNum;
+
+ i = 0;
+ Tree newTree = new Tree(100);
+ while (i < 100) {
+ randNum = LocalRandom.nextInt(0, 1000000);
+ newTree.addElement(randNum);
+ i++;
+ }
+ return newTree;
+ }
+
+ // build a circular linked list of 0.1 Meg
+ private CircularLinkedList buildCircularLinkedList() {
+ CircularLinkedList cl;
+ cl = new CircularLinkedList(100);
+ for(int i = 0; i < 1000; i++)
+ cl.grow();
+ return cl;
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/Tree.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/Tree.java
new file mode 100644
index 0000000..1025ea5
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/Tree.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package gc.gctests.JumbleGC;
+
+import java.util.Vector ;
+
+class treeNode {
+ static int memorySinkSize = 100;
+ int info;
+ treeNode left;
+ treeNode right;
+ int [] memory_sink;
+
+ public treeNode(int info) {
+ this.info = info;
+ memory_sink = new int[memorySinkSize];
+ }
+}
+
+
+public class Tree {
+
+ private treeNode TreeRoot; // root of Tree
+ private int elementCount; // number of elements in Tree
+ Vector TreeValues; // all the nodal values in the tree
+ // duplicated in this array.
+ private int TreeValueIndex; // Where to store next Tree value
+
+
+ Tree(int TreeSize) { TreeValues = new Vector(TreeSize); }
+
+ synchronized void addElement(int o) {
+ treeNode p,q;
+
+ treeNode newnode = new treeNode(o);
+ p = TreeRoot;
+ q = null;
+
+ while(p != null){
+ q = p;
+ if(newnode.info <= p.info)
+ p = p.left;
+ else
+ p = p.right;
+ }
+
+ if ( q == null ){
+ TreeRoot = newnode;
+ return;
+ }
+ if (newnode.info <= q.info )
+ q.left = newnode;
+ else
+ q.right = newnode;
+ elementCount++;
+ TreeValues.addElement(new Integer(o));
+ }
+
+
+int getTreeValue(int index) {
+ Integer num;
+ num = (Integer) TreeValues.elementAt(index);
+ TreeValues.removeElementAt(index);
+ return num.intValue();
+ }
+
+
+ int vectorSize(){ return TreeValues.size(); }
+
+
+ synchronized void PrettyPrint(){
+ Print(TreeRoot, "");
+ }
+
+ private void Print( treeNode root, String indent) {
+ if(root == null){
+ return;
+ }
+ Print(root.right, indent + " ");
+ System.out.println(indent + root.info);
+ Print(root.left, indent + " ");
+ }
+
+
+ synchronized int getNodeNumber(){return elementCount; }
+
+ synchronized private treeNode findNode(int o) {
+ treeNode p, q;
+ p = TreeRoot;
+ while(p != null && p.info != o){
+ q = p;
+ if (o < p.info )
+ p = p.left;
+ else if(o > p.info)
+ p = p.right;
+ }
+ return p;
+ }
+
+ // destroy subtree rooted at treeNode containing int o
+ // creating a subtree of garbage rooted at treeNode containing int o
+
+ void destroySubTree(int o) {
+ treeNode p,q;
+
+ // find treeNode containing p.
+ p = TreeRoot;
+ q = null;
+ while(p != null && p.info != o){
+ q = p;
+ if (o < p.info )
+ p = p.left;
+ else if(o > p.info)
+ p = p.right;
+ }
+
+ if (p == null){ // couldnt find treeNode
+ return;
+ }
+
+ // decrease elementCount of tree by the number of treeNodes
+ // in sub-tree rooted at p
+
+ elementCount -= getCount(p);
+ if (q == null){ // destroy the whole tree
+ TreeRoot = null;
+ return;
+ }
+
+ if (p.info > q.info ) // deleting right child
+ q.right = null;
+ else
+ q.left = null;
+ }
+
+
+ synchronized void deleteElement(int o){
+ treeNode p,q;
+ treeNode rc, sub_node, leftmost, leftmost_parent,s;
+
+ p = TreeRoot;
+ q = null;
+ sub_node = null;
+
+ while(p != null && p.info != o){
+ q = p;
+ if (o < p.info )
+ p = p.left;
+ else if(o > p.info)
+ p = p.right;
+ }
+
+ if ( p == null) // couldnt find treeNode
+ return;
+
+ rc = p.right;
+
+ if (rc == null){
+ sub_node = p.left;
+ } else if (rc.left == null) {
+ rc.left = p.left;
+ sub_node = p.right;
+ }else if ( rc.left != null && rc.right != null) {
+ s = rc;
+ leftmost_parent = null;
+ leftmost = null;
+ while ( s != null){
+ leftmost_parent = leftmost;
+ leftmost = s;
+ s = s.left;
+ }
+ leftmost_parent.left = leftmost.right;
+ leftmost.left = p.left;
+ leftmost.right= p.right;
+ sub_node = leftmost;
+ }
+
+ if ( q == null ){
+ TreeRoot = sub_node;
+ return;
+ }
+
+ if (p.info > q.info ) // deleting right child
+ q.right = sub_node;
+ else
+ q.left = sub_node;
+
+ return;
+ }
+
+
+ private int getCount( treeNode root) {
+ if (root == null )
+ return 0;
+ if (root.left == null && root.right == null)
+ return 1;
+ else
+ return getCount(root.left) + getCount(root.right) + 1;
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/JumbleGC002.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/JumbleGC002.java
new file mode 100644
index 0000000..a15a67f
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/JumbleGC002.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2003, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/JumbleGC002.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quarantine]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector can manage jumble in the JVM. The
+ * test fails if any unexpected exceptions and errors are thrown or the JVM
+ * is not crashed.
+ * The test starts a number of threads that is set in *.cfg file or calculates
+ * that value based on the machine. All threads have
+ * java.util.Vector field anf they fill that vector with 4 types of objects:
+ * 1. Initialized long[]
+ * 2. Uninitialized double[]
+ * 3. Initialized int[]
+ * 4. A nsk.share.gc.NonbranchyTree (number of nodes and their size depend
+ * on valkue returned by Runtime.maxMemory())
+ * As soon as the vector is filled, each thread removes half elements of it and
+ * then fills those places of the vector again. However, all threads use just
+ * about 10% of maximum amount of memory that JVM attemts to use, so
+ * OutOfMemoryError is treated as a failure. That means GC does not work
+ * quickly enough to destroy all objects that do not have references. The
+ * procedure of filling and cleaning of the vector is repeated for
+ * INTERNAL_ITERATIONS times.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.JumbleGC002.JumbleGC002
+ */
+
+package gc.gctests.JumbleGC002;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
+
+import nsk.share.*;
+import nsk.share.gc.*;
+
+/**
+ * This test simply does Algorithms.eatMemory() in a loop
+ * in multiple threads.
+ */
+public class JumbleGC002 extends ThreadedGCTest {
+
+ // The test should fill just about 10% of the heap
+ final static double PART_OF_HEAP = 0.1;
+ // Maximum number of elements in an array of primitive types
+ final static int ARRAY_MAX_LENGTH = 10;
+ // Internal number of iterations to create new objects and to drop
+ // references
+ final static int INTERNAL_ITERATIONS = 150;
+ // Size of core for each node of a tree
+ final static int EACH_NODE_SIZE = 1;
+ // Number of bytes that arrays of primitive types take in the vector
+ final static long PRIMITIVE_ARRAYS_SIZE = (long) (8 * ARRAY_MAX_LENGTH
+ + 8 * ARRAY_MAX_LENGTH + 4 * ARRAY_MAX_LENGTH);
+
+ private class Eater implements Runnable {
+
+ private Vector vector;
+ int numberOfElements;
+ int numberOfQuarters;
+ int id;
+ int nodes;
+ ThreadLocalRandom random = ThreadLocalRandom.current();
+
+ public Eater(int id, int numberOfQuarters, int nodes) {
+ this.numberOfQuarters = numberOfQuarters;
+ numberOfElements = 4 * numberOfQuarters;
+ this.id = id;
+ this.nodes = nodes;
+ }
+
+ public void run() {
+ // Make jumble in the heap!
+ initVector();
+ while (getExecutionController().continueExecution()) {
+ fillVector();
+ cleanVector();
+ }
+ }
+
+ // Initialize the vector and build appropriate number of cells in it
+ private void initVector() {
+ vector = new Vector();
+ for (int i = 0; i < numberOfElements; i++) {
+ vector.addElement(null);
+ }
+ }
+
+ // Fill the vector. It is devided into quarters. Each quarters has an
+ // initialized array of long and int, and uninitialized array of double.
+ // Each array has not more than ARRAY_MAX_LENGTH elements. The fourth
+ // element in the quarter is a NonbranchyTree.
+ private void fillVector() {
+ for (int i = 0; i < numberOfQuarters; i++) {
+
+ // Append initialized long[]
+ int length = random.nextInt(ARRAY_MAX_LENGTH);
+ long[] l = new long[length];
+ for (int j = 0; j < length; j++) {
+ l[j] = (long) j;
+ }
+ if (vector.elementAt(4 * i) == null) {
+ vector.setElementAt(l, 4 * i);
+ }
+
+ // Append not initialized double[]
+ length = random.nextInt(ARRAY_MAX_LENGTH);
+ double[] d = new double[length];
+ if (vector.elementAt(4 * i + 1) == null) {
+ vector.setElementAt(d, 4 * i + 1);
+ }
+
+ // Append initialized int[]
+ length = random.nextInt(ARRAY_MAX_LENGTH);
+ int[] n = new int[length];
+ for (int j = 0; j < length; j++) {
+ n[j] = j;
+ }
+ if (vector.elementAt(4 * i + 2) == null) {
+ vector.setElementAt(n, 4 * i + 2);
+ }
+
+ // Append a tree. Every even thread has a "bent" tree.
+ NonbranchyTree tree = new NonbranchyTree(nodes, 0.3f, EACH_NODE_SIZE);
+ if (id % 2 == 0) {
+ tree.bend();
+ }
+ if (vector.elementAt(4 * i + 3) == null) {
+ vector.setElementAt(tree, 4 * i + 3);
+ }
+ }
+ }
+
+ // Drop references to half of the elements of the vector
+ private void cleanVector() {
+ int index = random.nextInt(numberOfElements / 2);
+ for (int i = index; i < index + numberOfElements / 2; i++) {
+ vector.setElementAt(null, i);
+ }
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ // Perform calculations specific to the test
+ long memoryForThread = (long) (Runtime.getRuntime().maxMemory() * PART_OF_HEAP / runParams.getNumberOfThreads());
+ int numberOfQuarters;
+
+ if (i == 0) {
+ // The very first thread
+ numberOfQuarters = 1;
+ } else {
+ // All other threads
+ numberOfQuarters = 8;
+ }
+
+ // Calculate number of nodes for a tree depending on number of
+ // elements in the Vector
+
+ double freeMemory = (double) memoryForThread / numberOfQuarters
+ - (double) PRIMITIVE_ARRAYS_SIZE;
+ int nodes = (int) (freeMemory / (NonbranchyTree.MIN_NODE_SIZE + EACH_NODE_SIZE));
+ nodes = Math.max(1, nodes);
+ log.debug("Thread " + i + " has a tree with "
+ + nodes + " node(s).");
+
+ return new Eater(i, numberOfQuarters, nodes);
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new JumbleGC002(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large001/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large001/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large001/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large001/large001.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large001/large001.java
new file mode 100644
index 0000000..e670e31
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large001/large001.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/LargeObjects/large001.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quick]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly does not throw any
+ * unexpected exceptions/errors while allocating large objects (classes
+ * that have more than 65535 fields and classes that have less than 65535
+ * fields). 65535 of fields is a limitation for JVM (see JVM specification
+ * Second edition 4.10).
+ * Since it is impossible to create one class with about 65535 of fields
+ * (javac cannot compile it), a child class extends a parent class, so the
+ * fields are devided into two subsets. However, the child class still has
+ * about 65535 of fields.
+ * The test starts a number of threads. This number is either set in *.cfg
+ * file or is calculated by the test itself based on the machine (see
+ * nsk.share.gc.Algorithms.getThreadsCount() method). As soon as all threads
+ * are started, each thread begins its checking.
+ * There are 13 classes to be loaded by each thread. These classes are
+ * generated by nsk.share.gc.Generator (see its javadoc for more details).
+ * Each class has a huge number of fields, but this number is less than the JVM
+ * limitation.
+ * The test loads the classes with nsk.share.gc.GCClassUnloader class that
+ * extends nsk.share.ClassUnloader and has a bit different algorith of eating
+ * heap. As soon as a class is loaded, the test creates an instance of
+ * it - allocates an object of that type. Then it drops references to the
+ * class and to the instance and tries to unload the class. The test does not
+ * expect any exceptions to be thrown.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ *
+ * @comment generate and compile nsk.share.gc.newclass.* classes
+ * @run driver nsk.share.gc.GenClassesBuilder
+ *
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * -Xlog:gc*
+ * gc.gctests.LargeObjects.large001.large001
+ * -largeClassesPath classes
+ * -isOverLimitFields false
+ * -aggregationDepth 0
+ * -t 1
+ */
+
+package gc.gctests.LargeObjects.large001;
+
+import java.lang.reflect.*;
+import java.lang.ref.WeakReference;
+import java.util.*;
+import nsk.share.TestFailure;
+
+
+import nsk.share.gc.*;
+import nsk.share.*;
+
+public class large001 extends ThreadedGCTest {
+
+ // Package of the classes to be loaded
+ final static String PREFIX = "nsk.share.gc.newclass.";
+ // A bunch of classes that have number of fields more than JVM limitation
+ final static String[] LCLASSES = {PREFIX + "private_int_lchild",
+ PREFIX + "protected_short_lchild",
+ PREFIX + "public_long_lchild",
+ PREFIX + "public_Object_lchild",
+ PREFIX + "static_byte_lchild",
+ PREFIX + "static_float_lchild",
+ PREFIX + "transient_boolean_lchild",
+ PREFIX + "volatile_double_lchild",
+ PREFIX + "protected_combination_lchild",
+ PREFIX + "public_combination_lchild",
+ PREFIX + "static_combination_lchild",
+ PREFIX + "transient_combination_lchild",
+ PREFIX + "volatile_combination_lchild"
+ };
+ // A bunch of classes that have number of fields less than JVM limitation
+ final static String[] SCLASSES = {PREFIX + "private_int_schild",
+ PREFIX + "protected_short_schild",
+ PREFIX + "public_long_schild",
+ PREFIX + "public_Object_schild",
+ PREFIX + "static_byte_schild",
+ PREFIX + "static_float_schild",
+ PREFIX + "transient_boolean_schild",
+ PREFIX + "volatile_double_schild",
+ PREFIX + "protected_combination_schild",
+ PREFIX + "public_combination_schild",
+ PREFIX + "static_combination_schild",
+ PREFIX + "transient_combination_schild",
+ PREFIX + "volatile_combination_schild"
+ };
+ boolean isOverLimitFields = true;
+ int aggregationDepth = 0;
+ String largeClassesPath;
+
+ private class Worker implements Runnable {
+
+ int id;
+
+ public Worker(int id) {
+ this.id = id;
+ }
+
+ public void run() {
+ try {
+ // Use special ClassUnloader to load/unload classes
+ ClassUnloader unloader = new ClassUnloader();
+ String[] classes = isOverLimitFields ? LCLASSES : SCLASSES;
+
+ for (String name : classes) {
+ // Load the class
+ log.debug(id + ": Loading class: " + name);
+ unloader.loadClass(name, largeClassesPath);
+ log.debug(id + ": Class loaded: " + name);
+
+ Class loadedClass = unloader.getLoadedClass();
+ Object loadedClassInstance = loadedClass.newInstance();
+
+ log.debug(id + ": Instance of the class: " + loadedClassInstance);
+ int depth = aggregationDepth;
+ List<WeakReference> refs = new ArrayList<WeakReference>(depth);
+ addObjRef(loadedClassInstance, loadedClass, depth, refs);
+
+ // Drop all references to the class and try to unload it
+ Algorithms.eatMemory(getExecutionController());
+ log.debug(id + ": Testing non-null after GC force for: " + name);
+ if (loadedClass == null || loadedClassInstance == null) {
+ throw new Exception("Null class");
+ }
+ verifyObjRef(loadedClassInstance, depth);
+ for (WeakReference ref : refs) {
+ if (ref.get() == null) {
+ throw new Exception("Unexpected null reference");
+ }
+ }
+ refs = null;
+ loadedClass = null;
+ loadedClassInstance = null;
+
+ log.debug(id + ": Unloading class: "
+ + name);
+ boolean result = unloader.unloadClass(getExecutionController());
+ log.debug(id + ": Result of uloading "
+ + "class " + name + ": " + result);
+ }
+ } catch (OutOfMemoryError oome) {
+ // just skip if we eat memory in several threads...
+ // rethrow in the case of one thread
+ if (runParams.getNumberOfThreads() == 1) {
+ throw oome;
+ }
+ } catch (Throwable t) {
+ throw new TestFailure("Unexpected exception: ", t);
+ }
+ }
+
+ // This method recursively create chain of aggregated objects for given object
+ public void addObjRef(Object object, Class clazz, int count, List<WeakReference> list) throws Throwable {
+ if (count == 0) {
+ return;
+ }
+
+ Field[] fields = object.getClass().getFields();
+ for (Field field : fields) {
+ if (field.getName().startsWith("obj")) {
+ Object addedObject = clazz.newInstance();
+ field.set(object, addedObject);
+ System.out.println("Added field " + field.getName() + " .... " + count);
+ addObjRef(addedObject, clazz, count - 1, list);
+ list.add(new WeakReference<Object>(addedObject));
+ }
+ }
+ }
+
+ // This method recursively verfiy chain of aggregated objects for given object.
+ // Throws null pointer exception of objP/C field is null
+ public void verifyObjRef(Object object, int count) throws Throwable {
+ if (count == 0) {
+ return;
+ }
+
+ Field[] fields = object.getClass().getFields();
+ for (Field field : fields) {
+ if (field.getName().startsWith("obj")) {
+ Object obj = field.get(object);
+ verifyObjRef(obj, count - 1);
+ }
+ }
+ }
+ }
+
+ public large001(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("-largeClassesPath")) {
+ largeClassesPath = args[++i];
+ } else if (args[i].equals("-isOverLimitFields")) {
+ isOverLimitFields = Boolean.getBoolean(args[++i]);
+ } else if (args[i].equals("-aggregationDepth")) {
+ aggregationDepth = Integer.parseInt(args[++i]);
+ }
+ }
+ if (largeClassesPath == null || largeClassesPath.length() == 0) {
+ throw new TestFailure("No classpath for large classes is given");
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker(i);
+ }
+
+ @Override
+ public void run() {
+ if (isOverLimitFields) {
+ log.debug("Loading classes that have number "
+ + "of fields over limitation (more "
+ + "than 65535)");
+ } else {
+ log.debug("Loading classes that have number "
+ + "of fields under limitation (less "
+ + "than 65535)");
+ }
+ super.run();
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new large001(args), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large002/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large002/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large002/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large002/TestDescription.java
new file mode 100644
index 0000000..9668dfa
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large002/TestDescription.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/LargeObjects/large002.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly does not throw any
+ * unexpected exceptions/errors while allocating large objects (classes
+ * that have more than 65535 fields and classes that have less than 65535
+ * fields). 65535 of fields is a limitation for JVM (see JVM specification
+ * Second edition 4.10).
+ * Since it is impossible to create one class with about 65535 of fields
+ * (javac cannot compile it), a child class extends a parent class, so the
+ * fields are devided into two subsets. However, the child class still has
+ * about 65535 of fields.
+ * The test starts a number of threads. This number is either set in *.cfg
+ * file or is calculated by the test itself based on the machine (see
+ * nsk.share.gc.Algorithms.getThreadsCount() method). As soon as all threads
+ * are started, each thread begins its checking.
+ * There are 13 classes to be loaded by each thread. These classes are
+ * generated by nsk.share.gc.Generator (see its javadoc for more details).
+ * Each class has a huge number of fields, and the number of fields is more than
+ * the JVM limitation.
+ * The test loads the classes with nsk.share.gc.GCClassUnloader class that
+ * extends nsk.share.ClassUnloader and has a bit different algorith of eating
+ * heap. As soon as a class is loaded, the test creates an instance of
+ * it - allocates an object of that type. Then it drops references to the
+ * class and to the instance and tries to unload the class. The test does not
+ * expect any exceptions to be thrown.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ *
+ * @comment generate and compile nsk.share.gc.newclass.* classes
+ * @run driver nsk.share.gc.GenClassesBuilder
+ *
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.LargeObjects.large001.large001
+ * -largeClassesPath classes
+ * -isOverLimitFields true
+ * -aggregationDepth 0
+ * -t 1
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large003/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large003/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large003/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large003/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large003/TestDescription.java
new file mode 100644
index 0000000..5c940cf
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large003/TestDescription.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/LargeObjects/large003.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly does not throw any
+ * unexpected exceptions/errors while allocating large objects (classes
+ * that have more than 65535 fields and classes that have less than 65535
+ * fields). 65535 of fields is a limitation for JVM (see JVM specification
+ * Second edition 4.10).
+ * Since it is impossible to create one class with about 65535 of fields
+ * (javac cannot compile it), a child class extends a parent class, so the
+ * fields are devided into two subsets. However, the child class still has
+ * about 65535 of fields.
+ * The test starts a number of threads. This number is either set in *.cfg
+ * file or is calculated by the test itself based on the machine (see
+ * nsk.share.gc.Algorithms.getThreadsCount() method). As soon as all threads
+ * are started, each thread begins its checking.
+ * There are 13 classes to be loaded by each thread. These classes are
+ * generated by nsk.share.gc.Generator (see its javadoc for more details).
+ * Each class has a huge number of fields, but this number is less than the JVM
+ * limitation.
+ * The test loads the classes with nsk.share.gc.GCClassUnloader class that
+ * extends nsk.share.ClassUnloader and has a bit different algorith of eating
+ * heap. As soon as a class is loaded, the test creates an instance of
+ * it - allocates an object of that type. Then it drops references to the
+ * class and to the instance and tries to unload the class. The test does not
+ * expect any exceptions to be thrown.
+ * Additionaly to original tests this test create object with large count of
+ * field which contains also a reference to other such object wich also
+ * contains same reference and so on. The deep of such aggregation is controlled
+ * by the test. These references are verified after GC.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ *
+ * @comment generate and compile nsk.share.gc.newclass.* classes
+ * @run driver nsk.share.gc.GenClassesBuilder
+ *
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.LargeObjects.large001.large001
+ * -largeClassesPath classes
+ * -isOverLimitFields false
+ * -aggregationDepth 3
+ * -t 1
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large004/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large004/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large004/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large004/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large004/TestDescription.java
new file mode 100644
index 0000000..63873b7
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large004/TestDescription.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/LargeObjects/large004.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly does not throw any
+ * unexpected exceptions/errors while allocating large objects (classes
+ * that have more than 65535 fields and classes that have less than 65535
+ * fields). 65535 of fields is a limitation for JVM (see JVM specification
+ * Second edition 4.10).
+ * Since it is impossible to create one class with about 65535 of fields
+ * (javac cannot compile it), a child class extends a parent class, so the
+ * fields are devided into two subsets. However, the child class still has
+ * about 65535 of fields.
+ * The test starts a number of threads. This number is either set in *.cfg
+ * file or is calculated by the test itself based on the machine (see
+ * nsk.share.gc.Algorithms.getThreadsCount() method). As soon as all threads
+ * are started, each thread begins its checking.
+ * There are 13 classes to be loaded by each thread. These classes are
+ * generated by nsk.share.gc.Generator (see its javadoc for more details).
+ * Each class has a huge number of fields, but this number is less than the JVM
+ * limitation.
+ * The test loads the classes with nsk.share.gc.GCClassUnloader class that
+ * extends nsk.share.ClassUnloader and has a bit different algorith of eating
+ * heap. As soon as a class is loaded, the test creates an instance of
+ * it - allocates an object of that type. Then it drops references to the
+ * class and to the instance and tries to unload the class. The test does not
+ * expect any exceptions to be thrown.
+ * Additionaly to original tests this test create object with large count of
+ * field which contains also a reference to other such object wich also
+ * contains same reference and so on. The deep of such aggregation is controlled
+ * by the test. These references are verified after GC.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ *
+ * @comment generate and compile nsk.share.gc.newclass.* classes
+ * @run driver nsk.share.gc.GenClassesBuilder
+ *
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.LargeObjects.large001.large001
+ * -largeClassesPath classes
+ * -isOverLimitFields true
+ * -aggregationDepth 1
+ * -t 1
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large005/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large005/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large005/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large005/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large005/TestDescription.java
new file mode 100644
index 0000000..908da47
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LargeObjects/large005/TestDescription.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/LargeObjects/large005.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly does not throw any
+ * unexpected exceptions/errors while allocating large objects (classes
+ * that have more than 65535 fields and classes that have less than 65535
+ * fields). 65535 of fields is a limitation for JVM (see JVM specification
+ * Second edition 4.10).
+ * Since it is impossible to create one class with about 65535 of fields
+ * (javac cannot compile it), a child class extends a parent class, so the
+ * fields are devided into two subsets. However, the child class still has
+ * about 65535 of fields.
+ * The test starts a number of threads. This number is either set in *.cfg
+ * file or is calculated by the test itself based on the machine (see
+ * nsk.share.gc.Algorithms.getThreadsCount() method). As soon as all threads
+ * are started, each thread begins its checking.
+ * There are 13 classes to be loaded by each thread. These classes are
+ * generated by nsk.share.gc.Generator (see its javadoc for more details).
+ * Each class has a huge number of fields, but this number is less than the JVM
+ * limitation.
+ * The test loads the classes with nsk.share.gc.GCClassUnloader class that
+ * extends nsk.share.ClassUnloader and has a bit different algorith of eating
+ * heap. As soon as a class is loaded, the test creates an instance of
+ * it - allocates an object of that type. Then it drops references to the
+ * class and to the instance and tries to unload the class. The test does not
+ * expect any exceptions to be thrown.
+ * Additionaly to original tests this test create object with large count of
+ * field which contains also a reference to other such object wich also
+ * contains same reference and so on. The deep of such aggregation is controlled
+ * by the test. These references are verified after GC.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ *
+ * @comment generate and compile nsk.share.gc.newclass.* classes
+ * @run driver nsk.share.gc.GenClassesBuilder
+ *
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.LargeObjects.large001.large001
+ * -largeClassesPath classes
+ * -isOverLimitFields true
+ * -aggregationDepth 3
+ * -t 1
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC/LoadUnloadGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC/LoadUnloadGC.java
new file mode 100644
index 0000000..11dcf23
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC/LoadUnloadGC.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/LoadUnloadGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, monitoring]
+ * VM Testbase readme:
+ * In this test a 1000 classes are loaded and unloaded in a loop.
+ * Class0 gets loaded which results in Class1 getting loaded and so on all
+ * the way uptill class1000. The classes should be unloaded whenever a
+ * garbage collection takes place because their classloader is made unreachable
+ * at the end of the each loop iteration. The loop is repeated 1000 times.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @build nsk.share.gc.ClassChain
+ * @run main/othervm
+ * -XX:MaxMetaspaceSize=64M
+ * -XX:MetaspaceSize=32M
+ * -XX:CompressedClassSpaceSize=32M
+ * gc.gctests.LoadUnloadGC.LoadUnloadGC
+ */
+
+package gc.gctests.LoadUnloadGC;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.classload.ClassPathNonDelegatingClassLoader;
+import vm.share.monitoring.MemoryPoolFinder;
+
+import java.io.*;
+import java.util.*;
+import java.lang.management.MemoryPoolMXBean;
+
+/**
+ * This test checks that classes are unloaded when loaded multiple times
+ * with custom class loader.
+ */
+public class LoadUnloadGC extends ThreadedGCTest {
+ private final String className = "nsk.share.gc.ClassChain";
+ private int [] memory_reserve = new int[10000];
+
+ private class Loader implements Runnable {
+ private Class class_zero_class;
+ private Object class_zero_object;
+
+ public void run() {
+ try {
+ // load Class0 and instantiate it
+ // This will cause all thousand classes to get loaded
+ ClassPathNonDelegatingClassLoader loader = new ClassPathNonDelegatingClassLoader();
+ class_zero_class = loader.loadClass(className, false);
+ class_zero_object = class_zero_class.newInstance();
+ // Set all references to null . This should cause a GC
+ // which should forces an unloading of all these
+ // unreferenced classes.
+ class_zero_class = null;
+ class_zero_object = null;
+ loader = null;
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ return new Loader();
+ }
+
+ protected static int getThreadCount() {
+ MemoryPoolMXBean bean = MemoryPoolFinder.findPool(MemoryPoolFinder.METASPACE);
+ ClassPathNonDelegatingClassLoader loader = new ClassPathNonDelegatingClassLoader();
+ long used = bean.getUsage().getUsed();
+ long free = 0;
+ int classesCount = 1000;
+ int classesToLoad = 10;
+ if(bean.getUsage().getMax() == -1) {
+ throw new RuntimeException("Metaspace size should be limited for this test.");
+ }
+ try {
+ for(int i = 1; i <= classesToLoad; i++) {
+ loader.loadClass("nsk.share.gc.Class"+i);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ used = bean.getUsage().getUsed() - used;
+ free = (bean.getUsage().getMax() - bean.getUsage().getUsed())/2;
+ return Math.min((int)(0.95*free/(classesCount/classesToLoad*used)),
+ Runtime.getRuntime().availableProcessors());
+ }
+
+ public static void main(String args[]) {
+ int threadCount = getThreadCount();
+ if (Arrays.binarySearch(args,"-t") < 0) {
+ args = Arrays.copyOf(args,args.length+2);
+ args[args.length-2] = "-t";
+ args[args.length-1] = Integer.toString(threadCount);
+ }
+ GC.runTest(new LoadUnloadGC(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC2/LoadUnloadGC2.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC2/LoadUnloadGC2.java
new file mode 100644
index 0000000..1210603
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC2/LoadUnloadGC2.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/LoadUnloadGC2.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quick]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.LoadUnloadGC2.LoadUnloadGC2
+ */
+
+package gc.gctests.LoadUnloadGC2;
+
+import nsk.share.*;
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.gc.gp.*;
+import nsk.share.gc.gp.classload.*;
+import java.lang.reflect.Array;
+
+public class LoadUnloadGC2 extends GCTestBase {
+ public void run() {
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(500000);
+ try {
+ while (stresser.iteration()) {
+ GarbageProducer garbageProducer = new GeneratedClassProducer();
+ log.info("Iteration: " + stresser.getIteration());
+ GarbageUtils.eatMemory(stresser, garbageProducer, 0);
+ garbageProducer = null;
+ }
+ } finally {
+ stresser.finish();
+ }
+ }
+
+ public static void main(String[] args) {
+ Tests.runTest(new LoadUnloadGC2(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC2/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC2/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/LoadUnloadGC2/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/MTLinkedListGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/MTLinkedListGC.java
new file mode 100644
index 0000000..6d93dec
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/MTLinkedListGC.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/MTLinkedListGC.
+ * VM Testbase keywords: [gc, stress, nonconcurrent]
+ * VM Testbase readme:
+ * In this test 1000 threads contribute in the formation
+ * of 1 Meg circular Linked list. Insertion into the linked list
+ * is sequential. Once formed, the linked list is converted to
+ * garbage and the process repeated 50 times. The test fails
+ * if an OutofMemoryException is thrown and passes otherwise.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.MTLinkedListGC.MTLinkedListGC
+ */
+
+package gc.gctests.MTLinkedListGC;
+
+import java.util.Vector;
+import nsk.share.TestFailure;
+
+class CircularLinkedList {
+ synchronized void addElement(String info) {
+ node newnode;
+ int elementCount ; // Number of nodes in LinkedList
+ elementCount = elementCount();
+ // Do not allow the linked list to grow to more
+ // than 100000 nodes
+ if (elementCount >= MAXNODES)
+ return;
+ newnode = new node(info);
+ if (Root == null) {
+ Root = newnode;
+ Root.next = Root;
+ Root.prev = Root;
+ }
+ else {
+ newnode.next = Root.next;
+ Root.next.prev = newnode;
+ Root.next = newnode;
+ newnode.prev = Root;
+ }
+ }
+ private synchronized int elementCount() {
+ node p;
+ int count;
+ if (Root == null)
+ return 0;
+ p = Root;
+ count = 0;
+ do {
+ p = p.prev;
+ count++;
+ } while(p != Root);
+ return count;
+ }
+ private node Root;
+ private final int MAXNODES = 100000;
+}
+
+class LinkedListGrower extends Thread {
+ LinkedListGrower(int ThreadNumber) {
+ setName("Thread-" + ThreadNumber);
+ }
+
+ public void run() {
+ LinkedListHolder.getCircularLinkedList().addElement(getName());
+ }
+}
+
+class LinkedListHolder {
+ private static CircularLinkedList cl = new CircularLinkedList();
+ static CircularLinkedList getCircularLinkedList() { return cl; }
+ static void getNewList() { cl = new CircularLinkedList(); }
+}
+
+public class MTLinkedListGC {
+ public static void main(String args[]) {
+ int memory_reserve[] = new int [1000];
+ Thread ThreadsArray[] = new LinkedListGrower[1000];
+ int count;
+// for(int i = 0; i < ThreadsArray.length; i++ )
+// ThreadsArray[i] = new LinkedListGrower(i);
+ count = 0;
+ try {
+ while(count < 50 ){
+ for(int i = 0; i < ThreadsArray.length; i++ )
+ ThreadsArray[i] = new LinkedListGrower(i);
+ for(int i = 0 ; i < ThreadsArray.length ; i++)
+ ThreadsArray[i].start();
+ try {
+ for(int i =0 ; i < ThreadsArray.length ; i++)
+ ThreadsArray[i].join();
+ } catch(Exception e) { }
+ //turn the old linked list into garbage
+ LinkedListHolder.getNewList();
+ System.out.println("Finished iteration " + count);
+ count ++;
+ }
+ } catch (OutOfMemoryError e) {
+ memory_reserve = null;
+ System.gc();
+ throw new TestFailure("Test Failed at " + count +"th iteration.");
+ }
+ System.out.println("Test Passed");
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/node.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/node.java
new file mode 100644
index 0000000..ca12ab6
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTLinkedListGC/node.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package gc.gctests.MTLinkedListGC;
+
+class node {
+ int sink[];
+ String name;
+ node prev;
+ node next;
+
+ public node (String threadName){
+ name = threadName;
+ sink = new int[1000];
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MTasyncGC/MTasyncGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTasyncGC/MTasyncGC.java
new file mode 100644
index 0000000..08909a8
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTasyncGC/MTasyncGC.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/MTasyncGC.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * This test creates 1000 threads that run in a sequential
+ * fashion with each thread in turn generating 1Meg of garbage.
+ * The test relies upon the garbage collector asynchrnonously
+ * reclaiming garbage.
+ * The test fails if an OutOfMemoryError is thrown and passes
+ * if the test proceeds to completion without an exception being
+ * thrown.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.MTasyncGC.MTasyncGC
+ */
+
+package gc.gctests.MTasyncGC;
+
+import java.util.Vector;
+import nsk.share.TestFailure;
+
+// Each thread creates 1Meg of garbage in the run() method.
+
+class MemEvil extends Thread {
+ static Vector v = new Vector();
+ static {
+ for(int i = 0; i < 10; i++)
+ v.addElement(new char [100000]);
+ }
+
+ public void run () {
+ int i = 0;
+ while(i < 10) {
+ v.setElementAt(new char[100000], i);
+ i++;
+ }
+ }
+}
+
+
+public class MTasyncGC {
+
+ public static void main(String args[] ){
+ int i;
+ int memory_reserve[] = new int [10000];
+ Thread threadsHolder[] = new Thread[1000];
+
+ for(i = 0; i < threadsHolder.length; i++)
+ threadsHolder[i] = new MemEvil();
+
+ i = 0;
+ while(i < threadsHolder.length ){
+ try {
+ threadsHolder[i].start();
+ threadsHolder[i].join();
+ } catch ( Exception e ) {
+ memory_reserve = null;
+ System.gc();
+ throw new TestFailure("Test Failed.", e);
+ }
+ threadsHolder[i] = null;
+ i++;
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MTsyncGC/MTsyncGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTsyncGC/MTsyncGC.java
new file mode 100644
index 0000000..93cba1c
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MTsyncGC/MTsyncGC.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/MTsyncGC.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * This test creates 1000 threads that run in a sequential
+ * fashion with each thread in turn generating 1Meg of garbage.
+ * Before exiting, each of these threads synchronously calls
+ * the garbage collector in another thread.
+ * The test fails if an OutOfMemoryError is thrown and passes
+ * if nothing happens.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.MTsyncGC.MTsyncGC
+ */
+
+package gc.gctests.MTsyncGC;
+
+import nsk.share.TestFailure;
+import java.util.Vector;
+
+
+
+
+// Each thread creates 1Meg of garbage in the run() method.
+
+class MemEvil extends Thread {
+ static Vector v = new Vector();
+ static {
+ for(int i = 0; i < 10; i++)
+ v.addElement(new char [100000]);
+ }
+
+ public void run () {
+ int i = 0;
+ while(i < 10) {
+ v.setElementAt(new char[100000], i);
+ i++;
+ }
+ try {
+ //synchronously invoke the garbage
+ // collector in another thread
+ MTsyncGC.reclaimer.start();
+ MTsyncGC.reclaimer.join();
+ }catch (Exception e) {}
+ }
+}
+
+
+class Reclaimer extends Thread{
+ public void run() {
+ System.gc();
+ }
+}
+
+public class MTsyncGC {
+ static Reclaimer reclaimer = new Reclaimer();
+ public static void main(String args[] ){
+ int i;
+ int memory_reserve[] = new int [10000];
+ Thread threadsHolder[] = new Thread[1000];
+
+ for(i = 0; i < threadsHolder.length; i++)
+ threadsHolder[i] = new MemEvil();
+
+ i = 0;
+ while(i < threadsHolder.length ){
+ try {
+ threadsHolder[i].start();
+ threadsHolder[i].join();
+ } catch ( Exception e ) {
+ memory_reserve = null;
+ System.gc();
+ throw new TestFailure("Test Failed.", e);
+ }
+ threadsHolder[i] = null;
+ i++;
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MatrixJuggleGC/MatrixJuggleGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/MatrixJuggleGC/MatrixJuggleGC.java
new file mode 100644
index 0000000..6f29192
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MatrixJuggleGC/MatrixJuggleGC.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/MatrixJuggleGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * ********************************
+ * set TIMEOUT = 20
+ * *******************************
+ * This test creates a 2 dimensional matrix of (100X100)10,000 elements.
+ * Each element in this matrix houses the address of a "Cell" that
+ * occupies about 100 bytes. The total memory occupied by this structure is
+ * about 1M.
+ * Once this structure, has been built, 5 threads are let loose that
+ * randomly choose an element in this matrix and set its contents to null
+ * effectively creating 100bytes of garbage. The threads continue to act
+ * until all 5 threads combined have "nulled out" half the cells in the matrix.
+ * At this point, 5 refiller threads proceed to refill the empty
+ * matrix elements with new cells.
+ * Once the refiller threads have refilled all the empty matrix elements
+ * with new cells, the cycle begins all over again with the 5 "emptier"
+ * threads "nulling out" cells randomly.
+ * This is repeated 50 times. Every iteration produces 0.5 Meg
+ * of garbage. The maximum amount of live memory at use at any time is 1Meg.
+ * If no garbage collection takes place during any of the ten iterations,
+ * the total amount(live + garbage) of heap space consumed at the end
+ * of the program is 0.5*50 + 1 = 26Meg.
+ * The test fails if an OutOfMemory Exception is thrown.
+ * ----------------------------- --------
+ * | | | | | | | 100 |
+ * | | | | | *--|------>| bytes|
+ * | | | | | | --------
+ * -----------------------------
+ * . . . . . .
+ * . . . . . .
+ * . . . . . .
+ * .
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * ------------------------------
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * ------------------------------
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * ------------------------------
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * -----------------------------
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.MatrixJuggleGC.MatrixJuggleGC -iterations 1000000
+ */
+
+package gc.gctests.MatrixJuggleGC;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import java.util.Stack;
+import java.util.EmptyStackException;
+
+public class MatrixJuggleGC extends GCTestBase {
+ private int threadCount = 5;
+ private Matrix cm = new Matrix(100, 100);
+ private Stack<IndexPair> emptiedLocations = new Stack<IndexPair>();
+
+ private class CellEmptier extends Thread {
+ private boolean keepEmptying(){
+ int numberOfCells;
+ int matrixSize;
+
+ matrixSize = cm.returnArrayBound();
+ numberOfCells = (matrixSize + 1) * (matrixSize + 1) ;
+ if (cm.getCellCount() < numberOfCells/2)
+ return true;
+ else
+ return false;
+ }
+
+ public void run() {
+ int i, j, matrixSize,emptyCells;
+
+ matrixSize = cm.returnArrayBound();
+ while (keepEmptying()) {
+ i = LocalRandom.nextInt(0, matrixSize);
+ j = LocalRandom.nextInt(0, matrixSize);
+ emptiedLocations.push(new IndexPair(i,j));
+ cm.clear(i, j);
+ }
+ }
+ }
+
+ private class CellRefiller extends Thread {
+ public void run() {
+ int i, j, emptyCells;
+ while (!emptiedLocations.empty()) {
+ try {
+ IndexPair pair = emptiedLocations.pop();
+ cm.repopulate(pair.getI(), pair.getJ());
+ } catch (EmptyStackException e) {
+ break;
+ }
+ }
+ }
+ }
+
+ private class StackDump extends Thread {
+ public void run() {
+ int emptyCells;
+ while (true) {
+ emptyCells = emptiedLocations.size();
+ System.out.println("Number of empty cells = " + emptyCells);
+ }
+ }
+ }
+
+ private void runIteration() {
+ Thread emptierArray[] = new Thread[threadCount];
+ Thread fillerArray[] = new Thread[threadCount];
+ for (int i = 0; i < threadCount; i++)
+ emptierArray[i] = new CellEmptier();
+ for (int i = 0; i < threadCount; i++)
+ emptierArray[i].start();
+
+ // wait for "emptier" threads to finish their job
+
+ int i = 0;
+ while (i < threadCount) {
+ try {
+ emptierArray[i].join();
+ } catch(InterruptedException e) {}
+ i++;
+ }
+
+ // Now start refilling.
+
+ for (i = 0; i < threadCount; i++)
+ fillerArray[i] = new CellRefiller();
+ for (i = 0; i < threadCount; i++)
+ fillerArray[i].start();
+
+ i = 0;
+ while (i < threadCount ){
+ try {
+ fillerArray[i].join();
+ } catch(InterruptedException e){}
+ i++;
+ }
+ // reset count of cells
+ cm.resetCellCount();
+ }
+
+ public void run() {
+ threadCount = runParams.getNumberOfThreads();
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(runParams.getIterations());
+ while (stresser.iteration())
+ runIteration();
+ stresser.finish();
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new MatrixJuggleGC(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MatrixJuggleGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/MatrixJuggleGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MatrixJuggleGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEater/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEater/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEater/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEater/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEater/TestDescription.java
new file mode 100644
index 0000000..8f7ac8a
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEater/TestDescription.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/MemoryEater.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.MemoryEaterMT.MemoryEaterMT -t 1
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEaterMT/MemoryEaterMT.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEaterMT/MemoryEaterMT.java
new file mode 100644
index 0000000..58d80be
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEaterMT/MemoryEaterMT.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/MemoryEaterMT.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.MemoryEaterMT.MemoryEaterMT
+ */
+
+package gc.gctests.MemoryEaterMT;
+
+import nsk.share.gc.*;
+
+/**
+ * This test simply does Algorithms.eatMemory() in a loop
+ * in multiple threads.
+ */
+public class MemoryEaterMT extends ThreadedGCTest {
+
+ private class Eater implements Runnable, OOMStress {
+ public void run() {
+ Algorithms.eatMemory(getExecutionController());
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ return new Eater();
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new MemoryEaterMT(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEaterMT/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEaterMT/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/MemoryEaterMT/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/MonitorThread.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/MonitorThread.java
new file mode 100644
index 0000000..552e652
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/MonitorThread.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package gc.gctests.ObjectMonitorCleanup;
+
+import nsk.share.test.ExecutionController;
+
+/**
+ * Helper thread class for ObjectMonitorCleanup class
+ */
+public class MonitorThread extends Thread {
+
+ /**
+ * Object used for synchronization between threads in the test.
+ */
+ public static volatile Object otherObject;
+ /**
+ * Simple way for the test to check if the running thread completed
+ * it's work or not.
+ */
+ public boolean completedOk;
+ /**
+ * Tells the worker thread if it should keep running or if
+ * it should terminate.
+ */
+ public volatile boolean keepRunning;
+ private ExecutionController stresser;
+
+ /**
+ * Constructor for the thread.
+ *
+ * @param maxRunTimeMillis Maximum time in milliseconds that
+ * the thread should run.
+ */
+ public MonitorThread(ExecutionController stresser) {
+ this.stresser = stresser;
+ this.otherObject = new Object(); /* avoid null on first reference */
+ }
+
+ /**
+ * Main entry point for the thread.
+ */
+ public final void run() {
+ synchronized (this) {
+ completedOk = false;
+ keepRunning = true;
+ }
+
+ // Do we need to lock keepRunning before we check it?
+ while (keepRunning
+ && stresser.continueExecution()) {
+ Object placeholder = otherObject;
+ synchronized (placeholder) {
+ placeholder.notifyAll();
+ }
+ }
+
+ synchronized (this) {
+ completedOk = keepRunning;
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/ObjectMonitorCleanup.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/ObjectMonitorCleanup.java
new file mode 100644
index 0000000..61ef411
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/ObjectMonitorCleanup.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/ObjectMonitorCleanup.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Verifies that object monitor objects are cleared
+ * out just like PhantomReferences are.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.ObjectMonitorCleanup.ObjectMonitorCleanup
+ */
+
+package gc.gctests.ObjectMonitorCleanup;
+
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+import nsk.share.test.Stresser;
+
+
+public class ObjectMonitorCleanup extends GCTestBase {
+
+ /**
+ * Verifies that object monitor objects are cleared out
+ * just like PhantomReferences are.
+ *
+ * @return True if successful.
+ */
+ @Override
+ public void run() {
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(0);
+
+
+ MonitorThread mt = new MonitorThread(stresser);
+ mt.start();
+
+ try {
+ while (stresser.continueExecution()) {
+ MonitorThread.otherObject = new byte[(int) (runParams.getTestMemory() / 10000)];
+ synchronized (MonitorThread.otherObject) {
+ MonitorThread.otherObject.wait(10);
+ }
+ }
+ } catch (InterruptedException e) {
+ synchronized (mt) {
+ mt.keepRunning = false;
+ }
+
+ try {
+ Thread.sleep(runParams.getSleepTime());
+ } catch (InterruptedException e1) {
+ }
+
+ throw new TestFailure("Problem doing synchronization.");
+ }
+
+ try {
+ mt.join();
+
+ if (!mt.completedOk) {
+ throw new TestFailure("Test thread didn't report "
+ + "successful completion");
+ }
+ } catch (InterruptedException e) {
+ throw new TestFailure("Couldn't wait for thread to finish.");
+ }
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new ObjectMonitorCleanup(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ObjectMonitorCleanup/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/OneeFinalizerTest/OneeFinalizerTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/OneeFinalizerTest/OneeFinalizerTest.java
new file mode 100644
index 0000000..469ba83
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/OneeFinalizerTest/OneeFinalizerTest.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/OneeFinalizerTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Regression test that verifies that only one finalizer gets called.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * -Xlog:gc:gc.log
+ * gc.gctests.OneeFinalizerTest.OneeFinalizerTest
+ */
+
+package gc.gctests.OneeFinalizerTest;
+
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+import nsk.share.gc.gp.GarbageUtils;
+import nsk.share.test.Stresser;
+
+/**
+ * Test that verifies that finalize() method is invoking only once.
+ */
+public class OneeFinalizerTest extends GCTestBase {
+
+ private GlobalSafeCounter[] finalizerCounters = null;
+
+ /**
+ * Helper class used for counting number of calls to finalizers.
+ */
+ protected class GlobalSafeCounter {
+
+ private int counter;
+
+ /**
+ * Constructor that inits the global counter to 0.
+ */
+ protected GlobalSafeCounter() {
+ counter = 0;
+ }
+
+ /**
+ * Reset the global counter to 0.
+ */
+ protected final void resetCounter() {
+ synchronized (this) {
+ counter = 0;
+ }
+ }
+
+ /**
+ * Increase the global counter by 1.
+ */
+ protected final void increaseCounter() {
+ synchronized (this) {
+ counter++;
+ }
+ }
+
+ /**
+ * Retrieve the global counter value.
+ *
+ * @return value of the global counter
+ */
+ protected final int getCounterValue() {
+ int value;
+
+ synchronized (this) {
+ value = counter;
+ }
+
+ return value;
+ }
+ }
+
+ /**
+ * Helper class the implements finalize(), and that increments
+ * the global counters for each finalize() invokation.
+ */
+ protected class FinalizedObject {
+
+ private final int counterIndex;
+
+ /**
+ * Constructor for the helper object which implements finalize().
+ *
+ * @param index Index for the counter in the global array, that
+ * corresponds to this object.
+ */
+ protected FinalizedObject(int index) {
+ counterIndex = index;
+ }
+
+ /**
+ * Increases the global counter for this object when finalize()
+ * gets called (to make sure each finalizer gets called onee).
+ */
+ @Override
+ protected final void finalize() {
+ finalizerCounters[counterIndex].increaseCounter();
+ }
+ }
+
+ private void initOneeFinalizerTest(int numberOfObjects) {
+ // NOTE: Set to null in case it's been used before (to prevent OOM)
+ finalizerCounters = null;
+ finalizerCounters = new GlobalSafeCounter[numberOfObjects];
+
+ for (int i = 0; i < numberOfObjects; i++) {
+ finalizerCounters[i] = new GlobalSafeCounter();
+ }
+ }
+
+ /**
+ * Tests that the finalize() method on each FinalizedObject instance
+ * has been called exactly one time.
+ */
+ @Override
+ public void run() {
+
+
+ int numberOfObjects = 2000;
+
+ initOneeFinalizerTest(numberOfObjects);
+
+ FinalizedObject[] testObjects = new FinalizedObject[numberOfObjects];
+
+ // creates garbage
+ for (int i = 0; i < numberOfObjects; i++) {
+ testObjects[i] = new FinalizedObject(i);
+ }
+
+ if (testObjects[0].hashCode() == 212_85_06) {
+ System.out.println("Bingo!!!");
+ }
+
+ testObjects = null;
+
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(0);
+ /* force finalization */
+ GarbageUtils.eatMemory(stresser);
+ if (!stresser.continueExecution()) {
+ // may be we didn't eat all memory and didn't provoke GC
+ System.out.println("Passed without check");
+ return;
+ }
+ System.gc();
+ System.runFinalization();
+ System.gc();
+ System.runFinalization();
+ System.gc();
+
+ int numberOfFinalizersRunMoreThanOnce = 0;
+ int numberOfFinalizersNotRun = 0;
+
+ for (int i = 0; i < numberOfObjects; i++) {
+ int counter = finalizerCounters[i].getCounterValue();
+ if (counter > 1) {
+ numberOfFinalizersRunMoreThanOnce++;
+ System.err.println("Object #" + i + " counter = " + counter);
+ } else if (counter == 0) {
+ System.err.println("WARNING: Finalizer not run for object #" + i);
+ numberOfFinalizersNotRun++;
+ }
+ }
+
+ if (numberOfFinalizersNotRun > 0) {
+ System.err.println("WARNING: " + numberOfFinalizersNotRun + " finalizers not run");
+ }
+
+ if (numberOfFinalizersRunMoreThanOnce != 0) {
+ throw new TestFailure("OneeFinalizerTest failed. " + numberOfFinalizersRunMoreThanOnce + " errors");
+ }
+ System.out.println("Test passed.");
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new OneeFinalizerTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/OneeFinalizerTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/OneeFinalizerTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/OneeFinalizerTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PRHelper.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PRHelper.java
new file mode 100644
index 0000000..feb928a
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PRHelper.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package gc.gctests.PhantomReference;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+
+/**
+ * Helper class that extends PhantomReference, that we can use
+ * to match the hash code for the referent object.
+ */
+public final class PRHelper extends PhantomReference {
+
+ private int referentHashCode;
+
+ /**
+ * Constructor for extended PhantomReference class.
+ *
+ * @param o Referred object
+ * @param referenceQueue Reference queue to attach the PR to
+ */
+ public PRHelper(Object o, ReferenceQueue referenceQueue) {
+ super(o, referenceQueue);
+ referentHashCode = -1;
+ }
+
+ /**
+ * Get the referred objects hash code.
+ *
+ * @return Hash code for referred object
+ */
+ public int getReferentHashCode() {
+ return referentHashCode;
+ }
+
+ /**
+ * Set the original referred objects hash code for tracking.
+ *
+ * @param referentHashCode New hash code
+ */
+ public void setReferentHashCode(int referentHashCode) {
+ this.referentHashCode = referentHashCode;
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomHelper.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomHelper.java
new file mode 100644
index 0000000..050e040
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomHelper.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package gc.gctests.PhantomReference;
+
+import java.lang.ref.ReferenceQueue;
+import java.util.Date;
+import java.util.HashMap;
+
+/**
+ * Helper class that tracks the original hash code for the
+ * object.
+ */
+public final class PhantomHelper {
+
+ private int originalHashCode;
+ private int hashCounter;
+
+ /**
+ * Constructor for helper class that tracks the hash code.
+ *
+ * @param originalHashCode Referred objects hash code
+ */
+ public PhantomHelper(int originalHashCode) {
+ this.originalHashCode = originalHashCode;
+ hashCounter = 1;
+ }
+
+ /**
+ * Get the referred objects original hash code.
+ *
+ * @return Original referred objects hash code
+ */
+ public int getOriginalHashCode() {
+ return originalHashCode;
+ }
+
+ /**
+ * Increase the counter for the number of objects
+ * using this hash code.
+ */
+ public void increaseHashCounter() {
+ hashCounter++;
+ }
+
+ /**
+ * Decrease the counter for the number of objects
+ * using this hash code.
+ */
+ public void decreaseHashCounter() {
+ hashCounter--;
+ }
+
+ /**
+ * Retreive the hash code counter.
+ *
+ * @return Hash code counter value
+ */
+ public int getHashCounter() {
+ return hashCounter;
+ }
+
+ /**
+ * Verify all the hash codes from the objects in the reference
+ * queue against the hash map.
+ *
+ * @param rq Reference queue for the phantom references.
+ * @param hmHelper Hashmap that contains all the hash codes
+ * @param maxWaitTime Maximum time to wait for completion of deref:ing
+ * from the reference queue.
+ * @return True if all hash codes matches
+ */
+ public static final String checkAllHashCodes(ReferenceQueue rq,
+ HashMap hmHelper,
+ long maxWaitTime) {
+ // Check all the phantom references
+ long startTime = new Date().getTime();
+ boolean keepRunning = true;
+
+ while (keepRunning) {
+ try {
+ PRHelper prh = (PRHelper) rq.remove(1000);
+
+ if (prh != null) {
+ Integer ik = new Integer(prh.getReferentHashCode());
+ PhantomHelper ph = (PhantomHelper) hmHelper.get(ik);
+
+ if (ph != null) {
+ if (ph.getOriginalHashCode()
+ == prh.getReferentHashCode()) {
+ ph.decreaseHashCounter();
+ if (ph.getHashCounter() == 0) {
+ hmHelper.remove(
+ new Integer(prh.getReferentHashCode()));
+ } else {
+ hmHelper.put(ik, ph);
+ }
+ prh.clear();
+ }
+ } else {
+ return "Unmapped hash code detected. The test is faulty.";
+ }
+
+ prh = null;
+ }
+ } catch (InterruptedException e) {
+ ; // Checkstyle wants at least one line here...
+ }
+
+ if (new Date().getTime() - startTime > maxWaitTime) {
+ return "All phantom references weren't processed "
+ + "in the configured max time ("
+ + (maxWaitTime / 1000) + " secs)";
+ }
+
+ if (hmHelper.size() == 0) {
+ keepRunning = false;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceEvilTest/PhantomReferenceEvilTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceEvilTest/PhantomReferenceEvilTest.java
new file mode 100644
index 0000000..b9a5ccc
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceEvilTest/PhantomReferenceEvilTest.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/PhantomReference/PhantomReferenceEvilTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Test that verifies the PhantomReference handling in a more evil way.
+ * In this test, it will only keep every Xth object, thus causing more
+ * fragmentation and fill the heap with unused objects. This test should
+ * not throw any OOME during the test execution.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.PhantomReference.PhantomReferenceEvilTest.PhantomReferenceEvilTest
+ */
+
+package gc.gctests.PhantomReference.PhantomReferenceEvilTest;
+
+import gc.gctests.PhantomReference.PhantomHelper;
+import gc.gctests.PhantomReference.PRHelper;
+import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
+import java.util.Random;
+import java.util.HashMap;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+import nsk.share.gc.Memory;
+import nsk.share.gc.gp.GarbageUtils;
+import nsk.share.test.Stresser;
+
+/**
+ * Tests for the PhantomReference handling in a more evil way.
+ *
+ * This test must be run with a mx value set to ensure
+ * Runtime.maxMemory() doesn't return 0.
+ */
+public class PhantomReferenceEvilTest extends GCTestBase {
+
+ /**
+ * Test that verifies the PhantomReference handling in a more evil way.
+ * In this test, it will only keep every Xth object, thus causing more
+ * fragmentation and fill the heap with unused objects. This test should
+ * not throw any OOME during the test execution.
+ *
+ * @return success if all phantom references were enqueued
+ */
+ public final void run() {
+ long seed;
+ int minSize;
+ int maxSize;
+ int keepEveryXthObject;
+ double memPercentToFill;
+ long maxWaitTime;
+ long counter = 0;
+ long totalMemAlloced = 0;
+ long memToAlloc = 0;
+ long nrOfPrs = 0;
+ Runtime r = Runtime.getRuntime();
+
+
+ seed = runParams.getSeed();
+ minSize = 2048;
+ maxSize = 32768;
+ keepEveryXthObject = 5;
+ memPercentToFill = 0.45;
+ maxWaitTime = 30000;
+ memToAlloc = (long) (r.maxMemory() * memPercentToFill);
+ Random rndGenerator = new Random(seed);
+ long multiplier = maxSize - minSize;
+ ReferenceQueue rq = new ReferenceQueue();
+ HashMap hmHelper = new HashMap();
+ ArrayList alPhantomRefs = new ArrayList();
+
+ try {
+ try {
+ while (totalMemAlloced + Memory.getReferenceSize()
+ * hmHelper.size() < memToAlloc) {
+ int allocationSize = ((int) (rndGenerator.nextDouble()
+ * multiplier)) + minSize;
+ byte[] tmp = new byte[allocationSize];
+
+ if (counter % keepEveryXthObject == 0) {
+ Integer ik = new Integer(tmp.hashCode());
+ if (hmHelper.containsKey(ik)) {
+ PhantomHelper ph = (PhantomHelper) hmHelper.get(ik);
+ ph.increaseHashCounter();
+ hmHelper.put(ik, ph);
+ } else {
+ hmHelper.put(ik, new PhantomHelper(tmp.hashCode()));
+ }
+
+ PRHelper prh = new PRHelper(tmp, rq);
+ prh.setReferentHashCode(tmp.hashCode());
+ alPhantomRefs.add(prh);
+ totalMemAlloced +=
+ Memory.getArraySize(allocationSize, Memory.getByteSize())
+ + Memory.getReferenceSize()
+ + Memory.getReferenceObjectSize();
+
+ //Make sure the temporary object is dereferenced
+ prh = null;
+ nrOfPrs++;
+ }
+
+ // Make sure the temporary object is dereferenced
+ tmp = null;
+ counter++;
+ if (counter == Long.MAX_VALUE) {
+ counter = 0;
+ }
+ }
+ } catch (OutOfMemoryError oome) {
+ alPhantomRefs.clear();
+ hmHelper.clear();
+ log.info(nrOfPrs + " phantom refs had been allocated when "
+ + "OOME occured");
+ throw new TestFailure("OutOfMemoryException was thrown. This should "
+ + "not happen during the execution of this test.");
+ }
+
+
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(0);
+ GarbageUtils.eatMemory(stresser);
+ if (!stresser.continueExecution()) {
+ return; //we couldn't be sure that FullGC is triggered
+ }
+
+ String retInfo = PhantomHelper.checkAllHashCodes(
+ rq, hmHelper, maxWaitTime);
+ if (retInfo != null) {
+ alPhantomRefs.clear();
+ hmHelper.clear();
+ throw new TestFailure(retInfo);
+ }
+
+ log.info(nrOfPrs + " phantom refs were allocated during the test");
+ } finally {
+ // Make sure the ArrayList:s are live at the end of the test
+ // to make sure that the references gets enqueued.
+ alPhantomRefs.clear();
+ hmHelper.clear();
+ alPhantomRefs = null;
+ hmHelper = null;
+ }
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new PhantomReferenceEvilTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceEvilTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceEvilTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceEvilTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceTest/PhantomReferenceTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceTest/PhantomReferenceTest.java
new file mode 100644
index 0000000..0a4c628
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceTest/PhantomReferenceTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/PhantomReference/PhantomReferenceTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Test that verifies the PhantomReference handling in JRockit.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.PhantomReference.PhantomReferenceTest.PhantomReferenceTest
+ */
+
+package gc.gctests.PhantomReference.PhantomReferenceTest;
+
+import gc.gctests.PhantomReference.PRHelper;
+import gc.gctests.PhantomReference.PhantomHelper;
+import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Random;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+import nsk.share.gc.gp.GarbageUtils;
+import nsk.share.test.Stresser;
+
+/**
+ * Tests for the PhantomReference handling in JRockit.
+ */
+public class PhantomReferenceTest extends GCTestBase {
+
+ /**
+ * Test that verifies the PhantomReference handling in JRockit.
+ *
+ * @return success if all phantom references were enqueued
+ */
+ public final void run() {
+ long seed;
+ int minSize;
+ int maxSize;
+ int nrOfObjs;
+ int sleepTime;
+ long maxWaitTime;
+
+
+ seed = runParams.getSeed();
+ minSize = 2048;
+ maxSize = 32768;
+ nrOfObjs = 1000;
+ sleepTime = 10000;
+ maxWaitTime = 30000;
+
+ Random rndGenerator = new Random(seed);
+ long multiplier = maxSize - minSize;
+ ReferenceQueue rq = new ReferenceQueue();
+ HashMap hmHelper = new HashMap();
+ ArrayList alPhantomRefs = new ArrayList();
+
+ for (int i = 0; i < nrOfObjs; i++) {
+ int allocationSize = ((int) (rndGenerator.nextDouble()
+ * multiplier)) + minSize;
+ byte[] tmp = new byte[allocationSize];
+ Integer ik = new Integer(tmp.hashCode());
+ if (hmHelper.containsKey(ik)) {
+ PhantomHelper ph = (PhantomHelper) hmHelper.get(ik);
+ ph.increaseHashCounter();
+ hmHelper.put(ik, ph);
+ } else {
+ hmHelper.put(ik, new PhantomHelper(tmp.hashCode()));
+ }
+
+ PRHelper prh = new PRHelper(tmp, rq);
+ prh.setReferentHashCode(tmp.hashCode());
+ alPhantomRefs.add(prh);
+ prh = null;
+ tmp = null;
+ }
+
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(0);
+ GarbageUtils.eatMemory(stresser);
+ if (!stresser.continueExecution()) {
+ return; //we couldn't be sure that FullGC is triggered
+ }
+ String retInfo = PhantomHelper.checkAllHashCodes(
+ rq, hmHelper, maxWaitTime);
+ if (retInfo != null) {
+ alPhantomRefs.clear();
+ hmHelper.clear();
+ throw new TestFailure(retInfo);
+ }
+
+ // Make sure the ArrayList:s are live at the end of the test
+ // to make sure that the references gets enqueued.
+ alPhantomRefs.clear();
+ hmHelper.clear();
+
+ alPhantomRefs = null;
+ hmHelper = null;
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new PhantomReferenceTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom001/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom001/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom001/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom001/phantom001.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom001/phantom001.java
new file mode 100644
index 0000000..bbae96d
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom001/phantom001.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/PhantomReference/phantom001.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly works with
+ * PhantomReferences. It also checks that no unexpected exceptions and errors
+ * are thrown or the JVM is not crashed.
+ * The test starts a number of threads. Each thread run tests for some time
+ * or serveral iterations. See javadoc StressOptions for configuration.
+ * First of all each thread defines what type to check (there are 11 types
+ * totally). As soon as the type is defined, a PhantomRefence is created that
+ * refers to an array of tested type and is registered with in a queue. A
+ * PhantomRefence for NonbranchyTree and Referent calsses does not refer to
+ * arrays, but to instances of the classes.
+ * After that a thread performs next checks for the reference:
+ * 1. The reference is in queue after GC is provoked with
+ * Algorithms.eatMemory() method (a single thread eats the memory).
+ * 2. reference.get() returns null.
+ * 3. queue.poll() returns the reference that was created.
+ * 4. queue.poll() again returns null.
+ * 5. If the checked type is class (Referent), then it must be finalized,
+ * since the reference is already enqueued.
+ * 6. reference.clear() does not throw any exception.
+ * The test extends ThreadedGCTest and implements GarbageProducerAware and
+ * MemoryStrategyAware interfaces. The corresponding javadoc documentation
+ * for additional test configuration.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.PhantomReference.phantom001.phantom001 -ms low
+ */
+
+package gc.gctests.PhantomReference.phantom001;
+
+import java.lang.ref.*;
+import nsk.share.gc.*;
+import nsk.share.gc.gp.*;
+import nsk.share.gc.gp.string.InternedStringProducer;
+import nsk.share.gc.gp.string.RandomStringProducer;
+
+public class phantom001 extends ThreadedGCTest implements GarbageProducerAware, MemoryStrategyAware {
+
+ private GarbageProducer garbageProducer;
+ private MemoryStrategy memoryStrategy;
+ private InternedStringProducer internedStringProducer = new InternedStringProducer(new RandomStringProducer(10));
+ // Total number of types to test
+ final static int TYPES_COUNT = 12;
+ // Size of array of each tested type. The constant also specifies the
+ // number of nodes in a NonbranchyTree and size of each node
+ final static int SIZE = 100;
+
+ protected Runnable createRunnable(int i) {
+ return new Test();
+ }
+
+ public void setGarbageProducer(GarbageProducer garbageProducer) {
+ this.garbageProducer = garbageProducer;
+ }
+
+ public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
+ this.memoryStrategy = memoryStrategy;
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new phantom001(), args);
+ }
+
+ // The class implements the logic of the testcase
+ class Test implements Runnable {
+
+ int iteration;
+ private volatile boolean finalized;
+
+ public void run() {
+ try {
+ log.info("iteration " + iteration);
+ ReferenceQueue queue = new ReferenceQueue();
+ PhantomReference reference;
+ int code = iteration % TYPES_COUNT;
+ String type;
+ // Define a specific type for each thread to test
+ switch (code) {
+ case 0:
+ reference = new PhantomReference(new byte[SIZE], queue);
+ type = "byte";
+ break;
+ case 1:
+ reference = new PhantomReference(new short[SIZE], queue);
+ type = "short";
+ break;
+ case 2:
+ reference = new PhantomReference(new int[SIZE], queue);
+ type = "int";
+ break;
+ case 3:
+ reference = new PhantomReference(new long[SIZE], queue);
+ type = "long";
+ break;
+ case 4:
+ reference = new PhantomReference(new char[SIZE], queue);
+ type = "char";
+ break;
+ case 5:
+ reference = new PhantomReference(new boolean[SIZE], queue);
+ type = "boolean";
+ break;
+ case 6:
+ reference = new PhantomReference(new double[SIZE], queue);
+ type = "double";
+ break;
+ case 7:
+ reference = new PhantomReference(new float[SIZE], queue);
+ type = "float";
+ break;
+ case 8:
+ reference = new PhantomReference(new Object[SIZE], queue);
+ type = "Object";
+ break;
+ case 9:
+ reference = new PhantomReference(new NonbranchyTree(SIZE, 0.3f, SIZE),
+ queue);
+ type = "NonbranchyTree";
+ break;
+ case 10:
+ reference = new PhantomReference(internedStringProducer.create(SIZE), queue);
+ type = "InternedString";
+ break;
+ default:
+ reference = new PhantomReference(new Referent(), queue);
+ type = "class";
+ }
+
+ int initialFactor = memoryStrategy.equals(MemoryStrategy.HIGH) ? 1 : (memoryStrategy.equals(MemoryStrategy.LOW) ? 10 : 2);
+ GarbageUtils.eatMemory(getExecutionController(), garbageProducer, initialFactor , 10, 0);
+ if (type.equals("class")) {
+ while (!finalized && getExecutionController().continueExecution()) {
+ System.runFinalization(); //does not guarantee finalization, but increases the chance
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {}
+ GarbageUtils.eatMemory(getExecutionController(), garbageProducer, initialFactor , 10, 0);
+ }
+
+ //provoke gc once more to make finalized object phantom reachable
+ GarbageUtils.eatMemory(getExecutionController(), garbageProducer, initialFactor , 10, 0);
+ }
+ if (!getExecutionController().continueExecution()) {
+ // we were interrrupted by stresser. just exit...
+ return;
+ }
+ Reference polledReference = null;
+ try {
+ polledReference = queue.remove();
+ } catch (InterruptedException e) {
+ log.error("Unexpected InterruptedException during queue.remove().");
+ setFailed(true);
+ }
+ // Check the reference and the queue
+ // The polled reference must be equal to the one enqueued to
+ // the queue
+
+ if (polledReference != reference) {
+ log.error("The original reference is not equal to polled reference.");
+ setFailed(true);
+ }
+
+ // queue.poll() once again must return null now, since there is
+ // only one reference in the queue
+ polledReference = queue.poll();
+ if (polledReference != null) {
+ log.error("There are more than one references in the queue.");
+ setFailed(true);
+ }
+ reference.clear();
+ } catch (OutOfMemoryError e) {
+ }
+ iteration++;
+ }
+
+ class Referent {
+
+ //We need discard this flag to make second and following checks with type.equals("class") useful
+ public Referent() {
+ finalized = false;
+ }
+
+ protected void finalize() {
+ finalized = true;
+ }
+ }
+ }
+
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom002/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom002/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom002/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom002/TestDescription.java
new file mode 100644
index 0000000..1fddf0f
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/phantom002/TestDescription.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/PhantomReference/phantom002.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly works with
+ * PhantomReferences. It also checks that no unexpected exceptions and errors
+ * are thrown or the JVM is not crashed.
+ * The test starts a number of threads. Each thread run tests for some time
+ * or serveral iterations. See javadoc StressOptions for configuration.
+ * First of all each thread defines what type to check (there are 11 types
+ * totally). As soon as the type is defined, a PhantomRefence is created that
+ * refers to an array of tested type and is registered with in a queue. A
+ * PhantomRefence for NonbranchyTree and Referent calsses does not refer to
+ * arrays, but to instances of the classes.
+ * After that a thread performs next checks for the reference:
+ * 1. The reference is in queue after GC is provoked with
+ * Algorithms.eatMemory() method (a single thread eats the memory).
+ * 2. reference.get() returns null.
+ * 3. queue.poll() returns the reference that was created.
+ * 4. queue.poll() again returns null.
+ * 5. If the checked type is class (Referent), then it must be finalized,
+ * since the reference is already enqueued.
+ * 6. reference.clear() does not throw any exception.
+ * The test extends ThreadedGCTest and implements GarbageProducerAware and
+ * MemoryStrategyAware interfaces. The corresponding javadoc documentation
+ * for additional test configuration.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.PhantomReference.phantom001.phantom001 -ms high
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/CircularLinkedList.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/CircularLinkedList.java
new file mode 100644
index 0000000..cea2745
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/CircularLinkedList.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package gc.gctests.ReferencesGC;
+
+class node {
+ byte [] arr;
+ node next;
+ node prev;
+ node(){ arr = new byte[100]; }
+}
+
+public class CircularLinkedList implements Cloneable {
+ private node Root;
+
+ public void addElement() {
+ node newnode;
+
+ newnode = new node();
+ if (Root == null){
+ Root = newnode;
+ Root.next = Root;
+ Root.prev = Root;
+ } else{
+ newnode.next = Root.next;
+ Root.next.prev = newnode;
+ Root.next = newnode;
+ newnode.prev = Root;
+ }
+ }
+
+ public void addNelements(int n) {
+ for (int i = 0; i < n ; i++)
+ addElement();
+ }
+
+ public int elementCount() {
+ node p;
+ int count;
+
+ p = Root;
+ count = 0;
+
+ do {
+ p = p.prev;
+ count++;
+ }while(p != Root);
+ return count;
+ }
+
+ public Object clone() {
+ node p;
+ p = Root;
+
+ if ( p == null ) return null;
+ CircularLinkedList clone = new CircularLinkedList();
+ do {
+ clone.addElement();
+ p = p.prev;
+ } while(p != Root);
+ return clone;
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/ReferencesGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/ReferencesGC.java
new file mode 100644
index 0000000..8c5c4cb
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/ReferencesGC.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/ReferencesGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quick]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -XX:-UseGCOverheadLimit
+ * gc.gctests.ReferencesGC.ReferencesGC
+ * -range 200
+ * -ratio 0.9
+ * -t 1
+ */
+
+package gc.gctests.ReferencesGC;
+
+import java.lang.ref.*;
+import nsk.share.TestFailure;
+import nsk.share.gc.Algorithms;
+import nsk.share.gc.GC;
+import nsk.share.gc.ThreadedGCTest;
+import nsk.share.gc.gp.GarbageProducer;
+import nsk.share.gc.gp.GarbageUtils;
+import nsk.share.test.ExecutionController;
+
+public class ReferencesGC extends ThreadedGCTest {
+
+ static int RANGE = 256;
+ static float RATIO = (float) 1.0;
+
+ public static void main(String[] args) {
+ parseArgs(args);
+ GC.runTest(new ReferencesGC(), args);
+ }
+
+ public static void parseArgs(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].compareTo("-range") == 0) {
+ RANGE = new Integer(args[++i]).intValue();
+ } else if (args[i].compareTo("-ratio") == 0) {
+ RATIO = new Float(args[++i]).floatValue();
+ }
+ }
+ }
+
+ private class Worker implements Runnable {
+
+ static final int WEAK = 0;
+ static final int SOFT = 1;
+ static final int PHANTOM = 2;
+ private ExecutionController stresser;
+ int finalizationMaxTime = 1000 * 60 * runParams.getNumberOfThreads();
+ int[] alive = new int[3];
+ int[] enqued = new int[3];
+ CircularLinkedList holder[] = new CircularLinkedList[RANGE];
+ WeakReference wr[] = new WeakReference[RANGE];
+ SoftReference sr[] = new SoftReference[RANGE];
+ PhantomReference phr[] = new PhantomReference[RANGE];
+ ReferenceQueue refq = new ReferenceQueue();
+ GarbageProducer gp = GarbageUtils.getArrayProducers().get(0);
+ int iter = 0;
+
+ @Override
+ public void run() {
+ if (stresser == null) {
+ stresser = getExecutionController();
+ }
+
+ while (stresser.continueExecution()) {
+ int totalQ = 0;
+ try {
+ refq = new ReferenceQueue();
+ alive = new int[3];
+ enqued = new int[3];
+ for (int j = 0; j < RANGE; j++) {
+ holder[j] = new CircularLinkedList();
+ holder[j].addNelements(300);
+ wr[j] = new WeakReference(holder[j], refq);
+ sr[j] = new SoftReference(holder[j], refq);
+ phr[j] = new PhantomReference(holder[j], refq);
+ }
+ } catch (OutOfMemoryError oome) {
+ // we should just skip the test
+ // the other thread could eat all memory
+ continue;
+ }
+
+ for (int i = 0; i < RANGE; i++) {
+ if (wr[i].isEnqueued()) {
+ ++totalQ;
+ }
+ if (sr[i].isEnqueued()) {
+ ++totalQ;
+ }
+ if (phr[i].isEnqueued()) {
+ ++totalQ;
+ }
+ }
+ if (totalQ != 0) {
+ throw new TestFailure("There are " + totalQ + " references in the queue instead 0 before null-assigment.");
+ }
+
+ for (int i = 0; i < (int) (RANGE * RATIO); i++) {
+ holder[i] = null;
+ }
+
+ Algorithms.eatMemory(stresser);
+ if (!stresser.continueExecution()) {
+ break;
+ }
+ // At this point OOME was thrown and accordingly to spec
+ // all weak refs should be processed
+
+ alive = new int[3];
+ enqued = new int[3];
+ for (int i = 0; i < RANGE; i++) {
+ if (wr[i].get() != null) {
+ ++alive[WEAK];
+ }
+ if (wr[i].isEnqueued()) {
+ ++enqued[WEAK];
+ }
+ if (sr[i].get() != null) {
+ ++alive[SOFT];
+ }
+ if (sr[i].isEnqueued()) {
+ ++enqued[SOFT];
+ }
+ if (phr[i].isEnqueued()) {
+ ++enqued[PHANTOM];
+ }
+ }
+
+ long waitTime = System.currentTimeMillis() + finalizationMaxTime;
+ while (totalQ < (RANGE * RATIO * 3 * 0.9) && (System.currentTimeMillis() < waitTime)) {
+ alive = new int[3];
+ enqued = new int[3];
+ for (int i = 0; i < RANGE; i++) {
+ if (wr[i].get() != null) {
+ ++alive[WEAK];
+ }
+ if (wr[i].isEnqueued()) {
+ ++enqued[WEAK];
+ }
+ if (sr[i].get() != null) {
+ ++alive[SOFT];
+ }
+ if (sr[i].isEnqueued()) {
+ ++enqued[SOFT];
+ }
+ if (phr[i].isEnqueued()) {
+ ++enqued[PHANTOM];
+ }
+ }
+ totalQ = (enqued[WEAK] + enqued[SOFT] + enqued[PHANTOM]);
+ if (totalQ < (int) (3 * RANGE * RATIO * 0.9)) {
+ log.debug("After null-assignment to " + (int) (RANGE * RATIO) +
+ //" elements from " + lower + " to " + (upper - 1) +
+ " and provoking gc found:\n\t" +
+ enqued[WEAK] + " weak\n\t" +
+ enqued[SOFT] + " soft\n\t" +
+ enqued[PHANTOM] + " phantom " +
+ " queuened refs and \n\t" +
+ alive[WEAK] + " weak\n\t" +
+ alive[SOFT] + " soft\n\t" +
+ "alive refs.");
+ try {
+ log.debug("sleeping to give gc one more chance ......");
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ }
+ }
+ }
+ log.debug("iteration.... " + iter++);
+ if (totalQ < (int) (3 * RANGE * RATIO * 0.9) || totalQ > (int) (3 * RANGE * RATIO)) {
+ throw new TestFailure("Test failed");
+ }
+ }
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ReferencesGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/RememberedSet/RememberedSet.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/RememberedSet/RememberedSet.java
new file mode 100644
index 0000000..d4ab932
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/RememberedSet/RememberedSet.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2010, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+/*
+ * This test stress RememberetSet procerssing in the G1 by creation of references
+ * between different 1MB blocks.
+ * Test is specific for G1, for other GCs it should just pass.
+ */
+
+
+/*
+ * @test
+ * @modules java.base/jdk.internal.misc:+open java.base/jdk.internal.vm.annotation:+open java.base/sun.reflect.annotation:+open
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/RememberedSet.
+ * VM Testbase keywords: [gc, stress, stressopt, feature_g1, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.RememberedSet.RememberedSet
+ */
+
+package gc.gctests.RememberedSet;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import nsk.share.gc.GC;
+import nsk.share.gc.MemoryObject;
+import nsk.share.gc.ThreadedGCTest;
+import nsk.share.test.ExecutionController;
+import jdk.internal.misc.Unsafe;
+
+public class RememberedSet extends ThreadedGCTest {
+
+ static class PointerUtils {
+ private static Unsafe unsafe;
+ private static long fieldOffset;
+ private static PointerUtils instance = new PointerUtils();
+ private static boolean compressedRef = false;
+
+ static {
+ try {
+ unsafe = Unsafe.getUnsafe();
+ fieldOffset = unsafe.objectFieldOffset(PointerUtils.class.getDeclaredField("obj"));
+ long fieldOffset0 = unsafe.objectFieldOffset(PointerUtils.class.getDeclaredField("obj0"));
+ int oopSize = (int)Math.abs(fieldOffset - fieldOffset0);
+
+ if (oopSize != unsafe.addressSize()) {
+ System.out.println("Compressed oops detected");
+ compressedRef = true;
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private Object obj;
+ private Object obj0;
+
+ public synchronized static long toAddress(Object o) {
+ long address;
+ instance.obj = o;
+
+ if (compressedRef || unsafe.addressSize() == 4) {
+ address = unsafe.getInt(instance, fieldOffset);
+ }
+ else {
+ address = unsafe.getLong(instance, fieldOffset);
+ }
+
+ return address;
+ }
+
+ }
+ private ExecutionController stresser;
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ class Worker implements Runnable {
+
+ static final long BLOCK_SIZE = 1024 * 1024;
+
+
+ // this method tries to allocate a new MemoryObject
+ // which is in another 1MB block
+ MemoryObject getOutOfTheBlockObject(int size, Object obj) {
+ long address = PointerUtils.toAddress(obj);
+ MemoryObject ref = new MemoryObject(size);
+ int attempt = (int) (BLOCK_SIZE / size);
+ while (attempt != 0 && Math.abs(address - PointerUtils.toAddress(ref)) < BLOCK_SIZE) {
+ ref = new MemoryObject(size);
+ attempt--;
+ }
+ return ref;
+ }
+
+ @Override
+ public void run() {
+
+ int size = (int) Math.sqrt(BLOCK_SIZE);
+ int refsCount = (int) (runParams.getTestMemory() / BLOCK_SIZE);
+ int count = (int) (runParams.getTestMemory() / runParams.getNumberOfThreads() / (refsCount * size));
+ // Each cycle 10% of references and 10% of arrays are reallocated
+ int step = 10;
+
+ List<List<MemoryObject>> objs = new ArrayList<List<MemoryObject>>(count);
+ for (int i = 0; i < count; i++) {
+ List<MemoryObject> obj = new ArrayList<MemoryObject>();
+ objs.add(obj);
+ for (int j = 0; j < refsCount; j++) {
+ obj.add(getOutOfTheBlockObject(size, obj));
+ }
+ }
+ if (stresser == null) {
+ stresser = getExecutionController();
+ }
+ int shift = 0;
+ while (stresser.continueExecution()) {
+ for (int j = shift; j < refsCount; j += step) {
+ for (int i = 0; i < count; i ++) {
+ // update each 10th reference to allow GC previous one
+ List<MemoryObject> obj = objs.get(i);
+ obj.set(j, getOutOfTheBlockObject(size, obj));
+ }
+ }
+ for (int i = step - shift; i < count; i += step) {
+ // update each 10th array of references
+ // to allocate it in the another 1MB block (as new young object)
+ List<MemoryObject> obj = new ArrayList<MemoryObject>();
+ objs.set(i, obj);
+ for (int j = 0; j < refsCount; j++) {
+ obj.add(getOutOfTheBlockObject(size, obj));
+ }
+ }
+ // shift is changed from 0 to step - 1
+ log.debug("shift = " + shift);
+ shift = (shift + 1) % step;
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new RememberedSet(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/RememberedSet/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/RememberedSet/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/RememberedSet/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/SoftReferenceTest/SoftReferenceTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/SoftReferenceTest/SoftReferenceTest.java
new file mode 100644
index 0000000..7eae2bf
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/SoftReferenceTest/SoftReferenceTest.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/SoftReference/SoftReferenceTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Test that all SoftReferences has been cleared at time of OOM.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.SoftReference.SoftReferenceTest.SoftReferenceTest -stressTime 600
+ */
+
+package gc.gctests.SoftReference.SoftReferenceTest;
+
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.Random;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+import nsk.share.test.ExecutionController;
+import nsk.share.test.Stresser;
+
+/**
+ * Tests for the SoftReference handling in JRockit.
+ */
+public final class SoftReferenceTest extends GCTestBase {
+
+ private ExecutionController stresser;
+
+ /**
+ * Test that all SoftReferences has been cleared at
+ * time of OOM.
+ *
+ * @return success if all SoftReferences are NULL at
+ * time of OOM.
+ */
+ public void run() {
+ //prepare stresser
+ stresser = new Stresser("Stresser to limit execution time", runParams.getStressOptions());
+ stresser.start(1);
+
+ long seed;
+ int minSize;
+ int maxSize;
+ int keepEveryXthObject;
+ long counter = 0;
+
+ seed = runParams.getSeed();
+ minSize = 2048;
+ maxSize = 32768;
+ keepEveryXthObject = 4;
+
+
+ Random rndGenerator = new Random(seed);
+ long multiplier = maxSize - minSize;
+ ArrayList arrSoftRefs = new ArrayList();
+ ArrayList arrObjects = new ArrayList();
+ long numberOfNotNulledObjects = 0;
+ long oomSoftArraySize = 0;
+
+ try {
+ while (true && stresser.continueExecution()) {
+ int allocationSize = ((int) (rndGenerator.nextDouble()
+ * multiplier)) + minSize;
+ byte[] tmp = new byte[allocationSize];
+
+ // Keep every Xth object to make sure we hit OOM pretty fast
+ if (counter % keepEveryXthObject == 0) {
+ arrObjects.add(tmp);
+ } else {
+ arrSoftRefs.add(new SoftReference(tmp));
+ }
+
+ // Make sure the temporary object is dereferenced
+ tmp = null;
+
+ counter++;
+ if (counter == Long.MAX_VALUE) {
+ counter = 0;
+ }
+ }
+ } catch (OutOfMemoryError oome) {
+ // Get the number of soft refs first, so we don't trigger
+ // another OOM.
+ oomSoftArraySize = arrSoftRefs.size();
+
+ for (int i = 0; i < arrSoftRefs.size(); i++) {
+ SoftReference sr = (SoftReference) arrSoftRefs.get(i);
+ Object o = sr.get();
+
+ if (o != null) {
+ numberOfNotNulledObjects++;
+ }
+ }
+
+ // Make sure we clear all refs before we return failure, since
+ // coconut require some memory to complete, and since we're in
+ // an OOM situation, that could cause trouble.
+
+ arrSoftRefs = null;
+ arrObjects = null;
+
+ if (numberOfNotNulledObjects > 0) {
+ throw new TestFailure(numberOfNotNulledObjects + " out of "
+ + oomSoftArraySize + " SoftReferences was not "
+ + "null at time of OutOfMemoryError");
+ }
+ } finally {
+ arrSoftRefs = null;
+ arrObjects = null;
+ }
+
+
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new SoftReferenceTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/SoftReferenceTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/SoftReferenceTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/SoftReferenceTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft001/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft001/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft001/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft001/soft001.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft001/soft001.java
new file mode 100644
index 0000000..6ae9ecb
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft001/soft001.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/SoftReference/soft001.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly works with
+ * SoftReferences. It also checks that no unexpected exceptions and errors
+ * are thrown or the JVM is not crashed.
+ * The test starts a number of threads. Each thread run tests for some time
+ * or serveral iterations. See javadoc StressOptions for configuration.
+ * First of all each thread defines what type to check (there are 10 types
+ * totally). As soon as the type is defined, a SoftRefence is created that
+ * refers to an array of tested type and is registered with in a queue. A
+ * SoftRefence for NonbranchyTree class does not refer to an array, but to
+ * instances of the class.
+ * After that a thread performs next checks for the reference:
+ * 1. The reference is in queue after GC is provoked with
+ * Algorithms.eatMemory() method (a single thread eats the memory).
+ * 2. queue.remove() returns reference from the queue.
+ * 3. queue.poll() returns null.
+ * 4. reference.clear() does not throw any exception.
+ * The test extends ThreadedGCTest and implements GarbageProducerAware and
+ * MemoryStrategyAware interfaces. The corresponding javadoc documentation
+ * for additional test configuration.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.SoftReference.soft001.soft001 -ms low
+ */
+
+package gc.gctests.SoftReference.soft001;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+
+import nsk.share.gc.GC;
+import nsk.share.gc.NonbranchyTree;
+import nsk.share.gc.ThreadedGCTest;
+import nsk.share.gc.gp.GarbageProducer;
+import nsk.share.gc.gp.GarbageProducerAware;
+import nsk.share.gc.gp.GarbageUtils;
+import nsk.share.gc.gp.MemoryStrategy;
+import nsk.share.gc.gp.MemoryStrategyAware;
+import nsk.share.gc.gp.string.InternedStringProducer;
+import nsk.share.gc.gp.string.RandomStringProducer;
+
+public class soft001 extends ThreadedGCTest implements GarbageProducerAware, MemoryStrategyAware {
+
+ private GarbageProducer garbageProducer;
+ private InternedStringProducer internedStringProducer = new InternedStringProducer(new RandomStringProducer(10));
+ private MemoryStrategy memoryStrategy;
+ // Total number of types to test
+ final static int TYPES_COUNT = 11;
+ // Size of array of each tested type. The constant also specifies the
+ // number of nodes in a NonbranchyTree and size of each node
+ final static int SIZE = 100;
+
+ protected Runnable createRunnable(int i) {
+ return new Test();
+ }
+
+ public void setGarbageProducer(GarbageProducer garbageProducer) {
+ this.garbageProducer = garbageProducer;
+ }
+
+ public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
+ this.memoryStrategy = memoryStrategy;
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new soft001(), args);
+ }
+
+ // The class implements the logic of the testcase
+ class Test implements Runnable {
+
+ int iteration;
+
+ public void run() {
+ // Pre-allocated OOME message to avoid OOME when logging it
+ String oomMsg = "Ignored OOME in run()";
+ try {
+
+ log.info("iteration " + iteration);
+ ReferenceQueue queue = new ReferenceQueue();
+ SoftReference reference;
+ int code = iteration % TYPES_COUNT;
+ String type;
+ // Define a specific type for each thread to test
+ switch (code) {
+ case 0:
+ reference = new SoftReference(new byte[SIZE], queue);
+ type = "byte";
+ break;
+ case 1:
+ reference = new SoftReference(new short[SIZE], queue);
+ type = "short";
+ break;
+ case 2:
+ reference = new SoftReference(new int[SIZE], queue);
+ type = "int";
+ break;
+ case 3:
+ reference = new SoftReference(new long[SIZE], queue);
+ type = "long";
+ break;
+ case 4:
+ reference = new SoftReference(new char[SIZE], queue);
+ type = "char";
+ break;
+ case 5:
+ reference = new SoftReference(new boolean[SIZE], queue);
+ type = "boolean";
+ break;
+ case 6:
+ reference = new SoftReference(new double[SIZE], queue);
+ type = "double";
+ break;
+ case 7:
+ reference = new SoftReference(new float[SIZE], queue);
+ type = "float";
+ break;
+ case 8:
+ reference = new SoftReference(new Object[SIZE], queue);
+ type = "Object";
+ break;
+ case 9:
+ reference = new SoftReference(internedStringProducer.create(SIZE), queue);
+ type = "InternedString";
+ break;
+ default:
+ reference = new SoftReference(new NonbranchyTree(SIZE, 0.3f, SIZE),
+ queue);
+ type = "NonbranchyTree";
+ break;
+ }
+ int initialFactor = memoryStrategy.equals(MemoryStrategy.HIGH) ? 1 : (memoryStrategy.equals(MemoryStrategy.LOW) ? 10 : 2);
+ GarbageUtils.eatMemory(getExecutionController(), garbageProducer, initialFactor , 10, 0);
+ if (!getExecutionController().continueExecution()) {
+ // we were interrrupted by stresser. just exit...
+ return;
+ }
+ Reference polledReference = null;
+ try {
+ polledReference = queue.remove();
+ } catch (InterruptedException e) {
+ log.error("Unexpected InterruptedException during queue.remove().");
+ setFailed(true);
+ }
+ // Check the reference and the queue
+ // The polled reference must be equal to the one enqueued to
+ // the queue
+
+ if (polledReference != reference) {
+ log.error("The original reference is not equal to polled reference.");
+ setFailed(true);
+ }
+
+ // queue.poll() once again must return null now, since there is
+ // only one reference in the queue
+ polledReference = queue.poll();
+ if (polledReference != null) {
+ log.error("There are more than one references in the queue.");
+ setFailed(true);
+ }
+ reference.clear();
+ } catch (OutOfMemoryError e) {
+ log.info(oomMsg);
+ }
+ iteration++;
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft002/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft002/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft002/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft002/TestDescription.java
new file mode 100644
index 0000000..236c407
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft002/TestDescription.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/SoftReference/soft002.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly works with
+ * SoftReferences. It also checks that no unexpected exceptions and errors
+ * are thrown or the JVM is not crashed.
+ * The test starts a number of threads. Each thread run tests for some time
+ * or serveral iterations. See javadoc StressOptions for configuration.
+ * First of all each thread defines what type to check (there are 10 types
+ * totally). As soon as the type is defined, a SoftRefence is created that
+ * refers to an array of tested type and is registered with in a queue. A
+ * SoftRefence for NonbranchyTree class does not refer to an array, but to
+ * instances of the class.
+ * After that a thread performs next checks for the reference:
+ * 1. The reference is in queue after GC is provoked with
+ * Algorithms.eatMemory() method (a single thread eats the memory).
+ * 2. queue.remove() returns reference from the queue.
+ * 3. queue.poll() returns null.
+ * 4. reference.clear() does not throw any exception.
+ * The test extends ThreadedGCTest and implements GarbageProducerAware and
+ * MemoryStrategyAware interfaces. The corresponding javadoc documentation
+ * for additional test configuration.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.SoftReference.soft001.soft001 -ms high
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft003/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft003/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft003/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft003/soft003.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft003/soft003.java
new file mode 100644
index 0000000..36d7c2b
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft003/soft003.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/SoftReference/soft003.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.SoftReference.soft003.soft003 -t 1
+ */
+
+package gc.gctests.SoftReference.soft003;
+
+import java.lang.ref.Reference;
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.TestFailure;
+import java.lang.ref.SoftReference;
+
+/**
+ * Test that GC clears soft references before throwing OOM.
+ *
+ * This test creates a number of soft references, then provokes
+ * GC with Algorithms.eatMemory() and checks that all references
+ * have been cleared.
+ */
+public class soft003 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int arrayLength;
+ private int objectSize = 100;
+ private Reference[] references;
+
+ public void run() {
+ for (int i = 0; i < arrayLength; ++i) {
+ references[i] = new SoftReference<MemoryObject>(new MemoryObject(LocalRandom.nextInt(objectSize)));
+ }
+ Algorithms.eatMemory(getExecutionController());
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ // Check that all references have been cleared
+ int n = 0;
+ for (int i = 0; i < arrayLength; ++i) {
+ if (references[i].get() != null) {
+ ++n;
+ }
+ }
+ if (n != 0) {
+ references = null;
+ throw new TestFailure("Some of the references have been not cleared: " + n);
+ }
+ }
+
+ public void Worker() {
+ arrayLength = Memory.getArrayLength(runParams.getTestMemory(), Memory.getReferenceSize() + objectSize);
+ System.out.println("Array size: " + arrayLength);
+ references = new Reference[arrayLength];
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new soft003(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft004/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft004/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft004/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft004/soft004.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft004/soft004.java
new file mode 100644
index 0000000..a1e6a58
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft004/soft004.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/SoftReference/soft004.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.SoftReference.soft004.soft004 -t 1
+ */
+
+package gc.gctests.SoftReference.soft004;
+
+import nsk.share.gc.*;
+import java.lang.ref.SoftReference;
+
+/**
+ * Test that GC correctly clears soft references.
+ *
+ * This test is the same as soft003 except that it creates
+ * a number of soft references to same object.
+ *
+ * @see gc.gctests.SoftReference.soft003
+ */
+public class soft004 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int arrayLength;
+ private int objectSize = 100;
+ private SoftReference[] references;
+
+ private void makeReferences() {
+ MemoryObject obj = new MemoryObject(objectSize);
+ references = new SoftReference[arrayLength];
+ for (int i = 0; i < arrayLength; ++i) {
+ references[i] = new SoftReference<MemoryObject>(obj);
+ }
+ }
+
+ public void run() {
+ arrayLength = Memory.getArrayLength(runParams.getTestMemory() - objectSize, Memory.getReferenceSize() + objectSize);
+ System.out.println("Array size: " + arrayLength);
+ makeReferences();
+ Algorithms.eatMemory(getExecutionController());
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ int n = 0;
+ for (int i = 0; i < arrayLength; ++i) {
+ if (references[i].get() != null) {
+ ++n;
+ }
+ }
+ if (n != 0) {
+ log.error("Some of the references have been not cleared: " + n);
+ setFailed(true);
+ }
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new soft004(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft005/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft005/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft005/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft005/soft005.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft005/soft005.java
new file mode 100644
index 0000000..025a77c
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/SoftReference/soft005/soft005.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/SoftReference/soft005.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.SoftReference.soft005.soft005 -t 1
+ */
+
+package gc.gctests.SoftReference.soft005;
+
+import nsk.share.gc.*;
+import java.lang.ref.SoftReference;
+
+/**
+ * Test that GC correctly clears soft references.
+ *
+ * This test creates a number of soft references,
+ * each of which points to the next,
+ * then provokes GC with Algorithms.eatMemory(). Then
+ * checks that first reference has been cleared.
+ */
+public class soft005 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int length = 10000;
+ private int objectSize = 10000;
+ private SoftReference[] references;
+
+ public Worker() {
+ System.out.println("Array size: " + length);
+ System.out.println("Object size: " + objectSize);
+ references = new SoftReference[length];
+ }
+
+ private void makeReferences() {
+ references[length - 1] = null;
+ MemoryObject obj = new MemoryObject(objectSize);
+ references[0] = new SoftReference(obj);
+ for (int i = 1; i < length; ++i) {
+ references[i] = new SoftReference(references[i - 1]);
+ }
+ for (int i = 0; i < length - 1; ++i) {
+ references[i] = null;
+ }
+ }
+
+ public void run() {
+ makeReferences();
+ Algorithms.eatMemory(getExecutionController());
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ if (references[length - 1].get() != null) {
+ log.error("Last soft reference has not been cleared");
+ setFailed(true);
+ }
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new soft005(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal001/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal001/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal001/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal001/steal001.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal001/steal001.java
new file mode 100644
index 0000000..2634825
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal001/steal001.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2003, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/Steal/steal001.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly uses stealing technique:
+ * no unexpected exceptions and errors are thrown; the JVM is not crashed.
+ * Actually, the test is intended for Parallel Collector.
+ * The test starts just one thread and fills the memory with NonbranyTrees
+ * (the number of nodes of the tree and its size are based on
+ * Runtime.maxMemory() value) until OutOfMemoryError is thrown. All references
+ * to the trees are saved in a java.util.Vector. Then the test removes a
+ * number of trees from the vector, this number is equal to number of
+ * processors (returned by nsk.share.gc.Algorithms.availableProcessors()).
+ * Algorithms.eatMemory(int) is invoked after that to provoke GC to clean the
+ * memory. Then procedure is repeated.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.Steal.steal001.steal001
+ */
+
+package gc.gctests.Steal.steal001;
+
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
+import nsk.share.gc.*;
+import nsk.share.gc.gp.GarbageUtils;
+import nsk.share.test.ExecutionController;
+
+public class steal001 extends ThreadedGCTest {
+ // Preload ThreadLocalRandom class to avoid class initialization failure
+ // due to OOM error in static class initializer
+ final static public ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
+
+ // Internal number of iterations to remove and create new elements
+ // for the vector
+ final static int INTERNAL_ITERATIONS = 10;
+ // Approximate number of trees to fill the heap with
+ final static int TREES = 50;
+ // Number of nodes for each tree
+ final static int NODES = 500;
+
+ private class Eater implements Runnable {
+
+ private int nodeSize;
+ private List<NonbranchyTree> list;
+ int processors = Runtime.getRuntime().availableProcessors();
+ ExecutionController stresser;
+
+ public Eater(int nodeSize) {
+ list = new ArrayList<>();
+ this.nodeSize = nodeSize;
+ }
+
+ @Override
+ public void run() {
+ if (stresser == null) {
+ stresser = getExecutionController();
+ }
+ int counter = NODES;
+ while (stresser.continueExecution()) {
+ fillHeap(counter);
+ removeElements();
+ counter = (counter == 1) ? 1 : counter - 1;
+ }
+ }
+
+ // Fill the memory with trees of defined size until OutOfMemoryError
+ private void fillHeap(int n) {
+ try {
+ while (stresser.continueExecution()) {
+ // Passing in the ExecutionController to make sure we
+ // stop allocating nodes when time is up.
+ list.add(new NonbranchyTree(n, 0.3f, nodeSize, stresser));
+ }
+ } catch (OutOfMemoryError e) {
+ }
+ }
+
+ // Remove a number of elements (equal to number of processors) from the
+ // vector and provoke GC to clean the heap
+ private void removeElements() {
+ if (list.size() <= 0) {
+ return;
+ }
+ list.remove(0);
+ GarbageUtils.eatMemory(stresser);
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ // Perform calculations specific to the test
+ double treeSize = Runtime.getRuntime().maxMemory() / TREES;
+ int nodeSize = (int) (treeSize / NODES - NonbranchyTree.MIN_NODE_SIZE);
+ nodeSize = Math.max(1, nodeSize);
+ return new Eater(nodeSize);
+ }
+
+ public static void main(String args[]) {
+ // just to preload GarbageUtils and avoid exception
+ // in removeElements()
+ GarbageUtils.getGarbageProducers();
+ GC.runTest(new steal001(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal002/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal002/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal002/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal002/steal002.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal002/steal002.java
new file mode 100644
index 0000000..3cc2a62
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/Steal/steal002/steal002.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2003, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/Steal/steal002.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly uses stealing technique:
+ * no unexpected exceptions and errors are thrown; the JVM is not crashed.
+ * Actually, the test is intended for Parallel Collector.
+ * The test starts just one thread, then creates a small NonbranyTree and a
+ * huge one. Both trees are to fill about 80% of the memory. Then the test
+ * drops references to both trees and invoke Algorithms.eatMemory(int) to
+ * provoke GC to clean the memory. the GC should correctly remove both
+ * objects. If the GC is Parallel, there are more than one GC threads, so one
+ * will try to "steal" some job from others.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.Steal.steal002.steal002
+ */
+
+package gc.gctests.Steal.steal002;
+
+import nsk.share.gc.*;
+import nsk.share.test.ExecutionController;
+import nsk.share.test.Stresser;
+
+public class steal002 extends GCTestBase {
+
+ ExecutionController stresser;
+ // Number of nodes for the small tree
+ final static int SMALL_NODES = 10;
+ // Size (in bytes) for a node of the small tree
+ final static int SMALL_NODE_SIZE = 1;
+ // Number of nodes for the huge tree
+ final static int HUGE_NODES = 500;
+ // Part of the heap to fill with both trees
+ final static double PART_OF_HEAP = 0.8;
+ final int hugeNodeSize;
+ public static NonbranchyTree smallTree;
+ public static NonbranchyTree hugeTree;
+
+ @Override
+ public void run() {
+ if (stresser == null) {
+ stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(runParams.getIterations());
+ }
+ while (stresser.continueExecution()) {
+ // Create a small tree and a huge one. Then drop references
+ // to both of them.
+ smallTree = new NonbranchyTree(SMALL_NODES, 0.3f, SMALL_NODE_SIZE);
+ hugeTree = new NonbranchyTree(HUGE_NODES, 0.3f, hugeNodeSize);
+
+ // Drop references to both trees and provoke GC to clean
+ // the memory
+ hugeTree = null;
+ smallTree = null;
+
+ // Provoke GC to clean the memory
+ Algorithms.eatMemory(stresser);
+ }
+ }
+
+ public steal002() {
+ hugeNodeSize = Math.max(1, (int) (PART_OF_HEAP * Runtime.getRuntime().maxMemory() / HUGE_NODES
+ - NonbranchyTree.MIN_NODE_SIZE));
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new steal002(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringGC/StringGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringGC/StringGC.java
new file mode 100644
index 0000000..c7a3ffa
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringGC/StringGC.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quick]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.StringGC.StringGC
+ */
+
+package gc.gctests.StringGC;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+
+/**
+ * Test that added strings are collected.
+ *
+ * Idea based on old tests:
+ * gc/gctests/StringGC02
+ * gc/gctests/TestStringGC
+ */
+public class StringGC extends ThreadedGCTest {
+ private final String toAdd = "abcdef";
+ private int maxLength;
+
+ private class StringAdder implements Runnable {
+ private String s;
+
+ public void run() {
+ s = s + toAdd;
+ if (s.length() > maxLength)
+ s = "";
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ return new StringAdder();
+ }
+
+ public void run() {
+ maxLength = (int) Math.min(
+ runParams.getTestMemory() / runParams.getNumberOfThreads() / toAdd.length(),
+ Integer.MAX_VALUE);
+ super.run();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new StringGC(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringIntern/StringIntern.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringIntern/StringIntern.java
new file mode 100644
index 0000000..e3b60ec
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringIntern/StringIntern.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringIntern.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.StringIntern.StringIntern
+ */
+
+package gc.gctests.StringIntern;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+
+/**
+ * Test that strings returned by String.intern() can be collected.
+ *
+ * Create strings consisting of random characters, call String.intern().
+ * Check that intern() contract.
+ */
+public class StringIntern extends ThreadedGCTest {
+ private int maxLength = 1000;
+ private int checkCount = 100;
+
+ private class StringGenerator implements Runnable {
+ private StringBuffer sb = new StringBuffer();
+
+ private void generateRandomBuffer() {
+ int length = LocalRandom.nextInt(maxLength);
+ for (int i = 0; i < length; ++i)
+ sb.append((char) LocalRandom.nextInt(Integer.MAX_VALUE));
+ }
+
+ private String getString() {
+ return sb.toString();
+ }
+
+ public void run() {
+ generateRandomBuffer();
+ for (int i = 0; i < checkCount; ++i) {
+ String s1 = getString();
+ String s2 = getString();
+ if (s1.intern() != s2.intern()) {
+ log.error("Test failed on: " + s1);
+ setFailed(true);
+ }
+ }
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ return new StringGenerator();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new StringIntern(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringIntern/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringIntern/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringIntern/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternGC/StringInternGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternGC/StringInternGC.java
new file mode 100644
index 0000000..10b0373
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternGC/StringInternGC.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringInternGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quick]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.StringInternGC.StringInternGC
+ */
+
+package gc.gctests.StringInternGC;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+
+/**
+ * Test that strings returned by String.intern() can be collected.
+ *
+ * Create strings consisting of random characters, call String.intern().
+ * String pool should not overflow.
+ */
+public class StringInternGC extends ThreadedGCTest {
+ private int maxLength = 1000;
+
+ private class StringGenerator implements Runnable {
+ private StringBuffer sb = new StringBuffer();
+
+ private String generateString() {
+ int length = LocalRandom.nextInt(maxLength);
+ for (int i = 0; i < length; ++i)
+ sb.append((char) LocalRandom.nextInt(Integer.MAX_VALUE));
+ return sb.toString();
+ }
+
+
+ public void run() {
+ generateString().intern();
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ return new StringGenerator();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new StringInternGC(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync/StringInternSync.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync/StringInternSync.java
new file mode 100644
index 0000000..7fb5f31
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync/StringInternSync.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringInternSync.
+ * VM Testbase keywords: [gc, stress, stressopt, feature_perm_removal_jdk7, nonconcurrent]
+ * VM Testbase readme:
+ * The test verifies that String.intern is correctly synchronized.
+ * Test interns same strings in different threads and verifies that all interned equal
+ * strings are same objects.
+ * This test interns a few large strings.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -XX:+UnlockDiagnosticVMOptions
+ * -XX:+VerifyStringTableAtExit
+ * gc.gctests.StringInternSync.StringInternSync
+ * -ms low
+ */
+
+package gc.gctests.StringInternSync;
+
+import java.util.*;
+import java.util.ArrayList;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import nsk.share.TestBug;
+import nsk.share.TestFailure;
+import nsk.share.gc.*;
+import nsk.share.gc.gp.MemoryStrategy;
+import nsk.share.gc.gp.MemoryStrategyAware;
+import nsk.share.gc.gp.string.RandomStringProducer;
+
+public class StringInternSync extends ThreadedGCTest implements MemoryStrategyAware {
+
+ // The list of strings which will be interned
+ static final List<String> stringsToIntern = new ArrayList();
+ // The global container for references to internded strings
+ static final List<List<String>> internedStrings = new ArrayList<List<String>>();
+ // Approximate size occupied by all interned strings
+ long sizeOfAllInteredStrings = 0;
+ // maximum size of one string
+ int maxStringSize;
+ RandomStringProducer gp = new RandomStringProducer();
+ MemoryStrategy memoryStrategy;
+ ReadWriteLock rwlock = new ReentrantReadWriteLock();
+
+ @Override
+ public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
+ this.memoryStrategy = memoryStrategy;
+ }
+
+ private class StringGenerator implements Runnable {
+
+ List<String> internedLocal;
+
+ public StringGenerator(List<String> internedLocal) {
+ this.internedLocal = internedLocal;
+ }
+
+ public void run() {
+ try {
+ rwlock.readLock().lock();
+ internedLocal.clear();
+ for (String str : stringsToIntern) {
+ // Intern copy of string
+ // and save reference to it
+ internedLocal.add(new String(str).intern());
+ }
+ } finally {
+ rwlock.readLock().unlock();
+ }
+
+ // after each iteration 0 thread
+ // lock our main resource and verify String.intern
+ if (internedLocal == internedStrings.get(0)) {
+ try {
+ rwlock.writeLock().lock();
+ // We select first list and compare all other with it
+ // if 2 strings are equal they should be the same "=="
+ List<String> interned = internedStrings.get(0);
+
+ for (List<String> list : internedStrings) {
+ if (list == interned) {
+ continue;
+ }
+ if (list.size() == 0) {
+ continue; // this thread haven't got lock
+ }
+
+ if (list.size() != interned.size()) {
+ throw new TestFailure("Size of interned string list differ from origial."
+ + " interned " + list.size() + " original " + interned.size());
+ }
+ for (int i = 0; i < interned.size(); i++) {
+ String str = interned.get(i);
+ if (!str.equals(list.get(i))) {
+ throw new TestFailure("The interned strings are not the equals.");
+ }
+ if (str != list.get(i)) {
+ throw new TestFailure("The equal interned strings are not the same.");
+ }
+ }
+ list.clear();
+
+ }
+ interned.clear();
+ stringsToIntern.clear();
+ for (long currentSize = 0; currentSize <= sizeOfAllInteredStrings; currentSize++) {
+ stringsToIntern.add(gp.create(maxStringSize));
+ currentSize += maxStringSize;
+ }
+ } finally {
+ rwlock.writeLock().unlock();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void run() {
+ sizeOfAllInteredStrings = 10 * 1024 * 1024; // let use 100 * strings of size 10000
+ maxStringSize = (int) (sizeOfAllInteredStrings / memoryStrategy.getSize(sizeOfAllInteredStrings));
+ log.debug("The overall size of interned strings : " + sizeOfAllInteredStrings / (1024 * 1024) + "M");
+ log.debug("The count of interned strings : " + sizeOfAllInteredStrings / maxStringSize);
+ for (long currentSize = 0; currentSize <= sizeOfAllInteredStrings; currentSize++) {
+ stringsToIntern.add(gp.create(maxStringSize));
+ currentSize += maxStringSize;
+ }
+ super.run();
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ ArrayList list = new ArrayList();
+ internedStrings.add(list);
+ return new StringGenerator(list);
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new StringInternSync(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync2/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync2/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync2/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync2/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync2/TestDescription.java
new file mode 100644
index 0000000..b30408a
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSync2/TestDescription.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringInternSync2.
+ * VM Testbase keywords: [gc, stress, stressopt, feature_perm_removal_jdk7, nonconcurrent]
+ * VM Testbase readme:
+ * The test verifies that String.intern is correctly synchronized.
+ * Test interns same strings in different threads and verifies that all interned equal
+ * strings are same objects.
+ * This test interns a lot of small strings.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.StringInternSync.StringInternSync -ms high
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/StringGenerator.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/StringGenerator.java
new file mode 100644
index 0000000..c8cd621
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/StringGenerator.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package gc.gctests.StringInternSyncWithGC;
+
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+import java.util.List;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import nsk.share.TestBug;
+import nsk.share.TestFailure;
+import nsk.share.gc.gp.string.RandomStringProducer;
+import nsk.share.test.ExecutionController;
+import nsk.share.test.LocalRandom;
+
+class StringGenerator implements Runnable {
+
+ private final RandomStringProducer gp;
+ private final List<String> stringsToIntern;
+ private final int threadNumber;
+ private final int numberOfActions;
+ private final int maxStringSize;
+ private final StringInternSyncWithGC base;
+ private static final ReadWriteLock RWLOCK = new ReentrantReadWriteLock();
+
+ public StringGenerator(int threadId, StringInternSyncWithGC base) {
+ this.base = base;
+ threadNumber = threadId;
+ stringsToIntern = base.getStringsToIntern();
+ numberOfActions = base.getNumberOfThreads() > 4 ? base.getNumberOfThreads() : 4;
+ gp = base.getGarbageProducer();
+ maxStringSize = base.getMaxStringSize();
+ }
+
+ /* This field is public just to be not optimized */
+ public String copy;
+
+ @Override
+ public void run() {
+ ExecutionController stresser = base.getExecController();
+ try {
+ RWLOCK.readLock().lock();
+ Object[] refToInterned = new Object[stringsToIntern.size()];
+ for (int i = 0; i < stringsToIntern.size(); i++) {
+ if (!stresser.continueExecution()) {
+ return;
+ }
+ int index = LocalRandom.nextInt(stringsToIntern.size());
+ String str = stringsToIntern.get(index);
+ int action = LocalRandom.nextInt(numberOfActions);
+
+ /* We want to provoke a lot of collections for each interned copy
+ * so map should be "sparse".
+ */
+ copy = new String(str);
+ switch (action) {
+ case 0:
+ refToInterned[index] = copy.intern();
+ break;
+ case 1:
+ refToInterned[index] = new WeakReference(copy.intern());
+ break;
+ case 2:
+ refToInterned[index] = new SoftReference(copy.intern());
+ break;
+ default:
+ refToInterned[index] = null;
+ break;
+ }
+ }
+ for (int index = 0; index < stringsToIntern.size(); index++) {
+ verify(refToInterned[index], stringsToIntern.get(index));
+ }
+ } finally {
+ RWLOCK.readLock().unlock();
+ }
+
+ if (threadNumber == 0) {
+ try {
+ RWLOCK.writeLock().lock();
+ for (int index = 0; index < stringsToIntern.size(); index++) {
+ stringsToIntern.set(index, gp.create(maxStringSize).intern());
+ }
+ } finally {
+ RWLOCK.writeLock().unlock();
+ }
+ }
+ }
+
+ /*
+ * Verify that all exist interned strings in a map
+ * a same objects.
+ */
+ private void verify(Object obj, String str) {
+ if (obj == null) {
+ return;
+ }
+ if (obj instanceof Reference) {
+ obj = ((Reference) obj).get();
+ if (obj == null) {
+ return;
+ }
+ }
+ if (!(obj instanceof String)) {
+ throw new TestBug("Expected String. Find :" + obj.getClass());
+ }
+ String interned = (String) obj;
+ if (!interned.equals(str)) {
+ throw new TestFailure("Interned not equals to original string.");
+ }
+ if (obj != str.intern()) {
+ throw new TestFailure("Interned not same as original string.");
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/StringInternSyncWithGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/StringInternSyncWithGC.java
new file mode 100644
index 0000000..da07865
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/StringInternSyncWithGC.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2011, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringInternSyncWithGC.
+ * VM Testbase keywords: [gc, stress, stressopt, feature_perm_removal_jdk7, nonconcurrent]
+ * VM Testbase readme:
+ * The test verifies that String.intern is correctly synchronized with GC.
+ * Test interns and drop the same strings in different threads and provokes GC.
+ * Additionally test creates weak/soft references to interned strings.
+ * Test fails if any string object is inaccessible.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -Xlog:gc:gc.log
+ * gc.gctests.StringInternSyncWithGC.StringInternSyncWithGC
+ * -ms low
+ * -memUsage 3
+ * -appTimeout 30
+ * -capacityVerPart 2
+ */
+
+package gc.gctests.StringInternSyncWithGC;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import nsk.share.gc.*;
+import nsk.share.gc.gp.MemoryStrategy;
+import nsk.share.gc.gp.MemoryStrategyAware;
+import nsk.share.gc.gp.string.RandomStringProducer;
+import nsk.share.test.ExecutionController;
+
+public class StringInternSyncWithGC extends ThreadedGCTest implements MemoryStrategyAware {
+
+ // Maximum size of one string
+ // Depends from all size and memory strategy
+ private int maxStringSize;
+ private MemoryStrategy memoryStrategy;
+ private final int memUsageFactor;
+ private final long endTimeCapacityVer;
+
+ // The list of strings which are interned during iteration
+ private final List<String> stringsToIntern = new ArrayList();
+ private final RandomStringProducer gp = new RandomStringProducer();
+
+ public StringInternSyncWithGC(int memUsage, long endTimeCapVer) {
+ memUsageFactor = memUsage;
+ endTimeCapacityVer = endTimeCapVer;
+ }
+
+ @Override
+ public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
+ this.memoryStrategy = memoryStrategy;
+ }
+
+ /**
+ * Verify that we could use certain amount of memory.
+ */
+ private boolean verifyInternedStringCapacity(long initialSize) {
+ long currentSize = 0;
+ final int STEP = 1000;
+ int iter = 0;
+ char[] template = new char[(int) (initialSize / STEP)];
+
+ List<String> tmpList = new ArrayList<>(STEP);
+ try {
+ while (currentSize <= initialSize) {
+ if (endTimeCapacityVer < System.currentTimeMillis()) {
+ log.debug("Too long to verify interned string capacity");
+ log.debug("Silently pass.");
+ return false;
+ }
+ template[iter]++;
+ if (++iter == template.length) {
+ iter = 0;
+ }
+ String str = new String(template);
+ tmpList.add(str.intern());
+ currentSize += str.length() * 2; //each char costs 2 bytes
+ }
+ } catch (OutOfMemoryError oome) {
+ log.debug("It is not possible to allocate " + initialSize + " size of interned string.");
+ log.debug("Silently pass.");
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void run() {
+ long size = runParams.getTestMemory() / memUsageFactor;
+ if (!verifyInternedStringCapacity(size)) {
+ return;
+ }
+ // Approximate size occupied by all interned strings
+ long sizeOfAllInternedStrings = size / 2;
+ maxStringSize = (int) (sizeOfAllInternedStrings / memoryStrategy.getSize(sizeOfAllInternedStrings, Memory.getObjectExtraSize()));
+ // Each thread keeps reference to each created string.
+ long extraConsumption = runParams.getNumberOfThreads() * Memory.getReferenceSize();
+ log.debug("The overall size of interned strings : " + sizeOfAllInternedStrings / (1024 * 1024) + "M");
+ log.debug("The count of interned strings : " + sizeOfAllInternedStrings / (maxStringSize + extraConsumption));
+ for (long currentSize = 0; currentSize <= sizeOfAllInternedStrings;
+ currentSize += maxStringSize + extraConsumption) {
+ stringsToIntern.add(gp.create(maxStringSize));
+ }
+ super.run();
+ }
+
+ @Override
+ protected Runnable createRunnable(int threadId) {
+ return new StringGenerator(threadId, this);
+ }
+
+ public static void main(String[] args) {
+ int appTimeout = -1;
+ int memUsageFactor = 1;
+ // Part of time that function verifyInternedStringCapacity can take. Time = Application_Timeout / capacityVerTimePart
+ double capacityVerPart = 2;
+ for (int i = 0; i < args.length; ++i) {
+ switch (args[i]) {
+ case "-memUsage":
+ memUsageFactor = Integer.parseInt(args[i + 1]);
+ break;
+ case "-capacityVerPart":
+ capacityVerPart = Double.parseDouble(args[i + 1]);
+ break;
+ case "-appTimeout":
+ appTimeout = Integer.parseInt(args[i + 1]);
+ break;
+ default:
+ }
+ }
+ if (appTimeout == -1) {
+ throw new IllegalArgumentException("Specify -appTimeout.");
+ }
+ long endTimeCapacityVer = System.currentTimeMillis() + (long) (appTimeout / capacityVerPart * 60000);
+ GC.runTest(new StringInternSyncWithGC(memUsageFactor, endTimeCapacityVer), args);
+ }
+
+ protected List<String> getStringsToIntern() {
+ return stringsToIntern;
+ }
+
+ protected int getNumberOfThreads() {
+ return runParams.getNumberOfThreads();
+ }
+
+ protected RandomStringProducer getGarbageProducer() {
+ return gp;
+ }
+
+ protected int getMaxStringSize() {
+ return maxStringSize;
+ }
+
+ protected ExecutionController getExecController() {
+ return getExecutionController();
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC2/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC2/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC2/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC2/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC2/TestDescription.java
new file mode 100644
index 0000000..e5f094a
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC2/TestDescription.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringInternSyncWithGC2.
+ * VM Testbase keywords: [gc, stress, stressopt, feature_perm_removal_jdk7, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -Xlog:gc:gc.log
+ * gc.gctests.StringInternSyncWithGC.StringInternSyncWithGC
+ * -ms high
+ * -memUsage 3
+ * -appTimeout 30
+ * -capacityVerPart 2
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC3/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC3/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC3/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC3/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC3/TestDescription.java
new file mode 100644
index 0000000..0120c3c
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC3/TestDescription.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringInternSyncWithGC3.
+ * VM Testbase keywords: [gc, stress, stressopt, feature_perm_removal_jdk7, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -Xlog:gc:gc.log
+ * gc.gctests.StringInternSyncWithGC.StringInternSyncWithGC
+ * -ms low
+ * -memUsage 100
+ * -appTimeout 30
+ * -capacityVerPart 2
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC4/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC4/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC4/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC4/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC4/TestDescription.java
new file mode 100644
index 0000000..688d2c7
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/StringInternSyncWithGC4/TestDescription.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/StringInternSyncWithGC4.
+ * VM Testbase keywords: [gc, stress, stressopt, feature_perm_removal_jdk7, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * -Xlog:gc:gc.log
+ * gc.gctests.StringInternSyncWithGC.StringInternSyncWithGC
+ * -ms high
+ * -memUsage 100
+ * -appTimeout 30
+ * -capacityVerPart 2
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ThreadGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/ThreadGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ThreadGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/ThreadGC/ThreadGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/ThreadGC/ThreadGC.java
new file mode 100644
index 0000000..bb50e1a
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/ThreadGC/ThreadGC.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/ThreadGC.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * This tests attempts to stress the garbage collector my making
+ * synchronous calls to the garbage collector after producing garbage.
+ * The garbage collector is invoked in a separate thread.
+ * The test runs for one minute (see nsk.share.runner.ThreadsRunner and
+ * nsk.share.runner.RunParams. It passes if no exceptions are generated.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.ThreadGC.ThreadGC -gp random(arrays) -ms low
+ */
+
+package gc.gctests.ThreadGC;
+
+import nsk.share.gc.*;
+import nsk.share.gc.gp.*;
+import java.util.*;
+
+public class ThreadGC extends ThreadedGCTest implements GarbageProducerAware, MemoryStrategyAware {
+ private GarbageProducer garbageProducer;
+ private MemoryStrategy memoryStrategy;
+ private Reclaimer reclaimer;
+ private int count;
+ private long size;
+
+ private class Devourer implements Runnable {
+ private Object[] arr = null;
+ private int index;
+
+ public void run() {
+ if (arr == null || index >= count) {
+ arr = null;
+ arr = new Object[count];
+ index = 0;
+ synchronized (reclaimer) {
+ reclaimer.notify();
+ }
+ }
+ arr[index] = garbageProducer.create(size);
+ ++index;
+ }
+ }
+
+ private class Reclaimer implements Runnable {
+ private long waitTime = 1000;
+
+ public void run() {
+ try {
+ synchronized (this) {
+ this.wait(waitTime);
+ }
+ } catch (InterruptedException e) {
+ }
+ System.gc();
+ }
+ }
+
+ protected Runnable createRunnable(int i) {
+ if (i == 0)
+ return new Devourer();
+ else if (i == 1) {
+ reclaimer = new Reclaimer();
+ return reclaimer;
+ } else
+ return null;
+ }
+
+ public void run() {
+ size = GarbageUtils.getArraySize(runParams.getTestMemory(), memoryStrategy);
+ count = GarbageUtils.getArrayCount(runParams.getTestMemory(), memoryStrategy);
+ runParams.setIterations(count);
+ super.run();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new ThreadGC(), args);
+ }
+
+ public void setGarbageProducer(GarbageProducer garbageProducer) {
+ this.garbageProducer = garbageProducer;
+ }
+
+ public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
+ this.memoryStrategy = memoryStrategy;
+ }
+
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/TestDescription.java
new file mode 100644
index 0000000..592f23e
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/TestDescription.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/WeakReferenceEvilTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Test the WeakReference handling in a more evil way. In this test,
+ * it will only keep every Xth object, thus causing more fragmentation
+ * and fill the heap with unused objects. This test should not
+ * throw any OOME during the test execution.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.WeakReferenceEvilTest
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/WeakReferenceEvilTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/WeakReferenceEvilTest.java
new file mode 100644
index 0000000..a6dcd19
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceEvilTest/WeakReferenceEvilTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package gc.gctests.WeakReference;
+
+import java.util.Random;
+import java.util.ArrayList;
+import java.lang.ref.WeakReference;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+
+/**
+ * Original description from JRockit test:
+ * Tests for the WeakReference handling in JRockit (in a more evil way :)).
+ *
+ * This test must be run with a mx value set, as well as with
+ * -XXfullsystemgc, to ensure Runtime.maxMemory() doesn't return 0
+ * and that System.gc() gets run when called from Java.
+ */
+public class WeakReferenceEvilTest extends GCTestBase {
+
+ /**
+ * Test the WeakReference handling in a more evil way. In this test,
+ * it will only keep every Xth object, thus causing more fragmentation
+ * and fill the heap with unused objects. This test should not
+ * throw any OOME during the test execution.
+ *
+ * @return success if all WeakReferences are NULL after
+ * the test has run
+ */
+ public void run() {
+ long seed;
+ int minSize;
+ int maxSize;
+ int keepEveryXthObject;
+ double memPercentToFill;
+ long counter = 0;
+ long totalMemAlloced = 0;
+ long memToAlloc = 0;
+ Runtime r = Runtime.getRuntime();
+
+ seed = runParams.getSeed();
+ minSize = 2048;
+ maxSize = 32768;
+ memPercentToFill = 0.45;
+ keepEveryXthObject = 5;
+
+ memToAlloc = (long) (r.maxMemory() * memPercentToFill);
+
+ Random rndGenerator = new Random(seed);
+ long multiplier = maxSize - minSize;
+ ArrayList arrWeakRefs = new ArrayList();
+
+ try {
+ while (totalMemAlloced < memToAlloc) {
+ int allocationSize = ((int) (rndGenerator.nextDouble()
+ * multiplier)) + minSize;
+ byte[] tmp = new byte[allocationSize];
+
+ if (counter % keepEveryXthObject == 0) {
+ arrWeakRefs.add(new WeakReference(tmp));
+ totalMemAlloced += allocationSize;
+ }
+
+ // Make sure the temporary object is dereferenced
+ tmp = null;
+
+ counter++;
+ if (counter == Long.MAX_VALUE) {
+ counter = 0;
+ }
+ }
+
+ System.gc();
+
+ long numberOfNotNulledObjects = 0;
+
+ for (int i = 0; i < arrWeakRefs.size(); i++) {
+ WeakReference wr = (WeakReference) arrWeakRefs.get(i);
+ Object o = wr.get();
+
+ if (o != null) {
+ numberOfNotNulledObjects++;
+ }
+ }
+
+ if (numberOfNotNulledObjects > 0) {
+ throw new TestFailure(numberOfNotNulledObjects + " out of "
+ + arrWeakRefs.size() + " WeakReferences was not "
+ + "null after the GC had run");
+ }
+
+ log.info("All WeakReferences was cleared after the "
+ + "GC had run");
+ } catch (OutOfMemoryError oome) {
+ throw new TestFailure("OutOfMemoryException was thrown. This should "
+ + "not happen during the execution of this test.");
+ } finally {
+ arrWeakRefs = null;
+ }
+ }
+ public static void main(String[] args) {
+ GC.runTest(new WeakReferenceEvilTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/TestDescription.java
new file mode 100644
index 0000000..e32736e
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/TestDescription.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/WeakReferenceTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * Tests for the WeakReference handling in JRockit.
+ *
+ * COMMENTS
+ * This test was ported from JRockit test suite.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.WeakReferenceTest
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/WeakReferenceTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/WeakReferenceTest.java
new file mode 100644
index 0000000..f107e68
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/WeakReferenceTest/WeakReferenceTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package gc.gctests.WeakReference;
+
+import java.util.Random;
+import java.util.ArrayList;
+import java.lang.ref.WeakReference;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.GCTestBase;
+
+/**
+ * Original description from JRockit test:
+ *
+ * Tests for the WeakReference handling in JRockit.
+ *
+ * This test must be run with a mx value set, as well as with
+ * -XXfullsystemgc, to ensure Runtime.maxMemory() doesn't return 0
+ * and that System.gc() gets run when called from Java.
+ */
+public class WeakReferenceTest extends GCTestBase {
+
+ /**
+ * Test that all WeakReferences has been cleared after
+ * the GC has run. This test should not throw an OOME
+ * during the test execution.
+ *
+ */
+ @Override
+ public void run() {
+ long seed;
+ int minSize;
+ int maxSize;
+ double memPercentToFill;
+ long totalMemAlloced = 0;
+ long memToAlloc = 0;
+ Runtime r = Runtime.getRuntime();
+
+ seed = runParams.getSeed();
+ minSize = 2048;
+ maxSize = 32768;
+
+ memPercentToFill = 0.45;
+
+ memToAlloc = (long) (r.maxMemory() * memPercentToFill);
+
+ Random rndGenerator = new Random(seed);
+ long multiplier = maxSize - minSize;
+ ArrayList arrWeakRefs = new ArrayList();
+
+ try {
+ while (totalMemAlloced < memToAlloc) {
+ int allocationSize = ((int) (rndGenerator.nextDouble()
+ * multiplier)) + minSize;
+ byte[] tmp = new byte[allocationSize];
+
+ arrWeakRefs.add(new WeakReference(tmp));
+ totalMemAlloced += allocationSize;
+
+ // Make sure the temporary object is dereferenced
+ tmp = null;
+ }
+
+ System.gc();
+
+ long numberOfNotNulledObjects = 0;
+
+ for (int i = 0; i < arrWeakRefs.size(); i++) {
+ WeakReference wr = (WeakReference) arrWeakRefs.get(i);
+ Object o = wr.get();
+
+ if (o != null) {
+ numberOfNotNulledObjects++;
+ }
+ }
+
+ if (numberOfNotNulledObjects > 0) {
+ throw new TestFailure(numberOfNotNulledObjects + " out of "
+ + arrWeakRefs.size() + " WeakReferences was not "
+ + "null after the GC had run");
+ }
+
+ log.info("All WeakReferences was cleared after the "
+ + "GC had run");
+ } catch (OutOfMemoryError oome) {
+ throw new TestFailure("OutOfMemoryException was thrown. This should "
+ + "not happen during the execution of this test.");
+ } finally {
+ arrWeakRefs = null;
+ }
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new WeakReferenceTest(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak001/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak001/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak001/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak001/weak001.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak001/weak001.java
new file mode 100644
index 0000000..fe17474
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak001/weak001.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2004, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/weak001.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly works with
+ * WeakReferences. It also checks that no unexpected exceptions and errors
+ * are thrown or the JVM is not crashed.
+ * The test starts a number of threads. Each thread run tests for some time
+ * or serveral iterations. See javadoc StressOptions for configuration.
+ * First of all each test defines what type to check (there are 10 types
+ * totally). As soon as the type is defined, a WeakReference is created that
+ * refers to an array of tested type and is registered with in a queue. A
+ * WeakReference for NonbranchyTree class does not refer to an array, but to
+ * instances of the class.
+ * After that a thread performs next checks for the reference:
+ * 1. The reference is in queue after GC is provoked with
+ * Algorithms.eatMemory() method (a single thread eats the memory).
+ * 2. queue.remove() returns reference from the queue.
+ * 3. queue.poll() returns null.
+ * 4. reference.clear() does not throw any exception.
+ * The test extends ThreadedGCTest and implements GarbageProducerAware and
+ * MemoryStrategyAware interfaces. The corresponding javadoc documentation
+ * for additional test configuration.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.WeakReference.weak001.weak001 -ms low
+ */
+
+package gc.gctests.WeakReference.weak001;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+import nsk.share.gc.GC;
+import nsk.share.gc.NonbranchyTree;
+import nsk.share.gc.ThreadedGCTest;
+import nsk.share.gc.gp.GarbageProducer;
+import nsk.share.gc.gp.GarbageProducerAware;
+import nsk.share.gc.gp.GarbageUtils;
+import nsk.share.gc.gp.MemoryStrategy;
+import nsk.share.gc.gp.MemoryStrategyAware;
+import nsk.share.gc.gp.string.InternedStringProducer;
+import nsk.share.gc.gp.string.RandomStringProducer;
+
+public class weak001 extends ThreadedGCTest implements GarbageProducerAware, MemoryStrategyAware {
+
+ private GarbageProducer garbageProducer;
+ private MemoryStrategy memoryStrategy;
+ private InternedStringProducer internedStringProducer = new InternedStringProducer(new RandomStringProducer(10));
+ // Total number of types to test
+ final static int TYPES_COUNT = 11;
+ // Size of array of each tested type. The constant also specifies the
+ // number of nodes in a NonbranchyTree and size of each node
+ final static int SIZE = 100;
+
+ protected Runnable createRunnable(int i) {
+ return new Test();
+ }
+
+ public void setGarbageProducer(GarbageProducer garbageProducer) {
+ this.garbageProducer = garbageProducer;
+ }
+
+ public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
+ this.memoryStrategy = memoryStrategy;
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new weak001(), args);
+ }
+
+ // The class implements the logic of the testcase
+ class Test implements Runnable {
+
+ int iteration;
+
+ public void run() {
+ // Pre-allocated OOME message to avoid OOME when logging it
+ String oomMsg = "Ignored OOME in run()";
+ try {
+
+ log.info("iteration " + iteration);
+ ReferenceQueue queue = new ReferenceQueue();
+ WeakReference reference;
+ int code = iteration % TYPES_COUNT;
+ String type;
+ // Define a specific type for each thread to test
+ switch (code) {
+ case 0:
+ reference = new WeakReference(new byte[SIZE], queue);
+ type = "byte";
+ break;
+ case 1:
+ reference = new WeakReference(new short[SIZE], queue);
+ type = "short";
+ break;
+ case 2:
+ reference = new WeakReference(new int[SIZE], queue);
+ type = "int";
+ break;
+ case 3:
+ reference = new WeakReference(new long[SIZE], queue);
+ type = "long";
+ break;
+ case 4:
+ reference = new WeakReference(new char[SIZE], queue);
+ type = "char";
+ break;
+ case 5:
+ reference = new WeakReference(new boolean[SIZE], queue);
+ type = "boolean";
+ break;
+ case 6:
+ reference = new WeakReference(new double[SIZE], queue);
+ type = "double";
+ break;
+ case 7:
+ reference = new WeakReference(new float[SIZE], queue);
+ type = "float";
+ break;
+ case 8:
+ reference = new WeakReference(new Object[SIZE], queue);
+ type = "Object";
+ break;
+ case 9:
+ reference = new WeakReference(internedStringProducer.create(SIZE), queue);
+ type = "InternedString";
+ break;
+ default:
+ reference = new WeakReference(new NonbranchyTree(SIZE, 0.3f, SIZE),
+ queue);
+ type = "NonbranchyTree";
+ break;
+ }
+ int initialFactor = memoryStrategy.equals(MemoryStrategy.HIGH) ? 1 : (memoryStrategy.equals(MemoryStrategy.LOW) ? 10 : 2);
+ GarbageUtils.eatMemory(getExecutionController(), garbageProducer, initialFactor , 10, 0);
+ if (!getExecutionController().continueExecution()) {
+ // we were interrrupted by stresser. just exit...
+ return;
+ }
+ Reference polledReference = null;
+ try {
+ polledReference = queue.remove();
+ } catch (InterruptedException e) {
+ log.error("Unexpected InterruptedException during queue.remove().");
+ setFailed(true);
+ }
+ // Check the reference and the queue
+ // The polled reference must be equal to the one enqueued to
+ // the queue
+
+ if (polledReference != reference) {
+ log.error("The original reference is not equal to polled reference.");
+ setFailed(true);
+ }
+
+ // queue.poll() once again must return null now, since there is
+ // only one reference in the queue
+ polledReference = queue.poll();
+ if (polledReference != null) {
+ log.error("There are more than one references in the queue.");
+ setFailed(true);
+ }
+ reference.clear();
+ } catch (OutOfMemoryError e) {
+ log.info(oomMsg);
+ }
+ iteration++;
+ }
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak002/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak002/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak002/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak002/TestDescription.java
new file mode 100644
index 0000000..ee1c124
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak002/TestDescription.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/weak002.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ * VM Testbase readme:
+ * DESCRIPTION
+ * The test checks that Garbage Collector correctly works with
+ * WeakReferences. It also checks that no unexpected exceptions and errors
+ * are thrown or the JVM is not crashed.
+ * The test starts a number of threads. Each thread run tests for some time
+ * or serveral iterations. See javadoc StressOptions for configuration.
+ * First of all each test defines what type to check (there are 10 types
+ * totally). As soon as the type is defined, a WeakReference is created that
+ * refers to an array of tested type and is registered with in a queue. A
+ * WeakReference for NonbranchyTree class does not refer to an array, but to
+ * instances of the class.
+ * After that a thread performs next checks for the reference:
+ * 1. The reference is in queue after GC is provoked with
+ * Algorithms.eatMemory() method (a single thread eats the memory).
+ * 2. queue.remove() returns reference from the queue.
+ * 3. queue.poll() returns null.
+ * 4. reference.clear() does not throw any exception.
+ * The test extends ThreadedGCTest and implements GarbageProducerAware and
+ * MemoryStrategyAware interfaces. The corresponding javadoc documentation
+ * for additional test configuration.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.WeakReference.weak001.weak001 -ms high
+ */
+
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak003/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak003/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak003/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak003/weak003.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak003/weak003.java
new file mode 100644
index 0000000..c10409e
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak003/weak003.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/weak003.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.weak003.weak003 -t 1
+ */
+
+package gc.gctests.WeakReference.weak003;
+
+import java.lang.ref.Reference;
+import nsk.share.test.*;
+import nsk.share.TestFailure;
+import nsk.share.gc.*;
+import java.lang.ref.WeakReference;
+
+/**
+ * Test that GC clears weak references before throwing OOM.
+ *
+ * This test creates a number of weak references, then provokes
+ * GC with Algorithms.eatMemory and checks that all references
+ * have been cleared.
+ *
+ * This assertion is not clearly stated in javadoc for WeakReference,
+ * (but for SoftReference), but one would expect that quality GC
+ * will do it.
+ */
+public class weak003 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int arrayLength;
+ private int objectSize = 100;
+ private Reference<MemoryObject>[] references;
+
+ public void run() {
+ for (int i = 0; i < arrayLength; ++i) {
+ references[i] = new WeakReference<MemoryObject>(new MemoryObject(LocalRandom.nextInt(objectSize)));
+ }
+ Algorithms.eatMemory(getExecutionController());
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ // Check that all references have been cleared
+ int n = 0;
+ for (int i = 0; i < arrayLength; ++i) {
+ if (references[i].get() != null) {
+ ++n;
+ }
+ }
+ if (n != 0) {
+ references = null;
+ throw new TestFailure("Some of the references have been not cleared: " + n);
+ }
+ }
+
+ public void Worker() {
+ arrayLength = Memory.getArrayLength(runParams.getTestMemory(), Memory.getReferenceSize() + objectSize);
+ System.out.println("Array size: " + arrayLength);
+ references = new WeakReference[arrayLength];
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new weak003(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak004/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak004/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak004/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak004/weak004.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak004/weak004.java
new file mode 100644
index 0000000..14d3a43
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak004/weak004.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/weak004.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.weak004.weak004 -t 1
+ */
+
+package gc.gctests.WeakReference.weak004;
+
+import nsk.share.gc.*;
+import java.lang.ref.WeakReference;
+
+/**
+ * Test that GC correctly clears weak references.
+ *
+ * This test is the same as weak003 except that it creates
+ * weak references to same object.
+ */
+public class weak004 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int arrayLength;
+ private int objectSize = 100;
+ private WeakReference[] references;
+
+ private void makeReferences() {
+ MemoryObject obj = new MemoryObject(objectSize);
+ references = new WeakReference[arrayLength];
+ for (int i = 0; i < arrayLength; ++i) {
+ references[i] = new WeakReference<MemoryObject>(obj);
+ }
+ }
+
+ public void run() {
+ arrayLength = Memory.getArrayLength(runParams.getTestMemory() - objectSize, Memory.getReferenceSize() + objectSize);
+ System.out.println("Array size: " + arrayLength);
+ makeReferences();
+ Algorithms.eatMemory(getExecutionController());
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ int n = 0;
+ for (int i = 0; i < arrayLength; ++i) {
+ if (references[i].get() != null) {
+ ++n;
+ }
+ }
+ if (n != 0) {
+ log.error("Some of the references have been not cleared: " + n);
+ setFailed(true);
+ }
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new weak004(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak005/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak005/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak005/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak005/weak005.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak005/weak005.java
new file mode 100644
index 0000000..da9e8de
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak005/weak005.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/weak005.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.weak005.weak005 -t 1
+ */
+
+package gc.gctests.WeakReference.weak005;
+
+import nsk.share.gc.*;
+import java.lang.ref.WeakReference;
+
+/**
+ * Test that GC correctly clears weak references.
+ *
+ * This test creates a number of weak references,
+ * each of which points to the next, then provokes
+ * GC with Algorithms.eatMemory(). The test succeeds
+ * if last reference has been cleared.
+ */
+public class weak005 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int length = 10000;
+ private int objectSize = 10000;
+ private WeakReference[] references;
+
+ public Worker() {
+ System.out.println("Array size: " + length);
+ System.out.println("Object size: " + objectSize);
+ references = new WeakReference[length];
+ }
+
+ private void makeReferences() {
+ references[length - 1] = null;
+ MemoryObject obj = new MemoryObject(objectSize);
+ references[0] = new WeakReference(obj);
+ for (int i = 1; i < length; ++i) {
+ references[i] = new WeakReference(references[i - 1]);
+ }
+ for (int i = 0; i < length - 1; ++i) {
+ references[i] = null;
+ }
+ }
+
+ public void run() {
+ makeReferences();
+ Algorithms.eatMemory(getExecutionController());
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ if (references[length - 1].get() != null) {
+ log.error("Last weak reference has not been cleared");
+ setFailed(true);
+ }
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new weak005(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak006/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak006/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak006/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak006/weak006.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak006/weak006.java
new file mode 100644
index 0000000..e392367
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak006/weak006.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/weak006.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.weak006.weak006 -t 1
+ */
+
+package gc.gctests.WeakReference.weak006;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.TestFailure;
+import java.lang.ref.WeakReference;
+import java.lang.ref.SoftReference;
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+
+/**
+ * Test that GC correctly clears references.
+ *
+ * This test randomly creates a number of weak, soft,
+ * phantom and strong references, each of which points
+ * to the next, then provokes GC with Algorithms.eatMemory().
+ * The test succedes if last reference has been cleared.
+ */
+public class weak006 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int length;
+ private int objectSize = 100;
+ private Object[] references;
+ private Reference lastReference;
+
+ private Object makeReference(int n, Object o) {
+ switch (n) {
+ case 0:
+ return new WeakReference(o);
+ case 1:
+ return new SoftReference(o);
+ case 2:
+ return new PhantomReference(o, null);
+ case 4: {
+ // Array of strong references
+ int len = Memory.getArrayLength(objectSize, Memory.getReferenceSize());
+ Object[] arr = new Object[len];
+ for (int i = 0; i < len; ++i) {
+ arr[i] = o;
+ }
+ return arr;
+ }
+ case 5: {
+ // reference to array of strong references and strong reference to reference
+ int len = Memory.getArrayLength(objectSize, Memory.getReferenceSize());
+ Object[] arr = new Object[len];
+ for (int i = 1; i < len; ++i) {
+ arr[i] = o;
+ }
+ Reference ref = (Reference) makeReference(LocalRandom.nextInt(3), arr);
+ if (len > 0) {
+ arr[0] = ref;
+ }
+ return ref;
+ }
+ case 3:
+ default:
+ // Strong reference
+ return o;
+ }
+ }
+
+ private void clear() {
+ lastReference = null;
+ references[length - 1] = null;
+ }
+
+ private void makeReferences(int n) {
+ clear();
+ MemoryObject obj = new MemoryObject(objectSize);
+ references[0] = new WeakReference(obj);
+ for (int i = 1; i < length; ++i) {
+ if (i != length - 1) {
+ references[i] = makeReference(LocalRandom.nextInt(2), references[i - 1]);
+ } else {
+ lastReference = (Reference) makeReference(n, references[i - 1]);
+ references[i] = lastReference;
+ }
+ }
+ for (int i = 0; i < length; ++i) {
+ references[i] = null;
+ }
+ }
+
+ public void run() {
+ makeReferences(0);
+ ExecutionController stresser = getExecutionController();
+ Algorithms.eatMemory(stresser);
+ if (!stresser.continueExecution()) {
+ return;
+ }
+ if (lastReference.get() != null) {
+ references = null;
+ throw new TestFailure("Last weak reference has not been cleared");
+ }
+ makeReferences(1);
+ Algorithms.eatMemory(stresser);
+ if (!stresser.continueExecution()) {
+ return;
+ }
+ if (lastReference.get() != null) {
+ references = null;
+ throw new TestFailure("Last soft reference has not been cleared");
+ }
+ }
+
+ public Worker() {
+ length = Memory.getArrayLength(runParams.getTestMemory() - objectSize, Memory.getReferenceSize() + objectSize);
+ System.out.println("Array size: " + length);
+ references = new Object[length];
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new weak006(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak007/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak007/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak007/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak007/weak007.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak007/weak007.java
new file mode 100644
index 0000000..2aa556f
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak007/weak007.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2007, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReference/weak007.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.weak007.weak007 -t 1
+ */
+
+package gc.gctests.WeakReference.weak007;
+
+import nsk.share.TestFailure;
+import nsk.share.gc.*;
+import java.lang.ref.WeakReference;
+import java.lang.ref.Reference;
+
+/**
+ * Test that GC correctly clears weak references.
+ *
+ * This test creates a number of weak references,
+ * each of which points to the next, then provokes
+ * GC with Algorithms.eatMemory(). The test succeeds
+ * if last reference has been cleared and the object
+ * has been finalized.
+ */
+public class weak007 extends ThreadedGCTest {
+
+ class Worker implements Runnable {
+
+ private int length = 10000;
+ private int objectSize = 10000;
+ private Reference[] references;
+
+ private void makeReferences() {
+ references[length - 1] = null;
+ FinMemoryObject obj = new FinMemoryObject(objectSize);
+ references[0] = new WeakReference(obj);
+ for (int i = 1; i < length; ++i) {
+ references[i] = new WeakReference(references[i - 1]);
+ }
+ for (int i = 0; i < length - 1; ++i) {
+ references[i] = null;
+ }
+ }
+
+ public void run() {
+ makeReferences();
+ Algorithms.eatMemory(getExecutionController());
+ if (getExecutionController().continueExecution()) {
+ if (references[length - 1].get() != null) {
+ throw new TestFailure("Last weak reference has not been cleared");
+ }
+ } else {
+ log.info("Completed iterations: " + getExecutionController().getIteration());
+ }
+ }
+
+ public Worker() {
+ log.info("Array size: " + length);
+ log.info("Object size: " + objectSize);
+ references = new WeakReference[length];
+ }
+ }
+
+ @Override
+ protected Runnable createRunnable(int i) {
+ return new Worker();
+ }
+
+ public static void main(String[] args) {
+ GC.runTest(new weak007(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/CircularLinkedList.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/CircularLinkedList.java
new file mode 100644
index 0000000..b76ec46
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/CircularLinkedList.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package gc.gctests.WeakReferenceGC;
+
+class node {
+ byte [] arr;
+ node next;
+ node prev;
+ node(){ arr = new byte[100]; }
+}
+
+public class CircularLinkedList implements Cloneable {
+ private node Root;
+
+ public void addElement() {
+ node newnode;
+
+ newnode = new node();
+ if (Root == null){
+ Root = newnode;
+ Root.next = Root;
+ Root.prev = Root;
+ } else{
+ newnode.next = Root.next;
+ Root.next.prev = newnode;
+ Root.next = newnode;
+ newnode.prev = Root;
+ }
+ }
+
+ public void addNelements(int n) {
+ for (int i = 0; i < n ; i++)
+ addElement();
+ }
+
+ public int elementCount() {
+ node p;
+ int count;
+
+ p = Root;
+ count = 0;
+
+ do {
+ p = p.prev;
+ count++;
+ }while(p != Root);
+ return count;
+ }
+
+ public Object clone() {
+ node p;
+ p = Root;
+
+ if ( p == null ) return null;
+ CircularLinkedList clone = new CircularLinkedList();
+ do {
+ clone.addElement();
+ p = p.prev;
+ } while(p != Root);
+ return clone;
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/WeakReferenceGC.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/WeakReferenceGC.java
new file mode 100644
index 0000000..a2ea256
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReferenceGC/WeakReferenceGC.java
@@ -0,0 +1,271 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/WeakReferenceGC.
+ * VM Testbase keywords: [gc, nonconcurrent]
+ * VM Testbase readme:
+ * *******************************************
+ * set timeout = 25 when running this test
+ * *******************************************
+ * This tests checks to see if the garbage collector enqueues
+ * a weak reference when referrent has been turned to garbage.
+ * Weak references are enqueued in a non-deterministic way
+ * by the garbage collector, so the test uses a heuristic to
+ * determine whether the references are being enqueued in a timely
+ * manner which in turn determines whether outcome of the test.
+ * IF the user invokes the test with the following command line
+ * parameters :
+ * java WeakReferenceGC -qFactor 0.9 -gcCount 5
+ * the test expects that 90% of all objects with only weak references
+ * pointing to them will be enqueued within 5 calls to the garbage collector.
+ * When I ran the test, I consistently got figures of 98% enqueueing
+ * with just 1 call to the garbage collector. So if this test fails,
+ * at its current settings, the garbage collector is not performing as well
+ * as it used to.
+ * The test creates circular linked lists of size 0.1Meg each. The number
+ * of lists created can be set via the -numLists flag. The default
+ * value is 50.
+ * The circular linked lists have both strong and weak references pointing
+ * to them. The strong and weak references are kept in arrays.
+ * The strong references are all nulled out and System.gc() is called
+ * explicitly and the heuristic is applied. If the test does not
+ * satisfy the heuristic or an OutOfMemory exception is thrown,
+ * the test fails.
+ * Array containing Each circular linked list Array containing
+ * weak references is 0.1 Meg each and has strong references
+ * to linked lists. a weak reference, W<n> and a to linked lists.
+ * strong reference, x<n>
+ * pointing to it.
+ * ---- ---------------------------- -----
+ * | | | ---- ---- <-| | |
+ * | W1 |--> -->| |---.......>| | <---- | x1 |
+ * | | -->| |<---.......| |<-- | |
+ * ---- | ---- 1000 --- | -----
+ * ---------------------------
+ * . .
+ * . .
+ * . .
+ * . .
+ * . . 10
+ * . .
+ * ---- ---------------------------- -----
+ * | | | ---- ---- <-| | |
+ * | Wn |--> -->| |---.......>| | <---- | xn |
+ * | | -->| |<---.......| |<-- | |
+ * ---- | ---- 1000 --- | -----
+ * ---------------------------
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm
+ * gc.gctests.WeakReferenceGC.WeakReferenceGC
+ * -numList 50
+ * -qFactor 0.9
+ * -gcCount 5
+ * -iter 100
+ */
+
+package gc.gctests.WeakReferenceGC;
+
+import java.util.*;
+import java.lang.ref.*;
+import nsk.share.TestFailure;
+import nsk.share.gc.GC;
+import nsk.share.gc.ThreadedGCTest;
+import nsk.share.gc.gp.GarbageUtils;
+
+public class WeakReferenceGC extends ThreadedGCTest {
+
+ // A heuristic is used to determine the outcome(pass/fail
+ // status) of a test. If 90% of all objects that have
+ // _only_ weak references pointing to them are garbage
+ // collected with 5 explicit calls to the garbage collector
+ // the test is deemed a pass. The following two variables
+ // are used to define this heuristic: gcCount, qFactor
+
+ static String args[];
+
+ CircularLinkedList holder[];
+
+ int loopCount = 100; // # of times test is performed
+
+ int memory_reserve[];
+ int gcCount = 5;
+ int numLists = 50; // number of linked lists
+ float qFactor = (float) 0.9;
+ ReferenceQueue refQueue;
+ Vector results;
+ WeakReference wholder[];
+
+ public static void main(String[] args) {
+ WeakReferenceGC.args = args;
+ GC.runTest(new WeakReferenceGC(), args);
+ }
+
+ WeakReferenceGC() {
+ holder = new CircularLinkedList[numLists];
+ wholder = new WeakReference[numLists];
+ refQueue = new ReferenceQueue();
+ results = new Vector();
+ }
+
+ protected Runnable createRunnable(int i) {
+ return i > 0 ? null : new Worker();
+ }
+
+ private void dumpTestResults() {
+ double objectsRecovered;
+
+ System.out.println("Percentage of Objects" + " # of GC's");
+ System.out.println(" Recovered " + " Required");
+ for (int i = 0; i < results.size(); i++) {
+ Statistic s = (Statistic) results.elementAt(i);
+ objectsRecovered = Math.rint((float) (s.numEnqueued)
+ / (float) (numLists) * 100.0);
+ System.out.println(" " + objectsRecovered
+ + " % " + s.iterations);
+ }
+ }
+
+ private boolean hasPassed() {
+ boolean passed;
+ passed = true; // assume passed till proven otherwise
+
+ for (int i = 0; i < results.size(); i++) {
+ Statistic s = (Statistic) results.elementAt(i);
+ if ((s.iterations > gcCount)
+ || (s.numEnqueued < (int) (numLists * qFactor))) {
+ passed = false;
+ break; // test failed
+ }
+ }
+ return passed;
+ }
+
+ private void parseTestParams(String args[]) {
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].compareTo("-numList") == 0) {
+ numLists = new Integer(args[++i]).intValue();
+ } else if (args[i].compareTo("-qFactor") == 0) {
+ qFactor = new Float(args[++i]).floatValue();
+ } else if (args[i].compareTo("-gcCount") == 0) {
+ gcCount = new Integer(args[++i]).intValue();
+ } else if (args[i].compareTo("-iter") == 0) {
+ loopCount = new Integer(args[++i]).intValue();
+ // } else {
+ // System.err.println("usage : " +
+ // "java WeakReferenceGC [-numList <n>] " +
+ // "[-qFactor <0.x>] [-gcCount <n>] [-iter <n>]");
+ // throw new TestBug("Invalid arguments");
+ }
+ }
+ }
+
+ private void persistentGC() {
+ int numEnqueued, iter, qCriterion;
+
+ numEnqueued = 0; // number of weakReference enqueued
+ iter = 0;
+ qCriterion = (int) (numLists * qFactor);
+
+ while ((numEnqueued < qCriterion) && (iter <= gcCount)) {
+ iter++;
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ if (GarbageUtils.eatMemory(getExecutionController()) == 0) {
+ return; // We were unable to provoke OOME before timeout is over
+ }
+ numEnqueued = 0; // We set counter to zero to avoid counting references twice
+ for (int i = 0; i < numLists; i++) {
+ if (wholder[i].isEnqueued()) {
+ numEnqueued++;
+ }
+ }
+ }
+ results.addElement((new Statistic(iter, numEnqueued)));
+ }
+
+ private void runTest() {
+ int iter;
+ iter = 1;
+ try {
+ do {
+ for (int i = 0; i < numLists; i++) {
+ holder[i] = new CircularLinkedList();
+ holder[i].addNelements(1000);
+ wholder[i] = new WeakReference(holder[i], refQueue);
+ }
+
+ for (int i = 0; i < numLists; i++) {
+ holder[i] = null;
+ }
+
+ if (!getExecutionController().continueExecution()) {
+ return;
+ }
+ persistentGC();
+
+ iter++;
+ } while (iter <= loopCount);
+ } catch (OutOfMemoryError e) {
+ memory_reserve = null;
+ System.gc();
+ throw new TestFailure("Failed at iteration=" + loopCount);
+ }
+ }
+
+ //We can't override run() method in WeakReferenceGC, so we are carrying out it to Worker
+ private class Worker implements Runnable {
+ @Override
+ public void run() {
+ parseTestParams(args);
+ runTest();
+ dumpTestResults();
+ boolean passed = hasPassed();
+ if (passed == true) {
+ log.info("Test passed.");
+ } else {
+ log.error("Test failed.");
+ setFailed(true);
+ }
+ }
+ }
+}
+
+class Statistic {
+ int iterations;
+ int numEnqueued;
+
+ Statistic(int i, int num) {
+ iterations = i;
+ numEnqueued = num;
+ }
+
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/fileTest/TEST.properties b/test/hotspot/jtreg/vmTestbase/gc/gctests/fileTest/TEST.properties
new file mode 100644
index 0000000..04b22a1
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/fileTest/TEST.properties
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2017, 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+exclusiveAccess.dirs=.
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/fileTest/fileTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/fileTest/fileTest.java
new file mode 100644
index 0000000..abba3b5b
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/fileTest/fileTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key stress gc
+ *
+ * @summary converted from VM Testbase gc/gctests/fileTest.
+ * VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.fileTest.fileTest -Filename fileTest.java -iterations 500
+ */
+
+package gc.gctests.fileTest;
+
+import java.io.*;
+import java.util.*;
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.TestBug;
+import nsk.share.TestFailure;
+
+public class fileTest extends GCTestBase {
+ private File [] fileArray;
+ private FileInputStream [] fileInputArray;
+ private final static int fileNumber = 10000;
+ // The number of open file descriptors per process varies from one
+ // system to another. lets expermiment with just 20 open fd's.
+ private final static int inputStreamNumber = 20;
+ private String fileName;
+
+ public fileTest(String fileName) {
+ this.fileName = fileName;
+ fileArray = new File[fileNumber];
+ fileInputArray = new FileInputStream[inputStreamNumber];
+ }
+
+ public void runIteration() throws IOException {
+ for (int i = 0; i < fileNumber; ++i)
+ fileArray[i] = new File(fileName);
+ for (int i = 0; i < inputStreamNumber; ++i)
+ fileInputArray[i] = new FileInputStream(fileName);
+ for (int i = 0; i < inputStreamNumber; ++i)
+ fileInputArray[i].close();
+ }
+
+ public void run() {
+ try {
+ Stresser stresser = new Stresser(runParams.getStressOptions());
+ stresser.start(runParams.getIterations());
+ try {
+ while (stresser.iteration())
+ runIteration();
+ } finally {
+ stresser.finish();
+ }
+ } catch (IOException e) {
+ throw new TestFailure(e);
+ }
+ }
+
+ public static void main(String args[]) {
+ String fileName = null;
+ for (int i = 0 ; i < args.length ; i++) {
+ if( args[i].equals("-Filename"))
+ fileName = args[++i];
+ }
+ if (fileName == null)
+ throw new TestBug("No -Filename option is specified");
+ GC.runTest(new fileTest(fileName), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest01/gctest01.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest01/gctest01.java
new file mode 100644
index 0000000..7467318
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest01/gctest01.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/gctest01.
+ * VM Testbase keywords: [gc]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.gctest01.gctest01 100 10
+ */
+
+package gc.gctests.gctest01;
+
+import nsk.share.test.*;
+import nsk.share.log.*;
+import nsk.share.gc.*;
+import nsk.share.TestBug;
+
+import java.util.Random;
+//import RusageStruct;
+
+/* -- stress testing
+ create 20 memory evil threads requesting to allocate
+ the object of sizes from 8 to ( 2 ^ 19).
+ The live time of objects is very short.
+ Memory evil thread exits the first time memory allocation fails.
+ */
+
+class ThreadTracker {
+ static int threadCount = 0;
+
+ static synchronized int getThreadCount() {
+ return threadCount;
+ }
+
+ static synchronized void setThreadCount(int count) {
+ threadCount = count;
+ }
+
+ static synchronized void incr() {
+ threadCount++;
+ }
+
+ static synchronized void decr() {
+ threadCount--;
+ }
+}
+
+class PopulationException extends Exception {
+}
+
+class Person {
+ String name;
+ int ssid;
+ int age;
+ int buf[];
+ int bufsz;
+ static int populationLimit;
+ static int currentPopulation;
+
+ public Person(String n, int ssid, int age, int bufsz) throws PopulationException {
+ this.incr();
+ if (this.getPopulation() > this.getPopulationLimit()) {
+ throw new PopulationException();
+ }
+ name = n;
+ this.ssid = ssid;
+ this.age = age;
+ if ( bufsz > 0 ) {
+ this.bufsz = bufsz;
+ this.buf = new int[bufsz];
+ }
+ }
+
+ static synchronized void incr() {
+ currentPopulation++;
+ }
+
+ static synchronized int getPopulation() {
+ return currentPopulation;
+ }
+
+ static synchronized void setPopulation(int census) {
+ currentPopulation = census;
+ }
+
+ static synchronized void setPopulationLimit(int limit) {
+ populationLimit = limit;
+ }
+
+ static synchronized int getPopulationLimit() {
+ return populationLimit;
+ }
+}
+
+
+
+// create 20 memory evil threads requesting to allocate
+// the object of sizes from 8 to ( 2 ^ 19).
+// The live time of objects is very short.
+public class gctest01 extends TestBase {
+ private String[] args;
+
+ public gctest01(String[] args) {
+ setArgs(args);
+ }
+
+ class memevil extends Thread {
+ int sum;
+ int bufsz = 64;
+
+ public memevil(int bufsz) {
+ ThreadTracker.incr();
+ sum = 0;
+ this.bufsz = bufsz;
+
+ }
+
+ /* Person object is live short, it will be garbage after
+ control returns
+ */
+ private boolean doit() {
+ try {
+ Person p = new Person("Duke", 100, 100, bufsz);
+ } catch (OutOfMemoryError e ) {
+ log.info(getName() + ": Out of Memory");
+ return false; //should free up some memory
+ } catch (PopulationException e) {
+ //we've reached the limit, so stop
+ return false;
+ }
+ return true;
+ }
+
+ public void run() {
+ while ( doit() ) {
+ if ( LocalRandom.random() > 0.6668) {
+ try {
+ sleep(10); // to be nice
+ }
+ catch (InterruptedException e) {}
+ }
+ }
+ //must be done, decrement the thread count
+ ThreadTracker.decr();
+ }
+ }
+
+ class escaper extends Thread {
+ public void run() {
+ while ( ThreadTracker.getThreadCount() > 0 ) {
+ int buf[] = new int[32];
+ try
+ {
+ Thread.currentThread().sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ // log.info("Is the sun rising?");
+ }
+ }
+ }
+
+
+ public void run() {
+ int bufsz = 8;
+ int i = 3;
+ int peopleLimit = 1000;
+ String usage = "usage: gctest01 [NumberOfObjects [Iterations] ] ]";
+ int loops;
+ int LOOPCOUNT = 10;
+
+ if (args.length > 0) {
+ try {
+ peopleLimit = new Integer(args[0]).intValue();
+ } catch (NumberFormatException e) {
+ log.info(usage);
+ throw new TestBug("Bad input to gctest01." +
+ " Expected integer, got: ->" + args[0] + "<-", e);
+ }
+ }
+
+ if (args.length > 1 ) {
+ try {
+ LOOPCOUNT = new Integer(args[1]).intValue();
+ } catch (NumberFormatException e) {
+ log.error(usage);
+ throw new TestBug("Bad input to gctest01." +
+ " Expected int, got: ->" + args[1] + "<-", e);
+ }
+
+ }
+
+ double before = 0.0;
+ double after;
+
+ Person.setPopulationLimit(peopleLimit);
+
+ for (loops = 0; loops < LOOPCOUNT; loops++) {
+ Person.setPopulation(0);
+ escaper you = new escaper();
+ you.setName("Escaper");
+ you.start();
+ i = 3;
+ bufsz = 8;
+ while ( i < 20 )
+ {
+ memevil me = new memevil(bufsz);
+ me.setName("Memevil" + bufsz);
+ bufsz = 2*bufsz;
+ me.start();
+ i++;
+ Thread.currentThread().yield();
+ }
+ try
+ {
+ you.join();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ } // end of loops
+ log.info("Test passed.");
+
+ }
+
+ public void setArgs(String[] args) {
+ this.args = args;
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new gctest01(args), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest02/gctest02.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest02/gctest02.java
new file mode 100644
index 0000000..161708e
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest02/gctest02.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+//gctest02.java
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/gctest02.
+ * VM Testbase keywords: [gc]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm gc.gctests.gctest02.gctest02 100
+ */
+
+package gc.gctests.gctest02;
+
+import nsk.share.TestFailure;
+import nsk.share.TestBug;
+/* stress testing
+ create 16 memory evil threads requesting to allocate
+ the object of sizes from 8 to ( 2 ^ 19).
+ The live time of objects is random (0 ~ 1000).
+ Here we let the threads that reference the objects
+ to simulate the object life time.
+*/
+
+import java.util.Random;
+
+class PopulationException extends Exception {
+ //this exception is used to signal that we've
+ //reached the end of the test
+}
+
+//the LocalRandom class is used to isolate the pseudo-random
+//number generator from other parts of the system which might
+//silently be using it.
+//This is to make sure the tests are repeatable
+
+class LocalRandom {
+ public static Random rGen = null;
+
+ public static double random() {
+ //should fail if rGen is not initialized
+ return rGen.nextDouble();
+ }
+}
+
+class ThreadCount {
+ static int count= 0;
+ static synchronized void inc() { count++; }
+ static synchronized void dec() { count --; }
+ static synchronized int get() { return count; }
+}
+
+class Person {
+ String name;
+ int ssid;
+ int age;
+ int buf[];
+ int bufsz;
+ static int populationCount = 0;
+ static int populationLimit = 0;
+
+ Person(String n, int ssid, int age, int bufsz)
+ throws PopulationException {
+ name = n;
+ this.ssid = ssid;
+ this.age = age;
+ if ( bufsz > 0 ) {
+ this.bufsz = bufsz;
+ this.buf = new int[bufsz];
+ }
+ incPopulation();
+ if (getPopulation() > getPopulationLimit()) {
+ throw new PopulationException();
+ }
+ }
+ public static synchronized int getPopulationLimit() {
+ return populationLimit;
+ }
+ public static synchronized void setPopulationLimit(int newLimit) {
+ populationLimit = newLimit;
+ }
+ public static synchronized int getPopulation() {
+ return populationCount;
+ }
+ public static synchronized void incPopulation() {
+ populationCount ++;
+ }
+
+}
+
+// hr (humane resource) dept is using objects.
+// Put the hr thread to sleep to keep the reference to objects
+class hr extends Thread {
+ Person pp;
+ int lifetime;
+
+ hr(Person p, int l) {
+ pp = p;
+ lifetime = l;
+ }
+
+ public void run() {
+ // just sleep to emulate the life time of object referenced by p
+ try { sleep(lifetime); }
+ catch (InterruptedException e) {}
+ }
+}
+
+class Memevil extends Thread {
+ int sum;
+ int bufsz = 64;
+ boolean debug = false;
+
+ Memevil(int bufsz) {
+ sum = 0;
+ this.bufsz = bufsz;
+ }
+ /* Person object is live short, it will be garbage after
+ * control returns
+ */
+ private boolean doit() {
+ try {
+ Person p = new Person("Duke", 100, 100, bufsz);
+ hr useit = new hr(p, (int)(100*LocalRandom.random()));
+ useit.start();
+ return true;
+ }
+ catch (PopulationException e) {
+ return false;
+ }
+ catch (OutOfMemoryError e ) {
+ System.err.println(getName() + ": Out of Memory");
+ return false;
+ }
+ }
+ public void run() {
+ while ( doit() ) {
+ if ( LocalRandom.random() > 0.6668) {
+ try {
+ sleep(10); // to be nice
+ }
+ catch (InterruptedException e) {
+ }
+ }
+ Thread.yield();
+ }
+ //we've reached the population limit, so we're exiting the thread
+ ThreadCount.dec();
+ }
+}
+
+class Escaper extends Thread {
+ public void run() {
+ while ( ThreadCount.get() > 0 ) {
+ int buf[] = new int[32];
+ {
+ yield();
+ }
+ }
+ }
+}
+
+public class gctest02 {
+ public static void main(String args[] ) {
+ int bufsz = 8;
+ int peopleLimit = 1000;
+ long randomSeed = System.currentTimeMillis();
+ Memevil me=null;
+ if (args.length > 0)
+ {
+ try
+ {
+ peopleLimit = new Integer(args[0]).intValue();
+ }
+ catch (NumberFormatException e)
+ {
+ throw new TestBug(
+ "Bad input to gctest02. Expected integer, got: ->"
+ + args[0] + "<-", e);
+ }
+ }
+
+ if (args.length == 2)
+ {
+ try
+ {
+ randomSeed = new Long(args[1]).longValue();
+ }
+ catch (NumberFormatException e)
+ {
+ throw new TestBug(
+ "Bad input to gctest02. Expected long, got: ->"
+ + args[0] + "<-", e);
+ }
+ }
+ Person.setPopulationLimit(peopleLimit);
+ System.out.println("Seed value: " + randomSeed);
+ for (int ii=0; ii<40; ii++) {
+ bufsz = 8;
+ LocalRandom.rGen = new Random(randomSeed);
+ Person.populationCount = 0;
+ Escaper you = new Escaper();
+ you.setName("Escaper");
+ ThreadCount.inc();
+ you.start();
+ me = new Memevil(bufsz);
+ me.setName("Memevil" + bufsz);
+ bufsz = 2*bufsz;
+ me.start();
+ Thread.yield();
+ for (int i=1; i<11; i++) {
+ ThreadCount.inc();
+ me = new Memevil(bufsz);
+ me.setName("Memevil" + bufsz);
+ bufsz = 2*bufsz;
+ me.start();
+ Thread.yield();
+ }
+ try {
+ you.join();
+ }
+ catch (InterruptedException e) {
+ throw new TestFailure("InterruptedException in gctest2.main()");
+ }
+ for (int i=1; i<11; i++) {
+ try { me.join(); }
+ catch (InterruptedException e) {
+ throw new TestFailure("InterruptedException in gctest2.main()");
+ }
+ }
+ }
+ System.out.println("Test passed.");
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/Tree.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/Tree.java
new file mode 100644
index 0000000..33303f6
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/Tree.java
@@ -0,0 +1,404 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package gc.gctests.gctest03;
+
+class DataNodeException extends Exception
+{
+}
+
+
+class DataNode {
+ int key;
+ int buf[];
+ static int dataNodeCount = 0;
+ static int dataNodeLimit;
+
+ static synchronized void incDataNodeCount()
+ {
+ dataNodeCount++;
+ }
+
+ static synchronized int getDataNodeCount()
+ {
+ return dataNodeCount;
+ }
+
+ static synchronized void setDataNodeLimit(int newLimit)
+ {
+ dataNodeLimit = newLimit;
+ }
+
+ static synchronized int getDataNodeLimit()
+ {
+ return dataNodeLimit;
+ }
+
+ static synchronized void clearDataNodeCount()
+ {
+ dataNodeCount = 0;
+ }
+ DataNode(int key) throws DataNodeException
+ {
+
+ incDataNodeCount();
+ if (getDataNodeCount() > getDataNodeLimit())
+ {
+ throw (new DataNodeException());
+ }
+
+ this.key = key;
+ try {
+ buf = new int[key];
+ }
+ catch ( OutOfMemoryError e )
+ {
+ System.out.println(Thread.currentThread().getName() + " : outofmemory");
+ }
+ }
+
+ public void print()
+ {
+ System.out.println(key);
+ }
+
+ public boolean equals(DataNode d)
+ {
+ int k = d.getkey();
+
+ return ( key == k);
+ }
+
+ public boolean large(DataNode d)
+ {
+ int k = d.getkey();
+
+ return ( key > k);
+ }
+
+ public boolean less(DataNode d)
+
+ {
+ int k = d.getkey();
+
+ return ( key < k);
+ }
+
+ public int getkey()
+ { return key; }
+}
+
+
+class TreeNode {
+ DataNode data;
+ TreeNode parent;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode(DataNode key)
+ {
+ this.data = key;
+ parent = null;
+ left = null;
+ right = null;
+ }
+
+ public void print()
+ {
+ data.print();
+ }
+
+ public TreeNode getleft()
+ {
+ return left;
+ }
+
+ public TreeNode getright()
+ {
+ return right;
+ }
+
+ public TreeNode getparent()
+ {
+ return parent;
+ }
+
+ public synchronized void setleft(TreeNode left)
+ {
+ this.left = left;
+ }
+
+ public synchronized void setright(TreeNode right)
+ {
+ this.right = right;
+ }
+
+ public synchronized void setparent(TreeNode parent)
+ {
+ this.parent = parent;
+ }
+
+ public DataNode getData()
+ {
+ return data;
+ }
+
+ // print it out in order of a large one first
+ public void sprint()
+ {
+ //print itself
+ if ( left != null ) left.sprint();
+ System.out.println(data.getkey());
+ if ( right != null ) right.sprint();
+ }
+
+ // print it out in order of a small one first
+ public void lprint()
+ {
+ if (right != null ) right.lprint();
+ System.out.println(data.getkey());
+ if ( left != null ) left.lprint();
+ }
+
+ public synchronized TreeNode duplicate()
+ {
+ TreeNode tp = new TreeNode(data);
+
+ if ( left != null )
+ {
+ tp.left = left.duplicate();
+ }
+ if ( right != null )
+ {
+ tp.right = right.duplicate();
+ }
+ return tp;
+ }
+
+ public TreeNode search(DataNode d)
+ {
+ TreeNode tp = this;
+ DataNode k;
+
+ while ( tp != null )
+ {
+ k = tp.getData();
+ if ( k.equals(d) )
+ {
+ return tp;
+ }
+ else
+ if ( d.large(k) )
+ tp = tp.getright();
+ else
+ tp = tp.getleft();
+ }
+ return null;
+ }
+
+ public synchronized void insert(TreeNode t)
+ {
+ DataNode d = t.getData();
+
+ TreeNode tp = this;
+ TreeNode tp1 = tp;
+ DataNode d0;
+
+ while ( true )
+ {
+ d0 = tp.getData();
+
+ if ( d.large(d0) )
+ {
+ tp1 = tp;
+ tp = tp.getright();
+ if ( tp == null )
+ {
+ tp1.setright(t);
+ t.setparent(tp1);
+ break;
+ }
+ }
+ else
+ {
+ tp1 = tp;
+ tp = tp.getleft();
+ if (tp == null )
+ {
+ tp1.setleft(t);
+ t.setparent(tp1);
+ break;
+ }
+ }
+ }
+
+ }
+
+
+}
+
+
+class Tree {
+ TreeNode root = null;
+
+ Tree()
+ {
+ root = null;
+ }
+
+ Tree(TreeNode root)
+ {
+ this.root = root;
+ }
+
+ public synchronized void insert(TreeNode t)
+ {
+ if ( root == null )
+ {
+ root = t;
+ return;
+ }
+
+ root.insert(t);
+ }
+
+
+ public void sort1()
+ {
+ root.sprint();
+ }
+
+ public void sort2()
+ {
+ root.lprint();
+ }
+
+ public TreeNode search(DataNode d)
+ {
+ if ( root == null ) return null;
+ else return root.search(d);
+ }
+
+ public synchronized boolean remove(DataNode d)
+ {
+ if ( root == null ) return false;
+
+ TreeNode t = root.search(d);
+
+ // data is not in a heap
+ if ( t == null ) return false;
+
+/*
+ if ( d.equals(t.getData()) == false )
+ {
+ System.out.println("failed");
+ return false;
+ }
+ */
+
+ TreeNode p = t.getparent();
+ TreeNode l = t.getleft();
+ TreeNode r = t.getright();
+
+ // the removed node is a root
+ if ( p == null )
+ {
+ if ( l == null && r != null )
+ {
+ r.setparent(null);
+ root = r;
+ return true;
+ }
+ if ( l != null && r == null )
+ {
+ l.setparent(null);
+ root = l;
+ return true;
+ }
+ if ( l == null && r == null )
+ {
+ root = null;
+ return true;
+ }
+
+ if ( l != null && r != null )
+ {
+ r.setparent(null);
+ r.insert(l);
+ root = r;
+ return true;
+ }
+ }
+
+ // a leaf
+ if ( r == null && l == null )
+ {
+ if ( p.getright() == t )
+ {
+ /* right child */
+ p.setright(null);
+ }
+ else
+ p.setleft(null);
+ return true;
+ }
+
+ // a node without left child
+ if ( r != null && l == null )
+ {
+ r.setparent(p);
+ if ( t == p.getright() ) p.setright(r);
+ if ( t == p.getleft() ) p.setleft(r);
+ return true;
+ }
+
+ if ( r == null && l != null )
+ {
+ l.setparent(p);
+ if ( t == p.getright() ) p.setright(l);
+ if ( t == p.getleft() ) p.setleft(l);
+ return true;
+ }
+
+ // a node with two children
+ r.insert(l);
+ r.setparent(p);
+ if ( t == p.getright() ) p.setright(r);
+ if ( t == p.getleft() ) p.setleft(r);
+ return true;
+ }
+
+ public synchronized Tree copy()
+ {
+ if ( root == null ) return null;
+
+ return(new Tree(root.duplicate()));
+ }
+
+ public synchronized boolean isempty()
+ {
+ return ( root == null );
+ }
+
+
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/appthread.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/appthread.java
new file mode 100644
index 0000000..ba3ec14
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/appthread.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package gc.gctests.gctest03;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+
+//import Tree;
+//import LocalRandom;
+
+// remove the nodes whose key is the multiple of key from the tree
+class Redthread extends Thread {
+ Tree optree;
+ int key;
+
+ Redthread(Tree tr, int k)
+ {
+ optree = tr;
+ key = k;
+ }
+
+ public void run() {
+ int maxsz = (1024 * 64); // 64k
+ int i = 1;
+ int sz;
+
+ sz = 1;
+
+ while ( optree.isempty() == false)
+ {
+ DataNode d;
+// System.out.println(getName() + i);
+// sz = (key * i) % maxsz;
+ try
+ {
+ d = new DataNode(sz);
+ }
+ catch (DataNodeException e)
+ {
+//System.out.println(getName() + " exiting");
+ return;
+ }
+ if (optree.remove(d))
+// System.out.println(getName() + " removes " + sz);
+ i++;
+ try
+ {
+ sleep(3);
+ }
+ catch(InterruptedException e) {}
+
+// optree.sort1();
+ sz++;
+ }
+ }
+}
+
+// add the nodes whose key is the multiple of key from the tree
+class Bluethread extends Thread {
+ Tree optree;
+ int key;
+ private int loopcount = 0;
+
+ Bluethread(Tree tr, int k)
+ {
+ optree = tr;
+ key = k;
+ }
+
+ public void setloop(int n)
+ {
+ loopcount = n;
+ }
+
+ public void run()
+ {
+ int i;
+ int sz;
+ int maxsz = (1024 * 64); // 64k
+
+ i = 1; sz = 0;
+ while ( (loopcount== 0) ? true : (i < loopcount) )
+ {
+ sz = (key * i) % maxsz;
+ DataNode d;
+
+ try
+ {
+ d= new DataNode(sz);
+ }
+ catch (DataNodeException e)
+ {
+//System.out.println(getName() + " exiting");
+ return;
+ }
+
+ TreeNode t = new TreeNode(d);
+ // System.out.println(getName() + i);
+ if ( optree.search(d) == null )
+ {
+ optree.insert(t);
+// System.out.println(getName() + " insert " + sz);
+ }
+ //optree.sort1();
+ i++;
+ try
+ {
+ sleep(5);
+ }
+ catch(InterruptedException e) {}
+ }
+ }
+}
+
+class Yellowthread extends Thread {
+ Tree optree;
+ int key; // data to be moved from the tree
+
+ Yellowthread(Tree tr, int k)
+ {
+ optree = tr;
+ key = k;
+ }
+
+ // remove the nodes whose key is the multiple of key from the tree
+ public void run()
+ {
+ int i = 1;
+ while ( true )
+ {
+ DataNode d;
+ try
+ {
+ d = new DataNode(key*i);
+ }
+ catch (DataNodeException e)
+ {
+//System.out.println(getName() + " exiting");
+ return;
+ }
+ TreeNode t = optree.search(d);
+/* if ( t != null ) System.out.println(getName() + ": search = " +
+ * (t.getData()).getkey());
+ */
+ i++;
+ if ( LocalRandom.random() < 0.668 )
+ {
+ try
+ {
+ sleep(5);
+ }
+ catch(InterruptedException e) {}
+ }
+ }
+ }
+}
+
+public class appthread {
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/gctest03.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/gctest03.java
new file mode 100644
index 0000000..1ab6011
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/gctest03.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* stress testing
+ Redthreads keep removing new nodes from a binary sort tree(
+ all nodes of its left subtree is less than itself, all nodes
+ of its right subtree is large than itself).
+ Bluethreads keep adding nodes into the binary sort tree.
+ YellowThreads search the binary sort tree.
+ The nodes removed from the tree will become garbages immediately
+ Create 10 Redthreads and 10 Bluethreads to manipulate the
+ the same binary tree involving excessive memory allocation
+ to test if memory management module and gc() crash.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/gctest03.
+ * VM Testbase keywords: [gc]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @compile Tree.java appthread.java
+ * @run main/othervm gc.gctests.gctest03.gctest03 10000
+ */
+
+package gc.gctests.gctest03;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.TestFailure;
+import nsk.share.TestBug;
+
+//import Tree;
+//import Redthread;
+//import Bluethread;
+//import LocalRandom;
+import java.util.Random;
+
+public class gctest03 extends TestBase {
+ private String[] args;
+
+ public gctest03(String[] args) {
+ this.args = args;
+ }
+
+ public void run() {
+ int i = 1;
+ int dataNodeLimit = 100000;
+
+ if (args.length > 0) {
+ try {
+ dataNodeLimit = new Integer(args[0]).intValue();
+ } catch (NumberFormatException e) {
+ throw new TestBug("Bad input to gctest03. Expected integer, " +
+ " got: ->" + args[0] + "<-", e);
+ }
+ }
+
+ for (int j = 0; j < 10; j++) {
+ DataNode.setDataNodeLimit(dataNodeLimit);
+ DataNode.clearDataNodeCount();
+
+ Tree tr = new Tree();
+ for (i =2; i < 100; i++) {
+ try {
+ DataNode d = new DataNode(i);
+ TreeNode t = new TreeNode(d);
+ tr.insert(t);
+ } catch (DataNodeException e) {
+ throw new TestFailure("DataNodeException caught in gctest03.main()", e);
+ }
+ }
+
+ int sz = 10;
+
+ //create 10 threads adding data into binary tree.
+ // each thread only adds the multiple of its key
+ //(1, 2, 3, 4, 5, 6, 7, 8, 9 , 10). No duplication
+
+ Redthread rth[] = new Redthread[sz];
+
+ for(i=0; i < sz; i++) {
+ rth[i] = new Redthread(tr, i+1);
+ rth[i].setName("Redthread" + i);
+ rth[i].start();
+ }
+
+ //create 10 threads removing data from the tree.
+
+ Bluethread bth[] = new Bluethread[sz];
+
+ for(i=0; i < sz; i++) {
+ bth[i] = new Bluethread(tr, i+1);
+ bth[i].setName("Bluethread" + i);
+ bth[i].start();
+ }
+
+
+ //create 10 threads inquiring data from the tree
+
+ Yellowthread yth[] = new Yellowthread[sz];
+ for(i=0; i < sz; i++) {
+ yth[i] = new Yellowthread(tr, i+1);
+ yth[i].setName("Yellowthread" + i);
+ yth[i].start();
+ }
+
+ for (i = 0; i < sz; i++) {
+ try {
+ rth[i].join();
+ bth[i].join();
+ yth[i].join();
+ } catch (InterruptedException e) {
+ System.err.println("Error joining with threads in gctest03.main()");
+ System.err.println("Loop count: " + i);
+ }
+ }
+ }
+
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new gctest03(args), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest04/gctest04.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest04/gctest04.java
new file mode 100644
index 0000000..65bbaf9
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest04/gctest04.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/gctest04.
+ * VM Testbase keywords: [gc]
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @compile reqgen.java
+ * @run main/othervm gc.gctests.gctest04.gctest04
+ */
+
+package gc.gctests.gctest04;
+
+import nsk.share.test.*;
+import nsk.share.TestFailure;
+//gctest04.java
+
+//import queue;
+//import LocalRandom;
+import java.util.Random;
+import nsk.share.TestBug;
+import nsk.share.TestFailure;
+
+
+// small objects ( 8 ~ 32k), short live time ( 5 ~ 10 ms)
+public class gctest04 {
+ public static void main(String args[] )
+ {
+ int queueLimit = 1000;
+ long randomSeed = System.currentTimeMillis();
+
+ if (args.length > 0)
+ {
+ try
+ {
+ queueLimit = new Integer(args[0]).intValue();
+ }
+ catch (NumberFormatException e)
+ {
+ throw new TestBug("Bad input to gctest04. Expected integer, " +
+ " got: ->" + args[0] + "<-", e);
+ }
+ }
+
+ if (args.length == 2)
+ {
+ try
+ {
+ randomSeed = new Long(args[1]).longValue();
+ }
+ catch (NumberFormatException e)
+ {
+ throw new TestFailure("Bad input to gctest04. Expected long, got: ->" +
+ args[0] + "<-", e);
+ }
+ }
+
+ System.out.println("Seed value: " + randomSeed);
+
+
+
+ queue requestque = new queue(queueLimit);
+ reqgen gen = new reqgen(requestque, 5);
+ gen.setsize(8, 32*1024);
+ gen.setlive(5, 10);
+
+
+ reqdisp disp = new reqdisp(requestque);
+ gen.start();
+ disp.start();
+
+ try
+ {
+ gen.join();
+ System.out.println("Joined with gen thread");
+ disp.join();
+ System.out.println("Joined with disp thread");
+ }
+ catch (InterruptedException e)
+ {
+ System.err.println("InterruptedException in gctest04.main()");
+ }
+ System.out.println("Test passed.");
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest04/reqgen.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest04/reqgen.java
new file mode 100644
index 0000000..0f4de34
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest04/reqgen.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package gc.gctests.gctest04;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+
+//reqgen.java
+
+/* stress testing
+ reqgen is a subtype of Thread which generates
+ request to allocate small objects ( 8 ~ 32k), short live time ( 5 ~ 10 ms)
+ reqdisp is a subtype of Thread which dispatches request
+ and create a livethread object to allocate the requested memory
+ and simulate its life time.
+ */
+
+class bufreq
+{
+ int bufsz; // memory size
+ int life; // live time of the object
+ bufreq next;
+
+ bufreq(int bufsz, int t)
+ {
+ this.bufsz = bufsz;
+ this.life = t;
+ this.next = null;
+ }
+
+ public void setnext(bufreq b)
+ {
+ next = b;
+ }
+
+ public bufreq getnext()
+ {
+ return next;
+ }
+
+ public int getsize()
+ {
+ return bufsz;
+ }
+
+ public int livetime()
+ {
+ return life;
+ }
+}
+
+class queue
+{
+ bufreq head;
+ bufreq tail;
+ int limit;
+ int count;
+
+ queue(int newLimit)
+ {
+ head = null;
+ tail = null;
+ limit = newLimit;
+ count = 0;
+ }
+
+ public boolean okToContinue()
+ {
+ return (count < limit);
+ }
+
+ public synchronized void append(bufreq b)
+ {
+ count++;
+ if ( tail == null ) // head must be null too
+ {
+ head = tail = b;
+ return;
+ }
+ tail.setnext(b);
+ tail = b;
+ }
+
+ public synchronized bufreq remove()
+ {
+ if ( head == null ) return null;
+ bufreq buf = head;
+ head = head.getnext();
+ if ( head == null ) // only one element in the queue
+ {
+ tail = head = null;
+ }
+ return buf;
+ }
+}
+
+class reqgen extends Thread {
+ queue req;
+ int maxsz;
+ int minsz;
+ int maxlive;
+ int minlive;
+ int amda;
+
+ reqgen(queue req, int t)
+ {
+ this.req = req;
+ amda = t;
+ }
+
+ public void setsize(int s1, int s2)
+ {
+ maxsz = s2;
+ minsz = s1;
+ }
+
+ public void setlive(int t1, int t2)
+ {
+ maxlive = t2;
+ minlive = t1;
+ }
+
+ public void run()
+ {
+ bufreq buf;
+ int sz;
+ int t;
+
+ sz = minsz;
+ t = minlive;
+ while ( req.okToContinue() )
+ {
+ buf = new bufreq(sz, t);
+
+ sz = ( 2*sz);
+
+ if ( sz > maxsz)
+ {
+ sz = minsz;
+ }
+
+ t = ( 2 * t );
+ if ( t > maxlive)
+ {
+ t = minlive;
+ }
+
+ req.append(buf);
+
+ try
+ {
+ sleep(amda);
+ }
+ catch(InterruptedException e) {}
+ }
+ }
+
+ public bufreq nextreq()
+ {
+ return req.remove();
+ }
+
+}
+
+// buffer request dispatcher and allocator
+class reqdisp extends Thread {
+ queue req;
+
+ reqdisp(queue q )
+ {
+ req = q;
+ }
+
+ public void run()
+ {
+ bufreq r;
+ livethread lt;
+
+ while ( req.okToContinue() )
+ {
+ r = req.remove();
+ if ( r != null )
+ {
+ lt = new livethread(r);
+ lt.start();
+ }
+ // simulate the interarrival time
+ try
+ {
+ sleep((int)(LocalRandom.random() * 20));
+ }
+ catch (InterruptedException e) {}
+ }
+ }
+
+
+}
+
+class livethread extends Thread {
+ bufreq req;
+
+ livethread(bufreq r)
+ {
+ req = r;
+ }
+
+ public void run()
+ {
+ int buf[];
+
+ buf = new int[req.getsize()];
+
+ // simulate the life time of the created object
+ // if live time is 0, that means forever
+ if ( req.livetime() == 0 )
+ {
+ while ( true )
+ {
+ try
+ {
+ sleep(10000);
+ }
+ catch (InterruptedException e) {}
+ }
+ }
+ else
+ {
+ try
+ {
+ sleep(req.livetime());
+ }
+ catch (InterruptedException e) {}
+
+ }
+ // live object is outdated, should be GC'ed
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.c
new file mode 100644
index 0000000..6d04847
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/libmallocWithGC1.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2005, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <jni.h>
+#include <stdlib.h>
+#include <time.h>
+
+JNIEXPORT void JNICALL Java_gc_gctests_mallocWithGC1_mallocWithGC1_getMallocLock01
+(JNIEnv *env, jobject obj) {
+ char *c_ptr;
+ time_t current_time, old_time;
+
+ old_time = time(NULL);
+ current_time = 0;
+
+ while (current_time - old_time < 180) {
+ c_ptr = (char *) malloc(1);
+ free(c_ptr);
+ current_time = time(NULL);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/mallocWithGC1.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/mallocWithGC1.java
new file mode 100644
index 0000000..ff1a0a3
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/mallocWithGC1.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/mallocWithGC1.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * LD_LIBRARY PATH must include "$TESTBASE/src/misc/gc/utils/lib/sparc(or i386)"
+ * while running these tests. The native code for all the mallocWithGC* tests
+ * has been bunched up into a single .so.
+ * In this test, 2 threads are created, one thread(javaHeapEater)
+ * creates garbage by nulling out the elements of a vector, which formerly
+ * held points to circular linked lists. These elements are again repopulated
+ * with new linked lists. The second thread invokes a native function
+ * that continually mallocs and frees one byte of memory for 3 minutes
+ * a hold on a malloc lock.
+ * The idea here is to see if the vm deadlocks (if it does, it is ofcourse
+ * a failure ). This test was created because of the following problem
+ * that the vm used to have :
+ * "The malloc/GC deadlock problem is that a gc may suspend a thread (in native
+ * or VM code) that is in the middle of a malloc, so it has the "malloc" lock.
+ * GC may want to do a malloc, but it can't get the lock, so it deadlocks. "
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm/native/timeout=300 gc.gctests.mallocWithGC1.mallocWithGC1
+ */
+
+package gc.gctests.mallocWithGC1;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.TestFailure;
+import java.util.Vector;
+
+public class mallocWithGC1 implements Test {
+ private int objectSize = 100;
+
+ static {
+ System.loadLibrary("mallocWithGC1");
+ }
+
+ public native void getMallocLock01();
+
+ class javaHeapEater extends Thread {
+ private Vector v;
+
+ public javaHeapEater(Vector v) {
+ this.v = v;
+ }
+
+ public void run() throws OutOfMemoryError {
+ int gc_count;
+
+ for(int i = 0; i < 5 ; i++)
+ v.addElement(buildCircularLinkedList());
+ gc_count = 0;
+ while( gc_count < 10 ) {
+
+ for(int i = 0; i < 5 ; i++)
+ v.setElementAt(null, i);
+
+ for(int i = 0; i < 5 ; i++)
+ v.setElementAt(buildCircularLinkedList(),i);
+
+ gc_count++;
+ System.out.println("Finished iteration # " + gc_count);
+ }
+ }
+ }
+
+ class cHeapEater extends Thread{
+ public void run() {
+ getMallocLock01();
+ }
+ }
+
+ public void run() {
+ Vector v = new Vector(5);
+ Thread tArray[] = new Thread[2];
+
+ tArray[0] = new javaHeapEater(v);
+ tArray[1] = new cHeapEater();
+
+ try {
+ for(int i = 0; i < tArray.length ; i++ )
+ tArray[i].start();
+ for(int i = 0; i < tArray.length ; i++ )
+ tArray[i].join();
+ } catch (Exception e) {
+ throw new TestFailure("Test Failed.", e);
+ }
+ System.out.println("Test Passed.");
+ }
+
+ // build a circular linked list of 0.2 Meg
+
+ private CircularLinkedList buildCircularLinkedList() {
+ CircularLinkedList cl = new CircularLinkedList(objectSize);
+ for(int i = 0; i < 2000; i++)
+ cl.grow();
+ return cl;
+ }
+
+ public static void main(String args[]){
+ Tests.runTest(new mallocWithGC1(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.c
new file mode 100644
index 0000000..63ae875
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/libmallocWithGC2.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2005, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <jni.h>
+#include <stdlib.h>
+#include <time.h>
+
+JNIEXPORT void JNICALL Java_gc_gctests_mallocWithGC2_mallocWithGC2_getMallocLock02
+(JNIEnv *env, jobject obj) {
+ char *c_ptr;
+ time_t current_time, old_time;
+
+ old_time = time(NULL);
+ current_time = 0;
+
+ while (current_time - old_time < 180) {
+ c_ptr = (char *) malloc(1);
+ free(c_ptr);
+ current_time = time(NULL);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/mallocWithGC2.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/mallocWithGC2.java
new file mode 100644
index 0000000..cb8eb81
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/mallocWithGC2.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/mallocWithGC2.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * LD_LIBRARY PATH must include "$TESTBASE/src/misc/gc/utils/lib/sparc(or i386)"
+ * while running these tests. The native code for all the mallocWithGC* tests
+ * has been bunched up into a single .so.
+ * In this test, 2 threads are created, one thread(javaHeapEater)
+ * creates garbage by nulling out the elements of a vector, which formerly
+ * held points to circular linked lists. These elements are again repopulated
+ * with new linked lists. The second thread invokes a native function
+ * that continually mallocs and frees one byte of memory for 3 minutes
+ * a hold on a malloc lock.
+ * The difference between mallocWithGC1 mallocWithGC2 is the way the locks
+ * are held. here the "malloc" lock is more efficiently held, not by
+ * the expiration of a timer but as long as the java heap devourer thread
+ * stays alive.
+ * The idea here is to see if the vm deadlocks (if it does, it is ofcourse
+ * a failure ). This test was created because of the following problem
+ * that the vm used to have :
+ * "The malloc/GC deadlock problem is that a gc may suspend a thread (in native
+ * or VM code) that is in the middle of a malloc, so it has the "malloc" lock.
+ * GC may want to do a malloc, but it can't get the lock, so it deadlocks. "
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm/native gc.gctests.mallocWithGC2.mallocWithGC2
+ */
+
+package gc.gctests.mallocWithGC2;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import nsk.share.TestFailure;
+import java.util.Vector;
+
+public class mallocWithGC2 extends TestBase {
+ static {
+ System.loadLibrary("mallocWithGC2");
+ }
+
+ public native void getMallocLock02();
+
+ private class javaHeapEater extends Thread {
+ private Vector v;
+
+ javaHeapEater(Vector v) {
+ this.v = v;
+ }
+
+ public void run() throws OutOfMemoryError {
+ int gc_count;
+
+ for(int i = 0; i < 10 ; i++)
+ v.addElement(buildCircularLinkedList());
+ gc_count = 0;
+ while( gc_count < 10 ) {
+
+ for(int i = 0; i < 10 ; i++)
+ v.setElementAt(null, i);
+
+ for(int i = 0; i < 10 ; i++)
+ v.setElementAt(buildCircularLinkedList(),i);
+
+ gc_count++;
+ log.info("Finished iteration # " + gc_count);
+ }
+ }
+ }
+
+
+ private class cHeapEater extends Thread{
+ public void run() {
+ getMallocLock02();
+ }
+ }
+
+ public void run() {
+ Vector v = new Vector(10);
+ Thread tArray[] = new Thread[2];
+
+ tArray[0] = new javaHeapEater(v);
+ tArray[1] = new cHeapEater();
+
+ try {
+ for(int i = 0; i < tArray.length ; i++ )
+ tArray[i].start();
+
+ tArray[0].join(); // wait for the javaHeapEater Thread to finish
+ tArray[1].stop(); // Once javaHeapEater is finished, stop the
+ // the cHeapEater thread.
+ } catch (Exception e) {
+ throw new TestFailure("Test Failed.", e);
+ }
+ log.info("Test Passed.");
+ }
+
+ // build a circular linked list of 0.2 Meg
+
+ private CircularLinkedList buildCircularLinkedList() {
+ CircularLinkedList cl;
+
+ cl = new CircularLinkedList(100);
+ for(int i = 0; i < 2000; i++)
+ cl.grow();
+ return cl;
+ }
+
+ public static void main(String args[]) {
+ Tests.runTest(new mallocWithGC2(), args);
+ }
+
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.c
new file mode 100644
index 0000000..49ae509
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/libmallocWithGC3.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2005, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <jni.h>
+#include <stdlib.h>
+#include <time.h>
+
+JNIEXPORT void JNICALL
+Java_gc_gctests_mallocWithGC3_mallocWithGC3_getMallocLock03
+(JNIEnv *env, jobject obj) {
+ char *c_ptr;
+ time_t current_time, old_time;
+
+ old_time = time(NULL);
+ current_time = 0;
+
+ while (current_time - old_time < 180) {
+ c_ptr = (char *) malloc(1);
+ free(c_ptr);
+ current_time = time(NULL);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/mallocWithGC3.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/mallocWithGC3.java
new file mode 100644
index 0000000..8bc1bdd
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/mallocWithGC3.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/mallocWithGC3.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * ********************************************************
+ * LD_LIBRARY PATH must include "$TESTBASE/src/misc/gc/utils/lib/sparc(or i386)"
+ * while running these tests. The native code for all the mallocWithGC* tests
+ * has been bunched up into a single .so.
+ * ********************************************************
+ * In this test, 2 threads are created, one thread(javaHeapEater)
+ * creates garbage by nulling out the elements of a vector, which formerly
+ * held points to circular linked lists. These elements are again repopulated
+ * with new linked lists. The second thread invokes a native function
+ * that continually mallocs and frees one byte of memory for 3 minutes
+ * a hold on a malloc lock.
+ * In this test, the GC is called synchronously while another
+ * thread contines to malloc/free in a loop.
+ * The idea here is to see if the vm deadlocks (if it does, it is ofcourse
+ * a failure ). This test was created because of the following problem
+ * that the vm used to have :
+ * "The malloc/GC deadlock problem is that a gc may suspend a thread (in native
+ * or VM code) that is in the middle of a malloc, so it has the "malloc" lock.
+ * GC may want to do a malloc, but it can't get the lock, so it deadlocks. "
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm/native/timeout=300 gc.gctests.mallocWithGC3.mallocWithGC3
+ */
+
+package gc.gctests.mallocWithGC3;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import java.util.Vector;
+
+public class mallocWithGC3 extends TestBase {
+ static {
+ System.loadLibrary("mallocWithGC3");
+ }
+
+ public native void getMallocLock03();
+
+ private class javaHeapEater extends Thread {
+ private Vector v;
+
+ public javaHeapEater(Vector v) {
+ this.v = v;
+ }
+
+ public void run() throws OutOfMemoryError {
+ int gc_count;
+
+ for(int i = 0; i < 5 ; i++)
+ v.addElement(buildCircularLinkedList());
+ gc_count = 0;
+
+ while( gc_count < 10 ) {
+ for (int i = 0; i < 5 ; i++)
+ v.setElementAt(null, i);
+
+ System.gc(); // Forcibly call GC.
+
+ for (int i = 0; i < 5 ; i++)
+ v.setElementAt(buildCircularLinkedList(),i);
+
+ gc_count++;
+ log.info("Finished iteration # " + gc_count);
+ }
+ }
+ }
+
+ private class cHeapEater extends Thread {
+ public void run() {
+ getMallocLock03();
+ }
+ }
+
+ public void run() {
+ Vector v = new Vector(5);
+ Thread tArray[] = new Thread[2];
+
+ tArray[0] = new javaHeapEater(v);
+ tArray[1] = new cHeapEater();
+
+
+ try {
+ for(int i = 0; i < tArray.length ; i++ )
+ tArray[i].start();
+ for(int i = 0; i < tArray.length ; i++ )
+ tArray[i].join();
+ } catch (Exception e) {
+ setFailed(true);
+ }
+ }
+
+ // build a circular linked list of 0.4 Meg
+ private CircularLinkedList buildCircularLinkedList() {
+ CircularLinkedList cl;
+
+ cl = new CircularLinkedList(100);
+ for(int i = 0; i < 2000; i++)
+ cl.grow();
+ return cl;
+ }
+
+ public static void main(String args[]){
+ Tests.runTest(new mallocWithGC3(), args);
+ }
+
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.c
new file mode 100644
index 0000000..045c5ab
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/libnativeGC01.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2005, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <jni.h>
+#include <stdio.h>
+/*
+ * A C function that takes a reference to java Object( a circular Linked list)
+ * and utilizes this reference to do a java method callback to determine the
+ * number of elements in the linked list
+ */
+JNIEXPORT jint JNICALL
+Java_gc_gctests_nativeGC01_nativeGC01_nativeMethod01
+(JNIEnv *env, jobject obj, jobject linked_list) {
+ jclass cls, clss;
+ jmethodID mid, mid2;
+ int elementCount;
+
+ /* Before doing anything force a GC by
+ invoking a callback where System.gc() is called
+ */
+ cls = (*env)->GetObjectClass(env, obj);
+ mid = (*env)->GetMethodID(env, cls, "callbackGC", "()V");
+ if (mid == 0) {
+ printf("couldnt locate method callbackGC()");
+ return -1;
+ }
+ (*env)->CallVoidMethod(env,obj,mid);
+
+ /* Now that a GC has been done, invoke the callback
+ that counts the number of elements in the
+ circular linked list
+ */
+
+ clss = (*env)->GetObjectClass(env, linked_list);
+ mid2 = (*env)->GetMethodID(env, clss, "getLength", "()I" );
+ if (mid2 == 0) {
+ printf("couldnt locate method getLength()");
+ return -1;
+ }
+ elementCount = (*env)->CallIntMethod(env, linked_list, mid2);
+ return elementCount;
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/nativeGC01.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/nativeGC01.java
new file mode 100644
index 0000000..e207c52
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC01/nativeGC01.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/nativeGC01.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * This test creates a large linked list of 10,000 elements. After creating the
+ * linked list a native function is called. The native function calls a java
+ * method that removes all java references to the linked list and forces a garbage
+ * collection. The only live reference to the linked list if on the C stack . As
+ * there is a live reference on the C stack, the linked list should not be garbage collected.
+ * After forcing a garbage collection, the native code calls another java method
+ * that traverses the linked list to verify that the linked list has not
+ * been garbage collected.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm/native gc.gctests.nativeGC01.nativeGC01
+ */
+
+package gc.gctests.nativeGC01;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import java.util.Vector;
+
+public class nativeGC01 extends TestBase {
+ private CircularLinkedList cl;
+
+ public native int nativeMethod01(CircularLinkedList cl);
+
+ // This method is a callback that is invoked by a by the native
+ // function "nativeMethod()" before the bowels of the nativeMethod()
+ // function are executed.
+
+ public void callbackGC() {
+ cl = null;
+ System.gc();
+ }
+
+ public void run() {
+ int elementCount;
+ cl = buildBigCircularLinkedList(); // build a 2 meg Circular Linked list.
+ // Determine number of elements in the linked list with a native method
+ // after GC has been done.
+
+ try {
+ elementCount = nativeMethod01(cl);
+
+ if (elementCount == 10000) {
+ log.info("Test Passed");
+ } else {
+ log.info("Test Failed");
+ setFailed(true);
+ }
+ } catch (Exception e ) {
+ log.info(e);
+ log.info("broken test");
+ setFailed(true);
+ }
+
+ }
+
+ // build a circular linked list of 0.4 Meg
+ private CircularLinkedList buildBigCircularLinkedList() {
+ CircularLinkedList cl = new CircularLinkedList(100);
+ for(int i = 0; i < 10000; i++)
+ cl.grow();
+ return cl;
+ }
+
+ static {
+ System.loadLibrary("nativeGC01");
+ }
+
+ public static void main(String args[]){
+ Tests.runTest(new nativeGC01(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.c
new file mode 100644
index 0000000..a29ae70
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/libnativeGC02.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2005, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <jni.h>
+#include <stdio.h>
+
+/* A C function that takes a reference to java Object( a circular Linked list)
+ and utilizes this reference to do a java method callback to determine the
+ number of elements in the linked list */
+JNIEXPORT jint JNICALL
+Java_gc_gctests_nativeGC02_nativeGC02_nativeMethod02
+(JNIEnv *env, jobject obj, jobject linked_list) {
+ jclass cls, clss;
+ jmethodID mid, mid2;
+ jfieldID fid;
+ jobject llist;
+ int elementCount;
+
+ /* Store a reference to the linked list in the C stack */
+
+ clss = (*env)->GetObjectClass(env, obj);
+ fid = (*env)->GetFieldID(env, clss, "cl", "Lnsk/share/gc/CircularLinkedList;");
+ if (fid == 0) {
+ printf("could not locate field - cl\n");
+ return -1;
+ }
+
+ llist = (*env)->GetObjectField(env, obj, fid);
+
+ /* force a GC by invoking a callback where System.gc() is called
+ */
+
+ cls = (*env)->GetObjectClass(env, obj);
+ mid = (*env)->GetMethodID(env, cls, "callbackGC", "()V");
+ if (mid == 0){
+ printf("couldnt locate method callbackGC()\n");
+ return -1;
+ }
+ (*env)->CallVoidMethod(env,obj,mid);
+
+ /* Now that a GC has been done, invoke the callback
+ that counts the number of elements in the
+ circular linked list
+ */
+
+ clss = (*env)->GetObjectClass(env, linked_list);
+ mid2 = (*env)->GetMethodID(env, clss, "getLength", "(Lnsk/share/gc/CircularLinkedList;)I" );
+ if (mid2 == 0 ){
+ printf("couldnt locate method getLength(CircularLinkedList)\n");
+ return -1;
+ }
+ elementCount = (*env)->CallIntMethod(env, linked_list, mid2, llist);
+ return elementCount;
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/nativeGC02.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/nativeGC02.java
new file mode 100644
index 0000000..14a2942
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC02/nativeGC02.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/nativeGC02.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * This test is a variation of nativeGC01.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm/native gc.gctests.nativeGC02.nativeGC02
+ */
+
+package gc.gctests.nativeGC02;
+
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import java.util.Vector;
+
+public class nativeGC02 extends GCTestBase {
+ private int count = 10000;
+ CircularLinkedList cl;
+
+ public native int nativeMethod02(CircularLinkedList cl);
+
+ // This method is a callback that is invoked by a by the native
+ // function "nativeMethod()" before the bowels of the nativeMethod()
+ // function are executed.
+
+ public void callbackGC() {
+ cl = null;
+ System.gc();
+ }
+
+ public void run() {
+ int elementCount;
+
+ cl = buildBigCircularLinkedList(); // build a 2 meg Circular Linked list.
+ // Determine number of elements in the linked list with a native method
+ // after GC has been done.
+ try {
+ elementCount = nativeMethod02(cl);
+ if (elementCount == count) {
+ log.info("Test Passed");
+ } else {
+ log.info("Test Failed");
+ setFailed(true);
+ }
+ } catch (Exception e) {
+ log.info(e.toString());
+ log.info("broken test");
+ setFailed(true);
+ }
+ }
+
+ // build a circular linked list of 0.4 Meg
+ private CircularLinkedList buildBigCircularLinkedList() {
+ CircularLinkedList cl = new CircularLinkedList(100);
+ for (int i = 0; i < count; i++)
+ cl.grow();
+ return cl;
+ }
+
+ static {
+ System.loadLibrary("nativeGC02");
+ }
+
+ public static void main(String args[]){
+ Tests.runTest(new nativeGC02(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.c
new file mode 100644
index 0000000..fbe41e3
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/libnativeGC03.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2005, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <jni.h>
+
+JNIEXPORT void JNICALL
+Java_gc_gctests_nativeGC03_nativeGC03_nativeMethod03
+(JNIEnv *env, jobject obj, jobjectArray listHolder) {
+ jsize len;
+ int i, count;
+ jmethodID mid;
+ jclass clss;
+
+ len = (*env)->GetArrayLength(env, listHolder);
+ i = 0;
+ count = 0;
+ /*Trash all the linked lists */
+ while (count < 10) {
+ while (i < len) {
+ (*env)->SetObjectArrayElement(env, listHolder, i, NULL);
+ i++;
+ }
+
+ /* Invoke a callback that will refill the array */
+
+ clss = (*env)->GetObjectClass(env, obj);
+ mid = (*env)->GetMethodID(env, clss, "fillArray", "()V");
+ if (mid == 0) {
+ return;
+ }
+ (*env)->CallVoidMethod(env, obj, mid);
+ count++;
+ }
+
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/nativeGC03.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/nativeGC03.java
new file mode 100644
index 0000000..28c2412
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC03/nativeGC03.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/nativeGC03.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * The idea behind this test is that an array container pointers
+ * to circular linked lists is created in nativeGC03.java.
+ * Once the linkedlists are all created, a native function is called
+ * that trashes all the linked list by setting the elements of the
+ * array to null. After creating the garbage, a callback function
+ * is invoked that refills the array with new linked lists.
+ * The is goes on 10 times. The test passes if no OutofMemory exception
+ * is thrown.
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm/native gc.gctests.nativeGC03.nativeGC03
+ */
+
+package gc.gctests.nativeGC03;
+
+import nsk.share.TestFailure;
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import java.util.Vector;
+
+public class nativeGC03 extends GCTestBase {
+ private Object[] listHolder;
+
+ public native void nativeMethod03(Object[] listHolder);
+
+ // This method is a callback that is invoked by a by the native
+ // function "nativeMethod()" before the bowels of the nativeMethod()
+ // function are executed.
+ // build an array of 10 circular linked lists
+ private void fillArray() {
+ int i = 0;
+ while (i < 5) {
+ listHolder[i] = buildBigCircularLinkedList();
+ i++;
+ }
+ }
+
+ public void run() {
+ listHolder = new Object[5];
+
+ // Build an array of linked lists
+
+ fillArray();
+ try {
+ nativeMethod03(listHolder);
+ } catch (OutOfMemoryError e) {
+ throw new TestFailure("Test Failed");
+ }
+ System.out.println("Test Passed");
+ }
+
+ // Builds a circular linked list of 0.4Meg
+
+ private CircularLinkedList buildBigCircularLinkedList() {
+ CircularLinkedList cl = new CircularLinkedList(100);
+ for(int i = 0; i < 10000; i++)
+ cl.grow();
+ return cl;
+ }
+
+ static {
+ System.loadLibrary("nativeGC03");
+ }
+
+ public static void main(String args[]){
+ Tests.runTest(new nativeGC03(), args);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.c b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.c
new file mode 100644
index 0000000..b46be1a
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/libnativeGC05.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2005, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <jni.h>
+#include <stdio.h>
+
+JNIEXPORT void JNICALL
+Java_gc_gctests_nativeGC05_nativeGC05_kickOffRefillers
+(JNIEnv *env, jobject obj, jobject matrix, jobject stack) {
+ jclass matrixClass, stackClass, pairClass = 0;
+ jmethodID stack_pop_mid, stack_empty_mid, matrix_repopulate_mid, pair_geti_mid, pair_getj_mid;
+ jobject pair;
+ jint i, j;
+ jboolean b;
+
+ /* Get class objects associated with the objects passed in */
+ matrixClass = (*env)->GetObjectClass(env, matrix);
+ stackClass = (*env)->GetObjectClass(env, stack);
+
+ /* GetMethodID's for the pop() and Repopulate() methods */
+ stack_pop_mid = (*env)->GetMethodID(env, stackClass, "pop", "()Ljava/lang/Object;");
+ if (stack_pop_mid == 0) {
+ printf("could not get a methodID for Stack::pop()\n");
+ return;
+ }
+ stack_empty_mid = (*env)->GetMethodID(env, stackClass, "empty", "()Z");
+ if (stack_empty_mid == 0) {
+ printf("could not get a methodID for Stack::empty()\n");
+ return;
+ }
+
+ matrix_repopulate_mid = (*env)->GetMethodID(env, matrixClass, "repopulate", "(II)V");
+ if (matrix_repopulate_mid == 0) {
+ printf("could not get a methodID for Matrix::repopulate(int, int)\n");
+ return;
+ }
+
+ /** b = stack.empty(); */
+ b = (*env)->CallBooleanMethod(env, stack, stack_empty_mid);
+ while (b == JNI_FALSE) {
+ /** pair = stack.pop() */
+ pair = (*env)->CallObjectMethod(env, stack, stack_pop_mid);
+
+ if (pairClass == 0) {
+ pairClass = (*env)->GetObjectClass(env, pair);
+ pair_geti_mid = (*env)->GetMethodID(env, pairClass, "getI", "()I");
+ if (pair_geti_mid == 0) {
+ printf("could not get a methodID for IndexPair::getI()\n");
+ return;
+ }
+ pair_getj_mid = (*env)->GetMethodID(env, pairClass, "getJ", "()I");
+ if (pair_getj_mid == 0) {
+ printf("could not get a methodID for IndexPair::getJ()\n");
+ return;
+ }
+ }
+
+ /** i = pair.getI(); */
+ i = (*env)->CallIntMethod(env, pair, pair_geti_mid);
+ /** j = pair.getJ(); */
+ j = (*env)->CallIntMethod(env, pair, pair_getj_mid);
+
+ /* matrix.repopulate(i, j); */
+ (*env)->CallVoidMethod(env, matrix, matrix_repopulate_mid, i, j);
+
+ /** b = stack.empty(); */
+ b = (*env)->CallBooleanMethod(env, stack, stack_empty_mid);
+ }
+}
diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/nativeGC05.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/nativeGC05.java
new file mode 100644
index 0000000..fd0df75
--- /dev/null
+++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/nativeGC05/nativeGC05.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2002, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/*
+ * @test
+ * @key gc
+ *
+ * @summary converted from VM Testbase gc/gctests/nativeGC05.
+ * VM Testbase keywords: [gc]
+ * VM Testbase readme:
+ * ********************************
+ * set TIMEOUT = 20
+ * *******************************
+ * This test creates a 2 dimensional matrix of (100X100)10,000 elements.
+ * Each element in this matrix houses the address of a "Cell" that
+ * occupies about 100 bytes. The total memory occupied by this structure is
+ * about 1M.
+ * Once this structure, has been built, 5 threads are let loose that
+ * randomly choose an element in this matrix and set its contents to null
+ * effectively creating 100bytes of garbage. The threads continue to act
+ * until all 5 threads combined have "nulled out" half the cells in the matrix,
+ * which amounts to 0.5Meg of garbage. The indices of each "nulled out"
+ * cell is stored in a stack. This information is later used during
+ * the refilling stage by the native function, kickOffRefiller();
+ * The native function, kickOffRefiller() refills all the lacunae in the
+ * matrix with new cells.
+ * This process of nulling out" and refilling is repeated 50 times.
+ * Every iteration produces 0.5 Meg
+ * of garbage. The maximum amount of live memory at use at any time is 1Meg.
+ * If no garbage collection takes place during any of the ten iterations,
+ * the total amount(live + garbage) of heap space consumed at the end
+ * of the program is 0.5*50 + 1 = 26Meg.
+ * The test fails if an OutOfMemory Exception is thrown.
+ * ----------------------------- --------
+ * | | | | | | | 100 |
+ * | | | | | *--|------>| bytes|
+ * | | | | | | --------
+ * -----------------------------
+ * . . . . . .
+ * . . . . . .
+ * . . . . . .
+ * .
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * ------------------------------
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * ------------------------------
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * ------------------------------
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * -----------------------------
+ *
+ * @library /vmTestbase
+ * /test/lib
+ * @run driver jdk.test.lib.FileInstaller . .
+ * @run main/othervm/native gc.gctests.nativeGC05.nativeGC05
+ */
+
+package gc.gctests.nativeGC05;
+
+import nsk.share.TestFailure;
+import nsk.share.test.*;
+import nsk.share.gc.*;
+import java.util.Stack;
+
+public class nativeGC05 extends GCTestBase {
+ private final int threadCount = 5;
+ private Stack<IndexPair> emptiedLocations = new Stack<IndexPair>();
+ private Matrix matrix = new Matrix(100, 100);
+
+ public native void kickOffRefillers(Matrix matrix, Stack s);
+
+ private class CellEmptier extends Thread {
+ public CellEmptier() {
+ }
+
+ boolean keepEmptying(){
+ int numberOfCells;
+ int matrixSize;
+
+ matrixSize = matrix.returnArrayBound();
+ numberOfCells = (matrixSize + 1) * (matrixSize + 1) ;
+ if (matrix.getCellCount() < numberOfCells/2)
+ return true;
+ else
+ return false;
+ }
+
+ public void run() {
+ int i, j, matrixSize,emptyCells;
+
+ matrixSize = matrix.returnArrayBound();
+ while (keepEmptying()) {
+ i = LocalRandom.nextInt(0, matrixSize);
+ j = LocalRandom.nextInt(0, matrixSize);
+ emptiedLocations.push(new IndexPair(i,j)); //Register empty node
+ matrix.clear(i,j);
+ }
+ }
+ }
+
+
+ private class StackDump extends Thread {
+ public StackDump() {
+ }
+
+ public void run() {
+ int emptyCells;
+
+ while (true) {
+ emptyCells = emptiedLocations.size();
+ System.out.println("Number of empty cells = " + emptyCells);
+ }
+ }
+ }
+
+
+ public void run() {
+ Thread emptierArray[] = new Thread[threadCount];
+ int count = 0;
+ int memoryReserve[] = new int[10000];
+
+ //Create 5 CellEmptier Threads. There should be about 1Meg of
+ // created garbage by the times these 5 threads return.
+
+ try {
+ while (count < 50) {
+ for (int i = 0; i < threadCount; i++)
+ emptierArray[i] = new CellEmptier();
+ for (int i = 0; i < threadCount; i++)
+ emptierArray[i].start();
+
+ // wait for "emptier" threads to finish their job
+
+ int i = 0;
+ while (i < threadCount) {
+ try {
+ emptierArray[i].join();
+ } catch(InterruptedException e) {
+ }
+ i++;
+ }
+
+ // Now start refilling.
+
+ kickOffRefillers(matrix, emptiedLocations);
+
+ // reset count of cells emptied out and start again.
+ matrix.resetCellCount();
+ count++;
+ }
+ } catch (OutOfMemoryError e) {
+ memoryReserve = null;
+ System.gc();
+ throw new TestFailure("Test Failed at " + count + "th iteration.");
+ }
+ System.out.println("Test passed.");
+ }
+
+ public static void main(String args[]) {
+ GC.runTest(new nativeGC05(), args);
+ }
+
+ static {
+ System.loadLibrary("nativeGC05");
+ }
+}