src/hotspot/share/ci/ciType.cpp
author lfoltan
Mon, 23 Sep 2019 14:49:04 -0400
changeset 58273 08a5148e7c4e
parent 54786 ebf733a324d4
permissions -rw-r--r--
8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type Summary: Consistently use is_reference_type when comparing type for T_OBJECT or T_ARRAY. Reviewed-by: dlong, coleenp, hseigel Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
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: 54786
diff changeset
     2
 * Copyright (c) 2000, 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: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
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: 4571
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"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    26
#include "ci/ciEnv.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "ci/ciType.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47216
diff changeset
    28
#include "ci/ciUtilities.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "classfile/systemDictionary.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33611
diff changeset
    30
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 49449
diff changeset
    31
#include "memory/universe.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
ciType* ciType::_basic_types[T_CONFLICT+1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// ciType
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 54786
diff changeset
    38
// This class represents a Java reference or primitive type.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// ciType::ciType
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    43
ciType::ciType(BasicType basic_type) : ciMetadata() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _basic_type = basic_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 37248
diff changeset
    48
ciType::ciType(Klass* k) : ciMetadata(k) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 37248
diff changeset
    49
  _basic_type = k->is_array_klass() ? T_ARRAY : T_OBJECT;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// ciType::is_subtype_of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
bool ciType::is_subtype_of(ciType* type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if (this == type)  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  if (is_klass() && type->is_klass())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    return this->as_klass()->is_subtype_of(type->as_klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// ------------------------------------------------------------------
15210
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    64
// ciType::name
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    65
//
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    66
// Return the name of this type
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    67
const char* ciType::name() {
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    68
  if (is_primitive_type()) {
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    69
    return type2name(basic_type());
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    70
  } else {
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    71
    assert(is_klass(), "must be");
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    72
    return as_klass()->name()->as_utf8();
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    73
  }
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    74
}
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    75
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    76
// ------------------------------------------------------------------
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// ciType::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
void ciType::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  st->print(" type=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  print_name_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// ciType::print_name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// Print the name of this type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void ciType::print_name_on(outputStream* st) {
15210
eb42543a7050 8006109: test/java/util/AbstractSequentialList/AddAll.java fails: assert(rtype == ctype) failed: mismatched return types
twisti
parents: 14488
diff changeset
    90
  ResourceMark rm;
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    91
  st->print("%s", name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
// ciType::java_mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
ciInstance* ciType::java_mirror() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   101
  return CURRENT_THREAD_ENV->get_instance(Universe::java_mirror(basic_type()));
1
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
// ciType::box_klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
ciKlass* ciType::box_klass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (!is_primitive_type())  return this->as_klass();  // reference types are "self boxing"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // Void is "boxed" with a null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  if (basic_type() == T_VOID)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   114
  return CURRENT_THREAD_ENV->get_instance_klass(SystemDictionary::box_klass(basic_type()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// ciType::make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// Produce the ciType for a given primitive BasicType.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// As a bonus, produce the right reference type for T_OBJECT.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// Does not work on T_ARRAY.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
ciType* ciType::make(BasicType t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // short, etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Note: Bare T_ADDRESS means a raw pointer type, not a return_address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  assert((uint)t < T_CONFLICT+1, "range check");
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 1
diff changeset
   128
  if (t == T_OBJECT)  return ciEnv::_Object_klass;  // java/lang/Object
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  assert(_basic_types[t] != NULL, "domain check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return _basic_types[t];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
// ciReturnAddress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
// This class represents the type of a specific return address in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
// bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
// ciReturnAddress::ciReturnAddress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  assert(0 <= bci, "bci cannot be negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  _bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// ciReturnAddress::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
void ciReturnAddress::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  st->print(" bci=%d", _bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// ciReturnAddress::make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
ciReturnAddress* ciReturnAddress::make(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}