g1HRPrinter.hpp revision 9727:f944761a3ce3
1/*
2 * Copyright (c) 2011, 2015, 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_G1_G1HRPRINTER_HPP
26#define SHARE_VM_GC_G1_G1HRPRINTER_HPP
27
28#include "gc/g1/heapRegion.hpp"
29#include "logging/log.hpp"
30#include "memory/allocation.hpp"
31
32#define SKIP_RETIRED_FULL_REGIONS 1
33
34class G1HRPrinter VALUE_OBJ_CLASS_SPEC {
35public:
36  typedef enum {
37    Alloc,
38    AllocForce,
39    Retire,
40    Reuse,
41    CSet,
42    EvacFailure,
43    Cleanup,
44    PostCompaction,
45    Commit,
46    Uncommit
47  } ActionType;
48
49  typedef enum {
50    Unset,
51    Eden,
52    Survivor,
53    Old,
54    StartsHumongous,
55    ContinuesHumongous,
56    Archive
57  } RegionType;
58
59private:
60  static const char* action_name(ActionType action);
61  static const char* region_type_name(RegionType type);
62
63  // Print an action event. This version is used in most scenarios and
64  // only prints the region's bottom. The parameters type and top are
65  // optional (the "not set" values are Unset and NULL).
66  static void print(ActionType action, RegionType type,
67                    HeapRegion* hr, HeapWord* top);
68
69  // Print an action event. This version prints both the region's
70  // bottom and end. Used for Commit / Uncommit events.
71  static void print(ActionType action, HeapWord* bottom, HeapWord* end);
72
73public:
74  // In some places we iterate over a list in order to generate output
75  // for the list's elements. By exposing this we can avoid this
76  // iteration if the printer is not active.
77  const bool is_active() { return log_is_enabled(Trace, gc, region); }
78
79  // The methods below are convenient wrappers for the print() methods.
80
81  void alloc(HeapRegion* hr, RegionType type, bool force = false) {
82    if (is_active()) {
83      print((!force) ? Alloc : AllocForce, type, hr, NULL);
84    }
85  }
86
87  void alloc(RegionType type, HeapRegion* hr, HeapWord* top) {
88    if (is_active()) {
89      print(Alloc, type, hr, top);
90    }
91  }
92
93  void retire(HeapRegion* hr) {
94    if (is_active()) {
95      if (!SKIP_RETIRED_FULL_REGIONS || hr->top() < hr->end()) {
96        print(Retire, Unset, hr, hr->top());
97      }
98    }
99  }
100
101  void reuse(HeapRegion* hr) {
102    if (is_active()) {
103      print(Reuse, Unset, hr, NULL);
104    }
105  }
106
107  void cset(HeapRegion* hr) {
108    if (is_active()) {
109      print(CSet, Unset, hr, NULL);
110    }
111  }
112
113  void evac_failure(HeapRegion* hr) {
114    if (is_active()) {
115      print(EvacFailure, Unset, hr, NULL);
116    }
117  }
118
119  void cleanup(HeapRegion* hr) {
120    if (is_active()) {
121      print(Cleanup, Unset, hr, NULL);
122    }
123  }
124
125  void post_compaction(HeapRegion* hr, RegionType type) {
126    if (is_active()) {
127      print(PostCompaction, type, hr, hr->top());
128    }
129  }
130
131  void commit(HeapWord* bottom, HeapWord* end) {
132    if (is_active()) {
133      print(Commit, bottom, end);
134    }
135  }
136
137  void uncommit(HeapWord* bottom, HeapWord* end) {
138    if (is_active()) {
139      print(Uncommit, bottom, end);
140    }
141  }
142};
143
144#endif // SHARE_VM_GC_G1_G1HRPRINTER_HPP
145