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