src/share/vm/oops/arrayKlass.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/oops/arrayKlass.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,236 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "classfile/javaClasses.hpp"
    1.30 +#include "classfile/systemDictionary.hpp"
    1.31 +#include "classfile/vmSymbols.hpp"
    1.32 +#include "gc_interface/collectedHeap.inline.hpp"
    1.33 +#include "jvmtifiles/jvmti.h"
    1.34 +#include "memory/gcLocker.hpp"
    1.35 +#include "memory/universe.inline.hpp"
    1.36 +#include "oops/arrayKlass.hpp"
    1.37 +#include "oops/arrayOop.hpp"
    1.38 +#include "oops/instanceKlass.hpp"
    1.39 +#include "oops/objArrayOop.hpp"
    1.40 +#include "oops/oop.inline.hpp"
    1.41 +
    1.42 +int ArrayKlass::static_size(int header_size) {
    1.43 +  // size of an array klass object
    1.44 +  assert(header_size <= InstanceKlass::header_size(), "bad header size");
    1.45 +  // If this assert fails, see comments in base_create_array_klass.
    1.46 +  header_size = InstanceKlass::header_size();
    1.47 +  int vtable_len = Universe::base_vtable_size();
    1.48 +#ifdef _LP64
    1.49 +  int size = header_size + align_object_offset(vtable_len);
    1.50 +#else
    1.51 +  int size = header_size + vtable_len;
    1.52 +#endif
    1.53 +  return align_object_size(size);
    1.54 +}
    1.55 +
    1.56 +
    1.57 +Klass* ArrayKlass::java_super() const {
    1.58 +  if (super() == NULL)  return NULL;  // bootstrap case
    1.59 +  // Array klasses have primary supertypes which are not reported to Java.
    1.60 +  // Example super chain:  String[][] -> Object[][] -> Object[] -> Object
    1.61 +  return SystemDictionary::Object_klass();
    1.62 +}
    1.63 +
    1.64 +
    1.65 +oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
    1.66 +  ShouldNotReachHere();
    1.67 +  return NULL;
    1.68 +}
    1.69 +
    1.70 +// find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
    1.71 +Klass* ArrayKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
    1.72 +  // There are no fields in an array klass but look to the super class (Object)
    1.73 +  assert(super(), "super klass must be present");
    1.74 +  return super()->find_field(name, sig, fd);
    1.75 +}
    1.76 +
    1.77 +Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const {
    1.78 +  // There are no methods in an array klass but the super class (Object) has some
    1.79 +  assert(super(), "super klass must be present");
    1.80 +  return super()->uncached_lookup_method(name, signature, mode);
    1.81 +}
    1.82 +
    1.83 +ArrayKlass::ArrayKlass(Symbol* name) {
    1.84 +  set_name(name);
    1.85 +
    1.86 +  set_super(Universe::is_bootstrapping() ? (Klass*)NULL : SystemDictionary::Object_klass());
    1.87 +  set_layout_helper(Klass::_lh_neutral_value);
    1.88 +  set_dimension(1);
    1.89 +  set_higher_dimension(NULL);
    1.90 +  set_lower_dimension(NULL);
    1.91 +  set_component_mirror(NULL);
    1.92 +  // Arrays don't add any new methods, so their vtable is the same size as
    1.93 +  // the vtable of klass Object.
    1.94 +  int vtable_size = Universe::base_vtable_size();
    1.95 +  set_vtable_length(vtable_size);
    1.96 +  set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
    1.97 +}
    1.98 +
    1.99 +
   1.100 +// Initialization of vtables and mirror object is done separatly from base_create_array_klass,
   1.101 +// since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
   1.102 +void ArrayKlass::complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, TRAPS) {
   1.103 +  ResourceMark rm(THREAD);
   1.104 +  k->initialize_supers(super_klass(), CHECK);
   1.105 +  k->vtable()->initialize_vtable(false, CHECK);
   1.106 +  java_lang_Class::create_mirror(k, Handle(NULL), CHECK);
   1.107 +}
   1.108 +
   1.109 +GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) {
   1.110 +  // interfaces = { cloneable_klass, serializable_klass };
   1.111 +  assert(num_extra_slots == 0, "sanity of primitive array type");
   1.112 +  // Must share this for correct bootstrapping!
   1.113 +  set_secondary_supers(Universe::the_array_interfaces_array());
   1.114 +  return NULL;
   1.115 +}
   1.116 +
   1.117 +bool ArrayKlass::compute_is_subtype_of(Klass* k) {
   1.118 +  // An array is a subtype of Serializable, Clonable, and Object
   1.119 +  return    k == SystemDictionary::Object_klass()
   1.120 +         || k == SystemDictionary::Cloneable_klass()
   1.121 +         || k == SystemDictionary::Serializable_klass();
   1.122 +}
   1.123 +
   1.124 +
   1.125 +inline intptr_t* ArrayKlass::start_of_vtable() const {
   1.126 +  // all vtables start at the same place, that's why we use InstanceKlass::header_size here
   1.127 +  return ((intptr_t*)this) + InstanceKlass::header_size();
   1.128 +}
   1.129 +
   1.130 +
   1.131 +klassVtable* ArrayKlass::vtable() const {
   1.132 +  KlassHandle kh(Thread::current(), this);
   1.133 +  return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
   1.134 +}
   1.135 +
   1.136 +
   1.137 +objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
   1.138 +  if (length < 0) {
   1.139 +    THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
   1.140 +  }
   1.141 +  if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
   1.142 +    report_java_out_of_memory("Requested array size exceeds VM limit");
   1.143 +    JvmtiExport::post_array_size_exhausted();
   1.144 +    THROW_OOP_0(Universe::out_of_memory_error_array_size());
   1.145 +  }
   1.146 +  int size = objArrayOopDesc::object_size(length);
   1.147 +  Klass* k = array_klass(n+dimension(), CHECK_0);
   1.148 +  ArrayKlass* ak = ArrayKlass::cast(k);
   1.149 +  objArrayOop o =
   1.150 +    (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
   1.151 +  // initialization to NULL not necessary, area already cleared
   1.152 +  return o;
   1.153 +}
   1.154 +
   1.155 +void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
   1.156 +  Klass* k = this;
   1.157 +  // Iterate over this array klass and all higher dimensions
   1.158 +  while (k != NULL) {
   1.159 +    f(k, CHECK);
   1.160 +    k = ArrayKlass::cast(k)->higher_dimension();
   1.161 +  }
   1.162 +}
   1.163 +
   1.164 +void ArrayKlass::array_klasses_do(void f(Klass* k)) {
   1.165 +  Klass* k = this;
   1.166 +  // Iterate over this array klass and all higher dimensions
   1.167 +  while (k != NULL) {
   1.168 +    f(k);
   1.169 +    k = ArrayKlass::cast(k)->higher_dimension();
   1.170 +  }
   1.171 +}
   1.172 +
   1.173 +// GC support
   1.174 +
   1.175 +void ArrayKlass::oops_do(OopClosure* cl) {
   1.176 +  Klass::oops_do(cl);
   1.177 +
   1.178 +  cl->do_oop(adr_component_mirror());
   1.179 +}
   1.180 +
   1.181 +// JVM support
   1.182 +
   1.183 +jint ArrayKlass::compute_modifier_flags(TRAPS) const {
   1.184 +  return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
   1.185 +}
   1.186 +
   1.187 +// JVMTI support
   1.188 +
   1.189 +jint ArrayKlass::jvmti_class_status() const {
   1.190 +  return JVMTI_CLASS_STATUS_ARRAY;
   1.191 +}
   1.192 +
   1.193 +void ArrayKlass::remove_unshareable_info() {
   1.194 +  Klass::remove_unshareable_info();
   1.195 +  // Clear the java mirror
   1.196 +  set_component_mirror(NULL);
   1.197 +}
   1.198 +
   1.199 +void ArrayKlass::restore_unshareable_info(TRAPS) {
   1.200 +  Klass::restore_unshareable_info(CHECK);
   1.201 +  // Klass recreates the component mirror also
   1.202 +}
   1.203 +
   1.204 +// Printing
   1.205 +
   1.206 +void ArrayKlass::print_on(outputStream* st) const {
   1.207 +  assert(is_klass(), "must be klass");
   1.208 +  Klass::print_on(st);
   1.209 +}
   1.210 +
   1.211 +void ArrayKlass::print_value_on(outputStream* st) const {
   1.212 +  assert(is_klass(), "must be klass");
   1.213 +  for(int index = 0; index < dimension(); index++) {
   1.214 +    st->print("[]");
   1.215 +  }
   1.216 +}
   1.217 +
   1.218 +void ArrayKlass::oop_print_on(oop obj, outputStream* st) {
   1.219 +  assert(obj->is_array(), "must be array");
   1.220 +  Klass::oop_print_on(obj, st);
   1.221 +  st->print_cr(" - length: %d", arrayOop(obj)->length());
   1.222 +}
   1.223 +
   1.224 +
   1.225 +// Verification
   1.226 +
   1.227 +void ArrayKlass::verify_on(outputStream* st) {
   1.228 +  Klass::verify_on(st);
   1.229 +
   1.230 +  if (component_mirror() != NULL) {
   1.231 +    guarantee(component_mirror()->klass() != NULL, "should have a class");
   1.232 +  }
   1.233 +}
   1.234 +
   1.235 +void ArrayKlass::oop_verify_on(oop obj, outputStream* st) {
   1.236 +  guarantee(obj->is_array(), "must be array");
   1.237 +  arrayOop a = arrayOop(obj);
   1.238 +  guarantee(a->length() >= 0, "array with negative length?");
   1.239 +}

mercurial