hotspot/src/share/vm/oops/typeArrayKlass.cpp
author jiangli
Tue, 26 Jun 2012 19:08:44 -0400
changeset 13282 9872915dd78d
parent 12263 d20640f4f8fe
child 13728 882756847a04
permissions -rw-r--r--
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table. Summary: Change constMethodOop::_exception_table to optionally inlined u2 table. Reviewed-by: bdelsart, coleenp, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12114
9a825a536095 7123170: JCK vm/jvmti/ResourceExhausted/resexh001/resexh00101/ tests fails since 7u4 b02
sspitsyn
parents: 10566
diff changeset
     2
 * Copyright (c) 1997, 2012, 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: 5119
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5119
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: 5119
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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    26
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    27
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    28
#include "gc_interface/collectedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    29
#include "gc_interface/collectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    30
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    31
#include "memory/universe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    32
#include "memory/universe.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    33
#include "oops/instanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    34
#include "oops/klassOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    35
#include "oops/objArrayKlassKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    36
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    37
#include "oops/typeArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    38
#include "oops/typeArrayOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    39
#include "runtime/handles.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
bool typeArrayKlass::compute_is_subtype_of(klassOop k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  if (!k->klass_part()->oop_is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    return arrayKlass::compute_is_subtype_of(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  typeArrayKlass* tak = typeArrayKlass::cast(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (dimension() != tak->dimension()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  return element_type() == tak->element_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1
diff changeset
    52
klassOop typeArrayKlass::create_klass(BasicType type, int scale,
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1
diff changeset
    53
                                      const char* name_str, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  typeArrayKlass o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7890
diff changeset
    56
  Symbol* sym = NULL;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7890
diff changeset
    57
  if (name_str != NULL) {
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 12114
diff changeset
    58
    sym = SymbolTable::new_permanent_symbol(name_str, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  KlassHandle klassklass (THREAD, Universe::typeArrayKlassKlassObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  arrayKlassHandle k = base_create_array_klass(o.vtbl_value(), header_size(), klassklass, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  typeArrayKlass* ak = typeArrayKlass::cast(k());
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7890
diff changeset
    64
  ak->set_name(sym);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  ak->set_layout_helper(array_layout_helper(type));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  assert(scale == (1 << ak->log2_element_size()), "scale must check out");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert(ak->oop_is_javaArray(), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  assert(ak->oop_is_typeArray(), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  ak->set_max_length(arrayOopDesc::max_array_length(type));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  assert(k()->size() > header_size(), "bad size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Call complete_create_array_klass after all instance variables have been initialized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  KlassHandle super (THREAD, k->super());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  complete_create_array_klass(k, super, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
10566
630c177ec580 7081933: Use zeroing elimination optimization for large array
kvn
parents: 9997
diff changeset
    79
typeArrayOop typeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  assert(log2_element_size() >= 0, "bad scale");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (length >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if (length <= max_length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      KlassHandle h_k(THREAD, as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      typeArrayOop t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      CollectedHeap* ch = Universe::heap();
10566
630c177ec580 7081933: Use zeroing elimination optimization for large array
kvn
parents: 9997
diff changeset
    87
      if (do_zero) {
630c177ec580 7081933: Use zeroing elimination optimization for large array
kvn
parents: 9997
diff changeset
    88
        t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL);
630c177ec580 7081933: Use zeroing elimination optimization for large array
kvn
parents: 9997
diff changeset
    89
      } else {
630c177ec580 7081933: Use zeroing elimination optimization for large array
kvn
parents: 9997
diff changeset
    90
        t = (typeArrayOop)CollectedHeap::array_allocate_nozero(h_k, (int)size, length, CHECK_NULL);
630c177ec580 7081933: Use zeroing elimination optimization for large array
kvn
parents: 9997
diff changeset
    91
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      assert(t->is_parsable(), "Don't publish unless parsable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    } else {
3576
4ceec8fb3e18 6850957: Honor -XX:OnOutOfMemoryError when array size exceeds VM limit
martin
parents: 2105
diff changeset
    95
      report_java_out_of_memory("Requested array size exceeds VM limit");
12114
9a825a536095 7123170: JCK vm/jvmti/ResourceExhausted/resexh001/resexh00101/ tests fails since 7u4 b02
sspitsyn
parents: 10566
diff changeset
    96
      JvmtiExport::post_array_size_exhausted();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      THROW_OOP_0(Universe::out_of_memory_error_array_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
typeArrayOop typeArrayKlass::allocate_permanent(int length, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  int size = typeArrayOopDesc::object_size(layout_helper(), length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  KlassHandle h_k(THREAD, as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  typeArrayOop t = (typeArrayOop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    CollectedHeap::permanent_array_allocate(h_k, size, length, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  assert(t->is_parsable(), "Can't publish until parsable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
oop typeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // For typeArrays this is only called for the last dimension
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  assert(rank == 1, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  int length = *last_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  return allocate(length, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void typeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  assert(s->is_typeArray(), "must be type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Check destination
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (!d->is_typeArray() || element_type() != typeArrayKlass::cast(d->klass())->element_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    THROW(vmSymbols::java_lang_ArrayStoreException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Check is all offsets and lengths are non negative
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  if (src_pos < 0 || dst_pos < 0 || length < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Check if the ranges are valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  if  ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
     || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  }
5119
7bf54ea07181 6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents: 3576
diff changeset
   139
  // Check zero copy
7bf54ea07181 6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents: 3576
diff changeset
   140
  if (length == 0)
7bf54ea07181 6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents: 3576
diff changeset
   141
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // This is an attempt to make the copy_array fast.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  int l2es = log2_element_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  int ihs = array_header_in_bytes() / wordSize;
5119
7bf54ea07181 6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents: 3576
diff changeset
   146
  char* src = (char*) ((oop*)s + ihs) + ((size_t)src_pos << l2es);
7bf54ea07181 6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents: 3576
diff changeset
   147
  char* dst = (char*) ((oop*)d + ihs) + ((size_t)dst_pos << l2es);
7bf54ea07181 6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents: 3576
diff changeset
   148
  Copy::conjoint_memory_atomic(src, dst, (size_t)length << l2es);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// create a klass of array holding typeArrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
klassOop typeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  typeArrayKlassHandle h_this(THREAD, as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  return array_klass_impl(h_this, or_null, n, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
klassOop typeArrayKlass::array_klass_impl(typeArrayKlassHandle h_this, bool or_null, int n, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  int dimension = h_this->dimension();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(dimension <= n, "check order of chain");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    if (dimension == n)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      return h_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  objArrayKlassHandle  h_ak(THREAD, h_this->higher_dimension());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if (h_ak.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    if (or_null)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    JavaThread *jt = (JavaThread *)THREAD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      MutexLocker mc(Compile_lock, THREAD);   // for vtables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      // Atomic create higher dimension and link into list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      MutexLocker mu(MultiArray_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      h_ak = objArrayKlassHandle(THREAD, h_this->higher_dimension());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      if (h_ak.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        klassOop oak = objArrayKlassKlass::cast(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
          Universe::objArrayKlassKlassObj())->allocate_objArray_klass(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
          dimension + 1, h_this, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        h_ak = objArrayKlassHandle(THREAD, oak);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        h_ak->set_lower_dimension(h_this());
7890
7d1d76674e2e 7011386: race in objArrayKlass::array_klass_impl
kvn
parents: 7397
diff changeset
   182
        OrderAccess::storestore();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        h_this->set_higher_dimension(h_ak());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        assert(h_ak->oop_is_objArray(), "incorrect initialization of objArrayKlass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (or_null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    return h_ak->array_klass_or_null(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  return h_ak->array_klass(n, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
klassOop typeArrayKlass::array_klass_impl(bool or_null, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  return array_klass_impl(or_null, dimension() +  1, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
int typeArrayKlass::oop_size(oop obj) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  typeArrayOop t = typeArrayOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  return t->object_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
void typeArrayKlass::oop_follow_contents(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // Performance tweak: We skip iterating over the klass pointer since we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // know that Universe::typeArrayKlass never moves.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void typeArrayKlass::oop_follow_contents(ParCompactionManager* cm, oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // Performance tweak: We skip iterating over the klass pointer since we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // know that Universe::typeArrayKlass never moves.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
int typeArrayKlass::oop_adjust_pointers(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  typeArrayOop t = typeArrayOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // Performance tweak: We skip iterating over the klass pointer since we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // know that Universe::typeArrayKlass never moves.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  return t->object_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
int typeArrayKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  typeArrayOop t = typeArrayOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // Performance tweak: We skip iterating over the klass pointer since we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // know that Universe::typeArrayKlass never moves.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  return t->object_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
int typeArrayKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  typeArrayOop t = typeArrayOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // Performance tweak: We skip iterating over the klass pointer since we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // know that Universe::typeArrayKlass never moves.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  return t->object_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
void typeArrayKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
typeArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  assert(obj->is_typeArray(),"must be a type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  return typeArrayOop(obj)->object_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
void typeArrayKlass::initialize(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  // Nothing to do. Having this function is handy since objArrayKlasses can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // initialized by calling initialize on their bottom_klass, see objArrayKlass::initialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
const char* typeArrayKlass::external_name(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    case T_BOOLEAN: return "[Z";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    case T_CHAR:    return "[C";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    case T_FLOAT:   return "[F";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    case T_DOUBLE:  return "[D";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    case T_BYTE:    return "[B";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    case T_SHORT:   return "[S";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    case T_INT:     return "[I";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    case T_LONG:    return "[J";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    default: ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
// Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
static void print_boolean_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    st->print_cr(" - %3d: %s", index, (ta->bool_at(index) == 0) ? "false" : "true");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
static void print_char_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    jchar c = ta->char_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
static void print_float_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    st->print_cr(" - %3d: %g", index, ta->float_at(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
static void print_double_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    st->print_cr(" - %3d: %g", index, ta->double_at(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
static void print_byte_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    jbyte c = ta->byte_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
static void print_short_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    int v = ta->ushort_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    st->print_cr(" - %3d: 0x%x\t %d", index, v, v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
static void print_int_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    jint v = ta->int_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    st->print_cr(" - %3d: 0x%x %d", index, v, v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
static void print_long_array(typeArrayOop ta, int print_len, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  for (int index = 0; index < print_len; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    jlong v = ta->long_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    st->print_cr(" - %3d: 0x%x 0x%x", index, high(v), low(v));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
void typeArrayKlass::oop_print_on(oop obj, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  arrayKlass::oop_print_on(obj, st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  typeArrayOop ta = typeArrayOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  int print_len = MIN2((intx) ta->length(), MaxElementPrintSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  switch (element_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    case T_BOOLEAN: print_boolean_array(ta, print_len, st); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    case T_CHAR:    print_char_array(ta, print_len, st);    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    case T_FLOAT:   print_float_array(ta, print_len, st);   break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    case T_DOUBLE:  print_double_array(ta, print_len, st);  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    case T_BYTE:    print_byte_array(ta, print_len, st);    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    case T_SHORT:   print_short_array(ta, print_len, st);   break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    case T_INT:     print_int_array(ta, print_len, st);     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    case T_LONG:    print_long_array(ta, print_len, st);    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    default: ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  int remaining = ta->length() - print_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  if (remaining > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    tty->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
const char* typeArrayKlass::internal_name() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  return Klass::external_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
}