140 141 // Not found in cache, due to a cache collision. (Or, no cache at all.) 142 // Do a linear search, most recent to oldest. 143 for (int i = _handles->length() - 1; i >= 0; i--) { 144 if (_handles->at(i) == h) { 145 int findex = i + first_index; 146 if (_no_finds->contains(findex)) continue; // oops; skip this one 147 if (cloc != NULL) { 148 _indexes->set_cache_location_index(cloc, findex); 149 } 150 debug_only(_missed_indexes++); 151 return findex; 152 } 153 } 154 return -1; 155 } 156 157 // Explicitly instantiate these types 158 template class ValueRecorder<Metadata*>; 159 template class ValueRecorder<jobject>; | 140 141 // Not found in cache, due to a cache collision. (Or, no cache at all.) 142 // Do a linear search, most recent to oldest. 143 for (int i = _handles->length() - 1; i >= 0; i--) { 144 if (_handles->at(i) == h) { 145 int findex = i + first_index; 146 if (_no_finds->contains(findex)) continue; // oops; skip this one 147 if (cloc != NULL) { 148 _indexes->set_cache_location_index(cloc, findex); 149 } 150 debug_only(_missed_indexes++); 151 return findex; 152 } 153 } 154 return -1; 155 } 156 157 // Explicitly instantiate these types 158 template class ValueRecorder<Metadata*>; 159 template class ValueRecorder<jobject>; 160 161 oop ObjectLookup::ObjectEntry::oop_value() const { return JNIHandles::resolve(_value); } 162 163 ObjectLookup::ObjectLookup(): _gc_count(Universe::heap()->total_collections()), _values(4) {} 164 165 void ObjectLookup::maybe_resort() { 166 // The values are kept sorted by address which may be invalidated 167 // after a GC, so resort if a GC has occurred since last time. 168 if (_gc_count != Universe::heap()->total_collections()) { 169 _gc_count = Universe::heap()->total_collections(); 170 _values.sort(sort_by_address); 171 } 172 } 173 174 int ObjectLookup::sort_by_address(oop a, oop b) { 175 if (b > a) return 1; 176 if (a > b) return -1; 177 return 0; 178 } 179 180 int ObjectLookup::sort_by_address(ObjectEntry* a, ObjectEntry* b) { 181 return sort_by_address(a->oop_value(), b->oop_value()); 182 } 183 184 int ObjectLookup::sort_oop_by_address(oop const& a, ObjectEntry const& b) { 185 return sort_by_address(a, b.oop_value()); 186 } 187 188 int ObjectLookup::find_index(jobject handle, OopRecorder* oop_recorder) { 189 if (handle == NULL) { 190 return 0; 191 } 192 oop object = JNIHandles::resolve(handle); 193 maybe_resort(); 194 bool found; 195 int location = _values.find_sorted<oop, sort_oop_by_address>(object, found); 196 if (!found) { 197 jobject handle = JNIHandles::make_local(object); 198 ObjectEntry r(handle, oop_recorder->allocate_oop_index(handle)); 199 _values.insert_before(location, r); 200 return r.index(); 201 } 202 return _values.at(location).index(); 203 } 204 |