1 /* 2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @key gc 27 * 28 * @summary converted from VM Testbase gc/memory/Array/SampleMe. 29 * VM Testbase keywords: [gc] 30 * VM Testbase readme: 31 * ## This test is a basic implementation of the thoughts below. 32 * Create an object: Cell 33 * which contains an array of bytes, the size of 34 * which is determined in the ctor call 35 * You could then have varying sizes of these objects. 36 * You could then store them in an array. Then delete 37 * a subset and garbage collect: 38 * Basically, you are looking at the holes and the 39 * remaining cells, their numbers and their locations: 40 * small/medium/large sized chunks 41 * small/medium/large sized holes 42 * contiguous/mixed/discontiguous 43 * none, few, some, many, all 44 * The key here is to provide a broad spectrum of 45 * various GC scenarios. eventually, you will want 46 * to take into account generational effects by making 47 * sure that various portions of the chunks and holes 48 * are created before or after certain generational 49 * boundaries (1 Megabyte of allocs, for example). 50 * 51 * @library /vmTestbase 52 * /test/lib 53 * @run driver jdk.test.lib.FileInstaller . . 54 * @run main/othervm gc.memory.Array.SampleMe.SampleMe 55 */ 56 57 package gc.memory.Array.SampleMe; 58 59 //SampleMe.java 60 // import SampleClass; 61 62 public class SampleMe 63 { 64 public static void main(String args[]) 65 { 66 int arraySize = 2000; 67 long before; 68 long after; 69 70 SampleClass array[] = new SampleClass[arraySize]; 71 for (int i= 0; i < arraySize; i++) 72 { 73 array[i] = new SampleClass(); 74 if ((i % (arraySize / 10)) == 0) 75 { 76 System.out.println(i); 77 } 78 } 79 System.gc(); 80 System.out.println("Erasing objects"); 81 for (int i = 0; i < arraySize /2; i ++) 82 { 83 array[i*2] = null; 84 } 85 System.out.println("ready to GC"); 86 before = System.currentTimeMillis(); 87 System.gc(); 88 after = System.currentTimeMillis(); 89 System.out.println(after - before); 90 91 for (int i = 0; i < arraySize /3; i ++) 92 { 93 array[i*2 + 1] = null; 94 } 95 before = System.currentTimeMillis(); 96 System.gc(); 97 after = System.currentTimeMillis(); 98 System.out.println(after - before); 99 100 for (int i = 0; i < arraySize; i ++) 101 { 102 array[i] = null; 103 } 104 } 105 }