duke@435: /* xdono@631: * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // An objArrayOop is an array containing oops. duke@435: // Evaluating "String arg[10]" will create an objArrayOop. duke@435: duke@435: class objArrayOopDesc : public arrayOopDesc { coleenp@548: friend class objArrayKlass; coleenp@548: friend class Runtime1; coleenp@548: friend class psPromotionManager; ysr@777: friend class CSMarkOopClosure; ysr@777: friend class G1ParScanPartialArrayClosure; coleenp@548: coleenp@548: template T* obj_at_addr(int index) const { coleenp@548: assert(is_within_bounds(index), "index out of bounds"); coleenp@548: return &((T*)base())[index]; coleenp@548: } coleenp@548: duke@435: public: twisti@1330: // Returns the offset of the first element. twisti@1330: static int base_offset_in_bytes() { twisti@1330: return arrayOopDesc::base_offset_in_bytes(T_OBJECT); twisti@1330: } twisti@1330: coleenp@548: // base is the address following the header. coleenp@548: HeapWord* base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); } coleenp@548: duke@435: // Accessing coleenp@548: oop obj_at(int index) const { coleenp@548: // With UseCompressedOops decode the narrow oop in the objArray to an coleenp@548: // uncompressed oop. Otherwise this is simply a "*" operator. coleenp@548: if (UseCompressedOops) { coleenp@548: return load_decode_heap_oop(obj_at_addr(index)); coleenp@548: } else { coleenp@548: return load_decode_heap_oop(obj_at_addr(index)); coleenp@548: } coleenp@548: } duke@435: coleenp@548: void obj_at_put(int index, oop value) { coleenp@548: if (UseCompressedOops) { coleenp@548: oop_store(obj_at_addr(index), value); coleenp@548: } else { coleenp@548: oop_store(obj_at_addr(index), value); coleenp@548: } coleenp@548: } duke@435: // Sizing coleenp@548: static int header_size() { return arrayOopDesc::header_size(T_OBJECT); } coleenp@548: int object_size() { return object_size(length()); } coleenp@548: int array_size() { return array_size(length()); } duke@435: coleenp@548: static int object_size(int length) { coleenp@548: // This returns the object size in HeapWords. coleenp@548: return align_object_size(header_size() + array_size(length)); duke@435: } coleenp@548: coleenp@548: // Give size of objArrayOop in HeapWords minus the header coleenp@548: static int array_size(int length) { coleenp@548: // Without UseCompressedOops, this is simply: coleenp@548: // oop->length() * HeapWordsPerOop; coleenp@548: // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer. coleenp@548: // The oop elements are aligned up to wordSize coleenp@548: const int HeapWordsPerOop = heapOopSize/HeapWordSize; coleenp@548: if (HeapWordsPerOop > 0) { coleenp@548: return length * HeapWordsPerOop; coleenp@548: } else { coleenp@548: const int OopsPerHeapWord = HeapWordSize/heapOopSize; coleenp@548: int word_len = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord; coleenp@548: return word_len; coleenp@548: } coleenp@548: } coleenp@548: coleenp@548: // special iterators for index ranges, returns size of object coleenp@548: #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ coleenp@548: int oop_iterate_range(OopClosureType* blk, int start, int end); coleenp@548: coleenp@548: ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL) ysr@777: ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL) duke@435: };