< prev index next >

src/hotspot/share/oops/array.hpp

Print this page




  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_ARRAY_HPP
  26 #define SHARE_VM_OOPS_ARRAY_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/metaspace.hpp"
  30 #include "runtime/orderAccess.hpp"
  31 #include "utilities/align.hpp"
  32 
  33 // Array for metadata allocation
  34 
  35 template <typename T>
  36 class Array: public MetaspaceObj {
  37   friend class MetadataFactory;
  38   friend class MetaspaceShared;
  39   friend class VMStructs;
  40   friend class JVMCIVMStructs;
  41   friend class MethodHandleCompiler;           // special case
  42   friend class WhiteBox;
  43 protected:
  44   int _length;                                 // the number of array elements
  45   T   _data[1];                                // the array memory
  46 
  47   void initialize(int length) {
  48     _length = length;
  49   }
  50 


 105   // standard operations
 106   int  length() const                 { return _length; }
 107   T* data()                           { return _data; }
 108   bool is_empty() const               { return length() == 0; }
 109 
 110   int index_of(const T& x) const {
 111     int i = length();
 112     while (i-- > 0 && _data[i] != x) ;
 113 
 114     return i;
 115   }
 116 
 117   // sort the array.
 118   bool contains(const T& x) const      { return index_of(x) >= 0; }
 119 
 120   T    at(int i) const                 { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return _data[i]; }
 121   void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); _data[i] = x; }
 122   T*   adr_at(const int i)             { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return &_data[i]; }
 123   int  find(const T& x)                { return index_of(x); }
 124 
 125   T at_acquire(const int which)              { return OrderAccess::load_acquire(adr_at(which)); }
 126   void release_at_put(int which, T contents) { OrderAccess::release_store(adr_at(which), contents); }
 127 
 128   static int size(int length) {
 129     size_t bytes = align_up(byte_sizeof(length), BytesPerWord);
 130     size_t words = bytes / BytesPerWord;
 131 
 132     assert(words <= INT_MAX, "Overflow: " SIZE_FORMAT, words);
 133 
 134     return (int)words;
 135   }
 136   int size() {
 137     return size(_length);
 138   }
 139 
 140   static int length_offset_in_bytes() { return (int) (offset_of(Array<T>, _length)); }
 141   // Note, this offset don't have to be wordSize aligned.
 142   static int base_offset_in_bytes() { return (int) (offset_of(Array<T>, _data)); };
 143 
 144   // FIXME: How to handle this?
 145   void print_value_on(outputStream* st) const {
 146     st->print("Array<T>(" INTPTR_FORMAT ")", p2i(this));


  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_ARRAY_HPP
  26 #define SHARE_VM_OOPS_ARRAY_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/metaspace.hpp"

  30 #include "utilities/align.hpp"
  31 
  32 // Array for metadata allocation
  33 
  34 template <typename T>
  35 class Array: public MetaspaceObj {
  36   friend class MetadataFactory;
  37   friend class MetaspaceShared;
  38   friend class VMStructs;
  39   friend class JVMCIVMStructs;
  40   friend class MethodHandleCompiler;           // special case
  41   friend class WhiteBox;
  42 protected:
  43   int _length;                                 // the number of array elements
  44   T   _data[1];                                // the array memory
  45 
  46   void initialize(int length) {
  47     _length = length;
  48   }
  49 


 104   // standard operations
 105   int  length() const                 { return _length; }
 106   T* data()                           { return _data; }
 107   bool is_empty() const               { return length() == 0; }
 108 
 109   int index_of(const T& x) const {
 110     int i = length();
 111     while (i-- > 0 && _data[i] != x) ;
 112 
 113     return i;
 114   }
 115 
 116   // sort the array.
 117   bool contains(const T& x) const      { return index_of(x) >= 0; }
 118 
 119   T    at(int i) const                 { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return _data[i]; }
 120   void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); _data[i] = x; }
 121   T*   adr_at(const int i)             { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return &_data[i]; }
 122   int  find(const T& x)                { return index_of(x); }
 123 
 124   T at_acquire(const int which);
 125   void release_at_put(int which, T contents);
 126 
 127   static int size(int length) {
 128     size_t bytes = align_up(byte_sizeof(length), BytesPerWord);
 129     size_t words = bytes / BytesPerWord;
 130 
 131     assert(words <= INT_MAX, "Overflow: " SIZE_FORMAT, words);
 132 
 133     return (int)words;
 134   }
 135   int size() {
 136     return size(_length);
 137   }
 138 
 139   static int length_offset_in_bytes() { return (int) (offset_of(Array<T>, _length)); }
 140   // Note, this offset don't have to be wordSize aligned.
 141   static int base_offset_in_bytes() { return (int) (offset_of(Array<T>, _data)); };
 142 
 143   // FIXME: How to handle this?
 144   void print_value_on(outputStream* st) const {
 145     st->print("Array<T>(" INTPTR_FORMAT ")", p2i(this));
< prev index next >