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