Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/services/heapDumper.hpp
32285 views
/*1* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_SERVICES_HEAPDUMPER_HPP25#define SHARE_VM_SERVICES_HEAPDUMPER_HPP2627#include "memory/allocation.hpp"28#include "oops/oop.hpp"29#include "runtime/os.hpp"3031// HeapDumper is used to dump the java heap to file in HPROF binary format:32//33// { HeapDumper dumper(true /* full GC before heap dump */);34// if (dumper.dump("/export/java.hprof")) {35// ResourceMark rm;36// tty->print_cr("Dump failed: %s", dumper.error_as_C_string());37// } else {38// // dump succeeded39// }40// }41//4243class HeapDumper : public StackObj {44private:45char* _error;46bool _print_to_tty;47bool _gc_before_heap_dump;48bool _oome;49elapsedTimer _t;5051HeapDumper(bool gc_before_heap_dump, bool print_to_tty, bool oome) :52_gc_before_heap_dump(gc_before_heap_dump), _error(NULL), _print_to_tty(print_to_tty), _oome(oome) { }5354// string representation of error55char* error() const { return _error; }56void set_error(char* error);5758// indicates if progress messages can be sent to tty59bool print_to_tty() const { return _print_to_tty; }6061// internal timer.62elapsedTimer* timer() { return &_t; }6364static void dump_heap(bool oome);6566public:67HeapDumper(bool gc_before_heap_dump) :68_gc_before_heap_dump(gc_before_heap_dump), _error(NULL), _print_to_tty(false), _oome(false) { }6970~HeapDumper();7172// dumps the heap to the specified file, returns 0 if success.73int dump(const char* path);7475// returns error message (resource allocated), or NULL if no error76char* error_as_C_string() const;7778static void dump_heap() NOT_SERVICES_RETURN;7980static void dump_heap_from_oome() NOT_SERVICES_RETURN;81};8283#endif // SHARE_VM_SERVICES_HEAPDUMPER_HPP848586