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 31 #define SKIP_RETIRED_FULL_REGIONS 1 32 33 class G1HRPrinter { 34 35 private: 36 37 // Print an action event. 38 static void print(const char* action, HeapRegion* hr) { 39 log_trace(gc, region)("G1HR %s(%s) [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]", 40 action, hr->get_type_str(), p2i(hr->bottom()), p2i(hr->top()), p2i(hr->end())); 41 } 42 43 public: 44 // In some places we iterate over a list in order to generate output 45 // for the list's elements. By exposing this we can avoid this 46 // iteration if the printer is not active. 47 const bool is_active() { return log_is_enabled(Trace, gc, region); } 48 49 // The methods below are convenient wrappers for the print() method. 50 51 void alloc(HeapRegion* hr, bool force = false) { 52 if (is_active()) { 53 print((force) ? "ALLOC-FORCE" : "ALLOC", hr); 54 } 55 } 56 57 void retire(HeapRegion* hr) { 58 if (is_active()) { 59 if (!SKIP_RETIRED_FULL_REGIONS || hr->top() < hr->end()) { 60 print("RETIRE", hr); 61 } 62 } 63 } 64 65 void reuse(HeapRegion* hr) { 66 if (is_active()) { 67 print("REUSE", hr); 68 } 69 } 70 71 void cset(HeapRegion* hr) { 72 if (is_active()) { 73 print("CSET", hr); 74 } 75 } 76 77 void evac_failure(HeapRegion* hr) { 78 if (is_active()) { 79 print("EVAC-FAILURE", hr); 80 } 81 } 82 83 void cleanup(HeapRegion* hr) { 84 if (is_active()) { 85 print("CLEANUP", hr); 86 } 87 } 88 89 void post_compaction(HeapRegion* hr) { 90 if (is_active()) { 91 print("POST-COMPACTION", hr); 92 } 93 } 94 95 void commit(HeapRegion* hr) { 96 if (is_active()) { 97 print("COMMIT", hr); 98 } 99 } 100 101 void uncommit(HeapRegion* hr) { 102 if (is_active()) { 103 print("UNCOMMIT", hr); 104 } 105 } 106 }; 107 108 #endif // SHARE_VM_GC_G1_G1HRPRINTER_HPP