ciInstanceKlass.hpp revision 1472:c18cbe5936b8
1/* 2 * Copyright (c) 1999, 2008, 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// 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 ciBytecodeStream; 33 friend class ciEnv; 34 friend class ciExceptionHandler; 35 friend class ciMethod; 36 friend class ciField; 37 38private: 39 jobject _loader; 40 jobject _protection_domain; 41 42 bool _is_shared; 43 bool _is_initialized; 44 bool _is_linked; 45 bool _has_finalizer; 46 bool _has_subklass; 47 bool _has_nonstatic_fields; 48 49 ciFlags _flags; 50 jint _nonstatic_field_size; 51 jint _nonstatic_oop_map_size; 52 53 // Lazy fields get filled in only upon request. 54 ciInstanceKlass* _super; 55 ciInstance* _java_mirror; 56 57 ciConstantPoolCache* _field_cache; // cached map index->field 58 GrowableArray<ciField*>* _nonstatic_fields; 59 60 enum { implementors_limit = instanceKlass::implementors_limit }; 61 ciInstanceKlass* _implementors[implementors_limit]; 62 jint _nof_implementors; 63 64 GrowableArray<ciField*>* _non_static_fields; 65 66protected: 67 ciInstanceKlass(KlassHandle h_k); 68 ciInstanceKlass(ciSymbol* name, jobject loader, jobject protection_domain); 69 70 instanceKlass* get_instanceKlass() const { 71 return (instanceKlass*)get_Klass(); 72 } 73 74 oop loader(); 75 jobject loader_handle(); 76 77 oop protection_domain(); 78 jobject protection_domain_handle(); 79 80 const char* type_string() { return "ciInstanceKlass"; } 81 82 bool is_in_package_impl(const char* packagename, int len); 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 97public: 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 ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static); 155 156 GrowableArray<ciField*>* non_static_fields(); 157 158 // total number of nonstatic fields (including inherited): 159 int nof_nonstatic_fields() { 160 if (_nonstatic_fields == NULL) 161 return compute_nonstatic_fields(); 162 else 163 return _nonstatic_fields->length(); 164 } 165 // nth nonstatic field (presented by ascending address) 166 ciField* nonstatic_field_at(int i) { 167 assert(_nonstatic_fields != NULL, ""); 168 return _nonstatic_fields->at(i); 169 } 170 171 ciInstanceKlass* unique_concrete_subklass(); 172 bool has_finalizable_subclass(); 173 174 bool contains_field_offset(int offset) { 175 return instanceOopDesc::contains_field_offset(offset, nonstatic_field_size()); 176 } 177 178 // Get the instance of java.lang.Class corresponding to 179 // this klass. This instance is used for locking of 180 // synchronized static methods of this klass. 181 ciInstance* java_mirror(); 182 183 // Java access flags 184 bool is_public () { return flags().is_public(); } 185 bool is_final () { return flags().is_final(); } 186 bool is_super () { return flags().is_super(); } 187 bool is_interface () { return flags().is_interface(); } 188 bool is_abstract () { return flags().is_abstract(); } 189 190 ciMethod* find_method(ciSymbol* name, ciSymbol* signature); 191 // Note: To find a method from name and type strings, use ciSymbol::make, 192 // but consider adding to vmSymbols.hpp instead. 193 194 bool is_leaf_type(); 195 ciInstanceKlass* implementor(int n); 196 197 // Is the defining class loader of this class the default loader? 198 bool uses_default_loader(); 199 200 bool is_java_lang_Object(); 201 202 // Is this klass in the given package? 203 bool is_in_package(const char* packagename) { 204 return is_in_package(packagename, (int) strlen(packagename)); 205 } 206 bool is_in_package(const char* packagename, int len); 207 208 // What kind of ciObject is this? 209 bool is_instance_klass() { return true; } 210 bool is_java_klass() { return true; } 211}; 212