1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_interface/gcCause.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,124 @@ 1.4 +/* 1.5 + * Copyright (c) 2002, 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_INTERFACE_GCCAUSE_HPP 1.29 +#define SHARE_VM_GC_INTERFACE_GCCAUSE_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 + 1.33 +// 1.34 +// This class exposes implementation details of the various 1.35 +// collector(s), and we need to be very careful with it. If 1.36 +// use of this class grows, we should split it into public 1.37 +// and implemenation-private "causes". 1.38 +// 1.39 + 1.40 +class GCCause : public AllStatic { 1.41 + public: 1.42 + enum Cause { 1.43 + /* public */ 1.44 + _java_lang_system_gc, 1.45 + _full_gc_alot, 1.46 + _scavenge_alot, 1.47 + _allocation_profiler, 1.48 + _jvmti_force_gc, 1.49 + _gc_locker, 1.50 + _heap_inspection, 1.51 + _heap_dump, 1.52 + 1.53 + /* implementation independent, but reserved for GC use */ 1.54 + _no_gc, 1.55 + _no_cause_specified, 1.56 + _allocation_failure, 1.57 + 1.58 + /* implementation specific */ 1.59 + 1.60 + _tenured_generation_full, 1.61 + _metadata_GC_threshold, 1.62 + 1.63 + _cms_generation_full, 1.64 + _cms_initial_mark, 1.65 + _cms_final_remark, 1.66 + _cms_concurrent_mark, 1.67 + 1.68 + _old_generation_expanded_on_last_scavenge, 1.69 + _old_generation_too_full_to_scavenge, 1.70 + _adaptive_size_policy, 1.71 + 1.72 + _g1_inc_collection_pause, 1.73 + _g1_humongous_allocation, 1.74 + 1.75 + _last_ditch_collection, 1.76 + _last_gc_cause 1.77 + }; 1.78 + 1.79 + inline static bool is_user_requested_gc(GCCause::Cause cause) { 1.80 + return (cause == GCCause::_java_lang_system_gc || 1.81 + cause == GCCause::_jvmti_force_gc); 1.82 + } 1.83 + 1.84 + inline static bool is_serviceability_requested_gc(GCCause::Cause 1.85 + cause) { 1.86 + return (cause == GCCause::_jvmti_force_gc || 1.87 + cause == GCCause::_heap_inspection || 1.88 + cause == GCCause::_heap_dump); 1.89 + } 1.90 + 1.91 + // Return a string describing the GCCause. 1.92 + static const char* to_string(GCCause::Cause cause); 1.93 +}; 1.94 + 1.95 +// Helper class for doing logging that includes the GC Cause 1.96 +// as a string. 1.97 +class GCCauseString : StackObj { 1.98 + private: 1.99 + static const int _length = 128; 1.100 + char _buffer[_length]; 1.101 + int _position; 1.102 + 1.103 + public: 1.104 + GCCauseString(const char* prefix, GCCause::Cause cause) { 1.105 + if (PrintGCCause) { 1.106 + _position = jio_snprintf(_buffer, _length, "%s (%s) ", prefix, GCCause::to_string(cause)); 1.107 + } else { 1.108 + _position = jio_snprintf(_buffer, _length, "%s ", prefix); 1.109 + } 1.110 + assert(_position >= 0 && _position <= _length, 1.111 + err_msg("Need to increase the buffer size in GCCauseString? %d", _position)); 1.112 + } 1.113 + 1.114 + GCCauseString& append(const char* str) { 1.115 + int res = jio_snprintf(_buffer + _position, _length - _position, "%s", str); 1.116 + _position += res; 1.117 + assert(res >= 0 && _position <= _length, 1.118 + err_msg("Need to increase the buffer size in GCCauseString? %d", res)); 1.119 + return *this; 1.120 + } 1.121 + 1.122 + operator const char*() { 1.123 + return _buffer; 1.124 + } 1.125 +}; 1.126 + 1.127 +#endif // SHARE_VM_GC_INTERFACE_GCCAUSE_HPP