1281 prob = (0+PROB_MIN) / 2;
1282 else if( !not_taken )
1283 prob = (1+PROB_MAX) / 2;
1284 else { // Compute probability of true path
1285 prob = (float)taken / (float)(taken + not_taken);
1286 if (prob > PROB_MAX) prob = PROB_MAX;
1287 if (prob < PROB_MIN) prob = PROB_MIN;
1288 }
1289
1290 assert((cnt > 0.0f) && (prob > 0.0f),
1291 "Bad frequency assignment in if cnt=%g prob=%g taken=%d not_taken=%d", cnt, prob, taken, not_taken);
1292
1293 if (C->log() != nullptr) {
1294 const char* prob_str = nullptr;
1295 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always";
1296 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never";
1297 char prob_str_buf[30];
1298 if (prob_str == nullptr) {
1299 jio_snprintf(prob_str_buf, sizeof(prob_str_buf), "%20.2f", prob);
1300 prob_str = prob_str_buf;
1301 }
1302 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%f' prob='%s'",
1303 iter().get_dest(), taken, not_taken, cnt, prob_str);
1304 }
1305 return prob;
1306 }
1307
1308 //-----------------------------branch_prediction-------------------------------
1309 float Parse::branch_prediction(float& cnt,
1310 BoolTest::mask btest,
1311 int target_bci,
1312 Node* test) {
1313 float prob = dynamic_branch_prediction(cnt, btest, test);
1314 // If prob is unknown, switch to static prediction
1315 if (prob != PROB_UNKNOWN) return prob;
1316
1317 prob = PROB_FAIR; // Set default value
1318 if (btest == BoolTest::eq) // Exactly equal test?
1319 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent
1320 else if (btest == BoolTest::ne)
1359 }
1360
1361 //-------------------------------repush_if_args--------------------------------
1362 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp.
1363 inline int Parse::repush_if_args() {
1364 if (PrintOpto && WizardMode) {
1365 tty->print("defending against excessive implicit null exceptions on %s @%d in ",
1366 Bytecodes::name(iter().cur_bc()), iter().cur_bci());
1367 method()->print_name(); tty->cr();
1368 }
1369 int bc_depth = - Bytecodes::depth(iter().cur_bc());
1370 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
1371 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms
1372 assert(argument(0) != nullptr, "must exist");
1373 assert(bc_depth == 1 || argument(1) != nullptr, "two must exist");
1374 inc_sp(bc_depth);
1375 return bc_depth;
1376 }
1377
1378 // Used by StressUnstableIfTraps
1379 static volatile int _trap_stress_counter = 0;
1380
1381 void Parse::increment_trap_stress_counter(Node*& counter, Node*& incr_store) {
1382 Node* counter_addr = makecon(TypeRawPtr::make((address)&_trap_stress_counter));
1383 counter = make_load(control(), counter_addr, TypeInt::INT, T_INT, MemNode::unordered);
1384 counter = _gvn.transform(new AddINode(counter, intcon(1)));
1385 incr_store = store_to_memory(control(), counter_addr, counter, T_INT, MemNode::unordered);
1386 }
1387
1388 //----------------------------------do_ifnull----------------------------------
1389 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
1390 int target_bci = iter().get_dest();
1391
1392 Node* counter = nullptr;
1393 Node* incr_store = nullptr;
1394 bool do_stress_trap = StressUnstableIfTraps && ((C->random() % 2) == 0);
1395 if (do_stress_trap) {
1396 increment_trap_stress_counter(counter, incr_store);
1397 }
1398
1399 Block* branch_block = successor_for_bci(target_bci);
|
1281 prob = (0+PROB_MIN) / 2;
1282 else if( !not_taken )
1283 prob = (1+PROB_MAX) / 2;
1284 else { // Compute probability of true path
1285 prob = (float)taken / (float)(taken + not_taken);
1286 if (prob > PROB_MAX) prob = PROB_MAX;
1287 if (prob < PROB_MIN) prob = PROB_MIN;
1288 }
1289
1290 assert((cnt > 0.0f) && (prob > 0.0f),
1291 "Bad frequency assignment in if cnt=%g prob=%g taken=%d not_taken=%d", cnt, prob, taken, not_taken);
1292
1293 if (C->log() != nullptr) {
1294 const char* prob_str = nullptr;
1295 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always";
1296 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never";
1297 char prob_str_buf[30];
1298 if (prob_str == nullptr) {
1299 jio_snprintf(prob_str_buf, sizeof(prob_str_buf), "%20.2f", prob);
1300 prob_str = prob_str_buf;
1301 // The %20.2f adds many spaces to the string, to avoid some
1302 // picky overflow warning as noted in 8211929. But, 20 is the
1303 // *minimum* width, not *maximum*, so it's not clear how this
1304 // helps prevent overflow. Looks like we were forced to work
1305 // around a bug in gcc. In any case, strip the blanks.
1306 while (*prob_str == ' ') ++prob_str;
1307 }
1308 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%f' prob='%s'",
1309 iter().get_dest(), taken, not_taken, cnt, prob_str);
1310 }
1311 return prob;
1312 }
1313
1314 //-----------------------------branch_prediction-------------------------------
1315 float Parse::branch_prediction(float& cnt,
1316 BoolTest::mask btest,
1317 int target_bci,
1318 Node* test) {
1319 float prob = dynamic_branch_prediction(cnt, btest, test);
1320 // If prob is unknown, switch to static prediction
1321 if (prob != PROB_UNKNOWN) return prob;
1322
1323 prob = PROB_FAIR; // Set default value
1324 if (btest == BoolTest::eq) // Exactly equal test?
1325 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent
1326 else if (btest == BoolTest::ne)
1365 }
1366
1367 //-------------------------------repush_if_args--------------------------------
1368 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp.
1369 inline int Parse::repush_if_args() {
1370 if (PrintOpto && WizardMode) {
1371 tty->print("defending against excessive implicit null exceptions on %s @%d in ",
1372 Bytecodes::name(iter().cur_bc()), iter().cur_bci());
1373 method()->print_name(); tty->cr();
1374 }
1375 int bc_depth = - Bytecodes::depth(iter().cur_bc());
1376 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
1377 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms
1378 assert(argument(0) != nullptr, "must exist");
1379 assert(bc_depth == 1 || argument(1) != nullptr, "two must exist");
1380 inc_sp(bc_depth);
1381 return bc_depth;
1382 }
1383
1384 // Used by StressUnstableIfTraps
1385 volatile int Parse::_trap_stress_counter = 0;
1386
1387 void Parse::increment_trap_stress_counter(Node*& counter, Node*& incr_store) {
1388 Node* counter_addr = makecon(TypeRawPtr::make((address)&_trap_stress_counter));
1389 counter = make_load(control(), counter_addr, TypeInt::INT, T_INT, MemNode::unordered);
1390 counter = _gvn.transform(new AddINode(counter, intcon(1)));
1391 incr_store = store_to_memory(control(), counter_addr, counter, T_INT, MemNode::unordered);
1392 }
1393
1394 //----------------------------------do_ifnull----------------------------------
1395 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
1396 int target_bci = iter().get_dest();
1397
1398 Node* counter = nullptr;
1399 Node* incr_store = nullptr;
1400 bool do_stress_trap = StressUnstableIfTraps && ((C->random() % 2) == 0);
1401 if (do_stress_trap) {
1402 increment_trap_stress_counter(counter, incr_store);
1403 }
1404
1405 Block* branch_block = successor_for_bci(target_bci);
|