Mercurial > hg > graal-compiler
comparison src/share/vm/code/oopRecorder.hpp @ 17377: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
17376:9928ad27a80e | 17377:44b83285b645 |
---|---|
144 #ifdef ASSERT | 144 #ifdef ASSERT |
145 static int _find_index_calls, _hit_indexes, _missed_indexes; | 145 static int _find_index_calls, _hit_indexes, _missed_indexes; |
146 #endif | 146 #endif |
147 }; | 147 }; |
148 | 148 |
149 class OopRecorder; | |
150 | |
151 class ObjectLookup : public ResourceObj { | |
152 private: | |
153 class ObjectEntry { | |
154 private: | |
155 jobject _value; | |
156 int _index; | |
157 | |
158 public: | |
159 ObjectEntry(jobject value, int index): _value(value), _index(index) {} | |
160 ObjectEntry() {} | |
161 oop oop_value(); // { return JNIHandles::resolve(_value); } | |
162 int index() { return _index; } | |
163 }; | |
164 | |
165 GrowableArray<ObjectEntry> _values; | |
166 unsigned int _gc_count; | |
167 | |
168 // Utility sort functions | |
169 static int sort_by_address(oop a, oop b); | |
170 static int sort_by_address(ObjectEntry* a, ObjectEntry* b); | |
171 static int sort_oop_by_address(oop a, ObjectEntry b); | |
172 | |
173 public: | |
174 ObjectLookup(); | |
175 | |
176 // Resort list if a GC has occurred since the last sort | |
177 void maybe_resort(); | |
178 int find_index(jobject object, OopRecorder* oop_recorder); | |
179 }; | |
180 | |
149 class OopRecorder : public ResourceObj { | 181 class OopRecorder : public ResourceObj { |
150 private: | 182 private: |
151 ValueRecorder<jobject> _oops; | 183 ValueRecorder<jobject> _oops; |
152 ValueRecorder<Metadata*> _metadata; | 184 ValueRecorder<Metadata*> _metadata; |
185 ObjectLookup* _object_lookup; | |
153 public: | 186 public: |
154 OopRecorder(Arena* arena = NULL): _oops(arena), _metadata(arena) {} | 187 OopRecorder(Arena* arena = NULL, bool deduplicate = false): _oops(arena), _metadata(arena) { |
188 if (deduplicate) { | |
189 _object_lookup = new ObjectLookup(); | |
190 } else { | |
191 _object_lookup = NULL; | |
192 } | |
193 } | |
155 | 194 |
156 void check_for_duplicates(int index, jobject h) NOT_DEBUG_RETURN; | 195 void check_for_duplicates(int index, jobject h) NOT_DEBUG_RETURN; |
157 | 196 |
158 int allocate_oop_index(jobject h) { | 197 int allocate_oop_index(jobject h) { |
159 return _oops.allocate_index(h); | 198 return _oops.allocate_index(h); |
160 } | 199 } |
161 int find_index(jobject h) { | 200 int find_index(jobject h) { |
162 int result = _oops.find_index(h); | 201 int result = _object_lookup != NULL ? _object_lookup->find_index(h, this) : _oops.find_index(h); |
163 check_for_duplicates(result, h); | 202 check_for_duplicates(result, h); |
164 return result; | 203 return result; |
165 } | 204 } |
166 jobject oop_at(int index) { | 205 jobject oop_at(int index) { |
167 return _oops.at(index); | 206 return _oops.at(index); |