src/share/vm/utilities/nativeCallStack.cpp

Thu, 19 Mar 2015 19:53:34 +0100

author
zmajo
date
Thu, 19 Mar 2015 19:53:34 +0100
changeset 7638
aefa2e84b424
parent 7078
c6211b707068
child 9337
fc1c693e80bb
permissions
-rw-r--r--

8074869: C2 code generator can replace -0.0f with +0.0f on Linux
Summary: Instead of 'fpclass', use cast float->int and double->long to check if value is +0.0f and +0.0d, respectively.
Reviewed-by: kvn, simonis, dlong

zgu@7074 1 /*
zgu@7074 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
zgu@7074 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@7074 4 *
zgu@7074 5 * This code is free software; you can redistribute it and/or modify it
zgu@7074 6 * under the terms of the GNU General Public License version 2 only, as
zgu@7074 7 * published by the Free Software Foundation.
zgu@7074 8 *
zgu@7074 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@7074 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@7074 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@7074 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@7074 13 * accompanied this code).
zgu@7074 14 *
zgu@7074 15 * You should have received a copy of the GNU General Public License version
zgu@7074 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@7074 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@7074 18 *
zgu@7074 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@7074 20 * or visit www.oracle.com if you need additional information or have any
zgu@7074 21 * questions.
zgu@7074 22 *
zgu@7074 23 */
zgu@7074 24
zgu@7074 25 #include "precompiled.hpp"
zgu@7074 26 #include "runtime/os.hpp"
zgu@7074 27 #include "utilities/globalDefinitions.hpp"
zgu@7074 28 #include "utilities/nativeCallStack.hpp"
zgu@7074 29
zgu@7078 30 const NativeCallStack NativeCallStack::EMPTY_STACK(0, false);
zgu@7074 31
zgu@7074 32 NativeCallStack::NativeCallStack(int toSkip, bool fillStack) :
zgu@7074 33 _hash_value(0) {
zgu@7074 34
zgu@7074 35 #if !PLATFORM_NATIVE_STACK_WALKING_SUPPORTED
zgu@7074 36 fillStack = false;
zgu@7074 37 #endif
zgu@7074 38
zgu@7074 39 if (fillStack) {
zgu@7074 40 os::get_native_stack(_stack, NMT_TrackingStackDepth, toSkip);
zgu@7074 41 } else {
zgu@7074 42 for (int index = 0; index < NMT_TrackingStackDepth; index ++) {
zgu@7074 43 _stack[index] = NULL;
zgu@7074 44 }
zgu@7074 45 }
zgu@7074 46 }
zgu@7074 47
zgu@7074 48 NativeCallStack::NativeCallStack(address* pc, int frameCount) {
zgu@7074 49 int frameToCopy = (frameCount < NMT_TrackingStackDepth) ?
zgu@7074 50 frameCount : NMT_TrackingStackDepth;
zgu@7074 51 int index;
zgu@7074 52 for (index = 0; index < frameToCopy; index ++) {
zgu@7074 53 _stack[index] = pc[index];
zgu@7074 54 }
zgu@7074 55 for (; index < NMT_TrackingStackDepth; index ++) {
zgu@7074 56 _stack[index] = NULL;
zgu@7074 57 }
zgu@7074 58 }
zgu@7074 59
zgu@7074 60 // number of stack frames captured
zgu@7074 61 int NativeCallStack::frames() const {
zgu@7074 62 int index;
zgu@7074 63 for (index = 0; index < NMT_TrackingStackDepth; index ++) {
zgu@7074 64 if (_stack[index] == NULL) {
zgu@7074 65 break;
zgu@7074 66 }
zgu@7074 67 }
zgu@7074 68 return index;
zgu@7074 69 }
zgu@7074 70
zgu@7074 71 // Hash code. Any better algorithm?
zgu@7074 72 int NativeCallStack::hash() const {
zgu@7074 73 long hash_val = _hash_value;
zgu@7074 74 if (hash_val == 0) {
zgu@7074 75 long pc;
zgu@7074 76 int index;
zgu@7074 77 for (index = 0; index < NMT_TrackingStackDepth; index ++) {
zgu@7074 78 pc = (long)_stack[index];
zgu@7074 79 if (pc == 0) break;
zgu@7074 80 hash_val += pc;
zgu@7074 81 }
zgu@7074 82
zgu@7074 83 NativeCallStack* p = const_cast<NativeCallStack*>(this);
zgu@7074 84 p->_hash_value = (int)(hash_val & 0xFFFFFFFF);
zgu@7074 85 }
zgu@7074 86 return _hash_value;
zgu@7074 87 }
zgu@7074 88
zgu@7074 89 void NativeCallStack::print_on(outputStream* out) const {
zgu@7074 90 print_on(out, 0);
zgu@7074 91 }
zgu@7074 92
zgu@7074 93 // Decode and print this call path
zgu@7074 94 void NativeCallStack::print_on(outputStream* out, int indent) const {
zgu@7074 95 address pc;
zgu@7074 96 char buf[1024];
zgu@7074 97 int offset;
zgu@7074 98 if (is_empty()) {
zgu@7074 99 for (int index = 0; index < indent; index ++) out->print(" ");
zgu@7074 100 #if PLATFORM_NATIVE_STACK_WALKING_SUPPORTED
zgu@7074 101 out->print("[BOOTSTRAP]");
zgu@7074 102 #else
zgu@7074 103 out->print("[No stack]");
zgu@7074 104 #endif
zgu@7074 105 } else {
zgu@7074 106 for (int frame = 0; frame < NMT_TrackingStackDepth; frame ++) {
zgu@7074 107 pc = get_frame(frame);
zgu@7074 108 if (pc == NULL) break;
zgu@7074 109 // Print indent
zgu@7074 110 for (int index = 0; index < indent; index ++) out->print(" ");
zgu@7074 111 if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
zgu@7074 112 out->print_cr("[" PTR_FORMAT "] %s+0x%x", p2i(pc), buf, offset);
zgu@7074 113 } else {
zgu@7074 114 out->print_cr("[" PTR_FORMAT "]", p2i(pc));
zgu@7074 115 }
zgu@7074 116 }
zgu@7074 117 }
zgu@7074 118 }
zgu@7074 119

mercurial