Thu, 28 Jun 2012 17:03:16 -0400
6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain
zgu@2364 | 1 | /* |
zgu@3544 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
zgu@2364 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
zgu@2364 | 4 | * |
zgu@2364 | 5 | * This code is free software; you can redistribute it and/or modify it |
zgu@2364 | 6 | * under the terms of the GNU General Public License version 2 only, as |
zgu@2364 | 7 | * published by the Free Software Foundation. |
zgu@2364 | 8 | * |
zgu@2364 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
zgu@2364 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
zgu@2364 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
zgu@2364 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
zgu@2364 | 13 | * accompanied this code). |
zgu@2364 | 14 | * |
zgu@2364 | 15 | * You should have received a copy of the GNU General Public License version |
zgu@2364 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
zgu@2364 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
zgu@2364 | 18 | * |
zgu@2364 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
zgu@2364 | 20 | * or visit www.oracle.com if you need additional information or have any |
zgu@2364 | 21 | * questions. |
zgu@2364 | 22 | * |
zgu@2364 | 23 | */ |
zgu@2364 | 24 | |
zgu@2364 | 25 | |
zgu@3430 | 26 | #ifndef SHARE_VM_UTILITIES_DECODER_HPP |
zgu@3430 | 27 | #define SHARE_VM_UTILITIES_DECODER_HPP |
zgu@2364 | 28 | |
zgu@2364 | 29 | #include "memory/allocation.hpp" |
zgu@3430 | 30 | #include "runtime/mutex.hpp" |
zgu@2364 | 31 | |
zgu@3900 | 32 | class AbstractDecoder : public CHeapObj<mtInternal> { |
zgu@3430 | 33 | public: |
zgu@2364 | 34 | // status code for decoding native C frame |
zgu@2364 | 35 | enum decoder_status { |
zgu@3430 | 36 | not_available = -10, // real decoder is not available |
zgu@3430 | 37 | no_error = 0, // successfully decoded frames |
zgu@2364 | 38 | out_of_memory, // out of memory |
zgu@2364 | 39 | file_invalid, // invalid elf file |
zgu@2364 | 40 | file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map |
zgu@2364 | 41 | helper_not_found, // could not load dbghelp.dll (Windows only) |
zgu@2364 | 42 | helper_func_error, // decoding functions not found (Windows only) |
zgu@3430 | 43 | helper_init_error // SymInitialize failed (Windows only) |
zgu@2364 | 44 | }; |
zgu@2364 | 45 | |
zgu@3544 | 46 | // decode an pc address to corresponding function name and an offset from the beginning of |
zgu@3544 | 47 | // the function |
zgu@3544 | 48 | virtual bool decode(address pc, char* buf, int buflen, int* offset, |
zgu@3544 | 49 | const char* modulepath = NULL) = 0; |
zgu@3544 | 50 | // demangle a C++ symbol |
zgu@3544 | 51 | virtual bool demangle(const char* symbol, char* buf, int buflen) = 0; |
zgu@3544 | 52 | // if the decoder can decode symbols in vm |
zgu@3544 | 53 | virtual bool can_decode_C_frame_in_vm() const = 0; |
zgu@3544 | 54 | |
zgu@3544 | 55 | virtual decoder_status status() const { |
zgu@3544 | 56 | return _decoder_status; |
zgu@3544 | 57 | } |
zgu@3544 | 58 | |
zgu@3544 | 59 | virtual bool has_error() const { |
zgu@3544 | 60 | return is_error(_decoder_status); |
zgu@3544 | 61 | } |
zgu@3544 | 62 | |
zgu@3544 | 63 | static bool is_error(decoder_status status) { |
zgu@3544 | 64 | return (status > 0); |
zgu@3544 | 65 | } |
zgu@3544 | 66 | |
zgu@3544 | 67 | protected: |
zgu@3544 | 68 | decoder_status _decoder_status; |
zgu@3544 | 69 | }; |
zgu@3544 | 70 | |
zgu@3544 | 71 | // Do nothing decoder |
zgu@3544 | 72 | class NullDecoder : public AbstractDecoder { |
zgu@3544 | 73 | public: |
zgu@3430 | 74 | NullDecoder() { |
zgu@3430 | 75 | _decoder_status = not_available; |
zgu@3430 | 76 | } |
zgu@2364 | 77 | |
zgu@3430 | 78 | ~NullDecoder() {}; |
zgu@3430 | 79 | |
zgu@3430 | 80 | virtual bool decode(address pc, char* buf, int buflen, int* offset, |
zgu@3430 | 81 | const char* modulepath = NULL) { |
zgu@3430 | 82 | return false; |
zgu@3430 | 83 | } |
zgu@3430 | 84 | |
zgu@3430 | 85 | virtual bool demangle(const char* symbol, char* buf, int buflen) { |
zgu@3430 | 86 | return false; |
zgu@3430 | 87 | } |
zgu@3430 | 88 | |
zgu@3430 | 89 | virtual bool can_decode_C_frame_in_vm() const { |
zgu@3430 | 90 | return false; |
zgu@3430 | 91 | } |
zgu@3430 | 92 | }; |
zgu@3430 | 93 | |
zgu@3430 | 94 | |
zgu@3544 | 95 | class Decoder : AllStatic { |
zgu@3430 | 96 | public: |
zgu@3430 | 97 | static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL); |
zgu@3430 | 98 | static bool demangle(const char* symbol, char* buf, int buflen); |
zgu@2364 | 99 | static bool can_decode_C_frame_in_vm(); |
zgu@2364 | 100 | |
zgu@3544 | 101 | // shutdown shared instance |
zgu@3430 | 102 | static void shutdown(); |
zgu@3430 | 103 | protected: |
zgu@3544 | 104 | // shared decoder instance, _shared_instance_lock is needed |
zgu@3544 | 105 | static AbstractDecoder* get_shared_instance(); |
zgu@3544 | 106 | // a private instance for error handler. Error handler can be |
zgu@3544 | 107 | // triggered almost everywhere, including signal handler, where |
zgu@3544 | 108 | // no lock can be taken. So the shared decoder can not be used |
zgu@3544 | 109 | // in this scenario. |
zgu@3544 | 110 | static AbstractDecoder* get_error_handler_instance(); |
zgu@2364 | 111 | |
zgu@3544 | 112 | static AbstractDecoder* create_decoder(); |
zgu@3430 | 113 | private: |
zgu@3544 | 114 | static AbstractDecoder* _shared_decoder; |
zgu@3544 | 115 | static AbstractDecoder* _error_handler_decoder; |
zgu@3544 | 116 | static NullDecoder _do_nothing_decoder; |
zgu@2364 | 117 | |
zgu@3430 | 118 | protected: |
zgu@3544 | 119 | static Mutex* _shared_decoder_lock; |
zgu@2364 | 120 | }; |
zgu@2364 | 121 | |
zgu@3430 | 122 | #endif // SHARE_VM_UTILITIES_DECODER_HPP |