src/hotspot/share/code/exceptionHandlerTable.hpp
author tschatzl
Wed, 08 Aug 2018 15:31:06 +0200
changeset 51333 f6641fcf7b7e
parent 49373 47b5652f2928
child 53244 9807daeb47c4
permissions -rw-r--r--
8208670: Compiler changes to allow enabling -Wreorder Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    29
#include "oops/method.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    30
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// A HandlerTableEntry describes an individual entry of a subtable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// of ExceptionHandlerTable. An entry consists of a pair(bci, pco),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// where bci is the exception handler bci, and pco is the pc offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// relative to the nmethod code start for the compiled exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// handler corresponding to the (interpreted) exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// starting at bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// The first HandlerTableEntry of each subtable holds the length
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// and catch_pco for the subtable (the length is the number of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// subtable entries w/o header).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class HandlerTableEntry {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  int _pco;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  int _scope_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  HandlerTableEntry(int bci, int pco, int scope_depth) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    assert( 0 <= pco, "pco must be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    assert( 0 <= scope_depth, "scope_depth must be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    _bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _pco = pco;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _scope_depth = scope_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int len() const { return _bci; } // for entry at subtable begin
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int bci() const { return _bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  int pco() const { return _pco; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  int scope_depth() const { return _scope_depth; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// An ExceptionHandlerTable is an abstraction over a list of subtables
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// of exception handlers for CatchNodes. Each subtable has a one-entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// header holding length and catch_pco of the subtable, followed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// by 'length' entries for each exception handler that can be reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
// from the corresponding CatchNode. The catch_pco is the pc offset of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// the CatchNode in the corresponding nmethod. Empty subtables are dis-
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// carded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
// Structure of the table:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// table    = { subtable }.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// subtable = header entry { entry }.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// header   = a pair (number of subtable entries, catch pc offset, [unused])
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// entry    = a pair (handler bci, handler pc offset, scope depth)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// An ExceptionHandlerTable can be created from scratch, in which case
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// it is possible to add subtables. It can also be created from an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// nmethod (for lookup purposes) in which case the table cannot be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// modified.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
class nmethod;
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
    86
class ExceptionHandlerTable {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  HandlerTableEntry* _table;    // the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  int                _length;   // the current length of the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  int                _size;     // the number of allocated entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  ReallocMark        _nesting;  // assertion check for reallocations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
    93
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // add the entry & grow the table if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  void add_entry(HandlerTableEntry entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  HandlerTableEntry* subtable_for(int catch_pco) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // (compile-time) construction within compiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  ExceptionHandlerTable(int initial_size = 8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // (run-time) construction from nmethod
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 33160
diff changeset
   102
  ExceptionHandlerTable(const CompiledMethod* nm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // (compile-time) add entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  void add_subtable(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    int                 catch_pco, // the pc offset for the CatchNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    GrowableArray<intptr_t>* handler_bcis, // the exception handler entry point bcis
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    GrowableArray<intptr_t>* scope_depths_from_top_scope,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                                           // if representing exception handlers in multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                                           // inlined scopes, indicates which scope relative to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
                                           // the youngest/innermost one in which we are performing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
                                           // the lookup; zero (or null GrowableArray) indicates
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
                                           // innermost scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    GrowableArray<intptr_t>* handler_pcos  // pc offsets for the compiled handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // nmethod support
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 38133
diff changeset
   118
  int  size_in_bytes() const { return align_up(_length * (int)sizeof(HandlerTableEntry), oopSize); }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 33160
diff changeset
   119
  void copy_to(CompiledMethod* nm);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   120
  void copy_bytes_to(address addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void print_subtable(HandlerTableEntry* t) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  void print() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void print_subtable_for(int catch_pco) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
// Implicit null exception tables.  Maps an exception PC offset to a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
// continuation PC offset.  During construction it's a variable sized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
// array with a max size and current length.  When stored inside an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
// nmethod a zero length table takes no space.  This is detected by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// nul_chk_table_size() == 0.  Otherwise the table has a length word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
// followed by pairs of <excp-offset, const-offset>.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
// Use 32-bit representation for offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
typedef  uint              implicit_null_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
   143
class ImplicitExceptionTable {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  uint _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  uint _len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  implicit_null_entry *_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  ReallocMark          _nesting;  // assertion check for reallocations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
public:
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 49373
diff changeset
   150
  ImplicitExceptionTable( ) :  _size(0), _len(0), _data(0) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // (run-time) construction from nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  ImplicitExceptionTable( const nmethod *nm );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  void set_size( uint size );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  void append( uint exec_off, uint cont_off );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  uint at( uint exec_off ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  uint len() const { return _len; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  void copy_to(nmethod* nm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void print(address base) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  void verify(nmethod *nm) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   165
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   166
#endif // SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP