2422 // Before elimination mark all associated (same box and obj)
2423 // lock and unlock nodes.
2424 mark_eliminated_locking_nodes(n->as_AbstractLock());
2425 }
2426 }
2427 bool progress = true;
2428 while (progress) {
2429 progress = false;
2430 for (int i = C->macro_count(); i > 0; i--) {
2431 Node * n = C->macro_node(i-1);
2432 bool success = false;
2433 debug_only(int old_macro_count = C->macro_count(););
2434 if (n->is_AbstractLock()) {
2435 success = eliminate_locking_node(n->as_AbstractLock());
2436 }
2437 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2438 progress = progress || success;
2439 }
2440 }
2441 // Next, attempt to eliminate allocations
2442 progress = true;
2443 while (progress) {
2444 progress = false;
2445 for (int i = C->macro_count(); i > 0; i--) {
2446 Node * n = C->macro_node(i-1);
2447 bool success = false;
2448 debug_only(int old_macro_count = C->macro_count(););
2449 switch (n->class_id()) {
2450 case Node::Class_Allocate:
2451 case Node::Class_AllocateArray:
2452 success = eliminate_allocate_node(n->as_Allocate());
2453 break;
2454 case Node::Class_CallStaticJava:
2455 success = eliminate_boxing_node(n->as_CallStaticJava());
2456 break;
2457 case Node::Class_Lock:
2458 case Node::Class_Unlock:
2459 assert(!n->as_AbstractLock()->is_eliminated(), "sanity");
2460 break;
2461 default:
2462 assert(n->Opcode() == Op_LoopLimit ||
2463 n->Opcode() == Op_Opaque1 ||
2464 n->Opcode() == Op_Opaque2, "unknown node type in macro list");
2465 }
2466 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2467 progress = progress || success;
2468 }
2469 }
2470 }
2471
2472 //------------------------------expand_macro_nodes----------------------
2473 // Returns true if a failure occurred.
2474 bool PhaseMacroExpand::expand_macro_nodes() {
2475 // Last attempt to eliminate macro nodes.
2476 eliminate_macro_nodes();
2477
2478 // Make sure expansion will not cause node limit to be exceeded.
2479 // Worst case is a macro node gets expanded into about 50 nodes.
2480 // Allow 50% more for optimization.
2481 if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
2482 return true;
2483
2484 // Eliminate Opaque and LoopLimit nodes. Do it after all loop optimizations.
2485 bool progress = true;
2486 while (progress) {
2487 progress = false;
2488 for (int i = C->macro_count(); i > 0; i--) {
2489 Node * n = C->macro_node(i-1);
2490 bool success = false;
2491 debug_only(int old_macro_count = C->macro_count(););
2492 if (n->Opcode() == Op_LoopLimit) {
2493 // Remove it from macro list and put on IGVN worklist to optimize.
2494 C->remove_macro_node(n);
2495 _igvn._worklist.push(n);
2496 success = true;
2497 } else if (n->Opcode() == Op_CallStaticJava) {
2498 // Remove it from macro list and put on IGVN worklist to optimize.
2499 C->remove_macro_node(n);
2500 _igvn._worklist.push(n);
2501 success = true;
2502 } else if (n->Opcode() == Op_Opaque1 || n->Opcode() == Op_Opaque2) {
2503 _igvn.replace_node(n, n->in(1));
2504 success = true;
2505 }
2506 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2507 progress = progress || success;
2508 }
2509 }
2510
2511 // expand "macro" nodes
2512 // nodes are removed from the macro list as they are processed
2513 while (C->macro_count() > 0) {
2514 int macro_count = C->macro_count();
2515 Node * n = C->macro_node(macro_count-1);
2516 assert(n->is_macro(), "only macro nodes expected here");
2517 if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
2518 // node is unreachable, so don't try to expand it
2519 C->remove_macro_node(n);
2520 continue;
2521 }
2522 switch (n->class_id()) {
2523 case Node::Class_Allocate:
2524 expand_allocate(n->as_Allocate());
|
2422 // Before elimination mark all associated (same box and obj)
2423 // lock and unlock nodes.
2424 mark_eliminated_locking_nodes(n->as_AbstractLock());
2425 }
2426 }
2427 bool progress = true;
2428 while (progress) {
2429 progress = false;
2430 for (int i = C->macro_count(); i > 0; i--) {
2431 Node * n = C->macro_node(i-1);
2432 bool success = false;
2433 debug_only(int old_macro_count = C->macro_count(););
2434 if (n->is_AbstractLock()) {
2435 success = eliminate_locking_node(n->as_AbstractLock());
2436 }
2437 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2438 progress = progress || success;
2439 }
2440 }
2441 // Next, attempt to eliminate allocations
2442 _has_locks = false;
2443 progress = true;
2444 while (progress) {
2445 progress = false;
2446 for (int i = C->macro_count(); i > 0; i--) {
2447 Node * n = C->macro_node(i-1);
2448 bool success = false;
2449 debug_only(int old_macro_count = C->macro_count(););
2450 switch (n->class_id()) {
2451 case Node::Class_Allocate:
2452 case Node::Class_AllocateArray:
2453 success = eliminate_allocate_node(n->as_Allocate());
2454 break;
2455 case Node::Class_CallStaticJava:
2456 success = eliminate_boxing_node(n->as_CallStaticJava());
2457 break;
2458 case Node::Class_Lock:
2459 case Node::Class_Unlock:
2460 assert(!n->as_AbstractLock()->is_eliminated(), "sanity");
2461 _has_locks = true;
2462 break;
2463 default:
2464 assert(n->Opcode() == Op_LoopLimit ||
2465 n->Opcode() == Op_Opaque1 ||
2466 n->Opcode() == Op_Opaque2 ||
2467 n->Opcode() == Op_Opaque3, "unknown node type in macro list");
2468 }
2469 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2470 progress = progress || success;
2471 }
2472 }
2473 }
2474
2475 //------------------------------expand_macro_nodes----------------------
2476 // Returns true if a failure occurred.
2477 bool PhaseMacroExpand::expand_macro_nodes() {
2478 // Last attempt to eliminate macro nodes.
2479 eliminate_macro_nodes();
2480
2481 // Make sure expansion will not cause node limit to be exceeded.
2482 // Worst case is a macro node gets expanded into about 50 nodes.
2483 // Allow 50% more for optimization.
2484 if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
2485 return true;
2486
2487 // Eliminate Opaque and LoopLimit nodes. Do it after all loop optimizations.
2488 bool progress = true;
2489 while (progress) {
2490 progress = false;
2491 for (int i = C->macro_count(); i > 0; i--) {
2492 Node * n = C->macro_node(i-1);
2493 bool success = false;
2494 debug_only(int old_macro_count = C->macro_count(););
2495 if (n->Opcode() == Op_LoopLimit) {
2496 // Remove it from macro list and put on IGVN worklist to optimize.
2497 C->remove_macro_node(n);
2498 _igvn._worklist.push(n);
2499 success = true;
2500 } else if (n->Opcode() == Op_CallStaticJava) {
2501 // Remove it from macro list and put on IGVN worklist to optimize.
2502 C->remove_macro_node(n);
2503 _igvn._worklist.push(n);
2504 success = true;
2505 } else if (n->Opcode() == Op_Opaque1 || n->Opcode() == Op_Opaque2) {
2506 _igvn.replace_node(n, n->in(1));
2507 success = true;
2508 #if INCLUDE_RTM_OPT
2509 } else if ((n->Opcode() == Op_Opaque3) && ((Opaque3Node*)n)->rtm_opt()) {
2510 assert(C->profile_rtm(), "only when rtm deop code is added");
2511 assert((n->outcnt() == 1) && n->unique_out()->is_Cmp(), "");
2512 Node* cmp = n->unique_out();
2513 #ifdef ASSERT
2514 // Validate graph.
2515 assert((cmp->outcnt() == 1) && cmp->unique_out()->is_Bool(), "");
2516 BoolNode* bol = cmp->unique_out()->as_Bool();
2517 assert((bol->outcnt() == 1) && bol->unique_out()->is_If() &&
2518 (bol->_test._test == BoolTest::ne), "");
2519 IfNode* ifn = bol->unique_out()->as_If();
2520 assert((ifn->outcnt() == 2) &&
2521 ifn->proj_out(1)->is_uncommon_trap_proj(Deoptimization::Reason_rtm_state_change), "");
2522 #endif
2523 Node* repl = n->in(1);
2524 if (!_has_locks) {
2525 // Remove RTM state check if there are no locks in the code.
2526 // Replace input to compare the same value.
2527 repl = (cmp->in(1) == n) ? cmp->in(2) : cmp->in(1);
2528 }
2529 _igvn.replace_node(n, repl);
2530 success = true;
2531 #endif
2532 }
2533 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2534 progress = progress || success;
2535 }
2536 }
2537
2538 // expand "macro" nodes
2539 // nodes are removed from the macro list as they are processed
2540 while (C->macro_count() > 0) {
2541 int macro_count = C->macro_count();
2542 Node * n = C->macro_node(macro_count-1);
2543 assert(n->is_macro(), "only macro nodes expected here");
2544 if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
2545 // node is unreachable, so don't try to expand it
2546 C->remove_macro_node(n);
2547 continue;
2548 }
2549 switch (n->class_id()) {
2550 case Node::Class_Allocate:
2551 expand_allocate(n->as_Allocate());
|