annotate src/hotspot/share/oops/arrayKlass.cpp @ 52033:d6aa9ea2405d

8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation Reviewed-by: never, kvn, sspitsyn
author dnsimon
date Fri, 05 Oct 2018 20:03:14 +0200
parents 9c68699bebe5
children 08db5aa02f7b
rev   line source
duke@1 1 /*
stefank@49359 2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #include "precompiled.hpp"
stefank@7397 26 #include "classfile/javaClasses.hpp"
stefank@7397 27 #include "classfile/systemDictionary.hpp"
stefank@7397 28 #include "classfile/vmSymbols.hpp"
pliden@30764 29 #include "gc/shared/collectedHeap.inline.hpp"
stefank@7397 30 #include "jvmtifiles/jvmti.h"
iklam@46746 31 #include "memory/metaspaceClosure.hpp"
jprovino@37248 32 #include "memory/resourceArea.hpp"
stefank@49359 33 #include "memory/universe.hpp"
stefank@7397 34 #include "oops/arrayKlass.hpp"
stefank@7397 35 #include "oops/arrayOop.hpp"
stefank@7397 36 #include "oops/instanceKlass.hpp"
stefank@7397 37 #include "oops/objArrayOop.hpp"
stefank@7397 38 #include "oops/oop.inline.hpp"
simonis@49393 39 #include "runtime/handles.inline.hpp"
duke@1 40
coleenp@13952 41 int ArrayKlass::static_size(int header_size) {
duke@1 42 // size of an array klass object
coleenp@13728 43 assert(header_size <= InstanceKlass::header_size(), "bad header size");
duke@1 44 // If this assert fails, see comments in base_create_array_klass.
coleenp@13728 45 header_size = InstanceKlass::header_size();
coleenp@13728 46 int vtable_len = Universe::base_vtable_size();
coleenp@13728 47 int size = header_size + vtable_len;
coleenp@35898 48 return align_metadata_size(size);
duke@1 49 }
duke@1 50
duke@1 51
iklam@51329 52 InstanceKlass* ArrayKlass::java_super() const {
duke@1 53 if (super() == NULL) return NULL; // bootstrap case
duke@1 54 // Array klasses have primary supertypes which are not reported to Java.
duke@1 55 // Example super chain: String[][] -> Object[][] -> Object[] -> Object
never@4571 56 return SystemDictionary::Object_klass();
duke@1 57 }
duke@1 58
duke@1 59
coleenp@13952 60 oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
duke@1 61 ShouldNotReachHere();
duke@1 62 return NULL;
duke@1 63 }
duke@1 64
lfoltan@27020 65 // find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
lfoltan@27020 66 Klass* ArrayKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
lfoltan@27020 67 // There are no fields in an array klass but look to the super class (Object)
lfoltan@27020 68 assert(super(), "super klass must be present");
lfoltan@27020 69 return super()->find_field(name, sig, fd);
lfoltan@27020 70 }
lfoltan@27020 71
mgronlun@34666 72 Method* ArrayKlass::uncached_lookup_method(const Symbol* name,
mgronlun@34666 73 const Symbol* signature,
dholmes@50735 74 OverpassLookupMode overpass_mode,
dholmes@50735 75 PrivateLookupMode private_mode) const {
duke@1 76 // There are no methods in an array klass but the super class (Object) has some
duke@1 77 assert(super(), "super klass must be present");
lfoltan@28731 78 // Always ignore overpass methods in superclasses, although technically the
lfoltan@28731 79 // super klass of an array, (j.l.Object) should not have
lfoltan@28731 80 // any overpass methods present.
dholmes@50735 81 return super()->uncached_lookup_method(name, signature, Klass::skip_overpass, private_mode);
duke@1 82 }
duke@1 83
stefank@50752 84 ArrayKlass::ArrayKlass(Symbol* name, KlassID id) :
stefank@50752 85 Klass(id),
mgronlun@34666 86 _dimension(1),
mgronlun@34666 87 _higher_dimension(NULL),
mgerdin@35899 88 _lower_dimension(NULL) {
mgerdin@35899 89 // Arrays don't add any new methods, so their vtable is the same size as
mgerdin@35899 90 // the vtable of klass Object.
mgerdin@35899 91 set_vtable_length(Universe::base_vtable_size());
mgronlun@34666 92 set_name(name);
iklam@51329 93 set_super(Universe::is_bootstrapping() ? NULL : SystemDictionary::Object_klass());
mgronlun@34666 94 set_layout_helper(Klass::_lh_neutral_value);
mgronlun@34666 95 set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
egahlin@50113 96 JFR_ONLY(INIT_ID(this);)
duke@1 97 }
duke@1 98
duke@1 99
duke@1 100 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
coleenp@13952 101 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
coleenp@46329 102 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
ccheung@49948 103 k->initialize_supers(super_klass, NULL, CHECK);
iklam@46408 104 k->vtable().initialize_vtable(false, CHECK);
alanb@36508 105
alanb@36508 106 // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
alanb@36508 107 // These classes will be put on a fixup list and their module fields will be patched once
alanb@36508 108 // java.base is defined.
alanb@36508 109 assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
rprotacio@42636 110 "module entry not available post " JAVA_BASE_NAME " definition");
hseigel@46773 111 oop module = (module_entry != NULL) ? module_entry->module() : (oop)NULL;
coleenp@46271 112 java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), CHECK);
duke@1 113 }
duke@1 114
ccheung@49948 115 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
iklam@51329 116 Array<InstanceKlass*>* transitive_interfaces) {
duke@1 117 // interfaces = { cloneable_klass, serializable_klass };
duke@1 118 assert(num_extra_slots == 0, "sanity of primitive array type");
ccheung@49948 119 assert(transitive_interfaces == NULL, "sanity");
duke@1 120 // Must share this for correct bootstrapping!
coleenp@13728 121 set_secondary_supers(Universe::the_array_interfaces_array());
coleenp@13728 122 return NULL;
duke@1 123 }
duke@1 124
coleenp@13952 125 bool ArrayKlass::compute_is_subtype_of(Klass* k) {
duke@1 126 // An array is a subtype of Serializable, Clonable, and Object
never@4571 127 return k == SystemDictionary::Object_klass()
never@4571 128 || k == SystemDictionary::Cloneable_klass()
never@4571 129 || k == SystemDictionary::Serializable_klass();
duke@1 130 }
duke@1 131
coleenp@13952 132 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
dnsimon@52033 133 check_array_allocation_length(length, arrayOopDesc::max_array_length(T_ARRAY), CHECK_0);
duke@1 134 int size = objArrayOopDesc::object_size(length);
coleenp@13728 135 Klass* k = array_klass(n+dimension(), CHECK_0);
coleenp@13952 136 ArrayKlass* ak = ArrayKlass::cast(k);
eosterlund@50882 137 objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
eosterlund@50882 138 /* do_zero */ true, CHECK_0);
duke@1 139 // initialization to NULL not necessary, area already cleared
duke@1 140 return o;
duke@1 141 }
duke@1 142
coleenp@13952 143 void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
coleenp@13728 144 Klass* k = this;
coleenp@13728 145 // Iterate over this array klass and all higher dimensions
coleenp@13728 146 while (k != NULL) {
coleenp@13728 147 f(k, CHECK);
coleenp@13952 148 k = ArrayKlass::cast(k)->higher_dimension();
coleenp@13728 149 }
coleenp@13728 150 }
duke@1 151
coleenp@13952 152 void ArrayKlass::array_klasses_do(void f(Klass* k)) {
coleenp@13728 153 Klass* k = this;
duke@1 154 // Iterate over this array klass and all higher dimensions
duke@1 155 while (k != NULL) {
duke@1 156 f(k);
coleenp@13952 157 k = ArrayKlass::cast(k)->higher_dimension();
duke@1 158 }
duke@1 159 }
duke@1 160
duke@1 161 // JVM support
duke@1 162
coleenp@13952 163 jint ArrayKlass::compute_modifier_flags(TRAPS) const {
duke@1 164 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@1 165 }
duke@1 166
duke@1 167 // JVMTI support
duke@1 168
coleenp@13952 169 jint ArrayKlass::jvmti_class_status() const {
duke@1 170 return JVMTI_CLASS_STATUS_ARRAY;
duke@1 171 }
duke@1 172
iklam@46746 173 void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
iklam@46746 174 Klass::metaspace_pointers_do(it);
iklam@46746 175
iklam@46746 176 ResourceMark rm;
iklam@46746 177 log_trace(cds)("Iter(ArrayKlass): %p (%s)", this, external_name());
iklam@46746 178
iklam@46746 179 // need to cast away volatile
iklam@46746 180 it->push((Klass**)&_higher_dimension);
iklam@46746 181 it->push((Klass**)&_lower_dimension);
iklam@46746 182 }
iklam@46746 183
coleenp@13952 184 void ArrayKlass::remove_unshareable_info() {
coleenp@13728 185 Klass::remove_unshareable_info();
ccheung@47103 186 if (_higher_dimension != NULL) {
ccheung@47103 187 ArrayKlass *ak = ArrayKlass::cast(higher_dimension());
ccheung@47103 188 ak->remove_unshareable_info();
ccheung@47103 189 }
ccheung@47103 190 }
ccheung@47103 191
ccheung@47103 192 void ArrayKlass::remove_java_mirror() {
ccheung@47103 193 Klass::remove_java_mirror();
ccheung@47103 194 if (_higher_dimension != NULL) {
ccheung@47103 195 ArrayKlass *ak = ArrayKlass::cast(higher_dimension());
ccheung@47103 196 ak->remove_java_mirror();
ccheung@47103 197 }
coleenp@13728 198 }
coleenp@13728 199
iklam@26135 200 void ArrayKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
iklam@26135 201 assert(loader_data == ClassLoaderData::the_null_class_loader_data(), "array classes belong to null loader");
iklam@26135 202 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
coleenp@13728 203 // Klass recreates the component mirror also
ccheung@47103 204
ccheung@47103 205 if (_higher_dimension != NULL) {
ccheung@47103 206 ArrayKlass *ak = ArrayKlass::cast(higher_dimension());
ccheung@47103 207 ak->restore_unshareable_info(loader_data, protection_domain, CHECK);
ccheung@47103 208 }
coleenp@13728 209 }
coleenp@13728 210
duke@1 211 // Printing
duke@1 212
coleenp@13952 213 void ArrayKlass::print_on(outputStream* st) const {
coleenp@13728 214 assert(is_klass(), "must be klass");
coleenp@13728 215 Klass::print_on(st);
coleenp@13728 216 }
coleenp@13728 217
coleenp@13952 218 void ArrayKlass::print_value_on(outputStream* st) const {
coleenp@13728 219 assert(is_klass(), "must be klass");
coleenp@13728 220 for(int index = 0; index < dimension(); index++) {
coleenp@13728 221 st->print("[]");
coleenp@13728 222 }
coleenp@13728 223 }
coleenp@13728 224
coleenp@13952 225 void ArrayKlass::oop_print_on(oop obj, outputStream* st) {
duke@1 226 assert(obj->is_array(), "must be array");
duke@1 227 Klass::oop_print_on(obj, st);
duke@1 228 st->print_cr(" - length: %d", arrayOop(obj)->length());
duke@1 229 }
duke@1 230
coleenp@13728 231
duke@1 232 // Verification
duke@1 233
coleenp@22794 234 void ArrayKlass::verify_on(outputStream* st) {
coleenp@22794 235 Klass::verify_on(st);
coleenp@13728 236 }
coleenp@13728 237
coleenp@13952 238 void ArrayKlass::oop_verify_on(oop obj, outputStream* st) {
duke@1 239 guarantee(obj->is_array(), "must be array");
duke@1 240 arrayOop a = arrayOop(obj);
duke@1 241 guarantee(a->length() >= 0, "array with negative length?");
duke@1 242 }