1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/oops/arrayOop.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,70 @@ 1.4 +/* 1.5 + * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// arrayOopDesc is the abstract baseclass for all arrays. 1.29 + 1.30 +class arrayOopDesc : public oopDesc { 1.31 + friend class VMStructs; 1.32 + private: 1.33 + int _length; // number of elements in the array 1.34 + 1.35 + public: 1.36 + // Interpreter/Compiler offsets 1.37 + static int length_offset_in_bytes() { return offset_of(arrayOopDesc, _length); } 1.38 + static int base_offset_in_bytes(BasicType type) { return header_size(type) * HeapWordSize; } 1.39 + 1.40 + // Returns the address of the first element. 1.41 + void* base(BasicType type) const { return (void*) (((intptr_t) this) + base_offset_in_bytes(type)); } 1.42 + 1.43 + // Tells whether index is within bounds. 1.44 + bool is_within_bounds(int index) const { return 0 <= index && index < length(); } 1.45 + 1.46 + // Accessores for instance variable 1.47 + int length() const { return _length; } 1.48 + void set_length(int length) { _length = length; } 1.49 + 1.50 + // Header size computation. 1.51 + // Should only be called with constants as argument (will not constant fold otherwise) 1.52 + static int header_size(BasicType type) { 1.53 + return Universe::element_type_should_be_aligned(type) 1.54 + ? align_object_size(sizeof(arrayOopDesc)/HeapWordSize) 1.55 + : sizeof(arrayOopDesc)/HeapWordSize; 1.56 + } 1.57 + 1.58 + // This method returns the maximum length that can passed into 1.59 + // typeArrayOop::object_size(scale, length, header_size) without causing an 1.60 + // overflow. We substract an extra 2*wordSize to guard against double word 1.61 + // alignments. It gets the scale from the type2aelembytes array. 1.62 + static int32_t max_array_length(BasicType type) { 1.63 + assert(type >= 0 && type < T_CONFLICT, "wrong type"); 1.64 + assert(type2aelembytes[type] != 0, "wrong type"); 1.65 + // We use max_jint, since object_size is internally represented by an 'int' 1.66 + // This gives us an upper bound of max_jint words for the size of the oop. 1.67 + int32_t max_words = (max_jint - header_size(type) - 2); 1.68 + int elembytes = (type == T_OBJECT) ? T_OBJECT_aelem_bytes : type2aelembytes[type]; 1.69 + jlong len = ((jlong)max_words * HeapWordSize) / elembytes; 1.70 + return (len > max_jint) ? max_jint : (int32_t)len; 1.71 + } 1.72 + 1.73 +};