src/share/vm/code/oopRecorder.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 1934
e9ff18c4ace7
child 4037
da91efe96a93
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

duke@435 1 /*
jrose@1934 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "code/oopRecorder.hpp"
stefank@2314 27 #include "memory/allocation.inline.hpp"
stefank@2314 28 #include "oops/oop.inline.hpp"
duke@435 29
duke@435 30 #ifdef ASSERT
duke@435 31 int OopRecorder::_find_index_calls = 0;
duke@435 32 int OopRecorder::_hit_indexes = 0;
duke@435 33 int OopRecorder::_missed_indexes = 0;
duke@435 34 #endif //ASSERT
duke@435 35
duke@435 36
duke@435 37 OopRecorder::OopRecorder(Arena* arena) {
duke@435 38 _handles = NULL;
duke@435 39 _indexes = NULL;
duke@435 40 _arena = arena;
duke@435 41 _complete = false;
duke@435 42 }
duke@435 43
duke@435 44 OopRecorder::IndexCache::IndexCache() {
duke@435 45 assert(first_index > 0, "initial zero state of cache must be invalid index");
duke@435 46 Copy::zero_to_bytes(&_cache[0], sizeof(_cache));
duke@435 47 }
duke@435 48
duke@435 49 int OopRecorder::oop_size() {
duke@435 50 _complete = true;
duke@435 51 if (_handles == NULL) return 0;
duke@435 52 return _handles->length() * sizeof(oop);
duke@435 53 }
duke@435 54
twisti@1918 55 void OopRecorder::copy_to(nmethod* nm) {
duke@435 56 assert(_complete, "must be frozen");
duke@435 57 maybe_initialize(); // get non-null handles, even if we have no oops
twisti@1918 58 nm->copy_oops(_handles);
duke@435 59 }
duke@435 60
duke@435 61 void OopRecorder::maybe_initialize() {
duke@435 62 if (_handles == NULL) {
duke@435 63 if (_arena != NULL) {
duke@435 64 _handles = new(_arena) GrowableArray<jobject>(_arena, 10, 0, 0);
duke@435 65 _no_finds = new(_arena) GrowableArray<int>( _arena, 10, 0, 0);
duke@435 66 } else {
duke@435 67 _handles = new GrowableArray<jobject>(10, 0, 0);
duke@435 68 _no_finds = new GrowableArray<int>( 10, 0, 0);
duke@435 69 }
duke@435 70 }
duke@435 71 }
duke@435 72
duke@435 73
duke@435 74 jobject OopRecorder::handle_at(int index) {
duke@435 75 // there is always a NULL virtually present as first object
duke@435 76 if (index == null_index) return NULL;
duke@435 77 return _handles->at(index - first_index);
duke@435 78 }
duke@435 79
duke@435 80
duke@435 81 // Local definition. Used only in this module.
duke@435 82 inline bool OopRecorder::is_real_jobject(jobject h) {
duke@435 83 return h != NULL && h != (jobject)Universe::non_oop_word();
duke@435 84 }
duke@435 85
duke@435 86
duke@435 87 int OopRecorder::add_handle(jobject h, bool make_findable) {
duke@435 88 assert(!_complete, "cannot allocate more elements after size query");
duke@435 89 maybe_initialize();
duke@435 90 // indexing uses 1 as an origin--0 means null
duke@435 91 int index = _handles->length() + first_index;
duke@435 92 _handles->append(h);
duke@435 93
duke@435 94 // Support correct operation of find_index().
duke@435 95 assert(!(make_findable && !is_real_jobject(h)), "nulls are not findable");
duke@435 96 if (make_findable) {
duke@435 97 // This index may be returned from find_index().
duke@435 98 if (_indexes != NULL) {
duke@435 99 int* cloc = _indexes->cache_location(h);
duke@435 100 _indexes->set_cache_location_index(cloc, index);
duke@435 101 } else if (index == index_cache_threshold && _arena != NULL) {
duke@435 102 _indexes = new(_arena) IndexCache();
duke@435 103 for (int i = 0; i < _handles->length(); i++) {
duke@435 104 // Load the cache with pre-existing elements.
duke@435 105 int index0 = i + first_index;
duke@435 106 if (_no_finds->contains(index0)) continue;
duke@435 107 int* cloc = _indexes->cache_location(_handles->at(i));
duke@435 108 _indexes->set_cache_location_index(cloc, index0);
duke@435 109 }
duke@435 110 }
duke@435 111 } else if (is_real_jobject(h)) {
duke@435 112 // Remember that this index is not to be returned from find_index().
duke@435 113 // This case is rare, because most or all uses of allocate_index pass
duke@435 114 // a jobject argument of NULL or Universe::non_oop_word.
duke@435 115 // Thus, the expected length of _no_finds is zero.
duke@435 116 _no_finds->append(index);
duke@435 117 }
duke@435 118
duke@435 119 return index;
duke@435 120 }
duke@435 121
duke@435 122
duke@435 123 int OopRecorder::maybe_find_index(jobject h) {
duke@435 124 debug_only(_find_index_calls++);
duke@435 125 assert(!_complete, "cannot allocate more elements after size query");
duke@435 126 maybe_initialize();
duke@435 127 if (h == NULL) return null_index;
duke@435 128 assert(is_real_jobject(h), "must be valid jobject");
duke@435 129 int* cloc = (_indexes == NULL)? NULL: _indexes->cache_location(h);
duke@435 130 if (cloc != NULL) {
duke@435 131 int cindex = _indexes->cache_location_index(cloc);
duke@435 132 if (cindex == 0) {
duke@435 133 return -1; // We know this handle is completely new.
duke@435 134 }
duke@435 135 if (cindex >= first_index && _handles->at(cindex - first_index) == h) {
duke@435 136 debug_only(_hit_indexes++);
duke@435 137 return cindex;
duke@435 138 }
duke@435 139 if (!_indexes->cache_location_collision(cloc)) {
duke@435 140 return -1; // We know the current cache occupant is unique to that cloc.
duke@435 141 }
duke@435 142 }
duke@435 143
duke@435 144 // Not found in cache, due to a cache collision. (Or, no cache at all.)
duke@435 145 // Do a linear search, most recent to oldest.
duke@435 146 for (int i = _handles->length() - 1; i >= 0; i--) {
duke@435 147 if (_handles->at(i) == h) {
duke@435 148 int findex = i + first_index;
duke@435 149 if (_no_finds->contains(findex)) continue; // oops; skip this one
duke@435 150 if (cloc != NULL) {
duke@435 151 _indexes->set_cache_location_index(cloc, findex);
duke@435 152 }
duke@435 153 debug_only(_missed_indexes++);
duke@435 154 return findex;
duke@435 155 }
duke@435 156 }
duke@435 157 return -1;
duke@435 158 }

mercurial