Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalVMEntries.cpp @ 3570:da1b32a58d7e
Merge.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Fri, 02 Sep 2011 18:29:16 +0200 |
parents | 76a7f1732bb0 dbf8d6a4201f |
children | a72615456c50 |
comparison
equal
deleted
inserted
replaced
3569:76a7f1732bb0 | 3570:da1b32a58d7e |
---|---|
212 } | 212 } |
213 | 213 |
214 // public native int RiMethod_exceptionProbability(long vmId, int bci); | 214 // public native int RiMethod_exceptionProbability(long vmId, int bci); |
215 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_2exceptionProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 215 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_2exceptionProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
216 TRACE_graal_3("VMEntries::RiMethod_exceptionProbability"); | 216 TRACE_graal_3("VMEntries::RiMethod_exceptionProbability"); |
217 ciMethod* cimethod; | |
218 { | 217 { |
219 VM_ENTRY_MARK; | 218 VM_ENTRY_MARK; |
220 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | 219 methodOop method = getMethodFromHotSpotMethod(hotspot_method); |
221 cimethod = (ciMethod*)CURRENT_ENV->get_object(method); | 220 methodDataOop method_data = method->method_data(); |
222 } | 221 if (method_data == NULL || !method_data->is_mature()) { |
223 ciMethodData* method_data = cimethod->method_data(); | 222 return -1; |
224 | 223 } |
225 if (method_data == NULL || !method_data->is_mature()) return -1; | 224 ProfileData* data = method_data->bci_to_data(bci); |
226 | 225 if (data == NULL) { |
227 ciProfileData* profile = method_data->bci_to_data(bci); | 226 return 0; |
228 if (profile == NULL) { | 227 } |
229 return 0; | 228 uint trap = Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0; |
230 } | 229 if (trap > 0) { |
231 uint trap = method_data->trap_recompiled_at(profile); | 230 return 100; |
232 if (trap > 0) { | 231 } else { |
233 return 100; | 232 return trap; |
234 } else { | 233 } |
235 return trap; | 234 } |
236 } | 235 } |
236 | |
237 // ------------------------------------------------------------------ | |
238 // Adjust a CounterData count to be commensurate with | |
239 // interpreter_invocation_count. If the MDO exists for | |
240 // only 25% of the time the method exists, then the | |
241 // counts in the MDO should be scaled by 4X, so that | |
242 // they can be usefully and stably compared against the | |
243 // invocation counts in methods. | |
244 int scale_count(methodDataOop method_data, int count) { | |
245 if (count > 0) { | |
246 int counter_life; | |
247 int method_life = method_data->method()->interpreter_invocation_count(); | |
248 int current_mileage = methodDataOopDesc::mileage_of(method_data->method()); | |
249 int creation_mileage = method_data->creation_mileage(); | |
250 counter_life = current_mileage - creation_mileage; | |
251 | |
252 // counter_life due to backedge_counter could be > method_life | |
253 if (counter_life > method_life) | |
254 counter_life = method_life; | |
255 if (0 < counter_life && counter_life <= method_life) { | |
256 count = (int)((double)count * method_life / counter_life + 0.5); | |
257 count = (count > 0) ? count : 1; | |
258 } | |
259 } | |
260 return count; | |
237 } | 261 } |
238 | 262 |
239 // public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); | 263 // public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); |
240 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 264 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
241 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | 265 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); |
242 ciMethod* cimethod; | |
243 { | |
244 VM_ENTRY_MARK; | |
245 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | |
246 cimethod = (ciMethod*)CURRENT_ENV->get_object(method); | |
247 } | |
248 | |
249 ciCallProfile profile = cimethod->call_profile_at_bci(bci); | |
250 | |
251 Handle obj; | 266 Handle obj; |
252 { | 267 { |
253 VM_ENTRY_MARK; | 268 VM_ENTRY_MARK; |
254 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); | 269 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
255 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); | 270 if (strstr(method->name_and_sig_as_C_string(), "factor") != NULL) { |
256 assert(obj() != NULL, "must succeed in allocating instance"); | 271 // tty->print_cr("here"); |
257 | 272 } |
258 RiTypeProfile::set_count(obj, cimethod->scale_count(profile.count(), 1)); | 273 if (bci == 123) { |
259 RiTypeProfile::set_morphism(obj, profile.morphism()); | 274 // tty->print_cr("here2"); |
260 | 275 } |
261 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, profile.limit(), CHECK_NULL); | 276 methodDataHandle method_data = method->method_data(); |
262 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), profile.limit(), CHECK_NULL); | 277 if (method_data == NULL || !method_data->is_mature()) { |
263 for (int i=0; i<profile.limit(); i++) { | 278 return NULL; |
264 float prob = profile.receiver_prob(i); | 279 } |
265 ciKlass* receiver = profile.receiver(i); | 280 ProfileData* data = method_data->bci_to_data(bci); |
266 oop type = GraalCompiler::get_RiType(receiver, KlassHandle(), CHECK_NULL); | 281 if (data != NULL && data->is_ReceiverTypeData()) { |
267 | 282 ReceiverTypeData* recv = data->as_ReceiverTypeData(); |
268 probabilities->float_at_put(i, prob); | 283 // determine morphism |
269 types->obj_at_put(i, type); | 284 int morphism = 0; |
270 } | 285 uint total_count = 0; |
271 | 286 for (uint i = 0; i < recv->row_limit(); i++) { |
272 RiTypeProfile::set_probabilities(obj, probabilities()); | 287 klassOop receiver = recv->receiver(i); |
273 RiTypeProfile::set_types(obj, types()); | 288 if (receiver == NULL) continue; |
274 | 289 morphism++; |
290 total_count += recv->receiver_count(i); | |
291 } | |
292 | |
293 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); | |
294 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); | |
295 assert(obj() != NULL, "must succeed in allocating instance"); | |
296 | |
297 int count = MAX2(total_count, recv->count()); | |
298 RiTypeProfile::set_count(obj, scale_count(method_data(), count)); | |
299 RiTypeProfile::set_morphism(obj, morphism); | |
300 | |
301 if (morphism > 0) { | |
302 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, morphism, CHECK_NULL); | |
303 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), morphism, CHECK_NULL); | |
304 int pos = 0; | |
305 for (uint i = 0; i < recv->row_limit(); i++) { | |
306 KlassHandle receiver = recv->receiver(i); | |
307 if (receiver.is_null()) continue; | |
308 | |
309 float prob = recv->receiver_count(i) / (float) total_count; | |
310 oop type = GraalCompiler::get_RiType(receiver, KlassHandle(), CHECK_NULL); | |
311 | |
312 probabilities->float_at_put(pos, prob); | |
313 types->obj_at_put(pos, type); | |
314 | |
315 pos++; | |
316 } | |
317 | |
318 RiTypeProfile::set_probabilities(obj, probabilities()); | |
319 RiTypeProfile::set_types(obj, types()); | |
320 } else { | |
321 RiTypeProfile::set_probabilities(obj, NULL); | |
322 RiTypeProfile::set_types(obj, NULL); | |
323 } | |
324 } | |
275 } | 325 } |
276 | 326 |
277 return JNIHandles::make_local(obj()); | 327 return JNIHandles::make_local(obj()); |
278 } | 328 } |
279 | 329 |