< prev index next >

test/java/lang/management/MemoryMXBean/LowMemoryTest.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2010, 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  */


  52     private static final int NUM_CHUNKS = 2;
  53     private static final int YOUNG_GEN_SIZE = 8 * 1024 * 1024;
  54     private static long chunkSize;
  55 
  56     /**
  57      * Run the test multiple times with different GC versions.
  58      * First with default command line specified by the framework.
  59      * Then with GC versions specified by the test.
  60      */
  61     public static void main(String a[]) throws Throwable {
  62         final String main = "LowMemoryTest$TestMain";
  63         // Use a low young gen size to ensure that the
  64         // allocated objects are put in the old gen.
  65         final String nmFlag = "-Xmn" + YOUNG_GEN_SIZE;
  66         // Using large pages will change the young gen size,
  67         // make sure we don't use them for this test.
  68         final String lpFlag = "-XX:-UseLargePages";
  69         // Prevent G1 from selecting a large heap region size,
  70         // since that would change the young gen size.
  71         final String g1Flag = "-XX:G1HeapRegionSize=1m";
  72         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseSerialGC");
  73         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseParallelGC");
  74         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);
  75         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC");



  76     }
  77 
  78     private static volatile boolean listenerInvoked = false;
  79     static class SensorListener implements NotificationListener {
  80         @Override
  81         public void handleNotification(Notification notif, Object handback) {
  82             String type = notif.getType();
  83             if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) ||
  84                 type.equals(MemoryNotificationInfo.
  85                     MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
  86 
  87                 MemoryNotificationInfo minfo = MemoryNotificationInfo.
  88                     from((CompositeData) notif.getUserData());
  89 
  90                 MemoryUtil.printMemoryNotificationInfo(minfo, type);
  91                 listenerInvoked = true;
  92             }
  93         }
  94     }
  95 


   1 /*
   2  * Copyright (c) 2003, 2014, 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  */


  52     private static final int NUM_CHUNKS = 2;
  53     private static final int YOUNG_GEN_SIZE = 8 * 1024 * 1024;
  54     private static long chunkSize;
  55 
  56     /**
  57      * Run the test multiple times with different GC versions.
  58      * First with default command line specified by the framework.
  59      * Then with GC versions specified by the test.
  60      */
  61     public static void main(String a[]) throws Throwable {
  62         final String main = "LowMemoryTest$TestMain";
  63         // Use a low young gen size to ensure that the
  64         // allocated objects are put in the old gen.
  65         final String nmFlag = "-Xmn" + YOUNG_GEN_SIZE;
  66         // Using large pages will change the young gen size,
  67         // make sure we don't use them for this test.
  68         final String lpFlag = "-XX:-UseLargePages";
  69         // Prevent G1 from selecting a large heap region size,
  70         // since that would change the young gen size.
  71         final String g1Flag = "-XX:G1HeapRegionSize=1m";
  72         // Start test execution with -XX:-ExplicitGCInvokesConcurrent
  73         // Test is not targeted to work with -XX:+ExplicitGCInvokesConcurrent
  74         final String noExplictGC = "-XX:-ExplicitGCInvokesConcurrent";
  75         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseSerialGC", noExplictGC);
  76         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseParallelGC", noExplictGC);
  77         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag, noExplictGC);
  78         RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC", noExplictGC);
  79     }
  80 
  81     private static volatile boolean listenerInvoked = false;
  82     static class SensorListener implements NotificationListener {
  83         @Override
  84         public void handleNotification(Notification notif, Object handback) {
  85             String type = notif.getType();
  86             if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) ||
  87                 type.equals(MemoryNotificationInfo.
  88                     MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
  89 
  90                 MemoryNotificationInfo minfo = MemoryNotificationInfo.
  91                     from((CompositeData) notif.getUserData());
  92 
  93                 MemoryUtil.printMemoryNotificationInfo(minfo, type);
  94                 listenerInvoked = true;
  95             }
  96         }
  97     }
  98 


< prev index next >