< prev index next >

src/hotspot/share/oops/array.hpp

Print this page
rev 57095 : [mq]: use
rev 57096 : [mq]: trailing_semi


  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_OOPS_ARRAY_HPP
  26 #define SHARE_OOPS_ARRAY_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/metaspace.hpp"
  30 #include "runtime/atomic.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 
  51  private:
  52   // Turn off copy constructor and assignment operator.
  53   Array(const Array<T>&);
  54   void operator=(const Array<T>&);
  55 
  56   void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw() {
  57     size_t word_size = Array::size(length);
  58     return (void*) Metaspace::allocate(loader_data, word_size,
  59                                        MetaspaceObj::array_type(sizeof(T)), THREAD);
  60   }
  61 
  62   static size_t byte_sizeof(int length, size_t elm_byte_size) {
  63     return sizeof(Array<T>) + MAX2(length - 1, 0) * elm_byte_size;
  64   }
  65   static size_t byte_sizeof(int length) { return byte_sizeof(length, sizeof(T)); }
  66 
  67   // WhiteBox API helper.
  68   // Can't distinguish between array of length 0 and length 1,
  69   // will always return 0 in those cases.
  70   static int bytes_to_length(size_t bytes)       {
  71     assert(is_aligned(bytes, BytesPerWord), "Must be, for now");
  72 
  73     if (sizeof(Array<T>) >= bytes) {
  74       return 0;




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


  54 
  55   void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw() {
  56     size_t word_size = Array::size(length);
  57     return (void*) Metaspace::allocate(loader_data, word_size,
  58                                        MetaspaceObj::array_type(sizeof(T)), THREAD);
  59   }
  60 
  61   static size_t byte_sizeof(int length, size_t elm_byte_size) {
  62     return sizeof(Array<T>) + MAX2(length - 1, 0) * elm_byte_size;
  63   }
  64   static size_t byte_sizeof(int length) { return byte_sizeof(length, sizeof(T)); }
  65 
  66   // WhiteBox API helper.
  67   // Can't distinguish between array of length 0 and length 1,
  68   // will always return 0 in those cases.
  69   static int bytes_to_length(size_t bytes)       {
  70     assert(is_aligned(bytes, BytesPerWord), "Must be, for now");
  71 
  72     if (sizeof(Array<T>) >= bytes) {
  73       return 0;


< prev index next >