src/share/vm/oops/objArrayOop.hpp

Wed, 02 Feb 2011 11:35:26 -0500

author
bobv
date
Wed, 02 Feb 2011 11:35:26 -0500
changeset 2508
b92c45f2bc75
parent 2314
f95d63e2154a
child 3296
dc467e8b2c5e
permissions
-rw-r--r--

7016023: Enable building ARM and PPC from src/closed repository
Reviewed-by: dholmes, bdelsart

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_OOPS_OBJARRAYOOP_HPP
stefank@2314 26 #define SHARE_VM_OOPS_OBJARRAYOOP_HPP
stefank@2314 27
stefank@2314 28 #include "oops/arrayOop.hpp"
stefank@2314 29
duke@435 30 // An objArrayOop is an array containing oops.
duke@435 31 // Evaluating "String arg[10]" will create an objArrayOop.
duke@435 32
duke@435 33 class objArrayOopDesc : public arrayOopDesc {
coleenp@548 34 friend class objArrayKlass;
coleenp@548 35 friend class Runtime1;
coleenp@548 36 friend class psPromotionManager;
ysr@777 37 friend class CSMarkOopClosure;
ysr@777 38 friend class G1ParScanPartialArrayClosure;
coleenp@548 39
coleenp@548 40 template <class T> T* obj_at_addr(int index) const {
coleenp@548 41 assert(is_within_bounds(index), "index out of bounds");
coleenp@548 42 return &((T*)base())[index];
coleenp@548 43 }
coleenp@548 44
ysr@1526 45 private:
ysr@1526 46 // Give size of objArrayOop in HeapWords minus the header
ysr@1526 47 static int array_size(int length) {
ysr@1526 48 const int OopsPerHeapWord = HeapWordSize/heapOopSize;
ysr@1526 49 assert(OopsPerHeapWord >= 1 && (HeapWordSize % heapOopSize == 0),
ysr@1526 50 "Else the following (new) computation would be in error");
ysr@1526 51 #ifdef ASSERT
ysr@1526 52 // The old code is left in for sanity-checking; it'll
ysr@1526 53 // go away pretty soon. XXX
ysr@1526 54 // Without UseCompressedOops, this is simply:
ysr@1526 55 // oop->length() * HeapWordsPerOop;
ysr@1526 56 // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
ysr@1526 57 // The oop elements are aligned up to wordSize
ysr@1526 58 const int HeapWordsPerOop = heapOopSize/HeapWordSize;
ysr@1526 59 int old_res;
ysr@1526 60 if (HeapWordsPerOop > 0) {
ysr@1526 61 old_res = length * HeapWordsPerOop;
ysr@1526 62 } else {
ysr@1526 63 old_res = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
ysr@1526 64 }
ysr@1526 65 #endif // ASSERT
ysr@1530 66 int res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;
ysr@1526 67 assert(res == old_res, "Inconsistency between old and new.");
ysr@1526 68 return res;
ysr@1526 69 }
ysr@1526 70
duke@435 71 public:
twisti@1330 72 // Returns the offset of the first element.
twisti@1330 73 static int base_offset_in_bytes() {
twisti@1330 74 return arrayOopDesc::base_offset_in_bytes(T_OBJECT);
twisti@1330 75 }
twisti@1330 76
coleenp@548 77 // base is the address following the header.
coleenp@548 78 HeapWord* base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
coleenp@548 79
duke@435 80 // Accessing
coleenp@548 81 oop obj_at(int index) const {
coleenp@548 82 // With UseCompressedOops decode the narrow oop in the objArray to an
coleenp@548 83 // uncompressed oop. Otherwise this is simply a "*" operator.
coleenp@548 84 if (UseCompressedOops) {
coleenp@548 85 return load_decode_heap_oop(obj_at_addr<narrowOop>(index));
coleenp@548 86 } else {
coleenp@548 87 return load_decode_heap_oop(obj_at_addr<oop>(index));
coleenp@548 88 }
coleenp@548 89 }
duke@435 90
coleenp@548 91 void obj_at_put(int index, oop value) {
coleenp@548 92 if (UseCompressedOops) {
coleenp@548 93 oop_store(obj_at_addr<narrowOop>(index), value);
coleenp@548 94 } else {
coleenp@548 95 oop_store(obj_at_addr<oop>(index), value);
coleenp@548 96 }
coleenp@548 97 }
duke@435 98 // Sizing
coleenp@548 99 static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }
coleenp@548 100 int object_size() { return object_size(length()); }
duke@435 101
coleenp@548 102 static int object_size(int length) {
coleenp@548 103 // This returns the object size in HeapWords.
ysr@1530 104 uint asz = array_size(length);
ysr@1530 105 uint osz = align_object_size(header_size() + asz);
ysr@1530 106 assert(osz >= asz, "no overflow");
ysr@1530 107 assert((int)osz > 0, "no overflow");
ysr@1530 108 return (int)osz;
duke@435 109 }
coleenp@548 110
coleenp@548 111 // special iterators for index ranges, returns size of object
coleenp@548 112 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
coleenp@548 113 int oop_iterate_range(OopClosureType* blk, int start, int end);
coleenp@548 114
coleenp@548 115 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
ysr@777 116 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)
duke@435 117 };
stefank@2314 118
stefank@2314 119 #endif // SHARE_VM_OOPS_OBJARRAYOOP_HPP

mercurial