ciInstanceKlass.hpp revision 0:a61af66fc99e
1/*
2 * Copyright 1999-2007 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 */
24
25// ciInstanceKlass
26//
27// This class represents a klassOop in the HotSpot virtual machine
28// whose Klass part is an instanceKlass.  It may or may not
29// be loaded.
30class ciInstanceKlass : public ciKlass {
31  CI_PACKAGE_ACCESS
32  friend class ciEnv;
33  friend class ciMethod;
34  friend class ciField;
35  friend class ciBytecodeStream;
36
37private:
38  bool                   _is_shared;
39
40  jobject                _loader;
41  jobject                _protection_domain;
42
43  bool                   _is_initialized;
44  bool                   _is_linked;
45  bool                   _has_finalizer;
46  bool                   _has_subklass;
47  ciFlags                _flags;
48  jint                   _nonstatic_field_size;
49
50  // Lazy fields get filled in only upon request.
51  ciInstanceKlass*       _super;
52  ciInstance*            _java_mirror;
53
54  ciConstantPoolCache*   _field_cache;  // cached map index->field
55  GrowableArray<ciField*>* _nonstatic_fields;
56
57  enum { implementors_limit = instanceKlass::implementors_limit };
58  ciInstanceKlass*       _implementors[implementors_limit];
59  jint                   _nof_implementors;
60
61protected:
62  ciInstanceKlass(KlassHandle h_k);
63  ciInstanceKlass(ciSymbol* name, jobject loader, jobject protection_domain);
64
65  instanceKlass* get_instanceKlass() const {
66    return (instanceKlass*)get_Klass();
67  }
68
69  oop loader();
70  jobject loader_handle();
71
72  oop protection_domain();
73  jobject protection_domain_handle();
74
75  const char* type_string() { return "ciInstanceKlass"; }
76
77  void print_impl(outputStream* st);
78
79  ciConstantPoolCache* field_cache();
80
81  bool is_shared() { return _is_shared; }
82
83  bool compute_shared_is_initialized();
84  bool compute_shared_is_linked();
85  bool compute_shared_has_subklass();
86  int  compute_shared_nof_implementors();
87  int  compute_nonstatic_fields();
88  GrowableArray<ciField*>* compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields);
89
90public:
91  // Has this klass been initialized?
92  bool                   is_initialized() {
93    if (_is_shared && !_is_initialized) {
94      return is_loaded() && compute_shared_is_initialized();
95    }
96    return _is_initialized;
97  }
98  // Has this klass been linked?
99  bool                   is_linked() {
100    if (_is_shared && !_is_linked) {
101      return is_loaded() && compute_shared_is_linked();
102    }
103    return _is_linked;
104  }
105
106  // General klass information.
107  ciFlags                flags()          {
108    assert(is_loaded(), "must be loaded");
109    return _flags;
110  }
111  bool                   has_finalizer()  {
112    assert(is_loaded(), "must be loaded");
113    return _has_finalizer; }
114  bool                   has_subklass()   {
115    assert(is_loaded(), "must be loaded");
116    if (_is_shared && !_has_subklass) {
117      if (flags().is_final()) {
118        return false;
119      } else {
120        return compute_shared_has_subklass();
121      }
122    }
123    return _has_subklass;
124  }
125  jint                   size_helper()  {
126    return (Klass::layout_helper_size_in_bytes(layout_helper())
127            >> LogHeapWordSize);
128  }
129  jint                   nonstatic_field_size()  {
130    assert(is_loaded(), "must be loaded");
131    return _nonstatic_field_size; }
132  ciInstanceKlass*       super();
133  jint                   nof_implementors()  {
134    assert(is_loaded(), "must be loaded");
135    if (_is_shared)  return compute_shared_nof_implementors();
136    return _nof_implementors;
137  }
138
139  ciInstanceKlass* get_canonical_holder(int offset);
140  ciField* get_field_by_offset(int field_offset, bool is_static);
141  // total number of nonstatic fields (including inherited):
142  int nof_nonstatic_fields() {
143    if (_nonstatic_fields == NULL)
144      return compute_nonstatic_fields();
145    else
146      return _nonstatic_fields->length();
147  }
148  // nth nonstatic field (presented by ascending address)
149  ciField* nonstatic_field_at(int i) {
150    assert(_nonstatic_fields != NULL, "");
151    return _nonstatic_fields->at(i);
152  }
153
154  ciInstanceKlass* unique_concrete_subklass();
155  bool has_finalizable_subclass();
156
157  bool contains_field_offset(int offset) {
158      return (offset/wordSize) >= instanceOopDesc::header_size()
159             && (offset/wordSize)-instanceOopDesc::header_size() < nonstatic_field_size();
160  }
161
162  // Get the instance of java.lang.Class corresponding to
163  // this klass.  This instance is used for locking of
164  // synchronized static methods of this klass.
165  ciInstance*            java_mirror();
166
167  // Java access flags
168  bool is_public      () { return flags().is_public(); }
169  bool is_final       () { return flags().is_final(); }
170  bool is_super       () { return flags().is_super(); }
171  bool is_interface   () { return flags().is_interface(); }
172  bool is_abstract    () { return flags().is_abstract(); }
173
174  ciMethod* find_method(ciSymbol* name, ciSymbol* signature);
175  // Note:  To find a method from name and type strings, use ciSymbol::make,
176  // but consider adding to vmSymbols.hpp instead.
177
178  bool is_leaf_type();
179  ciInstanceKlass* implementor(int n);
180
181  // Is the defining class loader of this class the default loader?
182  bool uses_default_loader();
183
184  bool is_java_lang_Object();
185
186  // What kind of ciObject is this?
187  bool is_instance_klass() { return true; }
188  bool is_java_klass()     { return true; }
189};
190