hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
author roland
Tue, 22 Oct 2013 09:51:47 +0200
changeset 21095 1a04f7b3946e
parent 21088 4f0ada6dcace
child 21102 1dd11ccfe9da
permissions -rw-r--r--
8026251: New type profiling points: parameters to methods Summary: x86 interpreter and c1 type profiling for parameters on method entries Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5334
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5334
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5334
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    26
#include "c1/c1_Compilation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    27
#include "c1/c1_FrameMap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    28
#include "c1/c1_Instruction.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    29
#include "c1/c1_LIRAssembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    30
#include "c1/c1_LIRGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    31
#include "c1/c1_ValueStack.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    32
#include "ci/ciArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    33
#include "ci/ciInstance.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
    34
#include "ci/ciObjArray.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    35
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    36
#include "runtime/stubRoutines.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    37
#include "utilities/bitMap.inline.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
    38
#include "utilities/macros.hpp"
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
    39
#if INCLUDE_ALL_GCS
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6970
diff changeset
    40
#include "gc_implementation/g1/heapRegion.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
    41
#endif // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
#define __ gen()->lir(__FILE__, __LINE__)->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
#define __ gen()->lir()->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
    49
// TODO: ARM - Use some recognizable constant which still fits architectural constraints
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
    50
#ifdef ARM
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
    51
#define PATCHED_ADDR  (204)
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
    52
#else
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
    53
