Wed, 03 Jul 2019 20:42:37 +0800
Merge
zgu@7074 | 1 | /* |
zgu@9485 | 2 | * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
zgu@7074 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
zgu@7074 | 4 | * |
zgu@7074 | 5 | * This code is free software; you can redistribute it and/or modify it |
zgu@7074 | 6 | * under the terms of the GNU General Public License version 2 only, as |
zgu@7074 | 7 | * published by the Free Software Foundation. |
zgu@7074 | 8 | * |
zgu@7074 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
zgu@7074 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
zgu@7074 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
zgu@7074 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
zgu@7074 | 13 | * accompanied this code). |
zgu@7074 | 14 | * |
zgu@7074 | 15 | * You should have received a copy of the GNU General Public License version |
zgu@7074 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
zgu@7074 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
zgu@7074 | 18 | * |
zgu@7074 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
zgu@7074 | 20 | * or visit www.oracle.com if you need additional information or have any |
zgu@7074 | 21 | * questions. |
zgu@7074 | 22 | * |
zgu@7074 | 23 | */ |
zgu@7074 | 24 | |
zgu@7074 | 25 | #ifndef SHARE_VM_UTILITIES_NATIVE_CALL_STACK_HPP |
zgu@7074 | 26 | #define SHARE_VM_UTILITIES_NATIVE_CALL_STACK_HPP |
zgu@7074 | 27 | |
zgu@7074 | 28 | #include "memory/allocation.hpp" |
zgu@7074 | 29 | #include "services/nmtCommon.hpp" |
zgu@7074 | 30 | #include "utilities/ostream.hpp" |
zgu@7074 | 31 | |
zgu@7074 | 32 | /* |
zgu@7074 | 33 | * This class represents a native call path (does not include Java frame) |
zgu@7074 | 34 | * |
zgu@7074 | 35 | * This class is developed in the context of native memory tracking, it can |
zgu@7074 | 36 | * be an useful tool for debugging purpose. |
zgu@7074 | 37 | * |
zgu@7074 | 38 | * For example, following code should print out native call path: |
zgu@7074 | 39 | * |
zgu@7074 | 40 | * .... |
zgu@7074 | 41 | * NativeCallStack here; |
zgu@7074 | 42 | * here.print_on(tty); |
zgu@7074 | 43 | * .... |
zgu@7074 | 44 | * |
zgu@7074 | 45 | * However, there are a couple of restrictions on this class. If the restrictions are |
zgu@7074 | 46 | * not strictly followed, it may break native memory tracking badly. |
zgu@7074 | 47 | * |
zgu@7074 | 48 | * 1. Number of stack frames to capture, is defined by native memory tracking. |
zgu@7074 | 49 | * This number has impacts on how much memory to be used by native |
zgu@7074 | 50 | * memory tracking. |
zgu@7074 | 51 | * 2. The class is strict stack object, no heap or virtual memory can be allocated |
zgu@7074 | 52 | * from it. |
zgu@7074 | 53 | */ |
zgu@9485 | 54 | class MemTracker; |
zgu@9485 | 55 | |
zgu@7074 | 56 | class NativeCallStack : public StackObj { |
zgu@9485 | 57 | friend class MemTracker; |
zgu@7078 | 58 | |
zgu@9485 | 59 | private: |
kevinw@9337 | 60 | address _stack[NMT_TrackingStackDepth]; |
kevinw@9337 | 61 | unsigned int _hash_value; |
zgu@7074 | 62 | |
zgu@9485 | 63 | static NativeCallStack EMPTY_STACK; |
zgu@9485 | 64 | public: |
zgu@7074 | 65 | NativeCallStack(int toSkip = 0, bool fillStack = false); |
zgu@7074 | 66 | NativeCallStack(address* pc, int frameCount); |
zgu@7074 | 67 | |
zgu@9485 | 68 | static inline const NativeCallStack& empty_stack() { |
zgu@9485 | 69 | return EMPTY_STACK; |
zgu@9485 | 70 | } |
zgu@7074 | 71 | |
zgu@7074 | 72 | // if it is an empty stack |
zgu@7074 | 73 | inline bool is_empty() const { |
zgu@7074 | 74 | return _stack[0] == NULL; |
zgu@7074 | 75 | } |
zgu@7074 | 76 | |
zgu@7074 | 77 | // number of stack frames captured |
zgu@7074 | 78 | int frames() const; |
zgu@7074 | 79 | |
zgu@7074 | 80 | inline int compare(const NativeCallStack& other) const { |
zgu@7074 | 81 | return memcmp(_stack, other._stack, sizeof(_stack)); |
zgu@7074 | 82 | } |
zgu@7074 | 83 | |
zgu@7074 | 84 | inline bool equals(const NativeCallStack& other) const { |
zgu@7074 | 85 | // compare hash values |
zgu@7074 | 86 | if (hash() != other.hash()) return false; |
zgu@7074 | 87 | // compare each frame |
zgu@7074 | 88 | return compare(other) == 0; |
zgu@7074 | 89 | } |
zgu@7074 | 90 | |
zgu@7074 | 91 | inline address get_frame(int index) const { |
zgu@7074 | 92 | assert(index >= 0 && index < NMT_TrackingStackDepth, "Index out of bound"); |
zgu@7074 | 93 | return _stack[index]; |
zgu@7074 | 94 | } |
zgu@7074 | 95 | |
zgu@7074 | 96 | // Hash code. Any better algorithm? |
kevinw@9337 | 97 | unsigned int hash() const; |
zgu@7074 | 98 | |
zgu@7074 | 99 | void print_on(outputStream* out) const; |
zgu@7074 | 100 | void print_on(outputStream* out, int indent) const; |
zgu@7074 | 101 | }; |
zgu@7074 | 102 | |
zgu@7074 | 103 | #endif |