< prev index next >

test/gc/g1/TestShrinkDefragmentedHeap.java

Print this page




  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 TestShrinkDefragmentedHeap
  26  * @bug 8038423
  27  * @summary Verify that heap shrinks after GC in the presence of fragmentation due to humongous objects
  28  *     1. allocate small objects mixed with humongous ones
  29  *        "ssssHssssHssssHssssHssssHssssHssssH"
  30  *     2. release all allocated object except the last humongous one
  31  *        "..................................H"
  32  *     3. invoke gc and check that memory returned to the system (amount of committed memory got down)
  33  *
  34  * @library /testlibrary


  35  */
  36 import java.lang.management.ManagementFactory;
  37 import java.lang.management.MemoryUsage;
  38 import java.util.ArrayList;
  39 import java.util.List;
  40 import sun.management.ManagementFactoryHelper;
  41 import static com.oracle.java.testlibrary.Asserts.*;
  42 import com.oracle.java.testlibrary.ProcessTools;
  43 import com.oracle.java.testlibrary.OutputAnalyzer;
  44 
  45 public class TestShrinkDefragmentedHeap {
  46     // Since we store all the small objects, they become old and old regions are also allocated at the bottom of the heap
  47     // together with humongous regions. So if there are a lot of old regions in the lower part of the heap,
  48     // the humongous regions will be allocated in the upper part of the heap anyway.
  49     // To avoid this the Eden needs to be big enough to fit all the small objects.
  50     private static final int INITIAL_HEAP_SIZE  = 200 * 1024 * 1024;
  51     private static final int MINIMAL_YOUNG_SIZE = 190 * 1024 * 1024;
  52     private static final int REGION_SIZE        = 1 * 1024 * 1024;
  53 
  54     public static void main(String[] args) throws Exception, Throwable {




  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 TestShrinkDefragmentedHeap
  26  * @bug 8038423
  27  * @summary Verify that heap shrinks after GC in the presence of fragmentation due to humongous objects
  28  *     1. allocate small objects mixed with humongous ones
  29  *        "ssssHssssHssssHssssHssssHssssHssssH"
  30  *     2. release all allocated object except the last humongous one
  31  *        "..................................H"
  32  *     3. invoke gc and check that memory returned to the system (amount of committed memory got down)
  33  *
  34  * @library /testlibrary
  35  * @build com.oracle.java.testlibrary.*
  36  * @run main/othervm TestShrinkDefragmentedHeap
  37  */
  38 import java.lang.management.ManagementFactory;
  39 import java.lang.management.MemoryUsage;
  40 import java.util.ArrayList;
  41 import java.util.List;
  42 import sun.management.ManagementFactoryHelper;
  43 import static com.oracle.java.testlibrary.Asserts.*;
  44 import com.oracle.java.testlibrary.ProcessTools;
  45 import com.oracle.java.testlibrary.OutputAnalyzer;
  46 
  47 public class TestShrinkDefragmentedHeap {
  48     // Since we store all the small objects, they become old and old regions are also allocated at the bottom of the heap
  49     // together with humongous regions. So if there are a lot of old regions in the lower part of the heap,
  50     // the humongous regions will be allocated in the upper part of the heap anyway.
  51     // To avoid this the Eden needs to be big enough to fit all the small objects.
  52     private static final int INITIAL_HEAP_SIZE  = 200 * 1024 * 1024;
  53     private static final int MINIMAL_YOUNG_SIZE = 190 * 1024 * 1024;
  54     private static final int REGION_SIZE        = 1 * 1024 * 1024;
  55 
  56     public static void main(String[] args) throws Exception, Throwable {


< prev index next >