Source for gnu.gcj.util.GCInfo

   1: /* GCInfo.java -- Support for creating heap dumps.
   2:    Copyright (C) 2007  Free Software Foundation
   3: 
   4:    This file is part of libgcj.
   5: 
   6:    This software is copyrighted work licensed under the terms of the
   7:    Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
   8:    details.  */
   9: 
  10: package gnu.gcj.util;
  11: 
  12: public class GCInfo
  13: {
  14:   private GCInfo()
  15:   {
  16:   }
  17: 
  18:   /**
  19:    * @throws SecurityException if there is a SecurityManager installed
  20:    * and UtilPermission("dumpHeap") is not granted.
  21:    */
  22:   private static void checkPermission()
  23:   {
  24:     SecurityManager sm = System.getSecurityManager();
  25:     if (sm != null)
  26:       sm.checkPermission(new UtilPermission("dumpHeap"));
  27:   }
  28:   
  29: 
  30:   /**
  31:    * Dump a description of the heap state.
  32:    *
  33:    * @param namePrefix The filename prefix for the dump files.
  34:    *
  35:    * @throws SecurityException if there is a SecurityManager installed
  36:    * and UtilPermission("dumpHeap") is not granted.
  37:    */
  38:   public static synchronized void dump(String name)
  39:   {
  40:     checkPermission();
  41:     dump0(name);
  42:   }
  43:   
  44:   private static native void dump0(String name);
  45: 
  46: 
  47:   /**
  48:    * Create a heap dump.
  49:    *
  50:    * @param namePrefix The filename prefix for the dump files.
  51:    *
  52:    * @throws SecurityException if there is a SecurityManager installed
  53:    * and UtilPermission("dumpHeap") is not granted.
  54:    */
  55:   public static synchronized void enumerate(String namePrefix)
  56:   {
  57:     checkPermission();
  58:     enumerate0(namePrefix);
  59:   }
  60:   
  61:   private static native void enumerate0(String namePrefix);
  62: 
  63:   /**
  64:    * Cause a heap dump if out-of-memory condition occurs.
  65:    *
  66:    * @param namePrefix The filename prefix for the dump files.  If
  67:    * null no dumps are created.
  68:    *
  69:    * @throws SecurityException if there is a SecurityManager installed
  70:    * and UtilPermission("dumpHeap") is not granted.
  71:    */
  72:   public static synchronized void setOOMDump(String namePrefix)
  73:   {
  74:     checkPermission();
  75:     setOOMDump0(namePrefix);
  76:   }
  77:   
  78:   private static native void setOOMDump0(String namePrefix);
  79: }