src/share/vm/gc_implementation/shared/vmGCOperations.hpp

changeset 435
a61af66fc99e
child 574
c0492d52d55b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/shared/vmGCOperations.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,168 @@
     1.4 +/*
     1.5 + * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// The following class hierarchy represents
    1.29 +// a set of operations (VM_Operation) related to GC.
    1.30 +//
    1.31 +//  VM_Operation
    1.32 +//      VM_GC_Operation
    1.33 +//          VM_GC_HeapInspection
    1.34 +//          VM_GenCollectForAllocation
    1.35 +//          VM_GenCollectFull
    1.36 +//          VM_GenCollectFullConcurrent
    1.37 +//          VM_ParallelGCFailedAllocation
    1.38 +//          VM_ParallelGCFailedPermanentAllocation
    1.39 +//          VM_ParallelGCSystemGC
    1.40 +//  VM_GC_Operation
    1.41 +//   - implements methods common to all classes in the hierarchy:
    1.42 +//     prevents multiple gc requests and manages lock on heap;
    1.43 +//
    1.44 +//  VM_GC_HeapInspection
    1.45 +//   - prints class histogram on SIGBREAK if PrintClassHistogram
    1.46 +//     is specified; and also the attach "inspectheap" operation
    1.47 +//
    1.48 +//  VM_GenCollectForAllocation
    1.49 +//  VM_ParallelGCFailedAllocation
    1.50 +//  VM_ParallelGCFailedPermanentAllocation
    1.51 +//   - this operation is invoked when allocation is failed;
    1.52 +//     operation performs garbage collection and tries to
    1.53 +//     allocate afterwards;
    1.54 +//
    1.55 +//  VM_GenCollectFull
    1.56 +//  VM_GenCollectFullConcurrent
    1.57 +//  VM_ParallelGCSystemGC
    1.58 +//   - these operations preform full collection of heaps of
    1.59 +//     different kind
    1.60 +//
    1.61 +
    1.62 +class VM_GC_Operation: public VM_Operation {
    1.63 + protected:
    1.64 +  BasicLock     _pending_list_basic_lock; // for refs pending list notification (PLL)
    1.65 +  unsigned int  _gc_count_before;         // gc count before acquiring PLL
    1.66 +  unsigned int  _full_gc_count_before;    // full gc count before acquiring PLL
    1.67 +  bool          _full;                    // whether a "full" collection
    1.68 +  bool          _prologue_succeeded;      // whether doit_prologue succeeded
    1.69 +  GCCause::Cause _gc_cause;                // the putative cause for this gc op
    1.70 +  bool          _gc_locked;               // will be set if gc was locked
    1.71 +
    1.72 +  virtual bool skip_operation() const;
    1.73 +
    1.74 +  // java.lang.ref.Reference support
    1.75 +  void acquire_pending_list_lock();
    1.76 +  void release_and_notify_pending_list_lock();
    1.77 +
    1.78 + public:
    1.79 +  VM_GC_Operation(unsigned int gc_count_before,
    1.80 +                  unsigned int full_gc_count_before = 0,
    1.81 +                  bool full = false) {
    1.82 +    _full = full;
    1.83 +    _prologue_succeeded = false;
    1.84 +    _gc_count_before    = gc_count_before;
    1.85 +
    1.86 +    // A subclass constructor will likely overwrite the following
    1.87 +    _gc_cause           = GCCause::_no_cause_specified;
    1.88 +
    1.89 +    _gc_locked = false;
    1.90 +
    1.91 +    if (full) {
    1.92 +      _full_gc_count_before = full_gc_count_before;
    1.93 +    }
    1.94 +  }
    1.95 +  ~VM_GC_Operation() {}
    1.96 +
    1.97 +  // Acquire the reference synchronization lock
    1.98 +  virtual bool doit_prologue();
    1.99 +  // Do notifyAll (if needed) and release held lock
   1.100 +  virtual void doit_epilogue();
   1.101 +
   1.102 +  virtual bool allow_nested_vm_operations() const  { return true; }
   1.103 +  bool prologue_succeeded() const { return _prologue_succeeded; }
   1.104 +
   1.105 +  void set_gc_locked() { _gc_locked = true; }
   1.106 +  bool gc_locked() const  { return _gc_locked; }
   1.107 +
   1.108 +  static void notify_gc_begin(bool full = false);
   1.109 +  static void notify_gc_end();
   1.110 +};
   1.111 +
   1.112 +
   1.113 +class VM_GC_HeapInspection: public VM_GC_Operation {
   1.114 + private:
   1.115 +  outputStream* _out;
   1.116 +  bool _full_gc;
   1.117 + public:
   1.118 +  VM_GC_HeapInspection(outputStream* out, bool request_full_gc) :
   1.119 +    VM_GC_Operation(0 /* total collections,      dummy, ignored */,
   1.120 +                    0 /* total full collections, dummy, ignored */,
   1.121 +                    request_full_gc) {
   1.122 +    _out = out;
   1.123 +    _full_gc = request_full_gc;
   1.124 +  }
   1.125 +
   1.126 +  ~VM_GC_HeapInspection() {}
   1.127 +  virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; }
   1.128 +  virtual bool skip_operation() const;
   1.129 +  virtual bool doit_prologue();
   1.130 +  virtual void doit();
   1.131 +};
   1.132 +
   1.133 +
   1.134 +class VM_GenCollectForAllocation: public VM_GC_Operation {
   1.135 + private:
   1.136 +  HeapWord*   _res;
   1.137 +  size_t      _size;                       // size of object to be allocated.
   1.138 +  bool        _tlab;                       // alloc is of a tlab.
   1.139 + public:
   1.140 +  VM_GenCollectForAllocation(size_t size,
   1.141 +                             bool tlab,
   1.142 +                             unsigned int gc_count_before)
   1.143 +    : VM_GC_Operation(gc_count_before),
   1.144 +      _size(size),
   1.145 +      _tlab(tlab) {
   1.146 +    _res = NULL;
   1.147 +  }
   1.148 +  ~VM_GenCollectForAllocation()  {}
   1.149 +  virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; }
   1.150 +  virtual void doit();
   1.151 +  HeapWord* result() const       { return _res; }
   1.152 +};
   1.153 +
   1.154 +
   1.155 +// VM operation to invoke a collection of the heap as a
   1.156 +// GenCollectedHeap heap.
   1.157 +class VM_GenCollectFull: public VM_GC_Operation {
   1.158 + private:
   1.159 +  int _max_level;
   1.160 + public:
   1.161 +  VM_GenCollectFull(unsigned int gc_count_before,
   1.162 +                    unsigned int full_gc_count_before,
   1.163 +                    GCCause::Cause gc_cause,
   1.164 +                      int max_level)
   1.165 +    : VM_GC_Operation(gc_count_before, full_gc_count_before, true /* full */),
   1.166 +      _max_level(max_level)
   1.167 +  { _gc_cause = gc_cause; }
   1.168 +  ~VM_GenCollectFull() {}
   1.169 +  virtual VMOp_Type type() const { return VMOp_GenCollectFull; }
   1.170 +  virtual void doit();
   1.171 +};

mercurial