author | zgu |
Wed, 11 Jul 2018 13:28:07 -0400 | |
changeset 50965 | 29eaf3feab30 |
parent 50904 | b9c7eb8d8972 |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
25946 | 1 |
/* |
50904
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
25946 | 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 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef SHARE_VM_UTILITIES_NATIVE_CALL_STACK_HPP |
|
26 |
#define SHARE_VM_UTILITIES_NATIVE_CALL_STACK_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "services/nmtCommon.hpp" |
|
30 |
#include "utilities/ostream.hpp" |
|
31 |
||
32 |
/* |
|
33 |
* This class represents a native call path (does not include Java frame) |
|
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 |
*/ |
|
50904
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
54 |
class MemTracker; |
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
55 |
|
25946 | 56 |
class NativeCallStack : public StackObj { |
50904
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
57 |
private: |
29462
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
58 |
address _stack[NMT_TrackingStackDepth]; |
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
59 |
unsigned int _hash_value; |
25946 | 60 |
|
50904
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
61 |
public: |
25946 | 62 |
NativeCallStack(int toSkip = 0, bool fillStack = false); |
63 |
NativeCallStack(address* pc, int frameCount); |
|
64 |
||
50904
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
65 |
static inline const NativeCallStack& empty_stack() { |
50965
29eaf3feab30
8206183: Possible construct EMPTY_STACK and allocation stack, etc. on first use
zgu
parents:
50904
diff
changeset
|
66 |
static const NativeCallStack EMPTY_STACK(0, false); |
50904
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
67 |
return EMPTY_STACK; |
b9c7eb8d8972
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
zgu
parents:
47216
diff
changeset
|
68 |
} |
25946 | 69 |
|
70 |
// if it is an empty stack |
|
71 |
inline bool is_empty() const { |
|
72 |
return _stack[0] == NULL; |
|
73 |
} |
|
74 |
||
75 |
// number of stack frames captured |
|
76 |
int frames() const; |
|
77 |
||
78 |
inline int compare(const NativeCallStack& other) const { |
|
79 |
return memcmp(_stack, other._stack, sizeof(_stack)); |
|
80 |
} |
|
81 |
||
82 |
inline bool equals(const NativeCallStack& other) const { |
|
83 |
// compare hash values |
|
84 |
if (hash() != other.hash()) return false; |
|
85 |
// compare each frame |
|
86 |
return compare(other) == 0; |
|
87 |
} |
|
88 |
||
89 |
inline address get_frame(int index) const { |
|
90 |
assert(index >= 0 && index < NMT_TrackingStackDepth, "Index out of bound"); |
|
91 |
return _stack[index]; |
|
92 |
} |
|
93 |
||
94 |
// Hash code. Any better algorithm? |
|
29462
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
95 |
unsigned int hash() const; |
25946 | 96 |
|
97 |
void print_on(outputStream* out) const; |
|
98 |
void print_on(outputStream* out, int indent) const; |
|
99 |
}; |
|
100 |
||
101 |
#endif |