Path: blob/master/src/hotspot/share/services/heapDumper.hpp
41144 views
/*1* Copyright (c) 2005, 2020, 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_SERVICES_HEAPDUMPER_HPP25#define SHARE_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 outputStream;4445class HeapDumper : public StackObj {46private:47char* _error;48bool _gc_before_heap_dump;49bool _oome;50elapsedTimer _t;5152HeapDumper(bool gc_before_heap_dump, bool oome) :53_error(NULL), _gc_before_heap_dump(gc_before_heap_dump), _oome(oome) { }5455// string representation of error56char* error() const { return _error; }57void set_error(char const* error);5859// internal timer.60elapsedTimer* timer() { return &_t; }6162static void dump_heap(bool oome);6364public:65HeapDumper(bool gc_before_heap_dump) :66_error(NULL), _gc_before_heap_dump(gc_before_heap_dump), _oome(false) { }6768~HeapDumper();6970// dumps the heap to the specified file, returns 0 if success.71// additional info is written to out if not NULL.72// compression >= 0 creates a gzipped file with the given compression level.73int dump(const char* path, outputStream* out = NULL, int compression = -1);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_SERVICES_HEAPDUMPER_HPP848586