src/share/vm/oops/arrayOop.hpp

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 916
7d7a7c599c17
child 1014
0fbdb4381b99
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

duke@435 1 /*
xdono@631 2 * Copyright 1997-2008 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
kvn@600 44 // sizeof(arrayOopDesc) which should not appear in the code.
coleenp@548 45 static int header_size_in_bytes() {
kvn@600 46 size_t hs = align_size_up(length_offset_in_bytes() + sizeof(int),
kvn@600 47 HeapWordSize);
coleenp@548 48 #ifdef ASSERT
coleenp@548 49 // make sure it isn't called before UseCompressedOops is initialized.
coleenp@548 50 static size_t arrayoopdesc_hs = 0;
coleenp@548 51 if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
coleenp@548 52 assert(arrayoopdesc_hs == hs, "header size can't change");
coleenp@548 53 #endif // ASSERT
coleenp@548 54 return (int)hs;
coleenp@548 55 }
duke@435 56
duke@435 57 public:
coleenp@548 58 // The _length field is not declared in C++. It is allocated after the
coleenp@548 59 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
coleenp@548 60 // it occupies the second half of the _klass field in oopDesc.
coleenp@548 61 static int length_offset_in_bytes() {
coleenp@548 62 return UseCompressedOops ? klass_gap_offset_in_bytes() :
coleenp@548 63 sizeof(arrayOopDesc);
coleenp@548 64 }
coleenp@548 65
coleenp@548 66 // Returns the offset of the first element.
coleenp@548 67 static int base_offset_in_bytes(BasicType type) {
coleenp@548 68 return header_size(type) * HeapWordSize;
coleenp@548 69 }
duke@435 70
duke@435 71 // Returns the address of the first element.
coleenp@548 72 void* base(BasicType type) const {
coleenp@548 73 return (void*) (((intptr_t) this) + base_offset_in_bytes(type));
coleenp@548 74 }
duke@435 75
duke@435 76 // Tells whether index is within bounds.
duke@435 77 bool is_within_bounds(int index) const { return 0 <= index && index < length(); }
duke@435 78
coleenp@548 79 // Accessors for instance variable which is not a C++ declared nonstatic
coleenp@548 80 // field.
coleenp@548 81 int length() const {
coleenp@548 82 return *(int*)(((intptr_t)this) + length_offset_in_bytes());
coleenp@548 83 }
coleenp@548 84 void set_length(int length) {
coleenp@548 85 *(int*)(((intptr_t)this) + length_offset_in_bytes()) = length;
coleenp@548 86 }
duke@435 87
coleenp@548 88 // Should only be called with constants as argument
coleenp@548 89 // (will not constant fold otherwise)
coleenp@548 90 // Returns the header size in words aligned to the requirements of the
coleenp@548 91 // array object type.
duke@435 92 static int header_size(BasicType type) {
coleenp@548 93 size_t typesize_in_bytes = header_size_in_bytes();
coleenp@548 94 return (int)(Universe::element_type_should_be_aligned(type)
coleenp@548 95 ? align_object_size(typesize_in_bytes/HeapWordSize)
coleenp@548 96 : typesize_in_bytes/HeapWordSize);
duke@435 97 }
duke@435 98
jcoomes@916 99 // Return the maximum length of an array of BasicType. The length can passed
jcoomes@916 100 // to typeArrayOop::object_size(scale, length, header_size) without causing an
jcoomes@916 101 // overflow.
duke@435 102 static int32_t max_array_length(BasicType type) {
duke@435 103 assert(type >= 0 && type < T_CONFLICT, "wrong type");
kvn@464 104 assert(type2aelembytes(type) != 0, "wrong type");
jcoomes@916 105 const int bytes_per_element = type2aelembytes(type);
jcoomes@916 106 if (bytes_per_element < HeapWordSize) {
jcoomes@916 107 return max_jint;
jcoomes@916 108 }
jcoomes@916 109
jcoomes@916 110 const int32_t max_words = align_size_down(max_jint, MinObjAlignment);
jcoomes@916 111 const int32_t max_element_words = max_words - header_size(type);
jcoomes@916 112 const int32_t words_per_element = bytes_per_element >> LogHeapWordSize;
jcoomes@916 113 return max_element_words / words_per_element;
duke@435 114 }
duke@435 115 };

mercurial