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