annotate src/share/vm/ci/ciInstanceKlass.cpp @ 3700:f13867c41f73

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