src/hotspot/share/ci/ciArray.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 58273 08a5148e7c4e
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 49449
diff changeset
     2
 * Copyright (c) 1999, 2019, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "ci/ciArray.hpp"
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    27
#include "ci/ciArrayKlass.hpp"
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    28
#include "ci/ciConstant.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "ci/ciKlass.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49036
diff changeset
    30
#include "ci/ciUtilities.inline.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 22234
diff changeset
    31
#include "oops/objArrayOop.inline.hpp"
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 22234
diff changeset
    32
#include "oops/oop.inline.hpp"
49036
bc92debe57e4 8197999: Accessors in typeArrayOopDesc should use new Access API
rkennke
parents: 47216
diff changeset
    33
#include "oops/typeArrayOop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// ciArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// This class represents an arrayOop in the HotSpot virtual
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// machine.
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    39
static BasicType fixup_element_type(BasicType bt) {
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 49449
diff changeset
    40
  if (is_reference_type(bt))  return T_OBJECT;
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    41
  if (bt == T_BOOLEAN)  return T_BYTE;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    42
  return bt;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    43
}
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    44
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    45
ciConstant ciArray::element_value_impl(BasicType elembt,
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    46
                                       arrayOop ary,
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    47
                                       int index) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    48
  if (ary == NULL)
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    49
    return ciConstant();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    50
  assert(ary->is_array(), "");
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    51
  if (index < 0 || index >= ary->length())
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    52
    return ciConstant();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    53
  ArrayKlass* ak = (ArrayKlass*) ary->klass();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    54
  BasicType abt = ak->element_type();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    55
  if (fixup_element_type(elembt) !=
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    56
      fixup_element_type(abt))
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    57
    return ciConstant();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    58
  switch (elembt) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    59
  case T_ARRAY:
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    60
  case T_OBJECT:
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    61
    {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    62
      assert(ary->is_objArray(), "");
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    63
      objArrayOop objary = (objArrayOop) ary;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    64
      oop elem = objary->obj_at(index);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    65
      ciEnv* env = CURRENT_ENV;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    66
      ciObject* box = env->get_object(elem);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    67
      return ciConstant(T_OBJECT, box);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    68
    }
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 36330
diff changeset
    69
  default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 36330
diff changeset
    70
    break;
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    71
  }
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    72
  assert(ary->is_typeArray(), "");
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    73
  typeArrayOop tary = (typeArrayOop) ary;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    74
  jint value = 0;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    75
  switch (elembt) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    76
  case T_LONG:          return ciConstant(tary->long_at(index));
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    77
  case T_FLOAT:         return ciConstant(tary->float_at(index));
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    78
  case T_DOUBLE:        return ciConstant(tary->double_at(index));
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    79
  default:              return ciConstant();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    80
  case T_BYTE:          value = tary->byte_at(index);           break;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    81
  case T_BOOLEAN:       value = tary->byte_at(index) & 1;       break;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    82
  case T_SHORT:         value = tary->short_at(index);          break;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    83
  case T_CHAR:          value = tary->char_at(index);           break;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    84
  case T_INT:           value = tary->int_at(index);            break;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    85
  }
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    86
  return ciConstant(elembt, value);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    87
}
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    88
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    89
// ------------------------------------------------------------------
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    90
// ciArray::element_value
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    91
//
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    92
// Current value of an element.
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    93
// Returns T_ILLEGAL if there is no element at the given index.
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    94
ciConstant ciArray::element_value(int index) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    95
  BasicType elembt = element_basic_type();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    96
  GUARDED_VM_ENTRY(
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    97
    return element_value_impl(elembt, get_arrayOop(), index);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    98
  )
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
    99
}
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   100
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   101
// ------------------------------------------------------------------
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   102
// ciArray::element_value_by_offset
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   103
//
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   104
// Current value of an element at the specified offset.
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   105
// Returns T_ILLEGAL if there is no element at the given offset.
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   106
ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   107
  BasicType elembt = element_basic_type();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   108
  intptr_t shift  = exact_log2(type2aelembytes(elembt));
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   109
  intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   110
  intptr_t index = (element_offset - header) >> shift;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   111
  intptr_t offset = header + ((intptr_t)index << shift);
36330
37a0f096251b 8150186: Folding mismatched accesses with @Stable is incorrect
vlivanov
parents: 29081
diff changeset
   112
  if (offset != element_offset || index != (jint)index || index < 0 || index >= length()) {
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   113
    return ciConstant();
36330
37a0f096251b 8150186: Folding mismatched accesses with @Stable is incorrect
vlivanov
parents: 29081
diff changeset
   114
  }
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   115
  return element_value((jint) index);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 7397
diff changeset
   116
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// ciArray::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void ciArray::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  st->print(" length=%d type=", length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  klass()->print(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}