author | stefank |
Mon, 25 Nov 2019 12:33:15 +0100 | |
changeset 59252 | 623722a6aeb9 |
parent 50965 | 29eaf3feab30 |
permissions | -rw-r--r-- |
25946 | 1 |
/* |
49721
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
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 |
#include "precompiled.hpp" |
|
26 |
#include "runtime/os.hpp" |
|
49721
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
27 |
#include "utilities/decoder.hpp" |
25946 | 28 |
#include "utilities/globalDefinitions.hpp" |
29 |
#include "utilities/nativeCallStack.hpp" |
|
30 |
||
31 |
NativeCallStack::NativeCallStack(int toSkip, bool fillStack) : |
|
32 |
_hash_value(0) { |
|
33 |
||
34 |
if (fillStack) { |
|
40383
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
35 |
// We need to skip the NativeCallStack::NativeCallStack frame if a tail call is NOT used |
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
36 |
// to call os::get_native_stack. A tail call is used if _NMT_NOINLINE_ is not defined |
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
37 |
// (which means this is not a slowdebug build), and we are on 64-bit (except Windows). |
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
38 |
// This is not necessarily a rule, but what has been obvserved to date. |
49725
e740e1a38c96
8200550: Xcode 9.3 produce warning -Wexpansion-to-defined
kbarrett
parents:
49721
diff
changeset
|
39 |
#if (defined(_NMT_NOINLINE_) || defined(_WINDOWS) || !defined(_LP64)) |
e740e1a38c96
8200550: Xcode 9.3 produce warning -Wexpansion-to-defined
kbarrett
parents:
49721
diff
changeset
|
40 |
// Not a tail call. |
40383
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
41 |
toSkip++; |
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
42 |
#if (defined(_NMT_NOINLINE_) && defined(BSD) && defined(_LP64)) |
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
43 |
// Mac OS X slowdebug builds have this odd behavior where NativeCallStack::NativeCallStack |
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
44 |
// appears as two frames, so we need to skip an extra frame. |
1ebc8c5aed30
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
29574
diff
changeset
|
45 |
toSkip++; |
49725
e740e1a38c96
8200550: Xcode 9.3 produce warning -Wexpansion-to-defined
kbarrett
parents:
49721
diff
changeset
|
46 |
#endif // Special-case for BSD. |
e740e1a38c96
8200550: Xcode 9.3 produce warning -Wexpansion-to-defined
kbarrett
parents:
49721
diff
changeset
|
47 |
#endif // Not a tail call. |
25946 | 48 |
os::get_native_stack(_stack, NMT_TrackingStackDepth, toSkip); |
49 |
} else { |
|
50 |
for (int index = 0; index < NMT_TrackingStackDepth; index ++) { |
|
51 |
_stack[index] = NULL; |
|
52 |
} |
|
53 |
} |
|
54 |
} |
|
55 |
||
56 |
NativeCallStack::NativeCallStack(address* pc, int frameCount) { |
|
57 |
int frameToCopy = (frameCount < NMT_TrackingStackDepth) ? |
|
58 |
frameCount : NMT_TrackingStackDepth; |
|
59 |
int index; |
|
60 |
for (index = 0; index < frameToCopy; index ++) { |
|
61 |
_stack[index] = pc[index]; |
|
62 |
} |
|
63 |
for (; index < NMT_TrackingStackDepth; index ++) { |
|
64 |
_stack[index] = NULL; |
|
65 |
} |
|
29462
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
66 |
_hash_value = 0; |
25946 | 67 |
} |
68 |
||
69 |
// number of stack frames captured |
|
70 |
int NativeCallStack::frames() const { |
|
71 |
int index; |
|
72 |
for (index = 0; index < NMT_TrackingStackDepth; index ++) { |
|
73 |
if (_stack[index] == NULL) { |
|
74 |
break; |
|
75 |
} |
|
76 |
} |
|
77 |
return index; |
|
78 |
} |
|
79 |
||
80 |
// Hash code. Any better algorithm? |
|
29462
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
81 |
unsigned int NativeCallStack::hash() const { |
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
82 |
uintptr_t hash_val = _hash_value; |
25946 | 83 |
if (hash_val == 0) { |
29462
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
84 |
for (int index = 0; index < NMT_TrackingStackDepth; index++) { |
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
85 |
if (_stack[index] == NULL) break; |
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
86 |
hash_val += (uintptr_t)_stack[index]; |
25946 | 87 |
} |
88 |
||
89 |
NativeCallStack* p = const_cast<NativeCallStack*>(this); |
|
29462
f2e2922222a4
8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents:
26144
diff
changeset
|
90 |
p->_hash_value = (unsigned int)(hash_val & 0xFFFFFFFF); |
25946 | 91 |
} |
92 |
return _hash_value; |
|
93 |
} |
|
94 |
||
95 |
void NativeCallStack::print_on(outputStream* out) const { |
|
96 |
print_on(out, 0); |
|
97 |
} |
|
98 |
||
99 |
// Decode and print this call path |
|
100 |
void NativeCallStack::print_on(outputStream* out, int indent) const { |
|
101 |
address pc; |
|
102 |
char buf[1024]; |
|
103 |
int offset; |
|
49721
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
104 |
int line_no; |
25946 | 105 |
if (is_empty()) { |
106 |
for (int index = 0; index < indent; index ++) out->print(" "); |
|
107 |
out->print("[BOOTSTRAP]"); |
|
108 |
} else { |
|
109 |
for (int frame = 0; frame < NMT_TrackingStackDepth; frame ++) { |
|
110 |
pc = get_frame(frame); |
|
111 |
if (pc == NULL) break; |
|
112 |
// Print indent |
|
113 |
for (int index = 0; index < indent; index ++) out->print(" "); |
|
114 |
if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) { |
|
49721
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
115 |
out->print("[" PTR_FORMAT "] %s+0x%x", p2i(pc), buf, offset); |
25946 | 116 |
} else { |
49721
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
117 |
out->print("[" PTR_FORMAT "]", p2i(pc)); |
25946 | 118 |
} |
49721
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
119 |
|
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
120 |
if (Decoder::get_source_info(pc, buf, sizeof(buf), &line_no)) { |
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
121 |
out->print(" (%s:%d)", buf, line_no); |
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
122 |
} |
ea0cc7c74e75
8201242: Include source file/line number when reporting native call stack on supported platforms
zgu
parents:
47216
diff
changeset
|
123 |
out->cr(); |
25946 | 124 |
} |
125 |
} |
|
126 |
} |