hotspot/src/share/vm/code/vtableStubs.hpp
author never
Wed, 01 Feb 2012 16:57:08 -0800
changeset 11637 030466036615
parent 7408 c04a5c989f26
child 13391 30245956af37
permissions -rw-r--r--
7013347: allow crypto functions to be called inline to enhance performance Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
     2
 * Copyright (c) 1997, 2010, 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: 6176
diff changeset
    25
#ifndef SHARE_VM_CODE_VTABLESTUBS_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    26
#define SHARE_VM_CODE_VTABLESTUBS_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    27
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
    28
#include "code/vmreg.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    29
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// There's a one-to-one relationship between a VtableStub and such a pair.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
class VtableStub {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  friend class VtableStubs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  static address _chunk;             // For allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  static address _chunk_end;         // For allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  static VMReg   _receiver_location; // Where to find receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  VtableStub*    _next;              // Pointer to next entry in hash table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  const short    _index;             // vtable index
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  short          _ame_offset;        // Where an AbstractMethodError might occur
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  short          _npe_offset;        // Where a NullPointerException might occur
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  bool           _is_vtable_stub;    // True if vtable stub, false, is itable stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  /* code follows here */            // The vtableStub code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  void* operator new(size_t size, int code_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  VtableStub(bool is_vtable_stub, int index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
        : _next(NULL), _is_vtable_stub(is_vtable_stub),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
          _index(index), _ame_offset(-1), _npe_offset(-1) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  VtableStub* next() const                       { return _next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  int index() const                              { return _index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static VMReg receiver_location()               { return _receiver_location; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  void set_next(VtableStub* n)                   { _next = n; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  address code_begin() const                     { return (address)(this + 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  address code_end() const                       { return code_begin() + pd_code_size_limit(_is_vtable_stub); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  address entry_point() const                    { return code_begin(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static int entry_offset()                      { return sizeof(class VtableStub); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  bool matches(bool is_vtable_stub, int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    return _index == index && _is_vtable_stub == is_vtable_stub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  bool contains(address pc) const                { return code_begin() <= pc && pc < code_end(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  void set_exception_points(address npe_addr, address ame_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    _npe_offset = npe_addr - code_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    _ame_offset = ame_addr - code_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    assert(is_abstract_method_error(ame_addr),   "offset must be correct");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    assert(is_null_pointer_exception(npe_addr),  "offset must be correct");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    assert(!is_abstract_method_error(npe_addr),  "offset must be correct");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    assert(!is_null_pointer_exception(ame_addr), "offset must be correct");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // platform-dependent routines
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  static int  pd_code_size_limit(bool is_vtable_stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static int  pd_code_alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // CNC: Removed because vtable stubs are now made with an ideal graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // static bool pd_disregard_arg_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  static void align_chunk() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    if (off != 0)  _chunk += pd_code_alignment() - off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Query
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  bool is_itable_stub()                          { return !_is_vtable_stub; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  bool is_vtable_stub()                          { return  _is_vtable_stub; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  bool is_abstract_method_error(address epc)     { return epc == code_begin()+_ame_offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  bool is_null_pointer_exception(address epc)    { return epc == code_begin()+_npe_offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
    95
  void print_on(outputStream* st) const;
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
    96
  void print() const                             { print_on(tty); }
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
    97
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// VtableStubs creates the code stubs for compiled calls through vtables.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// There is one stub per (vtable index, args_size) pair, and the stubs are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// never deallocated. They don't need to be GCed because they contain no oops.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
class VtableStubs : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
 public:                                         // N must be public (some compilers need this for _table)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    N    = 256,                                  // size of stub table; must be power of two
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    mask = N - 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  static VtableStub* _table[N];                  // table of existing stubs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  static int         _number_of_vtable_stubs;    // number of stubs created so far (for statistics)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  static VtableStub* create_vtable_stub(int vtable_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  static VtableStub* create_itable_stub(int vtable_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  static VtableStub* lookup            (bool is_vtable_stub, int vtable_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  static void        enter             (bool is_vtable_stub, int vtable_index, VtableStub* s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  static inline uint hash              (bool is_vtable_stub, int vtable_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  static address     create_stub(bool is_vtable_stub, int vtable_index, methodOop method); // return the entry point of a stub for this call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  static bool        is_entry_point(address pc);                     // is pc a vtable stub entry point?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  static bool        contains(address pc);                           // is pc within any stub?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static VtableStub* stub_containing(address pc);                    // stub containing pc or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  static int         number_of_vtable_stubs() { return _number_of_vtable_stubs; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  static void        initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
   130
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
   131
#endif // SHARE_VM_CODE_VTABLESTUBS_HPP