src/share/vm/oops/objArrayOop.hpp

Tue, 24 Jun 2008 16:00:14 -0700

author
never
date
Tue, 24 Jun 2008 16:00:14 -0700
changeset 657
2a1a77d3458f
parent 548
ba764ed4b6f2
child 631
d1605aabd0a1
child 777
37f87013dfd8
permissions
-rw-r--r--

6718676: putback for 6604014 is incomplete
Reviewed-by: kvn, jrose

duke@435 1 /*
duke@435 2 * Copyright 1997-2003 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // An objArrayOop is an array containing oops.
duke@435 26 // Evaluating "String arg[10]" will create an objArrayOop.
duke@435 27
duke@435 28 class objArrayOopDesc : public arrayOopDesc {
coleenp@548 29 friend class objArrayKlass;
coleenp@548 30 friend class Runtime1;
coleenp@548 31 friend class psPromotionManager;
coleenp@548 32
coleenp@548 33 template <class T> T* obj_at_addr(int index) const {
coleenp@548 34 assert(is_within_bounds(index), "index out of bounds");
coleenp@548 35 return &((T*)base())[index];
coleenp@548 36 }
coleenp@548 37
duke@435 38 public:
coleenp@548 39 // base is the address following the header.
coleenp@548 40 HeapWord* base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
coleenp@548 41
duke@435 42 // Accessing
coleenp@548 43 oop obj_at(int index) const {
coleenp@548 44 // With UseCompressedOops decode the narrow oop in the objArray to an
coleenp@548 45 // uncompressed oop. Otherwise this is simply a "*" operator.
coleenp@548 46 if (UseCompressedOops) {
coleenp@548 47 return load_decode_heap_oop(obj_at_addr<narrowOop>(index));
coleenp@548 48 } else {
coleenp@548 49 return load_decode_heap_oop(obj_at_addr<oop>(index));
coleenp@548 50 }
coleenp@548 51 }
duke@435 52
coleenp@548 53 void obj_at_put(int index, oop value) {
coleenp@548 54 if (UseCompressedOops) {
coleenp@548 55 oop_store(obj_at_addr<narrowOop>(index), value);
coleenp@548 56 } else {
coleenp@548 57 oop_store(obj_at_addr<oop>(index), value);
coleenp@548 58 }
coleenp@548 59 }
duke@435 60 // Sizing
coleenp@548 61 static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }
coleenp@548 62 int object_size() { return object_size(length()); }
coleenp@548 63 int array_size() { return array_size(length()); }
duke@435 64
coleenp@548 65 static int object_size(int length) {
coleenp@548 66 // This returns the object size in HeapWords.
coleenp@548 67 return align_object_size(header_size() + array_size(length));
duke@435 68 }
coleenp@548 69
coleenp@548 70 // Give size of objArrayOop in HeapWords minus the header
coleenp@548 71 static int array_size(int length) {
coleenp@548 72 // Without UseCompressedOops, this is simply:
coleenp@548 73 // oop->length() * HeapWordsPerOop;
coleenp@548 74 // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
coleenp@548 75 // The oop elements are aligned up to wordSize
coleenp@548 76 const int HeapWordsPerOop = heapOopSize/HeapWordSize;
coleenp@548 77 if (HeapWordsPerOop > 0) {
coleenp@548 78 return length * HeapWordsPerOop;
coleenp@548 79 } else {
coleenp@548 80 const int OopsPerHeapWord = HeapWordSize/heapOopSize;
coleenp@548 81 int word_len = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
coleenp@548 82 return word_len;
coleenp@548 83 }
coleenp@548 84 }
coleenp@548 85
coleenp@548 86 // special iterators for index ranges, returns size of object
coleenp@548 87 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
coleenp@548 88 int oop_iterate_range(OopClosureType* blk, int start, int end);
coleenp@548 89
coleenp@548 90 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
coleenp@548 91 ALL_OOP_OOP_ITERATE_CLOSURES_3(ObjArrayOop_OOP_ITERATE_DECL)
duke@435 92 };

mercurial