src/hotspot/share/compiler/abstractDisassembler.cpp
author aoqi
Thu, 23 May 2019 00:21:39 +0800
changeset 54994 faf89c9568bd
parent 54960 e46fe26d7f77
child 55024 948385f851f2
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:
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     1
/*
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     3
 * Copyright (c) 2019 SAP SE. All rights reserved.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     5
 *
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     8
 * published by the Free Software Foundation.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
     9
 *
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    14
 * accompanied this code).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    15
 *
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    19
 *
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    22
 * questions.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    23
 *
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    24
 */
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    25
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    26
// AbstractDisassembler is the base class for
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    27
// platform-specific Disassembler classes.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    28
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    29
#include "precompiled.hpp"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    30
#include "asm/assembler.inline.hpp"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    31
#include "compiler/abstractDisassembler.hpp"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    32
#include "oops/oop.inline.hpp"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    33
#include "utilities/debug.hpp"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    34
#include "utilities/ostream.hpp"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    35
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    36
// Default values for what is being printed as line prefix when disassembling a single instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    37
// Can be overridden by command line parameter PrintAssemblyOptions.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    38
bool AbstractDisassembler::_show_data_hex      = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    39
bool AbstractDisassembler::_show_data_int      = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    40
bool AbstractDisassembler::_show_data_float    = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    41
bool AbstractDisassembler::_align_instr        = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    42
bool AbstractDisassembler::_show_pc            = true;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    43
bool AbstractDisassembler::_show_offset        = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    44
bool AbstractDisassembler::_show_structs       = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    45
bool AbstractDisassembler::_show_comment       = false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    46
bool AbstractDisassembler::_show_block_comment = false;
54994
faf89c9568bd 8224568: minimal and zero build fails after JDK-8213084
aoqi
parents: 54960
diff changeset
    47
faf89c9568bd 8224568: minimal and zero build fails after JDK-8213084
aoqi
parents: 54960
diff changeset
    48
// set "true" to see what's in memory bit by bit
faf89c9568bd 8224568: minimal and zero build fails after JDK-8213084
aoqi
parents: 54960
diff changeset
    49
// might prove cumbersome on platforms where instr_len is hard to find out
faf89c9568bd 8224568: minimal and zero build fails after JDK-8213084
aoqi
parents: 54960
diff changeset
    50
