hotspot/src/share/vm/utilities/nativeCallStack.cpp
author coleenp
Fri, 13 Nov 2015 16:50:39 -0500
changeset 34139 0728fe06ccf8
parent 29574 ab0121071f54
child 40383 1ebc8c5aed30
permissions -rw-r--r--
8027429: Add diagnostic command VM.info to get hs_err print-out Summary: refactored hs_err reporting code so that it can be used for VM.info safely Reviewed-by: dholmes, hseigel Contributed-by: coleen.phillimore@oracle.com, david.buck@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     1
/*
29574
ab0121071f54 8069111: Investigate NMT detail tracking support for 32bit ARM
cjplummer
parents: 29462
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     4
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     8
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    13
 * accompanied this code).
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    14
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    18
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    21
 * questions.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    22
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    23
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    24
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    25
#include "precompiled.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    26
#include "runtime/os.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    27
#include "utilities/globalDefinitions.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    28
#include "utilities/nativeCallStack.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    29
26144
35e11b657728 8055007: NMT2: emptyStack missing in minimal build
zgu
parents: 25946
diff changeset
    30
const NativeCallStack NativeCallStack::EMPTY_STACK(0, false);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    31
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    32
NativeCallStack::NativeCallStack(int toSkip, bool fillStack) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    33
  _hash_value(0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    34
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    35
  if (fillStack) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    36
    os::get_native_stack(_stack, NMT_TrackingStackDepth, toSkip);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    37
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    38
    for (int index = 0; index < NMT_TrackingStackDepth; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    39
      _stack[index] = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    40
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    41
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    42
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    43
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    44
NativeCallStack::NativeCallStack(address* pc, int frameCount) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    45
  int frameToCopy = (frameCount < NMT_TrackingStackDepth) ?
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    46
    frameCount : NMT_TrackingStackDepth;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    47
  int index;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    48
  for (index = 0; index < frameToCopy; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    49
    _stack[index] = pc[index];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    50
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    51
  for (; index < NMT_TrackingStackDepth; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    52
    _stack[index] = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    53
  }
29462
f2e2922222a4 8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents: 26144
diff changeset
    54
  _hash_value = 0;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    55
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    56
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    57
// number of stack frames captured
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    58
int NativeCallStack::frames() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    59
  int index;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    60
  for (index = 0; index < NMT_TrackingStackDepth; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    61
    if (_stack[index] == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    62
      break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    63
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    64
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    65
  return index;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    66
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    67
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    68
// Hash code. Any better algorithm?
29462
f2e2922222a4 8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents: 26144
diff changeset
    69
unsigned int NativeCallStack::hash() const {
f2e2922222a4 8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents: 26144
diff changeset
    70
  uintptr_t hash_val = _hash_value;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    71
  if (hash_val == 0) {
29462
f2e2922222a4 8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents: 26144
diff changeset
    72
    for (int index = 0; index < NMT_TrackingStackDepth; index++) {
f2e2922222a4 8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents: 26144
diff changeset
    73
      if (_stack[index] == NULL) break;
f2e2922222a4 8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents: 26144
diff changeset
    74
      hash_val += (uintptr_t)_stack[index];
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    75
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    76
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    77
    NativeCallStack* p = const_cast<NativeCallStack*>(this);
29462
f2e2922222a4 8069124: runtime/NMT/MallocSiteHashOverflow.java failing in nightlies
ctornqvi
parents: 26144
diff changeset
    78
    p->_hash_value = (unsigned int)(hash_val & 0xFFFFFFFF);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    79
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    80
  return _hash_value;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    81
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    82
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    83
void NativeCallStack::print_on(outputStream* out) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    84
  print_on(out, 0);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    85
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    86
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    87
// Decode and print this call path
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    88
void NativeCallStack::print_on(outputStream* out, int indent) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    89
  address pc;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    90
  char    buf[1024];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    91
  int     offset;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    92
  if (is_empty()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    93
    for (int index = 0; index < indent; index ++) out->print(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    94
    out->print("[BOOTSTRAP]");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    95
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    96
    for (int frame = 0; frame < NMT_TrackingStackDepth; frame ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    97
      pc = get_frame(frame);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    98
      if (pc == NULL) break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    99
      // Print indent
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   100
      for (int index = 0; index < indent; index ++) out->print(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   101
      if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   102
        out->print_cr("[" PTR_FORMAT "] %s+0x%x", p2i(pc), buf, offset);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   103
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   104
        out->print_cr("[" PTR_FORMAT "]", p2i(pc));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   105
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   106
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   107
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   108
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   109