< prev index next >

src/share/vm/oops/typeArrayOop.hpp

Print this page
rev 8961 : [mq]: diff-shenandoah.patch


   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 #include "runtime/orderAccess.inline.hpp"
  31 
  32 // A typeArrayOop is an array containing basic types (non oop elements).
  33 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
  34 #include <limits.h>
  35 
  36 class typeArrayOopDesc : public arrayOopDesc {
  37  protected:
  38   jchar*    char_base()   const { return (jchar*)   base(T_CHAR); }
  39   jboolean* bool_base()   const { return (jboolean*)base(T_BOOLEAN); }
  40   jbyte*    byte_base()   const { return (jbyte*)   base(T_BYTE); }
  41   jint*     int_base()    const { return (jint*)    base(T_INT); }
  42   jlong*    long_base()   const { return (jlong*)   base(T_LONG); }
  43   jshort*   short_base()  const { return (jshort*)  base(T_SHORT); }
  44   jfloat*   float_base()  const { return (jfloat*)  base(T_FLOAT); }
  45   jdouble*  double_base() const { return (jdouble*) base(T_DOUBLE); }
  46 
  47   friend class TypeArrayKlass;


  75   jushort* ushort_at_addr(int which) const {  // for field descriptor arrays
  76     assert(is_within_bounds(which), "index out of bounds");
  77     return (jushort*) &short_base()[which];
  78   }
  79 
  80   jlong* long_at_addr(int which) const {
  81     assert(is_within_bounds(which), "index out of bounds");
  82     return &long_base()[which];
  83   }
  84 
  85   jfloat* float_at_addr(int which) const {
  86     assert(is_within_bounds(which), "index out of bounds");
  87     return &float_base()[which];
  88   }
  89 
  90   jdouble* double_at_addr(int which) const {
  91     assert(is_within_bounds(which), "index out of bounds");
  92     return &double_base()[which];
  93   }
  94 
  95   jbyte byte_at(int which) const                  { return *byte_at_addr(which); }
  96   void byte_at_put(int which, jbyte contents)     { *byte_at_addr(which) = contents; }






  97 
  98   jboolean bool_at(int which) const               { return *bool_at_addr(which); }
  99   void bool_at_put(int which, jboolean contents)  { *bool_at_addr(which) = contents; }






 100 
 101   jchar char_at(int which) const                  { return *char_at_addr(which); }
 102   void char_at_put(int which, jchar contents)     { *char_at_addr(which) = contents; }






 103 
 104   jint int_at(int which) const                    { return *int_at_addr(which); }
 105   void int_at_put(int which, jint contents)       { *int_at_addr(which) = contents; }






 106 
 107   jshort short_at(int which) const                { return *short_at_addr(which); }
 108   void short_at_put(int which, jshort contents)   { *short_at_addr(which) = contents; }






 109 
 110   jushort ushort_at(int which) const              { return *ushort_at_addr(which); }
 111   void ushort_at_put(int which, jushort contents) { *ushort_at_addr(which) = contents; }






 112 
 113   jlong long_at(int which) const                  { return *long_at_addr(which); }
 114   void long_at_put(int which, jlong contents)     { *long_at_addr(which) = contents; }






 115 
 116   jfloat float_at(int which) const                { return *float_at_addr(which); }
 117   void float_at_put(int which, jfloat contents)   { *float_at_addr(which) = contents; }






 118 
 119   jdouble double_at(int which) const              { return *double_at_addr(which); }
 120   void double_at_put(int which, jdouble contents) { *double_at_addr(which) = contents; }






 121 
 122   jbyte byte_at_acquire(int which) const              { return OrderAccess::load_acquire(byte_at_addr(which)); }
 123   void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); }






 124 
 125   // Java thinks metadata arrays are just arrays of either long or int, since
 126   // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate
 127   // casting
 128 #ifdef _LP64
 129   Metadata* metadata_at(int which) const {
 130     return (Metadata*)*long_at_addr(which); }


 131   void metadata_at_put(int which, Metadata* contents) {
 132     *long_at_addr(which) = (long)contents;

 133   }
 134 #else
 135   Metadata* metadata_at(int which) const {
 136     return (Metadata*)*int_at_addr(which); }


 137   void metadata_at_put(int which, Metadata* contents) {
 138     *int_at_addr(which) = (int)contents;

 139   }
 140 #endif // _LP64
 141 
 142   // Sizing
 143 
 144   // Returns the number of words necessary to hold an array of "len"
 145   // elements each of the given "byte_size".
 146  private:
 147   static int object_size(int lh, int length) {
 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 = (juint)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 


   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 "gc/shared/barrierSet.hpp"
  29 #include "oops/arrayOop.hpp"
  30 #include "oops/typeArrayKlass.hpp"
  31 #include "runtime/orderAccess.inline.hpp"
  32 
  33 // A typeArrayOop is an array containing basic types (non oop elements).
  34 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
  35 #include <limits.h>
  36 
  37 class typeArrayOopDesc : public arrayOopDesc {
  38  protected:
  39   jchar*    char_base()   const { return (jchar*)   base(T_CHAR); }
  40   jboolean* bool_base()   const { return (jboolean*)base(T_BOOLEAN); }
  41   jbyte*    byte_base()   const { return (jbyte*)   base(T_BYTE); }
  42   jint*     int_base()    const { return (jint*)    base(T_INT); }
  43   jlong*    long_base()   const { return (jlong*)   base(T_LONG); }
  44   jshort*   short_base()  const { return (jshort*)  base(T_SHORT); }
  45   jfloat*   float_base()  const { return (jfloat*)  base(T_FLOAT); }
  46   jdouble*  double_base() const { return (jdouble*) base(T_DOUBLE); }
  47 
  48   friend class TypeArrayKlass;


  76   jushort* ushort_at_addr(int which) const {  // for field descriptor arrays
  77     assert(is_within_bounds(which), "index out of bounds");
  78     return (jushort*) &short_base()[which];
  79   }
  80 
  81   jlong* long_at_addr(int which) const {
  82     assert(is_within_bounds(which), "index out of bounds");
  83     return &long_base()[which];
  84   }
  85 
  86   jfloat* float_at_addr(int which) const {
  87     assert(is_within_bounds(which), "index out of bounds");
  88     return &float_base()[which];
  89   }
  90 
  91   jdouble* double_at_addr(int which) const {
  92     assert(is_within_bounds(which), "index out of bounds");
  93     return &double_base()[which];
  94   }
  95 
  96   jbyte byte_at(int which) const                  {
  97     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
  98     return *p->byte_at_addr(which);
  99   }
 100   void byte_at_put(int which, jbyte contents)     {
 101     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 102     *p->byte_at_addr(which) = contents;
 103   }
 104 
 105   jboolean bool_at(int which) const               {
 106     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 107     return *p->bool_at_addr(which);
 108   }
 109   void bool_at_put(int which, jboolean contents)  {
 110     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 111     *p->bool_at_addr(which) = contents;
 112   }
 113 
 114   jchar char_at(int which) const                  {
 115     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 116     return *p->char_at_addr(which);
 117   }
 118   void char_at_put(int which, jchar contents)     {
 119     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 120     *p->char_at_addr(which) = contents;
 121   }
 122 
 123   jint int_at(int which) const                    {
 124     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 125     return *p->int_at_addr(which);
 126   }
 127   void int_at_put(int which, jint contents)       {
 128     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 129     *p->int_at_addr(which) = contents;
 130   }
 131 
 132   jshort short_at(int which) const                {
 133     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 134     return *p->short_at_addr(which);
 135   }
 136   void short_at_put(int which, jshort contents)   {
 137     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 138     *p->short_at_addr(which) = contents;
 139   }
 140 
 141   jushort ushort_at(int which) const              {
 142     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 143     return *p->ushort_at_addr(which);
 144   }
 145   void ushort_at_put(int which, jushort contents) {
 146     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 147     *p->ushort_at_addr(which) = contents;
 148   }
 149 
 150   jlong long_at(int which) const                  {
 151     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 152     return *p->long_at_addr(which);
 153   }
 154   void long_at_put(int which, jlong contents)     {
 155     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 156     *p->long_at_addr(which) = contents;
 157   }
 158 
 159   jfloat float_at(int which) const                {
 160     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 161     return *p->float_at_addr(which);
 162   }
 163   void float_at_put(int which, jfloat contents)   {
 164     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 165     *p->float_at_addr(which) = contents;
 166   }
 167 
 168   jdouble double_at(int which) const              {
 169     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 170     return *p->double_at_addr(which);
 171   }
 172   void double_at_put(int which, jdouble contents) {
 173     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 174     *p->double_at_addr(which) = contents;
 175   }
 176 
 177   jbyte byte_at_acquire(int which) const              {
 178     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 179     return OrderAccess::load_acquire(p->byte_at_addr(which));
 180   }
 181   void release_byte_at_put(int which, jbyte contents) {
 182     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 183     OrderAccess::release_store(p->byte_at_addr(which), contents);
 184   }
 185 
 186   // Java thinks metadata arrays are just arrays of either long or int, since
 187   // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate
 188   // casting
 189 #ifdef _LP64
 190   Metadata* metadata_at(int which) const {
 191     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 192     return (Metadata*)*p->long_at_addr(which);
 193   }
 194   void metadata_at_put(int which, Metadata* contents) {
 195     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 196     *p->long_at_addr(which) = (long)contents;
 197   }
 198 #else
 199   Metadata* metadata_at(int which) const {
 200     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_oop((oop) this));
 201     return (Metadata*)*p->int_at_addr(which);
 202   }
 203   void metadata_at_put(int which, Metadata* contents) {
 204     typeArrayOop p = typeArrayOop(oopDesc::bs()->resolve_and_maybe_copy_oop(this));
 205     *p->int_at_addr(which) = (int)contents;
 206   }
 207 #endif // _LP64
 208 
 209   // Sizing
 210 
 211   // Returns the number of words necessary to hold an array of "len"
 212   // elements each of the given "byte_size".
 213  private:
 214   static int object_size(int lh, int length) {
 215     int instance_header_size = Klass::layout_helper_header_size(lh);
 216     int element_shift = Klass::layout_helper_log2_element_size(lh);
 217     DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh));
 218     assert(length <= arrayOopDesc::max_array_length(etype), "no overflow");
 219 
 220     julong size_in_bytes = (juint)length;
 221     size_in_bytes <<= element_shift;
 222     size_in_bytes += instance_header_size;
 223     julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize);
 224     assert(size_in_words <= (julong)max_jint, "no overflow");
 225 
< prev index next >