1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_GCHEAPSUMMARY_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCHEAPSUMMARY_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 
  30 class VirtualSpaceSummary : public StackObj {
  31   HeapWord* _start;
  32   HeapWord* _committed_end;
  33   HeapWord* _reserved_end;
  34 public:
  35   VirtualSpaceSummary() :
  36       _start(NULL), _committed_end(NULL), _reserved_end(NULL) { }
  37   VirtualSpaceSummary(HeapWord* start, HeapWord* committed_end, HeapWord* reserved_end) :
  38       _start(start), _committed_end(committed_end), _reserved_end(reserved_end) { }
  39 
  40   HeapWord* start() const { return _start; }
  41   HeapWord* committed_end() const { return _committed_end; }
  42   HeapWord* reserved_end() const { return _reserved_end; }
  43   size_t committed_size() const { return (uintptr_t)_committed_end - (uintptr_t)_start;  }
  44   size_t reserved_size() const { return (uintptr_t)_reserved_end - (uintptr_t)_start; }
  45 };
  46 
  47 class SpaceSummary : public StackObj {
  48   HeapWord* _start;
  49   HeapWord* _end;
  50   size_t    _used;
  51 public:
  52   SpaceSummary() :
  53       _start(NULL), _end(NULL), _used(0) { }
  54   SpaceSummary(HeapWord* start, HeapWord* end, size_t used) :
  55       _start(start), _end(end), _used(used) { }
  56 
  57   HeapWord* start() const { return _start; }
  58   HeapWord* end() const { return _end; }
  59   size_t used() const { return _used; }
  60   size_t size() const { return (uintptr_t)_end - (uintptr_t)_start; }
  61 };
  62 
  63 class MetaspaceSizes : public StackObj {
  64   size_t _capacity;
  65   size_t _used;
  66   size_t _reserved;
  67 
  68  public:
  69   MetaspaceSizes() : _capacity(0), _used(0), _reserved(0) {}
  70   MetaspaceSizes(size_t capacity, size_t used, size_t reserved) :
  71     _capacity(capacity), _used(used), _reserved(reserved) {}
  72 
  73   size_t capacity() const { return _capacity; }
  74   size_t used() const { return _used; }
  75   size_t reserved() const { return _reserved; }
  76 };
  77 
  78 class GCHeapSummary;
  79 class PSHeapSummary;
  80 
  81 class GCHeapSummaryVisitor {
  82  public:
  83   virtual void visit(const GCHeapSummary* heap_summary) const = 0;
  84   virtual void visit(const PSHeapSummary* heap_summary) const {}
  85 };
  86 
  87 class GCHeapSummary : public StackObj {
  88   VirtualSpaceSummary _heap;
  89   size_t _used;
  90 
  91  public:
  92    GCHeapSummary() :
  93        _heap(), _used(0) { }
  94    GCHeapSummary(VirtualSpaceSummary& heap_space, size_t used) :
  95        _heap(heap_space), _used(used) { }
  96 
  97   const VirtualSpaceSummary& heap() const { return _heap; }
  98   size_t used() const { return _used; }
  99 
 100    virtual void accept(GCHeapSummaryVisitor* visitor) const {
 101      visitor->visit(this);
 102    }
 103 };
 104 
 105 class PSHeapSummary : public GCHeapSummary {
 106   VirtualSpaceSummary  _old;
 107   SpaceSummary         _old_space;
 108   VirtualSpaceSummary  _young;
 109   SpaceSummary         _eden;
 110   SpaceSummary         _from;
 111   SpaceSummary         _to;
 112  public:
 113    PSHeapSummary(VirtualSpaceSummary& heap_space, size_t heap_used, VirtualSpaceSummary old, SpaceSummary old_space, VirtualSpaceSummary young, SpaceSummary eden, SpaceSummary from, SpaceSummary to) :
 114        GCHeapSummary(heap_space, heap_used), _old(old), _old_space(old_space), _young(young), _eden(eden), _from(from), _to(to) { }
 115    const VirtualSpaceSummary& old() const { return _old; }
 116    const SpaceSummary& old_space() const { return _old_space; }
 117    const VirtualSpaceSummary& young() const { return _young; }
 118    const SpaceSummary& eden() const { return _eden; }
 119    const SpaceSummary& from() const { return _from; }
 120    const SpaceSummary& to() const { return _to; }
 121 
 122    virtual void accept(GCHeapSummaryVisitor* visitor) const {
 123      visitor->visit(this);
 124    }
 125 };
 126 
 127 class MetaspaceSummary : public StackObj {
 128   MetaspaceSizes _meta_space;
 129   MetaspaceSizes _data_space;
 130   MetaspaceSizes _class_space;
 131 
 132  public:
 133   MetaspaceSummary() : _meta_space(), _data_space(), _class_space() {}
 134   MetaspaceSummary(const MetaspaceSizes& meta_space, const MetaspaceSizes& data_space, const MetaspaceSizes& class_space) :
 135        _meta_space(meta_space), _data_space(data_space), _class_space(class_space) { }
 136 
 137   const MetaspaceSizes& meta_space() const { return _meta_space; }
 138   const MetaspaceSizes& data_space() const { return _data_space; }
 139   const MetaspaceSizes& class_space() const { return _class_space; }
 140 };
 141 
 142 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCHEAPSUMMARY_HPP