src/hotspot/share/compiler/disassembler.cpp
author rkennke
Sun, 15 Oct 2017 22:54:03 +0200
changeset 47687 fb290fd1f9d4
parent 47216 71c04702a3d5
child 49164 7e958a8ebcd3
permissions -rw-r--r--
8171853: Remove Shark compiler Reviewed-by: dholmes, kvn, erikj, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     1
/*
47106
bed18a111b90 8173715: Remove FlatProfiler
gziemski
parents: 42650
diff changeset
     2
 * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     4
 *
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     7
 * published by the Free Software Foundation.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     8
 *
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    13
 * accompanied this code).
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    14
 *
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4584
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4584
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4584
diff changeset
    21
 * questions.
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    22
 *
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    23
 */
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    26
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    27
#include "code/codeCache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    28
#include "compiler/disassembler.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30281
diff changeset
    29
#include "gc/shared/cardTableModRefBS.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30281
diff changeset
    30
#include "gc/shared/collectedHeap.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35546
diff changeset
    31
#include "memory/resourceArea.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 26432
diff changeset
    32
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    33
#include "runtime/handles.inline.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24460
diff changeset
    34
#include "runtime/os.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    35
#include "runtime/stubCodeGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    36
#include "runtime/stubRoutines.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38658
diff changeset
    37
#include CPU_HEADER(depChecker)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    38
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    39
void*       Disassembler::_library               = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    40
bool        Disassembler::_tried_to_load_library = false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    41
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    42
// This routine is in the shared library:
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
    43
Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    44
Disassembler::decode_func Disassembler::_decode_instructions = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    45
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
    46
static const char hsdis_library_name[] = "hsdis-" HOTSPOT_LIB_ARCH;
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
    47
static const char decode_instructions_virtual_name[] = "decode_instructions_virtual";
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
    48
static const char decode_instructions_name[] = "decode_instructions";
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
    49
