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

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/shared/vmGCOperations.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,237 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP
    1.30 +
    1.31 +#include "memory/heapInspection.hpp"
    1.32 +#include "runtime/handles.hpp"
    1.33 +#include "runtime/jniHandles.hpp"
    1.34 +#include "runtime/synchronizer.hpp"
    1.35 +#include "runtime/vm_operations.hpp"
    1.36 +#include "prims/jvmtiExport.hpp"
    1.37 +
    1.38 +// The following class hierarchy represents
    1.39 +// a set of operations (VM_Operation) related to GC.
    1.40 +//
    1.41 +//  VM_Operation
    1.42 +//      VM_GC_Operation
    1.43 +//          VM_GC_HeapInspection
    1.44 +//          VM_GenCollectForAllocation
    1.45 +//          VM_GenCollectFull
    1.46 +//          VM_GenCollectFullConcurrent
    1.47 +//          VM_ParallelGCFailedAllocation
    1.48 +//          VM_ParallelGCSystemGC
    1.49 +//  VM_GC_Operation
    1.50 +//   - implements methods common to all classes in the hierarchy:
    1.51 +//     prevents multiple gc requests and manages lock on heap;
    1.52 +//
    1.53 +//  VM_GC_HeapInspection
    1.54 +//   - prints class histogram on SIGBREAK if PrintClassHistogram
    1.55 +//     is specified; and also the attach "inspectheap" operation
    1.56 +//
    1.57 +//  VM_GenCollectForAllocation
    1.58 +//  VM_ParallelGCFailedAllocation
    1.59 +//   - this operation is invoked when allocation is failed;
    1.60 +//     operation performs garbage collection and tries to
    1.61 +//     allocate afterwards;
    1.62 +//
    1.63 +//  VM_GenCollectFull
    1.64 +//  VM_GenCollectFullConcurrent
    1.65 +//  VM_ParallelGCSystemGC
    1.66 +//   - these operations preform full collection of heaps of
    1.67 +//     different kind
    1.68 +//
    1.69 +
    1.70 +class VM_GC_Operation: public VM_Operation {
    1.71 + protected:
    1.72 +  BasicLock     _pending_list_basic_lock; // for refs pending list notification (PLL)
    1.73 +  unsigned int  _gc_count_before;         // gc count before acquiring PLL
    1.74 +  unsigned int  _full_gc_count_before;    // full gc count before acquiring PLL
    1.75 +  bool          _full;                    // whether a "full" collection
    1.76 +  bool          _prologue_succeeded;      // whether doit_prologue succeeded
    1.77 +  GCCause::Cause _gc_cause;                // the putative cause for this gc op
    1.78 +  bool          _gc_locked;               // will be set if gc was locked
    1.79 +
    1.80 +  virtual bool skip_operation() const;
    1.81 +
    1.82 +  // java.lang.ref.Reference support
    1.83 +  void acquire_pending_list_lock();
    1.84 +  void release_and_notify_pending_list_lock();
    1.85 +
    1.86 + public:
    1.87 +  VM_GC_Operation(unsigned int gc_count_before,
    1.88 +                  GCCause::Cause _cause,
    1.89 +                  unsigned int full_gc_count_before = 0,
    1.90 +                  bool full = false) {
    1.91 +    _full = full;
    1.92 +    _prologue_succeeded = false;
    1.93 +    _gc_count_before    = gc_count_before;
    1.94 +
    1.95 +    // A subclass constructor will likely overwrite the following
    1.96 +    _gc_cause           = _cause;
    1.97 +
    1.98 +    _gc_locked = false;
    1.99 +
   1.100 +    _full_gc_count_before = full_gc_count_before;
   1.101 +    // In ParallelScavengeHeap::mem_allocate() collections can be
   1.102 +    // executed within a loop and _all_soft_refs_clear can be set
   1.103 +    // true after they have been cleared by a collection and another
   1.104 +    // collection started so that _all_soft_refs_clear can be true
   1.105 +    // when this collection is started.  Don't assert that
   1.106 +    // _all_soft_refs_clear have to be false here even though
   1.107 +    // mutators have run.  Soft refs will be cleared again in this
   1.108 +    // collection.
   1.109 +  }
   1.110 +  ~VM_GC_Operation() {
   1.111 +    CollectedHeap* ch = Universe::heap();
   1.112 +    ch->collector_policy()->set_all_soft_refs_clear(false);
   1.113 +  }
   1.114 +
   1.115 +  // Acquire the reference synchronization lock
   1.116 +  virtual bool doit_prologue();
   1.117 +  // Do notifyAll (if needed) and release held lock
   1.118 +  virtual void doit_epilogue();
   1.119 +
   1.120 +  virtual bool allow_nested_vm_operations() const  { return true; }
   1.121 +  bool prologue_succeeded() const { return _prologue_succeeded; }
   1.122 +
   1.123 +  void set_gc_locked() { _gc_locked = true; }
   1.124 +  bool gc_locked() const  { return _gc_locked; }
   1.125 +
   1.126 +  static void notify_gc_begin(bool full = false);
   1.127 +  static void notify_gc_end();
   1.128 +};
   1.129 +
   1.130 +
   1.131 +class VM_GC_HeapInspection: public VM_GC_Operation {
   1.132 + private:
   1.133 +  outputStream* _out;
   1.134 +  bool _full_gc;
   1.135 +  bool _csv_format; // "comma separated values" format for spreadsheet.
   1.136 +  bool _print_help;
   1.137 +  bool _print_class_stats;
   1.138 +  const char* _columns;
   1.139 + public:
   1.140 +  VM_GC_HeapInspection(outputStream* out, bool request_full_gc) :
   1.141 +    VM_GC_Operation(0 /* total collections,      dummy, ignored */,
   1.142 +                    GCCause::_heap_inspection /* GC Cause */,
   1.143 +                    0 /* total full collections, dummy, ignored */,
   1.144 +                    request_full_gc) {
   1.145 +    _out = out;
   1.146 +    _full_gc = request_full_gc;
   1.147 +    _csv_format = false;
   1.148 +    _print_help = false;
   1.149 +    _print_class_stats = false;
   1.150 +    _columns = NULL;
   1.151 +  }
   1.152 +
   1.153 +  ~VM_GC_HeapInspection() {}
   1.154 +  virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; }
   1.155 +  virtual bool skip_operation() const;
   1.156 +  virtual bool doit_prologue();
   1.157 +  virtual void doit();
   1.158 +  void set_csv_format(bool value) {_csv_format = value;}
   1.159 +  void set_print_help(bool value) {_print_help = value;}
   1.160 +  void set_print_class_stats(bool value) {_print_class_stats = value;}
   1.161 +  void set_columns(const char* value) {_columns = value;}
   1.162 + protected:
   1.163 +  bool collect();
   1.164 +};
   1.165 +
   1.166 +
   1.167 +class VM_GenCollectForAllocation: public VM_GC_Operation {
   1.168 + private:
   1.169 +  HeapWord*   _res;
   1.170 +  size_t      _size;                       // size of object to be allocated.
   1.171 +  bool        _tlab;                       // alloc is of a tlab.
   1.172 + public:
   1.173 +  VM_GenCollectForAllocation(size_t size,
   1.174 +                             bool tlab,
   1.175 +                             unsigned int gc_count_before)
   1.176 +    : VM_GC_Operation(gc_count_before, GCCause::_allocation_failure),
   1.177 +      _size(size),
   1.178 +      _tlab(tlab) {
   1.179 +    _res = NULL;
   1.180 +  }
   1.181 +  ~VM_GenCollectForAllocation()  {}
   1.182 +  virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; }
   1.183 +  virtual void doit();
   1.184 +  HeapWord* result() const       { return _res; }
   1.185 +};
   1.186 +
   1.187 +
   1.188 +// VM operation to invoke a collection of the heap as a
   1.189 +// GenCollectedHeap heap.
   1.190 +class VM_GenCollectFull: public VM_GC_Operation {
   1.191 + private:
   1.192 +  int _max_level;
   1.193 + public:
   1.194 +  VM_GenCollectFull(unsigned int gc_count_before,
   1.195 +                    unsigned int full_gc_count_before,
   1.196 +                    GCCause::Cause gc_cause,
   1.197 +                      int max_level)
   1.198 +    : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true /* full */),
   1.199 +      _max_level(max_level) { }
   1.200 +  ~VM_GenCollectFull() {}
   1.201 +  virtual VMOp_Type type() const { return VMOp_GenCollectFull; }
   1.202 +  virtual void doit();
   1.203 +};
   1.204 +
   1.205 +class VM_CollectForMetadataAllocation: public VM_GC_Operation {
   1.206 + private:
   1.207 +  MetaWord*                _result;
   1.208 +  size_t                   _size;     // size of object to be allocated
   1.209 +  Metaspace::MetadataType  _mdtype;
   1.210 +  ClassLoaderData*         _loader_data;
   1.211 + public:
   1.212 +  VM_CollectForMetadataAllocation(ClassLoaderData* loader_data,
   1.213 +                                  size_t size, Metaspace::MetadataType mdtype,
   1.214 +                                      unsigned int gc_count_before,
   1.215 +                                      unsigned int full_gc_count_before,
   1.216 +                                      GCCause::Cause gc_cause)
   1.217 +    : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true),
   1.218 +      _loader_data(loader_data), _size(size), _mdtype(mdtype), _result(NULL) {
   1.219 +  }
   1.220 +  virtual VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; }
   1.221 +  virtual void doit();
   1.222 +  MetaWord* result() const       { return _result; }
   1.223 +};
   1.224 +
   1.225 +class SvcGCMarker : public StackObj {
   1.226 + private:
   1.227 +  JvmtiGCMarker _jgcm;
   1.228 + public:
   1.229 +  typedef enum { MINOR, FULL, OTHER } reason_type;
   1.230 +
   1.231 +  SvcGCMarker(reason_type reason ) {
   1.232 +    VM_GC_Operation::notify_gc_begin(reason == FULL);
   1.233 +  }
   1.234 +
   1.235 +  ~SvcGCMarker() {
   1.236 +    VM_GC_Operation::notify_gc_end();
   1.237 +  }
   1.238 +};
   1.239 +
   1.240 +#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP

mercurial