A small utility

Andrew Haley aph at redhat.com
Mon May 28 05:07:15 PDT 2012


We were having a lot of difficulty with our ARM port: there was a
very rare crash in the garbage collector.  This little patch helped
a lot.  It's a thread that forces a full GC at some fixed interval,
here 500ms.  I don't know if anything similar exists in the HotSpot
developer sources, but I couldn't find it.  Offered here not as a
request for a commit, but in the hope that someone might find it
useful.

Andrew.



diff -r f293db049783 src/share/vm/runtime/vmThread.cpp
--- a/src/share/vm/runtime/vmThread.cpp Mon May 28 08:01:18 2012 -0400
+++ b/src/share/vm/runtime/vmThread.cpp Mon May 28 08:01:38 2012 -0400
@@ -245,6 +245,39 @@
   }
 }

+class BangerThread : NamedThread
+{
+public:
+
+  static BangerThread *the_thread;
+
+  static void create() {
+    the_thread = new BangerThread();
+    os::create_thread (the_thread, os::watcher_thread);
+    Thread::start(the_thread);
+  }
+
+  BangerThread() : NamedThread() {
+    set_name("banger");
+  }
+
+  void run() {
+    struct timespec req;
+    req.tv_nsec = 0.5e9;
+    req.tv_sec = 0;
+
+    for (;;)
+      {
+       nanosleep(&req, NULL);
+       // VM_ForceSafepoint op;
+       // VMThread::execute(&op);
+       Universe::heap()->collect(GCCause::_java_lang_system_gc);
+      }
+  }
+};
+
+BangerThread *BangerThread::the_thread;
+
 void VMThread::run() {
   assert(this == vm_thread(), "check");

@@ -269,6 +302,8 @@
   // possible to set the VM thread priority higher than any Java thread.
   os::set_native_priority( this, prio );

+  BangerThread::create();
+
   // Wait for VM_Operations until termination
   this->loop();



More information about the hotspot-dev mailing list