src/hotspot/share/code/oopRecorder.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 54783 3331dad9cb30
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
48831
05894c073b7e 8196199: Remove miscellaneous oop comparison operators
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    25
#include "precompiled.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    26
#include "ci/ciEnv.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    27
#include "ci/ciInstance.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    28
#include "ci/ciMetadata.hpp"
54783
3331dad9cb30 8223621: Move Universe usage out of oopRecorder.hpp
stefank
parents: 51333
diff changeset
    29
#include "code/oopRecorder.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    30
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    31
#include "oops/oop.inline.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 48831
diff changeset
    32
#include "runtime/jniHandles.inline.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 49192
diff changeset
    33
#include "utilities/copy.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    36
template <class T> int ValueRecorder<T>::_find_index_calls = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    37
template <class T> int ValueRecorder<T>::_hit_indexes      = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    38
template <class T> int ValueRecorder<T>::_missed_indexes   = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#endif //ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    42
template <class T> ValueRecorder<T>::ValueRecorder(Arena* arena) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _handles  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _indexes  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _arena    = arena;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _complete = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    49
template <class T> template <class X>  ValueRecorder<T>::IndexCache<X>::IndexCache() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  assert(first_index > 0, "initial zero state of cache must be invalid index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  Copy::zero_to_bytes(&_cache[0], sizeof(_cache));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    54
template <class T> int ValueRecorder<T>::size() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _complete = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  if (_handles == NULL)  return 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    57
  return _handles->length() * sizeof(T);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    60
template <class T> void ValueRecorder<T>::copy_values_to(nmethod* nm) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  assert(_complete, "must be frozen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  maybe_initialize();  // get non-null handles, even if we have no oops
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    63
  nm->copy_values(_handles);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    66
template <class T> void ValueRecorder<T>::maybe_initialize() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  if (_handles == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    if (_arena != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    69
      _handles  = new(_arena) GrowableArray<T>(_arena, 10, 0, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      _no_finds = new(_arena) GrowableArray<int>(    _arena, 10, 0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    72
      _handles  = new GrowableArray<T>(10, 0, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      _no_finds = new GrowableArray<int>(    10, 0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    79
template <class T> T ValueRecorder<T>::at(int index) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // there is always a NULL virtually present as first object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (index == null_index)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  return _handles->at(index - first_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    86
template <class T> int ValueRecorder<T>::add_handle(T h, bool make_findable) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  assert(!_complete, "cannot allocate more elements after size query");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  maybe_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // indexing uses 1 as an origin--0 means null
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  int index = _handles->length() + first_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  _handles->append(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Support correct operation of find_index().
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    94
  assert(!(make_findable && !is_real(h)), "nulls are not findable");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  if (make_findable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    // This index may be returned from find_index().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if (_indexes != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      int* cloc = _indexes->cache_location(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      _indexes->set_cache_location_index(cloc, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    } else if (index == index_cache_threshold && _arena != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   101
      _indexes = new(_arena) IndexCache<T>();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      for (int i = 0; i < _handles->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        // Load the cache with pre-existing elements.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        int index0 = i + first_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        if (_no_finds->contains(index0))  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        int* cloc = _indexes->cache_location(_handles->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        _indexes->set_cache_location_index(cloc, index0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   110
  } else if (is_real(h)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // Remember that this index is not to be returned from find_index().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // This case is rare, because most or all uses of allocate_index pass
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   113
    // an argument of NULL or Universe::non_oop_word.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // Thus, the expected length of _no_finds is zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    _no_finds->append(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  return index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   122
template <class T> int ValueRecorder<T>::maybe_find_index(T h) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  debug_only(_find_index_calls++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  assert(!_complete, "cannot allocate more elements after size query");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  maybe_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (h == NULL)  return null_index;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   127
  assert(is_real(h), "must be valid");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  int* cloc = (_indexes == NULL)? NULL: _indexes->cache_location(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  if (cloc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    int cindex = _indexes->cache_location_index(cloc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (cindex == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      return -1;   // We know this handle is completely new.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (cindex >= first_index && _handles->at(cindex - first_index) == h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      debug_only(_hit_indexes++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      return cindex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    if (!_indexes->cache_location_collision(cloc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      return -1;   // We know the current cache occupant is unique to that cloc.
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
  // Not found in cache, due to a cache collision.  (Or, no cache at all.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Do a linear search, most recent to oldest.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  for (int i = _handles->length() - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    if (_handles->at(i) == h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      int findex = i + first_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if (_no_finds->contains(findex))  continue;  // oops; skip this one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      if (cloc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        _indexes->set_cache_location_index(cloc, findex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      debug_only(_missed_indexes++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      return findex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   158
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   159
// Explicitly instantiate these types
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   160
template class ValueRecorder<Metadata*>;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   161
template class ValueRecorder<jobject>;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   162
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   163
oop ObjectLookup::ObjectEntry::oop_value() const { return JNIHandles::resolve(_value); }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   164
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 49593
diff changeset
   165
ObjectLookup::ObjectLookup(): _values(4), _gc_count(Universe::heap()->total_collections()) {}
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   166
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   167
void ObjectLookup::maybe_resort() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   168
  // The values are kept sorted by address which may be invalidated
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   169
  // after a GC, so resort if a GC has occurred since last time.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   170
  if (_gc_count != Universe::heap()->total_collections()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   171
    _gc_count = Universe::heap()->total_collections();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   172
    _values.sort(sort_by_address);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   173
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   174
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   175
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   176
int ObjectLookup::sort_by_address(oop a, oop b) {
48831
05894c073b7e 8196199: Remove miscellaneous oop comparison operators
coleenp
parents: 47216
diff changeset
   177
  // oopDesc::compare returns the opposite of what this function returned
05894c073b7e 8196199: Remove miscellaneous oop comparison operators
coleenp
parents: 47216
diff changeset
   178
  return -(oopDesc::compare(a, b));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   179
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   180
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   181
int ObjectLookup::sort_by_address(ObjectEntry* a, ObjectEntry* b) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   182
  return sort_by_address(a->oop_value(), b->oop_value());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   183
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   184
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   185
int ObjectLookup::sort_oop_by_address(oop const& a, ObjectEntry const& b) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   186
  return sort_by_address(a, b.oop_value());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   187
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   188
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   189
int ObjectLookup::find_index(jobject handle, OopRecorder* oop_recorder) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   190
  if (handle == NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   191
    return 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   192
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   193
  oop object = JNIHandles::resolve(handle);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   194
  maybe_resort();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   195
  bool found;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   196
  int location = _values.find_sorted<oop, sort_oop_by_address>(object, found);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   197
  if (!found) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   198
    jobject handle = JNIHandles::make_local(object);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   199
    ObjectEntry r(handle, oop_recorder->allocate_oop_index(handle));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   200
    _values.insert_before(location, r);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   201
    return r.index();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   202
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   203
  return _values.at(location).index();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 13728
diff changeset
   204
}