1 /*
2 * Copyright (c) 2014, 2015, 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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "runtime/os.hpp"
27 #include "utilities/globalDefinitions.hpp"
28 #include "utilities/nativeCallStack.hpp"
29
30 const NativeCallStack NativeCallStack::EMPTY_STACK(0, false);
31
32 NativeCallStack::NativeCallStack(int toSkip, bool fillStack) :
33 _hash_value(0) {
34
35 if (fillStack) {
36 os::get_native_stack(_stack, NMT_TrackingStackDepth, toSkip);
37 } else {
38 for (int index = 0; index < NMT_TrackingStackDepth; index ++) {
39 _stack[index] = NULL;
40 }
41 }
42 }
43
44 NativeCallStack::NativeCallStack(address* pc, int frameCount) {
45 int frameToCopy = (frameCount < NMT_TrackingStackDepth) ?
46 frameCount : NMT_TrackingStackDepth;
47 int index;
48 for (index = 0; index < frameToCopy; index ++) {
49 _stack[index] = pc[index];
50 }
51 for (; index < NMT_TrackingStackDepth; index ++) {
52 _stack[index] = NULL;
53 }
54 _hash_value = 0;
55 }
|
1 /*
2 * Copyright (c) 2014, 2016, 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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "runtime/os.hpp"
27 #include "utilities/globalDefinitions.hpp"
28 #include "utilities/nativeCallStack.hpp"
29
30 const NativeCallStack NativeCallStack::EMPTY_STACK(0, false);
31
32 NativeCallStack::NativeCallStack(int toSkip, bool fillStack) :
33 _hash_value(0) {
34
35 if (fillStack) {
36 // We need to skip the NativeCallStack::NativeCallStack frame if a tail call is NOT used
37 // to call os::get_native_stack. A tail call is used if _NMT_NOINLINE_ is not defined
38 // (which means this is not a slowdebug build), and we are on 64-bit (except Windows).
39 // This is not necessarily a rule, but what has been obvserved to date.
40 #define TAIL_CALL (!defined(_NMT_NOINLINE_) && !defined(WINDOWS) && defined(_LP64))
41 #if !TAIL_CALL
42 toSkip++;
43 #if (defined(_NMT_NOINLINE_) && defined(BSD) && defined(_LP64))
44 // Mac OS X slowdebug builds have this odd behavior where NativeCallStack::NativeCallStack
45 // appears as two frames, so we need to skip an extra frame.
46 toSkip++;
47 #endif
48 #endif
49 os::get_native_stack(_stack, NMT_TrackingStackDepth, toSkip);
50 } else {
51 for (int index = 0; index < NMT_TrackingStackDepth; index ++) {
52 _stack[index] = NULL;
53 }
54 }
55 }
56
57 NativeCallStack::NativeCallStack(address* pc, int frameCount) {
58 int frameToCopy = (frameCount < NMT_TrackingStackDepth) ?
59 frameCount : NMT_TrackingStackDepth;
60 int index;
61 for (index = 0; index < frameToCopy; index ++) {
62 _stack[index] = pc[index];
63 }
64 for (; index < NMT_TrackingStackDepth; index ++) {
65 _stack[index] = NULL;
66 }
67 _hash_value = 0;
68 }
|