annotate src/share/vm/oops/objArrayOop.hpp @ 7745:6dc8db7164d2

Added tag jdk9-b49 for changeset 360cd1fc42f1
author katleman
date Thu, 05 Feb 2015 11:43:29 -0800
parents b188e2fd26d7
children 6a5be7f00868
rev   line source
duke@0 1 /*
coleenp@6620 2 * Copyright (c) 1997, 2014, 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_OBJARRAYOOP_HPP
stefank@1879 26 #define SHARE_VM_OOPS_OBJARRAYOOP_HPP
stefank@1879 27
stefank@1879 28 #include "oops/arrayOop.hpp"
stefank@1879 29
duke@0 30 // An objArrayOop is an array containing oops.
duke@0 31 // Evaluating "String arg[10]" will create an objArrayOop.
duke@0 32
duke@0 33 class objArrayOopDesc : public arrayOopDesc {
coleenp@3707 34 friend class ObjArrayKlass;
coleenp@113 35 friend class Runtime1;
coleenp@113 36 friend class psPromotionManager;
johnc@2861 37 friend class CSetMarkOopClosure;
ysr@342 38 friend class G1ParScanPartialArrayClosure;
coleenp@113 39
coleenp@113 40 template <class T> T* obj_at_addr(int index) const {
coleenp@113 41 assert(is_within_bounds(index), "index out of bounds");
coleenp@113 42 return &((T*)base())[index];
coleenp@113 43 }
coleenp@113 44
ysr@1091 45 private:
ysr@1091 46 // Give size of objArrayOop in HeapWords minus the header
ysr@1091 47 static int array_size(int length) {
morris@7287 48 const uint OopsPerHeapWord = HeapWordSize/heapOopSize;
ysr@1091 49 assert(OopsPerHeapWord >= 1 && (HeapWordSize % heapOopSize == 0),
ysr@1091 50 "Else the following (new) computation would be in error");
morris@7287 51 uint res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;
ysr@1091 52 #ifdef ASSERT
ysr@1091 53 // The old code is left in for sanity-checking; it'll
ysr@1091 54 // go away pretty soon. XXX
ysr@1091 55 // Without UseCompressedOops, this is simply:
ysr@1091 56 // oop->length() * HeapWordsPerOop;
ysr@1091 57 // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
ysr@1091 58 // The oop elements are aligned up to wordSize
morris@7287 59 const uint HeapWordsPerOop = heapOopSize/HeapWordSize;
morris@7287 60 uint old_res;
ysr@1091 61 if (HeapWordsPerOop > 0) {
ysr@1091 62 old_res = length * HeapWordsPerOop;
ysr@1091 63 } else {
morris@7287 64 old_res = align_size_up((uint)length, OopsPerHeapWord)/OopsPerHeapWord;
ysr@1091 65 }
morris@7287 66 assert(res == old_res, "Inconsistency between old and new.");
ysr@1091 67 #endif // ASSERT
ysr@1091 68 return res;
ysr@1091 69 }
ysr@1091 70
duke@0 71 public:
twisti@895 72 // Returns the offset of the first element.
twisti@895 73 static int base_offset_in_bytes() {
twisti@895 74 return arrayOopDesc::base_offset_in_bytes(T_OBJECT);
twisti@895 75 }
twisti@895 76
coleenp@113 77 // base is the address following the header.
coleenp@113 78 HeapWord* base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
coleenp@113 79
duke@0 80 // Accessing
coleenp@113 81 oop obj_at(int index) const {
coleenp@113 82 // With UseCompressedOops decode the narrow oop in the objArray to an
coleenp@113 83 // uncompressed oop. Otherwise this is simply a "*" operator.
coleenp@113 84 if (UseCompressedOops) {
coleenp@113 85 return load_decode_heap_oop(obj_at_addr<narrowOop>(index));
coleenp@113 86 } else {
coleenp@113 87 return load_decode_heap_oop(obj_at_addr<oop>(index));
coleenp@113 88 }
coleenp@113 89 }
duke@0 90
coleenp@113 91 void obj_at_put(int index, oop value) {
coleenp@113 92 if (UseCompressedOops) {
coleenp@113 93 oop_store(obj_at_addr<narrowOop>(index), value);
coleenp@113 94 } else {
coleenp@113 95 oop_store(obj_at_addr<oop>(index), value);
coleenp@113 96 }
coleenp@113 97 }
coleenp@6620 98
coleenp@6620 99 oop atomic_compare_exchange_oop(int index, oop exchange_value, oop compare_value);
coleenp@6620 100
duke@0 101 // Sizing
coleenp@113 102 static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }
coleenp@113 103 int object_size() { return object_size(length()); }
duke@0 104
coleenp@113 105 static int object_size(int length) {
coleenp@113 106 // This returns the object size in HeapWords.
ysr@1095 107 uint asz = array_size(length);
ysr@1095 108 uint osz = align_object_size(header_size() + asz);
ysr@1095 109 assert(osz >= asz, "no overflow");
ysr@1095 110 assert((int)osz > 0, "no overflow");
ysr@1095 111 return (int)osz;
duke@0 112 }
coleenp@113 113
coleenp@113 114 // special iterators for index ranges, returns size of object
coleenp@113 115 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
coleenp@113 116 int oop_iterate_range(OopClosureType* blk, int start, int end);
coleenp@113 117
coleenp@113 118 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
ysr@342 119 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)
duke@0 120 };
stefank@1879 121
stefank@1879 122 #endif // SHARE_VM_OOPS_OBJARRAYOOP_HPP