src/share/vm/oops/arrayOop.hpp

Mon, 12 Aug 2013 17:37:02 +0200

author
ehelin
date
Mon, 12 Aug 2013 17:37:02 +0200
changeset 5694
7944aba7ba41
parent 4037
da91efe96a93
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8015107: NPG: Use consistent naming for metaspace concepts
Reviewed-by: coleenp, mgerdin, hseigel

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_OOPS_ARRAYOOP_HPP
stefank@2314 26 #define SHARE_VM_OOPS_ARRAYOOP_HPP
stefank@2314 27
stefank@2314 28 #include "memory/universe.inline.hpp"
stefank@2314 29 #include "oops/oop.hpp"
stefank@2314 30
coleenp@548 31 // arrayOopDesc is the abstract baseclass for all arrays. It doesn't
coleenp@548 32 // declare pure virtual to enforce this because that would allocate a vtbl
coleenp@548 33 // in each instance, which we don't want.
coleenp@548 34
coleenp@548 35 // The layout of array Oops is:
coleenp@548 36 //
coleenp@548 37 // markOop
coleenp@4037 38 // Klass* // 32 bits if compressed but declared 64 in LP64.
coleenp@548 39 // length // shares klass memory or allocated after declared fields.
coleenp@548 40
duke@435 41
duke@435 42 class arrayOopDesc : public oopDesc {
duke@435 43 friend class VMStructs;
coleenp@548 44
coleenp@548 45 // Interpreter/Compiler offsets
coleenp@548 46
coleenp@548 47 // Header size computation.
coleenp@548 48 // The header is considered the oop part of this type plus the length.
coleenp@548 49 // Returns the aligned header_size_in_bytes. This is not equivalent to
kvn@600 50 // sizeof(arrayOopDesc) which should not appear in the code.
coleenp@548 51 static int header_size_in_bytes() {
kvn@600 52 size_t hs = align_size_up(length_offset_in_bytes() + sizeof(int),
kvn@600 53 HeapWordSize);
coleenp@548 54 #ifdef ASSERT
coleenp@548 55 // make sure it isn't called before UseCompressedOops is initialized.
coleenp@548 56 static size_t arrayoopdesc_hs = 0;
coleenp@548 57 if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
coleenp@548 58 assert(arrayoopdesc_hs == hs, "header size can't change");
coleenp@548 59 #endif // ASSERT
coleenp@548 60 return (int)hs;
coleenp@548 61 }
duke@435 62
duke@435 63 public:
coleenp@548 64 // The _length field is not declared in C++. It is allocated after the
coleenp@548 65 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
coleenp@548 66 // it occupies the second half of the _klass field in oopDesc.
coleenp@548 67 static int length_offset_in_bytes() {
ehelin@5694 68 return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
coleenp@548 69 sizeof(arrayOopDesc);
coleenp@548 70 }
coleenp@548 71
coleenp@548 72 // Returns the offset of the first element.
coleenp@548 73 static int base_offset_in_bytes(BasicType type) {
coleenp@548 74 return header_size(type) * HeapWordSize;
coleenp@548 75 }
duke@435 76
duke@435 77 // Returns the address of the first element.
coleenp@548 78 void* base(BasicType type) const {
coleenp@548 79 return (void*) (((intptr_t) this) + base_offset_in_bytes(type));
coleenp@548 80 }
duke@435 81
duke@435 82 // Tells whether index is within bounds.
duke@435 83 bool is_within_bounds(int index) const { return 0 <= index && index < length(); }
duke@435 84
coleenp@548 85 // Accessors for instance variable which is not a C++ declared nonstatic
coleenp@548 86 // field.
coleenp@548 87 int length() const {
coleenp@548 88 return *(int*)(((intptr_t)this) + length_offset_in_bytes());
coleenp@548 89 }
coleenp@548 90 void set_length(int length) {
coleenp@548 91 *(int*)(((intptr_t)this) + length_offset_in_bytes()) = length;
coleenp@548 92 }
duke@435 93
coleenp@548 94 // Should only be called with constants as argument
coleenp@548 95 // (will not constant fold otherwise)
coleenp@548 96 // Returns the header size in words aligned to the requirements of the
coleenp@548 97 // array object type.
duke@435 98 static int header_size(BasicType type) {
coleenp@548 99 size_t typesize_in_bytes = header_size_in_bytes();
coleenp@548 100 return (int)(Universe::element_type_should_be_aligned(type)
kvn@1926 101 ? align_object_offset(typesize_in_bytes/HeapWordSize)
coleenp@548 102 : typesize_in_bytes/HeapWordSize);
duke@435 103 }
duke@435 104
jcoomes@916 105 // Return the maximum length of an array of BasicType. The length can passed
jcoomes@916 106 // to typeArrayOop::object_size(scale, length, header_size) without causing an
brutisso@3266 107 // overflow. We also need to make sure that this will not overflow a size_t on
brutisso@3266 108 // 32 bit platforms when we convert it to a byte size.
duke@435 109 static int32_t max_array_length(BasicType type) {
duke@435 110 assert(type >= 0 && type < T_CONFLICT, "wrong type");
kvn@464 111 assert(type2aelembytes(type) != 0, "wrong type");
brutisso@3266 112
brutisso@3271 113 const size_t max_element_words_per_size_t =
brutisso@3271 114 align_size_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment);
brutisso@3271 115 const size_t max_elements_per_size_t =
brutisso@3271 116 HeapWordSize * max_element_words_per_size_t / type2aelembytes(type);
brutisso@3266 117 if ((size_t)max_jint < max_elements_per_size_t) {
brutisso@3271 118 // It should be ok to return max_jint here, but parts of the code
brutisso@3271 119 // (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for
brutisso@3271 120 // passing around the size (in words) of an object. So, we need to avoid
brutisso@3271 121 // overflowing an int when we add the header. See CRs 4718400 and 7110613.
brutisso@3271 122 return align_size_down(max_jint - header_size(type), MinObjAlignment);
jcoomes@916 123 }
brutisso@3266 124 return (int32_t)max_elements_per_size_t;
brutisso@3266 125 }
jcoomes@916 126
brutisso@3266 127 // for unit testing
brutisso@3266 128 #ifndef PRODUCT
brutisso@3266 129 static bool check_max_length_overflow(BasicType type);
brutisso@3266 130 static int32_t old_max_array_length(BasicType type);
stefank@3335 131 static void test_max_array_length();
brutisso@3266 132 #endif
duke@435 133 };
stefank@2314 134
stefank@2314 135 #endif // SHARE_VM_OOPS_ARRAYOOP_HPP

mercurial