duke@435: /* stefank@2314: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_OOPS_TYPEARRAYOOP_HPP stefank@2314: #define SHARE_VM_OOPS_TYPEARRAYOOP_HPP stefank@2314: stefank@2314: #include "oops/arrayOop.hpp" stefank@2314: #include "oops/typeArrayKlass.hpp" stefank@2314: #ifdef TARGET_OS_ARCH_linux_x86 stefank@2314: # include "orderAccess_linux_x86.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_ARCH_linux_sparc stefank@2314: # include "orderAccess_linux_sparc.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_ARCH_linux_zero stefank@2314: # include "orderAccess_linux_zero.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_ARCH_solaris_x86 stefank@2314: # include "orderAccess_solaris_x86.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_ARCH_solaris_sparc stefank@2314: # include "orderAccess_solaris_sparc.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_ARCH_windows_x86 stefank@2314: # include "orderAccess_windows_x86.inline.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_OS_ARCH_linux_arm bobv@2508: # include "orderAccess_linux_arm.inline.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_OS_ARCH_linux_ppc bobv@2508: # include "orderAccess_linux_ppc.inline.hpp" bobv@2508: #endif stefank@2314: duke@435: // A typeArrayOop is an array containing basic types (non oop elements). duke@435: // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs} duke@435: #include duke@435: duke@435: class typeArrayOopDesc : public arrayOopDesc { duke@435: protected: duke@435: jchar* char_base() const { return (jchar*) base(T_CHAR); } duke@435: jboolean* bool_base() const { return (jboolean*)base(T_BOOLEAN); } duke@435: jbyte* byte_base() const { return (jbyte*) base(T_BYTE); } duke@435: jint* int_base() const { return (jint*) base(T_INT); } duke@435: jlong* long_base() const { return (jlong*) base(T_LONG); } duke@435: jshort* short_base() const { return (jshort*) base(T_SHORT); } duke@435: jfloat* float_base() const { return (jfloat*) base(T_FLOAT); } duke@435: jdouble* double_base() const { return (jdouble*) base(T_DOUBLE); } duke@435: duke@435: friend class typeArrayKlass; duke@435: duke@435: public: duke@435: jbyte* byte_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &byte_base()[which]; duke@435: } duke@435: duke@435: jboolean* bool_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &bool_base()[which]; duke@435: } duke@435: duke@435: jchar* char_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &char_base()[which]; duke@435: } duke@435: duke@435: jint* int_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &int_base()[which]; duke@435: } duke@435: duke@435: jshort* short_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &short_base()[which]; duke@435: } duke@435: duke@435: jushort* ushort_at_addr(int which) const { // for field descriptor arrays duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return (jushort*) &short_base()[which]; duke@435: } duke@435: duke@435: jlong* long_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &long_base()[which]; duke@435: } duke@435: duke@435: jfloat* float_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &float_base()[which]; duke@435: } duke@435: duke@435: jdouble* double_at_addr(int which) const { duke@435: assert(is_within_bounds(which), "index out of bounds"); duke@435: return &double_base()[which]; duke@435: } duke@435: duke@435: jbyte byte_at(int which) const { return *byte_at_addr(which); } duke@435: void byte_at_put(int which, jbyte contents) { *byte_at_addr(which) = contents; } duke@435: duke@435: jboolean bool_at(int which) const { return *bool_at_addr(which); } duke@435: void bool_at_put(int which, jboolean contents) { *bool_at_addr(which) = contents; } duke@435: duke@435: jchar char_at(int which) const { return *char_at_addr(which); } duke@435: void char_at_put(int which, jchar contents) { *char_at_addr(which) = contents; } duke@435: duke@435: jint int_at(int which) const { return *int_at_addr(which); } duke@435: void int_at_put(int which, jint contents) { *int_at_addr(which) = contents; } duke@435: duke@435: jshort short_at(int which) const { return *short_at_addr(which); } duke@435: void short_at_put(int which, jshort contents) { *short_at_addr(which) = contents; } duke@435: duke@435: jushort ushort_at(int which) const { return *ushort_at_addr(which); } duke@435: void ushort_at_put(int which, jushort contents) { *ushort_at_addr(which) = contents; } duke@435: duke@435: jlong long_at(int which) const { return *long_at_addr(which); } duke@435: void long_at_put(int which, jlong contents) { *long_at_addr(which) = contents; } duke@435: duke@435: jfloat float_at(int which) const { return *float_at_addr(which); } duke@435: void float_at_put(int which, jfloat contents) { *float_at_addr(which) = contents; } duke@435: duke@435: jdouble double_at(int which) const { return *double_at_addr(which); } duke@435: void double_at_put(int which, jdouble contents) { *double_at_addr(which) = contents; } duke@435: duke@435: jbyte byte_at_acquire(int which) const { return OrderAccess::load_acquire(byte_at_addr(which)); } duke@435: void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); } duke@435: duke@435: // Sizing duke@435: duke@435: // Returns the number of words necessary to hold an array of "len" duke@435: // elements each of the given "byte_size". duke@435: private: duke@435: static int object_size(int lh, int length) { duke@435: int instance_header_size = Klass::layout_helper_header_size(lh); duke@435: int element_shift = Klass::layout_helper_log2_element_size(lh); duke@435: DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh)); duke@435: assert(length <= arrayOopDesc::max_array_length(etype), "no overflow"); duke@435: duke@435: julong size_in_bytes = length; duke@435: size_in_bytes <<= element_shift; duke@435: size_in_bytes += instance_header_size; duke@435: julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize); duke@435: assert(size_in_words <= (julong)max_jint, "no overflow"); duke@435: duke@435: return align_object_size((intptr_t)size_in_words); duke@435: } duke@435: duke@435: public: duke@435: int object_size() { duke@435: typeArrayKlass* tk = typeArrayKlass::cast(klass()); duke@435: return object_size(tk->layout_helper(), length()); duke@435: } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_OOPS_TYPEARRAYOOP_HPP