src/share/vm/code/oopRecorder.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial