src/share/vm/opto/regalloc.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/opto/regalloc.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,130 @@
     1.4 +/*
     1.5 + * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "opto/regalloc.hpp"
    1.30 +
    1.31 +static const int NodeRegsOverflowSize = 200;
    1.32 +
    1.33 +void (*PhaseRegAlloc::_alloc_statistics[MAX_REG_ALLOCATORS])();
    1.34 +int PhaseRegAlloc::_num_allocators = 0;
    1.35 +#ifndef PRODUCT
    1.36 +int PhaseRegAlloc::_total_framesize = 0;
    1.37 +int PhaseRegAlloc::_max_framesize = 0;
    1.38 +#endif
    1.39 +
    1.40 +PhaseRegAlloc::PhaseRegAlloc( uint unique, PhaseCFG &cfg,
    1.41 +                              Matcher &matcher,
    1.42 +                              void (*pr_stats)() ):
    1.43 +               Phase(Register_Allocation), _cfg(cfg), _matcher(matcher),
    1.44 +               _node_oops(Thread::current()->resource_area()),
    1.45 +               _node_regs(0),
    1.46 +               _node_regs_max_index(0),
    1.47 +               _framesize(0xdeadbeef)
    1.48 +{
    1.49 +    int i;
    1.50 +
    1.51 +    for (i=0; i < _num_allocators; i++) {
    1.52 +        if (_alloc_statistics[i] == pr_stats)
    1.53 +            return;
    1.54 +    }
    1.55 +    assert((_num_allocators + 1) < MAX_REG_ALLOCATORS, "too many register allocators");
    1.56 +    _alloc_statistics[_num_allocators++] = pr_stats;
    1.57 +}
    1.58 +
    1.59 +
    1.60 +//------------------------------reg2offset-------------------------------------
    1.61 +int PhaseRegAlloc::reg2offset_unchecked( OptoReg::Name reg ) const {
    1.62 +  // Slots below _max_in_arg_stack_reg are offset by the entire frame.
    1.63 +  // Slots above _max_in_arg_stack_reg are frame_slots and are not offset.
    1.64 +  int slot = (reg < _matcher._new_SP)
    1.65 +    ? reg - OptoReg::stack0() + _framesize
    1.66 +    : reg - _matcher._new_SP;
    1.67 +  // Note:  We use the direct formula (reg - SharedInfo::stack0) instead of
    1.68 +  // OptoReg::reg2stack(reg), in order to avoid asserts in the latter
    1.69 +  // function.  This routine must remain unchecked, so that dump_frame()
    1.70 +  // can do its work undisturbed.
    1.71 +  // %%% not really clear why reg2stack would assert here
    1.72 +
    1.73 +  return slot*VMRegImpl::stack_slot_size;
    1.74 +}
    1.75 +
    1.76 +int PhaseRegAlloc::reg2offset( OptoReg::Name reg ) const {
    1.77 +
    1.78 +  // Not allowed in the out-preserve area.
    1.79 +  // In-preserve area is allowed so Intel can fetch the return pc out.
    1.80 +  assert( reg <  _matcher._old_SP ||
    1.81 +          (reg >= OptoReg::add(_matcher._old_SP,C->out_preserve_stack_slots()) &&
    1.82 +           reg <  _matcher._in_arg_limit) ||
    1.83 +          reg >=  OptoReg::add(_matcher._new_SP, C->out_preserve_stack_slots()) ||
    1.84 +          // Allow return_addr in the out-preserve area.
    1.85 +          reg == _matcher.return_addr(),
    1.86 +          "register allocated in a preserve area" );
    1.87 +  return reg2offset_unchecked( reg );
    1.88 +}
    1.89 +
    1.90 +//------------------------------offset2reg-------------------------------------
    1.91 +OptoReg::Name PhaseRegAlloc::offset2reg(int stk_offset) const {
    1.92 +  int slot = stk_offset / jintSize;
    1.93 +  int reg = (slot < (int) _framesize)
    1.94 +    ? slot + _matcher._new_SP
    1.95 +    : OptoReg::stack2reg(slot) - _framesize;
    1.96 +  assert(stk_offset == reg2offset((OptoReg::Name) reg),
    1.97 +         "offset2reg does not invert properly");
    1.98 +  return (OptoReg::Name) reg;
    1.99 +}
   1.100 +
   1.101 +//------------------------------set_oop----------------------------------------
   1.102 +void PhaseRegAlloc::set_oop( const Node *n, bool is_an_oop ) {
   1.103 +  if( is_an_oop ) {
   1.104 +    _node_oops.set(n->_idx);
   1.105 +  }
   1.106 +}
   1.107 +
   1.108 +//------------------------------is_oop-----------------------------------------
   1.109 +bool PhaseRegAlloc::is_oop( const Node *n ) const {
   1.110 +  return _node_oops.test(n->_idx) != 0;
   1.111 +}
   1.112 +
   1.113 +// Allocate _node_regs table with at least "size" elements
   1.114 +void PhaseRegAlloc::alloc_node_regs(int size) {
   1.115 +  _node_regs_max_index = size + (size >> 1) + NodeRegsOverflowSize;
   1.116 +  _node_regs = NEW_RESOURCE_ARRAY( OptoRegPair, _node_regs_max_index );
   1.117 +  // We assume our caller will fill in all elements up to size-1, so
   1.118 +  // only the extra space we allocate is initialized here.
   1.119 +  for( uint i = size; i < _node_regs_max_index; ++i )
   1.120 +    _node_regs[i].set_bad();
   1.121 +}
   1.122 +
   1.123 +#ifndef PRODUCT
   1.124 +void
   1.125 +PhaseRegAlloc::print_statistics() {
   1.126 +  tty->print_cr("Total frameslots = %d, Max frameslots = %d", _total_framesize, _max_framesize);
   1.127 +  int i;
   1.128 +
   1.129 +  for (i=0; i < _num_allocators; i++) {
   1.130 +    _alloc_statistics[i]();
   1.131 +  }
   1.132 +}
   1.133 +#endif

mercurial