src/hotspot/share/interpreter/oopMapCache.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 53149 259c36ef27df
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    25
#ifndef SHARE_INTERPRETER_OOPMAPCACHE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    26
#define SHARE_INTERPRETER_OOPMAPCACHE_HPP
7397
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 "oops/generateOopMap.hpp"
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
    29
#include "runtime/mutex.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// A Cache for storing (method, bci) -> oopMap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// The memory management system uses the cache when locating object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// references in an interpreted frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    35
// OopMapCache's are allocated lazily per InstanceKlass.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// The oopMap (InterpreterOopMap) is stored as a bit mask. If the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// bit_mask can fit into two words it is stored in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// the _bit_mask array, otherwise it is allocated on the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// For OopMapCacheEntry the bit_mask is allocated in the C heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// because these entries persist between garbage collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// For InterpreterOopMap the bit_mask is allocated in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// a resource area for better performance.  InterpreterOopMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// should only be created and deleted during same garbage collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// If ENABBLE_ZAP_DEAD_LOCALS is defined, two bits are used
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// per entry instead of one. In all cases,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// the first bit is set to indicate oops as opposed to other
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// values. If the second bit is available,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// it is set for dead values. We get the following encoding:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// 00 live value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// 01 live oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// 10 dead value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// 11 <unused>                                   (we cannot distinguish between dead oops or values with the current oop map generator)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
class OffsetClosure  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  virtual void offset_do(int offset) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 47216
diff changeset
    63
class OopMapCacheEntry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
class InterpreterOopMap: ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  friend class OopMapCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  enum {
25626
362d0c3a7651 8013942: JSR 292: assert(type() == T_OBJECT) failed: type check
sspitsyn
parents: 25473
diff changeset
    70
    N                = 4,                // the number of words reserved
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                                         // for inlined mask storage
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    small_mask_limit = N * BitsPerWord,  // the maximum number of bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
                                         // available for small masks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                                         // small_mask_limit can be set to 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                                         // for testing bit_mask allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    bits_per_entry   = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    dead_bit_number  = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    oop_bit_number   = 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    83
  Method*        _method;         // the method for which the mask is valid
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  unsigned short _bci;            // the bci    for which the mask is valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  int            _mask_size;      // the mask size in bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  int            _expression_stack_size; // the size of the expression stack in slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  intptr_t       _bit_mask[N];    // the bit mask if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                                  // mask_size <= small_mask_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                                  // ptr to bit mask otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
                                  // "protected" so that sub classes can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                                  // access it without using trickery in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                                  // methd bit_mask().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  bool _resource_allocate_bit_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // access methods
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   100
  Method*        method() const                  { return _method; }
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   101
  void           set_method(Method* v)           { _method = v; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  int            bci() const                     { return _bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  void           set_bci(int v)                  { _bci = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  int            mask_size() const               { return _mask_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  void           set_mask_size(int v)            { _mask_size = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Test bit mask size and return either the in-line bit mask or allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // bit mask.
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   108
  uintptr_t*  bit_mask() const                   { return (uintptr_t*)(mask_size() <= small_mask_limit ? (intptr_t)_bit_mask : _bit_mask[0]); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // return the word size of_bit_mask.  mask_size() <= 4 * MAX_USHORT
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   111
  size_t mask_word_size() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    return (mask_size() + BitsPerWord - 1) / BitsPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   115
  uintptr_t entry_at(int offset) const           { int i = offset * bits_per_entry; return bit_mask()[i / BitsPerWord] >> (i % BitsPerWord); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   117
  void set_expression_stack_size(int sz)         { _expression_stack_size = sz; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Lookup
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33063
diff changeset
   120
  bool match(const methodHandle& method, int bci) const { return _method == method() && _bci == bci; }
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   121
  bool is_empty() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  InterpreterOopMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  ~InterpreterOopMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Copy the OopMapCacheEntry in parameter "from" into this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // InterpreterOopMap.  If the _bit_mask[0] in "from" points to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // allocated space (i.e., the bit mask was to large to hold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // in-line), allocate the space from a Resource area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  void resource_copy(OopMapCacheEntry* from);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   136
  void iterate_oop(OffsetClosure* oop_closure) const;
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   137
  void print() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   139
  int number_of_entries() const                  { return mask_size() / bits_per_entry; }
25626
362d0c3a7651 8013942: JSR 292: assert(type() == T_OBJECT) failed: type check
sspitsyn
parents: 25473
diff changeset
   140
  bool is_dead(int offset) const                 { return (entry_at(offset) & (1 << dead_bit_number)) != 0; }
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   141
  bool is_oop (int offset) const                 { return (entry_at(offset) & (1 << oop_bit_number )) != 0; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
25473
185aff4215a4 8039905: heapdump/OnOOMToFile and heapdump/OnOOMToPath fail with "assert(fr().interpreter_frame_expression_stack_size() >= length) failed: error in expression stack!"
mgronlun
parents: 13728
diff changeset
   143
  int expression_stack_size() const              { return _expression_stack_size; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7408
diff changeset
   147
class OopMapCache : public CHeapObj<mtClass> {
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 33593
diff changeset
   148
 static OopMapCacheEntry* volatile _old_entries;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  enum { _size        = 32,     // Use fixed size for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
         _probe_depth = 3       // probe depth in case of collisions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 33593
diff changeset
   154
  OopMapCacheEntry* volatile * _array;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33063
diff changeset
   156
  unsigned int hash_value_for(const methodHandle& method, int bci) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  OopMapCacheEntry* entry_at(int i) const;
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 33593
diff changeset
   158
  bool put_at(int i, OopMapCacheEntry* entry, OopMapCacheEntry* old);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 33593
diff changeset
   160
  static void enqueue_for_cleanup(OopMapCacheEntry* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  OopMapCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  ~OopMapCache();                                // free up memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // flush cache entry is occupied by an obsolete method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  void flush_obsolete_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // Returns the oopMap for (method, bci) in parameter "entry".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // Returns false if an oop map was not found.
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 33593
diff changeset
   173
  void lookup(const methodHandle& method, int bci, InterpreterOopMap* entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Compute an oop map without updating the cache or grabbing any locks (for debugging)
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33063
diff changeset
   176
  static void compute_one_oop_map(const methodHandle& method, int bci, InterpreterOopMap* entry);
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 33593
diff changeset
   177
  static void cleanup_old_entries();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   179
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
   180
#endif // SHARE_INTERPRETER_OOPMAPCACHE_HPP