src/share/vm/ci/ciObjArrayKlass.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "ci/ciInstanceKlass.hpp"
aoqi@0 27 #include "ci/ciObjArrayKlass.hpp"
aoqi@0 28 #include "ci/ciSymbol.hpp"
aoqi@0 29 #include "ci/ciUtilities.hpp"
aoqi@0 30 #include "oops/objArrayKlass.hpp"
aoqi@0 31
aoqi@0 32 // ciObjArrayKlass
aoqi@0 33 //
aoqi@0 34 // This class represents a Klass* in the HotSpot virtual machine
aoqi@0 35 // whose Klass part is an ObjArrayKlass.
aoqi@0 36
aoqi@0 37 // ------------------------------------------------------------------
aoqi@0 38 // ciObjArrayKlass::ciObjArrayKlass
aoqi@0 39 //
aoqi@0 40 // Constructor for loaded object array klasses.
aoqi@0 41 ciObjArrayKlass::ciObjArrayKlass(KlassHandle h_k) : ciArrayKlass(h_k) {
aoqi@0 42 assert(get_Klass()->oop_is_objArray(), "wrong type");
aoqi@0 43 Klass* element_Klass = get_ObjArrayKlass()->bottom_klass();
aoqi@0 44 _base_element_klass = CURRENT_ENV->get_klass(element_Klass);
aoqi@0 45 assert(_base_element_klass->is_instance_klass() ||
aoqi@0 46 _base_element_klass->is_type_array_klass(), "bad base klass");
aoqi@0 47 if (dimension() == 1) {
aoqi@0 48 _element_klass = _base_element_klass;
aoqi@0 49 } else {
aoqi@0 50 _element_klass = NULL;
aoqi@0 51 }
aoqi@0 52 if (!ciObjectFactory::is_initialized()) {
aoqi@0 53 assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared");
aoqi@0 54 }
aoqi@0 55 }
aoqi@0 56
aoqi@0 57 // ------------------------------------------------------------------
aoqi@0 58 // ciObjArrayKlass::ciObjArrayKlass
aoqi@0 59 //
aoqi@0 60 // Constructor for unloaded object array klasses.
aoqi@0 61 ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name,
aoqi@0 62 ciKlass* base_element_klass,
aoqi@0 63 int dimension)
aoqi@0 64 : ciArrayKlass(array_name,
aoqi@0 65 dimension, T_OBJECT) {
aoqi@0 66 _base_element_klass = base_element_klass;
aoqi@0 67 assert(_base_element_klass->is_instance_klass() ||
aoqi@0 68 _base_element_klass->is_type_array_klass(), "bad base klass");
aoqi@0 69 if (dimension == 1) {
aoqi@0 70 _element_klass = base_element_klass;
aoqi@0 71 } else {
aoqi@0 72 _element_klass = NULL;
aoqi@0 73 }
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 // ------------------------------------------------------------------
aoqi@0 77 // ciObjArrayKlass::element_klass
aoqi@0 78 //
aoqi@0 79 // What is the one-level element type of this array?
aoqi@0 80 ciKlass* ciObjArrayKlass::element_klass() {
aoqi@0 81 if (_element_klass == NULL) {
aoqi@0 82 assert(dimension() > 1, "_element_klass should not be NULL");
aoqi@0 83 // Produce the element klass.
aoqi@0 84 if (is_loaded()) {
aoqi@0 85 VM_ENTRY_MARK;
aoqi@0 86 Klass* element_Klass = get_ObjArrayKlass()->element_klass();
aoqi@0 87 _element_klass = CURRENT_THREAD_ENV->get_klass(element_Klass);
aoqi@0 88 } else {
aoqi@0 89 VM_ENTRY_MARK;
aoqi@0 90 // We are an unloaded array klass. Attempt to fetch our
aoqi@0 91 // element klass by name.
aoqi@0 92 _element_klass = CURRENT_THREAD_ENV->get_klass_by_name_impl(
aoqi@0 93 this,
aoqi@0 94 constantPoolHandle(),
aoqi@0 95 construct_array_name(base_element_klass()->name(),
aoqi@0 96 dimension() - 1),
aoqi@0 97 false);
aoqi@0 98 }
aoqi@0 99 }
aoqi@0 100 return _element_klass;
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 // ------------------------------------------------------------------
aoqi@0 104 // ciObjArrayKlass::construct_array_name
aoqi@0 105 //
aoqi@0 106 // Build an array name from an element name and a dimension.
aoqi@0 107 ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name,
aoqi@0 108 int dimension) {
aoqi@0 109 EXCEPTION_CONTEXT;
aoqi@0 110 int element_len = element_name->utf8_length();
aoqi@0 111
aoqi@0 112 Symbol* base_name_sym = element_name->get_symbol();
aoqi@0 113 char* name;
aoqi@0 114
aoqi@0 115 if (base_name_sym->byte_at(0) == '[' ||
aoqi@0 116 (base_name_sym->byte_at(0) == 'L' && // watch package name 'Lxx'
aoqi@0 117 base_name_sym->byte_at(element_len-1) == ';')) {
aoqi@0 118
aoqi@0 119 int new_len = element_len + dimension + 1; // for the ['s and '\0'
aoqi@0 120 name = CURRENT_THREAD_ENV->name_buffer(new_len);
aoqi@0 121
aoqi@0 122 int pos = 0;
aoqi@0 123 for ( ; pos < dimension; pos++) {
aoqi@0 124 name[pos] = '[';
aoqi@0 125 }
aoqi@0 126 strncpy(name+pos, (char*)element_name->base(), element_len);
aoqi@0 127 name[new_len-1] = '\0';
aoqi@0 128 } else {
aoqi@0 129 int new_len = 3 // for L, ;, and '\0'
aoqi@0 130 + dimension // for ['s
aoqi@0 131 + element_len;
aoqi@0 132
aoqi@0 133 name = CURRENT_THREAD_ENV->name_buffer(new_len);
aoqi@0 134 int pos = 0;
aoqi@0 135 for ( ; pos < dimension; pos++) {
aoqi@0 136 name[pos] = '[';
aoqi@0 137 }
aoqi@0 138 name[pos++] = 'L';
aoqi@0 139 strncpy(name+pos, (char*)element_name->base(), element_len);
aoqi@0 140 name[new_len-2] = ';';
aoqi@0 141 name[new_len-1] = '\0';
aoqi@0 142 }
aoqi@0 143 return ciSymbol::make(name);
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 // ------------------------------------------------------------------
aoqi@0 147 // ciObjArrayKlass::make_impl
aoqi@0 148 //
aoqi@0 149 // Implementation of make.
aoqi@0 150 ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass) {
aoqi@0 151
aoqi@0 152 if (element_klass->is_loaded()) {
aoqi@0 153 EXCEPTION_CONTEXT;
aoqi@0 154 // The element klass is loaded
aoqi@0 155 Klass* array = element_klass->get_Klass()->array_klass(THREAD);
aoqi@0 156 if (HAS_PENDING_EXCEPTION) {
aoqi@0 157 CLEAR_PENDING_EXCEPTION;
aoqi@0 158 CURRENT_THREAD_ENV->record_out_of_memory_failure();
aoqi@0 159 return ciEnv::unloaded_ciobjarrayklass();
aoqi@0 160 }
aoqi@0 161 return CURRENT_THREAD_ENV->get_obj_array_klass(array);
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 // The array klass was unable to be made or the element klass was
aoqi@0 165 // not loaded.
aoqi@0 166 ciSymbol* array_name = construct_array_name(element_klass->name(), 1);
aoqi@0 167 if (array_name == ciEnv::unloaded_cisymbol()) {
aoqi@0 168 return ciEnv::unloaded_ciobjarrayklass();
aoqi@0 169 }
aoqi@0 170 return
aoqi@0 171 CURRENT_ENV->get_unloaded_klass(element_klass, array_name)
aoqi@0 172 ->as_obj_array_klass();
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 // ------------------------------------------------------------------
aoqi@0 176 // ciObjArrayKlass::make
aoqi@0 177 //
aoqi@0 178 // Make an array klass corresponding to the specified primitive type.
aoqi@0 179 ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass) {
aoqi@0 180 GUARDED_VM_ENTRY(return make_impl(element_klass);)
aoqi@0 181 }
aoqi@0 182
aoqi@0 183 ciKlass* ciObjArrayKlass::exact_klass() {
aoqi@0 184 ciType* base = base_element_type();
aoqi@0 185 if (base->is_instance_klass()) {
aoqi@0 186 ciInstanceKlass* ik = base->as_instance_klass();
aoqi@0 187 if (ik->exact_klass() != NULL) {
aoqi@0 188 return this;
aoqi@0 189 }
aoqi@0 190 } else if (base->is_primitive_type()) {
aoqi@0 191 return this;
aoqi@0 192 }
aoqi@0 193 return NULL;
aoqi@0 194 }

mercurial