arrayKlass.hpp revision 1472:c18cbe5936b8
1139804Simp/*
2139013Sdavidxu * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
3112904Sjeff * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4112904Sjeff *
5112904Sjeff * This code is free software; you can redistribute it and/or modify it
6112904Sjeff * under the terms of the GNU General Public License version 2 only, as
7112904Sjeff * published by the Free Software Foundation.
8112904Sjeff *
9112904Sjeff * This code is distributed in the hope that it will be useful, but WITHOUT
10112904Sjeff * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11112904Sjeff * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12112904Sjeff * version 2 for more details (a copy is included in the LICENSE file that
13112904Sjeff * accompanied this code).
14112904Sjeff *
15112904Sjeff * You should have received a copy of the GNU General Public License version
16112904Sjeff * 2 along with this work; if not, write to the Free Software Foundation,
17112904Sjeff * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18112904Sjeff *
19112904Sjeff * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20112904Sjeff * or visit www.oracle.com if you need additional information or have any
21112904Sjeff * questions.
22112904Sjeff *
23112904Sjeff */
24112904Sjeff
25112904Sjeff// arrayKlass is the abstract baseclass for all array classes
26112904Sjeff
27112904Sjeffclass arrayKlass: public Klass {
28116182Sobrien  friend class VMStructs;
29116182Sobrien private:
30116182Sobrien  int      _dimension;         // This is n'th-dimensional array.
31162536Sdavidxu  klassOop _higher_dimension;  // Refers the (n+1)'th-dimensional array (if present).
32112904Sjeff  klassOop _lower_dimension;   // Refers the (n-1)'th-dimensional array (if present).
33112904Sjeff  int      _vtable_len;        // size of vtable for this klass
34131431Smarcel  juint    _alloc_size;        // allocation profiling support
35112904Sjeff  oop      _component_mirror;  // component type, as a java/lang/Class
36115765Sjeff
37112904Sjeff public:
38164033Srwatson  // Testing operation
39112904Sjeff  bool oop_is_array() const { return true; }
40161678Sdavidxu
41165369Sdavidxu  // Instance variables
42161678Sdavidxu  int dimension() const                 { return _dimension;      }
43112904Sjeff  void set_dimension(int dimension)     { _dimension = dimension; }
44112904Sjeff
45112904Sjeff  klassOop higher_dimension() const     { return _higher_dimension; }
46216641Sdavidxu  void set_higher_dimension(klassOop k) { oop_store_without_check((oop*) &_higher_dimension, (oop) k); }
47139013Sdavidxu  oop* adr_higher_dimension()           { return (oop*)&this->_higher_dimension;}
48112904Sjeff
49112904Sjeff  klassOop lower_dimension() const      { return _lower_dimension; }
50139013Sdavidxu  void set_lower_dimension(klassOop k)  { oop_store_without_check((oop*) &_lower_dimension, (oop) k); }
51139013Sdavidxu  oop* adr_lower_dimension()            { return (oop*)&this->_lower_dimension;}
52139013Sdavidxu
53139013Sdavidxu  // Allocation profiling support
54139013Sdavidxu  juint alloc_size() const              { return _alloc_size; }
55139013Sdavidxu  void set_alloc_size(juint n)          { _alloc_size = n; }
56165369Sdavidxu
57165369Sdavidxu  // offset of first element, including any padding for the sake of alignment
58205014Snwhitehorn  int  array_header_in_bytes() const    { return layout_helper_header_size(layout_helper()); }
59162536Sdavidxu  int  log2_element_size() const        { return layout_helper_log2_element_size(layout_helper()); }
60162536Sdavidxu  // type of elements (T_OBJECT for both oop arrays and array-arrays)
61162536Sdavidxu  BasicType element_type() const        { return layout_helper_element_type(layout_helper()); }
62179970Sdavidxu
63179970Sdavidxu  oop  component_mirror() const         { return _component_mirror; }
64179970Sdavidxu  void set_component_mirror(oop m)      { oop_store((oop*) &_component_mirror, m); }
65161678Sdavidxu  oop* adr_component_mirror()           { return (oop*)&this->_component_mirror;}
66161678Sdavidxu
67161678Sdavidxu  // Compiler/Interpreter offset
68161678Sdavidxu  static ByteSize component_mirror_offset() { return byte_offset_of(arrayKlass, _component_mirror); }
69161678Sdavidxu
70161678Sdavidxu  virtual klassOop java_super() const;//{ return SystemDictionary::Object_klass(); }
71161678Sdavidxu
72161678Sdavidxu  // Allocation
73161678Sdavidxu  // Sizes points to the first dimension of the array, subsequent dimensions
74161678Sdavidxu  // are always in higher memory.  The callers of these set that up.
75161678Sdavidxu  virtual oop multi_allocate(int rank, jint* sizes, TRAPS);
76161678Sdavidxu  objArrayOop allocate_arrayArray(int n, int length, TRAPS);
77161678Sdavidxu
78161678Sdavidxu  // Lookup operations
79161678Sdavidxu  methodOop uncached_lookup_method(symbolOop name, symbolOop signature) const;
80161678Sdavidxu
81161678Sdavidxu  // Casting from klassOop
82161678Sdavidxu  static arrayKlass* cast(klassOop k) {
83161678Sdavidxu    Klass* kp = k->klass_part();
84161678Sdavidxu    assert(kp->null_vtbl() || kp->oop_is_array(), "cast to arrayKlass");
85161678Sdavidxu    return (arrayKlass*) kp;
86161678Sdavidxu  }
87115765Sjeff
88161678Sdavidxu  objArrayOop compute_secondary_supers(int num_extra_slots, TRAPS);
89161678Sdavidxu  bool compute_is_subtype_of(klassOop k);
90161678Sdavidxu
91161678Sdavidxu  // Sizing
92161678Sdavidxu  static int header_size()                 { return oopDesc::header_size() + sizeof(arrayKlass)/HeapWordSize; }
93161678Sdavidxu  int object_size(int header_size) const;
94161678Sdavidxu
95161678Sdavidxu  bool object_is_parsable() const          { return _vtable_len > 0; }
96161678Sdavidxu
97161678Sdavidxu  // Java vtable
98161678Sdavidxu  klassVtable* vtable() const;             // return new klassVtable
99161678Sdavidxu  int  vtable_length() const               { return _vtable_len; }
100161678Sdavidxu  static int base_vtable_length()          { return Universe::base_vtable_size(); }
101161678Sdavidxu  void set_vtable_length(int len)          { assert(len == base_vtable_length(), "bad length"); _vtable_len = len; }
102161678Sdavidxu protected:
103170300Sjeff  inline intptr_t* start_of_vtable() const;
104170300Sjeff
105161678Sdavidxu public:
106161678Sdavidxu  // Iterators
107161678Sdavidxu  void array_klasses_do(void f(klassOop k));
108161678Sdavidxu  void with_array_klasses_do(void f(klassOop k));
109161678Sdavidxu
110161678Sdavidxu  // Shared creation method
111161678Sdavidxu  static arrayKlassHandle base_create_array_klass(
112161678Sdavidxu                                          const Klass_vtbl& vtbl,
113161678Sdavidxu                                          int header_size, KlassHandle klass,
114161742Sdavidxu                                          TRAPS);
115161678Sdavidxu  // Return a handle.
116201991Sdavidxu  static void     complete_create_array_klass(arrayKlassHandle k, KlassHandle super_klass, TRAPS);
117201991Sdavidxu
118201991Sdavidxu public:
119201991Sdavidxu   // jvm support
120201991Sdavidxu   jint compute_modifier_flags(TRAPS) const;
121201991Sdavidxu
122115765Sjeff public:
123115765Sjeff   // JVMTI support
124161678Sdavidxu   jint jvmti_class_status() const;
125161678Sdavidxu
126201991Sdavidxu#ifndef PRODUCT
127201991Sdavidxu public:
128201991Sdavidxu  // Printing
129201991Sdavidxu  void oop_print_on(oop obj, outputStream* st);
130201991Sdavidxu#endif
131201991Sdavidxu public:
132201991Sdavidxu  // Verification
133201991Sdavidxu  void oop_verify_on(oop obj, outputStream* st);
134201991Sdavidxu};
135201991Sdavidxu