Mercurial > hg > truffle
comparison src/share/vm/opto/gcm.cpp @ 14909:4ca6dc0799b6
Backout jdk9 merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 01 Apr 2014 13:57:07 +0200 |
parents | 1077c8270209 |
children | 89152779163c |
comparison
equal
deleted
inserted
replaced
14908:8db6e76cb658 | 14909:4ca6dc0799b6 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
48 # include "adfiles/ad_zero.hpp" | 48 # include "adfiles/ad_zero.hpp" |
49 #endif | 49 #endif |
50 #ifdef TARGET_ARCH_MODEL_arm | 50 #ifdef TARGET_ARCH_MODEL_arm |
51 # include "adfiles/ad_arm.hpp" | 51 # include "adfiles/ad_arm.hpp" |
52 #endif | 52 #endif |
53 #ifdef TARGET_ARCH_MODEL_ppc_32 | 53 #ifdef TARGET_ARCH_MODEL_ppc |
54 # include "adfiles/ad_ppc_32.hpp" | 54 # include "adfiles/ad_ppc.hpp" |
55 #endif | 55 #endif |
56 #ifdef TARGET_ARCH_MODEL_ppc_64 | |
57 # include "adfiles/ad_ppc_64.hpp" | |
58 #endif | |
59 | |
60 | 56 |
61 // Portions of code courtesy of Clifford Click | 57 // Portions of code courtesy of Clifford Click |
62 | 58 |
63 // Optimization - Graph Style | 59 // Optimization - Graph Style |
64 | 60 |
1328 | 1324 |
1329 // Detect implicit-null-check opportunities. Basically, find NULL checks | 1325 // Detect implicit-null-check opportunities. Basically, find NULL checks |
1330 // with suitable memory ops nearby. Use the memory op to do the NULL check. | 1326 // with suitable memory ops nearby. Use the memory op to do the NULL check. |
1331 // I can generate a memory op if there is not one nearby. | 1327 // I can generate a memory op if there is not one nearby. |
1332 if (C->is_method_compilation()) { | 1328 if (C->is_method_compilation()) { |
1329 // Don't do it for natives, adapters, or runtime stubs | |
1330 int allowed_reasons = 0; | |
1331 // ...and don't do it when there have been too many traps, globally. | |
1332 for (int reason = (int)Deoptimization::Reason_none+1; | |
1333 reason < Compile::trapHistLength; reason++) { | |
1334 assert(reason < BitsPerInt, "recode bit map"); | |
1335 if (!C->too_many_traps((Deoptimization::DeoptReason) reason)) | |
1336 allowed_reasons |= nth_bit(reason); | |
1337 } | |
1333 // By reversing the loop direction we get a very minor gain on mpegaudio. | 1338 // By reversing the loop direction we get a very minor gain on mpegaudio. |
1334 // Feel free to revert to a forward loop for clarity. | 1339 // Feel free to revert to a forward loop for clarity. |
1335 // for( int i=0; i < (int)matcher._null_check_tests.size(); i+=2 ) { | 1340 // for( int i=0; i < (int)matcher._null_check_tests.size(); i+=2 ) { |
1336 for (int i = _matcher._null_check_tests.size() - 2; i >= 0; i -= 2) { | 1341 for (int i = _matcher._null_check_tests.size() - 2; i >= 0; i -= 2) { |
1337 Node* proj = _matcher._null_check_tests[i]; | 1342 Node* proj = _matcher._null_check_tests[i]; |
1338 Node* val = _matcher._null_check_tests[i + 1]; | 1343 Node* val = _matcher._null_check_tests[i + 1]; |
1339 Block* block = get_block_for_node(proj); | 1344 Block* block = get_block_for_node(proj); |
1340 implicit_null_check(block, proj, val, C->allowed_deopt_reasons()); | 1345 implicit_null_check(block, proj, val, allowed_reasons); |
1341 // The implicit_null_check will only perform the transformation | 1346 // The implicit_null_check will only perform the transformation |
1342 // if the null branch is truly uncommon, *and* it leads to an | 1347 // if the null branch is truly uncommon, *and* it leads to an |
1343 // uncommon trap. Combined with the too_many_traps guards | 1348 // uncommon trap. Combined with the too_many_traps guards |
1344 // above, this prevents SEGV storms reported in 6366351, | 1349 // above, this prevents SEGV storms reported in 6366351, |
1345 // by recompiling offending methods without this optimization. | 1350 // by recompiling offending methods without this optimization. |
1659 ch->compute_freq(); | 1664 ch->compute_freq(); |
1660 ch = ch->_sibling; | 1665 ch = ch->_sibling; |
1661 } | 1666 } |
1662 assert (_members.length() > 0, "no empty loops"); | 1667 assert (_members.length() > 0, "no empty loops"); |
1663 Block* hd = head(); | 1668 Block* hd = head(); |
1664 hd->_freq = 1.0; | 1669 hd->_freq = 1.0f; |
1665 for (int i = 0; i < _members.length(); i++) { | 1670 for (int i = 0; i < _members.length(); i++) { |
1666 CFGElement* s = _members.at(i); | 1671 CFGElement* s = _members.at(i); |
1667 double freq = s->_freq; | 1672 float freq = s->_freq; |
1668 if (s->is_block()) { | 1673 if (s->is_block()) { |
1669 Block* b = s->as_Block(); | 1674 Block* b = s->as_Block(); |
1670 for (uint j = 0; j < b->_num_succs; j++) { | 1675 for (uint j = 0; j < b->_num_succs; j++) { |
1671 Block* sb = b->_succs[j]; | 1676 Block* sb = b->_succs[j]; |
1672 update_succ_freq(sb, freq * b->succ_prob(j)); | 1677 update_succ_freq(sb, freq * b->succ_prob(j)); |
1674 } else { | 1679 } else { |
1675 CFGLoop* lp = s->as_CFGLoop(); | 1680 CFGLoop* lp = s->as_CFGLoop(); |
1676 assert(lp->_parent == this, "immediate child"); | 1681 assert(lp->_parent == this, "immediate child"); |
1677 for (int k = 0; k < lp->_exits.length(); k++) { | 1682 for (int k = 0; k < lp->_exits.length(); k++) { |
1678 Block* eb = lp->_exits.at(k).get_target(); | 1683 Block* eb = lp->_exits.at(k).get_target(); |
1679 double prob = lp->_exits.at(k).get_prob(); | 1684 float prob = lp->_exits.at(k).get_prob(); |
1680 update_succ_freq(eb, freq * prob); | 1685 update_succ_freq(eb, freq * prob); |
1681 } | 1686 } |
1682 } | 1687 } |
1683 } | 1688 } |
1684 | 1689 |
1686 // sum and normalize the exit probability. The "method" loop | 1691 // sum and normalize the exit probability. The "method" loop |
1687 // should keep the initial exit probability of 1, so that | 1692 // should keep the initial exit probability of 1, so that |
1688 // inner blocks do not get erroneously scaled. | 1693 // inner blocks do not get erroneously scaled. |
1689 if (_depth != 0) { | 1694 if (_depth != 0) { |
1690 // Total the exit probabilities for this loop. | 1695 // Total the exit probabilities for this loop. |
1691 double exits_sum = 0.0f; | 1696 float exits_sum = 0.0f; |
1692 for (int i = 0; i < _exits.length(); i++) { | 1697 for (int i = 0; i < _exits.length(); i++) { |
1693 exits_sum += _exits.at(i).get_prob(); | 1698 exits_sum += _exits.at(i).get_prob(); |
1694 } | 1699 } |
1695 | 1700 |
1696 // Normalize the exit probabilities. Until now, the | 1701 // Normalize the exit probabilities. Until now, the |
1933 } | 1938 } |
1934 | 1939 |
1935 //------------------------------update_succ_freq------------------------------- | 1940 //------------------------------update_succ_freq------------------------------- |
1936 // Update the appropriate frequency associated with block 'b', a successor of | 1941 // Update the appropriate frequency associated with block 'b', a successor of |
1937 // a block in this loop. | 1942 // a block in this loop. |
1938 void CFGLoop::update_succ_freq(Block* b, double freq) { | 1943 void CFGLoop::update_succ_freq(Block* b, float freq) { |
1939 if (b->_loop == this) { | 1944 if (b->_loop == this) { |
1940 if (b == head()) { | 1945 if (b == head()) { |
1941 // back branch within the loop | 1946 // back branch within the loop |
1942 // Do nothing now, the loop carried frequency will be | 1947 // Do nothing now, the loop carried frequency will be |
1943 // adjust later in scale_freq(). | 1948 // adjust later in scale_freq(). |
1974 | 1979 |
1975 //------------------------------scale_freq------------------------------------- | 1980 //------------------------------scale_freq------------------------------------- |
1976 // Scale frequency of loops and blocks by trip counts from outer loops | 1981 // Scale frequency of loops and blocks by trip counts from outer loops |
1977 // Do a top down traversal of loop tree (visit outer loops first.) | 1982 // Do a top down traversal of loop tree (visit outer loops first.) |
1978 void CFGLoop::scale_freq() { | 1983 void CFGLoop::scale_freq() { |
1979 double loop_freq = _freq * trip_count(); | 1984 float loop_freq = _freq * trip_count(); |
1980 _freq = loop_freq; | 1985 _freq = loop_freq; |
1981 for (int i = 0; i < _members.length(); i++) { | 1986 for (int i = 0; i < _members.length(); i++) { |
1982 CFGElement* s = _members.at(i); | 1987 CFGElement* s = _members.at(i); |
1983 double block_freq = s->_freq * loop_freq; | 1988 float block_freq = s->_freq * loop_freq; |
1984 if (g_isnan(block_freq) || block_freq < MIN_BLOCK_FREQUENCY) | 1989 if (g_isnan(block_freq) || block_freq < MIN_BLOCK_FREQUENCY) |
1985 block_freq = MIN_BLOCK_FREQUENCY; | 1990 block_freq = MIN_BLOCK_FREQUENCY; |
1986 s->_freq = block_freq; | 1991 s->_freq = block_freq; |
1987 } | 1992 } |
1988 CFGLoop* ch = _child; | 1993 CFGLoop* ch = _child; |
1991 ch = ch->_sibling; | 1996 ch = ch->_sibling; |
1992 } | 1997 } |
1993 } | 1998 } |
1994 | 1999 |
1995 // Frequency of outer loop | 2000 // Frequency of outer loop |
1996 double CFGLoop::outer_loop_freq() const { | 2001 float CFGLoop::outer_loop_freq() const { |
1997 if (_child != NULL) { | 2002 if (_child != NULL) { |
1998 return _child->_freq; | 2003 return _child->_freq; |
1999 } | 2004 } |
2000 return _freq; | 2005 return _freq; |
2001 } | 2006 } |
2040 tty->print("\n "); | 2045 tty->print("\n "); |
2041 for (int j = 0; j < _depth+1; j++) tty->print(" "); | 2046 for (int j = 0; j < _depth+1; j++) tty->print(" "); |
2042 k = 0; | 2047 k = 0; |
2043 } | 2048 } |
2044 Block *blk = _exits.at(i).get_target(); | 2049 Block *blk = _exits.at(i).get_target(); |
2045 double prob = _exits.at(i).get_prob(); | 2050 float prob = _exits.at(i).get_prob(); |
2046 tty->print(" ->%d@%d%%", blk->_pre_order, (int)(prob*100)); | 2051 tty->print(" ->%d@%d%%", blk->_pre_order, (int)(prob*100)); |
2047 } | 2052 } |
2048 tty->print("\n"); | 2053 tty->print("\n"); |
2049 } | 2054 } |
2050 #endif | 2055 #endif |