< prev index next >

test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/JumbleGC002.java

Print this page
rev 59093 : [mq]: randomness-code_vmTestbase_gc


  41  *         4. A nsk.share.gc.NonbranchyTree (number of nodes and their size depend
  42  *            on valkue returned by Runtime.maxMemory())
  43  *     As soon as the vector is filled, each thread removes half elements of it and
  44  *     then fills those places of the vector again. However, all threads use just
  45  *     about 10% of maximum amount of memory that JVM attemts to use, so
  46  *     OutOfMemoryError is treated as a failure. That means GC does not work
  47  *     quickly enough to destroy all objects that do not have references. The
  48  *     procedure of filling and cleaning of the vector is repeated for
  49  *     INTERNAL_ITERATIONS times.
  50  *
  51  * @library /vmTestbase
  52  *          /test/lib
  53  * @run driver jdk.test.lib.FileInstaller . .
  54  * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.JumbleGC002.JumbleGC002
  55  */
  56 
  57 package gc.gctests.JumbleGC002;
  58 
  59 import java.io.*;
  60 import java.util.*;
  61 import java.util.concurrent.ThreadLocalRandom;
  62 
  63 import nsk.share.*;
  64 import nsk.share.gc.*;

  65 
  66 /**
  67  * This test simply does Algorithms.eatMemory() in a loop
  68  * in multiple threads.
  69  */
  70 public class JumbleGC002 extends ThreadedGCTest {
  71 
  72     // The test should fill just about 10% of the heap
  73     final static double PART_OF_HEAP = 0.1;
  74     // Maximum number of elements in an array of primitive types
  75     final static int ARRAY_MAX_LENGTH = 10;
  76     // Internal number of iterations to create new objects and to drop
  77     // references
  78     final static int INTERNAL_ITERATIONS = 150;
  79     // Size of core for each node of a tree
  80     final static int EACH_NODE_SIZE = 1;
  81     // Number of bytes that arrays of primitive types take in the vector
  82     final static long PRIMITIVE_ARRAYS_SIZE = (long) (8 * ARRAY_MAX_LENGTH
  83             + 8 * ARRAY_MAX_LENGTH + 4 * ARRAY_MAX_LENGTH);
  84 
  85     private class Eater implements Runnable {
  86 
  87         private Vector vector;
  88         int numberOfElements;
  89         int numberOfQuarters;
  90         int id;
  91         int nodes;
  92         ThreadLocalRandom random = ThreadLocalRandom.current();
  93 
  94         public Eater(int id, int numberOfQuarters, int nodes) {
  95             this.numberOfQuarters = numberOfQuarters;
  96             numberOfElements = 4 * numberOfQuarters;
  97             this.id = id;
  98             this.nodes = nodes;
  99         }
 100 
 101         public void run() {
 102             // Make jumble in the heap!
 103             initVector();
 104             while (getExecutionController().continueExecution()) {
 105                 fillVector();
 106                 cleanVector();
 107             }
 108         }
 109 
 110         // Initialize the vector and build appropriate number of cells in it
 111         private void initVector() {
 112             vector = new Vector();
 113             for (int i = 0; i < numberOfElements; i++) {
 114                 vector.addElement(null);
 115             }
 116         }
 117 
 118         // Fill the vector. It is devided into quarters. Each quarters has an
 119         // initialized array of long and int, and uninitialized array of double.
 120         // Each array has not more than ARRAY_MAX_LENGTH elements. The fourth
 121         // element in the quarter is a NonbranchyTree.
 122         private void fillVector() {
 123             for (int i = 0; i < numberOfQuarters; i++) {
 124 
 125                 // Append initialized long[]
 126                 int length = random.nextInt(ARRAY_MAX_LENGTH);
 127                 long[] l = new long[length];
 128                 for (int j = 0; j < length; j++) {
 129                     l[j] = (long) j;
 130                 }
 131                 if (vector.elementAt(4 * i) == null) {
 132                     vector.setElementAt(l, 4 * i);
 133                 }
 134 
 135                 // Append not initialized double[]
 136                 length = random.nextInt(ARRAY_MAX_LENGTH);
 137                 double[] d = new double[length];
 138                 if (vector.elementAt(4 * i + 1) == null) {
 139                     vector.setElementAt(d, 4 * i + 1);
 140                 }
 141 
 142                 // Append initialized int[]
 143                 length = random.nextInt(ARRAY_MAX_LENGTH);
 144                 int[] n = new int[length];
 145                 for (int j = 0; j < length; j++) {
 146                     n[j] = j;
 147                 }
 148                 if (vector.elementAt(4 * i + 2) == null) {
 149                     vector.setElementAt(n, 4 * i + 2);
 150                 }
 151 
 152                 // Append a tree. Every even thread has a "bent" tree.
 153                 NonbranchyTree tree = new NonbranchyTree(nodes, 0.3f, EACH_NODE_SIZE);
 154                 if (id % 2 == 0) {
 155                     tree.bend();
 156                 }
 157                 if (vector.elementAt(4 * i + 3) == null) {
 158                     vector.setElementAt(tree, 4 * i + 3);
 159                 }
 160             }
 161         }
 162 
 163         // Drop references to half of the elements of the vector
 164         private void cleanVector() {
 165             int index = random.nextInt(numberOfElements / 2);
 166             for (int i = index; i < index + numberOfElements / 2; i++) {
 167                 vector.setElementAt(null, i);
 168             }
 169         }
 170     }
 171 
 172     protected Runnable createRunnable(int i) {
 173         // Perform calculations specific to the test
 174         long memoryForThread = (long) (Runtime.getRuntime().maxMemory() * PART_OF_HEAP / runParams.getNumberOfThreads());
 175         int numberOfQuarters;
 176 
 177         if (i == 0) {
 178             // The very first thread
 179             numberOfQuarters = 1;
 180         } else {
 181             // All other threads
 182             numberOfQuarters = 8;
 183         }
 184 
 185         // Calculate number of nodes for a tree depending on number of


  41  *         4. A nsk.share.gc.NonbranchyTree (number of nodes and their size depend
  42  *            on valkue returned by Runtime.maxMemory())
  43  *     As soon as the vector is filled, each thread removes half elements of it and
  44  *     then fills those places of the vector again. However, all threads use just
  45  *     about 10% of maximum amount of memory that JVM attemts to use, so
  46  *     OutOfMemoryError is treated as a failure. That means GC does not work
  47  *     quickly enough to destroy all objects that do not have references. The
  48  *     procedure of filling and cleaning of the vector is repeated for
  49  *     INTERNAL_ITERATIONS times.
  50  *
  51  * @library /vmTestbase
  52  *          /test/lib
  53  * @run driver jdk.test.lib.FileInstaller . .
  54  * @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.JumbleGC002.JumbleGC002
  55  */
  56 
  57 package gc.gctests.JumbleGC002;
  58 
  59 import java.io.*;
  60 import java.util.*;

  61 
  62 import nsk.share.*;
  63 import nsk.share.gc.*;
  64 import nsk.share.test.LocalRandom;
  65 
  66 /**
  67  * This test simply does Algorithms.eatMemory() in a loop
  68  * in multiple threads.
  69  */
  70 public class JumbleGC002 extends ThreadedGCTest {
  71 
  72     // The test should fill just about 10% of the heap
  73     final static double PART_OF_HEAP = 0.1;
  74     // Maximum number of elements in an array of primitive types
  75     final static int ARRAY_MAX_LENGTH = 10;
  76     // Internal number of iterations to create new objects and to drop
  77     // references
  78     final static int INTERNAL_ITERATIONS = 150;
  79     // Size of core for each node of a tree
  80     final static int EACH_NODE_SIZE = 1;
  81     // Number of bytes that arrays of primitive types take in the vector
  82     final static long PRIMITIVE_ARRAYS_SIZE = (long) (8 * ARRAY_MAX_LENGTH
  83             + 8 * ARRAY_MAX_LENGTH + 4 * ARRAY_MAX_LENGTH);
  84 
  85     private class Eater implements Runnable {
  86 
  87         private Vector vector;
  88         int numberOfElements;
  89         int numberOfQuarters;
  90         int id;
  91         int nodes;

  92 
  93         public Eater(int id, int numberOfQuarters, int nodes) {
  94             this.numberOfQuarters = numberOfQuarters;
  95             numberOfElements = 4 * numberOfQuarters;
  96             this.id = id;
  97             this.nodes = nodes;
  98         }
  99 
 100         public void run() {
 101             // Make jumble in the heap!
 102             initVector();
 103             while (getExecutionController().continueExecution()) {
 104                 fillVector();
 105                 cleanVector();
 106             }
 107         }
 108 
 109         // Initialize the vector and build appropriate number of cells in it
 110         private void initVector() {
 111             vector = new Vector();
 112             for (int i = 0; i < numberOfElements; i++) {
 113                 vector.addElement(null);
 114             }
 115         }
 116 
 117         // Fill the vector. It is devided into quarters. Each quarters has an
 118         // initialized array of long and int, and uninitialized array of double.
 119         // Each array has not more than ARRAY_MAX_LENGTH elements. The fourth
 120         // element in the quarter is a NonbranchyTree.
 121         private void fillVector() {
 122             for (int i = 0; i < numberOfQuarters; i++) {
 123 
 124                 // Append initialized long[]
 125                 int length = LocalRandom.nextInt(ARRAY_MAX_LENGTH);
 126                 long[] l = new long[length];
 127                 for (int j = 0; j < length; j++) {
 128                     l[j] = (long) j;
 129                 }
 130                 if (vector.elementAt(4 * i) == null) {
 131                     vector.setElementAt(l, 4 * i);
 132                 }
 133 
 134                 // Append not initialized double[]
 135                 length = LocalRandom.nextInt(ARRAY_MAX_LENGTH);
 136                 double[] d = new double[length];
 137                 if (vector.elementAt(4 * i + 1) == null) {
 138                     vector.setElementAt(d, 4 * i + 1);
 139                 }
 140 
 141                 // Append initialized int[]
 142                 length = LocalRandom.nextInt(ARRAY_MAX_LENGTH);
 143                 int[] n = new int[length];
 144                 for (int j = 0; j < length; j++) {
 145                     n[j] = j;
 146                 }
 147                 if (vector.elementAt(4 * i + 2) == null) {
 148                     vector.setElementAt(n, 4 * i + 2);
 149                 }
 150 
 151                 // Append a tree. Every even thread has a "bent" tree.
 152                 NonbranchyTree tree = new NonbranchyTree(nodes, 0.3f, EACH_NODE_SIZE);
 153                 if (id % 2 == 0) {
 154                     tree.bend();
 155                 }
 156                 if (vector.elementAt(4 * i + 3) == null) {
 157                     vector.setElementAt(tree, 4 * i + 3);
 158                 }
 159             }
 160         }
 161 
 162         // Drop references to half of the elements of the vector
 163         private void cleanVector() {
 164             int index = LocalRandom.nextInt(numberOfElements / 2);
 165             for (int i = index; i < index + numberOfElements / 2; i++) {
 166                 vector.setElementAt(null, i);
 167             }
 168         }
 169     }
 170 
 171     protected Runnable createRunnable(int i) {
 172         // Perform calculations specific to the test
 173         long memoryForThread = (long) (Runtime.getRuntime().maxMemory() * PART_OF_HEAP / runParams.getNumberOfThreads());
 174         int numberOfQuarters;
 175 
 176         if (i == 0) {
 177             // The very first thread
 178             numberOfQuarters = 1;
 179         } else {
 180             // All other threads
 181             numberOfQuarters = 8;
 182         }
 183 
 184         // Calculate number of nodes for a tree depending on number of
< prev index next >