src/hotspot/share/compiler/disassembler.cpp
author kvn
Wed, 01 May 2019 12:31:29 -0700
changeset 54669 ad45b3802d4e
parent 53657 3954d70e1c50
child 54786 ebf733a324d4
permissions -rw-r--r--
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library Reviewed-by: dnsimon, never, stefank, rehn, neliasso, dholmes, kbarrett, coleenp
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
/*
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53657
diff changeset
     2
 * Copyright (c) 2008, 2019, 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"
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
    26
#include "asm/macroAssembler.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47687
diff changeset
    27
#include "ci/ciUtilities.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    28
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    29
#include "code/codeCache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    30
#include "compiler/disassembler.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47687
diff changeset
    31
#include "gc/shared/cardTable.hpp"
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
    32
#include "gc/shared/cardTableBarrierSet.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30281
diff changeset
    33
#include "gc/shared/collectedHeap.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35546
diff changeset
    34
#include "memory/resourceArea.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 26432
diff changeset
    35
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    36
#include "runtime/handles.inline.hpp"
53657
3954d70e1c50 8218544: Fix build on windows: missing include
goetz
parents: 51092
diff changeset
    37
#include "runtime/os.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    38
#include "runtime/stubCodeGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    39
#include "runtime/stubRoutines.hpp"
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
    40
#include "utilities/resourceHash.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38658
diff changeset
    41
#include CPU_HEADER(depChecker)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    42
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    43
void*       Disassembler::_library               = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    44
bool        Disassembler::_tried_to_load_library = false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    45
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    46
// 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
    47
Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    48
Disassembler::decode_func Disassembler::_decode_instructions = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    49
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
    50
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
    51
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
    52
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
    53
static bool use_new_version = true;
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
    54
#define COMMENT_COLUMN  52 LP64_ONLY(+8) /*could be an option*/
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    55
#define BYTES_COMMENT   ";..."  /* funky byte display comment */
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    56
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    57
bool Disassembler::load_library() {
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
    58
  if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    59
    // Already succeeded.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    60
    return true;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    61
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    62
  if (_tried_to_load_library) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    63
    // Do not try twice.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    64
    // 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
    65
    return false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    66
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    67
  // Try to load it.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    68
  char ebuf[1024];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    69
  char buf[JVM_MAXPATHLEN];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    70
  os::jvm_path(buf, sizeof(buf));
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    71
  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
    72
  int lib_offset = -1;
33583
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    73
#ifdef STATIC_BUILD
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    74
  char* p = strrchr(buf, '/');
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    75
  *p = '\0';
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    76
  strcat(p, "/lib/");
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    77
  lib_offset = jvm_offset = strlen(buf);
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    78
#else
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    79
  {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    80
    // Match "jvm[^/]*" in jvm_path.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    81
    const char* base = buf;
24460
ec55671cfdc2 8043264: hsdis library not picked up correctly on expected paths
sspitsyn
parents: 24424
diff changeset
    82
    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
    83
    if (p != NULL) lib_offset = p - base + 1;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    84
    p = strstr(p ? p : base, "jvm");
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37248
diff changeset
    85
    if (p != NULL) jvm_offset = p - base;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    86
  }
33583
af842015bfaa 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31592
diff changeset
    87
#endif
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
    88
  // 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
    89
  // 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
    90
  // 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
    91
  // 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
    92
  // 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
    93
  // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    94
  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
    95
    // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    96
    strcpy(&buf[jvm_offset], hsdis_library_name);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    97
    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
    98
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37248
diff changeset
    99
    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
   100
      // 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
   101
      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
   102
      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
   103
      _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
   104
    }
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37248
diff changeset
   105
    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
   106
      // 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
   107
      buf[lib_offset - 1] = '\0';
