1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/nativeCallStack.hpp Wed Aug 27 08:19:12 2014 -0400 1.3 @@ -0,0 +1,95 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_UTILITIES_NATIVE_CALL_STACK_HPP 1.29 +#define SHARE_VM_UTILITIES_NATIVE_CALL_STACK_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "services/nmtCommon.hpp" 1.33 +#include "utilities/ostream.hpp" 1.34 + 1.35 +/* 1.36 + * This class represents a native call path (does not include Java frame) 1.37 + * 1.38 + * This class is developed in the context of native memory tracking, it can 1.39 + * be an useful tool for debugging purpose. 1.40 + * 1.41 + * For example, following code should print out native call path: 1.42 + * 1.43 + * .... 1.44 + * NativeCallStack here; 1.45 + * here.print_on(tty); 1.46 + * .... 1.47 + * 1.48 + * However, there are a couple of restrictions on this class. If the restrictions are 1.49 + * not strictly followed, it may break native memory tracking badly. 1.50 + * 1.51 + * 1. Number of stack frames to capture, is defined by native memory tracking. 1.52 + * This number has impacts on how much memory to be used by native 1.53 + * memory tracking. 1.54 + * 2. The class is strict stack object, no heap or virtual memory can be allocated 1.55 + * from it. 1.56 + */ 1.57 +class NativeCallStack : public StackObj { 1.58 + private: 1.59 + address _stack[NMT_TrackingStackDepth]; 1.60 + int _hash_value; 1.61 + 1.62 + public: 1.63 + NativeCallStack(int toSkip = 0, bool fillStack = false); 1.64 + NativeCallStack(address* pc, int frameCount); 1.65 + 1.66 + 1.67 + // if it is an empty stack 1.68 + inline bool is_empty() const { 1.69 + return _stack[0] == NULL; 1.70 + } 1.71 + 1.72 + // number of stack frames captured 1.73 + int frames() const; 1.74 + 1.75 + inline int compare(const NativeCallStack& other) const { 1.76 + return memcmp(_stack, other._stack, sizeof(_stack)); 1.77 + } 1.78 + 1.79 + inline bool equals(const NativeCallStack& other) const { 1.80 + // compare hash values 1.81 + if (hash() != other.hash()) return false; 1.82 + // compare each frame 1.83 + return compare(other) == 0; 1.84 + } 1.85 + 1.86 + inline address get_frame(int index) const { 1.87 + assert(index >= 0 && index < NMT_TrackingStackDepth, "Index out of bound"); 1.88 + return _stack[index]; 1.89 + } 1.90 + 1.91 + // Hash code. Any better algorithm? 1.92 + int hash() const; 1.93 + 1.94 + void print_on(outputStream* out) const; 1.95 + void print_on(outputStream* out, int indent) const; 1.96 +}; 1.97 + 1.98 +#endif