bool AbstractDisassembler::_show_bytes         = false;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    51
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    52
// Return #bytes printed. Callers may use that for output alignment.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    53
// Print instruction address, and offset from blob begin.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    54
// Offset width (2, 4, 6, 8 bytes) is adapted to size of blob.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    55
// Working assumption: we are at st->bol() upon entry. If not, it's the
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    56
//                     caller's responsibility to guarantee proper alignment.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    57
int AbstractDisassembler::print_location(address here, address begin, address end, outputStream* st, bool align, bool print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    58
  const int     pos_0  = st->position();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    59
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    60
  if (show_pc() || show_offset()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    61
    st->print(" ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    62
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    63
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    64
  if (show_pc()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    65
    if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    66
      st->print(" %*s", 18, "Address");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    67
    } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    68
      st->print(" " PTR_FORMAT, p2i(here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    69
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    70
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    71
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    72
  if (show_offset()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    73
#ifdef ASSERT
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    74
    if ((uintptr_t)begin > (uintptr_t)here) st->print(">>begin(" PTR_FORMAT ") > here(" PTR_FORMAT ")<<", p2i(begin), p2i(here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    75
    if ((uintptr_t)end   < (uintptr_t)here) st->print(">>  end(" PTR_FORMAT ") < here(" PTR_FORMAT ")<<", p2i(end),   p2i(here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    76
    assert((uintptr_t)begin <= (uintptr_t)end, "inverted address range");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    77
#endif
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    78
    const int blob_len = end - begin;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    79
    const int offset   = here - begin;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    80
    const int width    = (blob_len < (1<< 8)) ? 2 : (blob_len < (1<<16)) ? 4 : (blob_len < (1<<24)) ? 6 : 8;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    81
    if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    82
      st->print(" %*s", width+5, "offset");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    83
    } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    84
      st->print(" (+0x%*.*x)", width, width, offset);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    85
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    86
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    87
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    88
  if ((show_pc() || show_offset()) && !print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    89
    st->print(": ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    90
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    91
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    92
  if (align) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    93
    const uint tabspacing  = 8;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    94
    const uint pos         = st->position();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    95
    const uint aligned_pos = ((pos+tabspacing-1)/tabspacing)*tabspacing /* - 1 */;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    96
    st->fill_to(aligned_pos);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    97
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    98
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    99
  return st->position() - pos_0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   100
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   101
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   102
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   103
// Return #bytes printed. Callers may use that for output alignment.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   104
// Print instruction in hexadecimal representation, using 2-byte blocks.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   105
// Used with real disassemblies. Not so useful with abstract disassemblies.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   106
int AbstractDisassembler::print_instruction(address here, int len, int max_len, outputStream* st, bool align, bool print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   107
  if (show_bytes()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   108
    const int block_bytes = 2;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   109
    const int pos_0       = st->position();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   110
    address   pos         = here;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   111
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   112
    //---<  print instruction bytes in blocks  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   113
    // must print byte by byte: address might be unaligned.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   114
    for (; pos <= here + len - block_bytes; pos += block_bytes) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   115
      for (address byte = pos; byte < pos + block_bytes; byte++) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   116
        st->print("%2.2x", *byte);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   117
      }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   118
      st->print(" ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   119
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   120
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   121
    //---<  Print the remaining bytes of the instruction  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   122
    if ((len & (block_bytes - 1)) != 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   123
      for (; pos < here + len; pos++) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   124
        st->print("%2.2x", *pos);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   125
      }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   126
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   127
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   128
    //---<  filler for shorter than max_len instructions  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   129
    for (int i = len+1; i < max_len; i++) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   130
      st->print("  ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   131
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   132
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   133
    st->print(" "); // separator space.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   134
    print_delimiter(st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   135
    return st->position() - pos_0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   136
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   137
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   138
  if (align) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   139
    const uint tabspacing  = 8;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   140
    const uint pos         = st->position();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   141
    const uint aligned_pos = ((pos+tabspacing-1)/tabspacing)*tabspacing /* - 1 */;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   142
    st->fill_to(aligned_pos);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   143
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   144
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   145
  return 0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   146
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   147
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   148
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   149
// Return #bytes printed. Callers may use that for output alignment.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   150
// Print data (e.g. constant pool entries) in hex format.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   151
// Depending on the alignment, short, int, and long entities are printed.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   152
// If selected, data is formatted as int/long and float/double values in addition.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   153
int AbstractDisassembler::print_hexdata(address here, int len, outputStream* st, bool print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   154
  const int tsize = 8;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   155
  const int pos_0 = st->position();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   156
  int pos   = pos_0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   157
  int align = ((pos+tsize-1)/tsize)*tsize;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   158
  st->fill_to(align);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   159
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   160
  //---<  printing hex data  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   161
  if (show_data_hex()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   162
    switch (len) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   163
      case 1: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   164
                st->print("hex1");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   165
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   166
                st->print("0x%02x", *here);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   167
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   168
              st->fill_to(align += tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   169
      case 2: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   170
                st->print("  hex2");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   171
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   172
                if (((uintptr_t)(here)&0x01) == 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   173
                  st->print("0x%04x",   *((jushort*)here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   174
                }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   175
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   176
              st->fill_to(align += tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   177
      case 4: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   178
                st->print("      hex4");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   179
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   180
                if (((uintptr_t)(here)&0x03) == 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   181
                  st->print("0x%08x",   *((juint*)here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   182
                }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   183
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   184
              st->fill_to(align += 2*tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   185
      case 8: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   186
                st->print("              hex8");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   187
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   188
                if (((uintptr_t)(here)&0x07) == 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   189
                  st->print(PTR_FORMAT, *((uintptr_t*)here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   190
                }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   191
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   192
              st->fill_to(align += 3*tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   193
              break;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   194
      default: ;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   195
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   196
    pos   = st->position();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   197
    align = ((pos+tsize-1)/tsize)*tsize;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   198
    st->fill_to(align);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   199
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   200
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   201
  //---<  printing int/long data  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   202
  if (show_data_int()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   203
    switch (len) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   204
      case 4: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   205
                st->print("         int");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   206
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   207
                if (((uintptr_t)(here)&0x03) == 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   208
                  st->print("%12.1d",  *((jint*)here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   209
                }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   210
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   211
              st->fill_to(align += 2*tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   212
      case 8: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   213
                st->print("                   long");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   214
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   215
                if (((uintptr_t)(here)&0x07) == 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   216
                  st->print("%23.1ld", *((jlong*)here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   217
                }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   218
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   219
              st->fill_to(align += 3*tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   220
              break;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   221
      default: ;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   222
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   223
    pos   = st->position();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   224
    align = ((pos+tsize-1)/tsize)*tsize;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   225
    st->fill_to(align);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   226
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   227
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   228
  //---<  printing float/double data  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   229
  if (show_data_float()) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   230
    switch (len) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   231
      case 4: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   232
                st->print("          float");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   233
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   234
                if (((uintptr_t)(here)&0x03) == 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   235
                  st->print("%15.7e",  (double)*((float*)here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   236
                }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   237
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   238
              st->fill_to(align += 2*tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   239
      case 8: if (print_header) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   240
                st->print("                 double");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   241
              } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   242
                if (((uintptr_t)(here)&0x07) == 0) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   243
                  st->print("%23.15e",         *((double*)here));
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   244
                }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   245
              }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   246
              st->fill_to(align += 3*tsize);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   247
              break;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   248
      default: ;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   249
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   250
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   251
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   252
  return st->position() - pos_0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   253
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   254
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   255
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   256
// Return #bytes printed. Callers may use that for output alignment.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   257
// Print an instruction delimiter.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   258
int AbstractDisassembler::print_delimiter(outputStream* st) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   259
  if (align_instr()) { st->print("| "); return 2; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   260
  else               return 0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   261
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   262
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   263
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   264
// Decodes the one instruction at address start in a platform-independent format.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   265
// Returns the start of the next instruction (which is 'start' plus 'instruction_size_in_bytes').
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   266
// The parameter max_instr_size_in_bytes is used for output alignment purposes only.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   267
address AbstractDisassembler::decode_instruction_abstract(address start,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   268
                                                          outputStream* st,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   269
                                                          const int instruction_size_in_bytes,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   270
                                                          const int max_instr_size_in_bytes) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   271
  assert(instruction_size_in_bytes > 0, "no zero-size instructions!");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   272
  assert(max_instr_size_in_bytes >= instruction_size_in_bytes, "inconsistent call parameters");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   273
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   274
  //---<  current instruction is at the start address  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   275
  unsigned char* current = (unsigned char*) start;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   276
  int            filler_limit = align_instr() ? max_instr_size_in_bytes : ((instruction_size_in_bytes+abstract_instruction_bytes_per_block-1)/abstract_instruction_bytes_per_block)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   277
                                                                          *abstract_instruction_bytes_per_block;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   278
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   279
  //---<  print the instruction's bytes  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   280
  for (int i = 1; i <= instruction_size_in_bytes; i++) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   281
    st->print("%02x", *current);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   282
    ++current;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   283
    if (abstract_instruction_bytes_per_block <= max_instr_size_in_bytes) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   284
      if (i%abstract_instruction_bytes_per_block == 0) st->print(" ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   285
    } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   286
      if (i == instruction_size_in_bytes) st->print(" ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   287
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   288
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   289
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   290
  //---<  print some filler spaces to column-align instructions  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   291
  for (int i = instruction_size_in_bytes+1; i <= filler_limit; i++) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   292
    st->print("  ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   293
    if (abstract_instruction_bytes_per_block <= max_instr_size_in_bytes) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   294
      if (i%abstract_instruction_bytes_per_block == 0) st->print(" ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   295
    } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   296
      if (i == instruction_size_in_bytes) st->print(" ");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   297
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   298
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   299
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   300
  //---<  the address of the next instruction  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   301
  return (address) current;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   302
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   303
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   304
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   305
// Decodes all instructions in the given range [start..end)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   306
// calling decode_instruction_abstract for each instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   307
// The format is platform dependent only to the extend that
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   308
// it respects the actual instruction length where possible.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   309
// Does not print any markers or decorators.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   310
void AbstractDisassembler::decode_range_abstract(address range_start, address range_end,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   311
                                                 address start, address end,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   312
                                                 outputStream* st,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   313
                                                 const int max_instr_size_in_bytes) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   314
  assert(st != NULL, "need an output stream (no default)!");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   315
  int     idx = 0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   316
  address pos = range_start;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   317
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   318
  while ((pos != NULL) && (pos < range_end)) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   319
    int instr_size_in_bytes = Assembler::instr_len(pos);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   320
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   321
    if (idx == 0) print_location(pos, start, end, st, false, false);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   322
    else          print_delimiter(st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   323
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   324
    //---<  print the instruction's bytes  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   325
    // don't access storage beyond end of range
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   326
    if (pos + instr_size_in_bytes <= range_end) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   327
      pos = decode_instruction_abstract(pos, st, instr_size_in_bytes, max_instr_size_in_bytes);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   328
    } else {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   329
      // If the range to be decoded contains garbage at the end (e.g. 0xcc initializer bytes),
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   330
      // instruction size calculation may run out of sync. Just terminate in that case.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   331
      pos = range_end;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   332
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   333
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   334
    idx += instr_size_in_bytes;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   335
    if (start_newline(idx)) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   336
      st->cr();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   337
      idx = 0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   338
    }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   339
  }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   340
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   341
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   342
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   343
// Decodes all instructions in the given range [start..end).
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   344
// The output is enclosed in [MachCode] and [/MachCode] tags for later recognition.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   345
// The format is platform dependent only to the extend that
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   346
// it respects the actual instruction length where possible.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   347
void AbstractDisassembler::decode_abstract(address start, address end, outputStream* ost,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   348
                                           const int max_instr_size_in_bytes) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   349
  int     idx = 0;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   350
  address pos = start;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   351
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   352
  outputStream* st = (ost == NULL) ? tty : ost;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   353
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   354
  //---<  Open the output (Marker for post-mortem disassembler)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   355
  st->bol();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   356
  st->print_cr("[MachCode]");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   357
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   358
  decode_range_abstract(start, end, start, end, st, max_instr_size_in_bytes);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   359
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   360
  //---<  Close the output (Marker for post-mortem disassembler)  >---
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   361
  st->bol();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   362
  st->print_cr("[/MachCode]");
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   363
}