Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/oops/objArrayOop.hpp
48693 views
/*1* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_OOPS_OBJARRAYOOP_HPP25#define SHARE_VM_OOPS_OBJARRAYOOP_HPP2627#include "oops/arrayOop.hpp"2829// An objArrayOop is an array containing oops.30// Evaluating "String arg[10]" will create an objArrayOop.3132class objArrayOopDesc : public arrayOopDesc {33friend class ObjArrayKlass;34friend class Runtime1;35friend class psPromotionManager;36friend class CSetMarkOopClosure;37friend class G1ParScanPartialArrayClosure;3839template <class T> T* obj_at_addr(int index) const {40assert(is_within_bounds(index), "index out of bounds");41return &((T*)base())[index];42}4344private:45// Give size of objArrayOop in HeapWords minus the header46static int array_size(int length) {47const uint OopsPerHeapWord = HeapWordSize/heapOopSize;48assert(OopsPerHeapWord >= 1 && (HeapWordSize % heapOopSize == 0),49"Else the following (new) computation would be in error");50uint res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;51#ifdef ASSERT52// The old code is left in for sanity-checking; it'll53// go away pretty soon. XXX54// Without UseCompressedOops, this is simply:55// oop->length() * HeapWordsPerOop;56// With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.57// The oop elements are aligned up to wordSize58const uint HeapWordsPerOop = heapOopSize/HeapWordSize;59uint old_res;60if (HeapWordsPerOop > 0) {61old_res = length * HeapWordsPerOop;62} else {63old_res = align_size_up((uint)length, OopsPerHeapWord)/OopsPerHeapWord;64}65assert(res == old_res, "Inconsistency between old and new.");66#endif // ASSERT67return res;68}6970public:71// Returns the offset of the first element.72static int base_offset_in_bytes() {73return arrayOopDesc::base_offset_in_bytes(T_OBJECT);74}7576// base is the address following the header.77HeapWord* base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }7879// Accessing80oop obj_at(int index) const {81// With UseCompressedOops decode the narrow oop in the objArray to an82// uncompressed oop. Otherwise this is simply a "*" operator.83if (UseCompressedOops) {84return load_decode_heap_oop(obj_at_addr<narrowOop>(index));85} else {86return load_decode_heap_oop(obj_at_addr<oop>(index));87}88}8990void obj_at_put(int index, oop value) {91if (UseCompressedOops) {92oop_store(obj_at_addr<narrowOop>(index), value);93} else {94oop_store(obj_at_addr<oop>(index), value);95}96}97// Sizing98static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }99int object_size() { return object_size(length()); }100101static int object_size(int length) {102// This returns the object size in HeapWords.103uint asz = array_size(length);104uint osz = align_object_size(header_size() + asz);105assert(osz >= asz, "no overflow");106assert((int)osz > 0, "no overflow");107return (int)osz;108}109110// special iterators for index ranges, returns size of object111#define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \112int oop_iterate_range(OopClosureType* blk, int start, int end);113114ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)115ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)116};117118#endif // SHARE_VM_OOPS_OBJARRAYOOP_HPP119120121