src/hotspot/share/interpreter/oopMapCache.cpp
author stefank
Mon, 25 Nov 2019 12:22:13 +0100
changeset 59247 56bf71d64d51
parent 58083 9046db64ca39
child 59252 623722a6aeb9
permissions -rw-r--r--
8234562: Move OrderAccess::release_store*/load_acquire to Atomic Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 47634
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: 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    26
#include "interpreter/oopMapCache.hpp"
38259
b495d1cfe673 8153535: Convert TraceRedefineClasses to Unified Logging
rehn
parents: 33593
diff changeset
    27
#include "logging/log.hpp"
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
    28
#include "logging/logStream.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    29
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    30
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    31
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    32
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    33
#include "runtime/signature.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class OopMapCacheEntry: private InterpreterOopMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  friend class InterpreterOopMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  friend class OopMapForCacheEntry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  friend class OopMapCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  friend class VerifyClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
    41
 private:
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
    42
  OopMapCacheEntry* _next;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
    43
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Initialization
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 38259
diff changeset
    46
  void fill(const methodHandle& method, int bci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // fills the bit mask for native calls
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 38259
diff changeset
    48
  void fill_for_native(const methodHandle& method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  void set_mask(CellTypeState* vars, CellTypeState* stack, int stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // Deallocate bit masks and initialize fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  void allocate_bit_mask();   // allocates the bit mask on C heap f necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  void deallocate_bit_mask(); // allocates the bit mask on C heap f necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  bool verify_mask(CellTypeState *vars, CellTypeState *stack, int max_locals, int stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  OopMapCacheEntry() : InterpreterOopMap() {
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
    61
    _next = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
#ifdef ASSERT
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
    63
    _resource_allocate_bit_mask = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
// Implementation of OopMapForCacheEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// (subclass of GenerateOopMap, initializes an OopMapCacheEntry for a given method and bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
class OopMapForCacheEntry: public GenerateOopMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  OopMapCacheEntry *_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  int               _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  int               _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  virtual bool report_results() const     { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  virtual bool possible_gc_point          (BytecodeStream *bcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  virtual void fill_stackmap_prolog       (int nof_gc_points);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  virtual void fill_stackmap_epilog       ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  virtual void fill_stackmap_for_opcodes  (BytecodeStream *bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                                           CellTypeState* vars,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                                           CellTypeState* stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                                           int stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  virtual void fill_init_vars             (GrowableArray<intptr_t> *init_vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
 public:
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 38259
diff changeset
    88
  OopMapForCacheEntry(const methodHandle& method, int bci, OopMapCacheEntry *entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Computes stack map for (method,bci) and initialize entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  void compute_map(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  int  size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 38259
diff changeset
    96
OopMapForCacheEntry::OopMapForCacheEntry(const methodHandle& method, int bci, OopMapCacheEntry* entry) : GenerateOopMap(method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  _bci       = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  _entry     = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  _stack_top = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
void OopMapForCacheEntry::compute_map(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  assert(!method()->is_native(), "cannot compute oop map for native methods");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // First check if it is a method where the stackmap is always empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  if (method()->code_size() == 0 || method()->max_locals() + method()->max_stack() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    _entry->set_mask_size(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    GenerateOopMap::compute_map(CATCH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    result_for_basicblock(_bci);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
bool OopMapForCacheEntry::possible_gc_point(BytecodeStream *bcs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  return false; // We are not reporting any result. We call result_for_basicblock directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
void OopMapForCacheEntry::fill_stackmap_prolog(int nof_gc_points) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // Do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
void OopMapForCacheEntry::fill_stackmap_epilog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
void OopMapForCacheEntry::fill_init_vars(GrowableArray<intptr_t> *init_vars) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // Do nothing
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
void OopMapForCacheEntry::fill_stackmap_for_opcodes(BytecodeStream *bcs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
                                                    CellTypeState* vars,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
                                                    CellTypeState* stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
                                                    int stack_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // Only interested in one specific bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  if (bcs->bci() == _bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    _entry->set_mask(vars, stack, stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    _stack_top = stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
int OopMapForCacheEntry::size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  assert(_stack_top != -1, "compute_map must be called first");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  return ((method()->is_static()) ? 0 : 1) + method()->max_locals() + _stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// Implementation of InterpreterOopMap and OopMapCacheEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
class VerifyClosure : public OffsetClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  OopMapCacheEntry* _entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  bool              _failed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  VerifyClosure(OopMapCacheEntry* entry)         { _entry = entry; _failed = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  void offset_do(int offset)                     { if (!_entry->is_oop(offset)) _failed = true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  bool failed() const                            { return _failed; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
InterpreterOopMap::InterpreterOopMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  _resource_allocate_bit_mask = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
InterpreterOopMap::~InterpreterOopMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // The expection is that the bit mask was allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // last in this resource area.  That would make the free of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // bit_mask effective (see how FREE_RESOURCE_ARRAY does a free).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // If it was not allocated last, there is not a correctness problem
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // but the space for the bit_mask is not freed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  assert(_resource_allocate_bit_mask, "Trying to free C heap space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  if (mask_size() > small_mask_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    FREE_RESOURCE_ARRAY(uintptr_t, _bit_mask[0], mask_word_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
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: 24424
diff changeset
   186
bool InterpreterOopMap::is_empty() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  bool result = _method == NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  assert(_method != NULL || (_bci == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    (_mask_size == 0 || _mask_size == USHRT_MAX) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    _bit_mask[0] == 0), "Should be completely empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
void InterpreterOopMap::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  _method    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  _mask_size = USHRT_MAX;  // This value should cause a failure quickly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  _bci       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  _expression_stack_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  for (int i = 0; i < N; i++) _bit_mask[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
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: 24424
diff changeset
   202
void InterpreterOopMap::iterate_oop(OffsetClosure* oop_closure) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  int n = number_of_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  int word_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  uintptr_t value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  uintptr_t mask = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // iterate over entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  for (int i = 0; i < n; i++, mask <<= bits_per_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    // get current word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    if (mask == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      value = bit_mask()[word_index++];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    // test for oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
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: 24424
diff changeset
   219
void InterpreterOopMap::print() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  int n = number_of_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  tty->print("oop map for ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  method()->print_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  tty->print(" @ %d = [%d] { ", bci(), n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  for (int i = 0; i < n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    if (is_dead(i)) tty->print("%d+ ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    if (is_oop(i)) tty->print("%d ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  tty->print_cr("}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
class MaskFillerForNative: public NativeSignatureIterator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  uintptr_t * _mask;                             // the bit mask to be filled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  int         _size;                             // the mask size in bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  void set_one(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    i *= InterpreterOopMap::bits_per_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    assert(0 <= i && i < _size, "offset out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    _mask[i / BitsPerWord] |= (((uintptr_t) 1 << InterpreterOopMap::oop_bit_number) << (i % BitsPerWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  void pass_int()                                { /* ignore */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  void pass_long()                               { /* ignore */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  void pass_float()                              { /* ignore */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  void pass_double()                             { /* ignore */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  void pass_object()                             { set_one(offset()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 38259
diff changeset
   250
  MaskFillerForNative(const methodHandle& method, uintptr_t* mask, int size) : NativeSignatureIterator(method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    _mask   = mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    _size   = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    // initialize with 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    int i = (size + BitsPerWord - 1) / BitsPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    while (i-- > 0) _mask[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  void generate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    NativeSignatureIterator::iterate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
bool OopMapCacheEntry::verify_mask(CellTypeState* vars, CellTypeState* stack, int max_locals, int stack_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // Check mask includes map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  VerifyClosure blk(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  iterate_oop(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  if (blk.failed()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // Check if map is generated correctly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  // (Use ?: operator to make sure all 'true' & 'false' are represented exactly the same so we can use == afterwards)
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   271
  Log(interpreter, oopmap) logv;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   272
  LogStream st(logv.trace());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   274
  st.print("Locals (%d): ", max_locals);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  for(int i = 0; i < max_locals; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    bool v1 = is_oop(i)               ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    bool v2 = vars[i].is_reference()  ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    assert(v1 == v2, "locals oop mask generation error");
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   279
    st.print("%d", v1 ? 1 : 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   281
  st.cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   283
  st.print("Stack (%d): ", stack_top);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  for(int j = 0; j < stack_top; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    bool v1 = is_oop(max_locals + j)  ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    bool v2 = stack[j].is_reference() ? true : false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    assert(v1 == v2, "stack oop mask generation error");
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   288
    st.print("%d", v1 ? 1 : 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  }
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   290
  st.cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
void OopMapCacheEntry::allocate_bit_mask() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  if (mask_size() > small_mask_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    assert(_bit_mask[0] == 0, "bit mask should be new or just flushed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    _bit_mask[0] = (intptr_t)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   298
      NEW_C_HEAP_ARRAY(uintptr_t, mask_word_size(), mtClass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
void OopMapCacheEntry::deallocate_bit_mask() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  if (mask_size() > small_mask_limit && _bit_mask[0] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    assert(!Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      "This bit mask should not be in the resource area");
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25626
diff changeset
   306
    FREE_C_HEAP_ARRAY(uintptr_t, _bit_mask[0]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    debug_only(_bit_mask[0] = 0;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 38259
diff changeset
   312
void OopMapCacheEntry::fill_for_native(const methodHandle& mh) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  assert(mh->is_native(), "method must be native method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  set_mask_size(mh->size_of_parameters() * bits_per_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  allocate_bit_mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // fill mask for parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  MaskFillerForNative mf(mh, bit_mask(), mask_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  mf.generate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 38259
diff changeset
   322
void OopMapCacheEntry::fill(const methodHandle& method, int bci) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // Flush entry to deallocate an existing entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  set_method(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  set_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  if (method->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    // Native method activations have oops only among the parameters and one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    // extra oop following the parameters (the mirror for static native methods).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    fill_for_native(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    OopMapForCacheEntry gen(method, bci, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    gen.compute_map(CATCH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
void OopMapCacheEntry::set_mask(CellTypeState *vars, CellTypeState *stack, int stack_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  // compute bit mask size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  int max_locals = method()->max_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  int n_entries = max_locals + stack_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  set_mask_size(n_entries * bits_per_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  allocate_bit_mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  set_expression_stack_size(stack_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  // compute bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  int word_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  uintptr_t value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  uintptr_t mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  CellTypeState* cell = vars;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  for (int entry_index = 0; entry_index < n_entries; entry_index++, mask <<= bits_per_entry, cell++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    // store last word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    if (mask == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      bit_mask()[word_index++] = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    // switch to stack when done with locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    if (entry_index == max_locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      cell = stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    // set oop bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    if ( cell->is_reference()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      value |= (mask << oop_bit_number );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    // set dead bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    if (!cell->is_live()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      value |= (mask << dead_bit_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      assert(!cell->is_reference(), "dead value marked as oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // make sure last word is stored
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  bit_mask()[word_index] = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  // verify bit mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  assert(verify_mask(vars, stack, max_locals, stack_top), "mask could not be verified");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
void OopMapCacheEntry::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  deallocate_bit_mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  initialize();
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
// Implementation of OopMapCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
void InterpreterOopMap::resource_copy(OopMapCacheEntry* from) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  assert(_resource_allocate_bit_mask,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    "Should not resource allocate the _bit_mask");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  set_method(from->method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  set_bci(from->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  set_mask_size(from->mask_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  set_expression_stack_size(from->expression_stack_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // Is the bit mask contained in the entry?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  if (from->mask_size() <= small_mask_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    memcpy((void *)_bit_mask, (void *)from->_bit_mask,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
      mask_word_size() * BytesPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    // The expectation is that this InterpreterOopMap is a recently created
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    // and empty. It is used to get a copy of a cached entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    // If the bit mask has a value, it should be in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    // resource area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    assert(_bit_mask[0] == 0 ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      "The bit mask should have been allocated from a resource area");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    // Allocate the bit_mask from a Resource area for performance.  Allocating
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    // from the C heap as is done for OopMapCache has a significant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    // performance impact.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    _bit_mask[0] = (uintptr_t) NEW_RESOURCE_ARRAY(uintptr_t, mask_word_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    assert(_bit_mask[0] != 0, "bit mask was not allocated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    memcpy((void*) _bit_mask[0], (void*) from->_bit_mask[0],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      mask_word_size() * BytesPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33148
diff changeset
   425
inline unsigned int OopMapCache::hash_value_for(const methodHandle& method, int bci) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  // We use method->code_size() rather than method->identity_hash() below since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  // the mark may not be present if a pointer to the method is already reversed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  return   ((unsigned int) bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
         ^ ((unsigned int) method->max_locals()         << 2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
         ^ ((unsigned int) method->code_size()          << 4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
         ^ ((unsigned int) method->size_of_parameters() << 6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   434
OopMapCacheEntry* volatile OopMapCache::_old_entries = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   436
OopMapCache::OopMapCache() {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   437
  _array  = NEW_C_HEAP_ARRAY(OopMapCacheEntry*, _size, mtClass);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   438
  for(int i = 0; i < _size; i++) _array[i] = NULL;
1
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
OopMapCache::~OopMapCache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  assert(_array != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  // Deallocate oop maps that are allocated out-of-line
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  // Deallocate array
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   447
  FREE_C_HEAP_ARRAY(OopMapCacheEntry*, _array);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
OopMapCacheEntry* OopMapCache::entry_at(int i) const {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 58083
diff changeset
   451
  return Atomic::load_acquire(&(_array[i % _size]));
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   452
}
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   453
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   454
bool OopMapCache::put_at(int i, OopMapCacheEntry* entry, OopMapCacheEntry* old) {
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   455
  return Atomic::cmpxchg(entry, &_array[i % _size], old) == old;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
void OopMapCache::flush() {
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   459
  for (int i = 0; i < _size; i++) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   460
    OopMapCacheEntry* entry = _array[i];
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   461
    if (entry != NULL) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   462
      _array[i] = NULL;  // no barrier, only called in OopMapCache destructor
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   463
      entry->flush();
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   464
      FREE_C_HEAP_OBJ(entry);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   465
    }
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   466
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
void OopMapCache::flush_obsolete_entries() {
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   470
  assert(SafepointSynchronize::is_at_safepoint(), "called by RedefineClasses in a safepoint");
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   471
  for (int i = 0; i < _size; i++) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   472
    OopMapCacheEntry* entry = _array[i];
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   473
    if (entry != NULL && !entry->is_empty() && entry->method()->is_old()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
      // Cache entry is occupied by an old redefined method and we don't want
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
      // to pin it down so flush the entry.
38259
b495d1cfe673 8153535: Convert TraceRedefineClasses to Unified Logging
rehn
parents: 33593
diff changeset
   476
      if (log_is_enabled(Debug, redefine, class, oopmap)) {
b495d1cfe673 8153535: Convert TraceRedefineClasses to Unified Logging
rehn
parents: 33593
diff changeset
   477
        ResourceMark rm;
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   478
        log_debug(redefine, class, interpreter, oopmap)
38259
b495d1cfe673 8153535: Convert TraceRedefineClasses to Unified Logging
rehn
parents: 33593
diff changeset
   479
          ("flush: %s(%s): cached entry @%d",
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   480
           entry->method()->name()->as_C_string(), entry->method()->signature()->as_C_string(), i);
38259
b495d1cfe673 8153535: Convert TraceRedefineClasses to Unified Logging
rehn
parents: 33593
diff changeset
   481
      }
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   482
      _array[i] = NULL;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   483
      entry->flush();
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   484
      FREE_C_HEAP_OBJ(entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    }
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   486
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   489
// Called by GC for thread root scan during a safepoint only.  The other interpreted frame oopmaps
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   490
// are generated locally and not cached.
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33148
diff changeset
   491
void OopMapCache::lookup(const methodHandle& method,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
                         int bci,
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   493
                         InterpreterOopMap* entry_for) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   494
  assert(SafepointSynchronize::is_at_safepoint(), "called by GC in a safepoint");
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   495
  int probe = hash_value_for(method, bci);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   496
  int i;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   497
  OopMapCacheEntry* entry = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   499
  if (log_is_enabled(Debug, interpreter, oopmap)) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   500
    static int count = 0;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   501
    ResourceMark rm;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   502
    log_debug(interpreter, oopmap)
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   503
          ("%d - Computing oopmap at bci %d for %s at hash %d", ++count, bci,
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   504
           method()->name_and_sig_as_C_string(), probe);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   505
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  // Search hashtable for match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  for(i = 0; i < _probe_depth; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    entry = entry_at(probe + i);
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   510
    if (entry != NULL && !entry->is_empty() && entry->match(method, bci)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      entry_for->resource_copy(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
      assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   513
      log_debug(interpreter, oopmap)("- found at hash %d", probe + i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   518
  // Entry is not in hashtable.
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   519
  // Compute entry
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   521
  OopMapCacheEntry* tmp = NEW_C_HEAP_OBJ(OopMapCacheEntry, mtClass);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   522
  tmp->initialize();
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   523
  tmp->fill(method, bci);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   524
  entry_for->resource_copy(tmp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
221
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   526
  if (method->should_not_be_cached()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   527
    // It is either not safe or not a good idea to cache this Method*
221
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   528
    // 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
   529
    // interesting info via parameter entry_for, but we don't add it to
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   530
    // the cache. See the gory details in Method*.cpp.
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   531
    FREE_C_HEAP_OBJ(tmp);
221
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   532
    return;
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   533
  }
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   534
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  // First search for an empty slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  for(i = 0; i < _probe_depth; i++) {
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   537
    entry = entry_at(probe + i);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   538
    if (entry == NULL) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   539
      if (put_at(probe + i, tmp, NULL)) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   540
        assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   541
        return;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   542
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   546
  log_debug(interpreter, oopmap)("*** collision in oopmap cache - flushing item ***");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // No empty slot (uncommon case). Use (some approximation of a) LRU algorithm
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   549
  // where the first entry in the collision array is replaced with the new one.
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   550
  OopMapCacheEntry* old = entry_at(probe + 0);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   551
  if (put_at(probe + 0, tmp, old)) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   552
    enqueue_for_cleanup(old);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   553
  } else {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   554
    enqueue_for_cleanup(tmp);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   555
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   557
  assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   558
  return;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   559
}
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   560
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   561
void OopMapCache::enqueue_for_cleanup(OopMapCacheEntry* entry) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   562
  bool success = false;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   563
  OopMapCacheEntry* head;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   564
  do {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   565
    head = _old_entries;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   566
    entry->_next = head;
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   567
    success = Atomic::cmpxchg(entry, &_old_entries, head) == head;
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   568
  } while (!success);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   570
  if (log_is_enabled(Debug, interpreter, oopmap)) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   571
    ResourceMark rm;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   572
    log_debug(interpreter, oopmap)("enqueue %s at bci %d for cleanup",
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   573
                          entry->method()->name_and_sig_as_C_string(), entry->bci());
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   574
  }
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   575
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   577
// This is called after GC threads are done and nothing is accessing the old_entries
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   578
// list, so no synchronization needed.
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   579
void OopMapCache::cleanup_old_entries() {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   580
  OopMapCacheEntry* entry = _old_entries;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   581
  _old_entries = NULL;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   582
  while (entry != NULL) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   583
    if (log_is_enabled(Debug, interpreter, oopmap)) {
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   584
      ResourceMark rm;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   585
      log_debug(interpreter, oopmap)("cleanup entry %s at bci %d",
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   586
                          entry->method()->name_and_sig_as_C_string(), entry->bci());
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   587
    }
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   588
    OopMapCacheEntry* next = entry->_next;
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   589
    entry->flush();
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   590
    FREE_C_HEAP_OBJ(entry);
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46727
diff changeset
   591
    entry = next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33148
diff changeset
   595
void OopMapCache::compute_one_oop_map(const methodHandle& method, int bci, InterpreterOopMap* entry) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  // Due to the invariants above it's tricky to allocate a temporary OopMapCacheEntry on the stack
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 47634
diff changeset
   597
  OopMapCacheEntry* tmp = NEW_C_HEAP_OBJ(OopMapCacheEntry, mtClass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  tmp->initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  tmp->fill(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  entry->resource_copy(tmp);
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 47634
diff changeset
   601
  FREE_C_HEAP_OBJ(tmp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
}