src/share/vm/oops/arrayKlass.cpp

Tue, 24 Jun 2008 16:00:14 -0700

author
never
date
Tue, 24 Jun 2008 16:00:14 -0700
changeset 657
2a1a77d3458f
parent 435
a61af66fc99e
child 1311
1413494da700
permissions
-rw-r--r--

6718676: putback for 6604014 is incomplete
Reviewed-by: kvn, jrose

     1 /*
     2  * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 # include "incls/_precompiled.incl"
    26 # include "incls/_arrayKlass.cpp.incl"
    28 int arrayKlass::object_size(int header_size) const {
    29   // size of an array klass object
    30   assert(header_size <= instanceKlass::header_size(), "bad header size");
    31   // If this assert fails, see comments in base_create_array_klass.
    32   header_size = instanceKlass::header_size();
    33 #ifdef _LP64
    34   int size = header_size + align_object_offset(vtable_length());
    35 #else
    36   int size = header_size + vtable_length();
    37 #endif
    38   return align_object_size(size);
    39 }
    42 klassOop arrayKlass::java_super() const {
    43   if (super() == NULL)  return NULL;  // bootstrap case
    44   // Array klasses have primary supertypes which are not reported to Java.
    45   // Example super chain:  String[][] -> Object[][] -> Object[] -> Object
    46   return SystemDictionary::object_klass();
    47 }
    50 oop arrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
    51   ShouldNotReachHere();
    52   return NULL;
    53 }
    55 methodOop arrayKlass::uncached_lookup_method(symbolOop name, symbolOop signature) const {
    56   // There are no methods in an array klass but the super class (Object) has some
    57   assert(super(), "super klass must be present");
    58   return Klass::cast(super())->uncached_lookup_method(name, signature);
    59 }
    62 arrayKlassHandle arrayKlass::base_create_array_klass(
    63 const Klass_vtbl& cplusplus_vtbl, int header_size, KlassHandle klass, TRAPS) {
    64   // Allocation
    65   // Note: because the Java vtable must start at the same offset in all klasses,
    66   // we must insert filler fields into arrayKlass to make it the same size as instanceKlass.
    67   // If this assert fails, add filler to instanceKlass to make it bigger.
    68   assert(header_size <= instanceKlass::header_size(),
    69          "array klasses must be same size as instanceKlass");
    70   header_size = instanceKlass::header_size();
    71   // Arrays don't add any new methods, so their vtable is the same size as
    72   // the vtable of klass Object.
    73   int vtable_size = Universe::base_vtable_size();
    74   arrayKlassHandle k;
    75   KlassHandle base_klass = Klass::base_create_klass(klass,
    76                                                  header_size + vtable_size,
    77                                                  cplusplus_vtbl, CHECK_(k));
    79   // No safepoint should be possible until the handle's
    80   // target below becomes parsable
    81   No_Safepoint_Verifier no_safepoint;
    82   k = arrayKlassHandle(THREAD, base_klass());
    84   assert(!k()->is_parsable(), "not expecting parsability yet.");
    85   k->set_super(Universe::is_bootstrapping() ? (klassOop)NULL : SystemDictionary::object_klass());
    86   k->set_layout_helper(Klass::_lh_neutral_value);
    87   k->set_dimension(1);
    88   k->set_higher_dimension(NULL);
    89   k->set_lower_dimension(NULL);
    90   k->set_component_mirror(NULL);
    91   k->set_vtable_length(vtable_size);
    92   k->set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
    94   assert(k()->is_parsable(), "should be parsable here.");
    95   // Make sure size calculation is right
    96   assert(k()->size() == align_object_size(header_size + vtable_size), "wrong size for object");
    98   return k;
    99 }
   102 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
   103 // since a GC can happen. At this point all instance variables of the arrayKlass must be setup.
   104 void arrayKlass::complete_create_array_klass(arrayKlassHandle k, KlassHandle super_klass, TRAPS) {
   105   ResourceMark rm(THREAD);
   106   k->initialize_supers(super_klass(), CHECK);
   107   k->vtable()->initialize_vtable(false, CHECK);
   108   java_lang_Class::create_mirror(k, CHECK);
   109 }
   111 objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
   112   // interfaces = { cloneable_klass, serializable_klass };
   113   assert(num_extra_slots == 0, "sanity of primitive array type");
   114   // Must share this for correct bootstrapping!
   115   return Universe::the_array_interfaces_array();
   116 }
   118 bool arrayKlass::compute_is_subtype_of(klassOop k) {
   119   // An array is a subtype of Serializable, Clonable, and Object
   120   return    k == SystemDictionary::object_klass()
   121          || k == SystemDictionary::cloneable_klass()
   122          || k == SystemDictionary::serializable_klass();
   123 }
   126 inline intptr_t* arrayKlass::start_of_vtable() const {
   127   // all vtables start at the same place, that's why we use instanceKlass::header_size here
   128   return ((intptr_t*)as_klassOop()) + instanceKlass::header_size();
   129 }
   132 klassVtable* arrayKlass::vtable() const {
   133   KlassHandle kh(Thread::current(), as_klassOop());
   134   return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
   135 }
   138 objArrayOop arrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
   139   if (length < 0) {
   140     THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
   141   }
   142   if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
   143     THROW_OOP_0(Universe::out_of_memory_error_array_size());
   144   }
   145   int size = objArrayOopDesc::object_size(length);
   146   klassOop k = array_klass(n+dimension(), CHECK_0);
   147   arrayKlassHandle ak (THREAD, k);
   148   objArrayOop o =
   149     (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
   150   // initialization to NULL not necessary, area already cleared
   151   return o;
   152 }
   155 void arrayKlass::array_klasses_do(void f(klassOop k)) {
   156   klassOop k = as_klassOop();
   157   // Iterate over this array klass and all higher dimensions
   158   while (k != NULL) {
   159     f(k);
   160     k = arrayKlass::cast(k)->higher_dimension();
   161   }
   162 }
   165 void arrayKlass::with_array_klasses_do(void f(klassOop k)) {
   166   array_klasses_do(f);
   167 }
   169 // JVM support
   171 jint arrayKlass::compute_modifier_flags(TRAPS) const {
   172   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
   173 }
   175 // JVMTI support
   177 jint arrayKlass::jvmti_class_status() const {
   178   return JVMTI_CLASS_STATUS_ARRAY;
   179 }
   181 #ifndef PRODUCT
   183 // Printing
   185 void arrayKlass::oop_print_on(oop obj, outputStream* st) {
   186   assert(obj->is_array(), "must be array");
   187   Klass::oop_print_on(obj, st);
   188   st->print_cr(" - length: %d", arrayOop(obj)->length());
   189 }
   191 #endif
   193 // Verification
   195 void arrayKlass::oop_verify_on(oop obj, outputStream* st) {
   196   guarantee(obj->is_array(), "must be array");
   197   arrayOop a = arrayOop(obj);
   198   guarantee(a->length() >= 0, "array with negative length?");
   199 }

mercurial