hotspot/src/os/windows/vm/decoder_windows.cpp
author tschatzl
Wed, 11 Sep 2013 10:14:32 +0200
changeset 19981 6821d0a573c3
parent 15855 2ac9ebea17f3
child 19952 bc974e92f881
permissions -rw-r--r--
8016825: Large pages for the heap broken on Windows for compressed oops Summary: Correctly pass the requested base address for the heap to the OS function to reserve memory. Reviewed-by: brutisso, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     1
/*
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15186
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     4
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     8
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    13
 * accompanied this code).
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    14
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    18
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    21
 * questions.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    22
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    23
 */
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    24
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    25
#include "precompiled.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    26
#include "prims/jvm.h"
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15186
diff changeset
    27
#include "runtime/arguments.hpp"
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    28
#include "decoder_windows.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    29
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    30
WindowsDecoder::WindowsDecoder() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    31
  _dbghelp_handle = NULL;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    32
  _can_decode_in_vm = false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    33
  _pfnSymGetSymFromAddr64 = NULL;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    34
  _pfnUndecorateSymbolName = NULL;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    35
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    36
  _decoder_status = no_error;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    37
  initialize();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    38
}
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    39
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    40
void WindowsDecoder::initialize() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    41
  if (!has_error() && _dbghelp_handle == NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    42
    HMODULE handle = ::LoadLibrary("dbghelp.dll");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    43
    if (!handle) {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    44
      _decoder_status = helper_not_found;
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
    45
      return;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    46
    }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    47
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    48
    _dbghelp_handle = handle;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    49
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    50
    pfn_SymSetOptions _pfnSymSetOptions = (pfn_SymSetOptions)::GetProcAddress(handle, "SymSetOptions");
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    51
    pfn_SymInitialize _pfnSymInitialize = (pfn_SymInitialize)::GetProcAddress(handle, "SymInitialize");
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    52
    _pfnSymGetSymFromAddr64 = (pfn_SymGetSymFromAddr64)::GetProcAddress(handle, "SymGetSymFromAddr64");
15186
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    53
    _pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)::GetProcAddress(handle, "UnDecorateSymbolName");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    54
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    55
    if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    56
      _pfnSymGetSymFromAddr64 = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    57
      _pfnUndecorateSymbolName = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    58
      ::FreeLibrary(handle);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    59
      _dbghelp_handle = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    60
      _decoder_status = helper_func_error;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    61
      return;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    62
    }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    63
15186
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    64
    HANDLE hProcess = ::GetCurrentProcess();
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    65
    _pfnSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    66
    if (!_pfnSymInitialize(hProcess, NULL, TRUE)) {
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    67
      _pfnSymGetSymFromAddr64 = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    68
      _pfnUndecorateSymbolName = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    69
      ::FreeLibrary(handle);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    70
      _dbghelp_handle = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    71
      _decoder_status = helper_init_error;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    72
      return;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    73
    }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    74
15186
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    75
    // set pdb search paths
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    76
    pfn_SymSetSearchPath  _pfn_SymSetSearchPath =
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    77
      (pfn_SymSetSearchPath)::GetProcAddress(handle, "SymSetSearchPath");
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    78
    pfn_SymGetSearchPath  _pfn_SymGetSearchPath =
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    79
      (pfn_SymGetSearchPath)::GetProcAddress(handle, "SymGetSearchPath");
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    80
    if (_pfn_SymSetSearchPath != NULL && _pfn_SymGetSearchPath != NULL) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    81
      char paths[MAX_PATH];
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    82
      int  len = sizeof(paths);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    83
      if (!_pfn_SymGetSearchPath(hProcess, paths, len)) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    84
        paths[0] = '\0';
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    85
      } else {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    86
        // available spaces in path buffer
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    87
        len -= (int)strlen(paths);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    88
      }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    89
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    90
      char tmp_path[MAX_PATH];
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    91
      DWORD dwSize;
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    92
      HMODULE hJVM = ::GetModuleHandle("jvm.dll");
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    93
      tmp_path[0] = '\0';
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    94
      // append the path where jvm.dll is located
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    95
      if (hJVM != NULL && (dwSize = ::GetModuleFileName(hJVM, tmp_path, sizeof(tmp_path))) > 0) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    96
        while (dwSize > 0 && tmp_path[dwSize] != '\\') {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    97
          dwSize --;
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    98
        }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
    99
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   100
        tmp_path[dwSize] = '\0';
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   101
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   102
        if (dwSize > 0 && len > (int)dwSize + 1) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   103
          strncat(paths, os::path_separator(), 1);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   104
          strncat(paths, tmp_path, dwSize);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   105
          len -= dwSize + 1;
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   106
        }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   107
      }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   108
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   109
      // append $JRE/bin. Arguments::get_java_home actually returns $JRE
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   110
      // path
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   111
      char *p = Arguments::get_java_home();
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   112
      assert(p != NULL, "empty java home");
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   113
      size_t java_home_len = strlen(p);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   114
      if (len > (int)java_home_len + 5) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   115
        strncat(paths, os::path_separator(), 1);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   116
        strncat(paths, p, java_home_len);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   117
        strncat(paths, "\\bin", 4);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   118
        len -= (int)(java_home_len + 5);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   119
      }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   120
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   121
      // append $JDK/bin path if it exists
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   122
      assert(java_home_len < MAX_PATH, "Invalid path length");
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   123
      // assume $JRE is under $JDK, construct $JDK/bin path and
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   124
      // see if it exists or not
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   125
      if (strncmp(&p[java_home_len - 3], "jre", 3) == 0) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   126
        strncpy(tmp_path, p, java_home_len - 3);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   127
        tmp_path[java_home_len - 3] = '\0';
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   128
        strncat(tmp_path, "bin", 3);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   129
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   130
        // if the directory exists
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   131
        DWORD dwAttrib = GetFileAttributes(tmp_path);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   132
        if (dwAttrib != INVALID_FILE_ATTRIBUTES &&
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   133
            (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   134
          // tmp_path should have the same length as java_home_len, since we only
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   135
          // replaced 'jre' with 'bin'
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   136
          if (len > (int)java_home_len + 1) {
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   137
            strncat(paths, os::path_separator(), 1);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   138
            strncat(paths, tmp_path, java_home_len);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   139
          }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   140
        }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   141
      }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   142
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   143
      _pfn_SymSetSearchPath(hProcess, paths);
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   144
    }
1a255c84cf6a 7152671: RFE: Windows decoder should add some std dirs to the symbol search path
zgu
parents: 13963
diff changeset
   145
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   146
     // find out if jvm.dll contains private symbols, by decoding
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   147
     // current function and comparing the result
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11483
diff changeset
   148
     address addr = (address)Decoder::demangle;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   149
     char buf[MAX_PATH];
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   150
     if (decode(addr, buf, sizeof(buf), NULL)) {
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11483
diff changeset
   151
       _can_decode_in_vm = !strcmp(buf, "Decoder::demangle");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   152
     }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   153
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   154
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   155
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   156
void WindowsDecoder::uninitialize() {
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   157
  _pfnSymGetSymFromAddr64 = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   158
  _pfnUndecorateSymbolName = NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   159
  if (_dbghelp_handle != NULL) {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   160
    ::FreeLibrary(_dbghelp_handle);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   161
  }
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   162
  _dbghelp_handle = NULL;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   163
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   164
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   165
bool WindowsDecoder::can_decode_C_frame_in_vm() const {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   166
  return  (!has_error() && _can_decode_in_vm);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   167
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   168
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   169
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   170
bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* modulepath)  {
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   171
  if (_pfnSymGetSymFromAddr64 != NULL) {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   172
    PIMAGEHLP_SYMBOL64 pSymbol;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   173
    char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)];
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   174
    pSymbol = (PIMAGEHLP_SYMBOL64)symbolInfo;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   175
    pSymbol->MaxNameLength = MAX_PATH;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   176
    pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   177
    DWORD64 displacement;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   178
    if (_pfnSymGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   179
      if (buf != NULL) {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   180
        if (demangle(pSymbol->Name, buf, buflen)) {
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   181
          jio_snprintf(buf, buflen, "%s", pSymbol->Name);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   182
        }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   183
      }
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   184
      if(offset != NULL) *offset = (int)displacement;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   185
      return true;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   186
    }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   187
  }
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   188
  if (buf != NULL && buflen > 0) buf[0] = '\0';
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   189
  if (offset != NULL) *offset = -1;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   190
  return false;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   191
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   192
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10246
diff changeset
   193
bool WindowsDecoder::demangle(const char* symbol, char *buf, int buflen) {
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   194
  return _pfnUndecorateSymbolName != NULL &&
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   195
         _pfnUndecorateSymbolName(symbol, buf, buflen, UNDNAME_COMPLETE);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   196
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   197