objArrayOop.hpp revision 1472
0N/A/*
1472N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. 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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * 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;
342N/A friend class CSMarkOopClosure;
342N/A friend class G1ParScanPartialArrayClosure;
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
1091N/Aprivate:
1091N/A // Give size of objArrayOop in HeapWords minus the header
1091N/A static int array_size(int length) {
1091N/A const int OopsPerHeapWord = HeapWordSize/heapOopSize;
1091N/A assert(OopsPerHeapWord >= 1 && (HeapWordSize % heapOopSize == 0),
1091N/A "Else the following (new) computation would be in error");
1091N/A#ifdef ASSERT
1091N/A // The old code is left in for sanity-checking; it'll
1091N/A // go away pretty soon. XXX
1091N/A // Without UseCompressedOops, this is simply:
1091N/A // oop->length() * HeapWordsPerOop;
1091N/A // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
1091N/A // The oop elements are aligned up to wordSize
1091N/A const int HeapWordsPerOop = heapOopSize/HeapWordSize;
1091N/A int old_res;
1091N/A if (HeapWordsPerOop > 0) {
1091N/A old_res = length * HeapWordsPerOop;
1091N/A } else {
1091N/A old_res = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
1091N/A }
1091N/A#endif // ASSERT
1095N/A int res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;
1091N/A assert(res == old_res, "Inconsistency between old and new.");
1091N/A return res;
1091N/A }
1091N/A
0N/A public:
895N/A // Returns the offset of the first element.
895N/A static int base_offset_in_bytes() {
895N/A return arrayOopDesc::base_offset_in_bytes(T_OBJECT);
895N/A }
895N/A
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
113N/A static int object_size(int length) {
113N/A // This returns the object size in HeapWords.
1095N/A uint asz = array_size(length);
1095N/A uint osz = align_object_size(header_size() + asz);
1095N/A assert(osz >= asz, "no overflow");
1095N/A assert((int)osz > 0, "no overflow");
1095N/A return (int)osz;
113N/A }
0N/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)
342N/A ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)
0N/A};