src/share/vm/oops/objArrayOop.hpp

Thu, 05 Jun 2008 15:57:56 -0700

author
ysr
date
Thu, 05 Jun 2008 15:57:56 -0700
changeset 777
37f87013dfd8
parent 548
ba764ed4b6f2
child 791
1ee8caae33af
permissions
-rw-r--r--

6711316: Open source the Garbage-First garbage collector
Summary: First mercurial integration of the code for the Garbage-First garbage collector.
Reviewed-by: apetrusenko, iveresov, jmasa, sgoldman, tonyp, ysr

     1 /*
     2  * Copyright 1997-2003 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   // base is the address following the header.
    42   HeapWord* base() const      { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
    44   // Accessing
    45   oop obj_at(int index) const {
    46     // With UseCompressedOops decode the narrow oop in the objArray to an
    47     // uncompressed oop.  Otherwise this is simply a "*" operator.
    48     if (UseCompressedOops) {
    49       return load_decode_heap_oop(obj_at_addr<narrowOop>(index));
    50     } else {
    51       return load_decode_heap_oop(obj_at_addr<oop>(index));
    52     }
    53   }
    55   void obj_at_put(int index, oop value) {
    56     if (UseCompressedOops) {
    57       oop_store(obj_at_addr<narrowOop>(index), value);
    58     } else {
    59       oop_store(obj_at_addr<oop>(index), value);
    60     }
    61   }
    62   // Sizing
    63   static int header_size()    { return arrayOopDesc::header_size(T_OBJECT); }
    64   int object_size()           { return object_size(length()); }
    65   int array_size()            { return array_size(length()); }
    67   static int object_size(int length) {
    68     // This returns the object size in HeapWords.
    69     return align_object_size(header_size() + array_size(length));
    70   }
    72   // Give size of objArrayOop in HeapWords minus the header
    73   static int array_size(int length) {
    74     // Without UseCompressedOops, this is simply:
    75     // oop->length() * HeapWordsPerOop;
    76     // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
    77     // The oop elements are aligned up to wordSize
    78     const int HeapWordsPerOop = heapOopSize/HeapWordSize;
    79     if (HeapWordsPerOop > 0) {
    80       return length * HeapWordsPerOop;
    81     } else {
    82       const int OopsPerHeapWord = HeapWordSize/heapOopSize;
    83       int word_len = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
    84       return word_len;
    85     }
    86   }
    88   // special iterators for index ranges, returns size of object
    89 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix)     \
    90   int oop_iterate_range(OopClosureType* blk, int start, int end);
    92   ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
    93   ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)
    94 };

mercurial