src/share/vm/oops/objArrayOop.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OOPS_OBJARRAYOOP_HPP
aoqi@0 26 #define SHARE_VM_OOPS_OBJARRAYOOP_HPP
aoqi@0 27
aoqi@0 28 #include "oops/arrayOop.hpp"
aoqi@0 29
aoqi@0 30 // An objArrayOop is an array containing oops.
aoqi@0 31 // Evaluating "String arg[10]" will create an objArrayOop.
aoqi@0 32
aoqi@0 33 class objArrayOopDesc : public arrayOopDesc {
aoqi@0 34 friend class ObjArrayKlass;
aoqi@0 35 friend class Runtime1;
aoqi@0 36 friend class psPromotionManager;
aoqi@0 37 friend class CSetMarkOopClosure;
aoqi@0 38 friend class G1ParScanPartialArrayClosure;
aoqi@0 39
aoqi@0 40 template <class T> T* obj_at_addr(int index) const {
aoqi@0 41 assert(is_within_bounds(index), "index out of bounds");
aoqi@0 42 return &((T*)base())[index];
aoqi@0 43 }
aoqi@0 44
aoqi@0 45 private:
aoqi@0 46 // Give size of objArrayOop in HeapWords minus the header
aoqi@0 47 static int array_size(int length) {
aoqi@0 48 const int OopsPerHeapWord = HeapWordSize/heapOopSize;
aoqi@0 49 assert(OopsPerHeapWord >= 1 && (HeapWordSize % heapOopSize == 0),
aoqi@0 50 "Else the following (new) computation would be in error");
aoqi@0 51 #ifdef ASSERT
aoqi@0 52 // The old code is left in for sanity-checking; it'll
aoqi@0 53 // go away pretty soon. XXX
aoqi@0 54 // Without UseCompressedOops, this is simply:
aoqi@0 55 // oop->length() * HeapWordsPerOop;
aoqi@0 56 // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
aoqi@0 57 // The oop elements are aligned up to wordSize
aoqi@0 58 const int HeapWordsPerOop = heapOopSize/HeapWordSize;
aoqi@0 59 int old_res;
aoqi@0 60 if (HeapWordsPerOop > 0) {
aoqi@0 61 old_res = length * HeapWordsPerOop;
aoqi@0 62 } else {
aoqi@0 63 old_res = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
aoqi@0 64 }
aoqi@0 65 #endif // ASSERT
aoqi@0 66 int res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;
aoqi@0 67 assert(res == old_res, "Inconsistency between old and new.");
aoqi@0 68 return res;
aoqi@0 69 }
aoqi@0 70
aoqi@0 71 public:
aoqi@0 72 // Returns the offset of the first element.
aoqi@0 73 static int base_offset_in_bytes() {
aoqi@0 74 return arrayOopDesc::base_offset_in_bytes(T_OBJECT);
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 // base is the address following the header.
aoqi@0 78 HeapWord* base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
aoqi@0 79
aoqi@0 80 // Accessing
aoqi@0 81 oop obj_at(int index) const {
aoqi@0 82 // With UseCompressedOops decode the narrow oop in the objArray to an
aoqi@0 83 // uncompressed oop. Otherwise this is simply a "*" operator.
aoqi@0 84 if (UseCompressedOops) {
aoqi@0 85 return load_decode_heap_oop(obj_at_addr<narrowOop>(index));
aoqi@0 86 } else {
aoqi@0 87 return load_decode_heap_oop(obj_at_addr<oop>(index));
aoqi@0 88 }
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 void obj_at_put(int index, oop value) {
aoqi@0 92 if (UseCompressedOops) {
aoqi@0 93 oop_store(obj_at_addr<narrowOop>(index), value);
aoqi@0 94 } else {
aoqi@0 95 oop_store(obj_at_addr<oop>(index), value);
aoqi@0 96 }
aoqi@0 97 }
aoqi@0 98 // Sizing
aoqi@0 99 static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }
aoqi@0 100 int object_size() { return object_size(length()); }
aoqi@0 101
aoqi@0 102 static int object_size(int length) {
aoqi@0 103 // This returns the object size in HeapWords.
aoqi@0 104 uint asz = array_size(length);
aoqi@0 105 uint osz = align_object_size(header_size() + asz);
aoqi@0 106 assert(osz >= asz, "no overflow");
aoqi@0 107 assert((int)osz > 0, "no overflow");
aoqi@0 108 return (int)osz;
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 // special iterators for index ranges, returns size of object
aoqi@0 112 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
aoqi@0 113 int oop_iterate_range(OopClosureType* blk, int start, int end);
aoqi@0 114
aoqi@0 115 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
aoqi@0 116 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)
aoqi@0 117 };
aoqi@0 118
aoqi@0 119 #endif // SHARE_VM_OOPS_OBJARRAYOOP_HPP

mercurial