hotspot/src/share/vm/oops/arrayKlass.cpp
author bobv
Tue, 03 Aug 2010 08:13:38 -0400
changeset 6176 4d9030fe341f
parent 5547 f4b087cbb361
child 7397 5b173b4ca846
permissions -rw-r--r--
6953477: Increase portability and flexibility of building Hotspot Summary: A collection of portability improvements including shared code support for PPC, ARM platforms, software floating point, cross compilation support and improvements in error crash detail. Reviewed-by: phh, never, coleenp, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
     2
 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_arrayKlass.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
int arrayKlass::object_size(int header_size) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  // size of an array klass object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  assert(header_size <= instanceKlass::header_size(), "bad header size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  // If this assert fails, see comments in base_create_array_klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  header_size = instanceKlass::header_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  int size = header_size + align_object_offset(vtable_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  int size = header_size + vtable_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  return align_object_size(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
klassOop arrayKlass::java_super() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  if (super() == NULL)  return NULL;  // bootstrap case
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // Array klasses have primary supertypes which are not reported to Java.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Example super chain:  String[][] -> Object[][] -> Object[] -> Object
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3795
diff changeset
    46
  return SystemDictionary::Object_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
oop arrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
methodOop arrayKlass::uncached_lookup_method(symbolOop name, symbolOop signature) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // There are no methods in an array klass but the super class (Object) has some
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  assert(super(), "super klass must be present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  return Klass::cast(super())->uncached_lookup_method(name, signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
arrayKlassHandle arrayKlass::base_create_array_klass(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
const Klass_vtbl& cplusplus_vtbl, int header_size, KlassHandle klass, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Note: because the Java vtable must start at the same offset in all klasses,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // we must insert filler fields into arrayKlass to make it the same size as instanceKlass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // If this assert fails, add filler to instanceKlass to make it bigger.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  assert(header_size <= instanceKlass::header_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
         "array klasses must be same size as instanceKlass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  header_size = instanceKlass::header_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Arrays don't add any new methods, so their vtable is the same size as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // the vtable of klass Object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  int vtable_size = Universe::base_vtable_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  arrayKlassHandle k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  KlassHandle base_klass = Klass::base_create_klass(klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                                                 header_size + vtable_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                                                 cplusplus_vtbl, CHECK_(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // No safepoint should be possible until the handle's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // target below becomes parsable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  No_Safepoint_Verifier no_safepoint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  k = arrayKlassHandle(THREAD, base_klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  assert(!k()->is_parsable(), "not expecting parsability yet.");
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3795
diff changeset
    85
  k->set_super(Universe::is_bootstrapping() ? (klassOop)NULL : SystemDictionary::Object_klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  k->set_layout_helper(Klass::_lh_neutral_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  k->set_dimension(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  k->set_higher_dimension(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  k->set_lower_dimension(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  k->set_component_mirror(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  k->set_vtable_length(vtable_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  k->set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  assert(k()->is_parsable(), "should be parsable here.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Make sure size calculation is right
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(k()->size() == align_object_size(header_size + vtable_size), "wrong size for object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// Initialization of vtables and mirror object is done separatly from base_create_array_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// since a GC can happen. At this point all instance variables of the arrayKlass must be setup.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
void arrayKlass::complete_create_array_klass(arrayKlassHandle k, KlassHandle super_klass, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  k->initialize_supers(super_klass(), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  k->vtable()->initialize_vtable(false, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  java_lang_Class::create_mirror(k, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // interfaces = { cloneable_klass, serializable_klass };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert(num_extra_slots == 0, "sanity of primitive array type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Must share this for correct bootstrapping!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return Universe::the_array_interfaces_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
bool arrayKlass::compute_is_subtype_of(klassOop k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // An array is a subtype of Serializable, Clonable, and Object
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3795
diff changeset
   120
  return    k == SystemDictionary::Object_klass()
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3795
diff changeset
   121
         || k == SystemDictionary::Cloneable_klass()
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3795
diff changeset
   122
         || k == SystemDictionary::Serializable_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
inline intptr_t* arrayKlass::start_of_vtable() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // all vtables start at the same place, that's why we use instanceKlass::header_size here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  return ((intptr_t*)as_klassOop()) + instanceKlass::header_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
klassVtable* arrayKlass::vtable() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  KlassHandle kh(Thread::current(), as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
objArrayOop arrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (length < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
3576
4ceec8fb3e18 6850957: Honor -XX:OnOutOfMemoryError when array size exceeds VM limit
martin
parents: 1
diff changeset
   143
    report_java_out_of_memory("Requested array size exceeds VM limit");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    THROW_OOP_0(Universe::out_of_memory_error_array_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  int size = objArrayOopDesc::object_size(length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  klassOop k = array_klass(n+dimension(), CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  arrayKlassHandle ak (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  objArrayOop o =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // initialization to NULL not necessary, area already cleared
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  return o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
void arrayKlass::array_klasses_do(void f(klassOop k)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  klassOop k = as_klassOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Iterate over this array klass and all higher dimensions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  while (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    f(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    k = arrayKlass::cast(k)->higher_dimension();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
void arrayKlass::with_array_klasses_do(void f(klassOop k)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  array_klasses_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// JVM support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
jint arrayKlass::compute_modifier_flags(TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// JVMTI support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
jint arrayKlass::jvmti_class_status() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  return JVMTI_CLASS_STATUS_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
// Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
void arrayKlass::oop_print_on(oop obj, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  assert(obj->is_array(), "must be array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  Klass::oop_print_on(obj, st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  st->print_cr(" - length: %d", arrayOop(obj)->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// Verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
void arrayKlass::oop_verify_on(oop obj, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  guarantee(obj->is_array(), "must be array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  arrayOop a = arrayOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  guarantee(a->length() >= 0, "array with negative length?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
}