src/hotspot/share/compiler/disassembler.cpp
author lucy
Thu, 28 Nov 2019 16:28:53 +0100
changeset 59309 be238525d240
parent 55593 963924f1c891
permissions -rw-r--r--
8234583: PrintAssemblyOptions isn't passed to hsdis library Reviewed-by: vlivanov, mdoerr
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"
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    26
#include "asm/assembler.inline.hpp"
54994
faf89c9568bd 8224568: minimal and zero build fails after JDK-8213084
aoqi
parents: 54960
diff changeset
    27
#include "asm/macroAssembler.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47687
diff changeset
    28
#include "ci/ciUtilities.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    29
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    30
#include "code/codeCache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    31
#include "compiler/disassembler.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47687
diff changeset
    32
#include "gc/shared/cardTable.hpp"
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
    33
#include "gc/shared/cardTableBarrierSet.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30281
diff changeset
    34
#include "gc/shared/collectedHeap.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35546
diff changeset
    35
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54669
diff changeset
    36
#include "memory/universe.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 26432
diff changeset
    37
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    38
#include "runtime/handles.inline.hpp"
53657
3954d70e1c50 8218544: Fix build on windows: missing include
goetz
parents: 51092
diff changeset
    39
#include "runtime/os.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    40
#include "runtime/stubCodeGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    41
#include "runtime/stubRoutines.hpp"
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
    42
#include "utilities/resourceHash.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38658
diff changeset
    43
#include CPU_HEADER(depChecker)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    44
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    45
void*       Disassembler::_library               = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    46
bool        Disassembler::_tried_to_load_library = false;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    47
bool        Disassembler::_library_usable        = false;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    48
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    49
// 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
    50
Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    51
Disassembler::decode_func Disassembler::_decode_instructions = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    52
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
    53
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
    54
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
    55
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
    56
static bool use_new_version = true;
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
    57
#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
    58
