annotate src/share/vm/oops/typeArrayOop.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
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-2007 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 // A typeArrayOop is an array containing basic types (non oop elements).
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
a61af66fc99e Initial load
duke
parents:
diff changeset
27 #include <limits.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 class typeArrayOopDesc : public arrayOopDesc {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
31 jchar* char_base() const { return (jchar*) base(T_CHAR); }
a61af66fc99e Initial load
duke
parents:
diff changeset
32 jboolean* bool_base() const { return (jboolean*)base(T_BOOLEAN); }
a61af66fc99e Initial load
duke
parents:
diff changeset
33 jbyte* byte_base() const { return (jbyte*) base(T_BYTE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
34 jint* int_base() const { return (jint*) base(T_INT); }
a61af66fc99e Initial load
duke
parents:
diff changeset
35 jlong* long_base() const { return (jlong*) base(T_LONG); }
a61af66fc99e Initial load
duke
parents:
diff changeset
36 jshort* short_base() const { return (jshort*) base(T_SHORT); }
a61af66fc99e Initial load
duke
parents:
diff changeset
37 jfloat* float_base() const { return (jfloat*) base(T_FLOAT); }
a61af66fc99e Initial load
duke
parents:
diff changeset
38 jdouble* double_base() const { return (jdouble*) base(T_DOUBLE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 friend class typeArrayKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
43 jbyte* byte_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
45 return &byte_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 jboolean* bool_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return &bool_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 jchar* char_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return &char_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 jint* int_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return &int_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 jshort* short_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return &short_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 jushort* ushort_at_addr(int which) const { // for field descriptor arrays
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return (jushort*) &short_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 jlong* long_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return &long_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 jfloat* float_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return &float_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 jdouble* double_at_addr(int which) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 assert(is_within_bounds(which), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return &double_base()[which];
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 jbyte byte_at(int which) const { return *byte_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void byte_at_put(int which, jbyte contents) { *byte_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 jboolean bool_at(int which) const { return *bool_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void bool_at_put(int which, jboolean contents) { *bool_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 jchar char_at(int which) const { return *char_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 void char_at_put(int which, jchar contents) { *char_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 jint int_at(int which) const { return *int_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void int_at_put(int which, jint contents) { *int_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 jshort short_at(int which) const { return *short_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 void short_at_put(int which, jshort contents) { *short_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 jushort ushort_at(int which) const { return *ushort_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 void ushort_at_put(int which, jushort contents) { *ushort_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 jlong long_at(int which) const { return *long_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void long_at_put(int which, jlong contents) { *long_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 jfloat float_at(int which) const { return *float_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 void float_at_put(int which, jfloat contents) { *float_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 jdouble double_at(int which) const { return *double_at_addr(which); }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 void double_at_put(int which, jdouble contents) { *double_at_addr(which) = contents; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 jbyte byte_at_acquire(int which) const { return OrderAccess::load_acquire(byte_at_addr(which)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Sizing
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Returns the number of words necessary to hold an array of "len"
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // elements each of the given "byte_size".
a61af66fc99e Initial load
duke
parents:
diff changeset
122 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
123 static int object_size(int lh, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 int instance_header_size = Klass::layout_helper_header_size(lh);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 int element_shift = Klass::layout_helper_log2_element_size(lh);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh));
a61af66fc99e Initial load
duke
parents:
diff changeset
127 assert(length <= arrayOopDesc::max_array_length(etype), "no overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 julong size_in_bytes = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 size_in_bytes <<= element_shift;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 size_in_bytes += instance_header_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(size_in_words <= (julong)max_jint, "no overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return align_object_size((intptr_t)size_in_words);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
139 int object_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 typeArrayKlass* tk = typeArrayKlass::cast(klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return object_size(tk->layout_helper(), length());
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 };