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