src/share/vm/oops/arrayKlass.cpp

Tue, 26 Nov 2013 14:35:38 +0100

author
sjohanss
date
Tue, 26 Nov 2013 14:35:38 +0100
changeset 6148
55a0da3d420b
parent 5369
71180a6e5080
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8027675: Full collections with Serial slower in JDK 8 compared to 7u40
Summary: Reduced the number of calls to follow_class_loader and instead marked and pushed the klass holder directly. Also removed unneeded calls to adjust_klass.
Reviewed-by: coleenp, jmasa, mgerdin, tschatzl

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "classfile/javaClasses.hpp"
    27 #include "classfile/systemDictionary.hpp"
    28 #include "classfile/vmSymbols.hpp"
    29 #include "gc_interface/collectedHeap.inline.hpp"
    30 #include "jvmtifiles/jvmti.h"
    31 #include "memory/gcLocker.hpp"
    32 #include "memory/universe.inline.hpp"
    33 #include "oops/arrayKlass.hpp"
    34 #include "oops/arrayOop.hpp"
    35 #include "oops/instanceKlass.hpp"
    36 #include "oops/objArrayOop.hpp"
    37 #include "oops/oop.inline.hpp"
    39 int ArrayKlass::static_size(int header_size) {
    40   // size of an array klass object
    41   assert(header_size <= InstanceKlass::header_size(), "bad header size");
    42   // If this assert fails, see comments in base_create_array_klass.
    43   header_size = InstanceKlass::header_size();
    44   int vtable_len = Universe::base_vtable_size();
    45 #ifdef _LP64
    46   int size = header_size + align_object_offset(vtable_len);
    47 #else
    48   int size = header_size + vtable_len;
    49 #endif
    50   return align_object_size(size);
    51 }
    54 Klass* ArrayKlass::java_super() const {
    55   if (super() == NULL)  return NULL;  // bootstrap case
    56   // Array klasses have primary supertypes which are not reported to Java.
    57   // Example super chain:  String[][] -> Object[][] -> Object[] -> Object
    58   return SystemDictionary::Object_klass();
    59 }
    62 oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
    63   ShouldNotReachHere();
    64   return NULL;
    65 }
    67 Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
    68   // There are no methods in an array klass but the super class (Object) has some
    69   assert(super(), "super klass must be present");
    70   return super()->uncached_lookup_method(name, signature);
    71 }
    73 ArrayKlass::ArrayKlass(Symbol* name) {
    74   set_name(name);
    76   set_super(Universe::is_bootstrapping() ? (Klass*)NULL : SystemDictionary::Object_klass());
    77   set_layout_helper(Klass::_lh_neutral_value);
    78   set_dimension(1);
    79   set_higher_dimension(NULL);
    80   set_lower_dimension(NULL);
    81   set_component_mirror(NULL);
    82   // Arrays don't add any new methods, so their vtable is the same size as
    83   // the vtable of klass Object.
    84   int vtable_size = Universe::base_vtable_size();
    85   set_vtable_length(vtable_size);
    86   set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
    87 }
    90 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
    91 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
    92 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, TRAPS) {
    93   ResourceMark rm(THREAD);
    94   k->initialize_supers(super_klass(), CHECK);
    95   k->vtable()->initialize_vtable(false, CHECK);
    96   java_lang_Class::create_mirror(k, Handle(NULL), CHECK);
    97 }
    99 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) {
   100   // interfaces = { cloneable_klass, serializable_klass };
   101   assert(num_extra_slots == 0, "sanity of primitive array type");
   102   // Must share this for correct bootstrapping!
   103   set_secondary_supers(Universe::the_array_interfaces_array());
   104   return NULL;
   105 }
   107 bool ArrayKlass::compute_is_subtype_of(Klass* k) {
   108   // An array is a subtype of Serializable, Clonable, and Object
   109   return    k == SystemDictionary::Object_klass()
   110          || k == SystemDictionary::Cloneable_klass()
   111          || k == SystemDictionary::Serializable_klass();
   112 }
   115 inline intptr_t* ArrayKlass::start_of_vtable() const {
   116   // all vtables start at the same place, that's why we use InstanceKlass::header_size here
   117   return ((intptr_t*)this) + InstanceKlass::header_size();
   118 }
   121 klassVtable* ArrayKlass::vtable() const {
   122   KlassHandle kh(Thread::current(), this);
   123   return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
   124 }
   127 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
   128   if (length < 0) {
   129     THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
   130   }
   131   if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
   132     report_java_out_of_memory("Requested array size exceeds VM limit");
   133     JvmtiExport::post_array_size_exhausted();
   134     THROW_OOP_0(Universe::out_of_memory_error_array_size());
   135   }
   136   int size = objArrayOopDesc::object_size(length);
   137   Klass* k = array_klass(n+dimension(), CHECK_0);
   138   ArrayKlass* ak = ArrayKlass::cast(k);
   139   objArrayOop o =
   140     (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
   141   // initialization to NULL not necessary, area already cleared
   142   return o;
   143 }
   145 void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
   146   Klass* k = this;
   147   // Iterate over this array klass and all higher dimensions
   148   while (k != NULL) {
   149     f(k, CHECK);
   150     k = ArrayKlass::cast(k)->higher_dimension();
   151   }
   152 }
   154 void ArrayKlass::array_klasses_do(void f(Klass* k)) {
   155   Klass* k = this;
   156   // Iterate over this array klass and all higher dimensions
   157   while (k != NULL) {
   158     f(k);
   159     k = ArrayKlass::cast(k)->higher_dimension();
   160   }
   161 }
   163 // GC support
   165 void ArrayKlass::oops_do(OopClosure* cl) {
   166   Klass::oops_do(cl);
   168   cl->do_oop(adr_component_mirror());
   169 }
   171 // JVM support
   173 jint ArrayKlass::compute_modifier_flags(TRAPS) const {
   174   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
   175 }
   177 // JVMTI support
   179 jint ArrayKlass::jvmti_class_status() const {
   180   return JVMTI_CLASS_STATUS_ARRAY;
   181 }
   183 void ArrayKlass::remove_unshareable_info() {
   184   Klass::remove_unshareable_info();
   185   // Clear the java mirror
   186   set_component_mirror(NULL);
   187 }
   189 void ArrayKlass::restore_unshareable_info(TRAPS) {
   190   Klass::restore_unshareable_info(CHECK);
   191   // Klass recreates the component mirror also
   192 }
   194 // Printing
   196 void ArrayKlass::print_on(outputStream* st) const {
   197   assert(is_klass(), "must be klass");
   198   Klass::print_on(st);
   199 }
   201 void ArrayKlass::print_value_on(outputStream* st) const {
   202   assert(is_klass(), "must be klass");
   203   for(int index = 0; index < dimension(); index++) {
   204     st->print("[]");
   205   }
   206 }
   208 void ArrayKlass::oop_print_on(oop obj, outputStream* st) {
   209   assert(obj->is_array(), "must be array");
   210   Klass::oop_print_on(obj, st);
   211   st->print_cr(" - length: %d", arrayOop(obj)->length());
   212 }
   215 // Verification
   217 void ArrayKlass::verify_on(outputStream* st, bool check_dictionary) {
   218   Klass::verify_on(st, check_dictionary);
   220   if (component_mirror() != NULL) {
   221     guarantee(component_mirror()->klass() != NULL, "should have a class");
   222   }
   223 }
   225 void ArrayKlass::oop_verify_on(oop obj, outputStream* st) {
   226   guarantee(obj->is_array(), "must be array");
   227   arrayOop a = arrayOop(obj);
   228   guarantee(a->length() >= 0, "array with negative length?");
   229 }

mercurial