src/share/vm/oops/typeArrayOop.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2007, 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  */
  24 
























  25 // A typeArrayOop is an array containing basic types (non oop elements).
  26 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
  27 #include <limits.h>
  28 
  29 class typeArrayOopDesc : public arrayOopDesc {
  30  protected:
  31   jchar*    char_base()   const { return (jchar*)   base(T_CHAR); }
  32   jboolean* bool_base()   const { return (jboolean*)base(T_BOOLEAN); }
  33   jbyte*    byte_base()   const { return (jbyte*)   base(T_BYTE); }
  34   jint*     int_base()    const { return (jint*)    base(T_INT); }
  35   jlong*    long_base()   const { return (jlong*)   base(T_LONG); }
  36   jshort*   short_base()  const { return (jshort*)  base(T_SHORT); }
  37   jfloat*   float_base()  const { return (jfloat*)  base(T_FLOAT); }
  38   jdouble*  double_base() const { return (jdouble*) base(T_DOUBLE); }
  39 
  40   friend class typeArrayKlass;
  41 
  42  public:
  43   jbyte* byte_at_addr(int which) const {
  44     assert(is_within_bounds(which), "index out of bounds");


 124     int instance_header_size = Klass::layout_helper_header_size(lh);
 125     int element_shift = Klass::layout_helper_log2_element_size(lh);
 126     DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh));
 127     assert(length <= arrayOopDesc::max_array_length(etype), "no overflow");
 128 
 129     julong size_in_bytes = length;
 130     size_in_bytes <<= element_shift;
 131     size_in_bytes += instance_header_size;
 132     julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize);
 133     assert(size_in_words <= (julong)max_jint, "no overflow");
 134 
 135     return align_object_size((intptr_t)size_in_words);
 136   }
 137 
 138  public:
 139   int object_size() {
 140     typeArrayKlass* tk = typeArrayKlass::cast(klass());
 141     return object_size(tk->layout_helper(), length());
 142   }
 143 };


   1 /*
   2  * Copyright (c) 1997, 2010, 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  */
  24 
  25 #ifndef SHARE_VM_OOPS_TYPEARRAYOOP_HPP
  26 #define SHARE_VM_OOPS_TYPEARRAYOOP_HPP
  27 
  28 #include "oops/arrayOop.hpp"
  29 #include "oops/typeArrayKlass.hpp"
  30 #ifdef TARGET_OS_ARCH_linux_x86
  31 # include "orderAccess_linux_x86.inline.hpp"
  32 #endif
  33 #ifdef TARGET_OS_ARCH_linux_sparc
  34 # include "orderAccess_linux_sparc.inline.hpp"
  35 #endif
  36 #ifdef TARGET_OS_ARCH_linux_zero
  37 # include "orderAccess_linux_zero.inline.hpp"
  38 #endif
  39 #ifdef TARGET_OS_ARCH_solaris_x86
  40 # include "orderAccess_solaris_x86.inline.hpp"
  41 #endif
  42 #ifdef TARGET_OS_ARCH_solaris_sparc
  43 # include "orderAccess_solaris_sparc.inline.hpp"
  44 #endif
  45 #ifdef TARGET_OS_ARCH_windows_x86
  46 # include "orderAccess_windows_x86.inline.hpp"
  47 #endif
  48 
  49 // A typeArrayOop is an array containing basic types (non oop elements).
  50 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
  51 #include <limits.h>
  52 
  53 class typeArrayOopDesc : public arrayOopDesc {
  54  protected:
  55   jchar*    char_base()   const { return (jchar*)   base(T_CHAR); }
  56   jboolean* bool_base()   const { return (jboolean*)base(T_BOOLEAN); }
  57   jbyte*    byte_base()   const { return (jbyte*)   base(T_BYTE); }
  58   jint*     int_base()    const { return (jint*)    base(T_INT); }
  59   jlong*    long_base()   const { return (jlong*)   base(T_LONG); }
  60   jshort*   short_base()  const { return (jshort*)  base(T_SHORT); }
  61   jfloat*   float_base()  const { return (jfloat*)  base(T_FLOAT); }
  62   jdouble*  double_base() const { return (jdouble*) base(T_DOUBLE); }
  63 
  64   friend class typeArrayKlass;
  65 
  66  public:
  67   jbyte* byte_at_addr(int which) const {
  68     assert(is_within_bounds(which), "index out of bounds");


 148     int instance_header_size = Klass::layout_helper_header_size(lh);
 149     int element_shift = Klass::layout_helper_log2_element_size(lh);
 150     DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh));
 151     assert(length <= arrayOopDesc::max_array_length(etype), "no overflow");
 152 
 153     julong size_in_bytes = length;
 154     size_in_bytes <<= element_shift;
 155     size_in_bytes += instance_header_size;
 156     julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize);
 157     assert(size_in_words <= (julong)max_jint, "no overflow");
 158 
 159     return align_object_size((intptr_t)size_in_words);
 160   }
 161 
 162  public:
 163   int object_size() {
 164     typeArrayKlass* tk = typeArrayKlass::cast(klass());
 165     return object_size(tk->layout_helper(), length());
 166   }
 167 };
 168 
 169 #endif // SHARE_VM_OOPS_TYPEARRAYOOP_HPP