annotate src/share/vm/oops/typeArrayOop.hpp @ 5699:9d15b81d5d1b

8016839: JSR292: AME instead of IAE when calling a method Summary: Catch missing-because-illegal case for itable entries and use an exception-throwing method instead of null. Reviewed-by: acorn, jrose, coleenp
author drchase
date Tue, 26 Nov 2013 18:16:04 -0500
parents da91efe96a93
children
rev   line source
duke@0 1 /*
coleenp@3602 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #ifndef SHARE_VM_OOPS_TYPEARRAYOOP_HPP
stefank@1879 26 #define SHARE_VM_OOPS_TYPEARRAYOOP_HPP
stefank@1879 27
stefank@1879 28 #include "oops/arrayOop.hpp"
stefank@1879 29 #include "oops/typeArrayKlass.hpp"
stefank@1879 30 #ifdef TARGET_OS_ARCH_linux_x86
stefank@1879 31 # include "orderAccess_linux_x86.inline.hpp"
stefank@1879 32 #endif
stefank@1879 33 #ifdef TARGET_OS_ARCH_linux_sparc
stefank@1879 34 # include "orderAccess_linux_sparc.inline.hpp"
stefank@1879 35 #endif
stefank@1879 36 #ifdef TARGET_OS_ARCH_linux_zero
stefank@1879 37 # include "orderAccess_linux_zero.inline.hpp"
stefank@1879 38 #endif
stefank@1879 39 #ifdef TARGET_OS_ARCH_solaris_x86
stefank@1879 40 # include "orderAccess_solaris_x86.inline.hpp"
stefank@1879 41 #endif
stefank@1879 42 #ifdef TARGET_OS_ARCH_solaris_sparc
stefank@1879 43 # include "orderAccess_solaris_sparc.inline.hpp"
stefank@1879 44 #endif
stefank@1879 45 #ifdef TARGET_OS_ARCH_windows_x86
stefank@1879 46 # include "orderAccess_windows_x86.inline.hpp"
stefank@1879 47 #endif
bobv@2073 48 #ifdef TARGET_OS_ARCH_linux_arm
bobv@2073 49 # include "orderAccess_linux_arm.inline.hpp"
bobv@2073 50 #endif
bobv@2073 51 #ifdef TARGET_OS_ARCH_linux_ppc
bobv@2073 52 # include "orderAccess_linux_ppc.inline.hpp"
bobv@2073 53 #endif
never@2721 54 #ifdef TARGET_OS_ARCH_bsd_x86
never@2721 55 # include "orderAccess_bsd_x86.inline.hpp"
never@2721 56 #endif
never@2721 57 #ifdef TARGET_OS_ARCH_bsd_zero
never@2721 58 # include "orderAccess_bsd_zero.inline.hpp"
never@2721 59 #endif
stefank@1879 60
duke@0 61 // A typeArrayOop is an array containing basic types (non oop elements).
duke@0 62 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
duke@0 63 #include <limits.h>
duke@0 64
duke@0 65 class typeArrayOopDesc : public arrayOopDesc {
duke@0 66 protected:
duke@0 67 jchar* char_base() const { return (jchar*) base(T_CHAR); }
duke@0 68 jboolean* bool_base() const { return (jboolean*)base(T_BOOLEAN); }
duke@0 69 jbyte* byte_base() const { return (jbyte*) base(T_BYTE); }
duke@0 70 jint* int_base() const { return (jint*) base(T_INT); }
duke@0 71 jlong* long_base() const { return (jlong*) base(T_LONG); }
duke@0 72 jshort* short_base() const { return (jshort*) base(T_SHORT); }
duke@0 73 jfloat* float_base() const { return (jfloat*) base(T_FLOAT); }
duke@0 74 jdouble* double_base() const { return (jdouble*) base(T_DOUBLE); }
duke@0 75
coleenp@3707 76 friend class TypeArrayKlass;
duke@0 77
duke@0 78 public:
duke@0 79 jbyte* byte_at_addr(int which) const {
duke@0 80 assert(is_within_bounds(which), "index out of bounds");
duke@0 81 return &byte_base()[which];
duke@0 82 }
duke@0 83
duke@0 84 jboolean* bool_at_addr(int which) const {
duke@0 85 assert(is_within_bounds(which), "index out of bounds");
duke@0 86 return &bool_base()[which];
duke@0 87 }
duke@0 88
duke@0 89 jchar* char_at_addr(int which) const {
duke@0 90 assert(is_within_bounds(which), "index out of bounds");
duke@0 91 return &char_base()[which];
duke@0 92 }
duke@0 93
duke@0 94 jint* int_at_addr(int which) const {
duke@0 95 assert(is_within_bounds(which), "index out of bounds");
duke@0 96 return &int_base()[which];
duke@0 97 }
duke@0 98
duke@0 99 jshort* short_at_addr(int which) const {
duke@0 100 assert(is_within_bounds(which), "index out of bounds");
duke@0 101 return &short_base()[which];
duke@0 102 }
duke@0 103
duke@0 104 jushort* ushort_at_addr(int which) const { // for field descriptor arrays
duke@0 105 assert(is_within_bounds(which), "index out of bounds");
duke@0 106 return (jushort*) &short_base()[which];
duke@0 107 }
duke@0 108
duke@0 109 jlong* long_at_addr(int which) const {
duke@0 110 assert(is_within_bounds(which), "index out of bounds");
duke@0 111 return &long_base()[which];
duke@0 112 }
duke@0 113
duke@0 114 jfloat* float_at_addr(int which) const {
duke@0 115 assert(is_within_bounds(which), "index out of bounds");
duke@0 116 return &float_base()[which];
duke@0 117 }
duke@0 118
duke@0 119 jdouble* double_at_addr(int which) const {
duke@0 120 assert(is_within_bounds(which), "index out of bounds");
duke@0 121 return &double_base()[which];
duke@0 122 }
duke@0 123
duke@0 124 jbyte byte_at(int which) const { return *byte_at_addr(which); }
duke@0 125 void byte_at_put(int which, jbyte contents) { *byte_at_addr(which) = contents; }
duke@0 126
duke@0 127 jboolean bool_at(int which) const { return *bool_at_addr(which); }
duke@0 128 void bool_at_put(int which, jboolean contents) { *bool_at_addr(which) = contents; }
duke@0 129
duke@0 130 jchar char_at(int which) const { return *char_at_addr(which); }
duke@0 131 void char_at_put(int which, jchar contents) { *char_at_addr(which) = contents; }
duke@0 132
duke@0 133 jint int_at(int which) const { return *int_at_addr(which); }
duke@0 134 void int_at_put(int which, jint contents) { *int_at_addr(which) = contents; }
duke@0 135
duke@0 136 jshort short_at(int which) const { return *short_at_addr(which); }
duke@0 137 void short_at_put(int which, jshort contents) { *short_at_addr(which) = contents; }
duke@0 138
duke@0 139 jushort ushort_at(int which) const { return *ushort_at_addr(which); }
duke@0 140 void ushort_at_put(int which, jushort contents) { *ushort_at_addr(which) = contents; }
duke@0 141
duke@0 142 jlong long_at(int which) const { return *long_at_addr(which); }
duke@0 143 void long_at_put(int which, jlong contents) { *long_at_addr(which) = contents; }
duke@0 144
duke@0 145 jfloat float_at(int which) const { return *float_at_addr(which); }
duke@0 146 void float_at_put(int which, jfloat contents) { *float_at_addr(which) = contents; }
duke@0 147
duke@0 148 jdouble double_at(int which) const { return *double_at_addr(which); }
duke@0 149 void double_at_put(int which, jdouble contents) { *double_at_addr(which) = contents; }
duke@0 150
duke@0 151 jbyte byte_at_acquire(int which) const { return OrderAccess::load_acquire(byte_at_addr(which)); }
duke@0 152 void release_byte_at_put(int which, jbyte contents) { OrderAccess::release_store(byte_at_addr(which), contents); }
duke@0 153
coleenp@3602 154 // Java thinks metadata arrays are just arrays of either long or int, since
coleenp@3602 155 // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate
coleenp@3602 156 // casting
coleenp@3602 157 #ifdef _LP64
coleenp@3602 158 Metadata* metadata_at(int which) const {
coleenp@3602 159 return (Metadata*)*long_at_addr(which); }
coleenp@3602 160 void metadata_at_put(int which, Metadata* contents) {
coleenp@3602 161 *long_at_addr(which) = (long)contents;
coleenp@3602 162 }
coleenp@3602 163 #else
coleenp@3602 164 Metadata* metadata_at(int which) const {
coleenp@3602 165 return (Metadata*)*int_at_addr(which); }
coleenp@3602 166 void metadata_at_put(int which, Metadata* contents) {
coleenp@3602 167 *int_at_addr(which) = (int)contents;
coleenp@3602 168 }
coleenp@3602 169 #endif // _LP64
coleenp@3602 170
duke@0 171 // Sizing
duke@0 172
duke@0 173 // Returns the number of words necessary to hold an array of "len"
duke@0 174 // elements each of the given "byte_size".
duke@0 175 private:
duke@0 176 static int object_size(int lh, int length) {
duke@0 177 int instance_header_size = Klass::layout_helper_header_size(lh);
duke@0 178 int element_shift = Klass::layout_helper_log2_element_size(lh);
duke@0 179 DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh));
duke@0 180 assert(length <= arrayOopDesc::max_array_length(etype), "no overflow");
duke@0 181
duke@0 182 julong size_in_bytes = length;
duke@0 183 size_in_bytes <<= element_shift;
duke@0 184 size_in_bytes += instance_header_size;
duke@0 185 julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize);
duke@0 186 assert(size_in_words <= (julong)max_jint, "no overflow");
duke@0 187
duke@0 188 return align_object_size((intptr_t)size_in_words);
duke@0 189 }
duke@0 190
duke@0 191 public:
duke@0 192 int object_size() {
coleenp@3707 193 TypeArrayKlass* tk = TypeArrayKlass::cast(klass());
duke@0 194 return object_size(tk->layout_helper(), length());
duke@0 195 }
duke@0 196 };
stefank@1879 197
stefank@1879 198 #endif // SHARE_VM_OOPS_TYPEARRAYOOP_HPP