hotspot/src/share/vm/utilities/array.hpp
changeset 33105 294e48b4f704
parent 27680 8ecc0871c18e
child 35123 b0b89d83bcf5
equal deleted inserted replaced
33104:a7c0f60a1294 33105:294e48b4f704
   339 
   339 
   340     size_t left = bytes - sizeof(Array<T>);
   340     size_t left = bytes - sizeof(Array<T>);
   341     assert(is_size_aligned(left, sizeof(T)), "Must be");
   341     assert(is_size_aligned(left, sizeof(T)), "Must be");
   342 
   342 
   343     size_t elements = left / sizeof(T);
   343     size_t elements = left / sizeof(T);
   344     assert(elements <= (size_t)INT_MAX, err_msg("number of elements " SIZE_FORMAT "doesn't fit into an int.", elements));
   344     assert(elements <= (size_t)INT_MAX, "number of elements " SIZE_FORMAT "doesn't fit into an int.", elements);
   345 
   345 
   346     int length = (int)elements;
   346     int length = (int)elements;
   347 
   347 
   348     assert((size_t)size(length) * BytesPerWord == bytes,
   348     assert((size_t)size(length) * BytesPerWord == bytes,
   349         err_msg("Expected: " SIZE_FORMAT " got: " SIZE_FORMAT,
   349            "Expected: " SIZE_FORMAT " got: " SIZE_FORMAT,
   350                 bytes, (size_t)size(length) * BytesPerWord));
   350            bytes, (size_t)size(length) * BytesPerWord);
   351 
   351 
   352     return length;
   352     return length;
   353   }
   353   }
   354 
   354 
   355   explicit Array(int length) : _length(length) {
   355   explicit Array(int length) : _length(length) {
   378   }
   378   }
   379 
   379 
   380   // sort the array.
   380   // sort the array.
   381   bool contains(const T& x) const      { return index_of(x) >= 0; }
   381   bool contains(const T& x) const      { return index_of(x) >= 0; }
   382 
   382 
   383   T    at(int i) const                 { assert(i >= 0 && i< _length, err_msg("oob: 0 <= %d < %d", i, _length)); return _data[i]; }
   383   T    at(int i) const                 { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return _data[i]; }
   384   void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, err_msg("oob: 0 <= %d < %d", i, _length)); _data[i] = x; }
   384   void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); _data[i] = x; }
   385   T*   adr_at(const int i)             { assert(i >= 0 && i< _length, err_msg("oob: 0 <= %d < %d", i, _length)); return &_data[i]; }
   385   T*   adr_at(const int i)             { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return &_data[i]; }
   386   int  find(const T& x)                { return index_of(x); }
   386   int  find(const T& x)                { return index_of(x); }
   387 
   387 
   388   T at_acquire(const int which)              { return OrderAccess::load_acquire(adr_at(which)); }
   388   T at_acquire(const int which)              { return OrderAccess::load_acquire(adr_at(which)); }
   389   void release_at_put(int which, T contents) { OrderAccess::release_store(adr_at(which), contents); }
   389   void release_at_put(int which, T contents) { OrderAccess::release_store(adr_at(which), contents); }
   390 
   390