24460
ec55671cfdc2 8043264: hsdis library not picked up correctly on expected paths
sspitsyn
parents: 24424
diff changeset
   108
      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
   109
      if (p != NULL) {
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   110
        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
   111
        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
   112
        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
   113
        _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
   114
      }
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   115
    }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   116
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   117
  if (_library == NULL) {
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   118
    // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   119
    strcpy(&buf[0], hsdis_library_name);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   120
    strcat(&buf[0], os::dll_file_extension());
7405
e6fc8d3926f8 6348631: remove the use of the HPI library from Hotspot
ikrylov
parents: 7397
diff changeset
   121
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   122
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   123
  if (_library != NULL) {
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   124
    _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
   125
                                          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
   126
  }
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50528
diff changeset
   127
  if (_decode_instructions_virtual == NULL && _library != NULL) {
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   128
    // could not spot in new version, try old version
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   129
    _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
   130
                                          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
   131
    use_new_version = false;
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   132
  } else {
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   133
    use_new_version = true;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   134
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   135
  _tried_to_load_library = true;
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   136
  if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   137
    tty->print_cr("Could not load %s; %s; %s", buf,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   138
                  ((_library != NULL)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   139
                   ? "entry point is missing"
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   140
                   : (WizardMode || PrintMiscellaneous)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   141
                   ? (const char*)ebuf
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   142
                   : "library not loadable"),
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   143
                  "PrintAssembly is disabled");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   144
    return false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   145
  }
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
  // Success.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   148
  tty->print_cr("Loaded disassembler from %s", buf);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   149
  return true;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   150
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   151
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   152
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   153
class decode_env {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   154
 private:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   155
  nmethod*      _nm;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   156
  CodeBlob*     _code;
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14488
diff changeset
   157
  CodeStrings   _strings;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   158
  outputStream* _output;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   159
  address       _start, _end;
50528
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   160
  ptrdiff_t     _offset;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   161
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   162
  char          _option_buf[512];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   163
  char          _print_raw;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   164
  bool          _print_pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   165
  bool          _print_bytes;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   166
  address       _cur_insn;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   167
  int           _bytes_per_line; // arch-specific formatting option
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   168
  bool          _print_file_name;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   169
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   170
  static bool match(const char* event, const char* tag) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   171
    size_t taglen = strlen(tag);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   172
    if (strncmp(event, tag, taglen) != 0)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   173
      return false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   174
    char delim = event[taglen];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   175
    return delim == '\0' || delim == ' ' || delim == '/' || delim == '=';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   176
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   177
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   178
  void collect_options(const char* p) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   179
    if (p == NULL || p[0] == '\0')  return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   180
    size_t opt_so_far = strlen(_option_buf);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   181
    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
   182
    char* fillp = &_option_buf[opt_so_far];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   183
    if (opt_so_far > 0) *fillp++ = ',';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   184
    strcat(fillp, p);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   185
    // replace white space by commas:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   186
    char* q = fillp;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   187
    while ((q = strpbrk(q, " \t\n")) != NULL)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   188
      *q++ = ',';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   189
    // Note that multiple PrintAssemblyOptions flags accumulate with \n,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   190
    // which we want to be changed to a comma...
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   191
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   192
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   193
  void print_insn_labels();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   194
  void print_insn_bytes(address pc0, address pc);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   195
  void print_address(address value);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   196
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   197
  struct SourceFileInfo {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   198
    struct Link : public CHeapObj<mtCode> {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   199
      const char* file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   200
      int line;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   201
      Link* next;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   202
      Link(const char* f, int l) : file(f), line(l), next(NULL) {}
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   203
    };
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   204
    Link *head, *tail;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   205
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   206
    static unsigned hash(const address& a) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   207
      return primitive_hash<address>(a);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   208
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   209
    static bool equals(const address& a0, const address& a1) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   210
      return primitive_equals<address>(a0, a1);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   211
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   212
    void append(const char* file, int line) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   213
      if (tail != NULL && tail->file == file && tail->line == line) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   214
        // Don't print duplicated lines at the same address. This could happen with C
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   215
        // macros that end up having multiple "__" tokens on the same __LINE__.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   216
        return;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   217
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   218
      Link *link = new Link(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   219
      if (head == NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   220
        head = tail = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   221
      } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   222
        tail->next = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   223
        tail = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   224
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   225
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   226
    SourceFileInfo(const char* file, int line) : head(NULL), tail(NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   227
      append(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   228
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   229
  };
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   230
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   231
  typedef ResourceHashtable<
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   232
      address, SourceFileInfo,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   233
      SourceFileInfo::hash,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   234
      SourceFileInfo::equals,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   235
      15889,      // prime number
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   236
      ResourceObj::C_HEAP> SourceFileInfoTable;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   237
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   238
  static SourceFileInfoTable _src_table;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   239
  static const char* _cached_src;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   240
  static GrowableArray<const char*>* _cached_src_lines;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   241
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   242
 public:
50528
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   243
  decode_env(CodeBlob* code, outputStream* output,
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   244
             CodeStrings c = CodeStrings(), ptrdiff_t offset = 0);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   245
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   246
  address decode_instructions(address start, address end);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   247
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   248
  void start_insn(address pc) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   249
    _cur_insn = pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   250
    output()->bol();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   251
    print_insn_labels();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   252
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   253
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   254
  void end_insn(address pc) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   255
    address pc0 = cur_insn();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   256
    outputStream* st = output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   257
    if (_print_bytes && pc > pc0)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   258
      print_insn_bytes(pc0, pc);
4584
e2a449e8cc6f 6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents: 347
diff changeset
   259
    if (_nm != NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   260
      _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
   261
      // 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
   262
    }
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   263
    print_hook_comments(pc0, _nm != NULL);
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10017
diff changeset
   264
    // follow each complete insn by a nice newline
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 10017
diff changeset
   265
    st->cr();
347
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
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   268
  address handle_event(const char* event, address arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   269
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   270
  outputStream* output() { return _output; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   271
  address cur_insn() { return _cur_insn; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   272
  const char* options() { return _option_buf; }
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   273
  static void hook(const char* file, int line, address pc);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   274
  void print_hook_comments(address pc, bool newline);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   275
};
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   276
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   277
decode_env::SourceFileInfoTable decode_env::_src_table;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   278
const char* decode_env::_cached_src = NULL;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   279
GrowableArray<const char*>* decode_env::_cached_src_lines = NULL;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   280
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   281
void decode_env::hook(const char* file, int line, address pc) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   282
  // For simplication, we never free from this table. It's really not
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   283
  // necessary as we add to the table only when PrintInterpreter is true,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   284
  // which means we are debugging the VM and a little bit of extra
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   285
  // memory usage doesn't matter.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   286
  SourceFileInfo* found = _src_table.get(pc);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   287
  if (found != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   288
    found->append(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   289
  } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   290
    SourceFileInfo sfi(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   291
    _src_table.put(pc, sfi); // sfi is copied by value
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   292
  }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   293
}
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   294
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   295
void decode_env::print_hook_comments(address pc, bool newline) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   296
  SourceFileInfo* found = _src_table.get(pc);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   297
  outputStream* st = output();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   298
  if (found != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   299
    for (SourceFileInfo::Link *link = found->head; link; link = link->next) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   300
      const char* file = link->file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   301
      int line = link->line;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   302
      if (_cached_src == NULL || strcmp(_cached_src, file) != 0) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   303
        FILE* fp;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   304
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   305
        // _cached_src_lines is a single cache of the lines of a source file, and we refill this cache
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   306
        // every time we need to print a line from a different source file. It's not the fastest,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   307
        // but seems bearable.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   308
        if (_cached_src_lines != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   309
          for (int i=0; i<_cached_src_lines->length(); i++) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   310
            os::free((void*)_cached_src_lines->at(i));
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   311
          }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   312
          _cached_src_lines->clear();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   313
        } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   314
          _cached_src_lines = new (ResourceObj::C_HEAP, mtCode)GrowableArray<const char*>(0, true);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   315
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   316
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   317
        if ((fp = fopen(file, "r")) == NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   318
          _cached_src = NULL;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   319
          return;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   320
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   321
        _cached_src = file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   322
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   323
        char line[500]; // don't write lines that are too long in your source files!
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   324
        while (fgets(line, sizeof(line), fp) != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   325
          size_t len = strlen(line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   326
          if (len > 0 && line[len-1] == '\n') {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   327
            line[len-1] = '\0';
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   328
          }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   329
          _cached_src_lines->append(os::strdup(line));
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   330
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   331
        fclose(fp);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   332
        _print_file_name = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   333
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   334
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   335
      if (_print_file_name) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   336
        // We print the file name whenever we switch to a new file, or when
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   337
        // Disassembler::decode is called to disassemble a new block of code.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   338
        _print_file_name = false;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   339
        if (newline) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   340
          st->cr();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   341
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   342
        st->move_to(COMMENT_COLUMN);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   343
        st->print(";;@FILE: %s", file);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   344
        newline = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   345
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   346
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   347
      int index = line - 1; // 1-based line number -> 0-based index.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   348
      if (index >= _cached_src_lines->length()) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   349
        // This could happen if source file is mismatched.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   350
      } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   351
        const char* source_line = _cached_src_lines->at(index);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   352
        if (newline) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   353
          st->cr();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   354
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   355
        st->move_to(COMMENT_COLUMN);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   356
        st->print(";;%5d: %s", line, source_line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   357
        newline = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   358
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   359
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   360
  }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   361
}
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   362
50528
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   363
decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c,
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   364
                       ptrdiff_t offset) {
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25468
diff changeset
   365
  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
   366
  _output = output ? output : tty;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   367
  _code = code;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   368
  if (code != NULL && code->is_nmethod())
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   369
    _nm = (nmethod*) code;
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25468
diff changeset
   370
  _strings.copy(c);
50528
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   371
  _offset = offset;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   372
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   373
  // by default, output pc but not bytes:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   374
  _print_pc       = true;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   375
  _print_bytes    = false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   376
  _bytes_per_line = Disassembler::pd_instruction_alignment();
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   377
  _print_file_name= true;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   378
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   379
  // parse the global option string:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   380
  collect_options(Disassembler::pd_cpu_opts());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   381
  collect_options(PrintAssemblyOptions);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   382
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   383
  if (strstr(options(), "hsdis-")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   384
    if (strstr(options(), "hsdis-print-raw"))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   385
      _print_raw = (strstr(options(), "xml") ? 2 : 1);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   386
    if (strstr(options(), "hsdis-print-pc"))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   387
      _print_pc = !_print_pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   388
    if (strstr(options(), "hsdis-print-bytes"))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   389
      _print_bytes = !_print_bytes;
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
  if (strstr(options(), "help")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   392
    tty->print_cr("PrintAssemblyOptions help:");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   393
    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
   394
    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
   395
    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
   396
    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
   397
    tty->print_cr("combined options: %s", options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   398
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   399
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   400
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   401
address decode_env::handle_event(const char* event, address arg) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   402
  if (match(event, "insn")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   403
    start_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   404
  } else if (match(event, "/insn")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   405
    end_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   406
  } else if (match(event, "addr")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   407
    if (arg != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   408
      print_address(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   409
      return arg;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   410
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   411
  } 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
   412
    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
   413
    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
   414
        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
   415
      // 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
   416
      strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
30281
b1608535e50f 8076475: Misuses of strncpy/strncat
stuefe
parents: 29362
diff changeset
   417
      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
   418
      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
   419
    }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   420
  } else if (match(event, "format bytes-per-line")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   421
    _bytes_per_line = (int) (intptr_t) arg;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   422
  } else {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   423
    // ignore unrecognized markup
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   424
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   425
  return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   426
}
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
// 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
   429
void decode_env::print_address(address adr) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   430
  outputStream* st = _output;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   431
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   432
  if (adr == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   433
    st->print("NULL");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   434
    return;
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
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   437
  int small_num = (int)(intptr_t)adr;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   438
  if ((intptr_t)adr == (intptr_t)small_num
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   439
      && -1 <= small_num && small_num <= 9) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   440
    st->print("%d", small_num);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   441
    return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   442
  }
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 (Universe::is_fully_initialized()) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   445
    if (StubRoutines::contains(adr)) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   446
      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
   447
      if (desc == NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   448
        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
   449
      }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   450
      if (desc != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   451
        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
   452
        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
   453
          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
   454
        } else if (WizardMode) {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   455
          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
   456
        }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   457
        return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   458
      }
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   459
      st->print("Stub::<unknown> " PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   460
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   461
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   462
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49455
diff changeset
   463
    BarrierSet* bs = BarrierSet::barrier_set();
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
   464
    if (bs->is_a(BarrierSet::CardTableBarrierSet) &&
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47687
diff changeset
   465
        adr == ci_card_table_address_as<address>()) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   466
      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
   467
      if (WizardMode) st->print(" " INTPTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   468
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   469
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   470
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   471
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   472
  if (_nm == NULL) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   473
    // 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
   474
    // nmethod::reloc_string_for().
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   475
    ResourceMark rm;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   476
    const int buflen = 1024;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   477
    char* buf = NEW_RESOURCE_ARRAY(char, buflen);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   478
    int offset;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   479
    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
   480
      st->print(PTR_FORMAT " = %s",  p2i(adr), buf);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   481
      if (offset != 0) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   482
        st->print("+%d", offset);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   483
      }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   484
      return;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   485
    }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   486
  }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   487
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 8921
diff changeset
   488
  // 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
   489
  st->print(PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   490
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   491
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   492
void decode_env::print_insn_labels() {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   493
  address p = cur_insn();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   494
  outputStream* st = output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   495
  CodeBlob* cb = _code;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   496
  if (cb != NULL) {
4584
e2a449e8cc6f 6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents: 347
diff changeset
   497
    cb->print_block_comment(st, p);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   498
  }
50528
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   499
  _strings.print_block_comment(st, (intptr_t)(p - _start + _offset));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   500
  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
   501
    st->print("  " PTR_FORMAT ": ", p2i(p));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   502
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   503
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   504
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   505
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
   506
  outputStream* st = output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   507
  size_t incr = 1;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   508
  size_t perline = _bytes_per_line;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   509
  if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   510
      && !((uintptr_t)pc % sizeof(int))
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   511
      && !((uintptr_t)pc_limit % sizeof(int))) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   512
    incr = sizeof(int);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   513
    if (perline % incr)  perline += incr - (perline % incr);
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
  while (pc < pc_limit) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   516
    // tab to the desired column:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   517
    st->move_to(COMMENT_COLUMN);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   518
    address pc0 = pc;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   519
    address pc1 = pc + perline;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   520
    if (pc1 > pc_limit)  pc1 = pc_limit;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   521
    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
   522
      if (pc == pc0) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   523
        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
   524
      } else if ((uint)(pc - pc0) % sizeof(int) == 0) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   525
        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
   526
      }
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   527
      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
   528
        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
   529
      } else {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   530
        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
   531
      }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   532
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   533
    st->cr();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   534
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   535
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   536
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   537
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   538
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
   539
  decode_env* env = (decode_env*) env_pv;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   540
  return env->handle_event(event, (address) arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   541
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   542
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
   543
ATTRIBUTE_PRINTF(2, 3)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   544
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
   545
  decode_env* env = (decode_env*) env_pv;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   546
  outputStream* st = env->output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   547
  size_t flen = strlen(format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   548
  const char* raw = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   549
  if (flen == 0)  return 0;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   550
  if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   551
  if (flen < 2 ||
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   552
      strchr(format, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   553
    raw = format;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   554
  } else if (format[0] == '%' && format[1] == '%' &&
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   555
             strchr(format+2, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   556
    // happens a lot on machines with names like %foo
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   557
    flen--;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   558
    raw = format+1;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   559
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   560
  if (raw != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   561
    st->print_raw(raw, (int) flen);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   562
    return (int) flen;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   563
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   564
  va_list ap;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   565
  va_start(ap, format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   566
  julong cnt0 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   567
  st->vprint(format, ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   568
  julong cnt1 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   569
  va_end(ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   570
  return (int)(cnt1 - cnt0);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   571
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   572
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   573
address decode_env::decode_instructions(address start, address end) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   574
  _start = start; _end = end;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   575
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   576
  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
   577
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   578
  const int show_bytes = false; // for disassembler debugging
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   579
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   580
  //_version = Disassembler::pd_cpu_version();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   581
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   582
  if (!Disassembler::can_decode()) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   583
    return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   584
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   585
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   586
  // 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
   587
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   588
  if (_print_raw) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   589
    // 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
   590
    // This is mainly for debugging the library itself.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   591
    FILE* out = stdout;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   592
    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
   593
    return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   594
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   595
      (*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
   596
                                                    start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   597
                                                    NULL, (void*) xmlout,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   598
                                                    NULL, (void*) out,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   599
                                                    options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   600
      :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   601
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   602
      (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   603
                                            NULL, (void*) xmlout,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   604
                                            NULL, (void*) out,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   605
                                            options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   606
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   607
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   608
  return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   609
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   610
    (*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
   611
                                                  start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   612
                                                  &event_to_env,  (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   613
                                                  &printf_to_env, (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   614
                                                  options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   615
    :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   616
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   617
    (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   618
                                          &event_to_env,  (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   619
                                          &printf_to_env, (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   620
                                          options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   621
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   622
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   623
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   624
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
   625
  ttyLocker ttyl;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   626
  if (!load_library())  return;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   627
  if (cb->is_nmethod()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   628
    decode((nmethod*)cb, st);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   629
    return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   630
  }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   631
  decode_env env(cb, st);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   632
  env.output()->print_cr("----------------------------------------------------------------------");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   633
  if (cb->is_aot()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   634
    env.output()->print("A ");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   635
    if (cb->is_compiled()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   636
      CompiledMethod* cm = (CompiledMethod*)cb;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   637
      env.output()->print("%d ",cm->compile_id());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   638
      cm->method()->method_holder()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   639
      env.output()->print(".");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   640
      cm->method()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   641
      cm->method()->signature()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   642
    } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   643
      env.output()->print_cr("%s", cb->name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   644
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   645
  } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   646
    env.output()->print_cr("%s", cb->name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   647
  }
33198
dlong
parents: 33148 33160
diff changeset
   648
  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
   649
  env.decode_instructions(cb->code_begin(), cb->code_end());
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   650
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   651
50528
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   652
void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c,
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   653
                          ptrdiff_t offset) {
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
   654
  ttyLocker ttyl;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   655
  if (!load_library())  return;
50528
1fd4844371bb 8204680: Disassembly does not display code strings in stubs
aph
parents: 49754
diff changeset
   656
  decode_env env(CodeCache::find_blob_unsafe(start), st, c, offset);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   657
  env.decode_instructions(start, end);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   658
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   659
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   660
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
   661
  ttyLocker ttyl;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   662
  if (!load_library())  return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   663
  decode_env env(nm, st);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   664
  env.output()->print_cr("----------------------------------------------------------------------");
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   665
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6187
diff changeset
   666
  unsigned char* p   = nm->code_begin();
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6187
diff changeset
   667
  unsigned char* end = nm->code_end();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   668
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   669
  nm->method()->method_holder()->name()->print_symbol_on(env.output());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   670
  env.output()->print(".");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   671
  nm->method()->name()->print_symbol_on(env.output());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   672
  nm->method()->signature()->print_symbol_on(env.output());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   673
#if INCLUDE_JVMCI
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   674
  {
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 53657
diff changeset
   675
    const char* jvmciName = nm->jvmci_name();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   676
    if (jvmciName != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   677
      env.output()->print(" (%s)", jvmciName);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   678
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   679
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   680
#endif
33198
dlong
parents: 33148 33160
diff changeset
   681
  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
   682
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   683
  // Print constant table.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   684
  if (nm->consts_size() > 0) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   685
    nm->print_nmethod_labels(env.output(), nm->consts_begin());
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   686
    int offset = 0;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   687
    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
   688
      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
   689
        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
   690
      } else {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   691
        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
   692
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   693
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   694
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   695
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   696
  env.decode_instructions(p, end);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   697
}
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   698
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   699
// To prevent excessive code expansion in the interpreter generator, we
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   700
// do not inline this function into Disassembler::hook().
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   701
void Disassembler::_hook(const char* file, int line, MacroAssembler* masm) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   702
  decode_env::hook(file, line, masm->code_section()->end());
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   703
}