1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)objArrayKlass.hpp    1.87 07/05/29 09:44:23 JVM"
   3 #endif
   4 /*
   5  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 // objArrayKlass is the klass for objArrays
  29 
  30 class objArrayKlass : public arrayKlass {
  31   friend class VMStructs;
  32  private:
  33   klassOop _element_klass;            // The klass of the elements of this array type
  34   klassOop _bottom_klass;             // The one-dimensional type (instanceKlass or typeArrayKlass)
  35  public:
  36   // Instance variables
  37   klassOop element_klass() const      { return _element_klass; }
  38   void set_element_klass(klassOop k)  { oop_store_without_check((oop*) &_element_klass, (oop) k); }
  39   oop* element_klass_addr()           { return (oop*)&_element_klass; }
  40 
  41   klassOop bottom_klass() const       { return _bottom_klass; }
  42   void set_bottom_klass(klassOop k)   { oop_store_without_check((oop*) &_bottom_klass, (oop) k); }
  43   oop* bottom_klass_addr()            { return (oop*)&_bottom_klass; }
  44 
  45   // Compiler/Interpreter offset
  46   static int element_klass_offset_in_bytes() { return offset_of(objArrayKlass, _element_klass); }
  47 
  48   // Dispatched operation
  49   bool can_be_primary_super_slow() const;
  50   objArrayOop compute_secondary_supers(int num_extra_slots, TRAPS);
  51   bool compute_is_subtype_of(klassOop k);
  52   bool oop_is_objArray_slow()  const  { return true; }
  53   int oop_size(oop obj) const;
  54   int klass_oop_size() const          { return object_size(); }
  55 
  56   // Allocation
  57   DEFINE_ALLOCATE_PERMANENT(objArrayKlass);
  58   objArrayOop allocate(int length, TRAPS);
  59   oop multi_allocate(int rank, jint* sizes, TRAPS);
  60 
  61   // Copying
  62   void  copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
  63 
  64   // Compute protection domain
  65   oop protection_domain() { return Klass::cast(bottom_klass())->protection_domain(); }
  66   // Compute class loader
  67   oop class_loader() const { return Klass::cast(bottom_klass())->class_loader(); }
  68 
  69  private:
  70   // Either oop or narrowOop depending on UseCompressedOops.
  71   // must be called from within objArrayKlass.cpp
  72   template <class T> void do_copy(arrayOop s, T* src, arrayOop d,
  73                                   T* dst, int length, TRAPS);
  74  protected:
  75   // Returns the objArrayKlass for n'th dimension.
  76   virtual klassOop array_klass_impl(bool or_null, int n, TRAPS);
  77 
  78   // Returns the array class with this class as element type.
  79   virtual klassOop array_klass_impl(bool or_null, TRAPS);
  80 
  81  public:
  82   // Casting from klassOop
  83   static objArrayKlass* cast(klassOop k) {
  84     assert(k->klass_part()->oop_is_objArray_slow(), "cast to objArrayKlass");
  85     return (objArrayKlass*) k->klass_part(); 
  86   }
  87 
  88   // Sizing
  89   static int header_size()                { return oopDesc::header_size() + sizeof(objArrayKlass)/HeapWordSize; }
  90   int object_size() const                 { return arrayKlass::object_size(header_size()); }
  91 
  92   // Initialization (virtual from Klass)
  93   void initialize(TRAPS);
  94 
  95   // Garbage collection
  96   void oop_follow_contents(oop obj);
  97   int  oop_adjust_pointers(oop obj);
  98 
  99   // Parallel Scavenge and Parallel Old
 100   PARALLEL_GC_DECLS
 101 
 102   // Iterators
 103   int oop_oop_iterate(oop obj, OopClosure* blk) {
 104     return oop_oop_iterate_v(obj, blk);
 105   }
 106   int oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
 107     return oop_oop_iterate_v_m(obj, blk, mr);
 108   }
 109 #define ObjArrayKlass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix)   \
 110   int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk);         \
 111   int oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* blk,      \
 112                                      MemRegion mr);                     \
 113   int oop_oop_iterate_range##nv_suffix(oop obj, OopClosureType* blk,    \
 114                                      int start, int end);
 115 
 116   ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DECL)
 117   ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DECL)
 118 
 119   // JVM support
 120   jint compute_modifier_flags(TRAPS) const;
 121 
 122  private:
 123    static klassOop array_klass_impl   (objArrayKlassHandle this_oop, bool or_null, int n, TRAPS);
 124 
 125 #ifndef PRODUCT
 126  public:
 127   // Printing
 128   void oop_print_on      (oop obj, outputStream* st);
 129   void oop_print_value_on(oop obj, outputStream* st);
 130 #endif
 131 
 132  public:
 133   // Verification
 134   const char* internal_name() const;
 135   void oop_verify_on(oop obj, outputStream* st);
 136   void oop_verify_old_oop(oop obj, oop* p, bool allow_dirty);
 137   void oop_verify_old_oop(oop obj, narrowOop* p, bool allow_dirty);
 138 
 139 };
 140