< prev index next >

src/hotspot/share/oops/array.hpp

Print this page

  1 /*
  2  * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  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  *

 38   friend class ArchiveBuilder;
 39   friend class MetadataFactory;
 40   friend class VMStructs;
 41   friend class JVMCIVMStructs;
 42   friend class MethodHandleCompiler;           // special case
 43   friend class WhiteBox;
 44   friend class FieldInfoStream;
 45 protected:
 46   int _length;                                 // the number of array elements
 47   T   _data[1];                                // the array memory
 48 
 49   void initialize(int length) {
 50     _length = length;
 51   }
 52 
 53  private:
 54   NONCOPYABLE(Array);
 55 
 56   inline void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw();
 57 





 58   static size_t byte_sizeof(int length, size_t elm_byte_size) {
 59     return sizeof(Array<T>) + MAX2(length - 1, 0) * elm_byte_size;
 60   }
 61   static size_t byte_sizeof(int length) { return byte_sizeof(length, sizeof(T)); }
 62 
 63   // WhiteBox API helper.
 64   // Can't distinguish between array of length 0 and length 1,
 65   // will always return 0 in those cases.
 66   static int bytes_to_length(size_t bytes)       {
 67     assert(is_aligned(bytes, BytesPerWord), "Must be, for now");
 68 
 69     if (sizeof(Array<T>) >= bytes) {
 70       return 0;
 71     }
 72 
 73     size_t left = bytes - sizeof(Array<T>);
 74     assert(is_aligned(left, sizeof(T)), "Must be");
 75 
 76     size_t elements = left / sizeof(T);
 77     assert(elements <= (size_t)INT_MAX, "number of elements " SIZE_FORMAT "doesn't fit into an int.", elements);

  1 /*
  2  * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  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  *

 38   friend class ArchiveBuilder;
 39   friend class MetadataFactory;
 40   friend class VMStructs;
 41   friend class JVMCIVMStructs;
 42   friend class MethodHandleCompiler;           // special case
 43   friend class WhiteBox;
 44   friend class FieldInfoStream;
 45 protected:
 46   int _length;                                 // the number of array elements
 47   T   _data[1];                                // the array memory
 48 
 49   void initialize(int length) {
 50     _length = length;
 51   }
 52 
 53  private:
 54   NONCOPYABLE(Array);
 55 
 56   inline void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw();
 57 
 58   inline void* operator new(size_t size, ClassLoaderData* loader_data, int length) throw();
 59 
 60 // Work-around -- see JDK-8331086
 61   inline void* operator new(size_t size, int length, MEMFLAGS flags) throw();
 62 
 63   static size_t byte_sizeof(int length, size_t elm_byte_size) {
 64     return sizeof(Array<T>) + MAX2(length - 1, 0) * elm_byte_size;
 65   }
 66   static size_t byte_sizeof(int length) { return byte_sizeof(length, sizeof(T)); }
 67 
 68   // WhiteBox API helper.
 69   // Can't distinguish between array of length 0 and length 1,
 70   // will always return 0 in those cases.
 71   static int bytes_to_length(size_t bytes)       {
 72     assert(is_aligned(bytes, BytesPerWord), "Must be, for now");
 73 
 74     if (sizeof(Array<T>) >= bytes) {
 75       return 0;
 76     }
 77 
 78     size_t left = bytes - sizeof(Array<T>);
 79     assert(is_aligned(left, sizeof(T)), "Must be");
 80 
 81     size_t elements = left / sizeof(T);
 82     assert(elements <= (size_t)INT_MAX, "number of elements " SIZE_FORMAT "doesn't fit into an int.", elements);
< prev index next >