comparison src/share/vm/opto/compile.cpp @ 859:ea3f9723b5cf

6860599: nodes limit could be reached during Output phase Summary: Bailout compilation if nodes limit could be reached during Output phase. Reviewed-by: never, twisti
author kvn
date Thu, 23 Jul 2009 14:53:56 -0700
parents 75596850f863
children 046932b72aa2
comparison
equal deleted inserted replaced
858:5314d85ffd54 859:ea3f9723b5cf
439 _code_buffer("Compile::Fill_buffer"), 439 _code_buffer("Compile::Fill_buffer"),
440 _orig_pc_slot(0), 440 _orig_pc_slot(0),
441 _orig_pc_slot_offset_in_bytes(0), 441 _orig_pc_slot_offset_in_bytes(0),
442 _node_bundling_limit(0), 442 _node_bundling_limit(0),
443 _node_bundling_base(NULL), 443 _node_bundling_base(NULL),
444 _java_calls(0),
445 _inner_loops(0),
444 #ifndef PRODUCT 446 #ifndef PRODUCT
445 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")), 447 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")),
446 _printer(IdealGraphPrinter::printer()), 448 _printer(IdealGraphPrinter::printer()),
447 #endif 449 #endif
448 _congraph(NULL) { 450 _congraph(NULL) {
709 _do_escape_analysis(false), 711 _do_escape_analysis(false),
710 _failure_reason(NULL), 712 _failure_reason(NULL),
711 _code_buffer("Compile::Fill_buffer"), 713 _code_buffer("Compile::Fill_buffer"),
712 _node_bundling_limit(0), 714 _node_bundling_limit(0),
713 _node_bundling_base(NULL), 715 _node_bundling_base(NULL),
716 _java_calls(0),
717 _inner_loops(0),
714 #ifndef PRODUCT 718 #ifndef PRODUCT
715 _trace_opto_output(TraceOptoOutput), 719 _trace_opto_output(TraceOptoOutput),
716 _printer(NULL), 720 _printer(NULL),
717 #endif 721 #endif
718 _congraph(NULL) { 722 _congraph(NULL) {
1849 struct Final_Reshape_Counts : public StackObj { 1853 struct Final_Reshape_Counts : public StackObj {
1850 int _call_count; // count non-inlined 'common' calls 1854 int _call_count; // count non-inlined 'common' calls
1851 int _float_count; // count float ops requiring 24-bit precision 1855 int _float_count; // count float ops requiring 24-bit precision
1852 int _double_count; // count double ops requiring more precision 1856 int _double_count; // count double ops requiring more precision
1853 int _java_call_count; // count non-inlined 'java' calls 1857 int _java_call_count; // count non-inlined 'java' calls
1858 int _inner_loop_count; // count loops which need alignment
1854 VectorSet _visited; // Visitation flags 1859 VectorSet _visited; // Visitation flags
1855 Node_List _tests; // Set of IfNodes & PCTableNodes 1860 Node_List _tests; // Set of IfNodes & PCTableNodes
1856 1861
1857 Final_Reshape_Counts() : 1862 Final_Reshape_Counts() :
1858 _call_count(0), _float_count(0), _double_count(0), _java_call_count(0), 1863 _call_count(0), _float_count(0), _double_count(0),
1864 _java_call_count(0), _inner_loop_count(0),
1859 _visited( Thread::current()->resource_area() ) { } 1865 _visited( Thread::current()->resource_area() ) { }
1860 1866
1861 void inc_call_count () { _call_count ++; } 1867 void inc_call_count () { _call_count ++; }
1862 void inc_float_count () { _float_count ++; } 1868 void inc_float_count () { _float_count ++; }
1863 void inc_double_count() { _double_count++; } 1869 void inc_double_count() { _double_count++; }
1864 void inc_java_call_count() { _java_call_count++; } 1870 void inc_java_call_count() { _java_call_count++; }
1871 void inc_inner_loop_count() { _inner_loop_count++; }
1865 1872
1866 int get_call_count () const { return _call_count ; } 1873 int get_call_count () const { return _call_count ; }
1867 int get_float_count () const { return _float_count ; } 1874 int get_float_count () const { return _float_count ; }
1868 int get_double_count() const { return _double_count; } 1875 int get_double_count() const { return _double_count; }
1869 int get_java_call_count() const { return _java_call_count; } 1876 int get_java_call_count() const { return _java_call_count; }
1877 int get_inner_loop_count() const { return _inner_loop_count; }
1870 }; 1878 };
1871 1879
1872 static bool oop_offset_is_sane(const TypeInstPtr* tp) { 1880 static bool oop_offset_is_sane(const TypeInstPtr* tp) {
1873 ciInstanceKlass *k = tp->klass()->as_instance_klass(); 1881 ciInstanceKlass *k = tp->klass()->as_instance_klass();
1874 // Make sure the offset goes inside the instance layout. 1882 // Make sure the offset goes inside the instance layout.
1876 // Note that OffsetBot and OffsetTop are very negative. 1884 // Note that OffsetBot and OffsetTop are very negative.
1877 } 1885 }
1878 1886
1879 //------------------------------final_graph_reshaping_impl---------------------- 1887 //------------------------------final_graph_reshaping_impl----------------------
1880 // Implement items 1-5 from final_graph_reshaping below. 1888 // Implement items 1-5 from final_graph_reshaping below.
1881 static void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &fpu ) { 1889 static void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc ) {
1882 1890
1883 if ( n->outcnt() == 0 ) return; // dead node 1891 if ( n->outcnt() == 0 ) return; // dead node
1884 uint nop = n->Opcode(); 1892 uint nop = n->Opcode();
1885 1893
1886 // Check for 2-input instruction with "last use" on right input. 1894 // Check for 2-input instruction with "last use" on right input.
1918 case Op_ConvI2F: 1926 case Op_ConvI2F:
1919 case Op_ConF: 1927 case Op_ConF:
1920 case Op_CmpF: 1928 case Op_CmpF:
1921 case Op_CmpF3: 1929 case Op_CmpF3:
1922 // case Op_ConvL2F: // longs are split into 32-bit halves 1930 // case Op_ConvL2F: // longs are split into 32-bit halves
1923 fpu.inc_float_count(); 1931 frc.inc_float_count();
1924 break; 1932 break;
1925 1933
1926 case Op_ConvF2D: 1934 case Op_ConvF2D:
1927 case Op_ConvD2F: 1935 case Op_ConvD2F:
1928 fpu.inc_float_count(); 1936 frc.inc_float_count();
1929 fpu.inc_double_count(); 1937 frc.inc_double_count();
1930 break; 1938 break;
1931 1939
1932 // Count all double operations that may use FPU 1940 // Count all double operations that may use FPU
1933 case Op_AddD: 1941 case Op_AddD:
1934 case Op_SubD: 1942 case Op_SubD:
1941 // case Op_ConvL2D: // handled by leaf call 1949 // case Op_ConvL2D: // handled by leaf call
1942 // case Op_ConvD2L: // handled by leaf call 1950 // case Op_ConvD2L: // handled by leaf call
1943 case Op_ConD: 1951 case Op_ConD:
1944 case Op_CmpD: 1952 case Op_CmpD:
1945 case Op_CmpD3: 1953 case Op_CmpD3:
1946 fpu.inc_double_count(); 1954 frc.inc_double_count();
1947 break; 1955 break;
1948 case Op_Opaque1: // Remove Opaque Nodes before matching 1956 case Op_Opaque1: // Remove Opaque Nodes before matching
1949 case Op_Opaque2: // Remove Opaque Nodes before matching 1957 case Op_Opaque2: // Remove Opaque Nodes before matching
1950 n->subsume_by(n->in(1)); 1958 n->subsume_by(n->in(1));
1951 break; 1959 break;
1952 case Op_CallStaticJava: 1960 case Op_CallStaticJava:
1953 case Op_CallJava: 1961 case Op_CallJava:
1954 case Op_CallDynamicJava: 1962 case Op_CallDynamicJava:
1955 fpu.inc_java_call_count(); // Count java call site; 1963 frc.inc_java_call_count(); // Count java call site;
1956 case Op_CallRuntime: 1964 case Op_CallRuntime:
1957 case Op_CallLeaf: 1965 case Op_CallLeaf:
1958 case Op_CallLeafNoFP: { 1966 case Op_CallLeafNoFP: {
1959 assert( n->is_Call(), "" ); 1967 assert( n->is_Call(), "" );
1960 CallNode *call = n->as_Call(); 1968 CallNode *call = n->as_Call();
1961 // Count call sites where the FP mode bit would have to be flipped. 1969 // Count call sites where the FP mode bit would have to be flipped.
1962 // Do not count uncommon runtime calls: 1970 // Do not count uncommon runtime calls:
1963 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking, 1971 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
1964 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ... 1972 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
1965 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) { 1973 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
1966 fpu.inc_call_count(); // Count the call site 1974 frc.inc_call_count(); // Count the call site
1967 } else { // See if uncommon argument is shared 1975 } else { // See if uncommon argument is shared
1968 Node *n = call->in(TypeFunc::Parms); 1976 Node *n = call->in(TypeFunc::Parms);
1969 int nop = n->Opcode(); 1977 int nop = n->Opcode();
1970 // Clone shared simple arguments to uncommon calls, item (1). 1978 // Clone shared simple arguments to uncommon calls, item (1).
1971 if( n->outcnt() > 1 && 1979 if( n->outcnt() > 1 &&
1982 } 1990 }
1983 1991
1984 case Op_StoreD: 1992 case Op_StoreD:
1985 case Op_LoadD: 1993 case Op_LoadD:
1986 case Op_LoadD_unaligned: 1994 case Op_LoadD_unaligned:
1987 fpu.inc_double_count(); 1995 frc.inc_double_count();
1988 goto handle_mem; 1996 goto handle_mem;
1989 case Op_StoreF: 1997 case Op_StoreF:
1990 case Op_LoadF: 1998 case Op_LoadF:
1991 fpu.inc_float_count(); 1999 frc.inc_float_count();
1992 goto handle_mem; 2000 goto handle_mem;
1993 2001
1994 case Op_StoreB: 2002 case Op_StoreB:
1995 case Op_StoreC: 2003 case Op_StoreC:
1996 case Op_StoreCM: 2004 case Op_StoreCM:
2323 PackNode* p = (PackNode*) n; 2331 PackNode* p = (PackNode*) n;
2324 Node* btp = p->binaryTreePack(Compile::current(), 1, n->req()); 2332 Node* btp = p->binaryTreePack(Compile::current(), 1, n->req());
2325 n->subsume_by(btp); 2333 n->subsume_by(btp);
2326 } 2334 }
2327 break; 2335 break;
2336 case Op_Loop:
2337 case Op_CountedLoop:
2338 if (n->as_Loop()->is_inner_loop()) {
2339 frc.inc_inner_loop_count();
2340 }
2341 break;
2328 default: 2342 default:
2329 assert( !n->is_Call(), "" ); 2343 assert( !n->is_Call(), "" );
2330 assert( !n->is_Mem(), "" ); 2344 assert( !n->is_Mem(), "" );
2331 break; 2345 break;
2332 } 2346 }
2333 2347
2334 // Collect CFG split points 2348 // Collect CFG split points
2335 if (n->is_MultiBranch()) 2349 if (n->is_MultiBranch())
2336 fpu._tests.push(n); 2350 frc._tests.push(n);
2337 } 2351 }
2338 2352
2339 //------------------------------final_graph_reshaping_walk--------------------- 2353 //------------------------------final_graph_reshaping_walk---------------------
2340 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(), 2354 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
2341 // requires that the walk visits a node's inputs before visiting the node. 2355 // requires that the walk visits a node's inputs before visiting the node.
2342 static void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &fpu ) { 2356 static void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
2343 ResourceArea *area = Thread::current()->resource_area(); 2357 ResourceArea *area = Thread::current()->resource_area();
2344 Unique_Node_List sfpt(area); 2358 Unique_Node_List sfpt(area);
2345 2359
2346 fpu._visited.set(root->_idx); // first, mark node as visited 2360 frc._visited.set(root->_idx); // first, mark node as visited
2347 uint cnt = root->req(); 2361 uint cnt = root->req();
2348 Node *n = root; 2362 Node *n = root;
2349 uint i = 0; 2363 uint i = 0;
2350 while (true) { 2364 while (true) {
2351 if (i < cnt) { 2365 if (i < cnt) {
2352 // Place all non-visited non-null inputs onto stack 2366 // Place all non-visited non-null inputs onto stack
2353 Node* m = n->in(i); 2367 Node* m = n->in(i);
2354 ++i; 2368 ++i;
2355 if (m != NULL && !fpu._visited.test_set(m->_idx)) { 2369 if (m != NULL && !frc._visited.test_set(m->_idx)) {
2356 if (m->is_SafePoint() && m->as_SafePoint()->jvms() != NULL) 2370 if (m->is_SafePoint() && m->as_SafePoint()->jvms() != NULL)
2357 sfpt.push(m); 2371 sfpt.push(m);
2358 cnt = m->req(); 2372 cnt = m->req();
2359 nstack.push(n, i); // put on stack parent and next input's index 2373 nstack.push(n, i); // put on stack parent and next input's index
2360 n = m; 2374 n = m;
2361 i = 0; 2375 i = 0;
2362 } 2376 }
2363 } else { 2377 } else {
2364 // Now do post-visit work 2378 // Now do post-visit work
2365 final_graph_reshaping_impl( n, fpu ); 2379 final_graph_reshaping_impl( n, frc );
2366 if (nstack.is_empty()) 2380 if (nstack.is_empty())
2367 break; // finished 2381 break; // finished
2368 n = nstack.node(); // Get node from stack 2382 n = nstack.node(); // Get node from stack
2369 cnt = n->req(); 2383 cnt = n->req();
2370 i = nstack.index(); 2384 i = nstack.index();
2441 if (root()->req() == 1) { 2455 if (root()->req() == 1) {
2442 record_method_not_compilable("trivial infinite loop"); 2456 record_method_not_compilable("trivial infinite loop");
2443 return true; 2457 return true;
2444 } 2458 }
2445 2459
2446 Final_Reshape_Counts fpu; 2460 Final_Reshape_Counts frc;
2447 2461
2448 // Visit everybody reachable! 2462 // Visit everybody reachable!
2449 // Allocate stack of size C->unique()/2 to avoid frequent realloc 2463 // Allocate stack of size C->unique()/2 to avoid frequent realloc
2450 Node_Stack nstack(unique() >> 1); 2464 Node_Stack nstack(unique() >> 1);
2451 final_graph_reshaping_walk(nstack, root(), fpu); 2465 final_graph_reshaping_walk(nstack, root(), frc);
2452 2466
2453 // Check for unreachable (from below) code (i.e., infinite loops). 2467 // Check for unreachable (from below) code (i.e., infinite loops).
2454 for( uint i = 0; i < fpu._tests.size(); i++ ) { 2468 for( uint i = 0; i < frc._tests.size(); i++ ) {
2455 MultiBranchNode *n = fpu._tests[i]->as_MultiBranch(); 2469 MultiBranchNode *n = frc._tests[i]->as_MultiBranch();
2456 // Get number of CFG targets. 2470 // Get number of CFG targets.
2457 // Note that PCTables include exception targets after calls. 2471 // Note that PCTables include exception targets after calls.
2458 uint required_outcnt = n->required_outcnt(); 2472 uint required_outcnt = n->required_outcnt();
2459 if (n->outcnt() != required_outcnt) { 2473 if (n->outcnt() != required_outcnt) {
2460 // Check for a few special cases. Rethrow Nodes never take the 2474 // Check for a few special cases. Rethrow Nodes never take the
2496 } 2510 }
2497 } 2511 }
2498 // Check that I actually visited all kids. Unreached kids 2512 // Check that I actually visited all kids. Unreached kids
2499 // must be infinite loops. 2513 // must be infinite loops.
2500 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) 2514 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++)
2501 if (!fpu._visited.test(n->fast_out(j)->_idx)) { 2515 if (!frc._visited.test(n->fast_out(j)->_idx)) {
2502 record_method_not_compilable("infinite loop"); 2516 record_method_not_compilable("infinite loop");
2503 return true; // Found unvisited kid; must be unreach 2517 return true; // Found unvisited kid; must be unreach
2504 } 2518 }
2505 } 2519 }
2506 2520
2507 // If original bytecodes contained a mixture of floats and doubles 2521 // If original bytecodes contained a mixture of floats and doubles
2508 // check if the optimizer has made it homogenous, item (3). 2522 // check if the optimizer has made it homogenous, item (3).
2509 if( Use24BitFPMode && Use24BitFP && 2523 if( Use24BitFPMode && Use24BitFP &&
2510 fpu.get_float_count() > 32 && 2524 frc.get_float_count() > 32 &&
2511 fpu.get_double_count() == 0 && 2525 frc.get_double_count() == 0 &&
2512 (10 * fpu.get_call_count() < fpu.get_float_count()) ) { 2526 (10 * frc.get_call_count() < frc.get_float_count()) ) {
2513 set_24_bit_selection_and_mode( false, true ); 2527 set_24_bit_selection_and_mode( false, true );
2514 } 2528 }
2515 2529
2516 set_has_java_calls(fpu.get_java_call_count() > 0); 2530 set_java_calls(frc.get_java_call_count());
2531 set_inner_loops(frc.get_inner_loop_count());
2517 2532
2518 // No infinite loops, no reason to bail out. 2533 // No infinite loops, no reason to bail out.
2519 return false; 2534 return false;
2520 } 2535 }
2521 2536