hotspot/src/share/vm/interpreter/oopMapCache.hpp
author twisti
Fri, 27 Feb 2009 13:27:09 -0800
changeset 2131 98f9cef66a34
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6810672: Comment typos Summary: I have collected some typos I have found while looking at the code. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// A Cache for storing (method, bci) -> oopMap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// The memory management system uses the cache when locating object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// references in an interpreted frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// OopMapCache's are allocated lazily per instanceKlass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// The oopMap (InterpreterOopMap) is stored as a bit mask. If the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// bit_mask can fit into two words it is stored in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// the _bit_mask array, otherwise it is allocated on the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// For OopMapCacheEntry the bit_mask is allocated in the C heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// because these entries persist between garbage collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// For InterpreterOopMap the bit_mask is allocated in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// a resource area for better performance.  InterpreterOopMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// should only be created and deleted during same garbage collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// If ENABBLE_ZAP_DEAD_LOCALS is defined, two bits are used
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// per entry instead of one. In all cases,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// the first bit is set to indicate oops as opposed to other
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// values. If the second bit is available,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// it is set for dead values. We get the following encoding:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// 00 live value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// 01 live oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// 10 dead value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// 11 <unused>                                   (we cannot distinguish between dead oops or values with the current oop map generator)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
class OffsetClosure  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  virtual void offset_do(int offset) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
};
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 InterpreterOopMap: ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  friend class OopMapCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    N                = 2,                // the number of words reserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
                                         // for inlined mask storage
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    small_mask_limit = N * BitsPerWord,  // the maximum number of bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                                         // available for small masks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                                         // small_mask_limit can be set to 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                                         // for testing bit_mask allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
#ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    bits_per_entry   = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    dead_bit_number  = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    bits_per_entry   = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    oop_bit_number   = 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  methodOop      _method;         // the method for which the mask is valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  unsigned short _bci;            // the bci    for which the mask is valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  int            _mask_size;      // the mask size in bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  int            _expression_stack_size; // the size of the expression stack in slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  intptr_t       _bit_mask[N];    // the bit mask if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                                  // mask_size <= small_mask_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
                                  // ptr to bit mask otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
                                  // "protected" so that sub classes can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                                  // access it without using trickery in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                                  // methd bit_mask().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  bool _resource_allocate_bit_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // access methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  methodOop      method() const                  { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  void           set_method(methodOop v)         { _method = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  int            bci() const                     { return _bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void           set_bci(int v)                  { _bci = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  int            mask_size() const               { return _mask_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void           set_mask_size(int v)            { _mask_size = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  int            number_of_entries() const       { return mask_size() / bits_per_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Test bit mask size and return either the in-line bit mask or allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // bit mask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  uintptr_t*  bit_mask()                         { return (uintptr_t*)(mask_size() <= small_mask_limit ? (intptr_t)_bit_mask : _bit_mask[0]); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // return the word size of_bit_mask.  mask_size() <= 4 * MAX_USHORT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  size_t mask_word_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return (mask_size() + BitsPerWord - 1) / BitsPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  uintptr_t entry_at(int offset)            { int i = offset * bits_per_entry; return bit_mask()[i / BitsPerWord] >> (i % BitsPerWord); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  void set_expression_stack_size(int sz)    { _expression_stack_size = sz; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
#ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  bool is_dead(int offset)                       { return (entry_at(offset) & (1 << dead_bit_number)) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  bool match(methodHandle method, int bci)       { return _method == method() && _bci == bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  bool is_empty();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  InterpreterOopMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  ~InterpreterOopMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // Copy the OopMapCacheEntry in parameter "from" into this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // InterpreterOopMap.  If the _bit_mask[0] in "from" points to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // allocated space (i.e., the bit mask was to large to hold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // in-line), allocate the space from a Resource area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  void resource_copy(OopMapCacheEntry* from);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  void iterate_oop(OffsetClosure* oop_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  void oop_iterate(OopClosure * blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void oop_iterate(OopClosure * blk, MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  bool is_oop  (int offset)                      { return (entry_at(offset) & (1 << oop_bit_number )) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  int expression_stack_size()                    { return _expression_stack_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
#ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
class OopMapCache : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  enum { _size        = 32,     // Use fixed size for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
         _probe_depth = 3       // probe depth in case of collisions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  OopMapCacheEntry* _array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  unsigned int hash_value_for(methodHandle method, int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  OopMapCacheEntry* entry_at(int i) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  Mutex _mut;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  OopMapCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  ~OopMapCache();                                // free up memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // flush cache entry is occupied by an obsolete method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  void flush_obsolete_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Returns the oopMap for (method, bci) in parameter "entry".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // Returns false if an oop map was not found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  void lookup(methodHandle method, int bci, InterpreterOopMap* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // Compute an oop map without updating the cache or grabbing any locks (for debugging)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  static void compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // Helpers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Iterate over the entries in the cached OopMapCacheEntry's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  void oop_iterate(OopClosure *blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  void oop_iterate(OopClosure *blk, MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Returns total no. of bytes allocated as part of OopMapCache's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  static long memory_usage()                     PRODUCT_RETURN0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
};