Mercurial > hg > truffle
annotate src/share/vm/code/oopRecorder.cpp @ 17381:40dce17629ac
correct IfNode probabilities in If-Deopt situations
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Wed, 08 Oct 2014 10:49:53 +0200 |
parents | 44b83285b645 |
children | 50942f016967 |
rev | line source |
---|---|
0 | 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 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
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 | 22 * |
23 */ | |
24 | |
1972 | 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 | 29 #include "code/oopRecorder.hpp" |
30 #include "memory/allocation.inline.hpp" | |
31 #include "oops/oop.inline.hpp" | |
0 | 32 |
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; |
17374
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
37 |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
38 void OopRecorder::check_for_duplicates(int index, jobject h) { |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
39 oop o = JNIHandles::resolve(h); |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
40 for (int i = 1; i < oop_count(); i++) { |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
41 if (o == JNIHandles::resolve(oop_at(i)) && index != i) { |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
42 assert(false, "duplicate found"); |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
43 } |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
44 } |
9928ad27a80e
OopRecorder should check for duplicates
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
6725
diff
changeset
|
45 } |
0 | 46 #endif //ASSERT |
47 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
48 template <class T> ValueRecorder<T>::ValueRecorder(Arena* arena) { |
0 | 49 _handles = NULL; |
50 _indexes = NULL; | |
51 _arena = arena; | |
52 _complete = false; | |
53 } | |
54 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
55 template <class T> template <class X> ValueRecorder<T>::IndexCache<X>::IndexCache() { |
0 | 56 assert(first_index > 0, "initial zero state of cache must be invalid index"); |
57 Copy::zero_to_bytes(&_cache[0], sizeof(_cache)); | |
58 } | |
59 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
60 template <class T> int ValueRecorder<T>::size() { |
0 | 61 _complete = true; |
62 if (_handles == NULL) return 0; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
63 return _handles->length() * sizeof(T); |
0 | 64 } |
65 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
66 template <class T> void ValueRecorder<T>::copy_values_to(nmethod* nm) { |
0 | 67 assert(_complete, "must be frozen"); |
68 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
|
69 nm->copy_values(_handles); |
0 | 70 } |
71 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
72 template <class T> void ValueRecorder<T>::maybe_initialize() { |
0 | 73 if (_handles == NULL) { |
74 if (_arena != NULL) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
75 _handles = new(_arena) GrowableArray<T>(_arena, 10, 0, 0); |
0 | 76 _no_finds = new(_arena) GrowableArray<int>( _arena, 10, 0, 0); |
77 } else { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
78 _handles = new GrowableArray<T>(10, 0, 0); |
0 | 79 _no_finds = new GrowableArray<int>( 10, 0, 0); |
80 } | |
81 } | |
82 } | |
83 | |
84 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
85 template <class T> T ValueRecorder<T>::at(int index) { |
0 | 86 // there is always a NULL virtually present as first object |
87 if (index == null_index) return NULL; | |
88 return _handles->at(index - first_index); | |
89 } | |
90 | |
91 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
92 template <class T> int ValueRecorder<T>::add_handle(T h, bool make_findable) { |
0 | 93 assert(!_complete, "cannot allocate more elements after size query"); |
94 maybe_initialize(); | |
95 // indexing uses 1 as an origin--0 means null | |
96 int index = _handles->length() + first_index; | |
97 _handles->append(h); | |
98 | |
99 // Support correct operation of find_index(). | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
100 assert(!(make_findable && !is_real(h)), "nulls are not findable"); |
0 | 101 if (make_findable) { |
102 // This index may be returned from find_index(). | |
103 if (_indexes != NULL) { | |
104 int* cloc = _indexes->cache_location(h); | |
105 _indexes->set_cache_location_index(cloc, index); | |
106 } 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
|
107 _indexes = new(_arena) IndexCache<T>(); |
0 | 108 for (int i = 0; i < _handles->length(); i++) { |
109 // Load the cache with pre-existing elements. | |
110 int index0 = i + first_index; | |
111 if (_no_finds->contains(index0)) continue; | |
112 int* cloc = _indexes->cache_location(_handles->at(i)); | |
113 _indexes->set_cache_location_index(cloc, index0); | |
114 } | |
115 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
116 } else if (is_real(h)) { |
0 | 117 // Remember that this index is not to be returned from find_index(). |
118 // 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
|
119 // an argument of NULL or Universe::non_oop_word. |
0 | 120 // Thus, the expected length of _no_finds is zero. |
121 _no_finds->append(index); | |
122 } | |
123 | |
124 return index; | |
125 } | |
126 | |
127 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
128 template <class T> int ValueRecorder<T>::maybe_find_index(T h) { |
0 | 129 debug_only(_find_index_calls++); |
130 assert(!_complete, "cannot allocate more elements after size query"); | |
131 maybe_initialize(); | |
132 if (h == NULL) return null_index; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
133 assert(is_real(h), "must be valid"); |
0 | 134 int* cloc = (_indexes == NULL)? NULL: _indexes->cache_location(h); |
135 if (cloc != NULL) { | |
136 int cindex = _indexes->cache_location_index(cloc); | |
137 if (cindex == 0) { | |
138 return -1; // We know this handle is completely new. | |
139 } | |
140 if (cindex >= first_index && _handles->at(cindex - first_index) == h) { | |
141 debug_only(_hit_indexes++); | |
142 return cindex; | |
143 } | |
144 if (!_indexes->cache_location_collision(cloc)) { | |
145 return -1; // We know the current cache occupant is unique to that cloc. | |
146 } | |
147 } | |
148 | |
149 // Not found in cache, due to a cache collision. (Or, no cache at all.) | |
150 // Do a linear search, most recent to oldest. | |
151 for (int i = _handles->length() - 1; i >= 0; i--) { | |
152 if (_handles->at(i) == h) { | |
153 int findex = i + first_index; | |
154 if (_no_finds->contains(findex)) continue; // oops; skip this one | |
155 if (cloc != NULL) { | |
156 _indexes->set_cache_location_index(cloc, findex); | |
157 } | |
158 debug_only(_missed_indexes++); | |
159 return findex; | |
160 } | |
161 } | |
162 return -1; | |
163 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
164 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
165 // Explicitly instantiate these types |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
166 template class ValueRecorder<Metadata*>; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
167 template class ValueRecorder<jobject>; |
17375
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
168 |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
169 oop ObjectLookup::ObjectEntry::oop_value() { return JNIHandles::resolve(_value); } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
170 |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
171 ObjectLookup::ObjectLookup(): _gc_count(Universe::heap()->total_collections()), _values(4) {} |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
172 |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
173 void ObjectLookup::maybe_resort() { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
174 // The values are kept sorted by address which may be invalidated |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
175 // after a GC, so resort if a GC has occurred since last time. |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
176 if (_gc_count != Universe::heap()->total_collections()) { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
177 _gc_count = Universe::heap()->total_collections(); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
178 _values.sort(sort_by_address); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
179 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
180 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
181 |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
182 int ObjectLookup::sort_by_address(oop a, oop b) { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
183 if (b > a) return 1; |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
184 if (a > b) return -1; |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
185 return 0; |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
186 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
187 |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
188 int ObjectLookup::sort_by_address(ObjectEntry* a, ObjectEntry* b) { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
189 return sort_by_address(a->oop_value(), b->oop_value()); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
190 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
191 |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
192 int ObjectLookup::sort_oop_by_address(oop a, ObjectEntry b) { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
193 return sort_by_address(a, b.oop_value()); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
194 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
195 |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
196 int ObjectLookup::find_index(jobject handle, OopRecorder* oop_recorder) { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
197 if (handle == NULL) { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
198 return 0; |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
199 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
200 oop object = JNIHandles::resolve(handle); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
201 maybe_resort(); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
202 bool found; |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
203 int location = _values.find_binary<oop, sort_oop_by_address>(object, found); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
204 if (!found) { |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
205 assert(location <= _values.length(), "out of range"); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
206 jobject handle = JNIHandles::make_local(object); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
207 ObjectEntry r(handle, oop_recorder->allocate_oop_index(handle)); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
208 _values.insert_binary(location, r); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
209 return r.index(); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
210 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
211 return _values.at(location).index(); |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
212 } |
44b83285b645
Deduplicate constant oops during code installation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
17374
diff
changeset
|
213 |