Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/oops/objArrayOop.hpp
32285 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 "memory/barrierSet.hpp"28#include "oops/arrayOop.hpp"2930#if INCLUDE_ALL_GCS31#include "gc_implementation/shenandoah/shenandoahBarrierSet.hpp"32#endif3334// An objArrayOop is an array containing oops.35// Evaluating "String arg[10]" will create an objArrayOop.3637class objArrayOopDesc : public arrayOopDesc {38friend class ObjArrayKlass;39friend class Runtime1;40friend class psPromotionManager;41friend class CSetMarkOopClosure;42friend class G1ParScanPartialArrayClosure;4344template <class T> T* obj_at_addr(int index) const {45assert(is_within_bounds(index), "index out of bounds");46return &((T*)base())[index];47}4849private:50// Give size of objArrayOop in HeapWords minus the header51static int array_size(int length) {52const uint OopsPerHeapWord = HeapWordSize/heapOopSize;53assert(OopsPerHeapWord >= 1 && (HeapWordSize % heapOopSize == 0),54"Else the following (new) computation would be in error");55uint res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;56#ifdef ASSERT57// The old code is left in for sanity-checking; it'll58// go away pretty soon. XXX59// Without UseCompressedOops, this is simply:60// oop->length() * HeapWordsPerOop;61// With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.62// The oop elements are aligned up to wordSize63const uint HeapWordsPerOop = heapOopSize/HeapWordSize;64uint old_res;65if (HeapWordsPerOop > 0) {66old_res = length * HeapWordsPerOop;67} else {68old_res = align_size_up((uint)length, OopsPerHeapWord)/OopsPerHeapWord;69}70assert(res == old_res, "Inconsistency between old and new.");71#endif // ASSERT72return res;73}7475public:76// Returns the offset of the first element.77static int base_offset_in_bytes() {78return arrayOopDesc::base_offset_in_bytes(T_OBJECT);79}8081// base is the address following the header.82HeapWord* base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }8384// Accessing85oop obj_at(int index) const {86oop obj;87// With UseCompressedOops decode the narrow oop in the objArray to an88// uncompressed oop. Otherwise this is simply a "*" operator.89if (UseCompressedOops) {90obj = load_decode_heap_oop(obj_at_addr<narrowOop>(index));91} else {92obj = load_decode_heap_oop(obj_at_addr<oop>(index));93}94#if INCLUDE_ALL_GCS95if (UseShenandoahGC) {96obj = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(obj);97}98#endif99return obj;100}101102void obj_at_put(int index, oop value) {103if (UseCompressedOops) {104oop_store(obj_at_addr<narrowOop>(index), value);105} else {106oop_store(obj_at_addr<oop>(index), value);107}108}109// Sizing110static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }111int object_size() { return object_size(length()); }112113static int object_size(int length) {114// This returns the object size in HeapWords.115uint asz = array_size(length);116uint osz = align_object_size(header_size() + asz);117assert(osz >= asz, "no overflow");118assert((int)osz > 0, "no overflow");119return (int)osz;120}121122// special iterators for index ranges, returns size of object123#define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \124int oop_iterate_range(OopClosureType* blk, int start, int end);125126ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)127ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)128};129130#endif // SHARE_VM_OOPS_OBJARRAYOOP_HPP131132133