annotate hotspot/src/share/vm/ci/ciInstanceKlass.cpp @ 7397:5b173b4ca846

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents f088bb3df36d
children 96d498ec7ae1
rev   line source
duke@1 1 /*
never@5925 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #include "precompiled.hpp"
stefank@7397 26 #include "ci/ciField.hpp"
stefank@7397 27 #include "ci/ciInstance.hpp"
stefank@7397 28 #include "ci/ciInstanceKlass.hpp"
stefank@7397 29 #include "ci/ciUtilities.hpp"
stefank@7397 30 #include "classfile/systemDictionary.hpp"
stefank@7397 31 #include "memory/allocation.hpp"
stefank@7397 32 #include "memory/allocation.inline.hpp"
stefank@7397 33 #include "oops/oop.inline.hpp"
stefank@7397 34 #include "runtime/fieldDescriptor.hpp"
duke@1 35
duke@1 36 // ciInstanceKlass
duke@1 37 //
duke@1 38 // This class represents a klassOop in the HotSpot virtual machine
duke@1 39 // whose Klass part in an instanceKlass.
duke@1 40
duke@1 41 // ------------------------------------------------------------------
duke@1 42 // ciInstanceKlass::ciInstanceKlass
duke@1 43 //
duke@1 44 // Loaded instance klass.
kvn@217 45 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
kvn@217 46 ciKlass(h_k), _non_static_fields(NULL)
kvn@217 47 {
duke@1 48 assert(get_Klass()->oop_is_instance(), "wrong type");
duke@1 49 instanceKlass* ik = get_instanceKlass();
duke@1 50
duke@1 51 AccessFlags access_flags = ik->access_flags();
duke@1 52 _flags = ciFlags(access_flags);
duke@1 53 _has_finalizer = access_flags.has_finalizer();
duke@1 54 _has_subklass = ik->subklass() != NULL;
never@5925 55 _init_state = (instanceKlass::ClassState)ik->get_init_state();
duke@1 56 _nonstatic_field_size = ik->nonstatic_field_size();
coleenp@360 57 _has_nonstatic_fields = ik->has_nonstatic_fields();
duke@1 58 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
duke@1 59
duke@1 60 _nof_implementors = ik->nof_implementors();
duke@1 61 for (int i = 0; i < implementors_limit; i++) {
duke@1 62 _implementors[i] = NULL; // we will fill these lazily
duke@1 63 }
duke@1 64
duke@1 65 Thread *thread = Thread::current();
duke@1 66 if (ciObjectFactory::is_initialized()) {
duke@1 67 _loader = JNIHandles::make_local(thread, ik->class_loader());
duke@1 68 _protection_domain = JNIHandles::make_local(thread,
duke@1 69 ik->protection_domain());
duke@1 70 _is_shared = false;
duke@1 71 } else {
duke@1 72 Handle h_loader(thread, ik->class_loader());
duke@1 73 Handle h_protection_domain(thread, ik->protection_domain());
duke@1 74 _loader = JNIHandles::make_global(h_loader);
duke@1 75 _protection_domain = JNIHandles::make_global(h_protection_domain);
duke@1 76 _is_shared = true;
duke@1 77 }
duke@1 78
duke@1 79 // Lazy fields get filled in only upon request.
duke@1 80 _super = NULL;
duke@1 81 _java_mirror = NULL;
duke@1 82
duke@1 83 if (is_shared()) {
never@4571 84 if (h_k() != SystemDictionary::Object_klass()) {
duke@1 85 super();
duke@1 86 }
duke@1 87 java_mirror();
duke@1 88 //compute_nonstatic_fields(); // done outside of constructor
duke@1 89 }
duke@1 90
duke@1 91 _field_cache = NULL;
duke@1 92 }
duke@1 93
duke@1 94 // Version for unloaded classes:
duke@1 95 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
duke@1 96 jobject loader, jobject protection_domain)
duke@1 97 : ciKlass(name, ciInstanceKlassKlass::make())
duke@1 98 {
duke@1 99 assert(name->byte_at(0) != '[', "not an instance klass");
never@5925 100 _init_state = (instanceKlass::ClassState)0;
duke@1 101 _nonstatic_field_size = -1;
coleenp@360 102 _has_nonstatic_fields = false;
duke@1 103 _nonstatic_fields = NULL;
duke@1 104 _nof_implementors = -1;
duke@1 105 _loader = loader;
duke@1 106 _protection_domain = protection_domain;
duke@1 107 _is_shared = false;
duke@1 108 _super = NULL;
duke@1 109 _java_mirror = NULL;
duke@1 110 _field_cache = NULL;
duke@1 111 }
duke@1 112
duke@1 113
duke@1 114
duke@1 115 // ------------------------------------------------------------------
duke@1 116 // ciInstanceKlass::compute_shared_is_initialized
never@5925 117 void ciInstanceKlass::compute_shared_init_state() {
duke@1 118 GUARDED_VM_ENTRY(
duke@1 119 instanceKlass* ik = get_instanceKlass();
never@5925 120 _init_state = (instanceKlass::ClassState)ik->get_init_state();
duke@1 121 )
duke@1 122 }
duke@1 123
duke@1 124 // ------------------------------------------------------------------
duke@1 125 // ciInstanceKlass::compute_shared_has_subklass
duke@1 126 bool ciInstanceKlass::compute_shared_has_subklass() {
duke@1 127 GUARDED_VM_ENTRY(
duke@1 128 instanceKlass* ik = get_instanceKlass();
duke@1 129 _has_subklass = ik->subklass() != NULL;
duke@1 130 return _has_subklass;
duke@1 131 )
duke@1 132 }
duke@1 133
duke@1 134 // ------------------------------------------------------------------
duke@1 135 // ciInstanceKlass::compute_shared_nof_implementors
duke@1 136 int ciInstanceKlass::compute_shared_nof_implementors() {
duke@1 137 // We requery this property, since it is a very old ciObject.
duke@1 138 GUARDED_VM_ENTRY(
duke@1 139 instanceKlass* ik = get_instanceKlass();
duke@1 140 _nof_implementors = ik->nof_implementors();
duke@1 141 return _nof_implementors;
duke@1 142 )
duke@1 143 }
duke@1 144
duke@1 145 // ------------------------------------------------------------------
duke@1 146 // ciInstanceKlass::loader
duke@1 147 oop ciInstanceKlass::loader() {
duke@1 148 ASSERT_IN_VM;
duke@1 149 return JNIHandles::resolve(_loader);
duke@1 150 }
duke@1 151
duke@1 152 // ------------------------------------------------------------------
duke@1 153 // ciInstanceKlass::loader_handle
duke@1 154 jobject ciInstanceKlass::loader_handle() {
duke@1 155 return _loader;
duke@1 156 }
duke@1 157
duke@1 158 // ------------------------------------------------------------------
duke@1 159 // ciInstanceKlass::protection_domain
duke@1 160 oop ciInstanceKlass::protection_domain() {
duke@1 161 ASSERT_IN_VM;
duke@1 162 return JNIHandles::resolve(_protection_domain);
duke@1 163 }
duke@1 164
duke@1 165 // ------------------------------------------------------------------
duke@1 166 // ciInstanceKlass::protection_domain_handle
duke@1 167 jobject ciInstanceKlass::protection_domain_handle() {
duke@1 168 return _protection_domain;
duke@1 169 }
duke@1 170
duke@1 171 // ------------------------------------------------------------------
duke@1 172 // ciInstanceKlass::field_cache
duke@1 173 //
duke@1 174 // Get the field cache associated with this klass.
duke@1 175 ciConstantPoolCache* ciInstanceKlass::field_cache() {
duke@1 176 if (is_shared()) {
duke@1 177 return NULL;
duke@1 178 }
duke@1 179 if (_field_cache == NULL) {
duke@1 180 assert(!is_java_lang_Object(), "Object has no fields");
duke@1 181 Arena* arena = CURRENT_ENV->arena();
duke@1 182 _field_cache = new (arena) ciConstantPoolCache(arena, 5);
duke@1 183 }
duke@1 184 return _field_cache;
duke@1 185 }
duke@1 186
duke@1 187 // ------------------------------------------------------------------
duke@1 188 // ciInstanceKlass::get_canonical_holder
duke@1 189 //
duke@1 190 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
duke@1 191 #ifdef ASSERT
duke@1 192 if (!(offset >= 0 && offset < layout_helper())) {
duke@1 193 tty->print("*** get_canonical_holder(%d) on ", offset);
duke@1 194 this->print();
duke@1 195 tty->print_cr(" ***");
duke@1 196 };
duke@1 197 assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
duke@1 198 #endif
duke@1 199
coleenp@360 200 if (offset < instanceOopDesc::base_offset_in_bytes()) {
duke@1 201 // All header offsets belong properly to java/lang/Object.
duke@1 202 return CURRENT_ENV->Object_klass();
duke@1 203 }
duke@1 204
duke@1 205 ciInstanceKlass* self = this;
duke@1 206 for (;;) {
duke@1 207 assert(self->is_loaded(), "must be loaded to have size");
duke@1 208 ciInstanceKlass* super = self->super();
coleenp@360 209 if (super == NULL || super->nof_nonstatic_fields() == 0 ||
coleenp@360 210 !super->contains_field_offset(offset)) {
duke@1 211 return self;
duke@1 212 } else {
duke@1 213 self = super; // return super->get_canonical_holder(offset)
duke@1 214 }
duke@1 215 }
duke@1 216 }
duke@1 217
duke@1 218 // ------------------------------------------------------------------
duke@1 219 // ciInstanceKlass::is_java_lang_Object
duke@1 220 //
duke@1 221 // Is this klass java.lang.Object?
duke@1 222 bool ciInstanceKlass::is_java_lang_Object() {
duke@1 223 return equals(CURRENT_ENV->Object_klass());
duke@1 224 }
duke@1 225
duke@1 226 // ------------------------------------------------------------------
duke@1 227 // ciInstanceKlass::uses_default_loader
duke@1 228 bool ciInstanceKlass::uses_default_loader() {
twisti@4567 229 // Note: We do not need to resolve the handle or enter the VM
twisti@4567 230 // in order to test null-ness.
twisti@4567 231 return _loader == NULL;
twisti@4567 232 }
twisti@4567 233
twisti@4567 234 // ------------------------------------------------------------------
twisti@4567 235 // ciInstanceKlass::is_in_package
twisti@4567 236 //
twisti@4567 237 // Is this klass in the given package?
twisti@4567 238 bool ciInstanceKlass::is_in_package(const char* packagename, int len) {
twisti@4567 239 // To avoid class loader mischief, this test always rejects application classes.
twisti@4567 240 if (!uses_default_loader())
twisti@4567 241 return false;
twisti@4567 242 GUARDED_VM_ENTRY(
twisti@4567 243 return is_in_package_impl(packagename, len);
twisti@4567 244 )
twisti@4567 245 }
twisti@4567 246
twisti@4567 247 bool ciInstanceKlass::is_in_package_impl(const char* packagename, int len) {
twisti@4567 248 ASSERT_IN_VM;
twisti@4567 249
twisti@4567 250 // If packagename contains trailing '/' exclude it from the
twisti@4567 251 // prefix-test since we test for it explicitly.
twisti@4567 252 if (packagename[len - 1] == '/')
twisti@4567 253 len--;
twisti@4567 254
twisti@4567 255 if (!name()->starts_with(packagename, len))
twisti@4567 256 return false;
twisti@4567 257
twisti@4567 258 // Test if the class name is something like "java/lang".
twisti@4567 259 if ((len + 1) > name()->utf8_length())
twisti@4567 260 return false;
twisti@4567 261
twisti@4567 262 // Test for trailing '/'
twisti@4567 263 if ((char) name()->byte_at(len) != '/')
twisti@4567 264 return false;
twisti@4567 265
twisti@4567 266 // Make sure it's not actually in a subpackage:
twisti@4567 267 if (name()->index_of_at(len+1, "/", 1) >= 0)
twisti@4567 268 return false;
twisti@4567 269
twisti@4567 270 return true;
duke@1 271 }
duke@1 272
duke@1 273 // ------------------------------------------------------------------
duke@1 274 // ciInstanceKlass::print_impl
duke@1 275 //
duke@1 276 // Implementation of the print method.
duke@1 277 void ciInstanceKlass::print_impl(outputStream* st) {
duke@1 278 ciKlass::print_impl(st);
duke@1 279 GUARDED_VM_ENTRY(st->print(" loader=0x%x", (address)loader());)
duke@1 280 if (is_loaded()) {
duke@1 281 st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
duke@1 282 bool_to_str(is_initialized()),
duke@1 283 bool_to_str(has_finalizer()),
duke@1 284 bool_to_str(has_subklass()),
duke@1 285 layout_helper());
duke@1 286
duke@1 287 _flags.print_klass_flags();
duke@1 288
duke@1 289 if (_super) {
duke@1 290 st->print(" super=");
duke@1 291 _super->print_name();
duke@1 292 }
duke@1 293 if (_java_mirror) {
duke@1 294 st->print(" mirror=PRESENT");
duke@1 295 }
duke@1 296 } else {
duke@1 297 st->print(" loaded=false");
duke@1 298 }
duke@1 299 }
duke@1 300
duke@1 301 // ------------------------------------------------------------------
duke@1 302 // ciInstanceKlass::super
duke@1 303 //
duke@1 304 // Get the superklass of this klass.
duke@1 305 ciInstanceKlass* ciInstanceKlass::super() {
duke@1 306 assert(is_loaded(), "must be loaded");
duke@1 307 if (_super == NULL && !is_java_lang_Object()) {
duke@1 308 GUARDED_VM_ENTRY(
duke@1 309 klassOop super_klass = get_instanceKlass()->super();
duke@1 310 _super = CURRENT_ENV->get_object(super_klass)->as_instance_klass();
duke@1 311 )
duke@1 312 }
duke@1 313 return _super;
duke@1 314 }
duke@1 315
duke@1 316 // ------------------------------------------------------------------
duke@1 317 // ciInstanceKlass::java_mirror
duke@1 318 //
duke@1 319 // Get the instance of java.lang.Class corresponding to this klass.
jrose@5884 320 // Cache it on this->_java_mirror.
duke@1 321 ciInstance* ciInstanceKlass::java_mirror() {
duke@1 322 if (_java_mirror == NULL) {
jrose@5884 323 _java_mirror = ciKlass::java_mirror();
duke@1 324 }
duke@1 325 return _java_mirror;
duke@1 326 }
duke@1 327
duke@1 328 // ------------------------------------------------------------------
duke@1 329 // ciInstanceKlass::unique_concrete_subklass
duke@1 330 ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() {
duke@1 331 if (!is_loaded()) return NULL; // No change if class is not loaded
duke@1 332 if (!is_abstract()) return NULL; // Only applies to abstract classes.
duke@1 333 if (!has_subklass()) return NULL; // Must have at least one subklass.
duke@1 334 VM_ENTRY_MARK;
duke@1 335 instanceKlass* ik = get_instanceKlass();
duke@1 336 Klass* up = ik->up_cast_abstract();
duke@1 337 assert(up->oop_is_instance(), "must be instanceKlass");
duke@1 338 if (ik == up) {
duke@1 339 return NULL;
duke@1 340 }
duke@1 341 return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass();
duke@1 342 }
duke@1 343
duke@1 344 // ------------------------------------------------------------------
duke@1 345 // ciInstanceKlass::has_finalizable_subclass
duke@1 346 bool ciInstanceKlass::has_finalizable_subclass() {
duke@1 347 if (!is_loaded()) return true;
duke@1 348 VM_ENTRY_MARK;
duke@1 349 return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
duke@1 350 }
duke@1 351
duke@1 352 // ------------------------------------------------------------------
duke@1 353 // ciInstanceKlass::get_field_by_offset
duke@1 354 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
duke@1 355 if (!is_static) {
duke@1 356 for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
duke@1 357 ciField* field = _nonstatic_fields->at(i);
duke@1 358 int field_off = field->offset_in_bytes();
duke@1 359 if (field_off == field_offset)
duke@1 360 return field;
duke@1 361 if (field_off > field_offset)
duke@1 362 break;
duke@1 363 // could do binary search or check bins, but probably not worth it
duke@1 364 }
duke@1 365 return NULL;
duke@1 366 }
duke@1 367 VM_ENTRY_MARK;
duke@1 368 instanceKlass* k = get_instanceKlass();
duke@1 369 fieldDescriptor fd;
duke@1 370 if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
duke@1 371 return NULL;
duke@1 372 }
duke@1 373 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
duke@1 374 return field;
duke@1 375 }
duke@1 376
kvn@217 377 // ------------------------------------------------------------------
never@4450 378 // ciInstanceKlass::get_field_by_name
never@4450 379 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
never@4450 380 VM_ENTRY_MARK;
never@4450 381 instanceKlass* k = get_instanceKlass();
never@4450 382 fieldDescriptor fd;
never@4450 383 klassOop def = k->find_field(name->get_symbolOop(), signature->get_symbolOop(), is_static, &fd);
never@4450 384 if (def == NULL) {
never@4450 385 return NULL;
never@4450 386 }
never@4450 387 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
never@4450 388 return field;
never@4450 389 }
never@4450 390
never@4450 391 // ------------------------------------------------------------------
kvn@217 392 // ciInstanceKlass::non_static_fields.
kvn@217 393
kvn@217 394 class NonStaticFieldFiller: public FieldClosure {
kvn@217 395 GrowableArray<ciField*>* _arr;
kvn@217 396 ciEnv* _curEnv;
kvn@217 397 public:
kvn@217 398 NonStaticFieldFiller(ciEnv* curEnv, GrowableArray<ciField*>* arr) :
kvn@217 399 _curEnv(curEnv), _arr(arr)
kvn@217 400 {}
kvn@217 401 void do_field(fieldDescriptor* fd) {
kvn@217 402 ciField* field = new (_curEnv->arena()) ciField(fd);
kvn@217 403 _arr->append(field);
kvn@217 404 }
kvn@217 405 };
kvn@217 406
kvn@217 407 GrowableArray<ciField*>* ciInstanceKlass::non_static_fields() {
kvn@217 408 if (_non_static_fields == NULL) {
kvn@217 409 VM_ENTRY_MARK;
kvn@217 410 ciEnv* curEnv = ciEnv::current();
kvn@217 411 instanceKlass* ik = get_instanceKlass();
kvn@217 412 int max_n_fields = ik->fields()->length()/instanceKlass::next_offset;
kvn@217 413
kvn@6180 414 Arena* arena = curEnv->arena();
kvn@217 415 _non_static_fields =
kvn@6180 416 new (arena) GrowableArray<ciField*>(arena, max_n_fields, 0, NULL);
kvn@217 417 NonStaticFieldFiller filler(curEnv, _non_static_fields);
kvn@217 418 ik->do_nonstatic_fields(&filler);
kvn@217 419 }
kvn@217 420 return _non_static_fields;
kvn@217 421 }
kvn@217 422
duke@1 423 static int sort_field_by_offset(ciField** a, ciField** b) {
duke@1 424 return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
duke@1 425 // (no worries about 32-bit overflow...)
duke@1 426 }
duke@1 427
duke@1 428 // ------------------------------------------------------------------
duke@1 429 // ciInstanceKlass::compute_nonstatic_fields
duke@1 430 int ciInstanceKlass::compute_nonstatic_fields() {
duke@1 431 assert(is_loaded(), "must be loaded");
duke@1 432
duke@1 433 if (_nonstatic_fields != NULL)
duke@1 434 return _nonstatic_fields->length();
duke@1 435
coleenp@360 436 if (!has_nonstatic_fields()) {
duke@1 437 Arena* arena = CURRENT_ENV->arena();
duke@1 438 _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
duke@1 439 return 0;
duke@1 440 }
duke@1 441 assert(!is_java_lang_Object(), "bootstrap OK");
duke@1 442
coleenp@360 443 // Size in bytes of my fields, including inherited fields.
kvn@591 444 int fsize = nonstatic_field_size() * heapOopSize;
coleenp@360 445
duke@1 446 ciInstanceKlass* super = this->super();
duke@1 447 GrowableArray<ciField*>* super_fields = NULL;
coleenp@360 448 if (super != NULL && super->has_nonstatic_fields()) {
kvn@591 449 int super_fsize = super->nonstatic_field_size() * heapOopSize;
coleenp@360 450 int super_flen = super->nof_nonstatic_fields();
duke@1 451 super_fields = super->_nonstatic_fields;
duke@1 452 assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
coleenp@360 453 // See if I am no larger than my super; if so, I can use his fields.
coleenp@360 454 if (fsize == super_fsize) {
coleenp@360 455 _nonstatic_fields = super_fields;
coleenp@360 456 return super_fields->length();
coleenp@360 457 }
duke@1 458 }
duke@1 459
duke@1 460 GrowableArray<ciField*>* fields = NULL;
duke@1 461 GUARDED_VM_ENTRY({
duke@1 462 fields = compute_nonstatic_fields_impl(super_fields);
duke@1 463 });
duke@1 464
duke@1 465 if (fields == NULL) {
duke@1 466 // This can happen if this class (java.lang.Class) has invisible fields.
duke@1 467 _nonstatic_fields = super_fields;
duke@1 468 return super_fields->length();
duke@1 469 }
duke@1 470
duke@1 471 int flen = fields->length();
duke@1 472
duke@1 473 // Now sort them by offset, ascending.
duke@1 474 // (In principle, they could mix with superclass fields.)
duke@1 475 fields->sort(sort_field_by_offset);
duke@1 476 #ifdef ASSERT
coleenp@360 477 int last_offset = instanceOopDesc::base_offset_in_bytes();
duke@1 478 for (int i = 0; i < fields->length(); i++) {
duke@1 479 ciField* field = fields->at(i);
duke@1 480 int offset = field->offset_in_bytes();
coleenp@360 481 int size = (field->_type == NULL) ? heapOopSize : field->size_in_bytes();
twisti@6772 482 assert(last_offset <= offset, err_msg("no field overlap: %d <= %d", last_offset, offset));
duke@1 483 if (last_offset > (int)sizeof(oopDesc))
duke@1 484 assert((offset - last_offset) < BytesPerLong, "no big holes");
duke@1 485 // Note: Two consecutive T_BYTE fields will be separated by wordSize-1
duke@1 486 // padding bytes if one of them is declared by a superclass.
duke@1 487 // This is a minor inefficiency classFileParser.cpp.
duke@1 488 last_offset = offset + size;
duke@1 489 }
kvn@591 490 assert(last_offset <= (int)instanceOopDesc::base_offset_in_bytes() + fsize, "no overflow");
duke@1 491 #endif
duke@1 492
duke@1 493 _nonstatic_fields = fields;
duke@1 494 return flen;
duke@1 495 }
duke@1 496
duke@1 497 GrowableArray<ciField*>*
duke@1 498 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
duke@1 499 super_fields) {
duke@1 500 ASSERT_IN_VM;
duke@1 501 Arena* arena = CURRENT_ENV->arena();
duke@1 502 int flen = 0;
duke@1 503 GrowableArray<ciField*>* fields = NULL;
duke@1 504 instanceKlass* k = get_instanceKlass();
duke@1 505 typeArrayOop fields_array = k->fields();
duke@1 506 for (int pass = 0; pass <= 1; pass++) {
duke@1 507 for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) {
duke@1 508 fieldDescriptor fd;
duke@1 509 fd.initialize(k->as_klassOop(), i);
duke@1 510 if (fd.is_static()) continue;
duke@1 511 if (pass == 0) {
duke@1 512 flen += 1;
duke@1 513 } else {
duke@1 514 ciField* field = new (arena) ciField(&fd);
duke@1 515 fields->append(field);
duke@1 516 }
duke@1 517 }
duke@1 518
duke@1 519 // Between passes, allocate the array:
duke@1 520 if (pass == 0) {
duke@1 521 if (flen == 0) {
duke@1 522 return NULL; // return nothing if none are locally declared
duke@1 523 }
duke@1 524 if (super_fields != NULL) {
duke@1 525 flen += super_fields->length();
duke@1 526 }
duke@1 527 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
duke@1 528 if (super_fields != NULL) {
duke@1 529 fields->appendAll(super_fields);
duke@1 530 }
duke@1 531 }
duke@1 532 }
duke@1 533 assert(fields->length() == flen, "sanity");
duke@1 534 return fields;
duke@1 535 }
duke@1 536
duke@1 537 // ------------------------------------------------------------------
duke@1 538 // ciInstanceKlass::find_method
duke@1 539 //
duke@1 540 // Find a method in this klass.
duke@1 541 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
duke@1 542 VM_ENTRY_MARK;
duke@1 543 instanceKlass* k = get_instanceKlass();
duke@1 544 symbolOop name_sym = name->get_symbolOop();
duke@1 545 symbolOop sig_sym= signature->get_symbolOop();
duke@1 546
duke@1 547 methodOop m = k->find_method(name_sym, sig_sym);
duke@1 548 if (m == NULL) return NULL;
duke@1 549
duke@1 550 return CURRENT_THREAD_ENV->get_object(m)->as_method();
duke@1 551 }
duke@1 552
duke@1 553 // ------------------------------------------------------------------
duke@1 554 // ciInstanceKlass::is_leaf_type
duke@1 555 bool ciInstanceKlass::is_leaf_type() {
duke@1 556 assert(is_loaded(), "must be loaded");
duke@1 557 if (is_shared()) {
duke@1 558 return is_final(); // approximately correct
duke@1 559 } else {
duke@1 560 return !_has_subklass && (_nof_implementors == 0);
duke@1 561 }
duke@1 562 }
duke@1 563
duke@1 564 // ------------------------------------------------------------------
duke@1 565 // ciInstanceKlass::implementor
duke@1 566 //
duke@1 567 // Report an implementor of this interface.
duke@1 568 // Returns NULL if exact information is not available.
duke@1 569 // Note that there are various races here, since my copy
duke@1 570 // of _nof_implementors might be out of date with respect
duke@1 571 // to results returned by instanceKlass::implementor.
duke@1 572 // This is OK, since any dependencies we decide to assert
duke@1 573 // will be checked later under the Compile_lock.
duke@1 574 ciInstanceKlass* ciInstanceKlass::implementor(int n) {
kvn@7125 575 if (n >= implementors_limit) {
duke@1 576 return NULL;
duke@1 577 }
duke@1 578 ciInstanceKlass* impl = _implementors[n];
duke@1 579 if (impl == NULL) {
duke@1 580 if (_nof_implementors > implementors_limit) {
duke@1 581 return NULL;
duke@1 582 }
duke@1 583 // Go into the VM to fetch the implementor.
duke@1 584 {
duke@1 585 VM_ENTRY_MARK;
duke@1 586 klassOop k = get_instanceKlass()->implementor(n);
duke@1 587 if (k != NULL) {
duke@1 588 impl = CURRENT_THREAD_ENV->get_object(k)->as_instance_klass();
duke@1 589 }
duke@1 590 }
duke@1 591 // Memoize this result.
duke@1 592 if (!is_shared()) {
duke@1 593 _implementors[n] = (impl == NULL)? this: impl;
duke@1 594 }
duke@1 595 } else if (impl == this) {
duke@1 596 impl = NULL; // memoized null result from a VM query
duke@1 597 }
duke@1 598 return impl;
duke@1 599 }