0N/A/*
4170N/A * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_SERVICES_HEAPDUMPER_HPP
1879N/A#define SHARE_VM_SERVICES_HEAPDUMPER_HPP
1879N/A
1879N/A#include "memory/allocation.hpp"
1879N/A#include "oops/klassOop.hpp"
1879N/A#include "oops/oop.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A
0N/A// HeapDumper is used to dump the java heap to file in HPROF binary format:
0N/A//
0N/A// { HeapDumper dumper(true /* full GC before heap dump */);
0N/A// if (dumper.dump("/export/java.hprof")) {
0N/A// ResourceMark rm;
0N/A// tty->print_cr("Dump failed: %s", dumper.error_as_C_string());
0N/A// } else {
0N/A// // dump succeeded
0N/A// }
0N/A// }
0N/A//
0N/A
0N/Aclass HeapDumper : public StackObj {
0N/A private:
0N/A char* _error;
0N/A bool _print_to_tty;
0N/A bool _gc_before_heap_dump;
1695N/A bool _oome;
0N/A elapsedTimer _t;
0N/A
1695N/A HeapDumper(bool gc_before_heap_dump, bool print_to_tty, bool oome) :
1695N/A _gc_before_heap_dump(gc_before_heap_dump), _error(NULL), _print_to_tty(print_to_tty), _oome(oome) { }
1695N/A
0N/A // string representation of error
0N/A char* error() const { return _error; }
0N/A void set_error(char* error);
0N/A
0N/A // indicates if progress messages can be sent to tty
0N/A bool print_to_tty() const { return _print_to_tty; }
0N/A
0N/A // internal timer.
0N/A elapsedTimer* timer() { return &_t; }
0N/A
1695N/A static void dump_heap(bool oome);
1695N/A
0N/A public:
0N/A HeapDumper(bool gc_before_heap_dump) :
1695N/A _gc_before_heap_dump(gc_before_heap_dump), _error(NULL), _print_to_tty(false), _oome(false) { }
0N/A
0N/A ~HeapDumper();
0N/A
0N/A // dumps the heap to the specified file, returns 0 if success.
0N/A int dump(const char* path);
0N/A
0N/A // returns error message (resource allocated), or NULL if no error
0N/A char* error_as_C_string() const;
0N/A
4170N/A static void dump_heap();
1695N/A
4170N/A static void dump_heap_from_oome();
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_SERVICES_HEAPDUMPER_HPP