src/hotspot/share/compiler/disassembler.cpp
author aoqi
Thu, 23 May 2019 00:21:39 +0800
changeset 54994 faf89c9568bd
parent 54960 e46fe26d7f77
child 55051 fb9758536458
permissions -rw-r--r--
8224568: minimal and zero build fails after JDK-8213084 Reviewed-by: shade, lucy Contributed-by: Ao Qi <aoqi@loongson.cn>
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)) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   150
        _nm->print_code_comment_on(st, _post_decode_alignment, pc0, pc);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   151
        // 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
   152
      }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   153
      print_hook_comments(pc0, _nm != NULL);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   154
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   155
    Disassembler::annotate(pc0, output());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   156
    // follow each complete insn by a nice newline
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   157
    st->bol();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   158
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   159
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   160
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   161
  struct SourceFileInfo {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   162
    struct Link : public CHeapObj<mtCode> {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   163
      const char* file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   164
      int line;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   165
      Link* next;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   166
      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
   167
    };
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   168
    Link *head, *tail;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   169
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   170
    static unsigned hash(const address& a) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   171
      return primitive_hash<address>(a);
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 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
   174
      return primitive_equals<address>(a0, a1);
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
    void append(const char* file, int line) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   177
      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
   178
        // 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
   179
        // 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
   180
        return;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   181
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   182
      Link *link = new Link(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   183
      if (head == NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   184
        head = tail = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   185
      } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   186
        tail->next = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   187
        tail = link;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   188
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   189
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   190
    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
   191
      append(file, line);
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
  };
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   194
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   195
  typedef ResourceHashtable<
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   196
      address, SourceFileInfo,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   197
      SourceFileInfo::hash,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   198
      SourceFileInfo::equals,
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   199
      15889,      // prime number
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   200
      ResourceObj::C_HEAP> SourceFileInfoTable;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   201
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   202
  static SourceFileInfoTable _src_table;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   203
  static const char* _cached_src;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   204
  static GrowableArray<const char*>* _cached_src_lines;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   205
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   206
 public:
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   207
  decode_env(CodeBuffer* code, outputStream* output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   208
  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
   209
  decode_env(nmethod*    code, outputStream* output, CodeStrings c = CodeStrings());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   210
  // Constructor for a 'decode_env' to decode an arbitrary
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   211
  // piece of memory, hopefully containing code.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   212
  decode_env(address start, address end, outputStream* output);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   213
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   214
  // Add 'original_start' argument which is the the original address
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   215
  // 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
   216
  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
   217
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   218
  address handle_event(const char* event, address arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   219
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   220
  outputStream* output()   { return _output; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   221
  address       cur_insn() { return _cur_insn; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   222
  const char*   options()  { return _option_buf; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   223
  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
   224
  void print_hook_comments(address pc, bool newline);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   225
};
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   226
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   227
bool decode_env::_optionsParsed = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   228
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   229
decode_env::SourceFileInfoTable decode_env::_src_table;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   230
const char* decode_env::_cached_src = NULL;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   231
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
   232
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   233
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
   234
  // 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
   235
  // 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
   236
  // 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
   237
  // memory usage doesn't matter.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   238
  SourceFileInfo* found = _src_table.get(pc);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   239
  if (found != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   240
    found->append(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   241
  } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   242
    SourceFileInfo sfi(file, line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   243
    _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
   244
  }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   245
}
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   246
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   247
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
   248
  SourceFileInfo* found = _src_table.get(pc);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   249
  outputStream* st = output();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   250
  if (found != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   251
    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
   252
      const char* file = link->file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   253
      int line = link->line;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   254
      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
   255
        FILE* fp;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   256
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   257
        // _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
   258
        // 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
   259
        // but seems bearable.
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   260
        if (_cached_src_lines != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   261
          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
   262
            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
   263
          }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   264
          _cached_src_lines->clear();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   265
        } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   266
          _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
   267
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   268
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   269
        if ((fp = fopen(file, "r")) == NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   270
          _cached_src = NULL;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   271
          return;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   272
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   273
        _cached_src = file;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   274
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   275
        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
   276
        while (fgets(line, sizeof(line), fp) != NULL) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   277
          size_t len = strlen(line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   278
          if (len > 0 && line[len-1] == '\n') {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   279
            line[len-1] = '\0';
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   280
          }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   281
          _cached_src_lines->append(os::strdup(line));
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   282
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   283
        fclose(fp);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   284
        _print_file_name = true;
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
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   287
      if (_print_file_name) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   288
        // 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
   289
        // 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
   290
        _print_file_name = false;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   291
        if (newline) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   292
          st->cr();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   293
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   294
        st->move_to(COMMENT_COLUMN);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   295
        st->print(";;@FILE: %s", file);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   296
        newline = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   297
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   298
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   299
      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
   300
      if (index >= _cached_src_lines->length()) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   301
        // 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
   302
      } else {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   303
        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
   304
        if (newline) {
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   305
          st->cr();
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   306
        }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   307
        st->move_to(COMMENT_COLUMN);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   308
        st->print(";;%5d: %s", line, source_line);
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   309
        newline = true;
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   310
      }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   311
    }
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   312
  }
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
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   315
decode_env::decode_env(CodeBuffer* code, outputStream* output) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   316
  memset(this, 0, sizeof(*this));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   317
  _output = output ? output : tty;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   318
  _codeBlob    = NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   319
  _codeBuffer  = code;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   320
  _helpPrinted = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   321
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   322
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   323
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   324
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   325
decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   326
   memset(this, 0, sizeof(*this)); // Beware, this zeroes bits of fields.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   327
   _output = output ? output : tty;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   328
  _codeBlob    = code;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   329
  _codeBuffer  = NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   330
  _helpPrinted = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   331
  if (_codeBlob != NULL && _codeBlob->is_nmethod()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   332
    _nm = (nmethod*) code;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   333
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   334
  _strings.copy(c);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   335
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   336
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   337
}
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
decode_env::decode_env(nmethod* code, outputStream* output, CodeStrings c) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   340
  memset(this, 0, sizeof(*this)); // Beware, this zeroes bits of fields.
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   341
  _output = output ? output : tty;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   342
  _codeBlob    = NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   343
  _codeBuffer  = NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   344
  _nm          = code;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   345
  _start       = _nm->code_begin();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   346
  _end         = _nm->code_end();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   347
  _helpPrinted = false;
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25468
diff changeset
   348
  _strings.copy(c);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   349
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   350
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   351
}
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   352
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   353
// 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
   354
// of unknown origin, assuming it contains code.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   355
decode_env::decode_env(address start, address end, outputStream* output) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   356
  assert(start < end, "Range must have a positive size, [" PTR_FORMAT ".." PTR_FORMAT ").", p2i(start), p2i(end));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   357
  memset(this, 0, sizeof(*this));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   358
  _output = output ? output : tty;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   359
  _codeBlob    = NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   360
  _codeBuffer  = NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   361
  _start       = start;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   362
  _end         = end;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   363
  _helpPrinted = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   364
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   365
  process_options(_output);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   366
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   367
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   368
void decode_env::process_options(outputStream* ost) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   369
  // by default, output pc but not bytes:
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   370
  _print_help      = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   371
  _bytes_per_line  = Disassembler::pd_instruction_alignment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   372
  _print_file_name = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   373
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   374
  if (_optionsParsed) return;  // parse only once
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   375
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   376
  // parse the global option string:
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   377
  collect_options(Disassembler::pd_cpu_opts());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   378
  collect_options(PrintAssemblyOptions);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   379
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   380
  if (strstr(options(), "print-raw")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   381
    _print_raw = (strstr(options(), "xml") ? 2 : 1);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   382
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   383
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   384
  if (strstr(options(), "help")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   385
    _print_help = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   386
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   387
  if (strstr(options(), "align-instr")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   388
    AbstractDisassembler::toggle_align_instr();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   389
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   390
  if (strstr(options(), "show-pc")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   391
    AbstractDisassembler::toggle_show_pc();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   392
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   393
  if (strstr(options(), "show-offset")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   394
    AbstractDisassembler::toggle_show_offset();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   395
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   396
  if (strstr(options(), "show-bytes")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   397
    AbstractDisassembler::toggle_show_bytes();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   398
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   399
  if (strstr(options(), "show-data-hex")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   400
    AbstractDisassembler::toggle_show_data_hex();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   401
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   402
  if (strstr(options(), "show-data-int")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   403
    AbstractDisassembler::toggle_show_data_int();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   404
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   405
  if (strstr(options(), "show-data-float")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   406
    AbstractDisassembler::toggle_show_data_float();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   407
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   408
  if (strstr(options(), "show-structs")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   409
    AbstractDisassembler::toggle_show_structs();
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
  if (strstr(options(), "show-comment")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   412
    AbstractDisassembler::toggle_show_comment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   413
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   414
  if (strstr(options(), "show-block-comment")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   415
    AbstractDisassembler::toggle_show_block_comment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   416
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   417
  _optionsParsed = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   418
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   419
  if (_print_help && ! _helpPrinted) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   420
    _helpPrinted = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   421
    ost->print_cr("PrintAssemblyOptions help:");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   422
    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
   423
    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
   424
    ost->cr();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   425
    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
   426
    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
   427
    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
   428
    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
   429
    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
   430
    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
   431
    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
   432
    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
   433
    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
   434
    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
   435
    ost->print_cr("combined options: %s", options());
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   436
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   437
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   438
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   439
// Disassembly Event Handler.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   440
// This method receives events from the disassembler library hsdis
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   441
// via event_to_env for each decoding step (installed by
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   442
// Disassembler::decode_instructions(), replacing the default
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   443
// callback method). This enables dumping additional info
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   444
// and custom line formatting.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   445
// 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
   446
// 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
   447
// binutils decoder does not handle to our liking (suboptimal
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   448
// formatting, incomplete information, ...).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   449
// Returns:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   450
// - NULL for all standard invocations. The function result is not
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   451
//        examined (as of now, 20190409) by the hsdis decoder loop.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   452
// - next for 'insn0' invocations.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   453
//        next == arg: the custom decoder didn't do anything.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   454
//        next >  arg: the custom decoder did decode the instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   455
//                     next points to the next undecoded instruction
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   456
//                     (continuation point for decoder loop).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   457
//
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   458
// "Normal" sequence of events:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   459
//  insns   - start of instruction stream decoding
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   460
//  mach    - display architecture
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   461
//  format  - display bytes-per-line
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   462
//  for each instruction:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   463
//    insn    - start of instruction decoding
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   464
//    insn0   - custom decoder invocation (if any)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   465
//    addr    - print address value
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   466
//    /insn   - end of instruction decoding
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   467
//  /insns  - premature end of instruction stream due to no progress
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   468
//
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   469
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
   470
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   471
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   472
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   473
  //---<  Event: end decoding loop (error, no progress)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   474
  if (decode_env::match(event, "/insns")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   475
    // Nothing to be done here.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   476
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   477
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   478
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   479
  //---<  Event: start decoding loop  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   480
  if (decode_env::match(event, "insns")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   481
    // Nothing to be done here.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   482
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   483
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   484
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   485
  //---<  Event: finish decoding an instruction  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   486
  if (decode_env::match(event, "/insn")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   487
    output()->fill_to(_post_decode_alignment);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   488
    end_insn(arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   489
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   490
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   491
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   492
  //---<  Event: start decoding an instruction  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   493
  if (decode_env::match(event, "insn")) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   494
    start_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   495
  } else if (match(event, "/insn")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   496
    end_insn(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   497
  } else if (match(event, "addr")) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   498
    if (arg != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   499
      print_address(arg);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   500
      return arg;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   501
    }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   502
    calculate_alignment();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   503
    output()->fill_to(_pre_decode_alignment);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   504
    return NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   505
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   506
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   507
  //---<  Event: call custom decoder (platform specific)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   508
  if (decode_env::match(event, "insn0")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   509
    return Disassembler::decode_instruction0(arg, output(), arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   510
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   511
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   512
  //---<  Event: Print address  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   513
  if (decode_env::match(event, "addr")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   514
    print_address(arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   515
    return arg;
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
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   518
  //---<  Event: mach (inform about machine architecture)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   519
  // This event is problematic because it messes up the output.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   520
  // The event is fired after the instruction address has already
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   521
  // been printed. The decoded instruction (event "insn") is
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   522
  // printed afterwards. That doesn't look nice.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   523
  if (decode_env::match(event, "mach")) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   524
    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
   525
    static char buffer[64] = { 0, };
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   526
    // Output suppressed because it messes up disassembly.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   527
    // Only print this when the mach changes.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   528
    if (false && (strcmp(buffer, (const char*)arg) != 0 ||
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   529
                  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
   530
      // 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
   531
      strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
30281
b1608535e50f 8076475: Misuses of strncpy/strncat
stuefe
parents: 29362
diff changeset
   532
      buffer[sizeof(buffer) - 1] = '\0';
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   533
      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
   534
    }
54960
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: format bytes-per-line  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   539
  if (decode_env::match(event, "format bytes-per-line")) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   540
    _bytes_per_line = (int) (intptr_t) arg;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   541
    return NULL;
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   542
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   543
#endif
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   544
  return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   545
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   546
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   547
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
   548
  decode_env* env = (decode_env*) env_pv;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   549
  return env->handle_event(event, (address) arg);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   550
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   551
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   552
// 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
   553
void decode_env::print_address(address adr) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   554
  outputStream* st = output();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   555
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   556
  if (adr == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   557
    st->print("NULL");
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   558
    return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   559
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   560
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   561
  int small_num = (int)(intptr_t)adr;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   562
  if ((intptr_t)adr == (intptr_t)small_num
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   563
      && -1 <= small_num && small_num <= 9) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   564
    st->print("%d", small_num);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   565
    return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   566
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   567
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   568
  if (Universe::is_fully_initialized()) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   569
    if (StubRoutines::contains(adr)) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   570
      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
   571
      if (desc == NULL) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   572
        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
   573
      }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   574
      if (desc != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   575
        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
   576
        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
   577
          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
   578
        } else if (WizardMode) {
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   579
          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
   580
        }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   581
        return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   582
      }
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31592
diff changeset
   583
      st->print("Stub::<unknown> " PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   584
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   585
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   586
49754
ee93c1087584 8201362: Remove CollectedHeap::barrier_set()
pliden
parents: 49455
diff changeset
   587
    BarrierSet* bs = BarrierSet::barrier_set();
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
   588
    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
   589
        adr == ci_card_table_address_as<address>()) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   590
      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
   591
      if (WizardMode) st->print(" " INTPTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   592
      return;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   593
    }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   594
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   595
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   596
  if (_nm == NULL) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   597
    // 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
   598
    // nmethod::reloc_string_for().
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   599
    // 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
   600
    // In case we do DecodeErrorFile, Thread will not be initialized,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   601
    // causing a "assert(current != __null) failed" failure.
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   602
    const int buflen = 1024;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   603
    char buf[buflen];
35175
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   604
    int offset;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   605
    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
   606
      st->print(PTR_FORMAT " = %s",  p2i(adr), buf);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   607
      if (offset != 0) {
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   608
        st->print("+%d", offset);
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   609
      }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   610
      return;
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   611
    }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   612
  }
382588e9104a 8144853: Print the names of callees in PrintAssembly/PrintInterpreter
iklam
parents: 33585
diff changeset
   613
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 8921
diff changeset
   614
  // 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
   615
  st->print(PTR_FORMAT, p2i(adr));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   616
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   617
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   618
void decode_env::print_insn_labels() {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   619
  if (AbstractDisassembler::show_block_comment()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   620
    address       p  = cur_insn();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   621
    outputStream* st = output();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   622
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   623
    //---<  Block comments for nmethod  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   624
    // 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
   625
    // Prints nmethod_section_label as well.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   626
    if (_nm != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   627
      _nm->print_block_comment(st, p);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   628
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   629
    if (_codeBlob != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   630
      _codeBlob->print_block_comment(st, p);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   631
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   632
    if (_codeBuffer != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   633
      _codeBuffer->print_block_comment(st, p);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   634
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   635
    _strings.print_block_comment(st, (intptr_t)(p - _start));
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   636
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   637
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   638
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   639
void decode_env::print_insn_prefix() {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   640
  address       p  = cur_insn();
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   641
  outputStream* st = output();
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   642
  AbstractDisassembler::print_location(p, _start, _end, st, false, false);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   643
  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
   644
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   645
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
   646
ATTRIBUTE_PRINTF(2, 3)
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   647
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
   648
  decode_env* env = (decode_env*) env_pv;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   649
  outputStream* st = env->output();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   650
  size_t flen = strlen(format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   651
  const char* raw = NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   652
  if (flen == 0)  return 0;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   653
  if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   654
  if (flen < 2 ||
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   655
      strchr(format, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   656
    raw = format;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   657
  } else if (format[0] == '%' && format[1] == '%' &&
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   658
             strchr(format+2, '%') == NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   659
    // happens a lot on machines with names like %foo
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   660
    flen--;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   661
    raw = format+1;
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
  if (raw != NULL) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   664
    st->print_raw(raw, (int) flen);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   665
    return (int) flen;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   666
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   667
  va_list ap;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   668
  va_start(ap, format);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   669
  julong cnt0 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   670
  st->vprint(format, ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   671
  julong cnt1 = st->count();
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   672
  va_end(ap);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   673
  return (int)(cnt1 - cnt0);
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   674
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   675
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   676
// The 'original_start' argument holds the the original address where
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   677
// 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
   678
// is passed in, there is no original address.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   679
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
   680
  // CodeComment in Stubs.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   681
  // Properly initialize _start/_end. Overwritten too often if
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   682
  // printing of instructions is called for each instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   683
  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
   684
  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
   685
  if (start != NULL) set_start(start);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   686
  if (end   != NULL) set_end(end);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   687
  if (original_start == NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   688
    original_start = start;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   689
  }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   690
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   691
  //---<  Check (and correct) alignment  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   692
  // Don't check alignment of end, it is not aligned.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   693
  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
   694
    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
   695
    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
   696
  }
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   697
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   698
  // Trying to decode instructions doesn't make sense if we
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   699
  // couldn't load the disassembler library.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   700
  if (Disassembler::is_abstract()) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   701
    return NULL;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   702
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   703
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   704
  // 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
   705
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   706
  if (_print_raw) {
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   707
    // 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
   708
    // This is mainly for debugging the library itself.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   709
    FILE* out = stdout;
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   710
    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
   711
    return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   712
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   713
      (*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
   714
                                                    start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   715
                                                    NULL, (void*) xmlout,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   716
                                                    NULL, (void*) out,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   717
                                                    options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   718
      :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   719
      (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   720
      (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   721
                                            NULL, (void*) xmlout,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   722
                                            NULL, (void*) out,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   723
                                            options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   724
  }
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   725
14384
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   726
  return use_new_version ?
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   727
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   728
    (*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
   729
                                                  start, end - start,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   730
                                                  &event_to_env,  (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   731
                                                  &printf_to_env, (void*) this,
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   732
                                                  options(), 0/*nice new line*/)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   733
    :
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   734
    (address)
801df8025142 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 13897
diff changeset
   735
    (*Disassembler::_decode_instructions)(start, end,
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   736
                                          &event_to_env,  (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   737
                                          &printf_to_env, (void*) this,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   738
                                          options());
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   739
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   740
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   741
// ----------------------------------------------------------------------------
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   742
// Disassembler
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   743
// Used as a static wrapper for decode_env.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   744
// Each method will create a decode_env before decoding.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   745
// 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
   746
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   747
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   748
bool Disassembler::load_library(outputStream* st) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   749
  // 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
   750
  // 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
   751
  if (_tried_to_load_library) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   752
    return _library_usable;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   753
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   754
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   755
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   756
  // Print to given stream, if any.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   757
  // 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
   758
  st = ((st == NULL) && Verbose) ? tty : st;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   759
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   760
  // Compute fully qualified library name.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   761
  char ebuf[1024];
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   762
  char buf[JVM_MAXPATHLEN];
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   763
  os::jvm_path(buf, sizeof(buf));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   764
  int jvm_offset = -1;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   765
  int lib_offset = -1;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   766
#ifdef STATIC_BUILD
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   767
  char* p = strrchr(buf, '/');
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   768
  *p = '\0';
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   769
  strcat(p, "/lib/");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   770
  lib_offset = jvm_offset = strlen(buf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   771
#else
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   772
  {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   773
    // 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
   774
    // Match "[lib]jvm[^/]*" in jvm_path.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   775
    const char* base = buf;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   776
    const char* p = strrchr(buf, *os::file_separator());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   777
#ifdef _WIN32
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   778
    p = strstr(p ? p : base, "jvm");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   779
#else
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   780
    p = strstr(p ? p : base, "libjvm");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   781
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   782
    if (p != NULL) lib_offset = p - base + 1;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   783
    if (p != NULL) jvm_offset = p - base;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   784
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   785
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   786
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   787
  // Find the disassembler shared library.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   788
  // Search for several paths derived from libjvm, in this order:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   789
  // 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
   790
  // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   791
  // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   792
  // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   793
  if (jvm_offset >= 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   794
    // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   795
    strcpy(&buf[jvm_offset], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   796
    strcat(&buf[jvm_offset], os::dll_file_extension());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   797
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   798
    if (_library == NULL && lib_offset >= 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   799
      // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   800
      strcpy(&buf[lib_offset], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   801
      strcat(&buf[lib_offset], os::dll_file_extension());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   802
      _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   803
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   804
    if (_library == NULL && lib_offset > 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   805
      // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   806
      buf[lib_offset - 1] = '\0';
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   807
      const char* p = strrchr(buf, *os::file_separator());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   808
      if (p != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   809
        lib_offset = p - buf + 1;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   810
        strcpy(&buf[lib_offset], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   811
        strcat(&buf[lib_offset], os::dll_file_extension());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   812
        _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   813
      }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   814
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   815
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   816
  if (_library == NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   817
    // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   818
    strcpy(&buf[0], hsdis_library_name);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   819
    strcat(&buf[0], os::dll_file_extension());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   820
    _library = os::dll_load(buf, ebuf, sizeof ebuf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   821
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   822
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   823
  // load the decoder function to use (new or old version).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   824
  if (_library != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   825
    _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
   826
                                          os::dll_lookup(_library, decode_instructions_virtual_name));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   827
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   828
  if (_decode_instructions_virtual == NULL && _library != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   829
    // could not spot in new version, try old version
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   830
    _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   831
                                          os::dll_lookup(_library, decode_instructions_name));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   832
    use_new_version = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   833
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   834
    use_new_version = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   835
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   836
  _tried_to_load_library = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   837
  _library_usable        = _decode_instructions_virtual != NULL || _decode_instructions != NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   838
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   839
  // Create a dummy environment to initialize PrintAssemblyOptions.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   840
  // The PrintAssemblyOptions must be known for abstract disassemblies as well.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   841
  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
   842
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   843
  // Report problems during dll_load or dll_lookup, if any.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   844
  if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   845
    // Success.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   846
    if (_library_usable) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   847
      st->print_cr("Loaded disassembler from %s", buf);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   848
    } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   849
      st->print_cr("Could not load %s; %s; %s",
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   850
                   buf,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   851
                   ((_library != NULL)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   852
                    ? "entry point is missing"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   853
                    : ((WizardMode || PrintMiscellaneous)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   854
                       ? (const char*)ebuf
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   855
                       : "library not loadable")),
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   856
                   "PrintAssembly defaults to abstract disassembly.");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   857
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   858
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   859
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   860
  return _library_usable;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   861
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   862
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
// Directly disassemble code buffer.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   865
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
   866
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   867
  //---<  Test memory before decoding  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   868
  if (!(cb->contains(start) && cb->contains(end))) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   869
    //---<  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
   870
    if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   871
      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
   872
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   873
    return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   874
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   875
  if (!os::is_readable_range(start, end)) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   876
    //---<  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
   877
    if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   878
      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
   879
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   880
    return;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   881
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   882
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   883
  decode_env env(cb, st);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   884
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   885
  env.output()->print("Decoding CodeBuffer (" PTR_FORMAT ")", p2i(cb));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   886
  if (cb->name() != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   887
    env.output()->print(", name: %s,", cb->name());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   888
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   889
  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
   890
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   891
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   892
    AbstractDisassembler::decode_abstract(start, end, env.output(), Assembler::instr_maxlen());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   893
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   894
    env.decode_instructions(start, end);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   895
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   896
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   897
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   898
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   899
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   900
// Directly disassemble code blob.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   901
void Disassembler::decode(CodeBlob* cb, outputStream* st, CodeStrings c) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   902
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   903
  if (cb->is_nmethod()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   904
    // If we  have an nmethod at hand,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   905
    // call the specialized decoder directly.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   906
    decode((nmethod*)cb, st, c);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   907
    return;
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
  decode_env env(cb, st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   911
  env.output()->print_cr("--------------------------------------------------------------------------------");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   912
  if (cb->is_aot()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   913
    env.output()->print("A ");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   914
    if (cb->is_compiled()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   915
      CompiledMethod* cm = (CompiledMethod*)cb;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   916
      env.output()->print("%d ",cm->compile_id());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   917
      cm->method()->method_holder()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   918
      env.output()->print(".");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   919
      cm->method()->name()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   920
      cm->method()->signature()->print_symbol_on(env.output());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   921
    } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   922
      env.output()->print_cr("%s", cb->name());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   923
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   924
  } else {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   925
    env.output()->print("Decoding CodeBlob");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   926
    if (cb->name() != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   927
      env.output()->print(", name: %s,", cb->name());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   928
    }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40010
diff changeset
   929
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   930
  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
   931
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   932
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   933
    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
   934
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   935
    env.decode_instructions(cb->code_begin(), cb->code_end());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   936
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   937
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   938
#endif
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   939
}
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   940
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   941
// Decode a nmethod.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   942
// This includes printing the constant pool and all code segments.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   943
// 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
   944
void Disassembler::decode(nmethod* nm, outputStream* st, CodeStrings c) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   945
#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
   946
  ttyLocker ttyl;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   947
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   948
  decode_env env(nm, st);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   949
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   950
  nm->print_constant_pool(env.output());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   951
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   952
  env.output()->cr();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   953
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   954
    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
   955
  } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   956
    env.decode_instructions(nm->code_begin(), nm->code_end());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   957
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   958
  env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   959
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   960
}
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   961
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   962
// Decode a range, given as [start address, end address)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   963
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
   964
#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   965
  //---<  Test memory before decoding  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   966
  if (!os::is_readable_range(start, end)) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   967
    //---<  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
   968
    if (st != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   969
      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
   970
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   971
    return;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   972
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   973
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   974
  if (is_abstract()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   975
    AbstractDisassembler::decode_abstract(start, end, st, Assembler::instr_maxlen());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   976
    return;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   977
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   978
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   979
// 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
   980
// and treat the memory contents as "amorphic" piece of code.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   981
#if 0
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   982
  CodeBlob* cb = CodeCache::find_blob_unsafe(start);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   983
  if (cb != NULL) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   984
    // If we  have an CodeBlob at hand,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   985
    // call the specialized decoder directly.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   986
    decode(cb, st, c);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   987
  } else
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   988
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   989
  {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   990
    // This seems to be just a chunk of memory.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   991
    decode_env env(start, end, st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   992
    env.output()->print_cr("--------------------------------------------------------------------------------");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   993
    env.decode_instructions(start, end);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54810
diff changeset
   994
    env.output()->print_cr("--------------------------------------------------------------------------------");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   995
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31592
diff changeset
   996
#endif
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
   997
}
51056
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   998
3ddf41505d54 8204267: Generate comments in -XX:+PrintInterpreter to link to source code
iklam
parents: 50528
diff changeset
   999
// 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
  1000
// 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
  1001
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
  1002
  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
  1003
}