#define BYTES_COMMENT   ";..."  /* funky byte display comment */
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    59
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    60
class decode_env {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    61
 private:
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    62
  outputStream* _output;      // where the disassembly is directed to
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    63
  CodeBuffer*   _codeBuffer;  // != NULL only when decoding a CodeBuffer
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    64
  CodeBlob*     _codeBlob;    // != NULL only when decoding a CodeBlob
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    65
  nmethod*      _nm;          // != NULL only when decoding a nmethod
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14488
diff changeset
    66
  CodeStrings   _strings;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    67
  address       _start;       // != NULL when decoding a range of unknown type
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    68
  address       _end;         // != NULL when decoding a range of unknown type
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    69
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    70
  char          _option_buf[512];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    71
  char          _print_raw;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    72
  address       _cur_insn;        // address of instruction currently being decoded
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    73
  int           _bytes_per_line;  // arch-specific formatting option
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    74
  int           _pre_decode_alignment;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    75
  int           _post_decode_alignment;
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
    76
  bool          _print_file_name;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    77
  bool          _print_help;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    78
  bool          _helpPrinted;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    79
  static bool   _optionsParsed;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    80
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    81
  enum {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    82
    tabspacing = 8
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    83
  };
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    84
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    85
  // Check if the event matches the expected tag
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    86
  // The tag must be a substring of the event, and
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    87
  // the tag must be a token in the event, i.e. separated by delimiters
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    88
  static bool match(const char* event, const char* tag) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    89
    size_t eventlen = strlen(event);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    90
    size_t taglen   = strlen(tag);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    91
    if (eventlen < taglen)  // size mismatch
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    92
      return false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    93
    if (strncmp(event, tag, taglen) != 0)  // string mismatch
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    94
      return false;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    95
    char delim = event[taglen];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    96
    return delim == '\0' || delim == ' ' || delim == '/' || delim == '=';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    97
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
    98
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
    99
  // Merge new option string with previously recorded options
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   100
  void collect_options(const char* p) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   101
    if (p == NULL || p[0] == '\0')  return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   102
    size_t opt_so_far = strlen(_option_buf);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   103
    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
   104
    char* fillp = &_option_buf[opt_so_far];
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   105
    if (opt_so_far > 0) *fillp++ = ',';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   106
    strcat(fillp, p);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   107
    // replace white space by commas:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   108
    char* q = fillp;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   109
    while ((q = strpbrk(q, " \t\n")) != NULL)
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   110
      *q++ = ',';
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   111
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   112
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   113
  void process_options(outputStream* ost);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   114
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   115
  void print_insn_labels();
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   116
  void print_insn_prefix();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   117
  void print_address(address value);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   118
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   119
  // Properly initializes _start/_end. Overwritten too often if
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   120
  // printing of instructions is called for each instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   121
  void set_start(address s)   { _start = s; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   122
  void set_end  (address e)   { _end = e; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   123
  void set_nm   (nmethod* nm) { _nm = nm; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   124
  void set_output(outputStream* st) { _output = st; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   125
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   126
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   127
  // The disassembler library (sometimes) uses tabs to nicely align the instruction operands.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   128
  // Depending on the mnemonic length and the column position where the
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   129
  // mnemonic is printed, alignment may turn out to be not so nice.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   130
  // To improve, we assume 8-character tab spacing and left-align the mnemonic on a tab position.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   131
  // Instruction comments are aligned 4 tab positions to the right of the mnemonic.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   132
  void calculate_alignment() {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   133
    _pre_decode_alignment  = ((output()->position()+tabspacing-1)/tabspacing)*tabspacing;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   134
    _post_decode_alignment = _pre_decode_alignment + 4*tabspacing;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   135
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   136
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   137
  void start_insn(address pc) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   138
    _cur_insn = pc;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   139
    output()->bol();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   140
    print_insn_labels();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   141
    print_insn_prefix();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   142
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   143
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   144
  void end_insn(address pc) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   145
    address pc0 = cur_insn();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   146
    outputStream* st = output();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   147
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   148
    if (AbstractDisassembler::show_comment()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   149
      if ((_nm != NULL) && _nm->has_code_comment(pc0, pc)) {
55329
03af124751f5 8225429: Regression in disassembly quality
aph
parents: 55051
diff changeset
   150
        _nm->print_code_comment_on
03af124751f5 8225429: Regression in disassembly quality
aph
parents: 55051
diff changeset
   151
               (st,
03af124751f5 8225429: Regression in disassembly quality
aph
parents: 55051
diff changeset
   152
                _post_decode_alignment ? _post_decode_alignment : COMMENT_COLUMN,
03af124751f5 8225429: Regression in disassembly quality
aph
parents: 55051
diff changeset
   153
                pc0, pc);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   154
        // this calls reloc_string_for which calls oop::print_value_on
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   155
      }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   156
      print_hook_comments(pc0, _nm != NULL);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   157
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   158
    Disassembler::annotate(pc0, output());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   159
    // follow each complete insn by a nice newline
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   160
    st->bol();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   161
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   162
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   163
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   164
  struct SourceFileInfo {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   165
    struct Link : public CHeapObj<mtCode> {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   166
      const char* file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   167
      int line;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   168
      Link* next;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   169
      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
   170
    };
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   171
    Link *head, *tail;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   172
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   173
    static unsigned hash(const address& a) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   174
      return primitive_hash<address>(a);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   175
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   176
    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
   177
      return primitive_equals<address>(a0, a1);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   178
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   179
    void append(const char* file, int line) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   180
      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
   181
        // 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
   182
        // 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
   183
        return;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   184
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   185
      Link *link = new Link(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   186
      if (head == NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   187
        head = tail = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   188
      } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   189
        tail->next = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   190
        tail = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   191
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   192
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   193
    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
   194
      append(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   195
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   196
  };
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   197
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   198
  typedef ResourceHashtable<
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   199
      address, SourceFileInfo,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   200
      SourceFileInfo::hash,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   201
      SourceFileInfo::equals,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   202
      15889,      // prime number
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   203
      ResourceObj::C_HEAP> SourceFileInfoTable;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   204
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   205
  static SourceFileInfoTable _src_table;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   206
  static const char* _cached_src;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   207
  static GrowableArray<const char*>* _cached_src_lines;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   208
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   209
 public:
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   210
  decode_env(CodeBuffer* code, outputStream* output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   211
  decode_env(CodeBlob*   code, outputStream* output, CodeStrings c = CodeStrings() /* , ptrdiff_t offset */);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   212
  decode_env(nmethod*    code, outputStream* output, CodeStrings c = CodeStrings());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   213
  // Constructor for a 'decode_env' to decode an arbitrary
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   214
  // piece of memory, hopefully containing code.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   215
  decode_env(address start, address end, outputStream* output);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   216
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   217
  // Add 'original_start' argument which is the the original address
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   218
  // the instructions were located at (if this is not equal to 'start').
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   219
  address decode_instructions(address start, address end, address original_start = NULL);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   220
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   221
  address handle_event(const char* event, address arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   222
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   223
  outputStream* output()   { return _output; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   224
  address       cur_insn() { return _cur_insn; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   225
  const char*   options()  { return _option_buf; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   226
  static void   hook(const char* file, int line, address pc);
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   227
  void print_hook_comments(address pc, bool newline);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   228
};
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   229
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   230
bool decode_env::_optionsParsed = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   231
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   232
decode_env::SourceFileInfoTable decode_env::_src_table;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   233
const char* decode_env::_cached_src = NULL;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   234
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
   235
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   236
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
   237
  // 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
   238
  // 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
   239
  // 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
   240
  // memory usage doesn't matter.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   241
  SourceFileInfo* found = _src_table.get(pc);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   242
  if (found != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   243
    found->append(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   244
  } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   245
    SourceFileInfo sfi(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   246
    _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
   247
  }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   248
}
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   249
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   250
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
   251
  SourceFileInfo* found = _src_table.get(pc);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   252
  outputStream* st = output();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   253
  if (found != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   254
    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
   255
      const char* file = link->file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   256
      int line = link->line;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   257
      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
   258
        FILE* fp;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   259
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   260
        // _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
   261
        // 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
   262
        // but seems bearable.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   263
        if (_cached_src_lines != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   264
          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
   265
            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
   266
          }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   267
          _cached_src_lines->clear();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   268
        } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   269
          _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
   270
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   271
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   272
        if ((fp = fopen(file, "r")) == NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   273
          _cached_src = NULL;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   274
          return;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   275
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   276
        _cached_src = file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   277
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   278
        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
   279
        while (fgets(line, sizeof(line), fp) != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   280
          size_t len = strlen(line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   281
          if (len > 0 && line[len-1] == '\n') {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   282
            line[len-1] = '\0';
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   283
          }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   284
          _cached_src_lines->append(os::strdup(line));
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   285
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   286
        fclose(fp);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   287
        _print_file_name = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   288
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   289
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   290
      if (_print_file_name) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   291
        // 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
   292
        // 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
   293
        _print_file_name = false;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   294
        if (newline) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   295
          st->cr();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   296
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   297
        st->move_to(COMMENT_COLUMN);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   298
        st->print(";;@FILE: %s", file);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   299
        newline = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   300
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   301
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   302
      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
   303
      if (index >= _cached_src_lines->length()) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   304
        // 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
   305
      } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   306
        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
   307
        if (newline) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   308
          st->cr();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   309
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   310
        st->move_to(COMMENT_COLUMN);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   311
        st->print(";;%5d: %s", line, source_line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   312
        newline = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   313
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   314
    }
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
55593
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   318
decode_env::decode_env(CodeBuffer* code, outputStream* output) :
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   319
  _output(output ? output : tty),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   320
  _codeBuffer(code),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   321
  _codeBlob(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   322
  _nm(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   323
  _strings(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   324
  _start(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   325
  _end(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   326
  _option_buf(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   327
  _print_raw(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   328
  _cur_insn(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   329
  _bytes_per_line(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   330
  _pre_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   331
  _post_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   332
  _print_file_name(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   333
  _print_help(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   334
  _helpPrinted(false) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   335
55593
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   336
  memset(_option_buf, 0, sizeof(_option_buf));
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   337
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   338
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   339
55593
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   340
decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c) :
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   341
  _output(output ? output : tty),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   342
  _codeBuffer(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   343
  _codeBlob(code),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   344
  _nm(_codeBlob != NULL && _codeBlob->is_nmethod() ? (nmethod*) code : NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   345
  _strings(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   346
  _start(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   347
  _end(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   348
  _option_buf(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   349
  _print_raw(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   350
  _cur_insn(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   351
  _bytes_per_line(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   352
  _pre_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   353
  _post_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   354
  _print_file_name(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   355
  _print_help(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   356
  _helpPrinted(false) {
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   357
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   358
  memset(_option_buf, 0, sizeof(_option_buf));
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   359
  _strings.copy(c);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   360
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   361
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   362
55593
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   363
decode_env::decode_env(nmethod* code, outputStream* output, CodeStrings c) :
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   364
  _output(output ? output : tty),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   365
  _codeBuffer(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   366
  _codeBlob(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   367
  _nm(code),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   368
  _strings(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   369
  _start(_nm->code_begin()),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   370
  _end(_nm->code_end()),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   371
  _option_buf(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   372
  _print_raw(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   373
  _cur_insn(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   374
  _bytes_per_line(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   375
  _pre_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   376
  _post_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   377
  _print_file_name(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   378
  _print_help(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   379
  _helpPrinted(false) {
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   380
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   381
  memset(_option_buf, 0, sizeof(_option_buf));
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25468
diff changeset
   382
  _strings.copy(c);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   383
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   384
}
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   385
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   386
// Constructor for a 'decode_env' to decode a memory range [start, end)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   387
// of unknown origin, assuming it contains code.
55593
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   388
decode_env::decode_env(address start, address end, outputStream* output) :
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   389
  _output(output ? output : tty),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   390
  _codeBuffer(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   391
  _codeBlob(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   392
  _nm(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   393
  _strings(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   394
  _start(start),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   395
  _end(end),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   396
  _option_buf(),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   397
  _print_raw(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   398
  _cur_insn(NULL),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   399
  _bytes_per_line(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   400
  _pre_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   401
  _post_decode_alignment(0),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   402
  _print_file_name(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   403
  _print_help(false),
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   404
  _helpPrinted(false) {
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   405
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   406
  assert(start < end, "Range must have a positive size, [" PTR_FORMAT ".." PTR_FORMAT ").", p2i(start), p2i(end));
55593
963924f1c891 8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
rkennke
parents: 55329
diff changeset
   407
  memset(_option_buf, 0, sizeof(_option_buf));
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   408
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   409
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   410
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   411
void decode_env::process_options(outputStream* ost) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   412
  // by default, output pc but not bytes:
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   413
  _print_help      = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   414
  _bytes_per_line  = Disassembler::pd_instruction_alignment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   415
  _print_file_name = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   416
59309
be238525d240 8234583: PrintAssemblyOptions isn't passed to hsdis library
lucy
parents: 55593
diff changeset
   417
  // parse the global option string
be238525d240 8234583: PrintAssemblyOptions isn't passed to hsdis library
lucy
parents: 55593
diff changeset
   418
  // We need to fill the options buffer for each newly created
be238525d240 8234583: PrintAssemblyOptions isn't passed to hsdis library
lucy
parents: 55593
diff changeset
   419
  // decode_env instance. The hsdis_* library looks for options
be238525d240 8234583: PrintAssemblyOptions isn't passed to hsdis library
lucy
parents: 55593
diff changeset
   420
  // in that buffer.
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   421
  collect_options(Disassembler::pd_cpu_opts());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   422
  collect_options(PrintAssemblyOptions);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   423
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   424
  if (strstr(options(), "print-raw")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   425
    _print_raw = (strstr(options(), "xml") ? 2 : 1);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   426
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   427
59309
be238525d240 8234583: PrintAssemblyOptions isn't passed to hsdis library
lucy
parents: 55593
diff changeset
   428
  if (_optionsParsed) return;  // parse only once
be238525d240 8234583: PrintAssemblyOptions isn't passed to hsdis library
lucy
parents: 55593
diff changeset
   429
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   430
  if (strstr(options(), "help")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   431
    _print_help = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   432
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   433
  if (strstr(options(), "align-instr")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   434
    AbstractDisassembler::toggle_align_instr();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   435
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   436
  if (strstr(options(), "show-pc")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   437
    AbstractDisassembler::toggle_show_pc();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   438
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   439
  if (strstr(options(), "show-offset")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   440
    AbstractDisassembler::toggle_show_offset();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   441
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   442
  if (strstr(options(), "show-bytes")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   443
    AbstractDisassembler::toggle_show_bytes();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   444
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   445
  if (strstr(options(), "show-data-hex")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   446
    AbstractDisassembler::toggle_show_data_hex();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   447
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   448
  if (strstr(options(), "show-data-int")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   449
    AbstractDisassembler::toggle_show_data_int();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   450
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   451
  if (strstr(options(), "show-data-float")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   452
    AbstractDisassembler::toggle_show_data_float();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   453
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   454
  if (strstr(options(), "show-structs")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   455
    AbstractDisassembler::toggle_show_structs();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   456
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   457
  if (strstr(options(), "show-comment")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   458
    AbstractDisassembler::toggle_show_comment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   459
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   460
  if (strstr(options(), "show-block-comment")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   461
    AbstractDisassembler::toggle_show_block_comment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   462
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   463
  _optionsParsed = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   464
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   465
  if (_print_help && ! _helpPrinted) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   466
    _helpPrinted = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   467
    ost->print_cr("PrintAssemblyOptions help:");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   468
    ost->print_cr("  print-raw       test plugin by requesting raw output");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   469
    ost->print_cr("  print-raw-xml   test plugin by requesting raw xml");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   470
    ost->cr();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   471
    ost->print_cr("  show-pc            toggle printing current pc,        currently %s", AbstractDisassembler::show_pc()            ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   472
    ost->print_cr("  show-offset        toggle printing current offset,    currently %s", AbstractDisassembler::show_offset()        ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   473
    ost->print_cr("  show-bytes         toggle printing instruction bytes, currently %s", AbstractDisassembler::show_bytes()         ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   474
    ost->print_cr("  show-data-hex      toggle formatting data as hex,     currently %s", AbstractDisassembler::show_data_hex()      ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   475
    ost->print_cr("  show-data-int      toggle formatting data as int,     currently %s", AbstractDisassembler::show_data_int()      ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   476
    ost->print_cr("  show-data-float    toggle formatting data as float,   currently %s", AbstractDisassembler::show_data_float()    ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   477
    ost->print_cr("  show-structs       toggle compiler data structures,   currently %s", AbstractDisassembler::show_structs()       ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   478
    ost->print_cr("  show-comment       toggle instruction comments,       currently %s", AbstractDisassembler::show_comment()       ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   479
    ost->print_cr("  show-block-comment toggle block comments,             currently %s", AbstractDisassembler::show_block_comment() ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   480
    ost->print_cr("  align-instr        toggle instruction alignment,      currently %s", AbstractDisassembler::align_instr()        ? "ON" : "OFF");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   481
    ost->print_cr("combined options: %s", options());
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   482
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   483
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   484
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   485
// Disassembly Event Handler.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   486
// This method receives events from the disassembler library hsdis
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   487
// via event_to_env for each decoding step (installed by
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   488
// Disassembler::decode_instructions(), replacing the default
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   489
// callback method). This enables dumping additional info
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   490
// and custom line formatting.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   491
// In a future extension, calling a custom decode method will be
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   492
// supported. We can use such a method to decode instructions the
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   493
// binutils decoder does not handle to our liking (suboptimal
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   494
// formatting, incomplete information, ...).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   495
// Returns:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   496
// - NULL for all standard invocations. The function result is not
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   497
//        examined (as of now, 20190409) by the hsdis decoder loop.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   498
// - next for 'insn0' invocations.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   499
//        next == arg: the custom decoder didn't do anything.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   500
//        next >  arg: the custom decoder did decode the instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   501
//                     next points to the next undecoded instruction
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   502
//                     (continuation point for decoder loop).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   503
//
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   504
// "Normal" sequence of events:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   505
//  insns   - start of instruction stream decoding
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   506
//  mach    - display architecture
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   507
//  format  - display bytes-per-line
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   508
//  for each instruction:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   509
//    insn    - start of instruction decoding
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   510
//    insn0   - custom decoder invocation (if any)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   511
//    addr    - print address value
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   512
//    /insn   - end of instruction decoding
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   513
//  /insns  - premature end of instruction stream due to no progress
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   514
//
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   515
address decode_env::handle_event(const char* event, address arg) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   516
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   517
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   518
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   519
  //---<  Event: end decoding loop (error, no progress)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   520
  if (decode_env::match(event, "/insns")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   521
    // Nothing to be done here.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   522
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   523
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   524
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   525
  //---<  Event: start decoding loop  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   526
  if (decode_env::match(event, "insns")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   527
    // Nothing to be done here.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   528
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   529
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   530
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   531
  //---<  Event: finish decoding an instruction  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   532
  if (decode_env::match(event, "/insn")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   533
    output()->fill_to(_post_decode_alignment);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   534
    end_insn(arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   535
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   536
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   537
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   538
  //---<  Event: start decoding an instruction  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   539
  if (decode_env::match(event, "insn")) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   540
    start_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   541
  } else if (match(event, "/insn")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   542
    end_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   543
  } else if (match(event, "addr")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   544
    if (arg != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   545
      print_address(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   546
      return arg;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   547
    }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   548
    calculate_alignment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   549
    output()->fill_to(_pre_decode_alignment);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   550
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   551
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   552
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   553
  //---<  Event: call custom decoder (platform specific)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   554
  if (decode_env::match(event, "insn0")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   555
    return Disassembler::decode_instruction0(arg, output(), arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   556
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   557
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   558
  //---<  Event: Print address  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   559
  if (decode_env::match(event, "addr")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   560
    print_address(arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   561
    return arg;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   562
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   563
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   564
  //---<  Event: mach (inform about machine architecture)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   565
  // This event is problematic because it messes up the output.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   566
  // The event is fired after the instruction address has already
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   567
  // been printed. The decoded instruction (event "insn") is
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   568
  // printed afterwards. That doesn't look nice.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   569
  if (decode_env::match(event, "mach")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   570
    guarantee(arg != NULL, "event_to_env - arg must not be NULL for event 'mach'");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   571
    static char buffer[64] = { 0, };
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   572
    // Output suppressed because it messes up disassembly.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   573
    // Only print this when the mach changes.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   574
    if (false && (strcmp(buffer, (const char*)arg) != 0 ||
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   575
                  strlen((const char*)arg) > sizeof(buffer) - 1)) {
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   576
      // 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
   577
      strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
30281
b1608535e50f 8076475: Misuses of strncpy/strncat
stuefe
parents: 29362
diff changeset
   578
      buffer[sizeof(buffer) - 1] = '\0';
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   579
      output()->print_cr("[Disassembling for mach='%s']", (const char*)arg);
10017
34ddce3361b7 7062856: Disassembler needs to be smarter about finding hsdis after 1.7 launcher changes
never
parents: 9630
diff changeset
   580
    }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   581
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   582
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   583
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   584
  //---<  Event: format bytes-per-line  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   585
  if (decode_env::match(event, "format bytes-per-line")) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   586
    _bytes_per_line = (int) (intptr_t) arg;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   587
    return NULL;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   588
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   589
#endif
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   590
  return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   591
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   592
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   593
static void* event_to_env(void* env_pv, const char* event, void* arg) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   594
  decode_env* env = (decode_env*) env_pv;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   595
  return env->handle_event(event, (address) arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   596
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   597
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   598
// 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
   599
void decode_env::print_address(address adr) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   600
  outputStream* st = output();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   601
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   602
  if (adr == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   603
    st->print("NULL");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   604
    return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   605
  }
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
  int small_num = (int)(intptr_t)adr;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   608
  if ((intptr_t)adr == (intptr_t)small_num
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   609
      && -1 <= small_num && small_num <= 9) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   610
    st->print("%d", small_num);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   611
    return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   612
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   613
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   614
  if (Universe::is_fully_initialized()) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   615
    if (StubRoutines::contains(adr)) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   616
      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
   617
      if (desc == NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   618
        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
   619
      }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   620
      if (desc != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   621
        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
   622
        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
   623
          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
   624
        } else if (WizardMode) {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   625
          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
   626
        }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   627
        return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   628
      }
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   629
      st->print("Stub::<unknown> " PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   630
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   631
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   632
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49455
diff changeset
   633
    BarrierSet* bs = BarrierSet::barrier_set();
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
   634
    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
   635
        adr == ci_card_table_address_as<address>()) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   636
      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
   637
      if (WizardMode) st->print(" " INTPTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   638
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   639
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   640
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   641
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   642
  if (_nm == NULL) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   643
    // 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
   644
    // nmethod::reloc_string_for().
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   645
    // Allocate the buffer on the stack instead of as RESOURCE array.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   646
    // In case we do DecodeErrorFile, Thread will not be initialized,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   647
    // causing a "assert(current != __null) failed" failure.
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   648
    const int buflen = 1024;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   649
    char buf[buflen];
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   650
    int offset;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   651
    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
   652
      st->print(PTR_FORMAT " = %s",  p2i(adr), buf);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   653
      if (offset != 0) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   654
        st->print("+%d", offset);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   655
      }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   656
      return;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   657
    }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   658
  }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   659
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 8921
diff changeset
   660
  // 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
   661
  st->print(PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   662
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   663
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   664
void decode_env::print_insn_labels() {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   665
  if (AbstractDisassembler::show_block_comment()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   666
    address       p  = cur_insn();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   667
    outputStream* st = output();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   668
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   669
    //---<  Block comments for nmethod  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   670
    // Outputs a bol() before and a cr() after, but only if a comment is printed.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   671
    // Prints nmethod_section_label as well.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   672
    if (_nm != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   673
      _nm->print_block_comment(st, p);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   674
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   675
    if (_codeBlob != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   676
      _codeBlob->print_block_comment(st, p);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   677
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   678
    if (_codeBuffer != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   679
      _codeBuffer->print_block_comment(st, p);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   680
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   681
    _strings.print_block_comment(st, (intptr_t)(p - _start));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   682
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   683
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   684
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   685
void decode_env::print_insn_prefix() {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   686
  address       p  = cur_insn();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   687
  outputStream* st = output();
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   688
  AbstractDisassembler::print_location(p, _start, _end, st, false, false);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   689
  AbstractDisassembler::print_instruction(p, Assembler::instr_len(p), Assembler::instr_maxlen(), st, true, false);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   690
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   691
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
   692
ATTRIBUTE_PRINTF(2, 3)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   693
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
   694
  decode_env* env = (decode_env*) env_pv;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   695
  outputStream* st = env->output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   696
  size_t flen = strlen(format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   697
  const char* raw = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   698
  if (flen == 0)  return 0;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   699
  if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   700
  if (flen < 2 ||
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   701
      strchr(format, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   702
    raw = format;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   703
  } else if (format[0] == '%' && format[1] == '%' &&
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   704
             strchr(format+2, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   705
    // happens a lot on machines with names like %foo
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   706
    flen--;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   707
    raw = format+1;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   708
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   709
  if (raw != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   710
    st->print_raw(raw, (int) flen);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   711
    return (int) flen;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   712
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   713
  va_list ap;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   714
  va_start(ap, format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   715
  julong cnt0 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   716
  st->vprint(format, ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   717
  julong cnt1 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   718
  va_end(ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   719
  return (int)(cnt1 - cnt0);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   720
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   721
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   722
// The 'original_start' argument holds the the original address where
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   723
// the instructions were located in the originating system. If zero (NULL)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   724
// is passed in, there is no original address.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   725
address decode_env::decode_instructions(address start, address end, address original_start /* = 0*/) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   726
  // CodeComment in Stubs.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   727
  // Properly initialize _start/_end. Overwritten too often if
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   728
  // printing of instructions is called for each instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   729
  assert((_start == NULL) || (start == NULL) || (_start == start), "don't overwrite CTOR values");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   730
  assert((_end   == NULL) || (end   == NULL) || (_end   == end  ), "don't overwrite CTOR values");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   731
  if (start != NULL) set_start(start);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   732
  if (end   != NULL) set_end(end);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   733
  if (original_start == NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   734
    original_start = start;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   735
  }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   736
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   737
  //---<  Check (and correct) alignment  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   738
  // Don't check alignment of end, it is not aligned.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   739
  if (((uint64_t)start & ((uint64_t)Disassembler::pd_instruction_alignment() - 1)) != 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   740
    output()->print_cr("Decode range start:" PTR_FORMAT ": ... (unaligned)", p2i(start));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   741
    start = (address)((uint64_t)start & ~((uint64_t)Disassembler::pd_instruction_alignment() - 1));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   742
  }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   743
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   744
  // Trying to decode instructions doesn't make sense if we
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   745
  // couldn't load the disassembler library.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   746
  if (Disassembler::is_abstract()) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   747
    return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   748
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   749
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   750
  // 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
   751
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   752
  if (_print_raw) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   753
    // 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
   754
    // This is mainly for debugging the library itself.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   755
    FILE* out = stdout;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   756
    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
   757
    return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   758
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   759
      (*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
   760
                                                    start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   761
                                                    NULL, (void*) xmlout,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   762
                                                    NULL, (void*) out,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   763
                                                    options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   764
      :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   765
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   766
      (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   767
                                            NULL, (void*) xmlout,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   768
                                            NULL, (void*) out,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   769
                                            options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   770
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   771
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   772
  return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   773
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   774
    (*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
   775
                                                  start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   776
                                                  &event_to_env,  (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   777
                                                  &printf_to_env, (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   778
                                                  options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   779
    :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   780
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   781
    (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   782
                                          &event_to_env,  (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   783
                                          &printf_to_env, (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   784
                                          options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   785
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   786
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   787
// ----------------------------------------------------------------------------
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   788
// Disassembler
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   789
// Used as a static wrapper for decode_env.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   790
// Each method will create a decode_env before decoding.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   791
// You can call the decode_env methods directly if you already have one.
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   792
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   793
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   794
bool Disassembler::load_library(outputStream* st) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   795
  // Do not try to load multiple times. Failed once -> fails always.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   796
  // To force retry in debugger: assign _tried_to_load_library=0
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   797
  if (_tried_to_load_library) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   798
    return _library_usable;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   799
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   800
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   801
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   802
  // Print to given stream, if any.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   803
  // Print to tty if Verbose is on and no stream given.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   804
  st = ((st == NULL) && Verbose) ? tty : st;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   805
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   806
  // Compute fully qualified library name.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   807
  char ebuf[1024];
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   808
  char buf[JVM_MAXPATHLEN];
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   809
  os::jvm_path(buf, sizeof(buf));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   810
  int jvm_offset = -1;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   811
  int lib_offset = -1;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   812
#ifdef STATIC_BUILD
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   813
  char* p = strrchr(buf, '/');
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   814
  *p = '\0';
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   815
  strcat(p, "/lib/");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   816
  lib_offset = jvm_offset = strlen(buf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   817
#else
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   818
  {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   819
    // Match "libjvm" instead of "jvm" on *nix platforms. Creates better matches.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   820
    // Match "[lib]jvm[^/]*" in jvm_path.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   821
    const char* base = buf;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   822
    const char* p = strrchr(buf, *os::file_separator());
55051
fb9758536458 8224672: (lib)hsdis-<arch>.so search incorrect after JDK-8213084
lucy
parents: 54994
diff changeset
   823
    if (p != NULL) lib_offset = p - base + 1; // this points to the first char after separator
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   824
#ifdef _WIN32
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   825
    p = strstr(p ? p : base, "jvm");
55051
fb9758536458 8224672: (lib)hsdis-<arch>.so search incorrect after JDK-8213084
lucy
parents: 54994
diff changeset
   826
    if (p != NULL) jvm_offset = p - base;     // this points to 'j' in jvm.
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   827
#else
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   828
    p = strstr(p ? p : base, "libjvm");
55051
fb9758536458 8224672: (lib)hsdis-<arch>.so search incorrect after JDK-8213084
lucy
parents: 54994
diff changeset
   829
    if (p != NULL) jvm_offset = p - base + 3; // this points to 'j' in libjvm.
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   830
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   831
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   832
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   833
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   834
  // Find the disassembler shared library.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   835
  // Search for several paths derived from libjvm, in this order:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   836
  // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so  (for compatibility)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   837
  // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   838
  // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   839
  // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   840
  if (jvm_offset >= 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   841
    // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   842
    strcpy(&buf[jvm_offset], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   843
    strcat(&buf[jvm_offset], os::dll_file_extension());
55051
fb9758536458 8224672: (lib)hsdis-<arch>.so search incorrect after JDK-8213084
lucy
parents: 54994
diff changeset
   844
    if (Verbose) st->print_cr("Trying to load: %s", buf);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   845
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   846
    if (_library == NULL && lib_offset >= 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   847
      // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   848
      strcpy(&buf[lib_offset], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   849
      strcat(&buf[lib_offset], os::dll_file_extension());
55051
fb9758536458 8224672: (lib)hsdis-<arch>.so search incorrect after JDK-8213084
lucy
parents: 54994
diff changeset
   850
      if (Verbose) st->print_cr("Trying to load: %s", buf);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   851
      _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   852
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   853
    if (_library == NULL && lib_offset > 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   854
      // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   855
      buf[lib_offset - 1] = '\0';
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   856
      const char* p = strrchr(buf, *os::file_separator());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   857
      if (p != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   858
        lib_offset = p - buf + 1;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   859
        strcpy(&buf[lib_offset], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   860
        strcat(&buf[lib_offset], os::dll_file_extension());
55051
fb9758536458 8224672: (lib)hsdis-<arch>.so search incorrect after JDK-8213084
lucy
parents: 54994
diff changeset
   861
        if (Verbose) st->print_cr("Trying to load: %s", buf);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   862
        _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   863
      }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   864
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   865
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   866
  if (_library == NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   867
    // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   868
    strcpy(&buf[0], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   869
    strcat(&buf[0], os::dll_file_extension());
55051
fb9758536458 8224672: (lib)hsdis-<arch>.so search incorrect after JDK-8213084
lucy
parents: 54994
diff changeset
   870
    if (Verbose) st->print_cr("Trying to load: %s via LD_LIBRARY_PATH or equivalent", buf);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   871
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   872
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   873
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   874
  // load the decoder function to use (new or old version).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   875
  if (_library != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   876
    _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   877
                                          os::dll_lookup(_library, decode_instructions_virtual_name));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   878
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   879
  if (_decode_instructions_virtual == NULL && _library != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   880
    // could not spot in new version, try old version
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   881
    _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   882
                                          os::dll_lookup(_library, decode_instructions_name));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   883
    use_new_version = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   884
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   885
    use_new_version = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   886
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   887
  _tried_to_load_library = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   888
  _library_usable        = _decode_instructions_virtual != NULL || _decode_instructions != NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   889
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   890
  // Create a dummy environment to initialize PrintAssemblyOptions.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   891
  // The PrintAssemblyOptions must be known for abstract disassemblies as well.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   892
  decode_env dummy((unsigned char*)(&buf[0]), (unsigned char*)(&buf[1]), st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   893
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   894
  // Report problems during dll_load or dll_lookup, if any.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   895
  if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   896
    // Success.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   897
    if (_library_usable) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   898
      st->print_cr("Loaded disassembler from %s", buf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   899
    } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   900
      st->print_cr("Could not load %s; %s; %s",
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   901
                   buf,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   902
                   ((_library != NULL)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   903
                    ? "entry point is missing"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   904
                    : ((WizardMode || PrintMiscellaneous)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   905
                       ? (const char*)ebuf
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   906
                       : "library not loadable")),
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   907
                   "PrintAssembly defaults to abstract disassembly.");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   908
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   909
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   910
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   911
  return _library_usable;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   912
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   913
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   914
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   915
// Directly disassemble code buffer.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   916
void Disassembler::decode(CodeBuffer* cb, address start, address end, outputStream* st) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   917
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   918
  //---<  Test memory before decoding  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   919
  if (!(cb->contains(start) && cb->contains(end))) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   920
    //---<  Allow output suppression, but prevent writing to a NULL stream. Could happen with +PrintStubCode.  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   921
    if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   922
      st->print("Memory range [" PTR_FORMAT ".." PTR_FORMAT "] not contained in CodeBuffer", p2i(start), p2i(end));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   923
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   924
    return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   925
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   926
  if (!os::is_readable_range(start, end)) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   927
    //---<  Allow output suppression, but prevent writing to a NULL stream. Could happen with +PrintStubCode.  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   928
    if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   929
      st->print("Memory range [" PTR_FORMAT ".." PTR_FORMAT "] not readable", p2i(start), p2i(end));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   930
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   931
    return;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   932
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   933
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   934
  decode_env env(cb, st);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   935
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   936
  env.output()->print("Decoding CodeBuffer (" PTR_FORMAT ")", p2i(cb));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   937
  if (cb->name() != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   938
    env.output()->print(", name: %s,", cb->name());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   939
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   940
  env.output()->print_cr(" at  [" PTR_FORMAT ", " PTR_FORMAT "]  " JLONG_FORMAT " bytes", p2i(start), p2i(end), ((jlong)(end - start)));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   941
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   942
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   943
    AbstractDisassembler::decode_abstract(start, end, env.output(), Assembler::instr_maxlen());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   944
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   945
    env.decode_instructions(start, end);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   946
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   947
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   948
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   949
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   950
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   951
// Directly disassemble code blob.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   952
void Disassembler::decode(CodeBlob* cb, outputStream* st, CodeStrings c) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   953
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   954
  if (cb->is_nmethod()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   955
    // If we  have an nmethod at hand,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   956
    // call the specialized decoder directly.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   957
    decode((nmethod*)cb, st, c);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   958
    return;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   959
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   961
  decode_env env(cb, st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   962
  env.output()->print_cr("--------------------------------------------------------------------------------");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   963
  if (cb->is_aot()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   964
    env.output()->print("A ");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   965
    if (cb->is_compiled()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   966
      CompiledMethod* cm = (CompiledMethod*)cb;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   967
      env.output()->print("%d ",cm->compile_id());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   968
      cm->method()->method_holder()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   969
      env.output()->print(".");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   970
      cm->method()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   971
      cm->method()->signature()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   972
    } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   973
      env.output()->print_cr("%s", cb->name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   974
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   975
  } else {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   976
    env.output()->print("Decoding CodeBlob");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   977
    if (cb->name() != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   978
      env.output()->print(", name: %s,", cb->name());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   979
    }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   980
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   981
  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())));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   982
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   983
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   984
    AbstractDisassembler::decode_abstract(cb->code_begin(), cb->code_end(), env.output(), Assembler::instr_maxlen());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   985
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   986
    env.decode_instructions(cb->code_begin(), cb->code_end());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   987
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   988
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   989
#endif
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   990
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   991
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   992
// Decode a nmethod.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   993
// This includes printing the constant pool and all code segments.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   994
// The nmethod data structures (oop maps, relocations and the like) are not printed.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   995
void Disassembler::decode(nmethod* nm, outputStream* st, CodeStrings c) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   996
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
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
   997
  ttyLocker ttyl;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   998
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   999
  decode_env env(nm, st);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1000
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1001
  nm->print_constant_pool(env.output());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1002
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1003
  env.output()->cr();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1004
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1005
    AbstractDisassembler::decode_abstract(nm->code_begin(), nm->code_end(), env.output(), Assembler::instr_maxlen());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1006
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1007
    env.decode_instructions(nm->code_begin(), nm->code_end());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1008
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1009
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1010
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1011
}
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
  1012
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1013
// Decode a range, given as [start address, end address)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1014
void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c /*, ptrdiff_t offset */) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1015
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1016
  //---<  Test memory before decoding  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1017
  if (!os::is_readable_range(start, end)) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1018
    //---<  Allow output suppression, but prevent writing to a NULL stream. Could happen with +PrintStubCode.  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1019
    if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1020
      st->print("Memory range [" PTR_FORMAT ".." PTR_FORMAT "] not readable", p2i(start), p2i(end));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1021
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1022
    return;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1023
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1024
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1025
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1026
    AbstractDisassembler::decode_abstract(start, end, st, Assembler::instr_maxlen());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1027
    return;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1028
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1029
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1030
// Don't do that fancy stuff. If we just have two addresses, live with it
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1031
// and treat the memory contents as "amorphic" piece of code.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1032
#if 0
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1033
  CodeBlob* cb = CodeCache::find_blob_unsafe(start);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1034
  if (cb != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1035
    // If we  have an CodeBlob at hand,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1036
    // call the specialized decoder directly.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1037
    decode(cb, st, c);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1038
  } else
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1039
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
  1040
  {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1041
    // This seems to be just a chunk of memory.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1042
    decode_env env(start, end, st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1043
    env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1044
    env.decode_instructions(start, end);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
  1045
    env.output()->print_cr("--------------------------------------------------------------------------------");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
  1046
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
  1047
#endif
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
  1048
}
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
  1049
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
  1050
// 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
  1051
// 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
  1052
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
  1053
  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
  1054
}