src/share/vm/c1/c1_Runtime1.cpp

Print this page
rev 4136 : 7153771: array bound check elimination for c1
Summary: when possible optimize out array bound checks, inserting predicates when needed.
Reviewed-by:


1313   } else {
1314     bs->write_ref_array_pre((oop*)dst, num);
1315     Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num);
1316   }
1317   bs->write_ref_array(dst, num);
1318 JRT_END
1319 
1320 
1321 JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))
1322   // had to return int instead of bool, otherwise there may be a mismatch
1323   // between the C calling convention and the Java one.
1324   // e.g., on x86, GCC may clear only %al when returning a bool false, but
1325   // JVM takes the whole %eax as the return value, which may misinterpret
1326   // the return value as a boolean true.
1327 
1328   assert(mirror != NULL, "should null-check on mirror before calling");
1329   Klass* k = java_lang_Class::as_Klass(mirror);
1330   return (k != NULL && obj != NULL && obj->is_a(k)) ? 1 : 0;
1331 JRT_END
1332 












































1333 
1334 #ifndef PRODUCT
1335 void Runtime1::print_statistics() {
1336   tty->print_cr("C1 Runtime statistics:");
1337   tty->print_cr(" _resolve_invoke_virtual_cnt:     %d", SharedRuntime::_resolve_virtual_ctr);
1338   tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr);
1339   tty->print_cr(" _resolve_invoke_static_cnt:      %d", SharedRuntime::_resolve_static_ctr);
1340   tty->print_cr(" _handle_wrong_method_cnt:        %d", SharedRuntime::_wrong_method_ctr);
1341   tty->print_cr(" _ic_miss_cnt:                    %d", SharedRuntime::_ic_miss_ctr);
1342   tty->print_cr(" _generic_arraycopy_cnt:          %d", _generic_arraycopy_cnt);
1343   tty->print_cr(" _generic_arraycopystub_cnt:      %d", _generic_arraycopystub_cnt);
1344   tty->print_cr(" _byte_arraycopy_cnt:             %d", _byte_arraycopy_cnt);
1345   tty->print_cr(" _short_arraycopy_cnt:            %d", _short_arraycopy_cnt);
1346   tty->print_cr(" _int_arraycopy_cnt:              %d", _int_arraycopy_cnt);
1347   tty->print_cr(" _long_arraycopy_cnt:             %d", _long_arraycopy_cnt);
1348   tty->print_cr(" _primitive_arraycopy_cnt:        %d", _primitive_arraycopy_cnt);
1349   tty->print_cr(" _oop_arraycopy_cnt (C):          %d", Runtime1::_oop_arraycopy_cnt);
1350   tty->print_cr(" _oop_arraycopy_cnt (stub):       %d", _oop_arraycopy_cnt);
1351   tty->print_cr(" _arraycopy_slowcase_cnt:         %d", _arraycopy_slowcase_cnt);
1352   tty->print_cr(" _arraycopy_checkcast_cnt:        %d", _arraycopy_checkcast_cnt);




1313   } else {
1314     bs->write_ref_array_pre((oop*)dst, num);
1315     Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num);
1316   }
1317   bs->write_ref_array(dst, num);
1318 JRT_END
1319 
1320 
1321 JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))
1322   // had to return int instead of bool, otherwise there may be a mismatch
1323   // between the C calling convention and the Java one.
1324   // e.g., on x86, GCC may clear only %al when returning a bool false, but
1325   // JVM takes the whole %eax as the return value, which may misinterpret
1326   // the return value as a boolean true.
1327 
1328   assert(mirror != NULL, "should null-check on mirror before calling");
1329   Klass* k = java_lang_Class::as_Klass(mirror);
1330   return (k != NULL && obj != NULL && obj->is_a(k)) ? 1 : 0;
1331 JRT_END
1332 
1333 JRT_ENTRY(void, Runtime1::predicate_failed_trap(JavaThread* thread))
1334   ResourceMark rm;
1335 
1336   assert(!TieredCompilation, "incompatible with tiered compilation");
1337 
1338   RegisterMap reg_map(thread, false);
1339   frame runtime_frame = thread->last_frame();
1340   frame caller_frame = runtime_frame.sender(&reg_map);
1341 
1342   nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1343   assert (nm != NULL, "no more nmethod?");
1344   nm->make_not_entrant();
1345 
1346   methodHandle m(nm->method());
1347   MethodData* mdo = m->method_data();  
1348   
1349   if (mdo == NULL && !HAS_PENDING_EXCEPTION) {
1350     // Build an MDO.  Ignore errors like OutOfMemory;
1351     // that simply means we won't have an MDO to update.
1352     Method::build_interpreter_method_data(m, THREAD);
1353     if (HAS_PENDING_EXCEPTION) {
1354       assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
1355       CLEAR_PENDING_EXCEPTION;
1356     }
1357     mdo = m->method_data();
1358   }
1359 
1360   if (mdo != NULL) {
1361     mdo->inc_trap_count(Deoptimization::Reason_none);
1362   }
1363 
1364   if (TracePredicateFailedTraps) {
1365     stringStream ss1, ss2;
1366     vframeStream vfst(thread);
1367     methodHandle inlinee = methodHandle(vfst.method());
1368     inlinee->print_short_name(&ss1);
1369     m->print_short_name(&ss2);
1370     tty->print_cr("Predicate failed trap in method %s at bci %d inlined in %s at pc %x", ss1.as_string(), vfst.bci(), ss2.as_string(), caller_frame.pc());
1371   }
1372 
1373 
1374   Deoptimization::deoptimize_frame(thread, caller_frame.id());
1375 
1376 JRT_END
1377 
1378 #ifndef PRODUCT
1379 void Runtime1::print_statistics() {
1380   tty->print_cr("C1 Runtime statistics:");
1381   tty->print_cr(" _resolve_invoke_virtual_cnt:     %d", SharedRuntime::_resolve_virtual_ctr);
1382   tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr);
1383   tty->print_cr(" _resolve_invoke_static_cnt:      %d", SharedRuntime::_resolve_static_ctr);
1384   tty->print_cr(" _handle_wrong_method_cnt:        %d", SharedRuntime::_wrong_method_ctr);
1385   tty->print_cr(" _ic_miss_cnt:                    %d", SharedRuntime::_ic_miss_ctr);
1386   tty->print_cr(" _generic_arraycopy_cnt:          %d", _generic_arraycopy_cnt);
1387   tty->print_cr(" _generic_arraycopystub_cnt:      %d", _generic_arraycopystub_cnt);
1388   tty->print_cr(" _byte_arraycopy_cnt:             %d", _byte_arraycopy_cnt);
1389   tty->print_cr(" _short_arraycopy_cnt:            %d", _short_arraycopy_cnt);
1390   tty->print_cr(" _int_arraycopy_cnt:              %d", _int_arraycopy_cnt);
1391   tty->print_cr(" _long_arraycopy_cnt:             %d", _long_arraycopy_cnt);
1392   tty->print_cr(" _primitive_arraycopy_cnt:        %d", _primitive_arraycopy_cnt);
1393   tty->print_cr(" _oop_arraycopy_cnt (C):          %d", Runtime1::_oop_arraycopy_cnt);
1394   tty->print_cr(" _oop_arraycopy_cnt (stub):       %d", _oop_arraycopy_cnt);
1395   tty->print_cr(" _arraycopy_slowcase_cnt:         %d", _arraycopy_slowcase_cnt);
1396   tty->print_cr(" _arraycopy_checkcast_cnt:        %d", _arraycopy_checkcast_cnt);