< prev index next >

src/hotspot/share/oops/objArrayKlass.hpp

Print this page

  1 /*
  2  * Copyright (c) 1997, 2025, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_OOPS_OBJARRAYKLASS_HPP
 26 #define SHARE_OOPS_OBJARRAYKLASS_HPP
 27 
 28 #include "oops/arrayKlass.hpp"
 29 #include "utilities/macros.hpp"
 30 
 31 class ClassLoaderData;
 32 
 33 // ObjArrayKlass is the klass for objArrays
 34 
 35 class ObjArrayKlass : public ArrayKlass {
 36   friend class Deoptimization;
 37   friend class JVMCIVMStructs;
 38   friend class oopFactory;
 39   friend class VMStructs;
 40 
 41  public:
 42   static const KlassKind Kind = ObjArrayKlassKind;
 43 
 44  private:
 45   // If you add a new field that points to any metaspace object, you
 46   // must add this field to ObjArrayKlass::metaspace_pointers_do().
 47   Klass* _element_klass;            // The klass of the elements of this array type
 48   Klass* _bottom_klass;             // The one-dimensional type (InstanceKlass or TypeArrayKlass)

 49 








 50   // Constructor
 51   ObjArrayKlass(int n, Klass* element_klass, Symbol* name);
 52   static ObjArrayKlass* allocate_klass(ClassLoaderData* loader_data, int n, Klass* k, Symbol* name, TRAPS);
 53 
 54   objArrayOop allocate_instance(int length, TRAPS);

 55 
 56  protected:
 57   // Create array_name for element klass
 58   static Symbol* create_element_klass_array_name(JavaThread* current, Klass* element_klass);
 59 
 60  public:
 61   // For dummy objects
 62   ObjArrayKlass() {}
 63 
 64   // Instance variables
 65   Klass* element_klass() const      { return _element_klass; }
 66   void set_element_klass(Klass* k)  { _element_klass = k; }




 67 
 68   // Compiler/Interpreter offset
 69   static ByteSize element_klass_offset() { return byte_offset_of(ObjArrayKlass, _element_klass); }

 70 
 71   Klass* bottom_klass() const       { return _bottom_klass; }
 72   void set_bottom_klass(Klass* k)   { _bottom_klass = k; }
 73   Klass** bottom_klass_addr()       { return &_bottom_klass; }
 74 
 75   ModuleEntry* module() const override;
 76   PackageEntry* package() const override;
 77 
 78   // Dispatched operation
 79   bool can_be_primary_super_slow() const override;
 80   GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
 81                                                   Array<InstanceKlass*>* transitive_interfaces) override;
 82   DEBUG_ONLY(bool is_objArray_klass_slow() const override { return true; })
 83   size_t oop_size(oop obj) const override;
 84 
 85   // Allocation
 86   static ObjArrayKlass* allocate_objArray_klass(ClassLoaderData* loader_data,
 87                                                 int n, Klass* element_klass, TRAPS);
 88 
 89   oop multi_allocate(int rank, jint* sizes, TRAPS) override;
 90 
 91   // Copying
 92   void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) override;
 93 
 94   // Compute protection domain
 95   oop protection_domain() const override { return bottom_klass()->protection_domain(); }
 96 
 97   virtual void metaspace_pointers_do(MetaspaceClosure* iter) override;






 98 
 99  private:
100   // Either oop or narrowOop depending on UseCompressedOops.
101   // must be called from within ObjArrayKlass.cpp
102   void do_copy(arrayOop s, size_t src_offset,
103                arrayOop d, size_t dst_offset,
104                int length, TRAPS);
105  public:
106   static ObjArrayKlass* cast(Klass* k) {
107     return const_cast<ObjArrayKlass*>(cast(const_cast<const Klass*>(k)));
108   }
109 
110   static const ObjArrayKlass* cast(const Klass* k) {
111     assert(k->is_objArray_klass(), "cast to ObjArrayKlass");
112     return static_cast<const ObjArrayKlass*>(k);
113   }
114 
115   // Sizing
116   static int header_size()                { return sizeof(ObjArrayKlass)/wordSize; }
117   int size() const override               { return ArrayKlass::static_size(header_size()); }
118 
119   // Initialization (virtual from Klass)
120   void initialize(TRAPS) override;
121 
122   // Oop fields (and metadata) iterators
123   //
124   // The ObjArrayKlass iterators also visits the Object's klass.

  1 /*
  2  * Copyright (c) 1997, 2026, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_OOPS_OBJARRAYKLASS_HPP
 26 #define SHARE_OOPS_OBJARRAYKLASS_HPP
 27 
 28 #include "oops/arrayKlass.hpp"
 29 #include "utilities/macros.hpp"
 30 
 31 class ClassLoaderData;
 32 
 33 // ObjArrayKlass is the klass for objArrays
 34 
 35 class ObjArrayKlass : public ArrayKlass {
 36   friend class Deoptimization;

 37   friend class oopFactory;
 38   friend class VMStructs;
 39 
 40  public:
 41   static const KlassKind Kind = ObjArrayKlassKind;
 42 
 43  private:
 44   // If you add a new field that points to any metaspace object, you
 45   // must add this field to ObjArrayKlass::metaspace_pointers_do().
 46   Klass* _element_klass;            // The klass of the elements of this array type
 47   Klass* _bottom_klass;             // The one-dimensional type (InstanceKlass or TypeArrayKlass)
 48   ObjArrayKlass* _next_refined_array_klass;
 49 
 50   static ArrayDescription array_layout_selection(Klass* element, ArrayProperties properties);
 51   ObjArrayKlass* allocate_klass_from_description(ArrayDescription ad, TRAPS);
 52   ObjArrayKlass* klass_from_description(ArrayDescription adesc, TRAPS);
 53 
 54   inline ObjArrayKlass* next_refined_array_klass_acquire() const;
 55   inline void release_set_next_refined_klass(ObjArrayKlass* ak);
 56 
 57  protected:
 58   // Constructor
 59   ObjArrayKlass(int n, Klass* element_klass, Symbol* name, KlassKind kind, ArrayProperties props);
 60   static ObjArrayKlass* allocate_klass(ClassLoaderData* loader_data, int n, Klass* k, Symbol* name, ArrayProperties props, TRAPS);
 61 
 62   ObjArrayKlass* allocate_klass_with_properties(ArrayProperties props, TRAPS);
 63   objArrayOop allocate_instance(int length, ArrayProperties props, TRAPS);
 64 
 65  protected:
 66   // Create array_name for element klass
 67   static Symbol* create_element_klass_array_name(JavaThread* current, Klass* element_klass);
 68 
 69  public:
 70   // For dummy objects
 71   ObjArrayKlass() {}
 72 

 73   Klass* element_klass() const      { return _element_klass; }
 74 
 75   ObjArrayKlass* klass_with_properties(ArrayProperties props, TRAPS);
 76 
 77   ObjArrayKlass* next_refined_array_klass() const   { return _next_refined_array_klass; }
 78   bool find_refined_array_klass(ObjArrayKlass* k);
 79 
 80   // Compiler/Interpreter offset
 81   static ByteSize element_klass_offset()            { return byte_offset_of(ObjArrayKlass, _element_klass); }
 82   static ByteSize next_refined_array_klass_offset() { return byte_offset_of(ObjArrayKlass, _next_refined_array_klass); }
 83 
 84   Klass* bottom_klass() const       { return _bottom_klass; }

 85   Klass** bottom_klass_addr()       { return &_bottom_klass; }
 86 
 87   ModuleEntry* module() const override;
 88   PackageEntry* package() const override;
 89 
 90   // Dispatched operation
 91   bool can_be_primary_super_slow() const override;
 92   GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
 93                                                   Array<InstanceKlass*>* transitive_interfaces) override;
 94   DEBUG_ONLY(bool is_objArray_klass_slow() const override { return true; })
 95   size_t oop_size(oop obj) const override;
 96 
 97   // Allocation
 98   static ObjArrayKlass* allocate_objArray_klass(ClassLoaderData* loader_data,
 99                                                 int n, Klass* element_klass, TRAPS);
100 
101   oop multi_allocate(int rank, jint* sizes, TRAPS) override;
102 
103   // Copying
104   void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) override;
105 
106   // Compute protection domain
107   oop protection_domain() const override { return bottom_klass()->protection_domain(); }
108 
109   void metaspace_pointers_do(MetaspaceClosure* iter) override;
110 
111 #if INCLUDE_CDS
112   void remove_unshareable_info() override;
113   void remove_java_mirror() override;
114   void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
115 #endif
116 






117  public:
118   static ObjArrayKlass* cast(Klass* k) {
119     return const_cast<ObjArrayKlass*>(cast(const_cast<const Klass*>(k)));
120   }
121 
122   static const ObjArrayKlass* cast(const Klass* k) {
123     assert(k->is_objArray_klass(), "cast to ObjArrayKlass");
124     return static_cast<const ObjArrayKlass*>(k);
125   }
126 
127   // Sizing
128   static int header_size()                { return sizeof(ObjArrayKlass)/wordSize; }
129   int size() const override               { return ArrayKlass::static_size(header_size()); }
130 
131   // Initialization (virtual from Klass)
132   void initialize(TRAPS) override;
133 
134   // Oop fields (and metadata) iterators
135   //
136   // The ObjArrayKlass iterators also visits the Object's klass.
< prev index next >