hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
author xdono
Mon, 15 Dec 2008 16:55:11 -0800
changeset 1623 a0dd9009e992
parent 1412 2bb3fe3e00ea
child 1673 fe654c35dfe2
permissions -rw-r--r--
6785258: Update copyright year Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008 Reviewed-by: katleman, ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
1217
5eb97f366a6a 6754988: Update copyright year
xdono
parents: 1066
diff changeset
     2
 * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_c1_LIRGenerator.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
#define __ gen()->lir(__FILE__, __LINE__)->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#define __ gen()->lir()->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
void PhiResolverState::reset(int max_vregs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // Initialize array sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  _virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _virtual_operands.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _other_operands.at_put_grow(max_vregs - 1, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _other_operands.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  _vreg_table.at_put_grow(max_vregs - 1, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _vreg_table.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//--------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// PhiResolver
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// Resolves cycles:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//  r1 := r2  becomes  temp := r1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//  r2 := r1           r1 := r2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//                     r2 := temp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// and orders moves:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
//  r2 := r3  becomes  r1 := r2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//  r1 := r2           r2 := r3
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
PhiResolver::PhiResolver(LIRGenerator* gen, int max_vregs)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
 : _gen(gen)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
 , _state(gen->resolver_state())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 , _temp(LIR_OprFact::illegalOpr)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // reinitialize the shared state arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _state.reset(max_vregs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  assert(src->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  assert(dest->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  __ move(src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
void PhiResolver::move_temp_to(LIR_Opr dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  assert(_temp->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  emit_move(_temp, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
void PhiResolver::move_to_temp(LIR_Opr src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  assert(_temp->is_illegal(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  _temp = _gen->new_register(src->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  emit_move(src, _temp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
// Traverse assignment graph in depth first order and generate moves in post order
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// ie. two assignments: b := c, a := b start with node c:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// Call graph: move(NULL, c) -> move(c, b) -> move(b, a)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// Generates moves in this order: move b to a and move c to b
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// ie. cycle a := b, b := a start with node a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// Call graph: move(NULL, a) -> move(a, b) -> move(b, a)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
// Generates moves in this order: move b to temp, move a to b, move temp to a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
void PhiResolver::move(ResolveNode* src, ResolveNode* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (!dest->visited()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    dest->set_visited();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    for (int i = dest->no_of_destinations()-1; i >= 0; i --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      move(dest, dest->destination_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  } else if (!dest->start_node()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    // cylce in graph detected
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert(_loop == NULL, "only one loop valid!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    _loop = dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    move_to_temp(src->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  } // else dest is a start node
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  if (!dest->assigned()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    if (_loop == dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      move_temp_to(dest->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      dest->set_assigned();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    } else if (src != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      emit_move(src->operand(), dest->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      dest->set_assigned();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
PhiResolver::~PhiResolver() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // resolve any cycles in moves from and to virtual registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  for (i = virtual_operands().length() - 1; i >= 0; i --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    ResolveNode* node = virtual_operands()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    if (!node->visited()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      _loop = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      move(NULL, node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      node->set_start_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      assert(_temp->is_illegal(), "move_temp_to() call missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // generate move for move from non virtual register to abitrary destination
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  for (i = other_operands().length() - 1; i >= 0; i --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    ResolveNode* node = other_operands()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    for (int j = node->no_of_destinations() - 1; j >= 0; j --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      emit_move(node->operand(), node->destination_at(j)->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  ResolveNode* node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  if (opr->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    int vreg_num = opr->vreg_number();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    node = vreg_table().at_grow(vreg_num, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    assert(node == NULL || node->operand() == opr, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    if (node == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      node = new ResolveNode(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      vreg_table()[vreg_num] = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    // Make sure that all virtual operands show up in the list when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    // they are used as the source of a move.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    if (source && !virtual_operands().contains(node)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      virtual_operands().append(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    assert(source, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    node = new ResolveNode(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    other_operands().append(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  return node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void PhiResolver::move(LIR_Opr src, LIR_Opr dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert(dest->is_virtual(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  assert(src->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  assert(dest->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  ResolveNode* source = source_node(src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  source->append(destination_node(dest));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
//--------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
// LIRItem
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
void LIRItem::set_result(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  value()->set_operand(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  if (opr->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    _gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  _result = opr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
void LIRItem::load_item() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (result()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    // update the items result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    _result = value()->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  if (!result()->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    LIR_Opr reg = _gen->new_register(value()->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    __ move(result(), reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    if (result()->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      _result = reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      set_result(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
void LIRItem::load_for_store(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  if (_gen->can_store_as_constant(value(), type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    _result = value()->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    if (!_result->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      _result = LIR_OprFact::value_type(value()->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  } else if (type == T_BYTE || type == T_BOOLEAN) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
void LIRItem::load_item_force(LIR_Opr reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  LIR_Opr r = result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  if (r != reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    if (r->type() != reg->type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      // moves between different types need an intervening spill slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      LIR_Opr tmp = _gen->force_to_spill(r, reg->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      __ move(tmp, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      __ move(r, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    _result = reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
ciObject* LIRItem::get_jobject_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  ObjectType* oc = type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  if (oc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    return oc->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
jint LIRItem::get_jint_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  assert(type()->as_IntConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  return type()->as_IntConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
jint LIRItem::get_address_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  assert(type()->as_AddressConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  return type()->as_AddressConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
jfloat LIRItem::get_jfloat_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  assert(type()->as_FloatConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  return type()->as_FloatConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
jdouble LIRItem::get_jdouble_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  assert(type()->as_DoubleConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  return type()->as_DoubleConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
jlong LIRItem::get_jlong_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  assert(type()->as_LongConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  return type()->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
//--------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
void LIRGenerator::init() {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   288
  _bs = Universe::heap()->barrier_set();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
void LIRGenerator::block_do_prolog(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  if (PrintIRWithLIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    block->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // set up the list of LIR instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  assert(block->lir() == NULL, "LIR list already computed for this block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  _lir = new LIR_List(compilation(), block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  block->set_lir(_lir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  __ branch_destination(block->label());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  if (LIRTraceExecution &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      Compilation::current_compilation()->hir()->start()->block_id() != block->block_id() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      !block->is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    trace_block_entry(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
void LIRGenerator::block_do_epilog(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  if (PrintIRWithLIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  // LIR_Opr for unpinned constants shouldn't be referenced by other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  // blocks so clear them out after processing the block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  for (int i = 0; i < _unpinned_constants.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    _unpinned_constants.at(i)->clear_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  _unpinned_constants.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // clear our any registers for other local constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  _constants.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  _reg_for_constants.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
void LIRGenerator::block_do(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  block_do_prolog(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  set_block(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  for (Instruction* instr = block; instr != NULL; instr = instr->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    if (instr->is_pinned()) do_root(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  set_block(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  block_do_epilog(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
//-------------------------LIRGenerator-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
// This is where the tree-walk starts; instr must be root;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
void LIRGenerator::do_root(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  InstructionMark im(compilation(), instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  assert(instr->is_pinned(), "use only with roots");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  assert(instr->subst() == instr, "shouldn't have missed substitution");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  instr->visit(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  assert(!instr->has_uses() || instr->operand()->is_valid() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
         instr->as_Constant() != NULL || bailed_out(), "invalid item set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
// This is called for each node in tree; the walk stops if a root is reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
void LIRGenerator::walk(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  InstructionMark im(compilation(), instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  //stop walk when encounter a root
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  if (instr->is_pinned() && instr->as_Phi() == NULL || instr->operand()->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != NULL, "this root has not yet been visited");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    assert(instr->subst() == instr, "shouldn't have missed substitution");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    instr->visit(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    // assert(instr->use_count() > 0 || instr->as_Phi() != NULL, "leaf instruction must have a use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  Value value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  for_each_stack_value(state, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    assert(value->subst() == value, "missed substition");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
      walk(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      assert(value->operand()->is_valid(), "must be evaluated now");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  ValueStack* s = state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  int bci = x->bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  for_each_state(s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    IRScope* scope = s->scope();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    ciMethod* method = scope->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    MethodLivenessResult liveness = method->liveness_at_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    if (bci == SynchronizationEntryBCI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      if (x->as_ExceptionObject() || x->as_Throw()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
        // all locals are dead on exit from the synthetic unlocker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
        liveness.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
        assert(x->as_MonitorEnter(), "only other case is MonitorEnter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    if (!liveness.is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      // Degenerate or breakpointed method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      bailout("Degenerate or breakpointed method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      assert((int)liveness.size() == s->locals_size(), "error in use of liveness");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      for_each_local_value(s, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
        assert(value->subst() == value, "missed substition");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
        if (liveness.at(index) && !value->type()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
          if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
            walk(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
            assert(value->operand()->is_valid(), "must be evaluated now");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
          // NULL out this local so that linear scan can assume that all non-NULL values are live.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
          s->invalidate_local(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    bci = scope->caller_bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  return new CodeEmitInfo(x->bci(), state, ignore_xhandler ? NULL : x->exception_handlers());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
CodeEmitInfo* LIRGenerator::state_for(Instruction* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  return state_for(x, x->lock_stack());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
void LIRGenerator::jobject2reg_with_patching(LIR_Opr r, ciObject* obj, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  if (!obj->is_loaded() || PatchALot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    assert(info != NULL, "info must be set if class is not loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    __ oop2reg_patch(NULL, r, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    // no patching needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    __ oop2reg(obj->encoding(), r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                                    CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  CodeStub* stub = new RangeCheckStub(range_check_info, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  if (index->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
                index->as_jint(), null_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    cmp_reg_mem(lir_cond_aboveEqual, index, array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
                arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
void LIRGenerator::nio_range_check(LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  CodeStub* stub = new RangeCheckStub(info, index, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  if (index->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    cmp_mem_int(lir_cond_belowEqual, buffer, java_nio_Buffer::limit_offset(), index->as_jint(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    cmp_reg_mem(lir_cond_aboveEqual, index, buffer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
                java_nio_Buffer::limit_offset(), T_INT, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  __ move(index, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
// increment a counter returning the incremented value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
LIR_Opr LIRGenerator::increment_and_return_counter(LIR_Opr base, int offset, int increment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  LIR_Address* counter = new LIR_Address(base, offset, T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  LIR_Opr result = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  __ load(counter, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  __ add(result, LIR_OprFact::intConst(increment), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  __ store(result, counter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp_op, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  LIR_Opr result_op = result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  LIR_Opr left_op   = left;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  LIR_Opr right_op  = right;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  if (TwoOperandLIRForm && left_op != result_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    assert(right_op != result_op, "malformed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    __ move(left_op, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    left_op = result_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  switch(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    case Bytecodes::_dadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    case Bytecodes::_fadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    case Bytecodes::_ladd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    case Bytecodes::_iadd:  __ add(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    case Bytecodes::_fmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    case Bytecodes::_lmul:  __ mul(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    case Bytecodes::_dmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
        if (is_strictfp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
          __ mul_strictfp(left_op, right_op, result_op, tmp_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
          __ mul(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    case Bytecodes::_imul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
        bool    did_strength_reduce = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
        if (right->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
          int c = right->as_jint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
          if (is_power_of_2(c)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
            // do not need tmp here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
            __ shift_left(left_op, exact_log2(c), result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
            did_strength_reduce = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
            did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
        // we couldn't strength reduce so just emit the multiply
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
        if (!did_strength_reduce) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
          __ mul(left_op, right_op, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    case Bytecodes::_dsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    case Bytecodes::_fsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    case Bytecodes::_lsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    // ldiv and lrem are implemented with a direct runtime call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    case Bytecodes::_ddiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
        if (is_strictfp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
          __ div_strictfp (left_op, right_op, result_op, tmp_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
          __ div (left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    case Bytecodes::_drem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    default: ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
void LIRGenerator::arithmetic_op_int(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  arithmetic_op(code, result, left, right, false, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
void LIRGenerator::arithmetic_op_long(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  arithmetic_op(code, result, left, right, false, LIR_OprFact::illegalOpr, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
void LIRGenerator::arithmetic_op_fpu(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  arithmetic_op(code, result, left, right, is_strictfp, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
void LIRGenerator::shift_op(Bytecodes::Code code, LIR_Opr result_op, LIR_Opr value, LIR_Opr count, LIR_Opr tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  if (TwoOperandLIRForm && value != result_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    assert(count != result_op, "malformed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    __ move(value, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    value = result_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  assert(count->is_constant() || count->is_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  switch(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  case Bytecodes::_ishl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  case Bytecodes::_ishr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  case Bytecodes::_iushr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  default: ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
void LIRGenerator::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  if (TwoOperandLIRForm && left_op != result_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    assert(right_op != result_op, "malformed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    __ move(left_op, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    left_op = result_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  switch(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    case Bytecodes::_iand:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    case Bytecodes::_land:  __ logical_and(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    case Bytecodes::_ior:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    case Bytecodes::_lor:   __ logical_or(left_op, right_op, result_op);  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    case Bytecodes::_ixor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    case Bytecodes::_lxor:  __ logical_xor(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    default: ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
void LIRGenerator::monitor_enter(LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  if (!GenerateSynchronizationCode) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  // for slow path, use debug info for state after successful locking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  CodeStub* slow_path = new MonitorEnterStub(object, lock, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  __ load_stack_address_monitor(monitor_no, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  // for handling NullPointerException, use debug info representing just the lock stack before this monitorenter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  __ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, int monitor_no) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  if (!GenerateSynchronizationCode) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  // setup registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  LIR_Opr hdr = lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  lock = new_hdr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  CodeStub* slow_path = new MonitorExitStub(lock, UseFastLocking, monitor_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  __ load_stack_address_monitor(monitor_no, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  __ unlock_object(hdr, object, lock, slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  jobject2reg_with_patching(klass_reg, klass, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  // If klass is not loaded we do not know if the klass has finalizers:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  if (UseFastNewInstance && klass->is_loaded()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
      && !Klass::layout_helper_needs_slow_path(klass->layout_helper())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    Runtime1::StubID stub_id = klass->is_initialized() ? Runtime1::fast_new_instance_id : Runtime1::fast_new_instance_init_check_id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    assert(klass->is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    // allocate space for instance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    assert(klass->size_helper() >= 0, "illegal instance size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    const int instance_size = align_object_size(klass->size_helper());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
                       oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, Runtime1::new_instance_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    __ branch(lir_cond_always, T_ILLEGAL, slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    __ branch_destination(slow_path->continuation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
static bool is_constant_zero(Instruction* inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  IntConstant* c = inst->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  if (c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    return (c->value() == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
static bool positive_constant(Instruction* inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  IntConstant* c = inst->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  if (c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    return (c->value() >= 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
static ciArrayKlass* as_array_klass(ciType* type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  if (type != NULL && type->is_array_klass() && type->is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    return (ciArrayKlass*)type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  Instruction* src     = x->argument_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  Instruction* src_pos = x->argument_at(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  Instruction* dst     = x->argument_at(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  Instruction* dst_pos = x->argument_at(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  Instruction* length  = x->argument_at(4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  // first try to identify the likely type of the arrays involved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  ciArrayKlass* expected_type = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  bool is_exact = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    ciArrayKlass* src_exact_type    = as_array_klass(src->exact_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    ciArrayKlass* src_declared_type = as_array_klass(src->declared_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    ciArrayKlass* dst_exact_type    = as_array_klass(dst->exact_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
    ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    if (src_exact_type != NULL && src_exact_type == dst_exact_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      // the types exactly match so the type is fully known
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
      is_exact = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
      expected_type = src_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
    } else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
      ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
      ciArrayKlass* src_type = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
      if (src_exact_type != NULL && src_exact_type->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
        src_type = (ciArrayKlass*) src_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
      } else if (src_declared_type != NULL && src_declared_type->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
        src_type = (ciArrayKlass*) src_declared_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
      if (src_type != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
        if (src_type->element_type()->is_subtype_of(dst_type->element_type())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
          is_exact = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
          expected_type = dst_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    // at least pass along a good guess
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    if (expected_type == NULL) expected_type = dst_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    if (expected_type == NULL) expected_type = src_declared_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    if (expected_type == NULL) expected_type = dst_declared_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  // if a probable array type has been identified, figure out if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  // of the required checks for a fast case can be elided.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  int flags = LIR_OpArrayCopy::all_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  if (expected_type != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    // try to skip null checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    if (src->as_NewArray() != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
      flags &= ~LIR_OpArrayCopy::src_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    if (dst->as_NewArray() != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
      flags &= ~LIR_OpArrayCopy::dst_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    // check from incoming constant values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    if (positive_constant(src_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
      flags &= ~LIR_OpArrayCopy::src_pos_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    if (positive_constant(dst_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
      flags &= ~LIR_OpArrayCopy::dst_pos_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    if (positive_constant(length))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
      flags &= ~LIR_OpArrayCopy::length_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    // see if the range check can be elided, which might also imply
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
    // that src or dst is non-null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
    ArrayLength* al = length->as_ArrayLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    if (al != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      if (al->array() == src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
        // it's the length of the source array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
        flags &= ~LIR_OpArrayCopy::length_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
        flags &= ~LIR_OpArrayCopy::src_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
        if (is_constant_zero(src_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
          flags &= ~LIR_OpArrayCopy::src_range_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
      if (al->array() == dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
        // it's the length of the destination array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
        flags &= ~LIR_OpArrayCopy::length_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
        flags &= ~LIR_OpArrayCopy::dst_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
        if (is_constant_zero(dst_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
          flags &= ~LIR_OpArrayCopy::dst_range_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    if (is_exact) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
      flags &= ~LIR_OpArrayCopy::type_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  if (src == dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    // moving within a single array so no type checks are needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    if (flags & LIR_OpArrayCopy::type_check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      flags &= ~LIR_OpArrayCopy::type_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  *flagsp = flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  *expected_typep = (ciArrayKlass*)expected_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
LIR_Opr LIRGenerator::round_item(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  assert(opr->is_register(), "why spill if item is not register?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  if (RoundFPResults && UseSSE < 1 && opr->is_single_fpu()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    LIR_Opr result = new_register(T_FLOAT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    set_vreg_flag(result, must_start_in_memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    assert(opr->is_register(), "only a register can be spilled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    assert(opr->value_type()->is_float(), "rounding only for floats available");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    __ roundfp(opr, LIR_OprFact::illegalOpr, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  return opr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  assert(type2size[t] == type2size[value->type()], "size mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  if (!value->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    // force into a register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    LIR_Opr r = new_register(value->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    __ move(value, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    value = r;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  // create a spill location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  LIR_Opr tmp = new_register(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  set_vreg_flag(tmp, LIRGenerator::must_start_in_memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  // move from register to spill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  __ move(value, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  return tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  if (if_instr->should_profile()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    ciMethod* method = if_instr->profiled_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    assert(method != NULL, "method should be set if branch is profiled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    ciMethodData* md = method->method_data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    if (md == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
      bailout("out of memory building methodDataOop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    ciProfileData* data = md->bci_to_data(if_instr->profiled_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    assert(data != NULL, "must have profiling data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    assert(data->is_BranchData(), "need BranchData for two-way branches");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    int taken_count_offset     = md->byte_offset_of_slot(data, BranchData::taken_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    LIR_Opr md_reg = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    __ move(LIR_OprFact::oopConst(md->encoding()), md_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    LIR_Opr data_offset_reg = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    __ cmove(lir_cond(cond),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
             LIR_OprFact::intConst(taken_count_offset),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
             LIR_OprFact::intConst(not_taken_count_offset),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
             data_offset_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    LIR_Opr data_reg = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    __ move(LIR_OprFact::address(data_addr), data_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    // Use leal instead of add to avoid destroying condition codes on x86
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    __ leal(LIR_OprFact::address(fake_incr_value), data_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    __ move(data_reg, LIR_OprFact::address(data_addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
// Phi technique:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
// This is about passing live values from one basic block to the other.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
// In code generated with Java it is rather rare that more than one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
// value is on the stack from one basic block to the other.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
// We optimize our technique for efficient passing of one value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
// (of type long, int, double..) but it can be extended.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
// When entering or leaving a basic block, all registers and all spill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
// slots are release and empty. We use the released registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
// and spill slots to pass the live values from one block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
// to the other. The topmost value, i.e., the value on TOS of expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
// stack is passed in registers. All other values are stored in spilling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
// area. Every Phi has an index which designates its spill slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
// At exit of a basic block, we fill the register(s) and spill slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
// At entry of a basic block, the block_prolog sets up the content of phi nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
// and locks necessary registers and spilling slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
// move current value to referenced phi function
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  Phi* phi = sux_val->as_Phi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  // cur_val can be null without phi being null in conjunction with inlining
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  if (phi != NULL && cur_val != NULL && cur_val != phi && !phi->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    LIR_Opr operand = cur_val->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    if (cur_val->operand()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
      assert(cur_val->as_Constant() != NULL || cur_val->as_Local() != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
             "these can be produced lazily");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
      operand = operand_for_instruction(cur_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    resolver->move(operand, operand_for_instruction(phi));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
// Moves all stack values into their PHI position
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
void LIRGenerator::move_to_phi(ValueStack* cur_state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  BlockBegin* bb = block();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  if (bb->number_of_sux() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    BlockBegin* sux = bb->sux_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
    assert(sux->number_of_preds() > 0, "invalid CFG");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
    // a block with only one predecessor never has phi functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    if (sux->number_of_preds() > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
      int max_phis = cur_state->stack_size() + cur_state->locals_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
      PhiResolver resolver(this, _virtual_register_number + max_phis * 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      ValueStack* sux_state = sux->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
      Value sux_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
      for_each_stack_value(sux_state, index, sux_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
        move_to_phi(&resolver, cur_state->stack_at(index), sux_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
      // Inlining may cause the local state not to match up, so walk up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
      // the caller state until we get to the same scope as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
      // successor and then start processing from there.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
      while (cur_state->scope() != sux_state->scope()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
        cur_state = cur_state->caller_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
        assert(cur_state != NULL, "scopes don't match up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
      for_each_local_value(sux_state, index, sux_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
        move_to_phi(&resolver, cur_state->local_at(index), sux_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
      assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
LIR_Opr LIRGenerator::new_register(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  int vreg = _virtual_register_number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  // add a little fudge factor for the bailout, since the bailout is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  // only checked periodically.  This gives a few extra registers to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  // hand out before we really run out, which helps us keep from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  // tripping over assertions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  if (vreg + 20 >= LIR_OprDesc::vreg_max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
    bailout("out of virtual registers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    if (vreg + 2 >= LIR_OprDesc::vreg_max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
      // wrap it around
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      _virtual_register_number = LIR_OprDesc::vreg_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  _virtual_register_number += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  if (type == T_ADDRESS) type = T_INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  return LIR_OprFact::virtual_register(vreg, type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
// Try to lock using register in hint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
LIR_Opr LIRGenerator::rlock(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  return new_register(instr->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
// does an rlock and sets result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
LIR_Opr LIRGenerator::rlock_result(Value x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  LIR_Opr reg = rlock(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  set_result(x, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  return reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
// does an rlock and sets result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  LIR_Opr reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  case T_BYTE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    reg = rlock_byte(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    reg = rlock(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  set_result(x, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  return reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
//---------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
ciObject* LIRGenerator::get_jobject_constant(Value value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  ObjectType* oc = value->type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  if (oc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    return oc->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
void LIRGenerator::do_ExceptionObject(ExceptionObject* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  assert(block()->next() == x, "ExceptionObject must be first instruction of block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  // no moves are created for phi functions at the begin of exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  // handlers, so assign operands manually here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  for_each_phi_fun(block(), phi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
                   operand_for_instruction(phi));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  LIR_Opr thread_reg = getThreadPointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  __ move(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
          exceptionOopOpr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  __ move(LIR_OprFact::oopConst(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
          new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  __ move(LIR_OprFact::oopConst(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
          new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  LIR_Opr result = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  __ move(exceptionOopOpr(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  set_result(x, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
//                        visitor functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
void LIRGenerator::do_Phi(Phi* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  // phi functions are never visited directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
// Code for a constant is generated lazily unless the constant is frequently used and can't be inlined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
void LIRGenerator::do_Constant(Constant* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  if (x->state() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    // Any constant with a ValueStack requires patching so emit the patch here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
    LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    __ oop2reg_patch(NULL, reg, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  } else if (x->use_count() > 1 && !can_inline_as_constant(x)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    if (!x->is_pinned()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
      // unpinned constants are handled specially so that they can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
      // put into registers when they are used multiple times within a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
      // block.  After the block completes their operand will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
      // cleared so that other blocks can't refer to that register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
      set_result(x, load_constant(x));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
      LIR_Opr res = x->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
      if (!res->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
        res = LIR_OprFact::value_type(x->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
      if (res->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
        LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
        __ move(res, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
        set_result(x, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    set_result(x, LIR_OprFact::value_type(x->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
void LIRGenerator::do_Local(Local* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  // operand_for_instruction has the side effect of setting the result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  // so there's no need to do it here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  operand_for_instruction(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
void LIRGenerator::do_IfInstanceOf(IfInstanceOf* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  Unimplemented();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
void LIRGenerator::do_Return(Return* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  if (DTraceMethodProbes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
    BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
    signature.append(T_INT);    // thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    signature.append(T_OBJECT); // methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    LIR_OprList* args = new LIR_OprList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    args->append(getThreadPointer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    LIR_Opr meth = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    __ oop2reg(method()->encoding(), meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    args->append(meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
    call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  if (x->type()->is_void()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    __ return_op(LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    LIR_Opr reg = result_register_for(x->type(), /*callee=*/true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    LIRItem result(x->result(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    result.load_item_force(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    __ return_op(result.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
// Example: object.getClass ()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
void LIRGenerator::do_getClass(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  assert(x->number_of_arguments() == 1, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  LIRItem rcvr(x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
  rcvr.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
  // need to perform the null check on the rcvr
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
  if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    info = state_for(x, x->state()->copy_locks());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_OBJECT), result, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
  __ move(new LIR_Address(result, Klass::java_mirror_offset_in_bytes() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
                          klassOopDesc::klass_part_offset_in_bytes(), T_OBJECT), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
// Example: Thread.currentThread()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
void LIRGenerator::do_currentThread(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  assert(x->number_of_arguments() == 0, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  __ load(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::threadObj_offset()), T_OBJECT), reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
  assert(x->number_of_arguments() == 1, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  LIRItem receiver(x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  receiver.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  signature.append(T_OBJECT); // receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  LIR_OprList* args = new LIR_OprList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
  args->append(receiver.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  call_runtime(&signature, args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
               CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::register_finalizer_id)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
               voidType, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
//------------------------local access--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
  if (x->operand()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
    Constant* c = x->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
    if (c != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
      x->set_operand(LIR_OprFact::value_type(c->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
      assert(x->as_Phi() || x->as_Local() != NULL, "only for Phi and Local");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
      // allocate a virtual register for this local or phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
      x->set_operand(rlock(x));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
      _instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
  return x->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
Instruction* LIRGenerator::instruction_for_opr(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  if (opr->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
    return instruction_for_vreg(opr->vreg_number());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
Instruction* LIRGenerator::instruction_for_vreg(int reg_num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  if (reg_num < _instruction_for_operand.length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    return _instruction_for_operand.at(reg_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
  if (_vreg_flags.size_in_bits() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    BitMap2D temp(100, num_vreg_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
    temp.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
    _vreg_flags = temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  _vreg_flags.at_put_grow(vreg_num, f, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
  if (!_vreg_flags.is_valid_index(vreg_num, f)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  return _vreg_flags.at(vreg_num, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
// Block local constant handling.  This code is useful for keeping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
// unpinned constants and constants which aren't exposed in the IR in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
// registers.  Unpinned Constant instructions have their operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
// cleared when the block is finished so that other blocks can't end
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
// up referring to their registers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
LIR_Opr LIRGenerator::load_constant(Constant* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
  assert(!x->is_pinned(), "only for unpinned constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  _unpinned_constants.append(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
LIR_Opr LIRGenerator::load_constant(LIR_Const* c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  BasicType t = c->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  for (int i = 0; i < _constants.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    LIR_Const* other = _constants.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    if (t == other->type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
      switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
      case T_INT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
      case T_FLOAT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
        if (c->as_jint_bits() != other->as_jint_bits()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
      case T_LONG:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
      case T_DOUBLE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
        if (c->as_jint_hi_bits() != other->as_jint_lo_bits()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
        if (c->as_jint_lo_bits() != other->as_jint_hi_bits()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
      case T_OBJECT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
        if (c->as_jobject() != other->as_jobject()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
      return _reg_for_constants.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
  LIR_Opr result = new_register(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
  __ move((LIR_Opr)c, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
  _constants.append(c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
  _reg_for_constants.append(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
// Various barriers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1233
void LIRGenerator::pre_barrier(LIR_Opr addr_opr, bool patch,  CodeEmitInfo* info) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1234
  // Do the pre-write barrier, if any.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1235
  switch (_bs->kind()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1236
#ifndef SERIALGC
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1237
    case BarrierSet::G1SATBCT:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1238
    case BarrierSet::G1SATBCTLogging:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1239
      G1SATBCardTableModRef_pre_barrier(addr_opr, patch, info);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1240
      break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1241
#endif // SERIALGC
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1242
    case BarrierSet::CardTableModRef:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1243
    case BarrierSet::CardTableExtension:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1244
      // No pre barriers
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1245
      break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1246
    case BarrierSet::ModRef:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1247
    case BarrierSet::Other:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1248
      // No pre barriers
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1249
      break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1250
    default      :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1251
      ShouldNotReachHere();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1252
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1253
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1254
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1255
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
void LIRGenerator::post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1257
  switch (_bs->kind()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1258
#ifndef SERIALGC
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1259
    case BarrierSet::G1SATBCT:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1260
    case BarrierSet::G1SATBCTLogging:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1261
      G1SATBCardTableModRef_post_barrier(addr,  new_val);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1262
      break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1263
#endif // SERIALGC
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    case BarrierSet::CardTableModRef:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
    case BarrierSet::CardTableExtension:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
      CardTableModRef_post_barrier(addr,  new_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    case BarrierSet::ModRef:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    case BarrierSet::Other:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
      // No post barriers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    default      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1277
////////////////////////////////////////////////////////////////////////
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1278
#ifndef SERIALGC
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1279
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1280
void LIRGenerator::G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, bool patch,  CodeEmitInfo* info) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1281
  if (G1DisablePreBarrier) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1282
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1283
  // First we test whether marking is in progress.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1284
  BasicType flag_type;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1285
  if (in_bytes(PtrQueue::byte_width_of_active()) == 4) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1286
    flag_type = T_INT;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1287
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1288
    guarantee(in_bytes(PtrQueue::byte_width_of_active()) == 1,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1289
              "Assumption");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1290
    flag_type = T_BYTE;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1291
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1292
  LIR_Opr thrd = getThreadPointer();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1293
  LIR_Address* mark_active_flag_addr =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1294
    new LIR_Address(thrd,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1295
                    in_bytes(JavaThread::satb_mark_queue_offset() +
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1296
                             PtrQueue::byte_offset_of_active()),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1297
                    flag_type);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1298
  // Read the marking-in-progress flag.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1299
  LIR_Opr flag_val = new_register(T_INT);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1300
  __ load(mark_active_flag_addr, flag_val);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1301
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1302
  LabelObj* start_store = new LabelObj();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1303
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1304
  LIR_PatchCode pre_val_patch_code =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1305
    patch ? lir_patch_normal : lir_patch_none;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1306
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1307
  LIR_Opr pre_val = new_register(T_OBJECT);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1308
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1309
  __ cmp(lir_cond_notEqual, flag_val, LIR_OprFact::intConst(0));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1310
  if (!addr_opr->is_address()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1311
    assert(addr_opr->is_register(), "must be");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1312
    addr_opr = LIR_OprFact::address(new LIR_Address(addr_opr, 0, T_OBJECT));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1313
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1314
  CodeStub* slow = new G1PreBarrierStub(addr_opr, pre_val, pre_val_patch_code,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1315
                                        info);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1316
  __ branch(lir_cond_notEqual, T_INT, slow);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1317
  __ branch_destination(slow->continuation());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1318
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1319
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1320
void LIRGenerator::G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1321
  if (G1DisablePostBarrier) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1322
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1323
  // If the "new_val" is a constant NULL, no barrier is necessary.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1324
  if (new_val->is_constant() &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1325
      new_val->as_constant_ptr()->as_jobject() == NULL) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1326
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1327
  if (!new_val->is_register()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1328
    LIR_Opr new_val_reg = new_pointer_register();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1329
    if (new_val->is_constant()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1330
      __ move(new_val, new_val_reg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1331
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1332
      __ leal(new_val, new_val_reg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1333
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1334
    new_val = new_val_reg;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1335
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1336
  assert(new_val->is_register(), "must be a register at this point");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1337
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1338
  if (addr->is_address()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1339
    LIR_Address* address = addr->as_address_ptr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1340
    LIR_Opr ptr = new_pointer_register();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1341
    if (!address->index()->is_valid() && address->disp() == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1342
      __ move(address->base(), ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1343
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1344
      assert(address->disp() != max_jint, "lea doesn't support patched addresses!");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1345
      __ leal(addr, ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1346
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1347
    addr = ptr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1348
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1349
  assert(addr->is_register(), "must be a register at this point");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1350
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1351
  LIR_Opr xor_res = new_pointer_register();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1352
  LIR_Opr xor_shift_res = new_pointer_register();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1353
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1354
  if (TwoOperandLIRForm ) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1355
    __ move(addr, xor_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1356
    __ logical_xor(xor_res, new_val, xor_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1357
    __ move(xor_res, xor_shift_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1358
    __ unsigned_shift_right(xor_shift_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1359
                            LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1360
                            xor_shift_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1361
                            LIR_OprDesc::illegalOpr());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1362
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1363
    __ logical_xor(addr, new_val, xor_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1364
    __ unsigned_shift_right(xor_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1365
                            LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1366
                            xor_shift_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1367
                            LIR_OprDesc::illegalOpr());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1368
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1369
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1370
  if (!new_val->is_register()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1371
    LIR_Opr new_val_reg = new_pointer_register();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1372
    __ leal(new_val, new_val_reg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1373
    new_val = new_val_reg;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1374
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1375
  assert(new_val->is_register(), "must be a register at this point");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1376
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1377
  __ cmp(lir_cond_notEqual, xor_shift_res, LIR_OprFact::intptrConst(NULL_WORD));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1378
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1379
  CodeStub* slow = new G1PostBarrierStub(addr, new_val);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1380
  __ branch(lir_cond_notEqual, T_INT, slow);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1381
  __ branch_destination(slow->continuation());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1382
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1383
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1384
#endif // SERIALGC
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1385
////////////////////////////////////////////////////////////////////////
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1386
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
void LIRGenerator::CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1389
  assert(sizeof(*((CardTableModRefBS*)_bs)->byte_map_base) == sizeof(jbyte), "adjust this code");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1390
  LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
  if (addr->is_address()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
    LIR_Address* address = addr->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
    LIR_Opr ptr = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
    if (!address->index()->is_valid() && address->disp() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
      __ move(address->base(), ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
      assert(address->disp() != max_jint, "lea doesn't support patched addresses!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
      __ leal(addr, ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
    addr = ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
  assert(addr->is_register(), "must be a register at this point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
  LIR_Opr tmp = new_pointer_register();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
  if (TwoOperandLIRForm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
    __ move(addr, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    __ unsigned_shift_right(tmp, CardTableModRefBS::card_shift, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
    __ unsigned_shift_right(addr, CardTableModRefBS::card_shift, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  if (can_inline_as_constant(card_table_base)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
    __ move(LIR_OprFact::intConst(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
              new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
    __ move(LIR_OprFact::intConst(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
              new LIR_Address(tmp, load_constant(card_table_base),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
                              T_BYTE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
//------------------------field access--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
// Comment copied form templateTable_i486.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
// Volatile variables demand their effects be made known to all CPU's in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
// order.  Store buffers on most chips allow reads & writes to reorder; the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
// JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
// memory barrier (i.e., it's not sufficient that the interpreter does not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
// reorder volatile references, the hardware also must not reorder them).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
// According to the new Java Memory Model (JMM):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
// (1) All volatiles are serialized wrt to each other.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
// ALSO reads & writes act as aquire & release, so:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
// (2) A read cannot let unrelated NON-volatile memory refs that happen after
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
// the read float up to before the read.  It's OK for non-volatile memory refs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
// that happen before the volatile read to float down below it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
// (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
// that happen BEFORE the write float down to after the write.  It's OK for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
// non-volatile memory refs that happen after the volatile write to float up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
// before it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
// We only put in barriers around volatile refs (they are expensive), not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
// _between_ memory refs (that would require us to track the flavor of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
// previous memory refs).  Requirements (2) and (3) require some barriers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
// before volatile stores and after volatile loads.  These nearly cover
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
// requirement (1) but miss the volatile-store-volatile-load case.  This final
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
// case is placed after volatile-stores although it could just as well go
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
// before volatile-loads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
void LIRGenerator::do_StoreField(StoreField* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  bool needs_patching = x->needs_patching();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
  bool is_volatile = x->field()->is_volatile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
  BasicType field_type = x->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
  bool is_oop = (field_type == T_ARRAY || field_type == T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
    assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
    info = state_for(x, x->state_before());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
  } else if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
    if (nc == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
      info = state_for(x, x->lock_stack());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
      info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
  LIRItem object(x->obj(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
  LIRItem value(x->value(),  this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
  object.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
  if (is_volatile || needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
    // load item if field is volatile (fewer special cases for volatiles)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
    // load item if field not initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
    // load item if field not constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
    // because of code patching we cannot inline constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
    if (field_type == T_BYTE || field_type == T_BOOLEAN) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
      value.load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
    } else  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
      value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
    value.load_for_store(field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
  if (PrintNotLoaded && needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
    tty->print_cr("   ###class not loaded at store_%s bci %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
                  x->is_static() ?  "static" : "field", x->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
  if (x->needs_null_check() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
      (needs_patching ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
       MacroAssembler::needs_explicit_null_check(x->offset()))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
    // emit an explicit null check because the offset is too large
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
    __ null_check(object.result(), new CodeEmitInfo(info));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
  LIR_Address* address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
    // we need to patch the offset in the instruction so don't allow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
    // generate_address to try to be smart about emitting the -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
    // Otherwise the patching code won't know how to find the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
    // instruction to patch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
    address = new LIR_Address(object.result(), max_jint, field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
    address = generate_address(object.result(), x->offset(), field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
  if (is_volatile && os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
    __ membar_release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1520
  if (is_oop) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1521
    // Do the pre-write barrier, if any.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1522
    pre_barrier(LIR_OprFact::address(address),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1523
                needs_patching,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1524
                (info ? new CodeEmitInfo(info) : NULL));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1525
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1526
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
  if (is_volatile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
    assert(!needs_patching && x->is_loaded(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
           "how do we know it's volatile if it's not loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    volatile_field_store(value.result(), address, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
    LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
    __ store(value.result(), address, info, patch_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
  if (is_oop) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1537
#ifdef PRECISE_CARDMARK
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1538
    // Precise cardmarks don't work
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1539
    post_barrier(LIR_OprFact::address(address), value.result());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1540
#else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
    post_barrier(object.result(), value.result());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1542
#endif // PRECISE_CARDMARK
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
  if (is_volatile && os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
    __ membar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
void LIRGenerator::do_LoadField(LoadField* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
  bool needs_patching = x->needs_patching();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
  bool is_volatile = x->field()->is_volatile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
  BasicType field_type = x->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
    assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
    info = state_for(x, x->state_before());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
  } else if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
    if (nc == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
      info = state_for(x, x->lock_stack());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
      info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
  LIRItem object(x->obj(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
  object.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  if (PrintNotLoaded && needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
    tty->print_cr("   ###class not loaded at load_%s bci %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
                  x->is_static() ?  "static" : "field", x->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
  if (x->needs_null_check() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
      (needs_patching ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
       MacroAssembler::needs_explicit_null_check(x->offset()))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
    // emit an explicit null check because the offset is too large
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
    __ null_check(object.result(), new CodeEmitInfo(info));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
  LIR_Opr reg = rlock_result(x, field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
  LIR_Address* address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
    // we need to patch the offset in the instruction so don't allow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
    // generate_address to try to be smart about emitting the -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
    // Otherwise the patching code won't know how to find the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
    // instruction to patch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
    address = new LIR_Address(object.result(), max_jint, field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
    address = generate_address(object.result(), x->offset(), field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
  if (is_volatile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
    assert(!needs_patching && x->is_loaded(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
           "how do we know it's volatile if it's not loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
    volatile_field_load(address, reg, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
    LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    __ load(address, reg, info, patch_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  if (is_volatile && os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
    __ membar_acquire();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
//------------------------java.nio.Buffer.checkIndex------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
// int java.nio.Buffer.checkIndex(int)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
  // NOTE: by the time we are in checkIndex() we are guaranteed that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
  // the buffer is non-null (because checkIndex is package-private and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
  // only called from within other methods in the buffer).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
  assert(x->number_of_arguments() == 2, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
  LIRItem buf  (x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
  LIRItem index(x->argument_at(1), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
  buf.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
  index.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
  LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
  if (GenerateRangeChecks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
    CodeEmitInfo* info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
    CodeStub* stub = new RangeCheckStub(info, index.result(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
    if (index.result()->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
      cmp_mem_int(lir_cond_belowEqual, buf.result(), java_nio_Buffer::limit_offset(), index.result()->as_jint(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
      __ branch(lir_cond_belowEqual, T_INT, stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
      cmp_reg_mem(lir_cond_aboveEqual, index.result(), buf.result(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
                  java_nio_Buffer::limit_offset(), T_INT, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
      __ branch(lir_cond_aboveEqual, T_INT, stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
    __ move(index.result(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
    // Just load the index into the result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
    __ move(index.result(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
//------------------------array access--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
void LIRGenerator::do_ArrayLength(ArrayLength* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
  LIRItem array(x->array(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
  array.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
  if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
    if (nc == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
      info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
      info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
  __ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
void LIRGenerator::do_LoadIndexed(LoadIndexed* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
  bool use_length = x->length() != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
  LIRItem array(x->array(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
  LIRItem index(x->index(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
  LIRItem length(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
  bool needs_range_check = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
  if (use_length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
    needs_range_check = x->compute_needs_range_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
    if (needs_range_check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
      length.set_instruction(x->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
      length.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
  array.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
  if (index.is_constant() && can_inline_as_constant(x->index())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
    // let it be a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
    index.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
    index.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
  CodeEmitInfo* range_check_info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
  CodeEmitInfo* null_check_info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
  if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
    if (nc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
      null_check_info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
      null_check_info = range_check_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  // emit array address setup early so it schedules better
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
  LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
  if (GenerateRangeChecks && needs_range_check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
    if (use_length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
      // TODO: use a (modified) version of array_range_check that does not require a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
      //       constant length to be loaded to a register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
      __ cmp(lir_cond_belowEqual, length.result(), index.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
      __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
      array_range_check(array.result(), index.result(), null_check_info, range_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
      // The range check performs the null check, so clear it out for the load
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
      null_check_info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
  __ move(array_addr, rlock_result(x, x->elt_type()), null_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
void LIRGenerator::do_NullCheck(NullCheck* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
  if (x->can_trap()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
    LIRItem value(x->obj(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
    value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
    CodeEmitInfo* info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
    __ null_check(value.result(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
void LIRGenerator::do_Throw(Throw* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
  LIRItem exception(x->exception(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
  exception.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
  LIR_Opr exception_opr = exception.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
  CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
  if (PrintC1Statistics) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
    increment_counter(Runtime1::throw_count_address());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  // check if the instruction has an xhandler in any of the nested scopes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
  bool unwind = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
  if (info->exception_handlers()->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
    // this throw is not inside an xhandler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
    unwind = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
    // get some idea of the throw type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    bool type_is_exact = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
    ciType* throw_type = x->exception()->exact_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
    if (throw_type == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
      type_is_exact = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
      throw_type = x->exception()->declared_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
    if (throw_type != NULL && throw_type->is_instance_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
      ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
      unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
  // do null check before moving exception oop into fixed register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
  // to avoid a fixed interval with an oop during the null check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
  // Use a copy of the CodeEmitInfo because debug information is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  // different for null_check and throw.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
  if (GenerateCompilerNullChecks &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
      (x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    // if the exception object wasn't created using new then it might be null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
    __ null_check(exception_opr, new CodeEmitInfo(info, true));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  if (JvmtiExport::can_post_exceptions() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
      !block()->is_set(BlockBegin::default_exception_handler_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
    // we need to go through the exception lookup path to get JVMTI
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
    // notification done
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
    unwind = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  assert(!block()->is_set(BlockBegin::default_exception_handler_flag) || unwind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
         "should be no more handlers to dispatch to");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
  if (DTraceMethodProbes &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
      block()->is_set(BlockBegin::default_exception_handler_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
    // notify that this frame is unwinding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
    BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
    signature.append(T_INT);    // thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
    signature.append(T_OBJECT); // methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
    LIR_OprList* args = new LIR_OprList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
    args->append(getThreadPointer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
    LIR_Opr meth = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
    __ oop2reg(method()->encoding(), meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    args->append(meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
    call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
  // move exception oop into fixed register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
  __ move(exception_opr, exceptionOopOpr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
  if (unwind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
    __ unwind_exception(LIR_OprFact::illegalOpr, exceptionOopOpr(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
    __ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
void LIRGenerator::do_RoundFP(RoundFP* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
  LIRItem input(x->input(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
  input.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
  LIR_Opr input_opr = input.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
  assert(input_opr->is_register(), "why round if value is not in a register?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
  assert(input_opr->is_single_fpu() || input_opr->is_double_fpu(), "input should be floating-point value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  if (input_opr->is_single_fpu()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    set_result(x, round_item(input_opr)); // This code path not currently taken
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
    LIR_Opr result = new_register(T_DOUBLE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
    set_vreg_flag(result, must_start_in_memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
    __ roundfp(input_opr, LIR_OprFact::illegalOpr, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
    set_result(x, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
void LIRGenerator::do_UnsafeGetRaw(UnsafeGetRaw* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
  LIRItem base(x->base(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
  LIRItem idx(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
  base.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
    idx.set_instruction(x->index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
    idx.load_nonconstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
  LIR_Opr reg = rlock_result(x, x->basic_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
  int   log2_scale = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
    assert(x->index()->type()->tag() == intTag, "should not find non-int index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
    log2_scale = x->log2_scale();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
  assert(!x->has_index() || idx.value() == x->index(), "should match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
  LIR_Opr base_op = base.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
  if (x->base()->type()->tag() == longTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
    base_op = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
    __ convert(Bytecodes::_l2i, base.result(), base_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
    assert(x->base()->type()->tag() == intTag, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
  BasicType dst_type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
  LIR_Opr index_op = idx.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
  LIR_Address* addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
  if (index_op->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
    assert(log2_scale == 0, "must not have a scale");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
    addr = new LIR_Address(base_op, index_op->as_jint(), dst_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
  } else {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
  1861
#ifdef X86
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
    addr = new LIR_Address(base_op, index_op, LIR_Address::Scale(log2_scale), 0, dst_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
    if (index_op->is_illegal() || log2_scale == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
      addr = new LIR_Address(base_op, index_op, dst_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
      LIR_Opr tmp = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
      __ shift_left(index_op, log2_scale, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
      addr = new LIR_Address(base_op, tmp, dst_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  if (x->may_be_unaligned() && (dst_type == T_LONG || dst_type == T_DOUBLE)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
    __ unaligned_move(addr, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
    __ move(addr, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
void LIRGenerator::do_UnsafePutRaw(UnsafePutRaw* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
  int  log2_scale = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
  BasicType type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
    assert(x->index()->type()->tag() == intTag, "should not find non-int index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
    log2_scale = x->log2_scale();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
  LIRItem base(x->base(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  LIRItem value(x->value(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
  LIRItem idx(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
  base.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
    idx.set_instruction(x->index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
    idx.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
  if (type == T_BYTE || type == T_BOOLEAN) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
    value.load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
    value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
  LIR_Opr base_op = base.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
  if (x->base()->type()->tag() == longTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
    base_op = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
    __ convert(Bytecodes::_l2i, base.result(), base_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
    assert(x->base()->type()->tag() == intTag, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
  LIR_Opr index_op = idx.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
  if (log2_scale != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
    // temporary fix (platform dependent code without shift on Intel would be better)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
    index_op = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
    __ move(idx.result(), index_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
    __ shift_left(index_op, log2_scale, index_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
  LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
  __ move(value.result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
  BasicType type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
  LIRItem src(x->object(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
  LIRItem off(x->offset(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
  off.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
  src.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
  LIR_Opr reg = reg = rlock_result(x, x->basic_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
  if (x->is_volatile() && os::is_MP()) __ membar_acquire();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
  get_Object_unsafe(reg, src.result(), off.result(), type, x->is_volatile());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
  if (x->is_volatile() && os::is_MP()) __ membar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
  BasicType type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
  LIRItem src(x->object(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
  LIRItem off(x->offset(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
  LIRItem data(x->value(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
  src.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
  if (type == T_BOOLEAN || type == T_BYTE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
    data.load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
    data.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
  off.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
  if (x->is_volatile() && os::is_MP()) __ membar_release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
  put_Object_unsafe(src.result(), off.result(), data.result(), type, x->is_volatile());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
void LIRGenerator::do_UnsafePrefetch(UnsafePrefetch* x, bool is_store) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
  LIRItem src(x->object(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
  LIRItem off(x->offset(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
  src.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
  if (off.is_constant() && can_inline_as_constant(x->offset())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
    // let it be a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
    off.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
    off.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
  LIR_Address* addr = generate_address(src.result(), off.result(), 0, 0, T_BYTE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
  __ prefetch(addr, is_store);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
void LIRGenerator::do_UnsafePrefetchRead(UnsafePrefetchRead* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
  do_UnsafePrefetch(x, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
void LIRGenerator::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
  do_UnsafePrefetch(x, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
  int lng = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
  for (int i = 0; i < lng; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
    SwitchRange* one_range = x->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
    int low_key = one_range->low_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
    int high_key = one_range->high_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
    BlockBegin* dest = one_range->sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
    if (low_key == high_key) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
      __ cmp(lir_cond_equal, value, low_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
      __ branch(lir_cond_equal, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
    } else if (high_key - low_key == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
      __ cmp(lir_cond_equal, value, low_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
      __ branch(lir_cond_equal, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
      __ cmp(lir_cond_equal, value, high_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
      __ branch(lir_cond_equal, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
      LabelObj* L = new LabelObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
      __ cmp(lir_cond_less, value, low_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
      __ branch(lir_cond_less, L->label());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
      __ cmp(lir_cond_lessEqual, value, high_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
      __ branch(lir_cond_lessEqual, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
      __ branch_destination(L->label());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
  __ jump(default_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
  SwitchRangeList* res = new SwitchRangeList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
  int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
  if (len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
    BlockBegin* sux = x->sux_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
    int key = x->lo_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
    BlockBegin* default_sux = x->default_sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
    SwitchRange* range = new SwitchRange(key, sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
    for (int i = 0; i < len; i++, key++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
      BlockBegin* new_sux = x->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
      if (sux == new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
        // still in same range
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
        range->set_high_key(key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
        // skip tests which explicitly dispatch to the default
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
        if (sux != default_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
          res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
        range = new SwitchRange(key, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
      sux = new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
    if (res->length() == 0 || res->last() != range)  res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
// we expect the keys to be sorted by increasing value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
  SwitchRangeList* res = new SwitchRangeList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
  int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
  if (len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
    BlockBegin* default_sux = x->default_sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
    int key = x->key_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
    BlockBegin* sux = x->sux_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
    SwitchRange* range = new SwitchRange(key, sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
    for (int i = 1; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
      int new_key = x->key_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
      BlockBegin* new_sux = x->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
      if (key+1 == new_key && sux == new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
        // still in same range
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
        range->set_high_key(new_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
        // skip tests which explicitly dispatch to the default
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
        if (range->sux() != default_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
          res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
        range = new SwitchRange(new_key, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
      key = new_key;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
      sux = new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
    if (res->length() == 0 || res->last() != range)  res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
void LIRGenerator::do_TableSwitch(TableSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
  LIRItem tag(x->tag(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
  tag.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
  if (x->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
    __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
  // move values into phi locations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
  move_to_phi(x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
  int lo_key = x->lo_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
  int hi_key = x->hi_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
  int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
  CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
  LIR_Opr value = tag.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
  if (UseTableRanges) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
    do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
      __ cmp(lir_cond_equal, value, i + lo_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
      __ branch(lir_cond_equal, T_INT, x->sux_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
    __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
void LIRGenerator::do_LookupSwitch(LookupSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
  LIRItem tag(x->tag(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
  tag.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
  if (x->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
    __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
  // move values into phi locations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
  move_to_phi(x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
  LIR_Opr value = tag.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
  if (UseTableRanges) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
    do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
    int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
      __ cmp(lir_cond_equal, value, x->key_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
      __ branch(lir_cond_equal, T_INT, x->sux_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
    __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
void LIRGenerator::do_Goto(Goto* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
  if (block()->next()->as_OsrEntry()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
    // need to free up storage used for OSR entry point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
    LIR_Opr osrBuffer = block()->next()->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
    BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
    signature.append(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
    CallingConvention* cc = frame_map()->c_calling_convention(&signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
    __ move(osrBuffer, cc->args()->at(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
    __ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
                         getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
  if (x->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
    ValueStack* state = x->state_before() ? x->state_before() : x->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
    // increment backedge counter if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
    increment_backedge_counter(state_for(x, state));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
    CodeEmitInfo* safepoint_info = state_for(x, state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
    __ safepoint(safepoint_poll_register(), safepoint_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
  // emit phi-instruction move after safepoint since this simplifies
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
  // describing the state as the safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
  move_to_phi(x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
  __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
void LIRGenerator::do_Base(Base* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
  __ std_entry(LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
  // Emit moves from physical registers / stack slots to virtual registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
  CallingConvention* args = compilation()->frame_map()->incoming_arguments();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
  IRScope* irScope = compilation()->hir()->top_scope();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
  int java_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
  for (int i = 0; i < args->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
    LIR_Opr src = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
    assert(!src->is_illegal(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
    BasicType t = src->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
    // Types which are smaller than int are passed as int, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
    // correct the type which passed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2186
    switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
    case T_BYTE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
    case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
    case T_SHORT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
    case T_CHAR:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
      t = T_INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
    LIR_Opr dest = new_register(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
    __ move(src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
    // Assign new location to Local instruction for this local
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
    Local* local = x->state()->local_at(java_index)->as_Local();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
    assert(local != NULL, "Locals for incoming arguments must have been created");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
    assert(as_ValueType(t)->tag() == local->type()->tag(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
    local->set_operand(dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
    _instruction_for_operand.at_put_grow(dest->vreg_number(), local, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
    java_index += type2size[t];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
  if (DTraceMethodProbes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
    BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
    signature.append(T_INT);    // thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
    signature.append(T_OBJECT); // methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
    LIR_OprList* args = new LIR_OprList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
    args->append(getThreadPointer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
    LIR_Opr meth = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
    __ oop2reg(method()->encoding(), meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
    args->append(meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
    call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
  if (method()->is_synchronized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
    LIR_Opr obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
    if (method()->is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
      obj = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
      __ oop2reg(method()->holder()->java_mirror()->encoding(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
      Local* receiver = x->state()->local_at(0)->as_Local();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
      assert(receiver != NULL, "must already exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
      obj = receiver->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
    assert(obj->is_valid(), "must be valid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
    if (method()->is_synchronized() && GenerateSynchronizationCode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
      LIR_Opr lock = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
      __ load_stack_address_monitor(0, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
      CodeEmitInfo* info = new CodeEmitInfo(SynchronizationEntryBCI, scope()->start()->state(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
      CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
      // receiver is guaranteed non-NULL so don't need CodeEmitInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
      __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
  // increment invocation counters if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
  increment_invocation_counter(new CodeEmitInfo(0, scope()->start()->state(), NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
  // all blocks with a successor must end with an unconditional jump
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
  // to the successor even if they are consecutive
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
  __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
void LIRGenerator::do_OsrEntry(OsrEntry* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
  // construct our frame and model the production of incoming pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
  // to the OSR buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
  __ osr_entry(LIR_Assembler::osrBufferPointer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
  LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
  __ move(LIR_Assembler::osrBufferPointer(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
  int i = x->has_receiver() ? 1 : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
  for (; i < args->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
    LIRItem* param = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2265
    LIR_Opr loc = arg_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
      param->load_item_force(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2268
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2269
      LIR_Address* addr = loc->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2270
      param->load_for_store(addr->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2271
      if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2272
        __ unaligned_move(param->result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2273
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
        __ move(param->result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
  if (x->has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
    LIRItem* receiver = args->at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
    LIR_Opr loc = arg_list->at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
      receiver->load_item_force(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
      assert(loc->is_address(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
      receiver->load_for_store(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
      __ move(receiver->result(), loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
// Visits all arguments, returns appropriate items without loading them
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
  LIRItemList* argument_items = new LIRItemList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
  if (x->has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
    LIRItem* receiver = new LIRItem(x->receiver(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
    argument_items->append(receiver);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
  int idx = x->has_receiver() ? 1 : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
  for (int i = 0; i < x->number_of_arguments(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
    LIRItem* param = new LIRItem(x->argument_at(i), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
    argument_items->append(param);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
    idx += (param->type()->is_double_word() ? 2 : 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
  return argument_items;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
// The invoke with receiver has following phases:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
//   a) traverse and load/lock receiver;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
//   b) traverse all arguments -> item-array (invoke_visit_argument)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
//   c) push receiver on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
//   d) load each of the items and push on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
//   e) unlock receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
//   f) move receiver into receiver-register %o0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
//   g) lock result registers and emit call operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
// Before issuing a call, we must spill-save all values on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
// that are in caller-save register. "spill-save" moves thos registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
// either in a free callee-save register or spills them if no free
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
// callee save register is available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
// The problem is where to invoke spill-save.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
// - if invoked between e) and f), we may lock callee save
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
//   register in "spill-save" that destroys the receiver register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
//   before f) is executed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2328
// - if we rearange the f) to be earlier, by loading %o0, it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2329
//   may destroy a value on the stack that is currently in %o0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2330
//   and is waiting to be spilled
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2331
// - if we keep the receiver locked while doing spill-save,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2332
//   we cannot spill it as it is spill-locked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2333
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2334
void LIRGenerator::do_Invoke(Invoke* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2335
  CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2336
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2337
  LIR_OprList* arg_list = cc->args();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2338
  LIRItemList* args = invoke_visit_arguments(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2339
  LIR_Opr receiver = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2340
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2341
  // setup result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2342
  LIR_Opr result_register = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2343
  if (x->type() != voidType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2344
    result_register = result_register_for(x->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2345
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2346
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2347
  CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2348
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2349
  invoke_load_arguments(x, args, arg_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2350
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2351
  if (x->has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2352
    args->at(0)->load_item_force(LIR_Assembler::receiverOpr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2353
    receiver = args->at(0)->result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2355
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2356
  // emit invoke code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2357
  bool optimized = x->target_is_loaded() && x->target_is_final();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2358
  assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2359
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2360
  switch (x->code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2361
    case Bytecodes::_invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2362
      __ call_static(x->target(), result_register,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2363
                     SharedRuntime::get_resolve_static_call_stub(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2364
                     arg_list, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2365
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2366
    case Bytecodes::_invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2367
    case Bytecodes::_invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2368
    case Bytecodes::_invokeinterface:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2369
      // for final target we still produce an inline cache, in order
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2370
      // to be able to call mixed mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2371
      if (x->code() == Bytecodes::_invokespecial || optimized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2372
        __ call_opt_virtual(x->target(), receiver, result_register,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2373
                            SharedRuntime::get_resolve_opt_virtual_call_stub(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2374
                            arg_list, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2375
      } else if (x->vtable_index() < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2376
        __ call_icvirtual(x->target(), receiver, result_register,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2377
                          SharedRuntime::get_resolve_virtual_call_stub(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2378
                          arg_list, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2379
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2380
        int entry_offset = instanceKlass::vtable_start_offset() + x->vtable_index() * vtableEntry::size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2381
        int vtable_offset = entry_offset * wordSize + vtableEntry::method_offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2382
        __ call_virtual(x->target(), receiver, result_register, vtable_offset, arg_list, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2383
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2384
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2385
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2386
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2387
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2389
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2390
  if (x->type()->is_float() || x->type()->is_double()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2391
    // Force rounding of results from non-strictfp when in strictfp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2392
    // scope (or when we don't know the strictness of the callee, to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2393
    // be safe.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2394
    if (method()->is_strict()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2395
      if (!x->target_is_loaded() || !x->target_is_strictfp()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2396
        result_register = round_item(result_register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2397
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2398
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2399
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2400
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2401
  if (result_register->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2402
    LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2403
    __ move(result_register, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2404
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2405
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2406
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2407
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2408
void LIRGenerator::do_FPIntrinsics(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2409
  assert(x->number_of_arguments() == 1, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2410
  LIRItem value       (x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2411
  LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2412
  value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2413
  LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2414
  __ move(tmp, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2415
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2416
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2417
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2418
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2419
// Code for  :  x->x() {x->cond()} x->y() ? x->tval() : x->fval()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2420
void LIRGenerator::do_IfOp(IfOp* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2421
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2422
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2423
    ValueTag xtag = x->x()->type()->tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2424
    ValueTag ttag = x->tval()->type()->tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2425
    assert(xtag == intTag || xtag == objectTag, "cannot handle others");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2426
    assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2427
    assert(ttag == x->fval()->type()->tag(), "cannot handle others");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2428
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2429
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2431
  LIRItem left(x->x(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2432
  LIRItem right(x->y(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2433
  left.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2434
  if (can_inline_as_constant(right.value())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2435
    right.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2436
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2437
    right.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2438
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2439
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2440
  LIRItem t_val(x->tval(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2441
  LIRItem f_val(x->fval(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2442
  t_val.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2443
  f_val.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2444
  LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2445
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2446
  __ cmp(lir_cond(x->cond()), left.result(), right.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2447
  __ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2448
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2449
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2450
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2451
void LIRGenerator::do_Intrinsic(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2452
  switch (x->id()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2453
  case vmIntrinsics::_intBitsToFloat      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2454
  case vmIntrinsics::_doubleToRawLongBits :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2455
  case vmIntrinsics::_longBitsToDouble    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2456
  case vmIntrinsics::_floatToRawIntBits   : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2457
    do_FPIntrinsics(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2458
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2459
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2460
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2461
  case vmIntrinsics::_currentTimeMillis: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2462
    assert(x->number_of_arguments() == 0, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2463
    LIR_Opr reg = result_register_for(x->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2464
    __ call_runtime_leaf(CAST_FROM_FN_PTR(address, os::javaTimeMillis), getThreadTemp(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2465
                         reg, new LIR_OprList());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2466
    LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2467
    __ move(reg, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2468
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2469
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2470
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2471
  case vmIntrinsics::_nanoTime: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2472
    assert(x->number_of_arguments() == 0, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2473
    LIR_Opr reg = result_register_for(x->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2474
    __ call_runtime_leaf(CAST_FROM_FN_PTR(address, os::javaTimeNanos), getThreadTemp(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2475
                         reg, new LIR_OprList());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2476
    LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2477
    __ move(reg, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2478
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2479
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2480
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2481
  case vmIntrinsics::_Object_init:    do_RegisterFinalizer(x); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2482
  case vmIntrinsics::_getClass:       do_getClass(x);      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2483
  case vmIntrinsics::_currentThread:  do_currentThread(x); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2484
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2485
  case vmIntrinsics::_dlog:           // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2486
  case vmIntrinsics::_dlog10:         // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2487
  case vmIntrinsics::_dabs:           // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2488
  case vmIntrinsics::_dsqrt:          // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2489
  case vmIntrinsics::_dtan:           // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2490
  case vmIntrinsics::_dsin :          // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2491
  case vmIntrinsics::_dcos :          do_MathIntrinsic(x); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2492
  case vmIntrinsics::_arraycopy:      do_ArrayCopy(x);     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2493
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2494
  // java.nio.Buffer.checkIndex
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2495
  case vmIntrinsics::_checkIndex:     do_NIOCheckIndex(x); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2496
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2497
  case vmIntrinsics::_compareAndSwapObject:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2498
    do_CompareAndSwap(x, objectType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2499
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2500
  case vmIntrinsics::_compareAndSwapInt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2501
    do_CompareAndSwap(x, intType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2502
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2503
  case vmIntrinsics::_compareAndSwapLong:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2504
    do_CompareAndSwap(x, longType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2505
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2506
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2507
    // sun.misc.AtomicLongCSImpl.attemptUpdate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2508
  case vmIntrinsics::_attemptUpdate:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2509
    do_AttemptUpdate(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2510
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2511
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2512
  default: ShouldNotReachHere(); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2513
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2514
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2515
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2516
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2517
void LIRGenerator::do_ProfileCall(ProfileCall* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2518
  // Need recv in a temporary register so it interferes with the other temporaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2519
  LIR_Opr recv = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2520
  LIR_Opr mdo = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2521
  LIR_Opr tmp = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2522
  if (x->recv() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2523
    LIRItem value(x->recv(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2524
    value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2525
    recv = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2526
    __ move(value.result(), recv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2527
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2528
  __ profile_call(x->method(), x->bci_of_invoke(), mdo, recv, tmp, x->known_holder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2529
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2530
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2531
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2532
void LIRGenerator::do_ProfileCounter(ProfileCounter* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2533
  LIRItem mdo(x->mdo(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2534
  mdo.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2535
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2536
  increment_counter(new LIR_Address(mdo.result(), x->offset(), T_INT), x->increment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2537
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2538
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2539
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2540
LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2541
  LIRItemList args(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2542
  LIRItem value(arg1, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2543
  args.append(&value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2544
  BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2545
  signature.append(as_BasicType(arg1->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2546
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2547
  return call_runtime(&signature, &args, entry, result_type, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2548
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2549
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2550
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2551
LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2552
  LIRItemList args(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2553
  LIRItem value1(arg1, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2554
  LIRItem value2(arg2, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2555
  args.append(&value1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2556
  args.append(&value2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2557
  BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2558
  signature.append(as_BasicType(arg1->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2559
  signature.append(as_BasicType(arg2->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2560
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2561
  return call_runtime(&signature, &args, entry, result_type, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2562
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2563
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2564
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2565
LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2566
                                   address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2567
  // get a result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2568
  LIR_Opr phys_reg = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2569
  LIR_Opr result = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2570
  if (result_type->tag() != voidTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2571
    result = new_register(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2572
    phys_reg = result_register_for(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2573
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2574
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2575
  // move the arguments into the correct location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2576
  CallingConvention* cc = frame_map()->c_calling_convention(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2577
  assert(cc->length() == args->length(), "argument mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2578
  for (int i = 0; i < args->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2579
    LIR_Opr arg = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2580
    LIR_Opr loc = cc->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2581
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2582
      __ move(arg, loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2583
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2584
      LIR_Address* addr = loc->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2585
//           if (!can_store_as_constant(arg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2586
//             LIR_Opr tmp = new_register(arg->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2587
//             __ move(arg, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2588
//             arg = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2589
//           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2590
      if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2591
        __ unaligned_move(arg, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2592
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2593
        __ move(arg, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2594
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2595
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2596
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2597
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2598
  if (info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2599
    __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2600
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2601
    __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2602
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2603
  if (result->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2604
    __ move(phys_reg, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2605
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2606
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2607
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2608
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2609
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2610
LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2611
                                   address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2612
  // get a result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2613
  LIR_Opr phys_reg = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2614
  LIR_Opr result = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2615
  if (result_type->tag() != voidTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2616
    result = new_register(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2617
    phys_reg = result_register_for(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2619
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2620
  // move the arguments into the correct location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2621
  CallingConvention* cc = frame_map()->c_calling_convention(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2622
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2623
  assert(cc->length() == args->length(), "argument mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2624
  for (int i = 0; i < args->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2625
    LIRItem* arg = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2626
    LIR_Opr loc = cc->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2627
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2628
      arg->load_item_force(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2629
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2630
      LIR_Address* addr = loc->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2631
      arg->load_for_store(addr->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2632
      if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2633
        __ unaligned_move(arg->result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2634
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2635
        __ move(arg->result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2636
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2637
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2638
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2639
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2640
  if (info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2641
    __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2642
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2643
    __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2644
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2645
  if (result->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2646
    __ move(phys_reg, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2647
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2648
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2649
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2650
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2651
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2652
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2653
void LIRGenerator::increment_invocation_counter(CodeEmitInfo* info, bool backedge) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2654
#ifdef TIERED
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2655
  if (_compilation->env()->comp_level() == CompLevel_fast_compile &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2656
      (method()->code_size() >= Tier1BytecodeLimit || backedge)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2657
    int limit = InvocationCounter::Tier1InvocationLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2658
    int offset = in_bytes(methodOopDesc::invocation_counter_offset() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2659
                          InvocationCounter::counter_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2660
    if (backedge) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2661
      limit = InvocationCounter::Tier1BackEdgeLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2662
      offset = in_bytes(methodOopDesc::backedge_counter_offset() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2663
                        InvocationCounter::counter_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2664
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2665
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2666
    LIR_Opr meth = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2667
    __ oop2reg(method()->encoding(), meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2668
    LIR_Opr result = increment_and_return_counter(meth, offset, InvocationCounter::count_increment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2669
    __ cmp(lir_cond_aboveEqual, result, LIR_OprFact::intConst(limit));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2670
    CodeStub* overflow = new CounterOverflowStub(info, info->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2671
    __ branch(lir_cond_aboveEqual, T_INT, overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2672
    __ branch_destination(overflow->continuation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2673
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2674
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2675
}