changeset 12659:a2d3be7f08ad

Fix MXBean Full GC notifications.
author shade
date Wed, 14 Dec 2016 12:56:20 +0100
parents 155d04209453
children a09a9979e356
files src/share/vm/services/memoryManager.cpp src/share/vm/services/memoryManager.hpp src/share/vm/services/memoryService.cpp test/TEST.groups test/gc/shenandoah/MXNotificationsFullGC.java
diffstat 5 files changed, 88 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/services/memoryManager.cpp	Tue Dec 13 18:20:27 2016 +0100
+++ b/src/share/vm/services/memoryManager.cpp	Wed Dec 14 12:56:20 2016 +0100
@@ -91,8 +91,12 @@
   return (GCMemoryManager*) new G1OldGenMemoryManager();
 }
 
-GCMemoryManager* MemoryManager::get_shenandoah_memory_manager() {
-  return (GCMemoryManager*) new ShenandoahMemoryManager();
+GCMemoryManager* MemoryManager::get_shenandoah_minor_memory_manager() {
+  return (GCMemoryManager*) new ShenandoahMinorMemoryManager();
+}
+
+GCMemoryManager* MemoryManager::get_shenandoah_major_memory_manager() {
+  return (GCMemoryManager*) new ShenandoahMajorMemoryManager();
 }
 
 instanceOop MemoryManager::get_memory_manager_instance(TRAPS) {
--- a/src/share/vm/services/memoryManager.hpp	Tue Dec 13 18:20:27 2016 +0100
+++ b/src/share/vm/services/memoryManager.hpp	Wed Dec 14 12:56:20 2016 +0100
@@ -83,7 +83,8 @@
   static GCMemoryManager* get_psMarkSweep_memory_manager();
   static GCMemoryManager* get_g1YoungGen_memory_manager();
   static GCMemoryManager* get_g1OldGen_memory_manager();
-  static GCMemoryManager* get_shenandoah_memory_manager();
+  static GCMemoryManager* get_shenandoah_minor_memory_manager();
+  static GCMemoryManager* get_shenandoah_major_memory_manager();
 };
 
 class CodeCacheMemoryManager : public MemoryManager {
@@ -254,13 +255,18 @@
   const char* name() { return "G1 Old Generation"; }
 };
 
-class ShenandoahMemoryManager : public GCMemoryManager {
-private:
+class ShenandoahMinorMemoryManager : public GCMemoryManager {
 public:
-  ShenandoahMemoryManager() : GCMemoryManager() {}
+  ShenandoahMinorMemoryManager() : GCMemoryManager() {}
 
-  const char* name()         { return "Shenandoah";}
+  const char* name()         { return "Shenandoah Minor"; }
+};
 
+class ShenandoahMajorMemoryManager : public GCMemoryManager {
+public:
+  ShenandoahMajorMemoryManager() : GCMemoryManager() {}
+
+  const char* name()         { return "Shenandoah Major"; }
 };
 
 #endif // SHARE_VM_SERVICES_MEMORYMANAGER_HPP
--- a/src/share/vm/services/memoryService.cpp	Tue Dec 13 18:20:27 2016 +0100
+++ b/src/share/vm/services/memoryService.cpp	Wed Dec 14 12:56:20 2016 +0100
@@ -197,8 +197,12 @@
 
 void MemoryService::add_shenandoah_heap_info(ShenandoahHeap* pgch) {
   assert(UseShenandoahGC, "sanity");
-  _major_gc_manager = MemoryManager::get_shenandoah_memory_manager();
-  _minor_gc_manager = MemoryManager::get_shenandoah_memory_manager();
+
+  // Need to have different names for these managers, because having the same name
+  // would confuse notification mechanics: it will enable notifications only for
+  // the first manager with the matching name.
+  _major_gc_manager = MemoryManager::get_shenandoah_major_memory_manager();
+  _minor_gc_manager = MemoryManager::get_shenandoah_minor_memory_manager();
   _managers_list->append(_major_gc_manager);
   _managers_list->append(_minor_gc_manager);
   add_shenandoah_memory_pool(pgch, _minor_gc_manager, true);
--- a/test/TEST.groups	Tue Dec 13 18:20:27 2016 +0100
+++ b/test/TEST.groups	Wed Dec 14 12:56:20 2016 +0100
@@ -344,7 +344,8 @@
   gc/shenandoah/TestAllocLargeObjOOM.java \
   gc/shenandoah/TestAllocSmallObjOOM.java \
   gc/shenandoah/TestRegionSizeArgs.java \
-  gc/shenandoah/TestSingleThreadedShenandoah.java
+  gc/shenandoah/TestSingleThreadedShenandoah.java \
+  gc/shenandoah/MXNotificationsFullGC.java
 
 hotspot_fast_gc_1 = \
   gc/g1/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/gc/shenandoah/MXNotificationsFullGC.java	Wed Dec 14 12:56:20 2016 +0100
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2016, Red Hat, Inc. and/or its affiliates.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test MXNotificationsFullGC
+ * @summary Check that full GC notifications are reported on Shenandoah's full GCs
+ * @run main/othervm -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -Xmx1g -Xms1g MXNotificationsFullGC
+ */
+
+import javax.management.*;
+import java.lang.management.*;
+
+public class MXNotificationsFullGC {
+
+  static volatile boolean notified;
+  static volatile Object sink;
+
+  public static void main(String[] args) throws Exception {
+    NotificationListener listener = new NotificationListener() {
+      @Override
+      public void handleNotification(Notification n, Object o) {
+        if (n.getType().equals(com.sun.management.GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
+          notified = true;
+        }
+      }
+    };
+
+    for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
+      ((NotificationEmitter) bean).addNotificationListener(listener, null, null);
+    }
+
+    // Allocate 4*100K*10K = 4G, enough to blow the 1G heap into full GC
+    for (int c = 0; c < 10_000; c++) {
+       sink = new int[100_000];
+    }
+
+    if (!notified) {
+      throw new IllegalStateException("Should have been notified");
+    }
+  }
+}
+
+