src/share/vm/oops/typeArrayOop.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8140685.02 Sdiff src/share/vm/oops

src/share/vm/oops/typeArrayOop.hpp

Print this page




  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;
  48 
  49  public:
  50   jbyte* byte_at_addr(int which) const {
  51     assert(is_within_bounds(which), "index out of bounds");
  52     return &byte_base()[which];
  53   }
  54 
  55   jboolean* bool_at_addr(int which) const {
  56     assert(is_within_bounds(which), "index out of bounds");
  57     return &bool_base()[which];
  58   }
  59 
  60   jchar* char_at_addr(int which) const {
  61     assert(is_within_bounds(which), "index out of bounds");
  62     return &char_base()[which];
  63   }
  64 
  65   jint* int_at_addr(int which) const {
  66     assert(is_within_bounds(which), "index out of bounds");
  67     return &int_base()[which];
  68   }
  69 





  70   jshort* short_at_addr(int which) const {
  71     assert(is_within_bounds(which), "index out of bounds");
  72     return &short_base()[which];
  73   }
  74 
  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 


  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   juint*    uint_base()  const  { return (juint*)   base(T_INT); }
  43   jlong*    long_base()   const { return (jlong*)   base(T_LONG); }
  44   julong*   ulong_base()  const { return (julong*)  base(T_LONG); }
  45   jshort*   short_base()  const { return (jshort*)  base(T_SHORT); }
  46   jfloat*   float_base()  const { return (jfloat*)  base(T_FLOAT); }
  47   jdouble*  double_base() const { return (jdouble*) base(T_DOUBLE); }
  48 
  49   friend class TypeArrayKlass;
  50 
  51  public:
  52   jbyte* byte_at_addr(int which) const {
  53     assert(is_within_bounds(which), "index out of bounds");
  54     return &byte_base()[which];
  55   }
  56 
  57   jboolean* bool_at_addr(int which) const {
  58     assert(is_within_bounds(which), "index out of bounds");
  59     return &bool_base()[which];
  60   }
  61 
  62   jchar* char_at_addr(int which) const {
  63     assert(is_within_bounds(which), "index out of bounds");
  64     return &char_base()[which];
  65   }
  66 
  67   jint* int_at_addr(int which) const {
  68     assert(is_within_bounds(which), "index out of bounds");
  69     return &int_base()[which];
  70   }
  71 
  72   juint* uint_at_addr(int which) const {
  73     assert(is_within_bounds(which), "index out of bounds");
  74     return (juint*)&uint_base()[which];
  75   }
  76 
  77   jshort* short_at_addr(int which) const {
  78     assert(is_within_bounds(which), "index out of bounds");
  79     return &short_base()[which];
  80   }
  81 
  82   jushort* ushort_at_addr(int which) const {  // for field descriptor arrays
  83     assert(is_within_bounds(which), "index out of bounds");
  84     return (jushort*) &short_base()[which];
  85   }
  86 
  87   jlong* long_at_addr(int which) const {
  88     assert(is_within_bounds(which), "index out of bounds");
  89     return &long_base()[which];
  90   }
  91 
  92   julong* ulong_at_addr(int which) const {
  93     assert(is_within_bounds(which), "index out of bounds");
  94     return (julong*) &ulong_base()[which];
  95   }
  96 
  97   jfloat* float_at_addr(int which) const {
  98     assert(is_within_bounds(which), "index out of bounds");
  99     return &float_base()[which];
 100   }
 101 
 102   jdouble* double_at_addr(int which) const {
 103     assert(is_within_bounds(which), "index out of bounds");
 104     return &double_base()[which];
 105   }
 106 
 107   jbyte byte_at(int which) const                  { return *byte_at_addr(which); }
 108   void byte_at_put(int which, jbyte contents)     { *byte_at_addr(which) = contents; }
 109 
 110   jboolean bool_at(int which) const               { return *bool_at_addr(which); }
 111   void bool_at_put(int which, jboolean contents)  { *bool_at_addr(which) = contents; }
 112 
 113   jchar char_at(int which) const                  { return *char_at_addr(which); }
 114   void char_at_put(int which, jchar contents)     { *char_at_addr(which) = contents; }
 115 
 116   jint int_at(int which) const                    { return *int_at_addr(which); }
 117   void int_at_put(int which, jint contents)       { *int_at_addr(which) = contents; }
 118 
 119   jshort short_at(int which) const                { return *short_at_addr(which); }
 120   void short_at_put(int which, jshort contents)   { *short_at_addr(which) = contents; }
 121 
 122   jushort ushort_at(int which) const              { return *ushort_at_addr(which); }
 123   void ushort_at_put(int which, jushort contents) { *ushort_at_addr(which) = contents; }
 124 
 125   jlong long_at(int which) const                  { return *long_at_addr(which); }
 126   void long_at_put(int which, jlong contents)     { *long_at_addr(which) = contents; }
 127 
 128   jfloat float_at(int which) const                { return *float_at_addr(which); }
 129   void float_at_put(int which, jfloat contents)   { *float_at_addr(which) = contents; }
 130 
 131   jdouble double_at(int which) const              { return *double_at_addr(which); }
 132   void double_at_put(int which, jdouble contents) { *double_at_addr(which) = contents; }
 133 
 134   jbyte byte_at_acquire(int which) const              { return OrderAccess::load_acquire(byte_at_addr(which)); }
 135   void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); }
 136 
 137   // Java thinks Symbol* arrays are just arrays of either long or int, since
 138   // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate
 139   // casting
 140 #ifdef _LP64
 141   Symbol* symbol_at(int which) const {
 142     return (Symbol*)*ulong_at_addr(which); }
 143   void symbol_at_put(int which, Symbol* contents) {
 144     *ulong_at_addr(which) = (julong)contents;
 145   }
 146 #else
 147   Symbol* symbol_at(int which) const {
 148     return (Symbol*)*uint_at_addr(which); }
 149   void symbol_at_put(int which, Symbol* contents) {
 150     *uint_at_addr(which) = (juint)contents;
 151   }
 152 #endif // _LP64
 153 
 154   // Sizing
 155 
 156   // Returns the number of words necessary to hold an array of "len"
 157   // elements each of the given "byte_size".
 158  private:
 159   static int object_size(int lh, int length) {
 160     int instance_header_size = Klass::layout_helper_header_size(lh);
 161     int element_shift = Klass::layout_helper_log2_element_size(lh);
 162     DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh));
 163     assert(length <= arrayOopDesc::max_array_length(etype), "no overflow");
 164 
 165     julong size_in_bytes = (juint)length;
 166     size_in_bytes <<= element_shift;
 167     size_in_bytes += instance_header_size;
 168     julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize);
 169     assert(size_in_words <= (julong)max_jint, "no overflow");
 170 
src/share/vm/oops/typeArrayOop.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File