src/share/vm/oops/arrayOop.hpp

Sun, 13 Apr 2008 17:43:42 -0400

author
coleenp
date
Sun, 13 Apr 2008 17:43:42 -0400
changeset 548
ba764ed4b6f2
parent 464
d5fc211aea19
child 600
437d03ea40b1
permissions
-rw-r--r--

6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
coleenp@548 25 // arrayOopDesc is the abstract baseclass for all arrays. It doesn't
coleenp@548 26 // declare pure virtual to enforce this because that would allocate a vtbl
coleenp@548 27 // in each instance, which we don't want.
coleenp@548 28
coleenp@548 29 // The layout of array Oops is:
coleenp@548 30 //
coleenp@548 31 // markOop
coleenp@548 32 // klassOop // 32 bits if compressed but declared 64 in LP64.
coleenp@548 33 // length // shares klass memory or allocated after declared fields.
coleenp@548 34
duke@435 35
duke@435 36 class arrayOopDesc : public oopDesc {
duke@435 37 friend class VMStructs;
coleenp@548 38
coleenp@548 39 // Interpreter/Compiler offsets
coleenp@548 40
coleenp@548 41 // Header size computation.
coleenp@548 42 // The header is considered the oop part of this type plus the length.
coleenp@548 43 // Returns the aligned header_size_in_bytes. This is not equivalent to
coleenp@548 44 // sizeof(arrayOopDesc) which should not appear in the code, except here.
coleenp@548 45 static int header_size_in_bytes() {
coleenp@548 46 size_t hs = UseCompressedOops ?
coleenp@548 47 sizeof(arrayOopDesc) :
coleenp@548 48 align_size_up(sizeof(arrayOopDesc) + sizeof(int), HeapWordSize);
coleenp@548 49 #ifdef ASSERT
coleenp@548 50 // make sure it isn't called before UseCompressedOops is initialized.
coleenp@548 51 static size_t arrayoopdesc_hs = 0;
coleenp@548 52 if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
coleenp@548 53 assert(arrayoopdesc_hs == hs, "header size can't change");
coleenp@548 54 #endif // ASSERT
coleenp@548 55 return (int)hs;
coleenp@548 56 }
duke@435 57
duke@435 58 public:
coleenp@548 59 // The _length field is not declared in C++. It is allocated after the
coleenp@548 60 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
coleenp@548 61 // it occupies the second half of the _klass field in oopDesc.
coleenp@548 62 static int length_offset_in_bytes() {
coleenp@548 63 return UseCompressedOops ? klass_gap_offset_in_bytes() :
coleenp@548 64 sizeof(arrayOopDesc);
coleenp@548 65 }
coleenp@548 66
coleenp@548 67 // Returns the offset of the first element.
coleenp@548 68 static int base_offset_in_bytes(BasicType type) {
coleenp@548 69 return header_size(type) * HeapWordSize;
coleenp@548 70 }
duke@435 71
duke@435 72 // Returns the address of the first element.
coleenp@548 73 void* base(BasicType type) const {
coleenp@548 74 return (void*) (((intptr_t) this) + base_offset_in_bytes(type));
coleenp@548 75 }
duke@435 76
duke@435 77 // Tells whether index is within bounds.
duke@435 78 bool is_within_bounds(int index) const { return 0 <= index && index < length(); }
duke@435 79
coleenp@548 80 // Accessors for instance variable which is not a C++ declared nonstatic
coleenp@548 81 // field.
coleenp@548 82 int length() const {
coleenp@548 83 return *(int*)(((intptr_t)this) + length_offset_in_bytes());
coleenp@548 84 }
coleenp@548 85 void set_length(int length) {
coleenp@548 86 *(int*)(((intptr_t)this) + length_offset_in_bytes()) = length;
coleenp@548 87 }
duke@435 88
coleenp@548 89 // Should only be called with constants as argument
coleenp@548 90 // (will not constant fold otherwise)
coleenp@548 91 // Returns the header size in words aligned to the requirements of the
coleenp@548 92 // array object type.
duke@435 93 static int header_size(BasicType type) {
coleenp@548 94 size_t typesize_in_bytes = header_size_in_bytes();
coleenp@548 95 return (int)(Universe::element_type_should_be_aligned(type)
coleenp@548 96 ? align_object_size(typesize_in_bytes/HeapWordSize)
coleenp@548 97 : typesize_in_bytes/HeapWordSize);
duke@435 98 }
duke@435 99
duke@435 100 // This method returns the maximum length that can passed into
duke@435 101 // typeArrayOop::object_size(scale, length, header_size) without causing an
duke@435 102 // overflow. We substract an extra 2*wordSize to guard against double word
duke@435 103 // alignments. It gets the scale from the type2aelembytes array.
duke@435 104 static int32_t max_array_length(BasicType type) {
duke@435 105 assert(type >= 0 && type < T_CONFLICT, "wrong type");
kvn@464 106 assert(type2aelembytes(type) != 0, "wrong type");
duke@435 107 // We use max_jint, since object_size is internally represented by an 'int'
duke@435 108 // This gives us an upper bound of max_jint words for the size of the oop.
duke@435 109 int32_t max_words = (max_jint - header_size(type) - 2);
coleenp@548 110 int elembytes = type2aelembytes(type);
duke@435 111 jlong len = ((jlong)max_words * HeapWordSize) / elembytes;
duke@435 112 return (len > max_jint) ? max_jint : (int32_t)len;
duke@435 113 }
duke@435 114
duke@435 115 };

mercurial