src/hotspot/share/compiler/abstractDisassembler.hpp
author lucy
Tue, 21 May 2019 15:51:35 +0200
changeset 54960 e46fe26d7f77
permissions -rw-r--r--
8213084: Rework and enhance Print[Opto]Assembly output Reviewed-by: kvn, thartmann
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
#ifndef SHARE_COMPILER_ABSTRACTDISASSEMBLER_HPP
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    27
#define SHARE_COMPILER_ABSTRACTDISASSEMBLER_HPP
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
// AbstractDisassembler is the base class for
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    30
// platform-specific Disassembler classes.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    31
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    32
#include "utilities/globalDefinitions.hpp"
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    33
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    34
class AbstractDisassembler {
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
 private:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    37
  // These are some general settings which control
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    38
  // abstract disassembly output.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    39
  enum {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    40
    // that many bytes are dumped in one line.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    41
    abstract_instruction_bytes_per_line     = 32,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    42
    // instruction bytes are grouped in blocks of that many bytes.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    43
    abstract_instruction_bytes_per_block    =  2,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    44
    // instructions have this default len.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    45
    abstract_instruction_size_in_bytes      =  1,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    46
    // instructions have this maximum len.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    47
    abstract_instruction_maxsize_in_bytes   =  1
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    48
  };
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    49
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    50
  static bool _align_instr;        // vertical alignment of instructions in abstract disassembly
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    51
  static bool _show_pc;            // print the instruction address
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    52
  static bool _show_offset;        // print the instruction offset (from start of blob)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    53
  static bool _show_bytes;         // print instruction bytes
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    54
  static bool _show_data_hex;      // print instruction bytes
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    55
  static bool _show_data_int;      // print instruction bytes
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    56
  static bool _show_data_float;    // print instruction bytes
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    57
  static bool _show_structs;       // print compiler data structures (relocations, oop maps, scopes, metadata, ...)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    58
  static bool _show_comment;       // print instruction comments
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    59
  static bool _show_block_comment; // print block comments
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    60
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    61
 public:
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    62
  // Platform-independent location and instruction formatting.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    63
  // All functions return #characters printed.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    64
  static int  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
    65
  static int  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
    66
  static int  print_hexdata(address here, int len, outputStream* st, bool print_header = false);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    67
  static int  print_delimiter(outputStream* st);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    68
  static bool start_newline(int byte_count) { return byte_count >= abstract_instruction_bytes_per_line; }
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
  static void toggle_align_instr()        { _align_instr        = !_align_instr; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    71
  static void toggle_show_pc()            { _show_pc            = !_show_pc; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    72
  static void toggle_show_offset()        { _show_offset        = !_show_offset; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    73
  static void toggle_show_bytes()         { _show_bytes         = !_show_bytes; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    74
  static void toggle_show_data_hex()      { _show_data_hex      = !_show_data_hex; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    75
  static void toggle_show_data_int()      { _show_data_int      = !_show_data_int; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    76
  static void toggle_show_data_float()    { _show_data_float    = !_show_data_float; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    77
  static void toggle_show_structs()       { _show_structs       = !_show_structs; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    78
  static void toggle_show_comment()       { _show_comment       = !_show_comment; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    79
  static void toggle_show_block_comment() { _show_block_comment = !_show_block_comment; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    80
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    81
  static bool align_instr()        { return _align_instr; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    82
  static bool show_pc()            { return _show_pc; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    83
  static bool show_offset()        { return _show_offset; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    84
  static bool show_bytes()         { return _show_bytes; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    85
  static bool show_data_hex()      { return _show_data_hex; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    86
  static bool show_data_int()      { return _show_data_int; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    87
  static bool show_data_float()    { return _show_data_float; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    88
  static bool show_structs()       { return _show_structs; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    89
  static bool show_comment()       { return _show_comment; }
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    90
  static bool show_block_comment() { return _show_block_comment; }
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
  // Decodes the one instruction at address start in a platform-independent
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    93
  // format. Returns the start of the next instruction (which is
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    94
  // 'start' plus 'instruction_size_in_bytes'). The parameter max_instr_size_in_bytes
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    95
  // is used for output alignment purposes only.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    96
  static address decode_instruction_abstract(address start,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    97
                                             outputStream* st,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    98
                                             const int instruction_size_in_bytes,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
    99
                                             const int max_instr_size_in_bytes = abstract_instruction_maxsize_in_bytes);
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
  // Decodes all instructions in the given range [start..end)
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   102
  // calling decode_instruction_abstract for each instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   103
  // The format is platform dependent only to the extend that
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   104
  // it respects the actual instruction length where possible.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   105
  // Does not print any markers or decorators.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   106
  static void decode_range_abstract(address range_start, address range_end,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   107
                                    address start, address end,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   108
                                    outputStream* st,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   109
                                    const int max_instr_size_in_bytes = abstract_instruction_maxsize_in_bytes);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   110
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   111
  // Decodes all instructions in the given range in a platform-independent
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   112
  // format, calling decode_instruction_abstract for each instruction.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   113
  static void decode_abstract(address start, address end,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   114
                              outputStream* st,
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   115
                              const int max_instr_size_in_bytes = abstract_instruction_maxsize_in_bytes);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents:
diff changeset
   116
};
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
#endif // SHARE_COMPILER_ABSTRACTDISASSEMBLER_HPP