#define PATCHED_ADDR  (max_jint)
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
    54
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
void PhiResolverState::reset(int max_vregs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Initialize array sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  _virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _virtual_operands.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _other_operands.at_put_grow(max_vregs - 1, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _other_operands.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _vreg_table.at_put_grow(max_vregs - 1, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _vreg_table.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
//--------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
// PhiResolver
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// Resolves cycles:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
//  r1 := r2  becomes  temp := r1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
//  r2 := r1           r1 := r2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
//                     r2 := temp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// and orders moves:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//  r2 := r3  becomes  r1 := r2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
//  r1 := r2           r2 := r3
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
PhiResolver::PhiResolver(LIRGenerator* gen, int max_vregs)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
 : _gen(gen)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
 , _state(gen->resolver_state())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
 , _temp(LIR_OprFact::illegalOpr)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // reinitialize the shared state arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  _state.reset(max_vregs);
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
void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  assert(src->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  assert(dest->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  __ move(src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
void PhiResolver::move_temp_to(LIR_Opr dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  assert(_temp->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  emit_move(_temp, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
void PhiResolver::move_to_temp(LIR_Opr src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  assert(_temp->is_illegal(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  _temp = _gen->new_register(src->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  emit_move(src, _temp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// Traverse assignment graph in depth first order and generate moves in post order
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// ie. two assignments: b := c, a := b start with node c:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// Call graph: move(NULL, c) -> move(c, b) -> move(b, a)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// Generates moves in this order: move b to a and move c to b
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// ie. cycle a := b, b := a start with node a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// Call graph: move(NULL, a) -> move(a, b) -> move(b, a)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// Generates moves in this order: move b to temp, move a to b, move temp to a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
void PhiResolver::move(ResolveNode* src, ResolveNode* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  if (!dest->visited()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    dest->set_visited();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    for (int i = dest->no_of_destinations()-1; i >= 0; i --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      move(dest, dest->destination_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  } else if (!dest->start_node()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    // cylce in graph detected
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    assert(_loop == NULL, "only one loop valid!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    _loop = dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    move_to_temp(src->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  } // else dest is a start node
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  if (!dest->assigned()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (_loop == dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      move_temp_to(dest->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      dest->set_assigned();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    } else if (src != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      emit_move(src->operand(), dest->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      dest->set_assigned();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
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
PhiResolver::~PhiResolver() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // resolve any cycles in moves from and to virtual registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  for (i = virtual_operands().length() - 1; i >= 0; i --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    ResolveNode* node = virtual_operands()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    if (!node->visited()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      _loop = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      move(NULL, node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      node->set_start_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      assert(_temp->is_illegal(), "move_temp_to() call missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // generate move for move from non virtual register to abitrary destination
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  for (i = other_operands().length() - 1; i >= 0; i --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    ResolveNode* node = other_operands()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    for (int j = node->no_of_destinations() - 1; j >= 0; j --) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      emit_move(node->operand(), node->destination_at(j)->operand());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  ResolveNode* node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  if (opr->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    int vreg_num = opr->vreg_number();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    node = vreg_table().at_grow(vreg_num, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    assert(node == NULL || node->operand() == opr, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    if (node == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      node = new ResolveNode(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      vreg_table()[vreg_num] = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    // Make sure that all virtual operands show up in the list when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // they are used as the source of a move.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    if (source && !virtual_operands().contains(node)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      virtual_operands().append(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    assert(source, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    node = new ResolveNode(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    other_operands().append(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  return node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
void PhiResolver::move(LIR_Opr src, LIR_Opr dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  assert(dest->is_virtual(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  // tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  assert(src->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  assert(dest->is_valid(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  ResolveNode* source = source_node(src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  source->append(destination_node(dest));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
//--------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// LIRItem
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
void LIRItem::set_result(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  value()->set_operand(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  if (opr->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    _gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  _result = opr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
void LIRItem::load_item() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if (result()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    // update the items result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    _result = value()->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  if (!result()->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    LIR_Opr reg = _gen->new_register(value()->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    __ move(result(), reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    if (result()->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      _result = reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      set_result(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
void LIRItem::load_for_store(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (_gen->can_store_as_constant(value(), type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    _result = value()->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    if (!_result->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      _result = LIR_OprFact::value_type(value()->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  } else if (type == T_BYTE || type == T_BOOLEAN) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
void LIRItem::load_item_force(LIR_Opr reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  LIR_Opr r = result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  if (r != reg) {
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
   249
#if !defined(ARM) && !defined(E500V2)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    if (r->type() != reg->type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      // moves between different types need an intervening spill slot
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
   252
      r = _gen->force_to_spill(r, reg->type());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
   254
#endif
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
   255
    __ move(r, reg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    _result = reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
ciObject* LIRItem::get_jobject_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  ObjectType* oc = type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  if (oc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    return oc->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  return NULL;
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
jint LIRItem::get_jint_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_IntConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  return type()->as_IntConstant()->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
jint LIRItem::get_address_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_AddressConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  return type()->as_AddressConstant()->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
jfloat LIRItem::get_jfloat_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  assert(type()->as_FloatConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  return type()->as_FloatConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
jdouble LIRItem::get_jdouble_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  assert(type()->as_DoubleConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  return type()->as_DoubleConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
jlong LIRItem::get_jlong_constant() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  assert(is_constant() && value() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  assert(type()->as_LongConstant() != NULL, "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  return type()->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
//--------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
void LIRGenerator::init() {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   309
  _bs = Universe::heap()->barrier_set();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
void LIRGenerator::block_do_prolog(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  if (PrintIRWithLIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    block->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  // set up the list of LIR instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  assert(block->lir() == NULL, "LIR list already computed for this block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  _lir = new LIR_List(compilation(), block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  block->set_lir(_lir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  __ branch_destination(block->label());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  if (LIRTraceExecution &&
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5702
diff changeset
   328
      Compilation::current()->hir()->start()->block_id() != block->block_id() &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      !block->is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    trace_block_entry(block);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
void LIRGenerator::block_do_epilog(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  if (PrintIRWithLIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // LIR_Opr for unpinned constants shouldn't be referenced by other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // blocks so clear them out after processing the block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  for (int i = 0; i < _unpinned_constants.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    _unpinned_constants.at(i)->clear_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  _unpinned_constants.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  // clear our any registers for other local constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  _constants.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  _reg_for_constants.trunc_to(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
void LIRGenerator::block_do(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  block_do_prolog(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  set_block(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  for (Instruction* instr = block; instr != NULL; instr = instr->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    if (instr->is_pinned()) do_root(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  set_block(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  block_do_epilog(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
//-------------------------LIRGenerator-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
// This is where the tree-walk starts; instr must be root;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
void LIRGenerator::do_root(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  InstructionMark im(compilation(), instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  assert(instr->is_pinned(), "use only with roots");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  assert(instr->subst() == instr, "shouldn't have missed substitution");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  instr->visit(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  assert(!instr->has_uses() || instr->operand()->is_valid() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
         instr->as_Constant() != NULL || bailed_out(), "invalid item set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
// This is called for each node in tree; the walk stops if a root is reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
void LIRGenerator::walk(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  InstructionMark im(compilation(), instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  //stop walk when encounter a root
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  if (instr->is_pinned() && instr->as_Phi() == NULL || instr->operand()->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != NULL, "this root has not yet been visited");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    assert(instr->subst() == instr, "shouldn't have missed substitution");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    instr->visit(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    // assert(instr->use_count() > 0 || instr->as_Phi() != NULL, "leaf instruction must have a use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   404
  assert(state != NULL, "state must be defined");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   405
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
   406
#ifndef PRODUCT
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
   407
  state->verify();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
   408
#endif
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
   409
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   410
  ValueStack* s = state;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   411
  for_each_state(s) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   412
    if (s->kind() == ValueStack::EmptyExceptionState) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   413
      assert(s->stack_size() == 0 && s->locals_size() == 0 && (s->locks_size() == 0 || s->locks_size() == 1), "state must be empty");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   414
      continue;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   416
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   417
    int index;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   418
    Value value;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   419
    for_each_stack_value(s, index, value) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   420
      assert(value->subst() == value, "missed substitution");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   421
      if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   422
        walk(value);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   423
        assert(value->operand()->is_valid(), "must be evaluated now");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   424
      }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   425
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   426
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   427
    int bci = s->bci();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    IRScope* scope = s->scope();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    ciMethod* method = scope->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    MethodLivenessResult liveness = method->liveness_at_bci(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    if (bci == SynchronizationEntryBCI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
      if (x->as_ExceptionObject() || x->as_Throw()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
        // all locals are dead on exit from the synthetic unlocker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
        liveness.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      } else {
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10730
diff changeset
   437
        assert(x->as_MonitorEnter() || x->as_ProfileInvoke(), "only other cases are MonitorEnter and ProfileInvoke");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    if (!liveness.is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      // Degenerate or breakpointed method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      bailout("Degenerate or breakpointed method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
      assert((int)liveness.size() == s->locals_size(), "error in use of liveness");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      for_each_local_value(s, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        assert(value->subst() == value, "missed substition");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        if (liveness.at(index) && !value->type()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
          if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
            walk(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
            assert(value->operand()->is_valid(), "must be evaluated now");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
          // NULL out this local so that linear scan can assume that all non-NULL values are live.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
          s->invalidate_local(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
   460
  return new CodeEmitInfo(state, ignore_xhandler ? NULL : x->exception_handlers(), x->check_flag(Instruction::DeoptimizeOnException));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
CodeEmitInfo* LIRGenerator::state_for(Instruction* x) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
   465
  return state_for(x, x->exception_state());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   469
void LIRGenerator::klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  if (!obj->is_loaded() || PatchALot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    assert(info != NULL, "info must be set if class is not loaded");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   472
    __ klass2reg_patch(NULL, r, info);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    // no patching needed
13742
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
   475
    __ metadata2reg(obj->constant_encoding(), r);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
                                    CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  CodeStub* stub = new RangeCheckStub(range_check_info, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  if (index->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
                index->as_jint(), null_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    cmp_reg_mem(lir_cond_aboveEqual, index, array,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
                arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
void LIRGenerator::nio_range_check(LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  CodeStub* stub = new RangeCheckStub(info, index, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  if (index->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    cmp_mem_int(lir_cond_belowEqual, buffer, java_nio_Buffer::limit_offset(), index->as_jint(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    cmp_reg_mem(lir_cond_aboveEqual, index, buffer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
                java_nio_Buffer::limit_offset(), T_INT, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  __ move(index, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
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
   511
  LIR_Opr result_op = result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  LIR_Opr left_op   = left;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  LIR_Opr right_op  = right;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  if (TwoOperandLIRForm && left_op != result_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    assert(right_op != result_op, "malformed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    __ move(left_op, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    left_op = result_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  switch(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    case Bytecodes::_dadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    case Bytecodes::_fadd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    case Bytecodes::_ladd:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    case Bytecodes::_iadd:  __ add(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    case Bytecodes::_fmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    case Bytecodes::_lmul:  __ mul(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    case Bytecodes::_dmul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
        if (is_strictfp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
          __ mul_strictfp(left_op, right_op, result_op, tmp_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
          __ mul(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    case Bytecodes::_imul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
        bool    did_strength_reduce = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
        if (right->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
          int c = right->as_jint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
          if (is_power_of_2(c)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
            // do not need tmp here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
            __ shift_left(left_op, exact_log2(c), result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
            did_strength_reduce = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
            did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
        // we couldn't strength reduce so just emit the multiply
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
        if (!did_strength_reduce) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
          __ mul(left_op, right_op, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    case Bytecodes::_dsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    case Bytecodes::_fsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    case Bytecodes::_lsub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    // ldiv and lrem are implemented with a direct runtime call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    case Bytecodes::_ddiv:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
        if (is_strictfp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
          __ div_strictfp (left_op, right_op, result_op, tmp_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
          __ div (left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
    case Bytecodes::_drem:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    default: ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
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
   587
  arithmetic_op(code, result, left, right, false, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
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
   592
  arithmetic_op(code, result, left, right, false, LIR_OprFact::illegalOpr, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
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
   597
  arithmetic_op(code, result, left, right, is_strictfp, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
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
   602
  if (TwoOperandLIRForm && value != result_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    assert(count != result_op, "malformed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    __ move(value, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    value = result_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  assert(count->is_constant() || count->is_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  switch(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  case Bytecodes::_ishl:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  case Bytecodes::_ishr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  case Bytecodes::_iushr:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break;
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::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  if (TwoOperandLIRForm && left_op != result_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    assert(right_op != result_op, "malformed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    __ move(left_op, result_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    left_op = result_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  switch(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    case Bytecodes::_iand:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    case Bytecodes::_land:  __ logical_and(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    case Bytecodes::_ior:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    case Bytecodes::_lor:   __ logical_or(left_op, right_op, result_op);  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    case Bytecodes::_ixor:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    case Bytecodes::_lxor:  __ logical_xor(left_op, right_op, result_op); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    default: ShouldNotReachHere();
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
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
   644
  if (!GenerateSynchronizationCode) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  // for slow path, use debug info for state after successful locking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  CodeStub* slow_path = new MonitorEnterStub(object, lock, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  __ load_stack_address_monitor(monitor_no, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  // for handling NullPointerException, use debug info representing just the lock stack before this monitorenter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  __ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
   653
void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, LIR_Opr scratch, int monitor_no) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  if (!GenerateSynchronizationCode) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  // setup registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  LIR_Opr hdr = lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  lock = new_hdr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  CodeStub* slow_path = new MonitorExitStub(lock, UseFastLocking, monitor_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  __ load_stack_address_monitor(monitor_no, lock);
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
   660
  __ unlock_object(hdr, object, lock, scratch, slow_path);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
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) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   665
  klass2reg_with_patching(klass_reg, klass, info);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  // If klass is not loaded we do not know if the klass has finalizers:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  if (UseFastNewInstance && klass->is_loaded()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      && !Klass::layout_helper_needs_slow_path(klass->layout_helper())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    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
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    assert(klass->is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    // allocate space for instance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    assert(klass->size_helper() >= 0, "illegal instance size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    const int instance_size = align_object_size(klass->size_helper());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
                       oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, Runtime1::new_instance_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    __ branch(lir_cond_always, T_ILLEGAL, slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    __ branch_destination(slow_path->continuation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
static bool is_constant_zero(Instruction* inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  IntConstant* c = inst->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  if (c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    return (c->value() == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
static bool positive_constant(Instruction* inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  IntConstant* c = inst->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  if (c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    return (c->value() >= 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
static ciArrayKlass* as_array_klass(ciType* type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  if (type != NULL && type->is_array_klass() && type->is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
    return (ciArrayKlass*)type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   714
static ciType* phi_declared_type(Phi* phi) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   715
  ciType* t = phi->operand_at(0)->declared_type();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   716
  if (t == NULL) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   717
    return NULL;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   718
  }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   719
  for(int i = 1; i < phi->operand_count(); i++) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   720
    if (t != phi->operand_at(i)->declared_type()) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   721
      return NULL;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   722
    }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   723
  }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   724
  return t;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   725
}
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   726
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  Instruction* src     = x->argument_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  Instruction* src_pos = x->argument_at(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  Instruction* dst     = x->argument_at(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  Instruction* dst_pos = x->argument_at(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  Instruction* length  = x->argument_at(4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  // first try to identify the likely type of the arrays involved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  ciArrayKlass* expected_type = NULL;
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   736
  bool is_exact = false, src_objarray = false, dst_objarray = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    ciArrayKlass* src_exact_type    = as_array_klass(src->exact_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    ciArrayKlass* src_declared_type = as_array_klass(src->declared_type());
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   740
    Phi* phi;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   741
    if (src_declared_type == NULL && (phi = src->as_Phi()) != NULL) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   742
      src_declared_type = as_array_klass(phi_declared_type(phi));
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   743
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    ciArrayKlass* dst_exact_type    = as_array_klass(dst->exact_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type());
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   746
    if (dst_declared_type == NULL && (phi = dst->as_Phi()) != NULL) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   747
      dst_declared_type = as_array_klass(phi_declared_type(phi));
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   748
    }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   749
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    if (src_exact_type != NULL && src_exact_type == dst_exact_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
      // the types exactly match so the type is fully known
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
      is_exact = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
      expected_type = src_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    } else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
      ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
      ciArrayKlass* src_type = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
      if (src_exact_type != NULL && src_exact_type->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
        src_type = (ciArrayKlass*) src_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
      } else if (src_declared_type != NULL && src_declared_type->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
        src_type = (ciArrayKlass*) src_declared_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
      if (src_type != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
        if (src_type->element_type()->is_subtype_of(dst_type->element_type())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
          is_exact = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
          expected_type = dst_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    // at least pass along a good guess
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    if (expected_type == NULL) expected_type = dst_exact_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    if (expected_type == NULL) expected_type = src_declared_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    if (expected_type == NULL) expected_type = dst_declared_type;
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   773
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   774
    src_objarray = (src_exact_type && src_exact_type->is_obj_array_klass()) || (src_declared_type && src_declared_type->is_obj_array_klass());
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   775
    dst_objarray = (dst_exact_type && dst_exact_type->is_obj_array_klass()) || (dst_declared_type && dst_declared_type->is_obj_array_klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  // if a probable array type has been identified, figure out if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  // of the required checks for a fast case can be elided.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  int flags = LIR_OpArrayCopy::all_flags;
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   781
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   782
  if (!src_objarray)
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   783
    flags &= ~LIR_OpArrayCopy::src_objarray;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   784
  if (!dst_objarray)
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   785
    flags &= ~LIR_OpArrayCopy::dst_objarray;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   786
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   787
  if (!x->arg_needs_null_check(0))
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   788
    flags &= ~LIR_OpArrayCopy::src_null_check;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   789
  if (!x->arg_needs_null_check(2))
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   790
    flags &= ~LIR_OpArrayCopy::dst_null_check;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   791
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   792
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  if (expected_type != NULL) {
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   794
    Value length_limit = NULL;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   795
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   796
    IfOp* ifop = length->as_IfOp();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   797
    if (ifop != NULL) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   798
      // look for expressions like min(v, a.length) which ends up as
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   799
      //   x > y ? y : x  or  x >= y ? y : x
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   800
      if ((ifop->cond() == If::gtr || ifop->cond() == If::geq) &&
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   801
          ifop->x() == ifop->fval() &&
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   802
          ifop->y() == ifop->tval()) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   803
        length_limit = ifop->y();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   804
      }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   805
    }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   806
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   807
    // try to skip null checks and range checks
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   808
    NewArray* src_array = src->as_NewArray();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   809
    if (src_array != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
      flags &= ~LIR_OpArrayCopy::src_null_check;
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   811
      if (length_limit != NULL &&
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   812
          src_array->length() == length_limit &&
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   813
          is_constant_zero(src_pos)) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   814
        flags &= ~LIR_OpArrayCopy::src_range_check;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   815
      }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   816
    }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   817
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   818
    NewArray* dst_array = dst->as_NewArray();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   819
    if (dst_array != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
      flags &= ~LIR_OpArrayCopy::dst_null_check;
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   821
      if (length_limit != NULL &&
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   822
          dst_array->length() == length_limit &&
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   823
          is_constant_zero(dst_pos)) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   824
        flags &= ~LIR_OpArrayCopy::dst_range_check;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   825
      }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   826
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    // check from incoming constant values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    if (positive_constant(src_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
      flags &= ~LIR_OpArrayCopy::src_pos_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    if (positive_constant(dst_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
      flags &= ~LIR_OpArrayCopy::dst_pos_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    if (positive_constant(length))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
      flags &= ~LIR_OpArrayCopy::length_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    // see if the range check can be elided, which might also imply
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    // that src or dst is non-null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    ArrayLength* al = length->as_ArrayLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    if (al != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      if (al->array() == src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
        // it's the length of the source array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
        flags &= ~LIR_OpArrayCopy::length_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
        flags &= ~LIR_OpArrayCopy::src_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
        if (is_constant_zero(src_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
          flags &= ~LIR_OpArrayCopy::src_range_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
      if (al->array() == dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
        // it's the length of the destination array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
        flags &= ~LIR_OpArrayCopy::length_positive_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
        flags &= ~LIR_OpArrayCopy::dst_null_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
        if (is_constant_zero(dst_pos))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
          flags &= ~LIR_OpArrayCopy::dst_range_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    if (is_exact) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
      flags &= ~LIR_OpArrayCopy::type_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   860
  IntConstant* src_int = src_pos->type()->as_IntConstant();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   861
  IntConstant* dst_int = dst_pos->type()->as_IntConstant();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   862
  if (src_int && dst_int) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   863
    int s_offs = src_int->value();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   864
    int d_offs = dst_int->value();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   865
    if (src_int->value() >= dst_int->value()) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   866
      flags &= ~LIR_OpArrayCopy::overlapping;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   867
    }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   868
    if (expected_type != NULL) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   869
      BasicType t = expected_type->element_type()->basic_type();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   870
      int element_size = type2aelembytes(t);
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   871
      if (((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) &&
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   872
          ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0)) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   873
        flags &= ~LIR_OpArrayCopy::unaligned;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   874
      }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   875
    }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   876
  } else if (src_pos == dst_pos || is_constant_zero(dst_pos)) {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   877
    // src and dest positions are the same, or dst is zero so assume
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   878
    // nonoverlapping copy.
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   879
    flags &= ~LIR_OpArrayCopy::overlapping;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   880
  }
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 8676
diff changeset
   881
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  if (src == dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    // moving within a single array so no type checks are needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    if (flags & LIR_OpArrayCopy::type_check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
      flags &= ~LIR_OpArrayCopy::type_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  *flagsp = flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  *expected_typep = (ciArrayKlass*)expected_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
LIR_Opr LIRGenerator::round_item(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  assert(opr->is_register(), "why spill if item is not register?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  if (RoundFPResults && UseSSE < 1 && opr->is_single_fpu()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    LIR_Opr result = new_register(T_FLOAT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
    set_vreg_flag(result, must_start_in_memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    assert(opr->is_register(), "only a register can be spilled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    assert(opr->value_type()->is_float(), "rounding only for floats available");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    __ roundfp(opr, LIR_OprFact::illegalOpr, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  return opr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) {
13487
75aa4880b15f 7192167: JSR 292: C1 has old broken code which needs to be removed
twisti
parents: 13486
diff changeset
   909
  assert(type2size[t] == type2size[value->type()],
75aa4880b15f 7192167: JSR 292: C1 has old broken code which needs to be removed
twisti
parents: 13486
diff changeset
   910
         err_msg_res("size mismatch: t=%s, value->type()=%s", type2name(t), type2name(value->type())));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  if (!value->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    // force into a register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
    LIR_Opr r = new_register(value->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
    __ move(value, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    value = r;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  // create a spill location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  LIR_Opr tmp = new_register(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  set_vreg_flag(tmp, LIRGenerator::must_start_in_memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  // move from register to spill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  __ move(value, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  return tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  if (if_instr->should_profile()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
    ciMethod* method = if_instr->profiled_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    assert(method != NULL, "method should be set if branch is profiled");
7432
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7427
diff changeset
   931
    ciMethodData* md = method->method_data_or_null();
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7427
diff changeset
   932
    assert(md != NULL, "Sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
    ciProfileData* data = md->bci_to_data(if_instr->profiled_bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
    assert(data != NULL, "must have profiling data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    assert(data->is_BranchData(), "need BranchData for two-way branches");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
    int taken_count_offset     = md->byte_offset_of_slot(data, BranchData::taken_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   938
    if (if_instr->is_swapped()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   939
      int t = taken_count_offset;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   940
      taken_count_offset = not_taken_count_offset;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   941
      not_taken_count_offset = t;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   942
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   943
13742
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
   944
    LIR_Opr md_reg = new_register(T_METADATA);
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
   945
    __ metadata2reg(md->constant_encoding(), md_reg);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   946
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   947
    LIR_Opr data_offset_reg = new_pointer_register();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
    __ cmove(lir_cond(cond),
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   949
             LIR_OprFact::intptrConst(taken_count_offset),
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   950
             LIR_OprFact::intptrConst(not_taken_count_offset),
7713
1e06d2419258 7009231: C1: Incorrect CAS code for longs on SPARC 32bit
iveresov
parents: 7432
diff changeset
   951
             data_offset_reg, as_BasicType(if_instr->x()->type()));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   952
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   953
    // MDO cells are intptr_t, so the data_reg width is arch-dependent.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   954
    LIR_Opr data_reg = new_pointer_register();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   955
    LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type());
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
   956
    __ move(data_addr, data_reg);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
   957
    // Use leal instead of add to avoid destroying condition codes on x86
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
    __ leal(LIR_OprFact::address(fake_incr_value), data_reg);
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
   960
    __ move(data_reg, data_addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
// Phi technique:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
// This is about passing live values from one basic block to the other.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
// In code generated with Java it is rather rare that more than one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
// value is on the stack from one basic block to the other.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
// We optimize our technique for efficient passing of one value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
// (of type long, int, double..) but it can be extended.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
// When entering or leaving a basic block, all registers and all spill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
// slots are release and empty. We use the released registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
// and spill slots to pass the live values from one block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
// to the other. The topmost value, i.e., the value on TOS of expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
// stack is passed in registers. All other values are stored in spilling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
// area. Every Phi has an index which designates its spill slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
// At exit of a basic block, we fill the register(s) and spill slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
// At entry of a basic block, the block_prolog sets up the content of phi nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
// and locks necessary registers and spilling slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
// move current value to referenced phi function
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  Phi* phi = sux_val->as_Phi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  // cur_val can be null without phi being null in conjunction with inlining
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  if (phi != NULL && cur_val != NULL && cur_val != phi && !phi->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    LIR_Opr operand = cur_val->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    if (cur_val->operand()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
      assert(cur_val->as_Constant() != NULL || cur_val->as_Local() != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
             "these can be produced lazily");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
      operand = operand_for_instruction(cur_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    resolver->move(operand, operand_for_instruction(phi));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
// Moves all stack values into their PHI position
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
void LIRGenerator::move_to_phi(ValueStack* cur_state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  BlockBegin* bb = block();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  if (bb->number_of_sux() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
    BlockBegin* sux = bb->sux_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    assert(sux->number_of_preds() > 0, "invalid CFG");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    // a block with only one predecessor never has phi functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    if (sux->number_of_preds() > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      int max_phis = cur_state->stack_size() + cur_state->locals_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
      PhiResolver resolver(this, _virtual_register_number + max_phis * 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
      ValueStack* sux_state = sux->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
      Value sux_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
      int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1013
      assert(cur_state->scope() == sux_state->scope(), "not matching");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1014
      assert(cur_state->locals_size() == sux_state->locals_size(), "not matching");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1015
      assert(cur_state->stack_size() == sux_state->stack_size(), "not matching");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1016
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
      for_each_stack_value(sux_state, index, sux_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
        move_to_phi(&resolver, cur_state->stack_at(index), sux_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
      for_each_local_value(sux_state, index, sux_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
        move_to_phi(&resolver, cur_state->local_at(index), sux_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
      assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
LIR_Opr LIRGenerator::new_register(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  int vreg = _virtual_register_number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  // add a little fudge factor for the bailout, since the bailout is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  // only checked periodically.  This gives a few extra registers to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  // hand out before we really run out, which helps us keep from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  // tripping over assertions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  if (vreg + 20 >= LIR_OprDesc::vreg_max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    bailout("out of virtual registers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
    if (vreg + 2 >= LIR_OprDesc::vreg_max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
      // wrap it around
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
      _virtual_register_number = LIR_OprDesc::vreg_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  _virtual_register_number += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
  return LIR_OprFact::virtual_register(vreg, type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
// Try to lock using register in hint
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
LIR_Opr LIRGenerator::rlock(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  return new_register(instr->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
// does an rlock and sets result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
LIR_Opr LIRGenerator::rlock_result(Value x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  LIR_Opr reg = rlock(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  set_result(x, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  return reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
// does an rlock and sets result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  LIR_Opr reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  case T_BYTE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
    reg = rlock_byte(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    reg = rlock(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  set_result(x, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
  return reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
//---------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
ciObject* LIRGenerator::get_jobject_constant(Value value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  ObjectType* oc = value->type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  if (oc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    return oc->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
void LIRGenerator::do_ExceptionObject(ExceptionObject* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
  assert(block()->next() == x, "ExceptionObject must be first instruction of block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  // no moves are created for phi functions at the begin of exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  // handlers, so assign operands manually here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
  for_each_phi_fun(block(), phi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
                   operand_for_instruction(phi));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
  LIR_Opr thread_reg = getThreadPointer();
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1101
  __ move_wide(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT),
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1102
               exceptionOopOpr());
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1103
  __ move_wide(LIR_OprFact::oopConst(NULL),
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1104
               new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT));
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1105
  __ move_wide(LIR_OprFact::oopConst(NULL),
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1106
               new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
  LIR_Opr result = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  __ move(exceptionOopOpr(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  set_result(x, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
//                        visitor functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
void LIRGenerator::do_Phi(Phi* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  // phi functions are never visited directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
// 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
  1131
void LIRGenerator::do_Constant(Constant* x) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1132
  if (x->state_before() != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    // Any constant with a ValueStack requires patching so emit the patch here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
    LIR_Opr reg = rlock_result(x);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1135
    CodeEmitInfo* info = state_for(x, x->state_before());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    __ oop2reg_patch(NULL, reg, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
  } else if (x->use_count() > 1 && !can_inline_as_constant(x)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
    if (!x->is_pinned()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
      // unpinned constants are handled specially so that they can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
      // put into registers when they are used multiple times within a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
      // block.  After the block completes their operand will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
      // cleared so that other blocks can't refer to that register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
      set_result(x, load_constant(x));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
      LIR_Opr res = x->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
      if (!res->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
        res = LIR_OprFact::value_type(x->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
      if (res->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
        LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
        __ move(res, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
        set_result(x, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
    set_result(x, LIR_OprFact::value_type(x->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
void LIRGenerator::do_Local(Local* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
  // operand_for_instruction has the side effect of setting the result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  // so there's no need to do it here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  operand_for_instruction(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
void LIRGenerator::do_IfInstanceOf(IfInstanceOf* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  Unimplemented();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
void LIRGenerator::do_Return(Return* x) {
2867
69187054225f 6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents: 2105
diff changeset
  1175
  if (compilation()->env()->dtrace_method_probes()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
    BasicTypeList signature;
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1177
    signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT));    // thread
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  1178
    signature.append(T_OBJECT); // Method*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
    LIR_OprList* args = new LIR_OprList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
    args->append(getThreadPointer());
13742
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
  1181
    LIR_Opr meth = new_register(T_METADATA);
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
  1182
    __ metadata2reg(method()->constant_encoding(), meth);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    args->append(meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
    call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
  if (x->type()->is_void()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
    __ return_op(LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    LIR_Opr reg = result_register_for(x->type(), /*callee=*/true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    LIRItem result(x->result(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
    result.load_item_force(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
    __ return_op(result.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1199
// Examble: ref.get()
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1200
// Combination of LoadField and g1 pre-write barrier
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1201
void LIRGenerator::do_Reference_get(Intrinsic* x) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1202
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1203
  const int referent_offset = java_lang_ref_Reference::referent_offset;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1204
  guarantee(referent_offset > 0, "referent offset not initialized");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1205
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1206
  assert(x->number_of_arguments() == 1, "wrong type");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1207
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1208
  LIRItem reference(x->argument_at(0), this);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1209
  reference.load_item();
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1210
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1211
  // need to perform the null check on the reference objecy
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1212
  CodeEmitInfo* info = NULL;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1213
  if (x->needs_null_check()) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1214
    info = state_for(x);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1215
  }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1216
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1217
  LIR_Address* referent_field_adr =
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1218
    new LIR_Address(reference.result(), referent_offset, T_OBJECT);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1219
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1220
  LIR_Opr result = rlock_result(x);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1221
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1222
  __ load(referent_field_adr, result, info);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1223
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1224
  // Register the value in the referent field with the pre-barrier
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1225
  pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1226
              result /* pre_val */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1227
              false  /* do_load */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1228
              false  /* patch */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1229
              NULL   /* info */);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1230
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
12949
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1232
// Example: clazz.isInstance(object)
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1233
void LIRGenerator::do_isInstance(Intrinsic* x) {
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1234
  assert(x->number_of_arguments() == 2, "wrong type");
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1235
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1236
  // TODO could try to substitute this node with an equivalent InstanceOf
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1237
  // if clazz is known to be a constant Class. This will pick up newly found
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1238
  // constants after HIR construction. I'll leave this to a future change.
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1239
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1240
  // as a first cut, make a simple leaf call to runtime to stay platform independent.
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1241
  // could follow the aastore example in a future change.
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1242
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1243
  LIRItem clazz(x->argument_at(0), this);
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1244
  LIRItem object(x->argument_at(1), this);
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1245
  clazz.load_item();
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1246
  object.load_item();
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1247
  LIR_Opr result = rlock_result(x);
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1248
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1249
  // need to perform null check on clazz
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1250
  if (x->needs_null_check()) {
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1251
    CodeEmitInfo* info = state_for(x);
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1252
    __ null_check(clazz.result(), info);
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1253
  }
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1254
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1255
  LIR_Opr call_result = call_runtime(clazz.value(), object.value(),
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1256
                                     CAST_FROM_FN_PTR(address, Runtime1::is_instance_of),
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1257
                                     x->type(),
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1258
                                     NULL); // NULL CodeEmitInfo results in a leaf call
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1259
  __ move(call_result, result);
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1260
}
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  1261
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
// Example: object.getClass ()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
void LIRGenerator::do_getClass(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
  assert(x->number_of_arguments() == 1, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
  LIRItem rcvr(x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  rcvr.load_item();
21088
4f0ada6dcace 8008242: VerifyOops is broken on SPARC
morris
parents: 20709
diff changeset
  1268
  LIR_Opr temp = new_register(T_METADATA);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
  LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  // need to perform the null check on the rcvr
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  if (x->needs_null_check()) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1274
    info = state_for(x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
  }
21088
4f0ada6dcace 8008242: VerifyOops is broken on SPARC
morris
parents: 20709
diff changeset
  1276
4f0ada6dcace 8008242: VerifyOops is broken on SPARC
morris
parents: 20709
diff changeset
  1277
  // FIXME T_ADDRESS should actually be T_METADATA but it can't because the
4f0ada6dcace 8008242: VerifyOops is broken on SPARC
morris
parents: 20709
diff changeset
  1278
  // meaning of these two is mixed up (see JDK-8026837).
4f0ada6dcace 8008242: VerifyOops is broken on SPARC
morris
parents: 20709
diff changeset
  1279
  __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), temp, info);
4f0ada6dcace 8008242: VerifyOops is broken on SPARC
morris
parents: 20709
diff changeset
  1280
  __ move_wide(new LIR_Address(temp, in_bytes(Klass::java_mirror_offset()), T_OBJECT), result);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
// Example: Thread.currentThread()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
void LIRGenerator::do_currentThread(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
  assert(x->number_of_arguments() == 0, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
  LIR_Opr reg = rlock_result(x);
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  1288
  __ move_wide(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::threadObj_offset()), T_OBJECT), reg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  assert(x->number_of_arguments() == 1, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  LIRItem receiver(x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
  receiver.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  signature.append(T_OBJECT); // receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  LIR_OprList* args = new LIR_OprList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
  args->append(receiver.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
  CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
  call_runtime(&signature, args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
               CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::register_finalizer_id)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
               voidType, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
//------------------------local access--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
  if (x->operand()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
    Constant* c = x->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
    if (c != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
      x->set_operand(LIR_OprFact::value_type(c->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
      assert(x->as_Phi() || x->as_Local() != NULL, "only for Phi and Local");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
      // allocate a virtual register for this local or phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
      x->set_operand(rlock(x));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
      _instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
  return x->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
Instruction* LIRGenerator::instruction_for_opr(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
  if (opr->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    return instruction_for_vreg(opr->vreg_number());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
Instruction* LIRGenerator::instruction_for_vreg(int reg_num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
  if (reg_num < _instruction_for_operand.length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    return _instruction_for_operand.at(reg_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
  if (_vreg_flags.size_in_bits() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    BitMap2D temp(100, num_vreg_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    temp.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    _vreg_flags = temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
  _vreg_flags.at_put_grow(vreg_num, f, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
  if (!_vreg_flags.is_valid_index(vreg_num, f)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
  return _vreg_flags.at(vreg_num, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
// Block local constant handling.  This code is useful for keeping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
// unpinned constants and constants which aren't exposed in the IR in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
// registers.  Unpinned Constant instructions have their operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
// cleared when the block is finished so that other blocks can't end
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
// up referring to their registers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
LIR_Opr LIRGenerator::load_constant(Constant* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  assert(!x->is_pinned(), "only for unpinned constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  _unpinned_constants.append(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
LIR_Opr LIRGenerator::load_constant(LIR_Const* c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
  BasicType t = c->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
  for (int i = 0; i < _constants.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
    LIR_Const* other = _constants.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
    if (t == other->type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
      switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
      case T_INT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
      case T_FLOAT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
        if (c->as_jint_bits() != other->as_jint_bits()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
      case T_LONG:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
      case T_DOUBLE:
1673
fe654c35dfe2 6757316: load_constant() produces a wrong long constant, with high a low words swapped
never
parents: 1412
diff changeset
  1386
        if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue;
fe654c35dfe2 6757316: load_constant() produces a wrong long constant, with high a low words swapped
never
parents: 1412
diff changeset
  1387
        if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
      case T_OBJECT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
        if (c->as_jobject() != other->as_jobject()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
      return _reg_for_constants.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  LIR_Opr result = new_register(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  __ move((LIR_Opr)c, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
  _constants.append(c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  _reg_for_constants.append(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
// Various barriers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1406
void LIRGenerator::pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1407
                               bool do_load, bool patch, CodeEmitInfo* info) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1408
  // Do the pre-write barrier, if any.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1409
  switch (_bs->kind()) {
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  1410
#if INCLUDE_ALL_GCS
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1411
    case BarrierSet::G1SATBCT:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1412
    case BarrierSet::G1SATBCTLogging:
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1413
      G1SATBCardTableModRef_pre_barrier(addr_opr, pre_val, do_load, patch, info);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1414
      break;
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  1415
#endif // INCLUDE_ALL_GCS
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1416
    case BarrierSet::CardTableModRef:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1417
    case BarrierSet::CardTableExtension:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1418
      // No pre barriers
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1419
      break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1420
    case BarrierSet::ModRef:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1421
    case BarrierSet::Other:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1422
      // No pre barriers
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1423
      break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1424
    default      :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1425
      ShouldNotReachHere();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1426
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1427
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1428
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1429
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
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
  1431
  switch (_bs->kind()) {
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  1432
#if INCLUDE_ALL_GCS
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1433
    case BarrierSet::G1SATBCT:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1434
    case BarrierSet::G1SATBCTLogging:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1435
      G1SATBCardTableModRef_post_barrier(addr,  new_val);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1436
      break;
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  1437
#endif // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
    case BarrierSet::CardTableModRef:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
    case BarrierSet::CardTableExtension:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
      CardTableModRef_post_barrier(addr,  new_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
    case BarrierSet::ModRef:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    case BarrierSet::Other:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
      // No post barriers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
    default      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1451
////////////////////////////////////////////////////////////////////////
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  1452
#if INCLUDE_ALL_GCS
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1453
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1454
void LIRGenerator::G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1455
                                                     bool do_load, bool patch, CodeEmitInfo* info) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1456
  // First we test whether marking is in progress.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1457
  BasicType flag_type;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1458
  if (in_bytes(PtrQueue::byte_width_of_active()) == 4) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1459
    flag_type = T_INT;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1460
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1461
    guarantee(in_bytes(PtrQueue::byte_width_of_active()) == 1,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1462
              "Assumption");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1463
    flag_type = T_BYTE;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1464
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1465
  LIR_Opr thrd = getThreadPointer();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1466
  LIR_Address* mark_active_flag_addr =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1467
    new LIR_Address(thrd,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1468
                    in_bytes(JavaThread::satb_mark_queue_offset() +
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1469
                             PtrQueue::byte_offset_of_active()),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1470
                    flag_type);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1471
  // Read the marking-in-progress flag.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1472
  LIR_Opr flag_val = new_register(T_INT);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1473
  __ load(mark_active_flag_addr, flag_val);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1474
  __ cmp(lir_cond_notEqual, flag_val, LIR_OprFact::intConst(0));
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1475
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1476
  LIR_PatchCode pre_val_patch_code = lir_patch_none;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1477
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1478
  CodeStub* slow;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1479
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1480
  if (do_load) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1481
    assert(pre_val == LIR_OprFact::illegalOpr, "sanity");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1482
    assert(addr_opr != LIR_OprFact::illegalOpr, "sanity");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1483
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1484
    if (patch)
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1485
      pre_val_patch_code = lir_patch_normal;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1486
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1487
    pre_val = new_register(T_OBJECT);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1488
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1489
    if (!addr_opr->is_address()) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1490
      assert(addr_opr->is_register(), "must be");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1491
      addr_opr = LIR_OprFact::address(new LIR_Address(addr_opr, T_OBJECT));
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1492
    }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1493
    slow = new G1PreBarrierStub(addr_opr, pre_val, pre_val_patch_code, info);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1494
  } else {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1495
    assert(addr_opr == LIR_OprFact::illegalOpr, "sanity");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1496
    assert(pre_val->is_register(), "must be");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1497
    assert(pre_val->type() == T_OBJECT, "must be an object");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1498
    assert(info == NULL, "sanity");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1499
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1500
    slow = new G1PreBarrierStub(pre_val);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1501
  }
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1502
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1503
  __ branch(lir_cond_notEqual, T_INT, slow);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1504
  __ branch_destination(slow->continuation());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1505
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1506
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1507
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
  1508
  // 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
  1509
  if (new_val->is_constant() &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1510
      new_val->as_constant_ptr()->as_jobject() == NULL) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1511
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1512
  if (!new_val->is_register()) {
5695
7fbbde5b4e3e 6955349: C1: Make G1 barriers work with x64
iveresov
parents: 5687
diff changeset
  1513
    LIR_Opr new_val_reg = new_register(T_OBJECT);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1514
    if (new_val->is_constant()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1515
      __ move(new_val, new_val_reg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1516
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1517
      __ leal(new_val, new_val_reg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1518
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1519
    new_val = new_val_reg;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1520
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1521
  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
  1522
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1523
  if (addr->is_address()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1524
    LIR_Address* address = addr->as_address_ptr();
9120
3606dd709168 7034967: C1: assert(false) failed: error (assembler_sparc.cpp:2043)
iveresov
parents: 9102
diff changeset
  1525
    LIR_Opr ptr = new_pointer_register();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1526
    if (!address->index()->is_valid() && address->disp() == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1527
      __ move(address->base(), ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1528
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1529
      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
  1530
      __ leal(addr, ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1531
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1532
    addr = ptr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1533
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1534
  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
  1535
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1536
  LIR_Opr xor_res = new_pointer_register();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1537
  LIR_Opr xor_shift_res = new_pointer_register();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1538
  if (TwoOperandLIRForm ) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1539
    __ move(addr, xor_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1540
    __ logical_xor(xor_res, new_val, xor_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1541
    __ move(xor_res, xor_shift_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1542
    __ unsigned_shift_right(xor_shift_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1543
                            LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1544
                            xor_shift_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1545
                            LIR_OprDesc::illegalOpr());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1546
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1547
    __ logical_xor(addr, new_val, xor_res);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1548
    __ unsigned_shift_right(xor_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1549
                            LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1550
                            xor_shift_res,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1551
                            LIR_OprDesc::illegalOpr());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1552
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1553
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1554
  if (!new_val->is_register()) {
5695
7fbbde5b4e3e 6955349: C1: Make G1 barriers work with x64
iveresov
parents: 5687
diff changeset
  1555
    LIR_Opr new_val_reg = new_register(T_OBJECT);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1556
    __ leal(new_val, new_val_reg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1557
    new_val = new_val_reg;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1558
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1559
  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
  1560
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1561
  __ 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
  1562
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1563
  CodeStub* slow = new G1PostBarrierStub(addr, new_val);
5695
7fbbde5b4e3e 6955349: C1: Make G1 barriers work with x64
iveresov
parents: 5687
diff changeset
  1564
  __ branch(lir_cond_notEqual, LP64_ONLY(T_LONG) NOT_LP64(T_INT), slow);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1565
  __ branch_destination(slow->continuation());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1566
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1567
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  1568
#endif // INCLUDE_ALL_GCS
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1569
////////////////////////////////////////////////////////////////////////
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1570
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
void LIRGenerator::CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1573
  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
  1574
  LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
  if (addr->is_address()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
    LIR_Address* address = addr->as_address_ptr();
9120
3606dd709168 7034967: C1: assert(false) failed: error (assembler_sparc.cpp:2043)
iveresov
parents: 9102
diff changeset
  1577
    // ptr cannot be an object because we use this barrier for array card marks
3606dd709168 7034967: C1: assert(false) failed: error (assembler_sparc.cpp:2043)
iveresov
parents: 9102
diff changeset
  1578
    // and addr can point in the middle of an array.
3606dd709168 7034967: C1: assert(false) failed: error (assembler_sparc.cpp:2043)
iveresov
parents: 9102
diff changeset
  1579
    LIR_Opr ptr = new_pointer_register();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
    if (!address->index()->is_valid() && address->disp() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
      __ move(address->base(), ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
      assert(address->disp() != max_jint, "lea doesn't support patched addresses!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
      __ leal(addr, ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
    addr = ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
  assert(addr->is_register(), "must be a register at this point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1590
#ifdef ARM
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1591
  // TODO: ARM - move to platform-dependent code
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1592
  LIR_Opr tmp = FrameMap::R14_opr;
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1593
  if (VM_Version::supports_movw()) {
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1594
    __ move((LIR_Opr)card_table_base, tmp);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1595
  } else {
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1596
    __ move(new LIR_Address(FrameMap::Rthread_opr, in_bytes(JavaThread::card_table_base_offset()), T_ADDRESS), tmp);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1597
  }
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1598
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1599
  CardTableModRefBS* ct = (CardTableModRefBS*)_bs;
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1600
  LIR_Address *card_addr = new LIR_Address(tmp, addr, (LIR_Address::Scale) -CardTableModRefBS::card_shift, 0, T_BYTE);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1601
  if(((int)ct->byte_map_base & 0xff) == 0) {
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1602
    __ move(tmp, card_addr);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1603
  } else {
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1604
    LIR_Opr tmp_zero = new_register(T_INT);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1605
    __ move(LIR_OprFact::intConst(0), tmp_zero);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1606
    __ move(tmp_zero, card_addr);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1607
  }
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1608
#else // ARM
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
  LIR_Opr tmp = new_pointer_register();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
  if (TwoOperandLIRForm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
    __ move(addr, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
    __ unsigned_shift_right(tmp, CardTableModRefBS::card_shift, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    __ unsigned_shift_right(addr, CardTableModRefBS::card_shift, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
  if (can_inline_as_constant(card_table_base)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
    __ move(LIR_OprFact::intConst(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
              new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
    __ move(LIR_OprFact::intConst(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
              new LIR_Address(tmp, load_constant(card_table_base),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
                              T_BYTE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
  }
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1624
#endif // ARM
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
//------------------------field access--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
// Comment copied form templateTable_i486.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
// Volatile variables demand their effects be made known to all CPU's in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
// order.  Store buffers on most chips allow reads & writes to reorder; the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
// JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
// memory barrier (i.e., it's not sufficient that the interpreter does not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
// reorder volatile references, the hardware also must not reorder them).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
// According to the new Java Memory Model (JMM):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
// (1) All volatiles are serialized wrt to each other.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
// ALSO reads & writes act as aquire & release, so:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
// (2) A read cannot let unrelated NON-volatile memory refs that happen after
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
// the read float up to before the read.  It's OK for non-volatile memory refs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
// that happen before the volatile read to float down below it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
// (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
// that happen BEFORE the write float down to after the write.  It's OK for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
// non-volatile memory refs that happen after the volatile write to float up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
// before it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
// We only put in barriers around volatile refs (they are expensive), not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
// _between_ memory refs (that would require us to track the flavor of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
// previous memory refs).  Requirements (2) and (3) require some barriers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
// before volatile stores and after volatile loads.  These nearly cover
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
// requirement (1) but miss the volatile-store-volatile-load case.  This final
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
// case is placed after volatile-stores although it could just as well go
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
// before volatile-loads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
void LIRGenerator::do_StoreField(StoreField* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
  bool needs_patching = x->needs_patching();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
  bool is_volatile = x->field()->is_volatile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  BasicType field_type = x->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
  bool is_oop = (field_type == T_ARRAY || field_type == T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
    assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
    info = state_for(x, x->state_before());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
  } else if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
    if (nc == NULL) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1671
      info = state_for(x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
      info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
  LIRItem object(x->obj(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
  LIRItem value(x->value(),  this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
  object.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
  if (is_volatile || needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
    // load item if field is volatile (fewer special cases for volatiles)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
    // load item if field not initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
    // load item if field not constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
    // because of code patching we cannot inline constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
    if (field_type == T_BYTE || field_type == T_BOOLEAN) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
      value.load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
    } else  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
      value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
    value.load_for_store(field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1699
#ifndef PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  if (PrintNotLoaded && needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
    tty->print_cr("   ###class not loaded at store_%s bci %d",
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1702
                  x->is_static() ?  "static" : "field", x->printable_bci());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1704
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
  if (x->needs_null_check() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
      (needs_patching ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
       MacroAssembler::needs_explicit_null_check(x->offset()))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
    // emit an explicit null check because the offset is too large
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
    __ null_check(object.result(), new CodeEmitInfo(info));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
  LIR_Address* address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
    // we need to patch the offset in the instruction so don't allow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
    // generate_address to try to be smart about emitting the -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
    // Otherwise the patching code won't know how to find the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
    // instruction to patch.
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1719
    address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
    address = generate_address(object.result(), x->offset(), field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
  if (is_volatile && os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
    __ membar_release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1728
  if (is_oop) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1729
    // Do the pre-write barrier, if any.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1730
    pre_barrier(LIR_OprFact::address(address),
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1731
                LIR_OprFact::illegalOpr /* pre_val */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  1732
                true /* do_load*/,
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1733
                needs_patching,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1734
                (info ? new CodeEmitInfo(info) : NULL));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1735
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
  1736
8671
13ffa40a2f0a 6965570: assert(!needs_patching && x->is_loaded(),"how do we know it's volatile if it's not loaded")
never
parents: 8066
diff changeset
  1737
  if (is_volatile && !needs_patching) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
    volatile_field_store(value.result(), address, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
    LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
    __ store(value.result(), address, info, patch_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
  if (is_oop) {
3172
ad4ba6ce75a5 6849574: VM crash using NonBlockingHashMap (high_scale_lib)
never
parents: 2867
diff changeset
  1745
    // Store to object so mark the card of the header
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
    post_barrier(object.result(), value.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
  if (is_volatile && os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    __ membar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
void LIRGenerator::do_LoadField(LoadField* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  bool needs_patching = x->needs_patching();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
  bool is_volatile = x->field()->is_volatile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
  BasicType field_type = x->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
    assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
    info = state_for(x, x->state_before());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
  } else if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
    if (nc == NULL) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1767
      info = state_for(x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
      info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
  LIRItem object(x->obj(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
  object.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1777
#ifndef PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  if (PrintNotLoaded && needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
    tty->print_cr("   ###class not loaded at load_%s bci %d",
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1780
                  x->is_static() ?  "static" : "field", x->printable_bci());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1782
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1784
  bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  if (x->needs_null_check() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
      (needs_patching ||
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1787
       MacroAssembler::needs_explicit_null_check(x->offset()) ||
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1788
       stress_deopt)) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1789
    LIR_Opr obj = object.result();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1790
    if (stress_deopt) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1791
      obj = new_register(T_OBJECT);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1792
      __ move(LIR_OprFact::oopConst(NULL), obj);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1793
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
    // emit an explicit null check because the offset is too large
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1795
    __ null_check(obj, new CodeEmitInfo(info));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
  LIR_Opr reg = rlock_result(x, field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
  LIR_Address* address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
  if (needs_patching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
    // we need to patch the offset in the instruction so don't allow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
    // generate_address to try to be smart about emitting the -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
    // Otherwise the patching code won't know how to find the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
    // instruction to patch.
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  1805
    address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
    address = generate_address(object.result(), x->offset(), field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
8671
13ffa40a2f0a 6965570: assert(!needs_patching && x->is_loaded(),"how do we know it's volatile if it's not loaded")
never
parents: 8066
diff changeset
  1810
  if (is_volatile && !needs_patching) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
    volatile_field_load(address, reg, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
    LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    __ load(address, reg, info, patch_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
  if (is_volatile && os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
    __ membar_acquire();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
  }
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
//------------------------java.nio.Buffer.checkIndex------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
// int java.nio.Buffer.checkIndex(int)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
  // NOTE: by the time we are in checkIndex() we are guaranteed that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
  // the buffer is non-null (because checkIndex is package-private and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
  // only called from within other methods in the buffer).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
  assert(x->number_of_arguments() == 2, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
  LIRItem buf  (x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
  LIRItem index(x->argument_at(1), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
  buf.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
  index.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
  LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
  if (GenerateRangeChecks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
    CodeEmitInfo* info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
    CodeStub* stub = new RangeCheckStub(info, index.result(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
    if (index.result()->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
      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
  1842
      __ branch(lir_cond_belowEqual, T_INT, stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
      cmp_reg_mem(lir_cond_aboveEqual, index.result(), buf.result(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
                  java_nio_Buffer::limit_offset(), T_INT, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
      __ branch(lir_cond_aboveEqual, T_INT, stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
    __ move(index.result(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
    // Just load the index into the result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
    __ move(index.result(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
//------------------------array access--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
void LIRGenerator::do_ArrayLength(ArrayLength* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
  LIRItem array(x->array(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
  array.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
  LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
  CodeEmitInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
  if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
    if (nc == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
      info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
      info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
    }
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1872
    if (StressLoopInvariantCodeMotion && info->deoptimize_on_exception()) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1873
      LIR_Opr obj = new_register(T_OBJECT);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1874
      __ move(LIR_OprFact::oopConst(NULL), obj);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1875
      __ null_check(obj, new CodeEmitInfo(info));
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1876
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
  __ 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
  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_LoadIndexed(LoadIndexed* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
  bool use_length = x->length() != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
  LIRItem array(x->array(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
  LIRItem index(x->index(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
  LIRItem length(this);
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1887
  bool needs_range_check = x->compute_needs_range_check();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1888
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1889
  if (use_length && needs_range_check) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1890
    length.set_instruction(x->length());
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1891
    length.load_item();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
  array.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
  if (index.is_constant() && can_inline_as_constant(x->index())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
    // let it be a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
    index.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
    index.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
  CodeEmitInfo* range_check_info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
  CodeEmitInfo* null_check_info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
  if (x->needs_null_check()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
    NullCheck* nc = x->explicit_null_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
    if (nc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
      null_check_info = state_for(nc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
      null_check_info = range_check_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
    }
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1911
    if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1912
      LIR_Opr obj = new_register(T_OBJECT);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1913
      __ move(LIR_OprFact::oopConst(NULL), obj);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1914
      __ null_check(obj, new CodeEmitInfo(null_check_info));
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1915
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
  // emit array address setup early so it schedules better
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
  LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
  if (GenerateRangeChecks && needs_range_check) {
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1922
    if (StressLoopInvariantCodeMotion && range_check_info->deoptimize_on_exception()) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1923
      __ branch(lir_cond_always, T_ILLEGAL, new RangeCheckStub(range_check_info, index.result()));
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  1924
    } else if (use_length) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
      // TODO: use a (modified) version of array_range_check that does not require a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
      //       constant length to be loaded to a register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
      __ cmp(lir_cond_belowEqual, length.result(), index.result());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
      __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
      array_range_check(array.result(), index.result(), null_check_info, range_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
      // The range check performs the null check, so clear it out for the load
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
      null_check_info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
  __ move(array_addr, rlock_result(x, x->elt_type()), null_check_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
void LIRGenerator::do_NullCheck(NullCheck* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
  if (x->can_trap()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
    LIRItem value(x->obj(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
    value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
    CodeEmitInfo* info = state_for(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
    __ null_check(value.result(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1950
void LIRGenerator::do_TypeCast(TypeCast* x) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1951
  LIRItem value(x->obj(), this);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1952
  value.load_item();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1953
  // the result is the same as from the node we are casting
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1954
  set_result(x, value.result());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1955
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1956
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  1957
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
void LIRGenerator::do_Throw(Throw* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
  LIRItem exception(x->exception(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
  exception.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
  LIR_Opr exception_opr = exception.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
  CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
  if (PrintC1Statistics) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  1967
    increment_counter(Runtime1::throw_count_address(), T_INT);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
  // check if the instruction has an xhandler in any of the nested scopes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
  bool unwind = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
  if (info->exception_handlers()->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
    // this throw is not inside an xhandler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
    unwind = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
    // get some idea of the throw type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
    bool type_is_exact = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
    ciType* throw_type = x->exception()->exact_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
    if (throw_type == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
      type_is_exact = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
      throw_type = x->exception()->declared_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
    if (throw_type != NULL && throw_type->is_instance_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
      ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
      unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
  // do null check before moving exception oop into fixed register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
  // to avoid a fixed interval with an oop during the null check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
  // Use a copy of the CodeEmitInfo because debug information is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
  // different for null_check and throw.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
  if (GenerateCompilerNullChecks &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
      (x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
    // if the exception object wasn't created using new then it might be null.
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6742
diff changeset
  1997
    __ null_check(exception_opr, new CodeEmitInfo(info, x->state()->copy(ValueStack::ExceptionState, x->state()->bci())));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
5334
b2d040a8d375 6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents: 5055
diff changeset
  2000
  if (compilation()->env()->jvmti_can_post_on_exceptions()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
    // we need to go through the exception lookup path to get JVMTI
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
    // notification done
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
    unwind = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
  // move exception oop into fixed register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
  __ move(exception_opr, exceptionOopOpr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
  if (unwind) {
5334
b2d040a8d375 6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents: 5055
diff changeset
  2010
    __ unwind_exception(exceptionOopOpr());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
    __ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
void LIRGenerator::do_RoundFP(RoundFP* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
  LIRItem input(x->input(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
  input.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
  LIR_Opr input_opr = input.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
  assert(input_opr->is_register(), "why round if value is not in a register?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
  assert(input_opr->is_single_fpu() || input_opr->is_double_fpu(), "input should be floating-point value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
  if (input_opr->is_single_fpu()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
    set_result(x, round_item(input_opr)); // This code path not currently taken
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
    LIR_Opr result = new_register(T_DOUBLE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
    set_vreg_flag(result, must_start_in_memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
    __ roundfp(input_opr, LIR_OprFact::illegalOpr, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
    set_result(x, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
void LIRGenerator::do_UnsafeGetRaw(UnsafeGetRaw* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
  LIRItem base(x->base(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
  LIRItem idx(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
  base.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
    idx.set_instruction(x->index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
    idx.load_nonconstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
  LIR_Opr reg = rlock_result(x, x->basic_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
  int   log2_scale = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
    assert(x->index()->type()->tag() == intTag, "should not find non-int index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
    log2_scale = x->log2_scale();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
  assert(!x->has_index() || idx.value() == x->index(), "should match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
  LIR_Opr base_op = base.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
  if (x->base()->type()->tag() == longTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
    base_op = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
    __ convert(Bytecodes::_l2i, base.result(), base_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
    assert(x->base()->type()->tag() == intTag, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
  BasicType dst_type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
  LIR_Opr index_op = idx.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
  LIR_Address* addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
  if (index_op->is_constant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
    assert(log2_scale == 0, "must not have a scale");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
    addr = new LIR_Address(base_op, index_op->as_jint(), dst_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
  } else {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
  2071
#ifdef X86
4430
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2072
#ifdef _LP64
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2073
    if (!index_op->is_illegal() && index_op->type() == T_INT) {
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2074
      LIR_Opr tmp = new_pointer_register();
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2075
      __ convert(Bytecodes::_i2l, index_op, tmp);
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2076
      index_op = tmp;
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2077
    }
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2078
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
    addr = new LIR_Address(base_op, index_op, LIR_Address::Scale(log2_scale), 0, dst_type);
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  2080
#elif defined(ARM)
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  2081
    addr = generate_address(base_op, index_op, log2_scale, 0, dst_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
    if (index_op->is_illegal() || log2_scale == 0) {
4430
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2084
#ifdef _LP64
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2085
      if (!index_op->is_illegal() && index_op->type() == T_INT) {
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2086
        LIR_Opr tmp = new_pointer_register();
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2087
        __ convert(Bytecodes::_i2l, index_op, tmp);
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2088
        index_op = tmp;
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2089
      }
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2090
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
      addr = new LIR_Address(base_op, index_op, dst_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
    } else {
4430
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2093
      LIR_Opr tmp = new_pointer_register();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
      __ shift_left(index_op, log2_scale, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
      addr = new LIR_Address(base_op, tmp, dst_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
  if (x->may_be_unaligned() && (dst_type == T_LONG || dst_type == T_DOUBLE)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
    __ unaligned_move(addr, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
  } else {
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2103
    if (dst_type == T_OBJECT && x->is_wide()) {
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2104
      __ move_wide(addr, reg);
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2105
    } else {
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2106
      __ move(addr, reg);
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2107
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
void LIRGenerator::do_UnsafePutRaw(UnsafePutRaw* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
  int  log2_scale = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
  BasicType type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
    assert(x->index()->type()->tag() == intTag, "should not find non-int index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
    log2_scale = x->log2_scale();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
  LIRItem base(x->base(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
  LIRItem value(x->value(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
  LIRItem idx(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
  base.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
  if (x->has_index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
    idx.set_instruction(x->index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
    idx.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
  if (type == T_BYTE || type == T_BOOLEAN) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
    value.load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
    value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
  LIR_Opr base_op = base.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
  if (x->base()->type()->tag() == longTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
    base_op = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
    __ convert(Bytecodes::_l2i, base.result(), base_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
    assert(x->base()->type()->tag() == intTag, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
  LIR_Opr index_op = idx.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
  if (log2_scale != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
    // temporary fix (platform dependent code without shift on Intel would be better)
4430
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2152
    index_op = new_pointer_register();
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2153
#ifdef _LP64
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2154
    if(idx.result()->type() == T_INT) {
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2155
      __ convert(Bytecodes::_i2l, idx.result(), index_op);
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2156
    } else {
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2157
#endif
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  2158
      // TODO: ARM also allows embedded shift in the address
4430
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2159
      __ move(idx.result(), index_op);
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2160
#ifdef _LP64
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2161
    }
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2162
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
    __ shift_left(index_op, log2_scale, index_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
  }
4430
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2165
#ifdef _LP64
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2166
  else if(!index_op->is_illegal() && index_op->type() == T_INT) {
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2167
    LIR_Opr tmp = new_pointer_register();
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2168
    __ convert(Bytecodes::_i2l, index_op, tmp);
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2169
    index_op = tmp;
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2170
  }
95b539dfa1e8 6769124: various 64-bit fixes for c1
roland
parents: 3908
diff changeset
  2171
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
  LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
  __ move(value.result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
  BasicType type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
  LIRItem src(x->object(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
  LIRItem off(x->offset(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
  off.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
  src.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2186
  LIR_Opr value = rlock_result(x, x->basic_type());
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2187
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2188
  get_Object_unsafe(value, src.result(), off.result(), type, x->is_volatile());
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2189
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  2190
#if INCLUDE_ALL_GCS
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2191
  // We might be reading the value of the referent field of a
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2192
  // Reference object in order to attach it back to the live
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2193
  // object graph. If G1 is enabled then we need to record
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2194
  // the value that is being returned in an SATB log buffer.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2195
  //
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2196
  // We need to generate code similar to the following...
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2197
  //
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2198
  // if (offset == java_lang_ref_Reference::referent_offset) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2199
  //   if (src != NULL) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2200
  //     if (klass(src)->reference_type() != REF_NONE) {
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2201
  //       pre_barrier(..., value, ...);
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2202
  //     }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2203
  //   }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2204
  // }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2205
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2206
  if (UseG1GC && type == T_OBJECT) {
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2207
    bool gen_pre_barrier = true;     // Assume we need to generate pre_barrier.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2208
    bool gen_offset_check = true;    // Assume we need to generate the offset guard.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2209
    bool gen_source_check = true;    // Assume we need to check the src object for null.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2210
    bool gen_type_check = true;      // Assume we need to check the reference_type.
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2211
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2212
    if (off.is_constant()) {
9181
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2213
      jlong off_con = (off.type()->is_int() ?
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2214
                        (jlong) off.get_jint_constant() :
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2215
                        off.get_jlong_constant());
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2216
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2217
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2218
      if (off_con != (jlong) java_lang_ref_Reference::referent_offset) {
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2219
        // The constant offset is something other than referent_offset.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2220
        // We can skip generating/checking the remaining guards and
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2221
        // skip generation of the code stub.
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2222
        gen_pre_barrier = false;
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2223
      } else {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2224
        // The constant offset is the same as referent_offset -
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2225
        // we do not need to generate a runtime offset check.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2226
        gen_offset_check = false;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2227
      }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2228
    }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2229
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2230
    // We don't need to generate stub if the source object is an array
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2231
    if (gen_pre_barrier && src.type()->is_array()) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2232
      gen_pre_barrier = false;
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2233
    }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2234
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2235
    if (gen_pre_barrier) {
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2236
      // We still need to continue with the checks.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2237
      if (src.is_constant()) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2238
        ciObject* src_con = src.get_jobject_constant();
17879
49ac5c39b28f 8010724: [parfait] Null pointer dereference in hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
morris
parents: 17018
diff changeset
  2239
        guarantee(src_con != NULL, "no source constant");
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2240
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2241
        if (src_con->is_null_object()) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2242
          // The constant src object is null - We can skip
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2243
          // generating the code stub.
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2244
          gen_pre_barrier = false;
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2245
        } else {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2246
          // Non-null constant source object. We still have to generate
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2247
          // the slow stub - but we don't need to generate the runtime
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2248
          // null object check.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2249
          gen_source_check = false;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2250
        }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2251
      }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2252
    }
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2253
    if (gen_pre_barrier && !PatchALot) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2254
      // Can the klass of object be statically determined to be
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2255
      // a sub-class of Reference?
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2256
      ciType* type = src.value()->declared_type();
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2257
      if ((type != NULL) && type->is_loaded()) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2258
        if (type->is_subtype_of(compilation()->env()->Reference_klass())) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2259
          gen_type_check = false;
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2260
        } else if (type->is_klass() &&
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2261
                   !compilation()->env()->Object_klass()->is_subtype_of(type->as_klass())) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2262
          // Not Reference and not Object klass.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2263
          gen_pre_barrier = false;
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2264
        }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2265
      }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2266
    }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2267
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2268
    if (gen_pre_barrier) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2269
      LabelObj* Lcont = new LabelObj();
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2270
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2271
      // We can have generate one runtime check here. Let's start with
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2272
      // the offset check.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2273
      if (gen_offset_check) {
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2274
        // if (offset != referent_offset) -> continue
9181
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2275
        // If offset is an int then we can do the comparison with the
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2276
        // referent_offset constant; otherwise we need to move
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2277
        // referent_offset into a temporary register and generate
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2278
        // a reg-reg compare.
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2279
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2280
        LIR_Opr referent_off;
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2281
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2282
        if (off.type()->is_int()) {
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2283
          referent_off = LIR_OprFact::intConst(java_lang_ref_Reference::referent_offset);
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2284
        } else {
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2285
          assert(off.type()->is_long(), "what else?");
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2286
          referent_off = new_register(T_LONG);
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2287
          __ move(LIR_OprFact::longConst(java_lang_ref_Reference::referent_offset), referent_off);
d32bbcce6b1f 7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure
johnc
parents: 9176
diff changeset
  2288
        }
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2289
        __ cmp(lir_cond_notEqual, off.result(), referent_off);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2290
        __ branch(lir_cond_notEqual, as_BasicType(off.type()), Lcont->label());
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2291
      }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2292
      if (gen_source_check) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2293
        // offset is a const and equals referent offset
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2294
        // if (source == null) -> continue
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2295
        __ cmp(lir_cond_equal, src.result(), LIR_OprFact::oopConst(NULL));
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2296
        __ branch(lir_cond_equal, T_OBJECT, Lcont->label());
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2297
      }
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2298
      LIR_Opr src_klass = new_register(T_OBJECT);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2299
      if (gen_type_check) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2300
        // We have determined that offset == referent_offset && src != null.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2301
        // if (src->_klass->_reference_type == REF_NONE) -> continue
19156
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents: 18507
diff changeset
  2302
        __ move(new LIR_Address(src.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), src_klass);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  2303
        LIR_Address* reference_type_addr = new LIR_Address(src_klass, in_bytes(InstanceKlass::reference_type_offset()), T_BYTE);
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2304
        LIR_Opr reference_type = new_register(T_INT);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2305
        __ move(reference_type_addr, reference_type);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2306
        __ cmp(lir_cond_equal, reference_type, LIR_OprFact::intConst(REF_NONE));
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2307
        __ branch(lir_cond_equal, T_INT, Lcont->label());
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2308
      }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2309
      {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2310
        // We have determined that src->_klass->_reference_type != REF_NONE
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2311
        // so register the value in the referent field with the pre-barrier.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2312
        pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2313
                    value  /* pre_val */,
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2314
                    false  /* do_load */,
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2315
                    false  /* patch */,
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2316
                    NULL   /* info */);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2317
      }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents: 13391
diff changeset
  2318
      __ branch_destination(Lcont->label());
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2319
    }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2320
  }
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
  2321
#endif // INCLUDE_ALL_GCS
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  2322
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
  if (x->is_volatile() && os::is_MP()) __ membar_acquire();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2328
  BasicType type = x->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2329
  LIRItem src(x->object(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2330
  LIRItem off(x->offset(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2331
  LIRItem data(x->value(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2333
  src.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2334
  if (type == T_BOOLEAN || type == T_BYTE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2335
    data.load_byte_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2336
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2337
    data.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2339
  off.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2340
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2341
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2343
  if (x->is_volatile() && os::is_MP()) __ membar_release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2344
  put_Object_unsafe(src.result(), off.result(), data.result(), type, x->is_volatile());
7894
48e7725b6bc4 7010665: Misplaced membar in C1 implementation of Unsafe.get/putXXX
dholmes
parents: 7432
diff changeset
  2345
  if (x->is_volatile() && os::is_MP()) __ membar();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2346
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2347
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2348
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2349
void LIRGenerator::do_UnsafePrefetch(UnsafePrefetch* x, bool is_store) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2350
  LIRItem src(x->object(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2351
  LIRItem off(x->offset(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2353
  src.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2354
  if (off.is_constant() && can_inline_as_constant(x->offset())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2355
    // let it be a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2356
    off.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2357
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2358
    off.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2359
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2360
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2361
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2362
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2363
  LIR_Address* addr = generate_address(src.result(), off.result(), 0, 0, T_BYTE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2364
  __ prefetch(addr, is_store);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2365
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2366
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2367
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2368
void LIRGenerator::do_UnsafePrefetchRead(UnsafePrefetchRead* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2369
  do_UnsafePrefetch(x, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2370
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2372
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2373
void LIRGenerator::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2374
  do_UnsafePrefetch(x, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2375
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2376
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2377
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2378
void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2379
  int lng = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2380
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2381
  for (int i = 0; i < lng; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2382
    SwitchRange* one_range = x->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2383
    int low_key = one_range->low_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2384
    int high_key = one_range->high_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2385
    BlockBegin* dest = one_range->sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2386
    if (low_key == high_key) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2387
      __ cmp(lir_cond_equal, value, low_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2388
      __ branch(lir_cond_equal, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2389
    } else if (high_key - low_key == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2390
      __ cmp(lir_cond_equal, value, low_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2391
      __ branch(lir_cond_equal, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2392
      __ cmp(lir_cond_equal, value, high_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2393
      __ branch(lir_cond_equal, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2394
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2395
      LabelObj* L = new LabelObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2396
      __ cmp(lir_cond_less, value, low_key);
11563
1edf1d19c36d 7131028: Switch statement takes wrong path
iveresov
parents: 11430
diff changeset
  2397
      __ branch(lir_cond_less, T_INT, L->label());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2398
      __ cmp(lir_cond_lessEqual, value, high_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2399
      __ branch(lir_cond_lessEqual, T_INT, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2400
      __ branch_destination(L->label());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2401
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2402
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2403
  __ jump(default_sux);
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
SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2408
  SwitchRangeList* res = new SwitchRangeList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2409
  int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2410
  if (len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2411
    BlockBegin* sux = x->sux_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2412
    int key = x->lo_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2413
    BlockBegin* default_sux = x->default_sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2414
    SwitchRange* range = new SwitchRange(key, sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2415
    for (int i = 0; i < len; i++, key++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2416
      BlockBegin* new_sux = x->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2417
      if (sux == new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2418
        // still in same range
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2419
        range->set_high_key(key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2420
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2421
        // skip tests which explicitly dispatch to the default
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2422
        if (sux != default_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2423
          res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2424
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2425
        range = new SwitchRange(key, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2426
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2427
      sux = new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2428
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2429
    if (res->length() == 0 || res->last() != range)  res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2430
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2431
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2432
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2434
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2435
// we expect the keys to be sorted by increasing value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2436
SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2437
  SwitchRangeList* res = new SwitchRangeList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2438
  int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2439
  if (len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2440
    BlockBegin* default_sux = x->default_sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2441
    int key = x->key_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2442
    BlockBegin* sux = x->sux_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2443
    SwitchRange* range = new SwitchRange(key, sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2444
    for (int i = 1; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2445
      int new_key = x->key_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2446
      BlockBegin* new_sux = x->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2447
      if (key+1 == new_key && sux == new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2448
        // still in same range
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2449
        range->set_high_key(new_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2450
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2451
        // skip tests which explicitly dispatch to the default
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2452
        if (range->sux() != default_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2453
          res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2454
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2455
        range = new SwitchRange(new_key, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2456
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2457
      key = new_key;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2458
      sux = new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2459
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2460
    if (res->length() == 0 || res->last() != range)  res->append(range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2461
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2462
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2463
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2464
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2465
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2466
void LIRGenerator::do_TableSwitch(TableSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2467
  LIRItem tag(x->tag(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2468
  tag.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2469
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2470
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2471
  if (x->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2472
    __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2473
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2474
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2475
  // move values into phi locations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2476
  move_to_phi(x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2477
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2478
  int lo_key = x->lo_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2479
  int hi_key = x->hi_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2480
  int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2481
  LIR_Opr value = tag.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2482
  if (UseTableRanges) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2483
    do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2484
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2485
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2486
      __ cmp(lir_cond_equal, value, i + lo_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2487
      __ branch(lir_cond_equal, T_INT, x->sux_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2488
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2489
    __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2490
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2491
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2492
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2493
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2494
void LIRGenerator::do_LookupSwitch(LookupSwitch* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2495
  LIRItem tag(x->tag(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2496
  tag.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2497
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2498
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2499
  if (x->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2500
    __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2501
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2502
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2503
  // move values into phi locations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2504
  move_to_phi(x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2505
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2506
  LIR_Opr value = tag.result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2507
  if (UseTableRanges) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2508
    do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2509
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2510
    int len = x->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2511
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2512
      __ cmp(lir_cond_equal, value, x->key_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2513
      __ branch(lir_cond_equal, T_INT, x->sux_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2514
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2515
    __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2516
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2517
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2518
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2519
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2520
void LIRGenerator::do_Goto(Goto* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2521
  set_no_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2522
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2523
  if (block()->next()->as_OsrEntry()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2524
    // need to free up storage used for OSR entry point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2525
    LIR_Opr osrBuffer = block()->next()->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2526
    BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2527
    signature.append(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2528
    CallingConvention* cc = frame_map()->c_calling_convention(&signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2529
    __ move(osrBuffer, cc->args()->at(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2530
    __ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2531
                         getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2533
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2534
  if (x->is_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2535
    ValueStack* state = x->state_before() ? x->state_before() : x->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2536
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2537
    // increment backedge counter if needed
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2538
    CodeEmitInfo* info = state_for(x, state);
10730
38dcf027574e 7097679: Tiered: events with bad bci to Gotos reduced from Ifs
iveresov
parents: 10569
diff changeset
  2539
    increment_backedge_counter(info, x->profiled_bci());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2540
    CodeEmitInfo* safepoint_info = state_for(x, state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2541
    __ safepoint(safepoint_poll_register(), safepoint_info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2542
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2543
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2544
  // Gotos can be folded Ifs, handle this case.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2545
  if (x->should_profile()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2546
    ciMethod* method = x->profiled_method();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2547
    assert(method != NULL, "method should be set if branch is profiled");
7432
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7427
diff changeset
  2548
    ciMethodData* md = method->method_data_or_null();
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7427
diff changeset
  2549
    assert(md != NULL, "Sanity");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2550
    ciProfileData* data = md->bci_to_data(x->profiled_bci());
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2551
    assert(data != NULL, "must have profiling data");
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2552
    int offset;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2553
    if (x->direction() == Goto::taken) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2554
      assert(data->is_BranchData(), "need BranchData for two-way branches");
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2555
      offset = md->byte_offset_of_slot(data, BranchData::taken_offset());
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2556
    } else if (x->direction() == Goto::not_taken) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2557
      assert(data->is_BranchData(), "need BranchData for two-way branches");
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2558
      offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2559
    } else {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2560
      assert(data->is_JumpData(), "need JumpData for branches");
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2561
      offset = md->byte_offset_of_slot(data, JumpData::taken_offset());
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2562
    }
13742
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
  2563
    LIR_Opr md_reg = new_register(T_METADATA);
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
  2564
    __ metadata2reg(md->constant_encoding(), md_reg);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2565
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2566
    increment_counter(new LIR_Address(md_reg, offset,
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2567
                                      NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2568
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2569
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2570
  // emit phi-instruction move after safepoint since this simplifies
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2571
  // describing the state as the safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2572
  move_to_phi(x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2573
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2574
  __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2575
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2576
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2577
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2578
ciKlass* LIRGenerator::profile_arg_type(ciMethodData* md, int md_base_offset, int md_offset, intptr_t profiled_k, Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_k) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2579
  ciKlass* result = NULL;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2580
  bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2581
  bool do_update = !TypeEntries::is_type_unknown(profiled_k);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2582
  // known not to be null or null bit already set and already set to
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2583
  // unknown: nothing we can do to improve profiling
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2584
  if (!do_null && !do_update) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2585
    return result;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2586
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2587
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2588
  ciKlass* exact_klass = NULL;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2589
  Compilation* comp = Compilation::current();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2590
  if (do_update) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2591
    // try to find exact type, using CHA if possible, so that loading
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2592
    // the klass from the object can be avoided
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2593
    ciType* type = arg->exact_type();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2594
    if (type == NULL) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2595
      type = arg->declared_type();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2596
      type = comp->cha_exact_type(type);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2597
    }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2598
    assert(type == NULL || type->is_klass(), "type should be class");
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2599
    exact_klass = (type != NULL && type->is_loaded()) ? (ciKlass*)type : NULL;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2600
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2601
    do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2602
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2603
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2604
  if (!do_null && !do_update) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2605
    return result;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2606
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2607
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2608
  ciKlass* exact_signature_k = NULL;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2609
  if (do_update) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2610
    // Is the type from the signature exact (the only one possible)?
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2611
    exact_signature_k = signature_k->exact_klass();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2612
    if (exact_signature_k == NULL) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2613
      exact_signature_k = comp->cha_exact_type(signature_k);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2614
    } else {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2615
      result = exact_signature_k;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2616
      do_update = false;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2617
      // Known statically. No need to emit any code: prevent
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2618
      // LIR_Assembler::emit_profile_type() from emitting useless code
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2619
      profiled_k = ciTypeEntries::with_status(result, profiled_k);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2620
    }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2621
    if (exact_signature_k != NULL && exact_klass != exact_signature_k) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2622
      assert(exact_klass == NULL, "arg and signature disagree?");
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2623
      // sometimes the type of the signature is better than the best type
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2624
      // the compiler has
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2625
      exact_klass = exact_signature_k;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2626
      do_update = exact_klass == NULL || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2627
    }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2628
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2629
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2630
  if (!do_null && !do_update) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2631
    return result;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2632
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2633
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2634
  if (mdp == LIR_OprFact::illegalOpr) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2635
    mdp = new_register(T_METADATA);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2636
    __ metadata2reg(md->constant_encoding(), mdp);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2637
    if (md_base_offset != 0) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2638
      LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2639
      mdp = new_pointer_register();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2640
      __ leal(LIR_OprFact::address(base_type_address), mdp);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2641
    }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2642
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2643
  LIRItem value(arg, this);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2644
  value.load_item();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2645
  __ profile_type(new LIR_Address(mdp, md_offset, T_METADATA),
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2646
                  value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != NULL);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2647
  return result;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2648
}
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  2649
21095
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2650
// profile parameters on entry to the root of the compilation
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2651
void LIRGenerator::profile_parameters(Base* x) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2652
  if (compilation()->profile_parameters()) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2653
    CallingConvention* args = compilation()->frame_map()->incoming_arguments();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2654
    ciMethodData* md = scope()->method()->method_data_or_null();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2655
    assert(md != NULL, "Sanity");
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2656
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2657
    if (md->parameters_type_data() != NULL) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2658
      ciParametersTypeData* parameters_type_data = md->parameters_type_data();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2659
      ciTypeStackSlotEntries* parameters =  parameters_type_data->parameters();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2660
      LIR_Opr mdp = LIR_OprFact::illegalOpr;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2661
      for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2662
        LIR_Opr src = args->at(i);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2663
        assert(!src->is_illegal(), "check");
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2664
        BasicType t = src->type();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2665
        if (t == T_OBJECT || t == T_ARRAY) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2666
          intptr_t profiled_k = parameters->type(j);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2667
          Local* local = x->state()->local_at(java_index)->as_Local();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2668
          ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2669
                                            in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)),
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2670
                                            profiled_k, local, mdp, false, local->declared_type()->as_klass());
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2671
          // If the profile is known statically set it once for all and do not emit any code
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2672
          if (exact != NULL) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2673
            md->set_parameter_type(j, exact);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2674
          }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2675
          j++;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2676
        }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2677
        java_index += type2size[t];
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2678
      }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2679
    }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2680
  }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2681
}
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2682
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2683
void LIRGenerator::do_Base(Base* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2684
  __ std_entry(LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2685
  // Emit moves from physical registers / stack slots to virtual registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2686
  CallingConvention* args = compilation()->frame_map()->incoming_arguments();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2687
  IRScope* irScope = compilation()->hir()->top_scope();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2688
  int java_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2689
  for (int i = 0; i < args->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2690
    LIR_Opr src = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2691
    assert(!src->is_illegal(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2692
    BasicType t = src->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2693
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2694
    // Types which are smaller than int are passed as int, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2695
    // correct the type which passed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2696
    switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2697
    case T_BYTE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2698
    case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2699
    case T_SHORT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2700
    case T_CHAR:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2701
      t = T_INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2702
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2703
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2704
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2705
    LIR_Opr dest = new_register(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2706
    __ move(src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2707
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2708
    // Assign new location to Local instruction for this local
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2709
    Local* local = x->state()->local_at(java_index)->as_Local();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2710
    assert(local != NULL, "Locals for incoming arguments must have been created");
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  2711
#ifndef __SOFTFP__
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  2712
    // The java calling convention passes double as long and float as int.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2713
    assert(as_ValueType(t)->tag() == local->type()->tag(), "check");
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
  2714
#endif // __SOFTFP__
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2715
    local->set_operand(dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2716
    _instruction_for_operand.at_put_grow(dest->vreg_number(), local, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2717
    java_index += type2size[t];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2718
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2719
2867
69187054225f 6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents: 2105
diff changeset
  2720
  if (compilation()->env()->dtrace_method_probes()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2721
    BasicTypeList signature;
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2722
    signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT));    // thread
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  2723
    signature.append(T_OBJECT); // Method*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2724
    LIR_OprList* args = new LIR_OprList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2725
    args->append(getThreadPointer());
13742
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
  2726
    LIR_Opr meth = new_register(T_METADATA);
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
  2727
    __ metadata2reg(method()->constant_encoding(), meth);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2728
    args->append(meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2729
    call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2730
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2731
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2732
  if (method()->is_synchronized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2733
    LIR_Opr obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2734
    if (method()->is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2735
      obj = new_register(T_OBJECT);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 3172
diff changeset
  2736
      __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2737
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2738
      Local* receiver = x->state()->local_at(0)->as_Local();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2739
      assert(receiver != NULL, "must already exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2740
      obj = receiver->operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2741
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2742
    assert(obj->is_valid(), "must be valid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2743
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2744
    if (method()->is_synchronized() && GenerateSynchronizationCode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2745
      LIR_Opr lock = new_register(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2746
      __ load_stack_address_monitor(0, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2747
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  2748
      CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, x->check_flag(Instruction::DeoptimizeOnException));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2749
      CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2750
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2751
      // receiver is guaranteed non-NULL so don't need CodeEmitInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2752
      __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2753
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2754
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2755
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2756
  // increment invocation counters if needed
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2757
  if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
21095
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  2758
    profile_parameters(x);
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  2759
    CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL, false);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2760
    increment_invocation_counter(info);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  2761
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2762
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2763
  // all blocks with a successor must end with an unconditional jump
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2764
  // to the successor even if they are consecutive
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2765
  __ jump(x->default_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2766
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2767
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2768
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2769
void LIRGenerator::do_OsrEntry(OsrEntry* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2770
  // construct our frame and model the production of incoming pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2771
  // to the OSR buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2772
  __ osr_entry(LIR_Assembler::osrBufferPointer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2773
  LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2774
  __ move(LIR_Assembler::osrBufferPointer(), result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2775
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2776
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2778
void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) {
13487
75aa4880b15f 7192167: JSR 292: C1 has old broken code which needs to be removed
twisti
parents: 13486
diff changeset
  2779
  assert(args->length() == arg_list->length(),
75aa4880b15f 7192167: JSR 292: C1 has old broken code which needs to be removed
twisti
parents: 13486
diff changeset
  2780
         err_msg_res("args=%d, arg_list=%d", args->length(), arg_list->length()));
75aa4880b15f 7192167: JSR 292: C1 has old broken code which needs to be removed
twisti
parents: 13486
diff changeset
  2781
  for (int i = x->has_receiver() ? 1 : 0; i < args->length(); i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2782
    LIRItem* param = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2783
    LIR_Opr loc = arg_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2784
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2785
      param->load_item_force(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2786
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2787
      LIR_Address* addr = loc->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2788
      param->load_for_store(addr->type());
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2789
      if (addr->type() == T_OBJECT) {
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2790
        __ move_wide(param->result(), addr);
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2791
      } else
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2792
        if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2793
          __ unaligned_move(param->result(), addr);
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2794
        } else {
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2795
          __ move(param->result(), addr);
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2796
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2797
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2798
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2799
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2800
  if (x->has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2801
    LIRItem* receiver = args->at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2802
    LIR_Opr loc = arg_list->at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2803
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2804
      receiver->load_item_force(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2805
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2806
      assert(loc->is_address(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2807
      receiver->load_for_store(T_OBJECT);
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
  2808
      __ move_wide(receiver->result(), loc->as_address_ptr());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2809
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2810
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2811
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2812
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2813
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2814
// Visits all arguments, returns appropriate items without loading them
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2815
LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2816
  LIRItemList* argument_items = new LIRItemList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2817
  if (x->has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2818
    LIRItem* receiver = new LIRItem(x->receiver(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2819
    argument_items->append(receiver);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2820
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2821
  for (int i = 0; i < x->number_of_arguments(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2822
    LIRItem* param = new LIRItem(x->argument_at(i), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2823
    argument_items->append(param);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2824
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2825
  return argument_items;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2826
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2827
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2828
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2829
// The invoke with receiver has following phases:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2830
//   a) traverse and load/lock receiver;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2831
//   b) traverse all arguments -> item-array (invoke_visit_argument)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2832
//   c) push receiver on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2833
//   d) load each of the items and push on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2834
//   e) unlock receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2835
//   f) move receiver into receiver-register %o0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2836
//   g) lock result registers and emit call operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2837
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2838
// Before issuing a call, we must spill-save all values on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2839
// that are in caller-save register. "spill-save" moves thos registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2840
// either in a free callee-save register or spills them if no free
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2841
// callee save register is available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2842
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2843
// The problem is where to invoke spill-save.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2844
// - if invoked between e) and f), we may lock callee save
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2845
//   register in "spill-save" that destroys the receiver register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2846
//   before f) is executed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2847
// - if we rearange the f) to be earlier, by loading %o0, it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2848
//   may destroy a value on the stack that is currently in %o0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2849
//   and is waiting to be spilled
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2850
// - if we keep the receiver locked while doing spill-save,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2851
//   we cannot spill it as it is spill-locked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2852
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2853
void LIRGenerator::do_Invoke(Invoke* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2854
  CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2855
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2856
  LIR_OprList* arg_list = cc->args();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2857
  LIRItemList* args = invoke_visit_arguments(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2858
  LIR_Opr receiver = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2859
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2860
  // setup result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2861
  LIR_Opr result_register = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2862
  if (x->type() != voidType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2863
    result_register = result_register_for(x->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2864
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2865
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2866
  CodeEmitInfo* info = state_for(x, x->state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2867
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2868
  invoke_load_arguments(x, args, arg_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2869
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2870
  if (x->has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2871
    args->at(0)->load_item_force(LIR_Assembler::receiverOpr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2872
    receiver = args->at(0)->result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2873
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2874
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2875
  // emit invoke code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2876
  bool optimized = x->target_is_loaded() && x->target_is_final();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2877
  assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2878
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2879
  // JSR 292
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2880
  // Preserve the SP over MethodHandle call sites.
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2881
  ciMethod* target = x->target();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  2882
  bool is_method_handle_invoke = (// %%% FIXME: Are both of these relevant?
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  2883
                                  target->is_method_handle_intrinsic() ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  2884
                                  target->is_compiled_lambda_form());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  2885
  if (is_method_handle_invoke) {
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2886
    info->set_is_method_handle_invoke(true);
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2887
    __ move(FrameMap::stack_pointer(), FrameMap::method_handle_invoke_SP_save_opr());
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2888
  }
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2889
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2890
  switch (x->code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2891
    case Bytecodes::_invokestatic:
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2892
      __ call_static(target, result_register,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2893
                     SharedRuntime::get_resolve_static_call_stub(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2894
                     arg_list, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2895
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2896
    case Bytecodes::_invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2897
    case Bytecodes::_invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2898
    case Bytecodes::_invokeinterface:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2899
      // for final target we still produce an inline cache, in order
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2900
      // to be able to call mixed mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2901
      if (x->code() == Bytecodes::_invokespecial || optimized) {
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2902
        __ call_opt_virtual(target, receiver, result_register,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2903
                            SharedRuntime::get_resolve_opt_virtual_call_stub(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2904
                            arg_list, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2905
      } else if (x->vtable_index() < 0) {
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2906
        __ call_icvirtual(target, receiver, result_register,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2907
                          SharedRuntime::get_resolve_virtual_call_stub(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2908
                          arg_list, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2909
      } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  2910
        int entry_offset = InstanceKlass::vtable_start_offset() + x->vtable_index() * vtableEntry::size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2911
        int vtable_offset = entry_offset * wordSize + vtableEntry::method_offset_in_bytes();
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2912
        __ call_virtual(target, receiver, result_register, vtable_offset, arg_list, info);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2913
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2914
      break;
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4761
diff changeset
  2915
    case Bytecodes::_invokedynamic: {
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2916
      __ call_dynamic(target, receiver, result_register,
13487
75aa4880b15f 7192167: JSR 292: C1 has old broken code which needs to be removed
twisti
parents: 13486
diff changeset
  2917
                      SharedRuntime::get_resolve_static_call_stub(),
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4761
diff changeset
  2918
                      arg_list, info);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4761
diff changeset
  2919
      break;
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 4761
diff changeset
  2920
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2921
    default:
12959
4d33f9be7e87 7174928: JSR 292: unresolved invokedynamic call sites deopt and osr infinitely
twisti
parents: 12957
diff changeset
  2922
      fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(x->code())));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2923
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2924
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2925
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2926
  // JSR 292
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2927
  // Restore the SP after MethodHandle call sites.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  2928
  if (is_method_handle_invoke) {
5687
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2929
    __ move(FrameMap::method_handle_invoke_SP_save_opr(), FrameMap::stack_pointer());
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2930
  }
b862d1f189bd 6930772: JSR 292 needs to support SPARC C1
twisti
parents: 5334
diff changeset
  2931
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2932
  if (x->type()->is_float() || x->type()->is_double()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2933
    // Force rounding of results from non-strictfp when in strictfp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2934
    // scope (or when we don't know the strictness of the callee, to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2935
    // be safe.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2936
    if (method()->is_strict()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2937
      if (!x->target_is_loaded() || !x->target_is_strictfp()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2938
        result_register = round_item(result_register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2939
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2940
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2941
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2942
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2943
  if (result_register->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2944
    LIR_Opr result = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2945
    __ move(result_register, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2946
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2947
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2948
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2949
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2950
void LIRGenerator::do_FPIntrinsics(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2951
  assert(x->number_of_arguments() == 1, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2952
  LIRItem value       (x->argument_at(0), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2953
  LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2954
  value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2955
  LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2956
  __ move(tmp, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2957
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2958
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2959
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2960
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2961
// Code for  :  x->x() {x->cond()} x->y() ? x->tval() : x->fval()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2962
void LIRGenerator::do_IfOp(IfOp* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2963
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2964
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2965
    ValueTag xtag = x->x()->type()->tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2966
    ValueTag ttag = x->tval()->type()->tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2967
    assert(xtag == intTag || xtag == objectTag, "cannot handle others");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2968
    assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2969
    assert(ttag == x->fval()->type()->tag(), "cannot handle others");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2970
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2971
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2972
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2973
  LIRItem left(x->x(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2974
  LIRItem right(x->y(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2975
  left.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2976
  if (can_inline_as_constant(right.value())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2977
    right.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2978
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2979
    right.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2980
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2981
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2982
  LIRItem t_val(x->tval(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2983
  LIRItem f_val(x->fval(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2984
  t_val.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2985
  f_val.dont_load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2986
  LIR_Opr reg = rlock_result(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2987
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2988
  __ cmp(lir_cond(x->cond()), left.result(), right.result());
7713
1e06d2419258 7009231: C1: Incorrect CAS code for longs on SPARC 32bit
iveresov
parents: 7432
diff changeset
  2989
  __ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg, as_BasicType(x->x()->type()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2990
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2991
12377
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2992
void LIRGenerator::do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x) {
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2993
    assert(x->number_of_arguments() == expected_arguments, "wrong type");
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2994
    LIR_Opr reg = result_register_for(x->type());
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2995
    __ call_runtime_leaf(routine, getThreadTemp(),
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2996
                         reg, new LIR_OprList());
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2997
    LIR_Opr result = rlock_result(x);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2998
    __ move(reg, result);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  2999
}
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3000
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3001
#ifdef TRACE_HAVE_INTRINSICS
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3002
void LIRGenerator::do_ThreadIDIntrinsic(Intrinsic* x) {
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3003
    LIR_Opr thread = getThreadPointer();
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3004
    LIR_Opr osthread = new_pointer_register();
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3005
    __ move(new LIR_Address(thread, in_bytes(JavaThread::osthread_offset()), osthread->type()), osthread);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3006
    size_t thread_id_size = OSThread::thread_id_size();
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3007
    if (thread_id_size == (size_t) BytesPerLong) {
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3008
      LIR_Opr id = new_register(T_LONG);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3009
      __ move(new LIR_Address(osthread, in_bytes(OSThread::thread_id_offset()), T_LONG), id);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3010
      __ convert(Bytecodes::_l2i, id, rlock_result(x));
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3011
    } else if (thread_id_size == (size_t) BytesPerInt) {
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3012
      __ move(new LIR_Address(osthread, in_bytes(OSThread::thread_id_offset()), T_INT), rlock_result(x));
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3013
    } else {
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3014
      ShouldNotReachHere();
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3015
    }
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3016
}
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3017
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3018
void LIRGenerator::do_ClassIDIntrinsic(Intrinsic* x) {
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3019
    CodeEmitInfo* info = state_for(x);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3020
    CodeEmitInfo* info2 = new CodeEmitInfo(info); // Clone for the second null check
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  3021
    BasicType klass_pointer_type = NOT_LP64(T_INT) LP64_ONLY(T_LONG);
12377
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3022
    assert(info != NULL, "must have info");
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3023
    LIRItem arg(x->argument_at(1), this);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3024
    arg.load_item();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  3025
    LIR_Opr klass = new_pointer_register();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  3026
    __ move(new LIR_Address(arg.result(), java_lang_Class::klass_offset_in_bytes(), klass_pointer_type), klass, info);
12377
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3027
    LIR_Opr id = new_register(T_LONG);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3028
    ByteSize offset = TRACE_ID_OFFSET;
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3029
    LIR_Address* trace_id_addr = new LIR_Address(klass, in_bytes(offset), T_LONG);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3030
    __ move(trace_id_addr, id);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3031
    __ logical_or(id, LIR_OprFact::longConst(0x01l), id);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3032
    __ store(id, trace_id_addr);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3033
    __ logical_and(id, LIR_OprFact::longConst(~0x3l), id);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3034
    __ move(id, rlock_result(x));
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3035
}
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3036
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3038
void LIRGenerator::do_Intrinsic(Intrinsic* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3039
  switch (x->id()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3040
  case vmIntrinsics::_intBitsToFloat      :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3041
  case vmIntrinsics::_doubleToRawLongBits :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3042
  case vmIntrinsics::_longBitsToDouble    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3043
  case vmIntrinsics::_floatToRawIntBits   : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3044
    do_FPIntrinsics(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3045
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3046
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3047
12377
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3048
#ifdef TRACE_HAVE_INTRINSICS
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3049
  case vmIntrinsics::_threadID: do_ThreadIDIntrinsic(x); break;
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3050
  case vmIntrinsics::_classID: do_ClassIDIntrinsic(x); break;
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3051
  case vmIntrinsics::_counterTime:
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3052
    do_RuntimeCall(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), 0, x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3053
    break;
12377
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3054
#endif
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3055
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3056
  case vmIntrinsics::_currentTimeMillis:
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3057
    do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeMillis), 0, x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3058
    break;
12377
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3059
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3060
  case vmIntrinsics::_nanoTime:
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3061
    do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeNanos), 0, x);
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 11886
diff changeset
  3062
    break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3064
  case vmIntrinsics::_Object_init:    do_RegisterFinalizer(x); break;
12949
e125ba4c16bd 7171890: C1: add Class.isInstance intrinsic
roland
parents: 12739
diff changeset
  3065
  case vmIntrinsics::_isInstance:     do_isInstance(x);    break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3066
  case vmIntrinsics::_getClass:       do_getClass(x);      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3067
  case vmIntrinsics::_currentThread:  do_currentThread(x); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3068
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3069
  case vmIntrinsics::_dlog:           // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3070
  case vmIntrinsics::_dlog10:         // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3071
  case vmIntrinsics::_dabs:           // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3072
  case vmIntrinsics::_dsqrt:          // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3073
  case vmIntrinsics::_dtan:           // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3074
  case vmIntrinsics::_dsin :          // fall through
12739
09f26b73ae66 7133857: exp() and pow() should use the x87 ISA on x86
roland
parents: 12377
diff changeset
  3075
  case vmIntrinsics::_dcos :          // fall through
09f26b73ae66 7133857: exp() and pow() should use the x87 ISA on x86
roland
parents: 12377
diff changeset
  3076
  case vmIntrinsics::_dexp :          // fall through
09f26b73ae66 7133857: exp() and pow() should use the x87 ISA on x86
roland
parents: 12377
diff changeset
  3077
  case vmIntrinsics::_dpow :          do_MathIntrinsic(x); break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3078
  case vmIntrinsics::_arraycopy:      do_ArrayCopy(x);     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3080
  // java.nio.Buffer.checkIndex
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3081
  case vmIntrinsics::_checkIndex:     do_NIOCheckIndex(x); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3082
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3083
  case vmIntrinsics::_compareAndSwapObject:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3084
    do_CompareAndSwap(x, objectType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3085
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3086
  case vmIntrinsics::_compareAndSwapInt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3087
    do_CompareAndSwap(x, intType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3088
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3089
  case vmIntrinsics::_compareAndSwapLong:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3090
    do_CompareAndSwap(x, longType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3091
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3092
14832
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3093
  case vmIntrinsics::_loadFence :
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3094
    if (os::is_MP()) __ membar_acquire();
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3095
    break;
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3096
  case vmIntrinsics::_storeFence:
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3097
    if (os::is_MP()) __ membar_release();
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3098
    break;
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3099
  case vmIntrinsics::_fullFence :
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3100
    if (os::is_MP()) __ membar();
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3101
    break;
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 13969
diff changeset
  3102
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  3103
  case vmIntrinsics::_Reference_get:
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  3104
    do_Reference_get(x);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  3105
    break;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8676
diff changeset
  3106
18507
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 17879
diff changeset
  3107
  case vmIntrinsics::_updateCRC32:
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 17879
diff changeset
  3108
  case vmIntrinsics::_updateBytesCRC32:
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 17879
diff changeset
  3109
  case vmIntrinsics::_updateByteBufferCRC32:
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 17879
diff changeset
  3110
    do_update_CRC32(x);
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 17879
diff changeset
  3111
    break;
61bfc8995bb3 7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
drchase
parents: 17879
diff changeset
  3112
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3113
  default: ShouldNotReachHere(); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3116
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3117
void LIRGenerator::profile_arguments(ProfileCall* x) {
21095
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3118
  if (compilation()->profile_arguments()) {
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3119
    int bci = x->bci_of_invoke();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3120
    ciMethodData* md = x->method()->method_data_or_null();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3121
    ciProfileData* data = md->bci_to_data(bci);
21095
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3122
    if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) ||
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3123
        (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) {
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3124
      ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3125
      int base_offset = md->byte_offset_of_slot(data, extra);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3126
      LIR_Opr mdp = LIR_OprFact::illegalOpr;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3127
      ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3128
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3129
      Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3130
      int start = 0;
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3131
      int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments();
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3132
      if (x->nb_profiled_args() < stop) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3133
        // if called through method handle invoke, some arguments may have been popped
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3134
        stop = x->nb_profiled_args();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3135
      }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3136
      ciSignature* sig = x->callee()->signature();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3137
      // method handle call to virtual method
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3138
      bool has_receiver = x->inlined() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3139
      ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3140
      for (int i = 0; i < stop; i++) {
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3141
        int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset());
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3142
        ciKlass* exact = profile_arg_type(md, base_offset, off,
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3143
                                          args->type(i), x->profiled_arg_at(i+start), mdp,
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3144
                                          !x->arg_needs_null_check(i+start), sig_stream.next_klass());
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3145
        if (exact != NULL) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3146
          md->set_argument_type(bci, i, exact);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3147
        }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3148
      }
21095
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3149
    } else {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3150
#ifdef ASSERT
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3151
      Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke());
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3152
      int n = x->nb_profiled_args();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3153
      assert(MethodData::profile_parameters() && x->inlined() &&
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3154
             ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)),
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3155
             "only at JSR292 bytecodes");
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3156
#endif
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3157
    }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3158
  }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3159
}
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3160
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3161
// profile parameters on entry to an inlined method
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3162
void LIRGenerator::profile_parameters_at_call(ProfileCall* x) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3163
  if (compilation()->profile_parameters() && x->inlined()) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3164
    ciMethodData* md = x->callee()->method_data_or_null();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3165
    if (md != NULL) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3166
      ciParametersTypeData* parameters_type_data = md->parameters_type_data();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3167
      if (parameters_type_data != NULL) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3168
        ciTypeStackSlotEntries* parameters =  parameters_type_data->parameters();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3169
        LIR_Opr mdp = LIR_OprFact::illegalOpr;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3170
        bool has_receiver = !x->callee()->is_static();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3171
        ciSignature* sig = x->callee()->signature();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3172
        ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : NULL);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3173
        int i = 0; // to iterate on the Instructions
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3174
        Value arg = x->recv();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3175
        bool not_null = false;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3176
        int bci = x->bci_of_invoke();
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3177
        Bytecodes::Code bc = x->method()->java_code_at_bci(bci);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3178
        // The first parameter is the receiver so that's what we start
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3179
        // with if it exists. On exception if method handle call to
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3180
        // virtual method has receiver in the args list
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3181
        if (arg == NULL || !Bytecodes::has_receiver(bc)) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3182
          i = 1;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3183
          arg = x->profiled_arg_at(0);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3184
          not_null = !x->arg_needs_null_check(0);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3185
        }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3186
        int k = 0; // to iterate on the profile data
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3187
        for (;;) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3188
          intptr_t profiled_k = parameters->type(k);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3189
          ciKlass* exact = profile_arg_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)),
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3190
                                            in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)),
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3191
                                            profiled_k, arg, mdp, not_null, sig_stream.next_klass());
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3192
          // If the profile is known statically set it once for all and do not emit any code
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3193
          if (exact != NULL) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3194
            md->set_parameter_type(k, exact);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3195
          }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3196
          k++;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3197
          if (k >= parameters_type_data->number_of_parameters()) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3198
#ifdef ASSERT
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3199
            int extra = 0;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3200
            if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 &&
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3201
                x->nb_profiled_args() >= TypeProfileParmsLimit &&
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3202
                x->recv() != NULL && Bytecodes::has_receiver(bc)) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3203
              extra += 1;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3204
            }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3205
            assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?");
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3206
#endif
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3207
            break;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3208
          }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3209
          arg = x->profiled_arg_at(i);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3210
          not_null = !x->arg_needs_null_check(i);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3211
          i++;
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3212
        }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3213
      }
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3214
    }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3215
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3216
}
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3217
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3218
void LIRGenerator::do_ProfileCall(ProfileCall* x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3219
  // Need recv in a temporary register so it interferes with the other temporaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3220
  LIR_Opr recv = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3221
  LIR_Opr mdo = new_register(T_OBJECT);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3222
  // tmp is used to hold the counters on SPARC
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3223
  LIR_Opr tmp = new_pointer_register();
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3224
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3225
  if (x->nb_profiled_args() > 0) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3226
    profile_arguments(x);
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3227
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 20695
diff changeset
  3228
21095
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3229
  // profile parameters on inlined method entry including receiver
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3230
  if (x->recv() != NULL || x->nb_profiled_args() > 0) {
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3231
    profile_parameters_at_call(x);
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3232
  }
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 21088
diff changeset
  3233
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3234
  if (x->recv() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3235
    LIRItem value(x->recv(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3236
    value.load_item();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3237
    recv = new_register(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3238
    __ move(value.result(), recv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3239
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 12959
diff changeset
  3240
  __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3242
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3243
void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) {
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3244
  int bci = x->bci_of_invoke();
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3245
  ciMethodData* md = x->method()->method_data_or_null();
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3246
  ciProfileData* data = md->bci_to_data(bci);
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3247
  assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type");
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3248
  ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret();
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3249
  LIR_Opr mdp = LIR_OprFact::illegalOpr;
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3250
  ciKlass* exact = profile_arg_type(md, 0, md->byte_offset_of_slot(data, ret->type_offset()),
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3251
                                    ret->type(), x->ret(), mdp,
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3252
                                    !x->needs_null_check(), x->callee()->signature()->return_type()->as_klass());
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3253
  if (exact != NULL) {
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3254
    md->set_return_type(bci, exact);
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3255
  }
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3256
}
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 20702
diff changeset
  3257
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3258
void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3259
  // We can safely ignore accessors here, since c2 will inline them anyway,
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3260
  // accessors are also always mature.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3261
  if (!x->inlinee()->is_accessor()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3262
    CodeEmitInfo* info = state_for(x, x->state(), true);
10569
f5ce1108443b 7096639: Tiered: Incorrect counter overflow handling for inlined methods
iveresov
parents: 9979
diff changeset
  3263
    // Notify the runtime very infrequently only to take care of counter overflows
f5ce1108443b 7096639: Tiered: Incorrect counter overflow handling for inlined methods
iveresov
parents: 9979
diff changeset
  3264
    increment_event_counter_impl(info, x->inlinee(), (1 << Tier23InlineeNotifyFreqLog) - 1, InvocationEntryBci, false, true);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3265
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3266
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3267
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3268
void LIRGenerator::increment_event_counter(CodeEmitInfo* info, int bci, bool backedge) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3269
  int freq_log;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3270
  int level = compilation()->env()->comp_level();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3271
  if (level == CompLevel_limited_profile) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3272
    freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3273
  } else if (level == CompLevel_full_profile) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3274
    freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3275
  } else {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3276
    ShouldNotReachHere();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3277
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3278
  // Increment the appropriate invocation/backedge counter and notify the runtime.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3279
  increment_event_counter_impl(info, info->scope()->method(), (1 << freq_log) - 1, bci, backedge, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3281
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3282
void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3283
                                                ciMethod *method, int frequency,
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3284
                                                int bci, bool backedge, bool notify) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3285
  assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3286
  int level = _compilation->env()->comp_level();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3287
  assert(level > CompLevel_simple, "Shouldn't be here");
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3288
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3289
  int offset = -1;
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3290
  LIR_Opr counter_holder;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3291
  if (level == CompLevel_limited_profile) {
20695
4f5a5e95090b 8025566: EXCEPTION_ACCESS_VIOLATION in compiled by C1 String.valueOf method
twisti
parents: 19156
diff changeset
  3292
    MethodCounters* counters_adr = method->ensure_method_counters();
4f5a5e95090b 8025566: EXCEPTION_ACCESS_VIOLATION in compiled by C1 String.valueOf method
twisti
parents: 19156
diff changeset
  3293
    if (counters_adr == NULL) {
4f5a5e95090b 8025566: EXCEPTION_ACCESS_VIOLATION in compiled by C1 String.valueOf method
twisti
parents: 19156
diff changeset
  3294
      bailout("method counters allocation failed");
4f5a5e95090b 8025566: EXCEPTION_ACCESS_VIOLATION in compiled by C1 String.valueOf method
twisti
parents: 19156
diff changeset
  3295
      return;
4f5a5e95090b 8025566: EXCEPTION_ACCESS_VIOLATION in compiled by C1 String.valueOf method
twisti
parents: 19156
diff changeset
  3296
    }
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3297
    counter_holder = new_pointer_register();
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3298
    __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3299
    offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3300
                                 MethodCounters::invocation_counter_offset());
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3301
  } else if (level == CompLevel_full_profile) {
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3302
    counter_holder = new_register(T_METADATA);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  3303
    offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
  3304
                                 MethodData::invocation_counter_offset());
7432
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7427
diff changeset
  3305
    ciMethodData* md = method->method_data_or_null();
f06f1253c317 7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents: 7427
diff changeset
  3306
    assert(md != NULL, "Sanity");
13742
9180987e305d 7195816: NPG: Crash in c1_ValueType - ShouldNotReachHere
roland
parents: 13734
diff changeset
  3307
    __ metadata2reg(md->constant_encoding(), counter_holder);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3308
  } else {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3309
    ShouldNotReachHere();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3310
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3311
  LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3312
  LIR_Opr result = new_register(T_INT);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3313
  __ load(counter, result);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3314
  __ add(result, LIR_OprFact::intConst(InvocationCounter::count_increment), result);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3315
  __ store(result, counter);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3316
  if (notify) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3317
    LIR_Opr mask = load_immediate(frequency << InvocationCounter::count_shift, T_INT);
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3318
    LIR_Opr meth = new_register(T_METADATA);
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16620
diff changeset
  3319
    __ metadata2reg(method->constant_encoding(), meth);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3320
    __ logical_and(result, mask, result);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3321
    __ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0));
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3322
    // The bci for info can point to cmp for if's we want the if bci
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3323
    CodeStub* overflow = new CounterOverflowStub(info, bci, meth);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3324
    __ branch(lir_cond_equal, T_INT, overflow);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3325
    __ branch_destination(overflow->continuation());
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3326
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6176
diff changeset
  3327
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3328
8065
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3329
void LIRGenerator::do_RuntimeCall(RuntimeCall* x) {
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3330
  LIR_OprList* args = new LIR_OprList(x->number_of_arguments());
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3331
  BasicTypeList* signature = new BasicTypeList(x->number_of_arguments());
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3332
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3333
  if (x->pass_thread()) {
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3334
    signature->append(T_ADDRESS);
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3335
    args->append(getThreadPointer());
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3336
  }
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3337
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3338
  for (int i = 0; i < x->number_of_arguments(); i++) {
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3339
    Value a = x->argument_at(i);
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3340
    LIRItem* item = new LIRItem(a, this);
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3341
    item->load_item();
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3342
    args->append(item->result());
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3343
    signature->append(as_BasicType(a->type()));
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3344
  }
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3345
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3346
  LIR_Opr result = call_runtime(signature, args, x->entry(), x->type(), NULL);
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3347
  if (x->type() == voidType) {
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3348
    set_no_result(x);
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3349
  } else {
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3350
    __ move(result, rlock_result(x));
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3351
  }
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3352
}
7ca689ce3d32 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 7713
diff changeset
  3353
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16672
diff changeset
  3354
#ifdef ASSERT
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3355
void LIRGenerator::do_Assert(Assert *x) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3356
  ValueTag tag = x->x()->type()->tag();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3357
  If::Condition cond = x->cond();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3358
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3359
  LIRItem xitem(x->x(), this);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3360
  LIRItem yitem(x->y(), this);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3361
  LIRItem* xin = &xitem;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3362
  LIRItem* yin = &yitem;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3363
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3364
  assert(tag == intTag, "Only integer assertions are valid!");
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3365
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3366
  xin->load_item();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3367
  yin->dont_load_item();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3368
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3369
  set_no_result(x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3370
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3371
  LIR_Opr left = xin->result();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3372
  LIR_Opr right = yin->result();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3373
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3374
  __ lir_assert(lir_cond(x->cond()), left, right, x->message(), true);
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16672
diff changeset
  3375
}
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3376
#endif
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3377
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3378
void LIRGenerator::do_RangeCheckPredicate(RangeCheckPredicate *x) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3379
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3380
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3381
  Instruction *a = x->x();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3382
  Instruction *b = x->y();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3383
  if (!a || StressRangeCheckElimination) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3384
    assert(!b || StressRangeCheckElimination, "B must also be null");
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3385
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3386
    CodeEmitInfo *info = state_for(x, x->state());
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3387
    CodeStub* stub = new PredicateFailedStub(info);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3388
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3389
    __ jump(stub);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3390
  } else if (a->type()->as_IntConstant() && b->type()->as_IntConstant()) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3391
    int a_int = a->type()->as_IntConstant()->value();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3392
    int b_int = b->type()->as_IntConstant()->value();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3393
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3394
    bool ok = false;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3395
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3396
    switch(x->cond()) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3397
      case Instruction::eql: ok = (a_int == b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3398
      case Instruction::neq: ok = (a_int != b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3399
      case Instruction::lss: ok = (a_int < b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3400
      case Instruction::leq: ok = (a_int <= b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3401
      case Instruction::gtr: ok = (a_int > b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3402
      case Instruction::geq: ok = (a_int >= b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3403
      case Instruction::aeq: ok = ((unsigned int)a_int >= (unsigned int)b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3404
      case Instruction::beq: ok = ((unsigned int)a_int <= (unsigned int)b_int); break;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3405
      default: ShouldNotReachHere();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3406
    }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3407
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3408
    if (ok) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3409
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3410
      CodeEmitInfo *info = state_for(x, x->state());
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3411
      CodeStub* stub = new PredicateFailedStub(info);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3412
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3413
      __ jump(stub);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3414
    }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3415
  } else {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3416
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3417
    ValueTag tag = x->x()->type()->tag();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3418
    If::Condition cond = x->cond();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3419
    LIRItem xitem(x->x(), this);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3420
    LIRItem yitem(x->y(), this);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3421
    LIRItem* xin = &xitem;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3422
    LIRItem* yin = &yitem;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3423
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3424
    assert(tag == intTag, "Only integer deoptimizations are valid!");
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3425
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3426
    xin->load_item();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3427
    yin->dont_load_item();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3428
    set_no_result(x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3429
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3430
    LIR_Opr left = xin->result();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3431
    LIR_Opr right = yin->result();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3432
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3433
    CodeEmitInfo *info = state_for(x, x->state());
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3434
    CodeStub* stub = new PredicateFailedStub(info);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3435
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3436
    __ cmp(lir_cond(cond), left, right);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3437
    __ branch(lir_cond(cond), right->type(), stub);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3438
  }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3439
}
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3440
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15482
diff changeset
  3441
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3442
LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3443
  LIRItemList args(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3444
  LIRItem value(arg1, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3445
  args.append(&value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3446
  BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3447
  signature.append(as_BasicType(arg1->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3448
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3449
  return call_runtime(&signature, &args, entry, result_type, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3450
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3451
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3452
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3453
LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3454
  LIRItemList args(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3455
  LIRItem value1(arg1, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3456
  LIRItem value2(arg2, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3457
  args.append(&value1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3458
  args.append(&value2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3459
  BasicTypeList signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3460
  signature.append(as_BasicType(arg1->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3461
  signature.append(as_BasicType(arg2->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3462
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3463
  return call_runtime(&signature, &args, entry, result_type, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3464
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3465
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3466
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3467
LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3468
                                   address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3469
  // get a result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3470
  LIR_Opr phys_reg = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3471
  LIR_Opr result = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3472
  if (result_type->tag() != voidTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3473
    result = new_register(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3474
    phys_reg = result_register_for(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3476
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3477
  // move the arguments into the correct location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3478
  CallingConvention* cc = frame_map()->c_calling_convention(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3479
  assert(cc->length() == args->length(), "argument mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3480
  for (int i = 0; i < args->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3481
    LIR_Opr arg = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3482
    LIR_Opr loc = cc->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3483
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3484
      __ move(arg, loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3485
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3486
      LIR_Address* addr = loc->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3487
//           if (!can_store_as_constant(arg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3488
//             LIR_Opr tmp = new_register(arg->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3489
//             __ move(arg, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3490
//             arg = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3491
//           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3492
      if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3493
        __ unaligned_move(arg, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3494
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3495
        __ move(arg, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3496
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3497
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3499
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3500
  if (info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3501
    __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3502
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3503
    __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3505
  if (result->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3506
    __ move(phys_reg, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3507
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3508
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3509
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3511
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3512
LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3513
                                   address entry, ValueType* result_type, CodeEmitInfo* info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3514
  // get a result register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3515
  LIR_Opr phys_reg = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3516
  LIR_Opr result = LIR_OprFact::illegalOpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3517
  if (result_type->tag() != voidTag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3518
    result = new_register(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3519
    phys_reg = result_register_for(result_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3520
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3521
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3522
  // move the arguments into the correct location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3523
  CallingConvention* cc = frame_map()->c_calling_convention(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3525
  assert(cc->length() == args->length(), "argument mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3526
  for (int i = 0; i < args->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3527
    LIRItem* arg = args->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3528
    LIR_Opr loc = cc->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3529
    if (loc->is_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3530
      arg->load_item_force(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3531
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3532
      LIR_Address* addr = loc->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3533
      arg->load_for_store(addr->type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3534
      if (addr->type() == T_LONG || addr->type() == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3535
        __ unaligned_move(arg->result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3536
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3537
        __ move(arg->result(), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3538
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3539
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3540
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3541
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3542
  if (info) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3543
    __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3544
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3545
    __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3546
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3547
  if (result->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3548
    __ move(phys_reg, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3550
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3551
}
11886
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3552
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3553
void LIRGenerator::do_MemBar(MemBar* x) {
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3554
  if (os::is_MP()) {
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3555
    LIR_Code code = x->code();
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3556
    switch(code) {
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3557
      case lir_membar_acquire   : __ membar_acquire(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3558
      case lir_membar_release   : __ membar_release(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3559
      case lir_membar           : __ membar(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3560
      case lir_membar_loadload  : __ membar_loadload(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3561
      case lir_membar_storestore: __ membar_storestore(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3562
      case lir_membar_loadstore : __ membar_loadstore(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3563
      case lir_membar_storeload : __ membar_storeload(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3564
      default                   : ShouldNotReachHere(); break;
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3565
    }
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3566
  }
feebf5c9f40c 7120481: storeStore barrier in constructor with final field
jiangli
parents: 11563
diff changeset
  3567
}