test/jdk/java/lang/management/MemoryMXBean/LowMemoryTest.java
changeset 59053 ba6c248cae19
parent 51754 594919232b8f
equal deleted inserted replaced
59051:f0312c7d5b37 59053:ba6c248cae19
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    82 
    82 
    83         // Runs the test collecting subprocess I/O while it's running.
    83         // Runs the test collecting subprocess I/O while it's running.
    84         traceTest(classMain + ", -XX:+UseSerialGC", nmFlag, lpFlag, "-XX:+UseSerialGC");
    84         traceTest(classMain + ", -XX:+UseSerialGC", nmFlag, lpFlag, "-XX:+UseSerialGC");
    85         traceTest(classMain + ", -XX:+UseParallelGC", nmFlag, lpFlag, "-XX:+UseParallelGC");
    85         traceTest(classMain + ", -XX:+UseParallelGC", nmFlag, lpFlag, "-XX:+UseParallelGC");
    86         traceTest(classMain + ", -XX:+UseG1GC", nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);
    86         traceTest(classMain + ", -XX:+UseG1GC", nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);
    87         if (!Compiler.isGraalEnabled()) { // Graal does not support CMS
       
    88             traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC");
       
    89         }
       
    90     }
    87     }
    91 
    88 
    92     /*
    89     /*
    93      * Creating command-line for running subprocess JVM:
    90      * Creating command-line for running subprocess JVM:
    94      *
    91      *
   167             }
   164             }
   168         }
   165         }
   169     }
   166     }
   170 
   167 
   171     static class TestListener implements NotificationListener {
   168     static class TestListener implements NotificationListener {
   172         private boolean isRelaxed = false;
       
   173         private int triggers = 0;
   169         private int triggers = 0;
   174         private final long[] count = new long[NUM_TRIGGERS * 2];
   170         private final long[] count = new long[NUM_TRIGGERS * 2];
   175         private final long[] usedMemory = new long[NUM_TRIGGERS * 2];
   171         private final long[] usedMemory = new long[NUM_TRIGGERS * 2];
   176 
       
   177         public TestListener() {
       
   178             isRelaxed = ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-XX:+UseConcMarkSweepGC");
       
   179         }
       
   180 
   172 
   181         @Override
   173         @Override
   182         public void handleNotification(Notification notif, Object handback) {
   174         public void handleNotification(Notification notif, Object handback) {
   183             MemoryNotificationInfo minfo = MemoryNotificationInfo.
   175             MemoryNotificationInfo minfo = MemoryNotificationInfo.
   184                 from((CompositeData) notif.getUserData());
   176                 from((CompositeData) notif.getUserData());
   210         private boolean checkValue(int value, int target) {
   202         private boolean checkValue(int value, int target) {
   211             return checkValue((long)value, target);
   203             return checkValue((long)value, target);
   212         }
   204         }
   213 
   205 
   214         private boolean checkValue(long value, int target) {
   206         private boolean checkValue(long value, int target) {
   215             if (!isRelaxed) {
   207             return value == target;
   216                 return value == target;
       
   217             } else {
       
   218                 return value >= target;
       
   219             }
       
   220         }
   208         }
   221     }
   209     }
   222 
   210 
   223     private static long newThreshold;
   211     private static long newThreshold;
   224 
   212