src/share/vm/oops/typeArrayOop.hpp

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/typeArrayOop.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,201 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2012, 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 +#ifndef SHARE_VM_OOPS_TYPEARRAYOOP_HPP
    1.29 +#define SHARE_VM_OOPS_TYPEARRAYOOP_HPP
    1.30 +
    1.31 +#include "oops/arrayOop.hpp"
    1.32 +#include "oops/typeArrayKlass.hpp"
    1.33 +#ifdef TARGET_OS_ARCH_linux_x86
    1.34 +# include "orderAccess_linux_x86.inline.hpp"
    1.35 +#endif
    1.36 +#ifdef TARGET_OS_ARCH_linux_sparc
    1.37 +# include "orderAccess_linux_sparc.inline.hpp"
    1.38 +#endif
    1.39 +#ifdef TARGET_OS_ARCH_linux_zero
    1.40 +# include "orderAccess_linux_zero.inline.hpp"
    1.41 +#endif
    1.42 +#ifdef TARGET_OS_ARCH_solaris_x86
    1.43 +# include "orderAccess_solaris_x86.inline.hpp"
    1.44 +#endif
    1.45 +#ifdef TARGET_OS_ARCH_solaris_sparc
    1.46 +# include "orderAccess_solaris_sparc.inline.hpp"
    1.47 +#endif
    1.48 +#ifdef TARGET_OS_ARCH_windows_x86
    1.49 +# include "orderAccess_windows_x86.inline.hpp"
    1.50 +#endif
    1.51 +#ifdef TARGET_OS_ARCH_linux_arm
    1.52 +# include "orderAccess_linux_arm.inline.hpp"
    1.53 +#endif
    1.54 +#ifdef TARGET_OS_ARCH_linux_ppc
    1.55 +# include "orderAccess_linux_ppc.inline.hpp"
    1.56 +#endif
    1.57 +#ifdef TARGET_OS_ARCH_aix_ppc
    1.58 +# include "orderAccess_aix_ppc.inline.hpp"
    1.59 +#endif
    1.60 +#ifdef TARGET_OS_ARCH_bsd_x86
    1.61 +# include "orderAccess_bsd_x86.inline.hpp"
    1.62 +#endif
    1.63 +#ifdef TARGET_OS_ARCH_bsd_zero
    1.64 +# include "orderAccess_bsd_zero.inline.hpp"
    1.65 +#endif
    1.66 +
    1.67 +// A typeArrayOop is an array containing basic types (non oop elements).
    1.68 +// It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
    1.69 +#include <limits.h>
    1.70 +
    1.71 +class typeArrayOopDesc : public arrayOopDesc {
    1.72 + protected:
    1.73 +  jchar*    char_base()   const { return (jchar*)   base(T_CHAR); }
    1.74 +  jboolean* bool_base()   const { return (jboolean*)base(T_BOOLEAN); }
    1.75 +  jbyte*    byte_base()   const { return (jbyte*)   base(T_BYTE); }
    1.76 +  jint*     int_base()    const { return (jint*)    base(T_INT); }
    1.77 +  jlong*    long_base()   const { return (jlong*)   base(T_LONG); }
    1.78 +  jshort*   short_base()  const { return (jshort*)  base(T_SHORT); }
    1.79 +  jfloat*   float_base()  const { return (jfloat*)  base(T_FLOAT); }
    1.80 +  jdouble*  double_base() const { return (jdouble*) base(T_DOUBLE); }
    1.81 +
    1.82 +  friend class TypeArrayKlass;
    1.83 +
    1.84 + public:
    1.85 +  jbyte* byte_at_addr(int which) const {
    1.86 +    assert(is_within_bounds(which), "index out of bounds");
    1.87 +    return &byte_base()[which];
    1.88 +  }
    1.89 +
    1.90 +  jboolean* bool_at_addr(int which) const {
    1.91 +    assert(is_within_bounds(which), "index out of bounds");
    1.92 +    return &bool_base()[which];
    1.93 +  }
    1.94 +
    1.95 +  jchar* char_at_addr(int which) const {
    1.96 +    assert(is_within_bounds(which), "index out of bounds");
    1.97 +    return &char_base()[which];
    1.98 +  }
    1.99 +
   1.100 +  jint* int_at_addr(int which) const {
   1.101 +    assert(is_within_bounds(which), "index out of bounds");
   1.102 +    return &int_base()[which];
   1.103 +  }
   1.104 +
   1.105 +  jshort* short_at_addr(int which) const {
   1.106 +    assert(is_within_bounds(which), "index out of bounds");
   1.107 +    return &short_base()[which];
   1.108 +  }
   1.109 +
   1.110 +  jushort* ushort_at_addr(int which) const {  // for field descriptor arrays
   1.111 +    assert(is_within_bounds(which), "index out of bounds");
   1.112 +    return (jushort*) &short_base()[which];
   1.113 +  }
   1.114 +
   1.115 +  jlong* long_at_addr(int which) const {
   1.116 +    assert(is_within_bounds(which), "index out of bounds");
   1.117 +    return &long_base()[which];
   1.118 +  }
   1.119 +
   1.120 +  jfloat* float_at_addr(int which) const {
   1.121 +    assert(is_within_bounds(which), "index out of bounds");
   1.122 +    return &float_base()[which];
   1.123 +  }
   1.124 +
   1.125 +  jdouble* double_at_addr(int which) const {
   1.126 +    assert(is_within_bounds(which), "index out of bounds");
   1.127 +    return &double_base()[which];
   1.128 +  }
   1.129 +
   1.130 +  jbyte byte_at(int which) const                  { return *byte_at_addr(which); }
   1.131 +  void byte_at_put(int which, jbyte contents)     { *byte_at_addr(which) = contents; }
   1.132 +
   1.133 +  jboolean bool_at(int which) const               { return *bool_at_addr(which); }
   1.134 +  void bool_at_put(int which, jboolean contents)  { *bool_at_addr(which) = contents; }
   1.135 +
   1.136 +  jchar char_at(int which) const                  { return *char_at_addr(which); }
   1.137 +  void char_at_put(int which, jchar contents)     { *char_at_addr(which) = contents; }
   1.138 +
   1.139 +  jint int_at(int which) const                    { return *int_at_addr(which); }
   1.140 +  void int_at_put(int which, jint contents)       { *int_at_addr(which) = contents; }
   1.141 +
   1.142 +  jshort short_at(int which) const                { return *short_at_addr(which); }
   1.143 +  void short_at_put(int which, jshort contents)   { *short_at_addr(which) = contents; }
   1.144 +
   1.145 +  jushort ushort_at(int which) const              { return *ushort_at_addr(which); }
   1.146 +  void ushort_at_put(int which, jushort contents) { *ushort_at_addr(which) = contents; }
   1.147 +
   1.148 +  jlong long_at(int which) const                  { return *long_at_addr(which); }
   1.149 +  void long_at_put(int which, jlong contents)     { *long_at_addr(which) = contents; }
   1.150 +
   1.151 +  jfloat float_at(int which) const                { return *float_at_addr(which); }
   1.152 +  void float_at_put(int which, jfloat contents)   { *float_at_addr(which) = contents; }
   1.153 +
   1.154 +  jdouble double_at(int which) const              { return *double_at_addr(which); }
   1.155 +  void double_at_put(int which, jdouble contents) { *double_at_addr(which) = contents; }
   1.156 +
   1.157 +  jbyte byte_at_acquire(int which) const              { return OrderAccess::load_acquire(byte_at_addr(which)); }
   1.158 +  void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); }
   1.159 +
   1.160 +  // Java thinks metadata arrays are just arrays of either long or int, since
   1.161 +  // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate
   1.162 +  // casting
   1.163 +#ifdef _LP64
   1.164 +  Metadata* metadata_at(int which) const {
   1.165 +    return (Metadata*)*long_at_addr(which); }
   1.166 +  void metadata_at_put(int which, Metadata* contents) {
   1.167 +    *long_at_addr(which) = (long)contents;
   1.168 +  }
   1.169 +#else
   1.170 +  Metadata* metadata_at(int which) const {
   1.171 +    return (Metadata*)*int_at_addr(which); }
   1.172 +  void metadata_at_put(int which, Metadata* contents) {
   1.173 +    *int_at_addr(which) = (int)contents;
   1.174 +  }
   1.175 +#endif // _LP64
   1.176 +
   1.177 +  // Sizing
   1.178 +
   1.179 +  // Returns the number of words necessary to hold an array of "len"
   1.180 +  // elements each of the given "byte_size".
   1.181 + private:
   1.182 +  static int object_size(int lh, int length) {
   1.183 +    int instance_header_size = Klass::layout_helper_header_size(lh);
   1.184 +    int element_shift = Klass::layout_helper_log2_element_size(lh);
   1.185 +    DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh));
   1.186 +    assert(length <= arrayOopDesc::max_array_length(etype), "no overflow");
   1.187 +
   1.188 +    julong size_in_bytes = length;
   1.189 +    size_in_bytes <<= element_shift;
   1.190 +    size_in_bytes += instance_header_size;
   1.191 +    julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize);
   1.192 +    assert(size_in_words <= (julong)max_jint, "no overflow");
   1.193 +
   1.194 +    return align_object_size((intptr_t)size_in_words);
   1.195 +  }
   1.196 +
   1.197 + public:
   1.198 +  int object_size() {
   1.199 +    TypeArrayKlass* tk = TypeArrayKlass::cast(klass());
   1.200 +    return object_size(tk->layout_helper(), length());
   1.201 +  }
   1.202 +};
   1.203 +
   1.204 +#endif // SHARE_VM_OOPS_TYPEARRAYOOP_HPP

mercurial