1282 NamedCounter* c = _named_counters;
1283 while (c) {
1284 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1285 int count = c->count();
1286 if (count > 0) {
1287 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1288 if (Verbose) {
1289 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1290 }
1291 total_lock_count += count;
1292 if (eliminated) {
1293 eliminated_lock_count += count;
1294 }
1295 }
1296 } else if (c->tag() == NamedCounter::BiasedLockingCounter) {
1297 BiasedLockingCounters* blc = ((BiasedLockingNamedCounter*)c)->counters();
1298 if (blc->nonzero()) {
1299 tty->print_cr("%s", c->name());
1300 blc->print_on(tty);
1301 }
1302 }
1303 c = c->next();
1304 }
1305 if (total_lock_count > 0) {
1306 tty->print_cr("dynamic locks: %d", total_lock_count);
1307 if (eliminated_lock_count) {
1308 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1309 (int)(eliminated_lock_count * 100.0 / total_lock_count));
1310 }
1311 }
1312 }
1313
1314 //
1315 // Allocate a new NamedCounter. The JVMState is used to generate the
1316 // name which consists of method@line for the inlining tree.
1317 //
1318
1319 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1320 int max_depth = youngest_jvms->depth();
1321
1322 // Visit scopes from youngest to oldest.
1323 bool first = true;
1324 stringStream st;
1325 for (int depth = max_depth; depth >= 1; depth--) {
1326 JVMState* jvms = youngest_jvms->of_depth(depth);
1327 ciMethod* m = jvms->has_method() ? jvms->method() : NULL;
1328 if (!first) {
1329 st.print(" ");
1330 } else {
1331 first = false;
1332 }
1333 int bci = jvms->bci();
1334 if (bci < 0) bci = 0;
1335 st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
1336 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1337 }
1338 NamedCounter* c;
1339 if (tag == NamedCounter::BiasedLockingCounter) {
1340 c = new BiasedLockingNamedCounter(strdup(st.as_string()));
1341 } else {
1342 c = new NamedCounter(strdup(st.as_string()), tag);
1343 }
1344
1345 // atomically add the new counter to the head of the list. We only
1346 // add counters so this is safe.
1347 NamedCounter* head;
1348 do {
1349 head = _named_counters;
1350 c->set_next(head);
1351 } while (Atomic::cmpxchg_ptr(c, &_named_counters, head) != head);
1352 return c;
1353 }
1354
1355 //-----------------------------------------------------------------------------
1356 // Non-product code
1357 #ifndef PRODUCT
1358
1359 int trace_exception_counter = 0;
1360 static void trace_exception(oop exception_oop, address exception_pc, const char* msg) {
1361 ttyLocker ttyl;
1362 trace_exception_counter++;
1363 tty->print("%d [Exception (%s): ", trace_exception_counter, msg);
1364 exception_oop->print_value();
1365 tty->print(" in ");
1366 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1367 if (blob->is_nmethod()) {
1368 nmethod* nm = blob->as_nmethod_or_null();
|
1282 NamedCounter* c = _named_counters;
1283 while (c) {
1284 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1285 int count = c->count();
1286 if (count > 0) {
1287 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1288 if (Verbose) {
1289 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1290 }
1291 total_lock_count += count;
1292 if (eliminated) {
1293 eliminated_lock_count += count;
1294 }
1295 }
1296 } else if (c->tag() == NamedCounter::BiasedLockingCounter) {
1297 BiasedLockingCounters* blc = ((BiasedLockingNamedCounter*)c)->counters();
1298 if (blc->nonzero()) {
1299 tty->print_cr("%s", c->name());
1300 blc->print_on(tty);
1301 }
1302 #if INCLUDE_RTM_OPT
1303 } else if (c->tag() == NamedCounter::RTMLockingCounter) {
1304 RTMLockingCounters* rlc = ((RTMLockingNamedCounter*)c)->counters();
1305 if (rlc->nonzero()) {
1306 tty->print_cr("%s", c->name());
1307 rlc->print_on(tty);
1308 }
1309 #endif
1310 }
1311 c = c->next();
1312 }
1313 if (total_lock_count > 0) {
1314 tty->print_cr("dynamic locks: %d", total_lock_count);
1315 if (eliminated_lock_count) {
1316 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1317 (int)(eliminated_lock_count * 100.0 / total_lock_count));
1318 }
1319 }
1320 }
1321
1322 //
1323 // Allocate a new NamedCounter. The JVMState is used to generate the
1324 // name which consists of method@line for the inlining tree.
1325 //
1326
1327 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1328 int max_depth = youngest_jvms->depth();
1329
1330 // Visit scopes from youngest to oldest.
1331 bool first = true;
1332 stringStream st;
1333 for (int depth = max_depth; depth >= 1; depth--) {
1334 JVMState* jvms = youngest_jvms->of_depth(depth);
1335 ciMethod* m = jvms->has_method() ? jvms->method() : NULL;
1336 if (!first) {
1337 st.print(" ");
1338 } else {
1339 first = false;
1340 }
1341 int bci = jvms->bci();
1342 if (bci < 0) bci = 0;
1343 st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
1344 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1345 }
1346 NamedCounter* c;
1347 if (tag == NamedCounter::BiasedLockingCounter) {
1348 c = new BiasedLockingNamedCounter(strdup(st.as_string()));
1349 } else if (tag == NamedCounter::RTMLockingCounter) {
1350 c = new RTMLockingNamedCounter(strdup(st.as_string()));
1351 } else {
1352 c = new NamedCounter(strdup(st.as_string()), tag);
1353 }
1354
1355 // atomically add the new counter to the head of the list. We only
1356 // add counters so this is safe.
1357 NamedCounter* head;
1358 do {
1359 c->set_next(NULL);
1360 head = _named_counters;
1361 c->set_next(head);
1362 } while (Atomic::cmpxchg_ptr(c, &_named_counters, head) != head);
1363 return c;
1364 }
1365
1366 //-----------------------------------------------------------------------------
1367 // Non-product code
1368 #ifndef PRODUCT
1369
1370 int trace_exception_counter = 0;
1371 static void trace_exception(oop exception_oop, address exception_pc, const char* msg) {
1372 ttyLocker ttyl;
1373 trace_exception_counter++;
1374 tty->print("%d [Exception (%s): ", trace_exception_counter, msg);
1375 exception_oop->print_value();
1376 tty->print(" in ");
1377 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1378 if (blob->is_nmethod()) {
1379 nmethod* nm = blob->as_nmethod_or_null();
|