src/hotspot/share/ci/ciObjArrayKlass.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 51997 9ce37fa2e179
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain 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
/*
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
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/ciInstanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "ci/ciObjArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "ci/ciSymbol.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47216
diff changeset
    29
#include "ci/ciUtilities.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/objArrayKlass.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// ciObjArrayKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10008
diff changeset
    34
// This class represents a Klass* in the HotSpot virtual machine
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
    35
// whose Klass part is an ObjArrayKlass.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// ciObjArrayKlass::ciObjArrayKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// Constructor for loaded object array klasses.
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 33611
diff changeset
    41
ciObjArrayKlass::ciObjArrayKlass(Klass* k) : ciArrayKlass(k) {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 22234
diff changeset
    42
  assert(get_Klass()->is_objArray_klass(), "wrong type");
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
    43
  Klass* element_Klass = get_ObjArrayKlass()->bottom_klass();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10008
diff changeset
    44
  _base_element_klass = CURRENT_ENV->get_klass(element_Klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  assert(_base_element_klass->is_instance_klass() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
         _base_element_klass->is_type_array_klass(), "bad base klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (dimension() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    _element_klass = _base_element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    _element_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if (!ciObjectFactory::is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// ciObjArrayKlass::ciObjArrayKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// Constructor for unloaded object array klasses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                                 ciKlass* base_element_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
                                 int dimension)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  : ciArrayKlass(array_name,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10008
diff changeset
    65
                 dimension, T_OBJECT) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _base_element_klass = base_element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    assert(_base_element_klass->is_instance_klass() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
           _base_element_klass->is_type_array_klass(), "bad base klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    if (dimension == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      _element_klass = base_element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      _element_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// ciObjArrayKlass::element_klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// What is the one-level element type of this array?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
ciKlass* ciObjArrayKlass::element_klass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (_element_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    assert(dimension() > 1, "_element_klass should not be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // Produce the element klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    if (is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      VM_ENTRY_MARK;
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
    86
      Klass* element_Klass = get_ObjArrayKlass()->element_klass();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10008
diff changeset
    87
      _element_klass = CURRENT_THREAD_ENV->get_klass(element_Klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      // We are an unloaded array klass.  Attempt to fetch our
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      // element klass by name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      _element_klass = CURRENT_THREAD_ENV->get_klass_by_name_impl(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                          this,
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 8921
diff changeset
    94
                          constantPoolHandle(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                          construct_array_name(base_element_klass()->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                                               dimension() - 1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                          false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  return _element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
// ciObjArrayKlass::construct_array_name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
// Build an array name from an element name and a dimension.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                                                int dimension) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  EXCEPTION_CONTEXT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  int element_len = element_name->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   112
  Symbol* base_name_sym = element_name->get_symbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  char* name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
diff changeset
   115
  if (base_name_sym->char_at(0) == JVM_SIGNATURE_ARRAY ||
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
diff changeset
   116
      (base_name_sym->char_at(0) == JVM_SIGNATURE_CLASS &&  // watch package name 'Lxx'
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
diff changeset
   117
       base_name_sym->char_at(element_len-1) == JVM_SIGNATURE_ENDCLASS)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    int new_len = element_len + dimension + 1; // for the ['s and '\0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    name = CURRENT_THREAD_ENV->name_buffer(new_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    int pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    for ( ; pos < dimension; pos++) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
diff changeset
   124
      name[pos] = JVM_SIGNATURE_ARRAY;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    strncpy(name+pos, (char*)element_name->base(), element_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    name[new_len-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    int new_len =   3                       // for L, ;, and '\0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                  + dimension               // for ['s
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
                  + element_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    name = CURRENT_THREAD_ENV->name_buffer(new_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    int pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    for ( ; pos < dimension; pos++) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
diff changeset
   136
      name[pos] = JVM_SIGNATURE_ARRAY;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    }
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
diff changeset
   138
    name[pos++] = JVM_SIGNATURE_CLASS;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    strncpy(name+pos, (char*)element_name->base(), element_len);
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 51997
diff changeset
   140
    name[new_len-2] = JVM_SIGNATURE_ENDCLASS;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    name[new_len-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  return ciSymbol::make(name);
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
// ciObjArrayKlass::make_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
// Implementation of make.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  if (element_klass->is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    EXCEPTION_CONTEXT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    // The element klass is loaded
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10008
diff changeset
   155
    Klass* array = element_klass->get_Klass()->array_klass(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      CURRENT_THREAD_ENV->record_out_of_memory_failure();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      return ciEnv::unloaded_ciobjarrayklass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10008
diff changeset
   161
    return CURRENT_THREAD_ENV->get_obj_array_klass(array);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // The array klass was unable to be made or the element klass was
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // not loaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  ciSymbol* array_name = construct_array_name(element_klass->name(), 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  if (array_name == ciEnv::unloaded_cisymbol()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    return ciEnv::unloaded_ciobjarrayklass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    CURRENT_ENV->get_unloaded_klass(element_klass, array_name)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
                        ->as_obj_array_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// ciObjArrayKlass::make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
// Make an array klass corresponding to the specified primitive type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  GUARDED_VM_ENTRY(return make_impl(element_klass);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   182
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   183
ciKlass* ciObjArrayKlass::exact_klass() {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   184
  ciType* base = base_element_type();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   185
  if (base->is_instance_klass()) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   186
    ciInstanceKlass* ik = base->as_instance_klass();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   187
    if (ik->exact_klass() != NULL) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   188
      return this;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   189
    }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   190
  } else if (base->is_primitive_type()) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   191
    return this;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   192
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   193
  return NULL;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 13952
diff changeset
   194
}