src/share/vm/oops/objArrayOop.hpp

Mon, 20 Jul 2009 08:20:00 -0700

author
twisti
date
Mon, 20 Jul 2009 08:20:00 -0700
changeset 1330
94b6d06fd759
parent 791
1ee8caae33af
child 1383
89e0543e1737
permissions
-rw-r--r--

6860920: serialize.cpp shouldn't use objArrayOopDesc::base_offset_in_bytes(T_BYTE)
Summary: serialize.cpp currently uses objArrayOopDesc::base_offset_in_bytes(T_BYTE), which seems to be wrong.
Reviewed-by: coleenp, kvn

     1 /*
     2  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // An objArrayOop is an array containing oops.
    26 // Evaluating "String arg[10]" will create an objArrayOop.
    28 class objArrayOopDesc : public arrayOopDesc {
    29   friend class objArrayKlass;
    30   friend class Runtime1;
    31   friend class psPromotionManager;
    32   friend class CSMarkOopClosure;
    33   friend class G1ParScanPartialArrayClosure;
    35   template <class T> T* obj_at_addr(int index) const {
    36     assert(is_within_bounds(index), "index out of bounds");
    37     return &((T*)base())[index];
    38   }
    40  public:
    41   // Returns the offset of the first element.
    42   static int base_offset_in_bytes() {
    43     return arrayOopDesc::base_offset_in_bytes(T_OBJECT);
    44   }
    46   // base is the address following the header.
    47   HeapWord* base() const      { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
    49   // Accessing
    50   oop obj_at(int index) const {
    51     // With UseCompressedOops decode the narrow oop in the objArray to an
    52     // uncompressed oop.  Otherwise this is simply a "*" operator.
    53     if (UseCompressedOops) {
    54       return load_decode_heap_oop(obj_at_addr<narrowOop>(index));
    55     } else {
    56       return load_decode_heap_oop(obj_at_addr<oop>(index));
    57     }
    58   }
    60   void obj_at_put(int index, oop value) {
    61     if (UseCompressedOops) {
    62       oop_store(obj_at_addr<narrowOop>(index), value);
    63     } else {
    64       oop_store(obj_at_addr<oop>(index), value);
    65     }
    66   }
    67   // Sizing
    68   static int header_size()    { return arrayOopDesc::header_size(T_OBJECT); }
    69   int object_size()           { return object_size(length()); }
    70   int array_size()            { return array_size(length()); }
    72   static int object_size(int length) {
    73     // This returns the object size in HeapWords.
    74     return align_object_size(header_size() + array_size(length));
    75   }
    77   // Give size of objArrayOop in HeapWords minus the header
    78   static int array_size(int length) {
    79     // Without UseCompressedOops, this is simply:
    80     // oop->length() * HeapWordsPerOop;
    81     // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
    82     // The oop elements are aligned up to wordSize
    83     const int HeapWordsPerOop = heapOopSize/HeapWordSize;
    84     if (HeapWordsPerOop > 0) {
    85       return length * HeapWordsPerOop;
    86     } else {
    87       const int OopsPerHeapWord = HeapWordSize/heapOopSize;
    88       int word_len = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
    89       return word_len;
    90     }
    91   }
    93   // special iterators for index ranges, returns size of object
    94 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix)     \
    95   int oop_iterate_range(OopClosureType* blk, int start, int end);
    97   ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
    98   ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)
    99 };

mercurial