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