annotate src/share/vm/code/oopRecorder.cpp @ 10408:836a62f43af9

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