hotspot/src/share/vm/utilities/decoder.cpp
author zgu
Tue, 17 Jan 2012 13:08:52 -0500
changeset 11483 4d3f4bca0019
parent 10565 dc90c239f4ec
child 11761 bf460b379a6a
permissions -rw-r--r--
7071311: Decoder enhancement Summary: Made decoder thread-safe Reviewed-by: coleenp, kamg
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
/*
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
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"
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    27
#include "runtime/mutexLocker.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    28
#include "utilities/decoder.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    29
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    30
#if defined(_WINDOWS)
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    31
  #include "decoder_windows.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    32
#elif defined(__APPLE__)
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    33
  #include "decoder_machO.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    34
#else
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    35
  #include "decoder_elf.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    36
#endif
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    37
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    38
NullDecoder*  Decoder::_decoder = NULL;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    39
NullDecoder   Decoder::_do_nothing_decoder;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    40
Mutex*           Decoder::_decoder_lock = new Mutex(Mutex::safepoint,
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    41
                                "DecoderLock");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    42
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    43
// _decoder_lock should already acquired before enter this method
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    44
NullDecoder* Decoder::get_decoder() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    45
  assert(_decoder_lock != NULL && _decoder_lock->owned_by_self(),
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    46
    "Require DecoderLock to enter");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    47
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    48
  if (_decoder != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    49
    return _decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    50
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    51
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    52
  // Decoder is a secondary service. Although, it is good to have,
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    53
  // but we can live without it.
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    54
#if defined(_WINDOWS)
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    55
  _decoder = new (std::nothrow) WindowsDecoder();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    56
#elif defined (__APPLE__)
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    57
    _decoder = new (std::nothrow)MachODecoder();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    58
#else
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    59
    _decoder = new (std::nothrow)ElfDecoder();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    60
#endif
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    61
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    62
  if (_decoder == NULL || _decoder->has_error()) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    63
    if (_decoder != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    64
      delete _decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    65
    }
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    66
    _decoder = &_do_nothing_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    67
  }
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    68
  return _decoder;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    69
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    70
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    71
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    72
  assert(_decoder_lock != NULL, "Just check");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    73
  MutexLockerEx locker(_decoder_lock, true);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    74
  NullDecoder* decoder = get_decoder();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    75
  assert(decoder != NULL, "null decoder");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    76
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    77
  return decoder->decode(addr, buf, buflen, offset, modulepath);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    78
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    79
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    80
bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    81
  assert(_decoder_lock != NULL, "Just check");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    82
  MutexLockerEx locker(_decoder_lock, true);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    83
  NullDecoder* decoder = get_decoder();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    84
  assert(decoder != NULL, "null decoder");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    85
  return decoder->demangle(symbol, buf, buflen);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    86
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    87
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    88
bool Decoder::can_decode_C_frame_in_vm() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    89
  assert(_decoder_lock != NULL, "Just check");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    90
  MutexLockerEx locker(_decoder_lock, true);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    91
  NullDecoder* decoder = get_decoder();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    92
  assert(decoder != NULL, "null decoder");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    93
  return decoder->can_decode_C_frame_in_vm();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    94
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    95
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    96
// shutdown real decoder and replace it with
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    97
// _do_nothing_decoder
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    98
void Decoder::shutdown() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    99
  assert(_decoder_lock != NULL, "Just check");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   100
  MutexLockerEx locker(_decoder_lock, true);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   101
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   102
  if (_decoder != NULL && _decoder != &_do_nothing_decoder) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   103
    delete _decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   104
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   105
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   106
  _decoder = &_do_nothing_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   107
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   108