duke@435: /* brutisso@3456: * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_INTERFACE_GCCAUSE_HPP stefank@2314: #define SHARE_VM_GC_INTERFACE_GCCAUSE_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" stefank@2314: duke@435: // duke@435: // This class exposes implementation details of the various duke@435: // collector(s), and we need to be very careful with it. If duke@435: // use of this class grows, we should split it into public duke@435: // and implemenation-private "causes". duke@435: // duke@435: duke@435: class GCCause : public AllStatic { duke@435: public: duke@435: enum Cause { duke@435: /* public */ duke@435: _java_lang_system_gc, duke@435: _full_gc_alot, duke@435: _scavenge_alot, duke@435: _allocation_profiler, duke@435: _jvmti_force_gc, duke@435: _gc_locker, duke@435: _heap_inspection, duke@435: _heap_dump, duke@435: duke@435: /* implementation independent, but reserved for GC use */ duke@435: _no_gc, duke@435: _no_cause_specified, duke@435: _allocation_failure, duke@435: duke@435: /* implementation specific */ duke@435: duke@435: _tenured_generation_full, coleenp@4037: _metadata_GC_threshold, duke@435: duke@435: _cms_generation_full, duke@435: _cms_initial_mark, duke@435: _cms_final_remark, duke@435: duke@435: _old_generation_expanded_on_last_scavenge, duke@435: _old_generation_too_full_to_scavenge, duke@435: _adaptive_size_policy, duke@435: apetrusenko@1112: _g1_inc_collection_pause, brutisso@3456: _g1_humongous_allocation, ysr@777: duke@435: _last_ditch_collection, duke@435: _last_gc_cause duke@435: }; duke@435: duke@435: inline static bool is_user_requested_gc(GCCause::Cause cause) { duke@435: return (cause == GCCause::_java_lang_system_gc || duke@435: cause == GCCause::_jvmti_force_gc); duke@435: } ysr@777: duke@435: inline static bool is_serviceability_requested_gc(GCCause::Cause duke@435: cause) { duke@435: return (cause == GCCause::_jvmti_force_gc || duke@435: cause == GCCause::_heap_inspection || duke@435: cause == GCCause::_heap_dump); duke@435: } ysr@777: duke@435: // Return a string describing the GCCause. duke@435: static const char* to_string(GCCause::Cause cause); duke@435: }; stefank@2314: brutisso@3767: // Helper class for doing logging that includes the GC Cause brutisso@3767: // as a string. brutisso@3767: class GCCauseString : StackObj { brutisso@3767: private: brutisso@3767: static const int _length = 128; brutisso@3767: char _buffer[_length]; brutisso@3767: int _position; brutisso@3767: brutisso@3767: public: brutisso@3767: GCCauseString(const char* prefix, GCCause::Cause cause) { brutisso@3767: if (PrintGCCause) { jmasa@4391: _position = jio_snprintf(_buffer, _length, "%s (%s) ", prefix, GCCause::to_string(cause)); brutisso@3767: } else { jmasa@4391: _position = jio_snprintf(_buffer, _length, "%s ", prefix); brutisso@3767: } brutisso@3767: assert(_position >= 0 && _position <= _length, brutisso@3767: err_msg("Need to increase the buffer size in GCCauseString? %d", _position)); brutisso@3767: } brutisso@3767: brutisso@3767: GCCauseString& append(const char* str) { brutisso@3767: int res = jio_snprintf(_buffer + _position, _length - _position, "%s", str); brutisso@3767: _position += res; brutisso@3767: assert(res >= 0 && _position <= _length, brutisso@3767: err_msg("Need to increase the buffer size in GCCauseString? %d", res)); brutisso@3767: return *this; brutisso@3767: } brutisso@3767: brutisso@3767: operator const char*() { brutisso@3767: return _buffer; brutisso@3767: } brutisso@3767: }; brutisso@3767: stefank@2314: #endif // SHARE_VM_GC_INTERFACE_GCCAUSE_HPP