1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/oops/typeArrayOop.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,143 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 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 +// A typeArrayOop is an array containing basic types (non oop elements). 1.29 +// It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs} 1.30 +#include <limits.h> 1.31 + 1.32 +class typeArrayOopDesc : public arrayOopDesc { 1.33 + protected: 1.34 + jchar* char_base() const { return (jchar*) base(T_CHAR); } 1.35 + jboolean* bool_base() const { return (jboolean*)base(T_BOOLEAN); } 1.36 + jbyte* byte_base() const { return (jbyte*) base(T_BYTE); } 1.37 + jint* int_base() const { return (jint*) base(T_INT); } 1.38 + jlong* long_base() const { return (jlong*) base(T_LONG); } 1.39 + jshort* short_base() const { return (jshort*) base(T_SHORT); } 1.40 + jfloat* float_base() const { return (jfloat*) base(T_FLOAT); } 1.41 + jdouble* double_base() const { return (jdouble*) base(T_DOUBLE); } 1.42 + 1.43 + friend class typeArrayKlass; 1.44 + 1.45 + public: 1.46 + jbyte* byte_at_addr(int which) const { 1.47 + assert(is_within_bounds(which), "index out of bounds"); 1.48 + return &byte_base()[which]; 1.49 + } 1.50 + 1.51 + jboolean* bool_at_addr(int which) const { 1.52 + assert(is_within_bounds(which), "index out of bounds"); 1.53 + return &bool_base()[which]; 1.54 + } 1.55 + 1.56 + jchar* char_at_addr(int which) const { 1.57 + assert(is_within_bounds(which), "index out of bounds"); 1.58 + return &char_base()[which]; 1.59 + } 1.60 + 1.61 + jint* int_at_addr(int which) const { 1.62 + assert(is_within_bounds(which), "index out of bounds"); 1.63 + return &int_base()[which]; 1.64 + } 1.65 + 1.66 + jshort* short_at_addr(int which) const { 1.67 + assert(is_within_bounds(which), "index out of bounds"); 1.68 + return &short_base()[which]; 1.69 + } 1.70 + 1.71 + jushort* ushort_at_addr(int which) const { // for field descriptor arrays 1.72 + assert(is_within_bounds(which), "index out of bounds"); 1.73 + return (jushort*) &short_base()[which]; 1.74 + } 1.75 + 1.76 + jlong* long_at_addr(int which) const { 1.77 + assert(is_within_bounds(which), "index out of bounds"); 1.78 + return &long_base()[which]; 1.79 + } 1.80 + 1.81 + jfloat* float_at_addr(int which) const { 1.82 + assert(is_within_bounds(which), "index out of bounds"); 1.83 + return &float_base()[which]; 1.84 + } 1.85 + 1.86 + jdouble* double_at_addr(int which) const { 1.87 + assert(is_within_bounds(which), "index out of bounds"); 1.88 + return &double_base()[which]; 1.89 + } 1.90 + 1.91 + jbyte byte_at(int which) const { return *byte_at_addr(which); } 1.92 + void byte_at_put(int which, jbyte contents) { *byte_at_addr(which) = contents; } 1.93 + 1.94 + jboolean bool_at(int which) const { return *bool_at_addr(which); } 1.95 + void bool_at_put(int which, jboolean contents) { *bool_at_addr(which) = contents; } 1.96 + 1.97 + jchar char_at(int which) const { return *char_at_addr(which); } 1.98 + void char_at_put(int which, jchar contents) { *char_at_addr(which) = contents; } 1.99 + 1.100 + jint int_at(int which) const { return *int_at_addr(which); } 1.101 + void int_at_put(int which, jint contents) { *int_at_addr(which) = contents; } 1.102 + 1.103 + jshort short_at(int which) const { return *short_at_addr(which); } 1.104 + void short_at_put(int which, jshort contents) { *short_at_addr(which) = contents; } 1.105 + 1.106 + jushort ushort_at(int which) const { return *ushort_at_addr(which); } 1.107 + void ushort_at_put(int which, jushort contents) { *ushort_at_addr(which) = contents; } 1.108 + 1.109 + jlong long_at(int which) const { return *long_at_addr(which); } 1.110 + void long_at_put(int which, jlong contents) { *long_at_addr(which) = contents; } 1.111 + 1.112 + jfloat float_at(int which) const { return *float_at_addr(which); } 1.113 + void float_at_put(int which, jfloat contents) { *float_at_addr(which) = contents; } 1.114 + 1.115 + jdouble double_at(int which) const { return *double_at_addr(which); } 1.116 + void double_at_put(int which, jdouble contents) { *double_at_addr(which) = contents; } 1.117 + 1.118 + jbyte byte_at_acquire(int which) const { return OrderAccess::load_acquire(byte_at_addr(which)); } 1.119 + void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); } 1.120 + 1.121 + // Sizing 1.122 + 1.123 + // Returns the number of words necessary to hold an array of "len" 1.124 + // elements each of the given "byte_size". 1.125 + private: 1.126 + static int object_size(int lh, int length) { 1.127 + int instance_header_size = Klass::layout_helper_header_size(lh); 1.128 + int element_shift = Klass::layout_helper_log2_element_size(lh); 1.129 + DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh)); 1.130 + assert(length <= arrayOopDesc::max_array_length(etype), "no overflow"); 1.131 + 1.132 + julong size_in_bytes = length; 1.133 + size_in_bytes <<= element_shift; 1.134 + size_in_bytes += instance_header_size; 1.135 + julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize); 1.136 + assert(size_in_words <= (julong)max_jint, "no overflow"); 1.137 + 1.138 + return align_object_size((intptr_t)size_in_words); 1.139 + } 1.140 + 1.141 + public: 1.142 + int object_size() { 1.143 + typeArrayKlass* tk = typeArrayKlass::cast(klass()); 1.144 + return object_size(tk->layout_helper(), length()); 1.145 + } 1.146 +};