hotspot/src/share/vm/interpreter/oopMapCache.cpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 5402 c51fd0c1d005
child 6176 4d9030fe341f
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
     2
 * Copyright (c) 1997, 2008, 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: 5402
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
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: 5402
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_oopMapCache.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class OopMapCacheEntry: private InterpreterOopMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  friend class InterpreterOopMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  friend class OopMapForCacheEntry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  friend class OopMapCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  friend class VerifyClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  void fill(methodHandle method, int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // fills the bit mask for native calls
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  void fill_for_native(methodHandle method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  void set_mask(CellTypeState* vars, CellTypeState* stack, int stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // Deallocate bit masks and initialize fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  void allocate_bit_mask();   // allocates the bit mask on C heap f necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  void deallocate_bit_mask(); // allocates the bit mask on C heap f necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  bool verify_mask(CellTypeState *vars, CellTypeState *stack, int max_locals, int stack_top);
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
  OopMapCacheEntry() : InterpreterOopMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
     _resource_allocate_bit_mask = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
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
// Implementation of OopMapForCacheEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// (subclass of GenerateOopMap, initializes an OopMapCacheEntry for a given method and bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
class OopMapForCacheEntry: public GenerateOopMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  OopMapCacheEntry *_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  int               _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  int               _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  virtual bool report_results() const     { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  virtual bool possible_gc_point          (BytecodeStream *bcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  virtual void fill_stackmap_prolog       (int nof_gc_points);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  virtual void fill_stackmap_epilog       ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  virtual void fill_stackmap_for_opcodes  (BytecodeStream *bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                                           CellTypeState* vars,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
                                           CellTypeState* stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
                                           int stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  virtual void fill_init_vars             (GrowableArray<intptr_t> *init_vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry *entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Computes stack map for (method,bci) and initialize entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  void compute_map(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  int  size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
OopMapForCacheEntry::OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry* entry) : GenerateOopMap(method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  _bci       = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  _entry     = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  _stack_top = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
void OopMapForCacheEntry::compute_map(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  assert(!method()->is_native(), "cannot compute oop map for native methods");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // First check if it is a method where the stackmap is always empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  if (method()->code_size() == 0 || method()->max_locals() + method()->max_stack() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    _entry->set_mask_size(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    GenerateOopMap::compute_map(CATCH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    result_for_basicblock(_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
bool OopMapForCacheEntry::possible_gc_point(BytecodeStream *bcs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  return false; // We are not reporting any result. We call result_for_basicblock directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void OopMapForCacheEntry::fill_stackmap_prolog(int nof_gc_points) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
void OopMapForCacheEntry::fill_stackmap_epilog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void OopMapForCacheEntry::fill_init_vars(GrowableArray<intptr_t> *init_vars) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
void OopMapForCacheEntry::fill_stackmap_for_opcodes(BytecodeStream *bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                                                    CellTypeState* vars,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                                                    CellTypeState* stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                                                    int stack_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // Only interested in one specific bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  if (bcs->bci() == _bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _entry->set_mask(vars, stack, stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    _stack_top = stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
int OopMapForCacheEntry::size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  assert(_stack_top != -1, "compute_map must be called first");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  return ((method()->is_static()) ? 0 : 1) + method()->max_locals() + _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// Implementation of InterpreterOopMap and OopMapCacheEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
class VerifyClosure : public OffsetClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  OopMapCacheEntry* _entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  bool              _failed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  VerifyClosure(OopMapCacheEntry* entry)         { _entry = entry; _failed = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  void offset_do(int offset)                     { if (!_entry->is_oop(offset)) _failed = true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  bool failed() const                            { return _failed; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
InterpreterOopMap::InterpreterOopMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  _resource_allocate_bit_mask = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
InterpreterOopMap::~InterpreterOopMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // The expection is that the bit mask was allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // last in this resource area.  That would make the free of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // bit_mask effective (see how FREE_RESOURCE_ARRAY does a free).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // If it was not allocated last, there is not a correctness problem
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // but the space for the bit_mask is not freed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  assert(_resource_allocate_bit_mask, "Trying to free C heap space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  if (mask_size() > small_mask_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    FREE_RESOURCE_ARRAY(uintptr_t, _bit_mask[0], mask_word_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
bool InterpreterOopMap::is_empty() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  bool result = _method == NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  assert(_method != NULL || (_bci == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    (_mask_size == 0 || _mask_size == USHRT_MAX) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    _bit_mask[0] == 0), "Should be completely empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
void InterpreterOopMap::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  _method    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  _mask_size = USHRT_MAX;  // This value should cause a failure quickly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  _bci       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  _expression_stack_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  for (int i = 0; i < N; i++) _bit_mask[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
void InterpreterOopMap::oop_iterate(OopClosure *blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if (method() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    blk->do_oop((oop*) &_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
void InterpreterOopMap::oop_iterate(OopClosure *blk, MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  if (method() != NULL && mr.contains(&_method)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    blk->do_oop((oop*) &_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
void InterpreterOopMap::iterate_oop(OffsetClosure* oop_closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  int n = number_of_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  int word_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  uintptr_t value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  uintptr_t mask = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // iterate over entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  for (int i = 0; i < n; i++, mask <<= bits_per_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    // get current word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    if (mask == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      value = bit_mask()[word_index++];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    // test for oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
void InterpreterOopMap::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // If we are doing mark sweep _method may not have a valid header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // $$$ This used to happen only for m/s collections; we might want to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // think of an appropriate generalization of this distinction.
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 4013
diff changeset
   227
  guarantee(Universe::heap()->is_gc_active() || _method->is_oop_or_null(),
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 4013
diff changeset
   228
            "invalid oop in oopMapCache");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
#ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
void InterpreterOopMap::iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  int n = number_of_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  int word_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  uintptr_t value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  uintptr_t mask = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // iterate over entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  for (int i = 0; i < n; i++, mask <<= bits_per_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    // get current word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    if (mask == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      value = bit_mask()[word_index++];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    // test for dead values  & oops, and for live values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
         if ((value & (mask << dead_bit_number)) != 0)  dead_closure->offset_do(i); // call this for all dead values or oops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    else if ((value & (mask <<  oop_bit_number)) != 0)   oop_closure->offset_do(i); // call this for all live oops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    else                                               value_closure->offset_do(i); // call this for all live values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
void InterpreterOopMap::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  int n = number_of_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  tty->print("oop map for ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  method()->print_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  tty->print(" @ %d = [%d] { ", bci(), n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  for (int i = 0; i < n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
#ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    if (is_dead(i)) tty->print("%d+ ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    if (is_oop(i)) tty->print("%d ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  tty->print_cr("}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
class MaskFillerForNative: public NativeSignatureIterator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  uintptr_t * _mask;                             // the bit mask to be filled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  int         _size;                             // the mask size in bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  void set_one(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    i *= InterpreterOopMap::bits_per_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    assert(0 <= i && i < _size, "offset out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    _mask[i / BitsPerWord] |= (((uintptr_t) 1 << InterpreterOopMap::oop_bit_number) << (i % BitsPerWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  void pass_int()                                { /* ignore */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  void pass_long()                               { /* ignore */ }
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents: 670
diff changeset
   284
#if defined(_LP64) || defined(ZERO)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  void pass_float()                              { /* ignore */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  void pass_double()                             { /* ignore */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  void pass_object()                             { set_one(offset()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  MaskFillerForNative(methodHandle method, uintptr_t* mask, int size) : NativeSignatureIterator(method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    _mask   = mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    _size   = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    // initialize with 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    int i = (size + BitsPerWord - 1) / BitsPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    while (i-- > 0) _mask[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  void generate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    NativeSignatureIterator::iterate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
bool OopMapCacheEntry::verify_mask(CellTypeState* vars, CellTypeState* stack, int max_locals, int stack_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Check mask includes map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  VerifyClosure blk(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  iterate_oop(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (blk.failed()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // Check if map is generated correctly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // (Use ?: operator to make sure all 'true' & 'false' are represented exactly the same so we can use == afterwards)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  if (TraceOopMapGeneration && Verbose) tty->print("Locals (%d): ", max_locals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  for(int i = 0; i < max_locals; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    bool v1 = is_oop(i)               ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    bool v2 = vars[i].is_reference()  ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    assert(v1 == v2, "locals oop mask generation error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
#ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    bool v3 = is_dead(i)              ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    bool v4 = !vars[i].is_live()      ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    assert(v3 == v4, "locals live mask generation error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    assert(!(v1 && v3), "dead value marked as oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  if (TraceOopMapGeneration && Verbose) { tty->cr(); tty->print("Stack (%d): ", stack_top); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  for(int j = 0; j < stack_top; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    bool v1 = is_oop(max_locals + j)  ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    bool v2 = stack[j].is_reference() ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    assert(v1 == v2, "stack oop mask generation error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
#ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    bool v3 = is_dead(max_locals + j) ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    bool v4 = !stack[j].is_live()     ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    assert(v3 == v4, "stack live mask generation error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    assert(!(v1 && v3), "dead value marked as oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  if (TraceOopMapGeneration && Verbose) tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
void OopMapCacheEntry::allocate_bit_mask() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  if (mask_size() > small_mask_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    assert(_bit_mask[0] == 0, "bit mask should be new or just flushed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    _bit_mask[0] = (intptr_t)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      NEW_C_HEAP_ARRAY(uintptr_t, mask_word_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
void OopMapCacheEntry::deallocate_bit_mask() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  if (mask_size() > small_mask_limit && _bit_mask[0] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    assert(!Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      "This bit mask should not be in the resource area");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    FREE_C_HEAP_ARRAY(uintptr_t, _bit_mask[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    debug_only(_bit_mask[0] = 0;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
void OopMapCacheEntry::fill_for_native(methodHandle mh) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  assert(mh->is_native(), "method must be native method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  set_mask_size(mh->size_of_parameters() * bits_per_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  allocate_bit_mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  // fill mask for parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  MaskFillerForNative mf(mh, bit_mask(), mask_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  mf.generate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
void OopMapCacheEntry::fill(methodHandle method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  // Flush entry to deallocate an existing entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  set_method(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  set_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  if (method->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    // Native method activations have oops only among the parameters and one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    // extra oop following the parameters (the mirror for static native methods).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    fill_for_native(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    OopMapForCacheEntry gen(method, bci, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    gen.compute_map(CATCH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
void OopMapCacheEntry::set_mask(CellTypeState *vars, CellTypeState *stack, int stack_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  // compute bit mask size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  int max_locals = method()->max_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  int n_entries = max_locals + stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  set_mask_size(n_entries * bits_per_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  allocate_bit_mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  set_expression_stack_size(stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // compute bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  int word_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  uintptr_t value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  uintptr_t mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  CellTypeState* cell = vars;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  for (int entry_index = 0; entry_index < n_entries; entry_index++, mask <<= bits_per_entry, cell++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    // store last word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    if (mask == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      bit_mask()[word_index++] = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    // switch to stack when done with locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    if (entry_index == max_locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      cell = stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    // set oop bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    if ( cell->is_reference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      value |= (mask << oop_bit_number );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  #ifdef ENABLE_ZAP_DEAD_LOCALS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    // set dead bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    if (!cell->is_live()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      value |= (mask << dead_bit_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      assert(!cell->is_reference(), "dead value marked as oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  // make sure last word is stored
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  bit_mask()[word_index] = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  // verify bit mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  assert(verify_mask(vars, stack, max_locals, stack_top), "mask could not be verified");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
void OopMapCacheEntry::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  deallocate_bit_mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
// Implementation of OopMapCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
static long _total_memory_usage = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
long OopMapCache::memory_usage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  return _total_memory_usage;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
void InterpreterOopMap::resource_copy(OopMapCacheEntry* from) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  assert(_resource_allocate_bit_mask,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    "Should not resource allocate the _bit_mask");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  assert(from->method()->is_oop(), "MethodOop is bad");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  set_method(from->method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  set_bci(from->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  set_mask_size(from->mask_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  set_expression_stack_size(from->expression_stack_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // Is the bit mask contained in the entry?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  if (from->mask_size() <= small_mask_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    memcpy((void *)_bit_mask, (void *)from->_bit_mask,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      mask_word_size() * BytesPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    // The expectation is that this InterpreterOopMap is a recently created
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    // and empty. It is used to get a copy of a cached entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    // If the bit mask has a value, it should be in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    // resource area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    assert(_bit_mask[0] == 0 ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
      Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      "The bit mask should have been allocated from a resource area");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    // Allocate the bit_mask from a Resource area for performance.  Allocating
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    // from the C heap as is done for OopMapCache has a significant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    // performance impact.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    _bit_mask[0] = (uintptr_t) NEW_RESOURCE_ARRAY(uintptr_t, mask_word_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    assert(_bit_mask[0] != 0, "bit mask was not allocated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    memcpy((void*) _bit_mask[0], (void*) from->_bit_mask[0],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      mask_word_size() * BytesPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
inline unsigned int OopMapCache::hash_value_for(methodHandle method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  // We use method->code_size() rather than method->identity_hash() below since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  // the mark may not be present if a pointer to the method is already reversed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  return   ((unsigned int) bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
         ^ ((unsigned int) method->max_locals()         << 2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
         ^ ((unsigned int) method->code_size()          << 4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
         ^ ((unsigned int) method->size_of_parameters() << 6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
OopMapCache::OopMapCache() :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  _mut(Mutex::leaf, "An OopMapCache lock", true)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  _array  = NEW_C_HEAP_ARRAY(OopMapCacheEntry, _size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  // Cannot call flush for initialization, since flush
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  // will check if memory should be deallocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  for(int i = 0; i < _size; i++) _array[i].initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  NOT_PRODUCT(_total_memory_usage += sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
OopMapCache::~OopMapCache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  assert(_array != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  // Deallocate oop maps that are allocated out-of-line
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  // Deallocate array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  NOT_PRODUCT(_total_memory_usage -= sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  FREE_C_HEAP_ARRAY(OopMapCacheEntry, _array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
OopMapCacheEntry* OopMapCache::entry_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  return &_array[i % _size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
void OopMapCache::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  for (int i = 0; i < _size; i++) _array[i].flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
void OopMapCache::flush_obsolete_entries() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  for (int i = 0; i < _size; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    if (!_array[i].is_empty() && _array[i].method()->is_old()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      // Cache entry is occupied by an old redefined method and we don't want
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      // to pin it down so flush the entry.
221
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   535
      RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   536
        _array[i].method()->name()->as_C_string(),
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   537
        _array[i].method()->signature()->as_C_string(), i));
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   538
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
      _array[i].flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
void OopMapCache::oop_iterate(OopClosure *blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
void OopMapCache::oop_iterate(OopClosure *blk, MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk, mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
void OopMapCache::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  for (int i = 0; i < _size; i++) _array[i].verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
void OopMapCache::lookup(methodHandle method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
                         int bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
                         InterpreterOopMap* entry_for) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  MutexLocker x(&_mut);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  OopMapCacheEntry* entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  int probe = hash_value_for(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  // Search hashtable for match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  for(i = 0; i < _probe_depth; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    entry = entry_at(probe + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    if (entry->match(method, bci)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
      entry_for->resource_copy(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  if (TraceOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    static int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    tty->print("%d - Computing oopmap at bci %d for ", ++count, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
    method->print_value(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  // Entry is not in hashtable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // Compute entry and return it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
221
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   584
  if (method->should_not_be_cached()) {
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   585
    // It is either not safe or not a good idea to cache this methodOop
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   586
    // at this time. We give the caller of lookup() a copy of the
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   587
    // interesting info via parameter entry_for, but we don't add it to
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   588
    // the cache. See the gory details in methodOop.cpp.
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   589
    compute_one_oop_map(method, bci, entry_for);
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   590
    return;
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   591
  }
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   592
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  // First search for an empty slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  for(i = 0; i < _probe_depth; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    entry  = entry_at(probe + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
    if (entry->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
      entry->fill(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
      entry_for->resource_copy(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
      assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  if (TraceOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    tty->print_cr("*** collision in oopmap cache - flushing item ***");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  // No empty slot (uncommon case). Use (some approximation of a) LRU algorithm
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  //entry_at(probe + _probe_depth - 1)->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  //for(i = _probe_depth - 1; i > 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  //  // Coping entry[i] = entry[i-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  //  OopMapCacheEntry *to   = entry_at(probe + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  //  OopMapCacheEntry *from = entry_at(probe + i - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  //  to->copy(from);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  assert(method->is_method(), "gaga");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  entry = entry_at(probe + 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  entry->fill(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  // Copy the  newly cached entry to input parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  entry_for->resource_copy(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  if (TraceOopMapGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    tty->print("Done with ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    method->print_value(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
void OopMapCache::compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  // Due to the invariants above it's tricky to allocate a temporary OopMapCacheEntry on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  OopMapCacheEntry* tmp = NEW_C_HEAP_ARRAY(OopMapCacheEntry, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  tmp->initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  tmp->fill(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  entry->resource_copy(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  FREE_C_HEAP_ARRAY(OopMapCacheEntry, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
}