src/share/vm/oops/objArrayOop.hpp

changeset 548
ba764ed4b6f2
parent 435
a61af66fc99e
child 631
d1605aabd0a1
child 777
37f87013dfd8
     1.1 --- a/src/share/vm/oops/objArrayOop.hpp	Fri Apr 11 09:56:35 2008 -0400
     1.2 +++ b/src/share/vm/oops/objArrayOop.hpp	Sun Apr 13 17:43:42 2008 -0400
     1.3 @@ -26,20 +26,67 @@
     1.4  // Evaluating "String arg[10]" will create an objArrayOop.
     1.5  
     1.6  class objArrayOopDesc : public arrayOopDesc {
     1.7 +  friend class objArrayKlass;
     1.8 +  friend class Runtime1;
     1.9 +  friend class psPromotionManager;
    1.10 +
    1.11 +  template <class T> T* obj_at_addr(int index) const {
    1.12 +    assert(is_within_bounds(index), "index out of bounds");
    1.13 +    return &((T*)base())[index];
    1.14 +  }
    1.15 +
    1.16   public:
    1.17 +  // base is the address following the header.
    1.18 +  HeapWord* base() const      { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
    1.19 +
    1.20    // Accessing
    1.21 -  oop obj_at(int index) const           { return *obj_at_addr(index);           }
    1.22 -  void obj_at_put(int index, oop value) { oop_store(obj_at_addr(index), value); }
    1.23 -  oop* base() const                     { return (oop*) arrayOopDesc::base(T_OBJECT); }
    1.24 +  oop obj_at(int index) const {
    1.25 +    // With UseCompressedOops decode the narrow oop in the objArray to an
    1.26 +    // uncompressed oop.  Otherwise this is simply a "*" operator.
    1.27 +    if (UseCompressedOops) {
    1.28 +      return load_decode_heap_oop(obj_at_addr<narrowOop>(index));
    1.29 +    } else {
    1.30 +      return load_decode_heap_oop(obj_at_addr<oop>(index));
    1.31 +    }
    1.32 +  }
    1.33  
    1.34 +  void obj_at_put(int index, oop value) {
    1.35 +    if (UseCompressedOops) {
    1.36 +      oop_store(obj_at_addr<narrowOop>(index), value);
    1.37 +    } else {
    1.38 +      oop_store(obj_at_addr<oop>(index), value);
    1.39 +    }
    1.40 +  }
    1.41    // Sizing
    1.42 -  static int header_size()              { return arrayOopDesc::header_size(T_OBJECT); }
    1.43 -  static int object_size(int length)    { return align_object_size(header_size() + length); }
    1.44 -  int object_size()                     { return object_size(length()); }
    1.45 +  static int header_size()    { return arrayOopDesc::header_size(T_OBJECT); }
    1.46 +  int object_size()           { return object_size(length()); }
    1.47 +  int array_size()            { return array_size(length()); }
    1.48  
    1.49 -  // Returns the address of the index'th element
    1.50 -  oop* obj_at_addr(int index) const {
    1.51 -    assert(is_within_bounds(index), "index out of bounds");
    1.52 -    return &base()[index];
    1.53 +  static int object_size(int length) {
    1.54 +    // This returns the object size in HeapWords.
    1.55 +    return align_object_size(header_size() + array_size(length));
    1.56    }
    1.57 +
    1.58 +  // Give size of objArrayOop in HeapWords minus the header
    1.59 +  static int array_size(int length) {
    1.60 +    // Without UseCompressedOops, this is simply:
    1.61 +    // oop->length() * HeapWordsPerOop;
    1.62 +    // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
    1.63 +    // The oop elements are aligned up to wordSize
    1.64 +    const int HeapWordsPerOop = heapOopSize/HeapWordSize;
    1.65 +    if (HeapWordsPerOop > 0) {
    1.66 +      return length * HeapWordsPerOop;
    1.67 +    } else {
    1.68 +      const int OopsPerHeapWord = HeapWordSize/heapOopSize;
    1.69 +      int word_len = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
    1.70 +      return word_len;
    1.71 +    }
    1.72 +  }
    1.73 +
    1.74 +  // special iterators for index ranges, returns size of object
    1.75 +#define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix)     \
    1.76 +  int oop_iterate_range(OopClosureType* blk, int start, int end);
    1.77 +
    1.78 +  ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
    1.79 +  ALL_OOP_OOP_ITERATE_CLOSURES_3(ObjArrayOop_OOP_ITERATE_DECL)
    1.80  };

mercurial