Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/oops/arrayKlass.cpp
32285 views
/*1* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/javaClasses.hpp"26#include "classfile/systemDictionary.hpp"27#include "classfile/vmSymbols.hpp"28#include "gc_interface/collectedHeap.inline.hpp"29#include "jvmtifiles/jvmti.h"30#include "memory/gcLocker.hpp"31#include "memory/universe.inline.hpp"32#include "oops/arrayKlass.hpp"33#include "oops/arrayOop.hpp"34#include "oops/instanceKlass.hpp"35#include "oops/objArrayOop.hpp"36#include "oops/oop.inline.hpp"3738int ArrayKlass::static_size(int header_size) {39// size of an array klass object40assert(header_size <= InstanceKlass::header_size(), "bad header size");41// If this assert fails, see comments in base_create_array_klass.42header_size = InstanceKlass::header_size();43int vtable_len = Universe::base_vtable_size();44#ifdef _LP6445int size = header_size + align_object_offset(vtable_len);46#else47int size = header_size + vtable_len;48#endif49return align_object_size(size);50}515253Klass* ArrayKlass::java_super() const {54if (super() == NULL) return NULL; // bootstrap case55// Array klasses have primary supertypes which are not reported to Java.56// Example super chain: String[][] -> Object[][] -> Object[] -> Object57return SystemDictionary::Object_klass();58}596061oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {62ShouldNotReachHere();63return NULL;64}6566// find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined67Klass* ArrayKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {68// There are no fields in an array klass but look to the super class (Object)69assert(super(), "super klass must be present");70return super()->find_field(name, sig, fd);71}7273Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const {74// There are no methods in an array klass but the super class (Object) has some75assert(super(), "super klass must be present");76// Always ignore overpass methods in superclasses, although technically the77// super klass of an array, (j.l.Object) should not have78// any overpass methods present.79return super()->uncached_lookup_method(name, signature, Klass::skip_overpass);80}8182ArrayKlass::ArrayKlass(Symbol* name) {83set_name(name);8485set_super(Universe::is_bootstrapping() ? (Klass*)NULL : SystemDictionary::Object_klass());86set_layout_helper(Klass::_lh_neutral_value);87set_dimension(1);88set_higher_dimension(NULL);89set_lower_dimension(NULL);90set_component_mirror(NULL);91// Arrays don't add any new methods, so their vtable is the same size as92// the vtable of klass Object.93int vtable_size = Universe::base_vtable_size();94set_vtable_length(vtable_size);95set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)96JFR_ONLY(INIT_ID(this);)97}9899100// Initialization of vtables and mirror object is done separatly from base_create_array_klass,101// since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.102void ArrayKlass::complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, TRAPS) {103ResourceMark rm(THREAD);104k->initialize_supers(super_klass(), CHECK);105k->vtable()->initialize_vtable(false, CHECK);106java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(NULL), CHECK);107}108109GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) {110// interfaces = { cloneable_klass, serializable_klass };111assert(num_extra_slots == 0, "sanity of primitive array type");112// Must share this for correct bootstrapping!113set_secondary_supers(Universe::the_array_interfaces_array());114return NULL;115}116117bool ArrayKlass::compute_is_subtype_of(Klass* k) {118// An array is a subtype of Serializable, Clonable, and Object119return k == SystemDictionary::Object_klass()120|| k == SystemDictionary::Cloneable_klass()121|| k == SystemDictionary::Serializable_klass();122}123124125inline intptr_t* ArrayKlass::start_of_vtable() const {126// all vtables start at the same place, that's why we use InstanceKlass::header_size here127return ((intptr_t*)this) + InstanceKlass::header_size();128}129130131klassVtable* ArrayKlass::vtable() const {132KlassHandle kh(Thread::current(), this);133return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());134}135136137objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {138if (length < 0) {139THROW_0(vmSymbols::java_lang_NegativeArraySizeException());140}141if (length > arrayOopDesc::max_array_length(T_ARRAY)) {142report_java_out_of_memory("Requested array size exceeds VM limit");143JvmtiExport::post_array_size_exhausted();144THROW_OOP_0(Universe::out_of_memory_error_array_size());145}146int size = objArrayOopDesc::object_size(length);147Klass* k = array_klass(n+dimension(), CHECK_0);148ArrayKlass* ak = ArrayKlass::cast(k);149objArrayOop o =150(objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);151// initialization to NULL not necessary, area already cleared152return o;153}154155void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {156Klass* k = this;157// Iterate over this array klass and all higher dimensions158while (k != NULL) {159f(k, CHECK);160k = ArrayKlass::cast(k)->higher_dimension();161}162}163164void ArrayKlass::array_klasses_do(void f(Klass* k)) {165Klass* k = this;166// Iterate over this array klass and all higher dimensions167while (k != NULL) {168f(k);169k = ArrayKlass::cast(k)->higher_dimension();170}171}172173// GC support174175void ArrayKlass::oops_do(OopClosure* cl) {176Klass::oops_do(cl);177178cl->do_oop(adr_component_mirror());179}180181// JVM support182183jint ArrayKlass::compute_modifier_flags(TRAPS) const {184return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;185}186187// JVMTI support188189jint ArrayKlass::jvmti_class_status() const {190return JVMTI_CLASS_STATUS_ARRAY;191}192193void ArrayKlass::remove_unshareable_info() {194Klass::remove_unshareable_info();195// Clear the java mirror196set_component_mirror(NULL);197}198199void ArrayKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {200assert(loader_data == ClassLoaderData::the_null_class_loader_data(), "array classes belong to null loader");201Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);202// Klass recreates the component mirror also203}204205// Printing206207void ArrayKlass::print_on(outputStream* st) const {208assert(is_klass(), "must be klass");209Klass::print_on(st);210}211212void ArrayKlass::print_value_on(outputStream* st) const {213assert(is_klass(), "must be klass");214for(int index = 0; index < dimension(); index++) {215st->print("[]");216}217}218219void ArrayKlass::oop_print_on(oop obj, outputStream* st) {220assert(obj->is_array(), "must be array");221Klass::oop_print_on(obj, st);222st->print_cr(" - length: %d", arrayOop(obj)->length());223}224225226// Verification227228void ArrayKlass::verify_on(outputStream* st) {229Klass::verify_on(st);230231if (component_mirror() != NULL) {232guarantee(component_mirror()->klass() != NULL, "should have a class");233}234}235236void ArrayKlass::oop_verify_on(oop obj, outputStream* st) {237guarantee(obj->is_array(), "must be array");238arrayOop a = arrayOop(obj);239guarantee(a->length() >= 0, "array with negative length?");240}241242243