comparison src/share/vm/code/oopRecorder.cpp @ 17375:44b83285b645

Deduplicate constant oops during code installation
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 08 Oct 2014 11:50:00 -0700
parents 9928ad27a80e
children 50942f016967
comparison
equal deleted inserted replaced
17374:9928ad27a80e 17375:44b83285b645
163 } 163 }
164 164
165 // Explicitly instantiate these types 165 // Explicitly instantiate these types
166 template class ValueRecorder<Metadata*>; 166 template class ValueRecorder<Metadata*>;
167 template class ValueRecorder<jobject>; 167 template class ValueRecorder<jobject>;
168
169 oop ObjectLookup::ObjectEntry::oop_value() { return JNIHandles::resolve(_value); }
170
171 ObjectLookup::ObjectLookup(): _gc_count(Universe::heap()->total_collections()), _values(4) {}
172
173 void ObjectLookup::maybe_resort() {
174 // The values are kept sorted by address which may be invalidated
175 // after a GC, so resort if a GC has occurred since last time.
176 if (_gc_count != Universe::heap()->total_collections()) {
177 _gc_count = Universe::heap()->total_collections();
178 _values.sort(sort_by_address);
179 }
180 }
181
182 int ObjectLookup::sort_by_address(oop a, oop b) {
183 if (b > a) return 1;
184 if (a > b) return -1;
185 return 0;
186 }
187
188 int ObjectLookup::sort_by_address(ObjectEntry* a, ObjectEntry* b) {
189 return sort_by_address(a->oop_value(), b->oop_value());
190 }
191
192 int ObjectLookup::sort_oop_by_address(oop a, ObjectEntry b) {
193 return sort_by_address(a, b.oop_value());
194 }
195
196 int ObjectLookup::find_index(jobject handle, OopRecorder* oop_recorder) {
197 if (handle == NULL) {
198 return 0;
199 }
200 oop object = JNIHandles::resolve(handle);
201 maybe_resort();
202 bool found;
203 int location = _values.find_binary<oop, sort_oop_by_address>(object, found);
204 if (!found) {
205 assert(location <= _values.length(), "out of range");
206 jobject handle = JNIHandles::make_local(object);
207 ObjectEntry r(handle, oop_recorder->allocate_oop_index(handle));
208 _values.insert_binary(location, r);
209 return r.index();
210 }
211 return _values.at(location).index();
212 }
213