hotspot/src/share/vm/code/oopRecorder.cpp
author coleenp
Thu, 27 Jan 2011 16:11:27 -0800
changeset 8076 96d498ec7ae1
parent 7397 5b173b4ca846
child 13728 882756847a04
permissions -rw-r--r--
6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5702
jrose
parents: 5547 5686
diff changeset
     2
 * Copyright (c) 1998, 2010, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    26
#include "code/oopRecorder.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    27
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    28
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
int OopRecorder::_find_index_calls = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
int OopRecorder::_hit_indexes      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
int OopRecorder::_missed_indexes   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#endif //ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
OopRecorder::OopRecorder(Arena* arena) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _handles  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _indexes  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _arena    = arena;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  _complete = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
OopRecorder::IndexCache::IndexCache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  assert(first_index > 0, "initial zero state of cache must be invalid index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  Copy::zero_to_bytes(&_cache[0], sizeof(_cache));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
int OopRecorder::oop_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  _complete = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  if (_handles == NULL)  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  return _handles->length() * sizeof(oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
    55
void OopRecorder::copy_to(nmethod* nm) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  assert(_complete, "must be frozen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  maybe_initialize();  // get non-null handles, even if we have no oops
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
    58
  nm->copy_oops(_handles);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
void OopRecorder::maybe_initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  if (_handles == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    if (_arena != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      _handles  = new(_arena) GrowableArray<jobject>(_arena, 10, 0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      _no_finds = new(_arena) GrowableArray<int>(    _arena, 10, 0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      _handles  = new GrowableArray<jobject>(10, 0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      _no_finds = new GrowableArray<int>(    10, 0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
jobject OopRecorder::handle_at(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // there is always a NULL virtually present as first object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  if (index == null_index)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  return _handles->at(index - first_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// Local definition.  Used only in this module.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
inline bool OopRecorder::is_real_jobject(jobject h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  return h != NULL && h != (jobject)Universe::non_oop_word();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
int OopRecorder::add_handle(jobject h, bool make_findable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  assert(!_complete, "cannot allocate more elements after size query");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  maybe_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // indexing uses 1 as an origin--0 means null
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int index = _handles->length() + first_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _handles->append(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Support correct operation of find_index().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  assert(!(make_findable && !is_real_jobject(h)), "nulls are not findable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  if (make_findable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    // This index may be returned from find_index().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    if (_indexes != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      int* cloc = _indexes->cache_location(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      _indexes->set_cache_location_index(cloc, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    } else if (index == index_cache_threshold && _arena != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      _indexes = new(_arena) IndexCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      for (int i = 0; i < _handles->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        // Load the cache with pre-existing elements.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        int index0 = i + first_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        if (_no_finds->contains(index0))  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        int* cloc = _indexes->cache_location(_handles->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        _indexes->set_cache_location_index(cloc, index0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  } else if (is_real_jobject(h)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // Remember that this index is not to be returned from find_index().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // This case is rare, because most or all uses of allocate_index pass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // a jobject argument of NULL or Universe::non_oop_word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    // Thus, the expected length of _no_finds is zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    _no_finds->append(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  return index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
int OopRecorder::maybe_find_index(jobject h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  debug_only(_find_index_calls++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  assert(!_complete, "cannot allocate more elements after size query");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  maybe_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  if (h == NULL)  return null_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  assert(is_real_jobject(h), "must be valid jobject");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  int* cloc = (_indexes == NULL)? NULL: _indexes->cache_location(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  if (cloc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    int cindex = _indexes->cache_location_index(cloc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    if (cindex == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      return -1;   // We know this handle is completely new.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    if (cindex >= first_index && _handles->at(cindex - first_index) == h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      debug_only(_hit_indexes++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      return cindex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    if (!_indexes->cache_location_collision(cloc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      return -1;   // We know the current cache occupant is unique to that cloc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Not found in cache, due to a cache collision.  (Or, no cache at all.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Do a linear search, most recent to oldest.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  for (int i = _handles->length() - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    if (_handles->at(i) == h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      int findex = i + first_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      if (_no_finds->contains(findex))  continue;  // oops; skip this one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      if (cloc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        _indexes->set_cache_location_index(cloc, findex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      debug_only(_missed_indexes++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      return findex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}