src/share/vm/opto/macro.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 8031320_8u Sdiff src/share/vm/opto

src/share/vm/opto/macro.cpp

Print this page
rev 5968 : 8031320: Use Intel RTM instructions for locks
Summary: Use RTM for inflated locks and stack locks.
Reviewed-by: iveresov, twisti, roland, dcubed


2420       // Before elimination mark all associated (same box and obj)
2421       // lock and unlock nodes.
2422       mark_eliminated_locking_nodes(n->as_AbstractLock());
2423     }
2424   }
2425   bool progress = true;
2426   while (progress) {
2427     progress = false;
2428     for (int i = C->macro_count(); i > 0; i--) {
2429       Node * n = C->macro_node(i-1);
2430       bool success = false;
2431       debug_only(int old_macro_count = C->macro_count(););
2432       if (n->is_AbstractLock()) {
2433         success = eliminate_locking_node(n->as_AbstractLock());
2434       }
2435       assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2436       progress = progress || success;
2437     }
2438   }
2439   // Next, attempt to eliminate allocations

2440   progress = true;
2441   while (progress) {
2442     progress = false;
2443     for (int i = C->macro_count(); i > 0; i--) {
2444       Node * n = C->macro_node(i-1);
2445       bool success = false;
2446       debug_only(int old_macro_count = C->macro_count(););
2447       switch (n->class_id()) {
2448       case Node::Class_Allocate:
2449       case Node::Class_AllocateArray:
2450         success = eliminate_allocate_node(n->as_Allocate());
2451         break;
2452       case Node::Class_CallStaticJava:
2453         success = eliminate_boxing_node(n->as_CallStaticJava());
2454         break;
2455       case Node::Class_Lock:
2456       case Node::Class_Unlock:
2457         assert(!n->as_AbstractLock()->is_eliminated(), "sanity");

2458         break;
2459       default:
2460         assert(n->Opcode() == Op_LoopLimit ||
2461                n->Opcode() == Op_Opaque1   ||
2462                n->Opcode() == Op_Opaque2, "unknown node type in macro list");

2463       }
2464       assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2465       progress = progress || success;
2466     }
2467   }
2468 }
2469 
2470 //------------------------------expand_macro_nodes----------------------
2471 //  Returns true if a failure occurred.
2472 bool PhaseMacroExpand::expand_macro_nodes() {
2473   // Last attempt to eliminate macro nodes.
2474   eliminate_macro_nodes();
2475 
2476   // Make sure expansion will not cause node limit to be exceeded.
2477   // Worst case is a macro node gets expanded into about 50 nodes.
2478   // Allow 50% more for optimization.
2479   if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
2480     return true;
2481 
2482   // Eliminate Opaque and LoopLimit nodes. Do it after all loop optimizations.
2483   bool progress = true;
2484   while (progress) {
2485     progress = false;
2486     for (int i = C->macro_count(); i > 0; i--) {
2487       Node * n = C->macro_node(i-1);
2488       bool success = false;
2489       debug_only(int old_macro_count = C->macro_count(););
2490       if (n->Opcode() == Op_LoopLimit) {
2491         // Remove it from macro list and put on IGVN worklist to optimize.
2492         C->remove_macro_node(n);
2493         _igvn._worklist.push(n);
2494         success = true;
2495       } else if (n->Opcode() == Op_CallStaticJava) {
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_Opaque1 || n->Opcode() == Op_Opaque2) {
2501         _igvn.replace_node(n, n->in(1));
2502         success = true;
























2503       }
2504       assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2505       progress = progress || success;
2506     }
2507   }
2508 
2509   // expand "macro" nodes
2510   // nodes are removed from the macro list as they are processed
2511   while (C->macro_count() > 0) {
2512     int macro_count = C->macro_count();
2513     Node * n = C->macro_node(macro_count-1);
2514     assert(n->is_macro(), "only macro nodes expected here");
2515     if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
2516       // node is unreachable, so don't try to expand it
2517       C->remove_macro_node(n);
2518       continue;
2519     }
2520     switch (n->class_id()) {
2521     case Node::Class_Allocate:
2522       expand_allocate(n->as_Allocate());




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


src/share/vm/opto/macro.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File