static bool use_new_version = true;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    50
#define COMMENT_COLUMN  40 LP64_ONLY(+8) /*could be an option*/
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    51
#define BYTES_COMMENT   ";..."  /* funky byte display comment */
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    52
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    53
bool Disassembler::load_library() {
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
    54
  if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    55
    // Already succeeded.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    56
    return true;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    57
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    58
  if (_tried_to_load_library) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    59
    // Do not try twice.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    60
    // To force retry in debugger: assign _tried_to_load_library=0
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    61
    return false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    62
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    63
  // Try to load it.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    64
  char ebuf[1024];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    65
  char buf[JVM_MAXPATHLEN];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    66
  os::jvm_path(buf, sizeof(buf));
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    67
  int jvm_offset = -1;
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    68
  int lib_offset = -1;
33583
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    69
#ifdef STATIC_BUILD
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    70
  char* p = strrchr(buf, '/');
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    71
  *p = '\0';
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    72
  strcat(p, "/lib/");
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    73
  lib_offset = jvm_offset = strlen(buf);
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    74
#else
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    75
  {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    76
    // Match "jvm[^/]*" in jvm_path.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    77
    const char* base = buf;
24460
ec55671cfdc2 8043264: hsdis library not picked up correctly on expected paths
sspitsyn
parents: 24424
diff changeset
    78
    const char* p = strrchr(buf, *os::file_separator());
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    79
    if (p != NULL) lib_offset = p - base + 1;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    80
    p = strstr(p ? p : base, "jvm");
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37248
diff changeset
    81
    if (p != NULL) jvm_offset = p - base;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    82
  }
33583
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    83
#endif
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    84
  // Find the disassembler shared library.
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    85
  // Search for several paths derived from libjvm, in this order:
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    86
  // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so  (for compatibility)
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    87
  // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    88
  // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    89
  // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    90
  if (jvm_offset >= 0) {
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    91
    // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    92
    strcpy(&buf[jvm_offset], hsdis_library_name);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    93
    strcat(&buf[jvm_offset], os::dll_file_extension());
7405
e6fc8d3926f8 6348631: remove the use of the HPI library from Hotspot
ikrylov
parents: 7397
diff changeset
    94
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37248
diff changeset
    95
    if (_library == NULL && lib_offset >= 0) {
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    96
      // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    97
      strcpy(&buf[lib_offset], hsdis_library_name);
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    98
      strcat(&buf[lib_offset], os::dll_file_extension());
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    99
      _library = os::dll_load(buf, ebuf, sizeof ebuf);
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   100
    }
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37248
diff changeset
   101
    if (_library == NULL && lib_offset > 0) {
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   102
      // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   103
      buf[lib_offset - 1] = '\0';
24460
ec55671cfdc2 8043264: hsdis library not picked up correctly on expected paths
sspitsyn
parents: 24424
diff changeset
   104
      const char* p = strrchr(buf, *os::file_separator());
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   105
      if (p != NULL) {
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   106
        lib_offset = p - buf + 1;
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   107
        strcpy(&buf[lib_offset], hsdis_library_name);
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   108
        strcat(&buf[lib_offset], os::dll_file_extension());
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   109
        _library = os::dll_load(buf, ebuf, sizeof ebuf);
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   110
      }
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   111
    }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   112
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   113
  if (_library == NULL) {
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   114
    // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   115
    strcpy(&buf[0], hsdis_library_name);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   116
    strcat(&buf[0], os::dll_file_extension());
7405
e6fc8d3926f8 6348631: remove the use of the HPI library from Hotspot
ikrylov
parents: 7397
diff changeset
   117
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   118
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   119
  if (_library != NULL) {
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   120
    _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   121
                                          os::dll_lookup(_library, decode_instructions_virtual_name));
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   122
  }
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   123
  if (_decode_instructions_virtual == NULL) {
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   124
    // could not spot in new version, try old version
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   125
    _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
7405
e6fc8d3926f8 6348631: remove the use of the HPI library from Hotspot
ikrylov
parents: 7397
diff changeset
   126
                                          os::dll_lookup(_library, decode_instructions_name));
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   127
    use_new_version = false;
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   128
  } else {
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   129
    use_new_version = true;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   130
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   131
  _tried_to_load_library = true;
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   132
  if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   133
    tty->print_cr("Could not load %s; %s; %s", buf,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   134
                  ((_library != NULL)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   135
                   ? "entry point is missing"
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   136
                   : (WizardMode || PrintMiscellaneous)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   137
                   ? (const char*)ebuf
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   138
                   : "library not loadable"),
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   139
                  "PrintAssembly is disabled");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   140
    return false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   141
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   142
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   143
  // Success.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   144
  tty->print_cr("Loaded disassembler from %s", buf);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   145
  return true;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   146
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   147
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   148
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   149
class decode_env {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   150
 private:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   151
  nmethod*      _nm;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   152
  CodeBlob*     _code;
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14488
diff changeset
   153
  CodeStrings   _strings;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   154
  outputStream* _output;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   155
  address       _start, _end;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   156
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   157
  char          _option_buf[512];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   158
  char          _print_raw;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   159
  bool          _print_pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   160
  bool          _print_bytes;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   161
  address       _cur_insn;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   162
  int           _bytes_per_line; // arch-specific formatting option
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   163
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   164
  static bool match(const char* event, const char* tag) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   165
    size_t taglen = strlen(tag);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   166
    if (strncmp(event, tag, taglen) != 0)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   167
      return false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   168
    char delim = event[taglen];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   169
    return delim == '\0' || delim == ' ' || delim == '/' || delim == '=';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   170
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   171
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   172
  void collect_options(const char* p) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   173
    if (p == NULL || p[0] == '\0')  return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   174
    size_t opt_so_far = strlen(_option_buf);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   175
    if (opt_so_far + 1 + strlen(p) + 1 > sizeof(_option_buf))  return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   176
    char* fillp = &_option_buf[opt_so_far];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   177
    if (opt_so_far > 0) *fillp++ = ',';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   178
    strcat(fillp, p);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   179
    // replace white space by commas:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   180
    char* q = fillp;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   181
    while ((q = strpbrk(q, " \t\n")) != NULL)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   182
      *q++ = ',';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   183
    // Note that multiple PrintAssemblyOptions flags accumulate with \n,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   184
    // which we want to be changed to a comma...
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   185
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   186
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   187
  void print_insn_labels();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   188
  void print_insn_bytes(address pc0, address pc);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   189
  void print_address(address value);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   190
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   191
 public:
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14488
diff changeset
   192
  decode_env(CodeBlob* code, outputStream* output, CodeStrings c = CodeStrings());
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   193
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   194
  address decode_instructions(address start, address end);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   195
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   196
  void start_insn(address pc) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   197
    _cur_insn = pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   198
    output()->bol();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   199
    print_insn_labels();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   200
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   201
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   202
  void end_insn(address pc) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   203
    address pc0 = cur_insn();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   204
    outputStream* st = output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   205
    if (_print_bytes && pc > pc0)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   206
      print_insn_bytes(pc0, pc);
4584
e2a449e8cc6f 6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents: 347
diff changeset
   207
    if (_nm != NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   208
      _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc);
4584
e2a449e8cc6f 6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents: 347
diff changeset
   209
      // this calls reloc_string_for which calls oop::print_value_on
e2a449e8cc6f 6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents: 347
diff changeset
   210
    }
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10017
diff changeset
   211
    // follow each complete insn by a nice newline
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10017
diff changeset
   212
    st->cr();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   213
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   214
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   215
  address handle_event(const char* event, address arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   216
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   217
  outputStream* output() { return _output; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   218
  address cur_insn() { return _cur_insn; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   219
  const char* options() { return _option_buf; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   220
};
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   221
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14488
diff changeset
   222
decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c) {
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25468
diff changeset
   223
  memset(this, 0, sizeof(*this)); // Beware, this zeroes bits of fields.
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   224
  _output = output ? output : tty;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   225
  _code = code;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   226
  if (code != NULL && code->is_nmethod())
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   227
    _nm = (nmethod*) code;
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25468
diff changeset
   228
  _strings.copy(c);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   229
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   230
  // by default, output pc but not bytes:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   231
  _print_pc       = true;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   232
  _print_bytes    = false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   233
  _bytes_per_line = Disassembler::pd_instruction_alignment();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   234
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   235
  // parse the global option string:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   236
  collect_options(Disassembler::pd_cpu_opts());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   237
  collect_options(PrintAssemblyOptions);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   238
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   239
  if (strstr(options(), "hsdis-")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   240
    if (strstr(options(), "hsdis-print-raw"))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   241
      _print_raw = (strstr(options(), "xml") ? 2 : 1);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   242
    if (strstr(options(), "hsdis-print-pc"))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   243
      _print_pc = !_print_pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   244
    if (strstr(options(), "hsdis-print-bytes"))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   245
      _print_bytes = !_print_bytes;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   246
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   247
  if (strstr(options(), "help")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   248
    tty->print_cr("PrintAssemblyOptions help:");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   249
    tty->print_cr("  hsdis-print-raw       test plugin by requesting raw output");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   250
    tty->print_cr("  hsdis-print-raw-xml   test plugin by requesting raw xml");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   251
    tty->print_cr("  hsdis-print-pc        turn off PC printing (on by default)");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   252
    tty->print_cr("  hsdis-print-bytes     turn on instruction byte output");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   253
    tty->print_cr("combined options: %s", options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   254
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   255
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   256
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   257
address decode_env::handle_event(const char* event, address arg) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   258
  if (match(event, "insn")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   259
    start_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   260
  } else if (match(event, "/insn")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   261
    end_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   262
  } else if (match(event, "addr")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   263
    if (arg != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   264
      print_address(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   265
      return arg;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   266
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   267
  } else if (match(event, "mach")) {
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   268
    static char buffer[32] = { 0, };
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   269
    if (strcmp(buffer, (const char*)arg) != 0 ||
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   270
        strlen((const char*)arg) > sizeof(buffer) - 1) {
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   271
      // Only print this when the mach changes
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   272
      strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
30281
b1608535e50f 8076475: Misuses of strncpy/strncat
stuefe
parents: 29362
diff changeset
   273
      buffer[sizeof(buffer) - 1] = '\0';
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   274
      output()->print_cr("[Disassembling for mach='%s']", arg);
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   275
    }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   276
  } else if (match(event, "format bytes-per-line")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   277
    _bytes_per_line = (int) (intptr_t) arg;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   278
  } else {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   279
    // ignore unrecognized markup
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   280
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   281
  return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   282
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   283
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   284
// called by the disassembler to print out jump targets and data addresses
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   285
void decode_env::print_address(address adr) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   286
  outputStream* st = _output;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   287
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   288
  if (adr == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   289
    st->print("NULL");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   290
    return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   291
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   292
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   293
  int small_num = (int)(intptr_t)adr;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   294
  if ((intptr_t)adr == (intptr_t)small_num
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   295
      && -1 <= small_num && small_num <= 9) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   296
    st->print("%d", small_num);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   297
    return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   298
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   299
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   300
  if (Universe::is_fully_initialized()) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   301
    if (StubRoutines::contains(adr)) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   302
      StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   303
      if (desc == NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   304
        desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   305
      }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   306
      if (desc != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   307
        st->print("Stub::%s", desc->name());
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   308
        if (desc->begin() != adr) {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   309
          st->print(INTX_FORMAT_W(+) " " PTR_FORMAT, adr - desc->begin(), p2i(adr));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   310
        } else if (WizardMode) {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   311
          st->print(" " PTR_FORMAT, p2i(adr));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   312
        }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   313
        return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   314
      }
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   315
      st->print("Stub::<unknown> " PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   316
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   317
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   318
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   319
    BarrierSet* bs = Universe::heap()->barrier_set();
29325
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents: 29083
diff changeset
   320
    if (bs->is_a(BarrierSet::CardTableModRef) &&
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents: 29083
diff changeset
   321
        adr == (address)(barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base)) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   322
      st->print("word_map_base");
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   323
      if (WizardMode) st->print(" " INTPTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   324
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   325
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   326
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   327
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   328
  if (_nm == NULL) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   329
    // Don't do this for native methods, as the function name will be printed in
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   330
    // nmethod::reloc_string_for().
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   331
    ResourceMark rm;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   332
    const int buflen = 1024;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   333
    char* buf = NEW_RESOURCE_ARRAY(char, buflen);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   334
    int offset;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   335
    if (os::dll_address_to_function_name(adr, buf, buflen, &offset)) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   336
      st->print(PTR_FORMAT " = %s",  p2i(adr), buf);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   337
      if (offset != 0) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   338
        st->print("+%d", offset);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   339
      }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   340
      return;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   341
    }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   342
  }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   343
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 8921
diff changeset
   344
  // Fall through to a simple (hexadecimal) numeral.
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   345
  st->print(PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   346
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   348
void decode_env::print_insn_labels() {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   349
  address p = cur_insn();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   350
  outputStream* st = output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   351
  CodeBlob* cb = _code;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   352
  if (cb != NULL) {
4584
e2a449e8cc6f 6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents: 347
diff changeset
   353
    cb->print_block_comment(st, p);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   354
  }
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14488
diff changeset
   355
  _strings.print_block_comment(st, (intptr_t)(p - _start));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   356
  if (_print_pc) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   357
    st->print("  " PTR_FORMAT ": ", p2i(p));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   358
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   359
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   360
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   361
void decode_env::print_insn_bytes(address pc, address pc_limit) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   362
  outputStream* st = output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   363
  size_t incr = 1;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   364
  size_t perline = _bytes_per_line;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   365
  if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   366
      && !((uintptr_t)pc % sizeof(int))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   367
      && !((uintptr_t)pc_limit % sizeof(int))) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   368
    incr = sizeof(int);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   369
    if (perline % incr)  perline += incr - (perline % incr);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   370
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   371
  while (pc < pc_limit) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   372
    // tab to the desired column:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   373
    st->move_to(COMMENT_COLUMN);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   374
    address pc0 = pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   375
    address pc1 = pc + perline;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   376
    if (pc1 > pc_limit)  pc1 = pc_limit;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   377
    for (; pc < pc1; pc += incr) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   378
      if (pc == pc0) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   379
        st->print(BYTES_COMMENT);
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   380
      } else if ((uint)(pc - pc0) % sizeof(int) == 0) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   381
        st->print(" ");         // put out a space on word boundaries
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   382
      }
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   383
      if (incr == sizeof(int)) {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   384
        st->print("%08x", *(int*)pc);
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   385
      } else {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   386
        st->print("%02x", (*pc)&0xFF);
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   387
      }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   388
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   389
    st->cr();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   390
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   391
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   392
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   393
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   394
static void* event_to_env(void* env_pv, const char* event, void* arg) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   395
  decode_env* env = (decode_env*) env_pv;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   396
  return env->handle_event(event, (address) arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   397
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   398
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
   399
ATTRIBUTE_PRINTF(2, 3)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   400
static int printf_to_env(void* env_pv, const char* format, ...) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   401
  decode_env* env = (decode_env*) env_pv;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   402
  outputStream* st = env->output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   403
  size_t flen = strlen(format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   404
  const char* raw = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   405
  if (flen == 0)  return 0;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   406
  if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   407
  if (flen < 2 ||
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   408
      strchr(format, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   409
    raw = format;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   410
  } else if (format[0] == '%' && format[1] == '%' &&
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   411
             strchr(format+2, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   412
    // happens a lot on machines with names like %foo
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   413
    flen--;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   414
    raw = format+1;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   415
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   416
  if (raw != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   417
    st->print_raw(raw, (int) flen);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   418
    return (int) flen;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   419
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   420
  va_list ap;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   421
  va_start(ap, format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   422
  julong cnt0 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   423
  st->vprint(format, ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   424
  julong cnt1 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   425
  va_end(ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   426
  return (int)(cnt1 - cnt0);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   427
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   428
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   429
address decode_env::decode_instructions(address start, address end) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   430
  _start = start; _end = end;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   431
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   432
  assert(((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment()) == 0), "misaligned insn addr");
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   433
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   434
  const int show_bytes = false; // for disassembler debugging
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   435
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   436
  //_version = Disassembler::pd_cpu_version();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   437
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   438
  if (!Disassembler::can_decode()) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   439
    return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   440
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   441
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   442
  // decode a series of instructions and return the end of the last instruction
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   443
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   444
  if (_print_raw) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   445
    // Print whatever the library wants to print, w/o fancy callbacks.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   446
    // This is mainly for debugging the library itself.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   447
    FILE* out = stdout;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   448
    FILE* xmlout = (_print_raw > 1 ? out : NULL);
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   449
    return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   450
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   451
      (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   452
                                                    start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   453
                                                    NULL, (void*) xmlout,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   454
                                                    NULL, (void*) out,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   455
                                                    options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   456
      :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   457
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   458
      (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   459
                                            NULL, (void*) xmlout,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   460
                                            NULL, (void*) out,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   461
                                            options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   462
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   463
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   464
  return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   465
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   466
    (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   467
                                                  start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   468
                                                  &event_to_env,  (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   469
                                                  &printf_to_env, (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   470
                                                  options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   471
    :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   472
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   473
    (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   474
                                          &event_to_env,  (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   475
                                          &printf_to_env, (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   476
                                          options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   477
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   478
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   479
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   480
void Disassembler::decode(CodeBlob* cb, outputStream* st) {
35542
9dccb7f9f656 8071374: -XX:+PrintAssembly -XX:+PrintSignatureHandlers crash fastdebug VM with assert(limit == __null || limit <= nm->code_end()) in RelocIterator::initialize
vlivanov
parents: 33585
diff changeset
   481
  ttyLocker ttyl;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   482
  if (!load_library())  return;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   483
  if (cb->is_nmethod()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   484
    decode((nmethod*)cb, st);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   485
    return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   486
  }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   487
  decode_env env(cb, st);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   488
  env.output()->print_cr("----------------------------------------------------------------------");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   489
  if (cb->is_aot()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   490
    env.output()->print("A ");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   491
    if (cb->is_compiled()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   492
      CompiledMethod* cm = (CompiledMethod*)cb;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   493
      env.output()->print("%d ",cm->compile_id());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   494
      cm->method()->method_holder()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   495
      env.output()->print(".");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   496
      cm->method()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   497
      cm->method()->signature()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   498
    } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   499
      env.output()->print_cr("%s", cb->name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   500
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   501
  } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   502
    env.output()->print_cr("%s", cb->name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   503
  }
33198
dlong
parents: 33148 33160
diff changeset
   504
  env.output()->print_cr(" at  [" PTR_FORMAT ", " PTR_FORMAT "]  " JLONG_FORMAT " bytes", p2i(cb->code_begin()), p2i(cb->code_end()), ((jlong)(cb->code_end() - cb->code_begin())) * sizeof(unsigned char*));
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6187
diff changeset
   505
  env.decode_instructions(cb->code_begin(), cb->code_end());
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   506
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   507
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14488
diff changeset
   508
void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) {
35542
9dccb7f9f656 8071374: -XX:+PrintAssembly -XX:+PrintSignatureHandlers crash fastdebug VM with assert(limit == __null || limit <= nm->code_end()) in RelocIterator::initialize
vlivanov
parents: 33585
diff changeset
   509
  ttyLocker ttyl;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   510
  if (!load_library())  return;
13887
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 10017
diff changeset
   511
  decode_env env(CodeCache::find_blob_unsafe(start), st, c);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   512
  env.decode_instructions(start, end);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   513
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   514
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   515
void Disassembler::decode(nmethod* nm, outputStream* st) {
35542
9dccb7f9f656 8071374: -XX:+PrintAssembly -XX:+PrintSignatureHandlers crash fastdebug VM with assert(limit == __null || limit <= nm->code_end()) in RelocIterator::initialize
vlivanov
parents: 33585
diff changeset
   516
  ttyLocker ttyl;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   517
  if (!load_library())  return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   518
  decode_env env(nm, st);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   519
  env.output()->print_cr("----------------------------------------------------------------------");
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   520
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6187
diff changeset
   521
  unsigned char* p   = nm->code_begin();
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6187
diff changeset
   522
  unsigned char* end = nm->code_end();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   523
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   524
  nm->method()->method_holder()->name()->print_symbol_on(env.output());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   525
  env.output()->print(".");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   526
  nm->method()->name()->print_symbol_on(env.output());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   527
  nm->method()->signature()->print_symbol_on(env.output());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   528
#if INCLUDE_JVMCI
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   529
  {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   530
    char buffer[O_BUFLEN];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   531
    char* jvmciName = nm->jvmci_installed_code_name(buffer, O_BUFLEN);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   532
    if (jvmciName != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   533
      env.output()->print(" (%s)", jvmciName);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   534
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   535
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   536
#endif
33198
dlong
parents: 33148 33160
diff changeset
   537
  env.output()->print_cr("  [" PTR_FORMAT ", " PTR_FORMAT "]  " JLONG_FORMAT " bytes", p2i(p), p2i(end), ((jlong)(end - p)));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   538
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   539
  // Print constant table.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   540
  if (nm->consts_size() > 0) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   541
    nm->print_nmethod_labels(env.output(), nm->consts_begin());
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   542
    int offset = 0;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   543
    for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   544
      if ((offset % 8) == 0) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   545
        env.output()->print_cr("  " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT "   " PTR64_FORMAT, p2i(p), offset, *((int32_t*) p), *((int64_t*) p));
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   546
      } else {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   547
        env.output()->print_cr("  " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT,                    p2i(p), offset, *((int32_t*) p));
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   548
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   549
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   550
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   551
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   552
  env.decode_instructions(p, end);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   553
}