annotate src/share/vm/oops/arrayOop.hpp @ 29:d5fc211aea19

6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM Summary: T_ADDRESS size is defined as 'int' size (4 bytes) but C2 use it for raw pointers and as memory type for StoreP and LoadP nodes. Reviewed-by: jrose
author kvn
date Mon, 25 Feb 2008 15:05:44 -0800
parents a61af66fc99e
children ba764ed4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // arrayOopDesc is the abstract baseclass for all arrays.
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 class arrayOopDesc : public oopDesc {
a61af66fc99e Initial load
duke
parents:
diff changeset
28 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
30 int _length; // number of elements in the array
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Interpreter/Compiler offsets
a61af66fc99e Initial load
duke
parents:
diff changeset
34 static int length_offset_in_bytes() { return offset_of(arrayOopDesc, _length); }
a61af66fc99e Initial load
duke
parents:
diff changeset
35 static int base_offset_in_bytes(BasicType type) { return header_size(type) * HeapWordSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // Returns the address of the first element.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 void* base(BasicType type) const { return (void*) (((intptr_t) this) + base_offset_in_bytes(type)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Tells whether index is within bounds.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 bool is_within_bounds(int index) const { return 0 <= index && index < length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Accessores for instance variable
a61af66fc99e Initial load
duke
parents:
diff changeset
44 int length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
45 void set_length(int length) { _length = length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Header size computation.
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Should only be called with constants as argument (will not constant fold otherwise)
a61af66fc99e Initial load
duke
parents:
diff changeset
49 static int header_size(BasicType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return Universe::element_type_should_be_aligned(type)
a61af66fc99e Initial load
duke
parents:
diff changeset
51 ? align_object_size(sizeof(arrayOopDesc)/HeapWordSize)
a61af66fc99e Initial load
duke
parents:
diff changeset
52 : sizeof(arrayOopDesc)/HeapWordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // This method returns the maximum length that can passed into
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // typeArrayOop::object_size(scale, length, header_size) without causing an
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // overflow. We substract an extra 2*wordSize to guard against double word
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // alignments. It gets the scale from the type2aelembytes array.
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static int32_t max_array_length(BasicType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 assert(type >= 0 && type < T_CONFLICT, "wrong type");
29
d5fc211aea19 6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents: 0
diff changeset
61 assert(type2aelembytes(type) != 0, "wrong type");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // We use max_jint, since object_size is internally represented by an 'int'
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // This gives us an upper bound of max_jint words for the size of the oop.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 int32_t max_words = (max_jint - header_size(type) - 2);
29
d5fc211aea19 6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents: 0
diff changeset
65 int elembytes = (type == T_OBJECT) ? T_OBJECT_aelem_bytes : type2aelembytes(type);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66 jlong len = ((jlong)max_words * HeapWordSize) / elembytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return (len > max_jint) ? max_jint : (int32_t)len;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 };