172 } |
172 } |
173 return map; |
173 return map; |
174 } |
174 } |
175 |
175 |
176 AOTOopRecorder::AOTOopRecorder(Arena* arena, bool deduplicate) : OopRecorder(arena, deduplicate) { |
176 AOTOopRecorder::AOTOopRecorder(Arena* arena, bool deduplicate) : OopRecorder(arena, deduplicate) { |
177 _meta_strings = new GrowableArray<const char*>(); |
177 _meta_refs = new GrowableArray<jobject>(); |
178 } |
178 } |
179 |
179 |
180 int AOTOopRecorder::nr_meta_strings() const { |
180 int AOTOopRecorder::nr_meta_refs() const { |
181 return _meta_strings->length(); |
181 return _meta_refs->length(); |
182 } |
182 } |
183 |
183 |
184 const char* AOTOopRecorder::meta_element(int pos) const { |
184 jobject AOTOopRecorder::meta_element(int pos) const { |
185 return _meta_strings->at(pos); |
185 return _meta_refs->at(pos); |
186 } |
186 } |
187 |
187 |
188 int AOTOopRecorder::find_index(Metadata* h) { |
188 int AOTOopRecorder::find_index(Metadata* h) { |
|
189 JavaThread* THREAD = JavaThread::current(); |
|
190 int oldCount = metadata_count(); |
189 int index = this->OopRecorder::find_index(h); |
191 int index = this->OopRecorder::find_index(h); |
|
192 int newCount = metadata_count(); |
|
193 |
|
194 if (oldCount == newCount) { |
|
195 // found a match |
|
196 return index; |
|
197 } |
|
198 |
|
199 vmassert(index + 1 == newCount, "must be last"); |
190 |
200 |
191 Klass* klass = NULL; |
201 Klass* klass = NULL; |
|
202 oop result = NULL; |
192 if (h->is_klass()) { |
203 if (h->is_klass()) { |
193 klass = (Klass*) h; |
204 klass = (Klass*) h; |
194 record_meta_string(klass->signature_name(), index); |
205 result = CompilerToVM::get_jvmci_type(klass, CATCH); |
195 } else if (h->is_method()) { |
206 } else if (h->is_method()) { |
196 Method* method = (Method*) h; |
207 Method* method = (Method*) h; |
197 // Need klass->signature_name() in method name |
208 methodHandle mh(method); |
198 klass = method->method_holder(); |
209 result = CompilerToVM::get_jvmci_method(method, CATCH); |
199 const char* klass_name = klass->signature_name(); |
210 } |
200 int klass_name_len = (int)strlen(klass_name); |
211 jobject ref = JNIHandles::make_local(THREAD, result); |
201 Symbol* method_name = method->name(); |
212 record_meta_ref(ref, index); |
202 Symbol* signature = method->signature(); |
|
203 int method_name_len = method_name->utf8_length(); |
|
204 int method_sign_len = signature->utf8_length(); |
|
205 int len = klass_name_len + 1 + method_name_len + method_sign_len; |
|
206 char* dest = NEW_RESOURCE_ARRAY(char, len + 1); |
|
207 strcpy(dest, klass_name); |
|
208 dest[klass_name_len] = '.'; |
|
209 strcpy(&dest[klass_name_len + 1], method_name->as_C_string()); |
|
210 strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string()); |
|
211 dest[len] = 0; |
|
212 record_meta_string(dest, index); |
|
213 } |
|
214 |
213 |
215 return index; |
214 return index; |
216 } |
215 } |
217 |
216 |
218 int AOTOopRecorder::find_index(jobject h) { |
217 int AOTOopRecorder::find_index(jobject h) { |
222 oop javaMirror = JNIHandles::resolve(h); |
221 oop javaMirror = JNIHandles::resolve(h); |
223 Klass* klass = java_lang_Class::as_Klass(javaMirror); |
222 Klass* klass = java_lang_Class::as_Klass(javaMirror); |
224 return find_index(klass); |
223 return find_index(klass); |
225 } |
224 } |
226 |
225 |
227 void AOTOopRecorder::record_meta_string(const char* name, int index) { |
226 void AOTOopRecorder::record_meta_ref(jobject o, int index) { |
228 assert(index > 0, "must be 1..n"); |
227 assert(index > 0, "must be 1..n"); |
229 index -= 1; // reduce by one to convert to array index |
228 index -= 1; // reduce by one to convert to array index |
230 |
229 |
231 if (index < _meta_strings->length()) { |
230 assert(index == _meta_refs->length(), "must be last"); |
232 assert(strcmp(name, _meta_strings->at(index)) == 0, "must match"); |
231 _meta_refs->append(o); |
233 } else { |
|
234 assert(index == _meta_strings->length(), "must be last"); |
|
235 _meta_strings->append(name); |
|
236 } |
|
237 } |
232 } |
238 |
233 |
239 void* CodeInstaller::record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS) { |
234 void* CodeInstaller::record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS) { |
240 /* |
235 /* |
241 * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base |
236 * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base |