8034263: Test java/lang/management/MemoryMXBean/LowMemoryTest.java fails intermittently
authorjbachorik
Thu, 04 Dec 2014 10:34:55 +0100
changeset 28245 5560f8810064
parent 28104 2289175871fb
child 28246 c9ebe8cf5b40
child 28247 f6b1d27113b7
8034263: Test java/lang/management/MemoryMXBean/LowMemoryTest.java fails intermittently Reviewed-by: sla
jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java
--- a/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java	Tue Dec 09 08:58:19 2014 +0100
+++ b/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java	Thu Dec 04 10:34:55 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,11 +35,13 @@
  * @run main/timeout=600 LowMemoryTest
  */
 
+import com.sun.management.DiagnosticCommandMBean;
 import java.lang.management.*;
 import java.util.*;
 import java.util.concurrent.Phaser;
 import javax.management.*;
 import javax.management.openmbean.CompositeData;
+import sun.management.ManagementFactoryHelper;
 
 public class LowMemoryTest {
     private static final MemoryMXBean mm = ManagementFactory.getMemoryMXBean();
@@ -94,9 +96,15 @@
     }
 
     static class TestListener implements NotificationListener {
+        private boolean isRelaxed = false;
         private int triggers = 0;
         private final long[] count = new long[NUM_TRIGGERS * 2];
         private final long[] usedMemory = new long[NUM_TRIGGERS * 2];
+
+        public TestListener() {
+            isRelaxed = ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-XX:+UseConcMarkSweepGC");
+        }
+
         @Override
         public void handleNotification(Notification notif, Object handback) {
             MemoryNotificationInfo minfo = MemoryNotificationInfo.
@@ -106,7 +114,8 @@
             triggers++;
         }
         public void checkResult() throws Exception {
-            if (triggers != NUM_TRIGGERS) {
+            if ((!isRelaxed && triggers != NUM_TRIGGERS) ||
+                (isRelaxed && triggers < NUM_TRIGGERS)) {
                 throw new RuntimeException("Unexpected number of triggers = " +
                     triggers + " but expected to be " + NUM_TRIGGERS);
             }