src/hotspot/share/ci/ciInstance.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 53143 6b7240a24b56
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
/*
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 38030
diff changeset
     2
 * Copyright (c) 1999, 2017, 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"
53143
6b7240a24b56 8216157: Enable inlining of java_lang_Class::is_primitive
redestad
parents: 49449
diff changeset
    26
#include "classfile/javaClasses.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "ci/ciConstant.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "ci/ciField.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "ci/ciInstance.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "ci/ciInstanceKlass.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47216
diff changeset
    31
#include "ci/ciUtilities.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// ciInstance
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// This class represents an instanceOop in the HotSpot virtual
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// machine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// ciObject::java_mirror_type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
ciType* ciInstance::java_mirror_type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  oop m = get_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Return NULL if it is not java.lang.Class.
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 1
diff changeset
    46
  if (m == NULL || m->klass() != SystemDictionary::Class_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Return either a primitive type or a klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  if (java_lang_Class::is_primitive(m)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    return ciType::make(java_lang_Class::primitive_type(m));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9123
diff changeset
    53
    Klass* k = java_lang_Class::as_Klass(m);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    assert(k != NULL, "");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9123
diff changeset
    55
    return CURRENT_THREAD_ENV->get_klass(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// ------------------------------------------------------------------
38030
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    60
// ciInstance::field_value_impl
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    61
ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 38030
diff changeset
    62
  oop obj = get_oop();
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 38030
diff changeset
    63
  assert(obj != NULL, "bad oop");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  switch(field_btype) {
38030
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    65
    case T_BYTE:    return ciConstant(field_btype, obj->byte_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    66
    case T_CHAR:    return ciConstant(field_btype, obj->char_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    67
    case T_SHORT:   return ciConstant(field_btype, obj->short_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    68
    case T_BOOLEAN: return ciConstant(field_btype, obj->bool_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    69
    case T_INT:     return ciConstant(field_btype, obj->int_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    70
    case T_FLOAT:   return ciConstant(obj->float_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    71
    case T_DOUBLE:  return ciConstant(obj->double_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    72
    case T_LONG:    return ciConstant(obj->long_field(offset));
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    73
    case T_OBJECT:  // fall through
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    74
    case T_ARRAY: {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      oop o = obj->obj_field(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      // A field will be "constant" if it is known always to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      // a non-null reference to an instance of a particular class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      // or to a particular array.  This can happen even if the instance
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      // or array is not perm.  In such a case, an "unloaded" ciArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      // or ciInstance is created.  The compiler may be able to use
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      // information about the object's class (which is exact) or length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      if (o == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        return ciConstant(field_btype, ciNullObject::make());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
        return ciConstant(field_btype, CURRENT_ENV->get_object(o));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    }
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46271
diff changeset
    90
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46271
diff changeset
    91
      fatal("no field value: %s", type2name(field_btype));
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46271
diff changeset
    92
      return ciConstant();
1
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
// ------------------------------------------------------------------
38030
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    97
// ciInstance::field_value
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    98
//
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
    99
// Constant value of a field.
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   100
ciConstant ciInstance::field_value(ciField* field) {
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   101
  assert(is_loaded(), "invalid access - must be loaded");
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   102
  assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   103
  assert(field->is_static() || klass()->is_subclass_of(field->holder()), "invalid access - must be subclass");
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   104
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   105
  GUARDED_VM_ENTRY(return field_value_impl(field->type()->basic_type(), field->offset());)
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   106
}
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   107
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   108
// ------------------------------------------------------------------
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
// ciInstance::field_value_by_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
// Constant value of a field at the specified offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
ciConstant ciInstance::field_value_by_offset(int field_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  ciInstanceKlass* ik = klass()->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  ciField* field = ik->get_field_by_offset(field_offset, false);
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 19715
diff changeset
   115
  if (field == NULL)
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 19715
diff changeset
   116
    return ciConstant();  // T_ILLEGAL
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  return field_value(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// ciInstance::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
void ciInstance::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  st->print(" type=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  klass()->print(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
}
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 7397
diff changeset
   128
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 7397
diff changeset
   129
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 7397
diff changeset
   130
ciKlass* ciInstance::java_lang_Class_klass() {
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 7397
diff changeset
   131
  VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9123
diff changeset
   132
  return CURRENT_ENV->get_metadata(java_lang_Class::as_Klass(get_oop()))->as_klass();
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 7397
diff changeset
   133
}