annotate hotspot/src/share/vm/ci/ciInstanceKlass.cpp @ 44738:11431bbc9549

8168699: Validate special case invocations Reviewed-by: acorn, kvn, lfoltan, ctornqvi, ahgross, vlivanov
author coleenp
date Thu, 01 Dec 2016 14:21:31 -0500
parents 2091069b6851
children 3c12af929e7d
rev   line source
duke@1 1 /*
jprovino@37248 2 * Copyright (c) 1999, 2016, 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"
jprovino@37248 33 #include "memory/resourceArea.hpp"
stefank@7397 34 #include "oops/oop.inline.hpp"
never@10546 35 #include "oops/fieldStreams.hpp"
stefank@7397 36 #include "runtime/fieldDescriptor.hpp"
duke@1 37
duke@1 38 // ciInstanceKlass
duke@1 39 //
coleenp@13728 40 // This class represents a Klass* in the HotSpot virtual machine
coleenp@13728 41 // whose Klass part in an InstanceKlass.
duke@1 42
duke@1 43 // ------------------------------------------------------------------
duke@1 44 // ciInstanceKlass::ciInstanceKlass
duke@1 45 //
duke@1 46 // Loaded instance klass.
kvn@217 47 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
anoll@26706 48 ciKlass(h_k)
kvn@217 49 {
coleenp@33611 50 assert(get_Klass()->is_instance_klass(), "wrong type");
never@8314 51 assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
coleenp@13728 52 InstanceKlass* ik = get_instanceKlass();
duke@1 53
duke@1 54 AccessFlags access_flags = ik->access_flags();
duke@1 55 _flags = ciFlags(access_flags);
duke@1 56 _has_finalizer = access_flags.has_finalizer();
duke@1 57 _has_subklass = ik->subklass() != NULL;
coleenp@11407 58 _init_state = ik->init_state();
duke@1 59 _nonstatic_field_size = ik->nonstatic_field_size();
coleenp@360 60 _has_nonstatic_fields = ik->has_nonstatic_fields();
dholmes@41669 61 _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
vlivanov@31519 62 _is_anonymous = ik->is_anonymous();
duke@1 63 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
roland@28396 64 _has_injected_fields = -1;
jiangli@12369 65 _implementor = NULL; // we will fill these lazily
duke@1 66
duke@1 67 Thread *thread = Thread::current();
duke@1 68 if (ciObjectFactory::is_initialized()) {
duke@1 69 _loader = JNIHandles::make_local(thread, ik->class_loader());
duke@1 70 _protection_domain = JNIHandles::make_local(thread,
duke@1 71 ik->protection_domain());
duke@1 72 _is_shared = false;
duke@1 73 } else {
duke@1 74 Handle h_loader(thread, ik->class_loader());
duke@1 75 Handle h_protection_domain(thread, ik->protection_domain());
duke@1 76 _loader = JNIHandles::make_global(h_loader);
duke@1 77 _protection_domain = JNIHandles::make_global(h_protection_domain);
duke@1 78 _is_shared = true;
duke@1 79 }
duke@1 80
duke@1 81 // Lazy fields get filled in only upon request.
duke@1 82 _super = NULL;
duke@1 83 _java_mirror = NULL;
duke@1 84
duke@1 85 if (is_shared()) {
never@4571 86 if (h_k() != SystemDictionary::Object_klass()) {
duke@1 87 super();
duke@1 88 }
duke@1 89 //compute_nonstatic_fields(); // done outside of constructor
duke@1 90 }
duke@1 91
duke@1 92 _field_cache = NULL;
duke@1 93 }
duke@1 94
duke@1 95 // Version for unloaded classes:
duke@1 96 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
duke@1 97 jobject loader, jobject protection_domain)
coleenp@13728 98 : ciKlass(name, T_OBJECT)
duke@1 99 {
duke@1 100 assert(name->byte_at(0) != '[', "not an instance klass");
coleenp@13728 101 _init_state = (InstanceKlass::ClassState)0;
duke@1 102 _nonstatic_field_size = -1;
coleenp@360 103 _has_nonstatic_fields = false;
duke@1 104 _nonstatic_fields = NULL;
roland@28396 105 _has_injected_fields = -1;
vlivanov@31519 106 _is_anonymous = false;
duke@1 107 _loader = loader;
duke@1 108 _protection_domain = protection_domain;
duke@1 109 _is_shared = false;
duke@1 110 _super = NULL;
duke@1 111 _java_mirror = NULL;
duke@1 112 _field_cache = NULL;
duke@1 113 }
duke@1 114
duke@1 115
duke@1 116
duke@1 117 // ------------------------------------------------------------------
duke@1 118 // ciInstanceKlass::compute_shared_is_initialized
never@5925 119 void ciInstanceKlass::compute_shared_init_state() {
duke@1 120 GUARDED_VM_ENTRY(
coleenp@13728 121 InstanceKlass* ik = get_instanceKlass();
coleenp@11407 122 _init_state = ik->init_state();
duke@1 123 )
duke@1 124 }
duke@1 125
duke@1 126 // ------------------------------------------------------------------
duke@1 127 // ciInstanceKlass::compute_shared_has_subklass
duke@1 128 bool ciInstanceKlass::compute_shared_has_subklass() {
duke@1 129 GUARDED_VM_ENTRY(
coleenp@13728 130 InstanceKlass* ik = get_instanceKlass();
duke@1 131 _has_subklass = ik->subklass() != NULL;
duke@1 132 return _has_subklass;
duke@1 133 )
duke@1 134 }
duke@1 135
duke@1 136 // ------------------------------------------------------------------
duke@1 137 // ciInstanceKlass::loader
duke@1 138 oop ciInstanceKlass::loader() {
duke@1 139 ASSERT_IN_VM;
duke@1 140 return JNIHandles::resolve(_loader);
duke@1 141 }
duke@1 142
duke@1 143 // ------------------------------------------------------------------
duke@1 144 // ciInstanceKlass::loader_handle
duke@1 145 jobject ciInstanceKlass::loader_handle() {
duke@1 146 return _loader;
duke@1 147 }
duke@1 148
duke@1 149 // ------------------------------------------------------------------
duke@1 150 // ciInstanceKlass::protection_domain
duke@1 151 oop ciInstanceKlass::protection_domain() {
duke@1 152 ASSERT_IN_VM;
duke@1 153 return JNIHandles::resolve(_protection_domain);
duke@1 154 }
duke@1 155
duke@1 156 // ------------------------------------------------------------------
duke@1 157 // ciInstanceKlass::protection_domain_handle
duke@1 158 jobject ciInstanceKlass::protection_domain_handle() {
duke@1 159 return _protection_domain;
duke@1 160 }
duke@1 161
duke@1 162 // ------------------------------------------------------------------
duke@1 163 // ciInstanceKlass::field_cache
duke@1 164 //
duke@1 165 // Get the field cache associated with this klass.
duke@1 166 ciConstantPoolCache* ciInstanceKlass::field_cache() {
duke@1 167 if (is_shared()) {
duke@1 168 return NULL;
duke@1 169 }
duke@1 170 if (_field_cache == NULL) {
duke@1 171 assert(!is_java_lang_Object(), "Object has no fields");
duke@1 172 Arena* arena = CURRENT_ENV->arena();
duke@1 173 _field_cache = new (arena) ciConstantPoolCache(arena, 5);
duke@1 174 }
duke@1 175 return _field_cache;
duke@1 176 }
duke@1 177
duke@1 178 // ------------------------------------------------------------------
duke@1 179 // ciInstanceKlass::get_canonical_holder
duke@1 180 //
duke@1 181 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
duke@1 182 #ifdef ASSERT
duke@1 183 if (!(offset >= 0 && offset < layout_helper())) {
duke@1 184 tty->print("*** get_canonical_holder(%d) on ", offset);
duke@1 185 this->print();
duke@1 186 tty->print_cr(" ***");
duke@1 187 };
duke@1 188 assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
duke@1 189 #endif
duke@1 190
coleenp@360 191 if (offset < instanceOopDesc::base_offset_in_bytes()) {
duke@1 192 // All header offsets belong properly to java/lang/Object.
duke@1 193 return CURRENT_ENV->Object_klass();
duke@1 194 }
duke@1 195
duke@1 196 ciInstanceKlass* self = this;
duke@1 197 for (;;) {
duke@1 198 assert(self->is_loaded(), "must be loaded to have size");
duke@1 199 ciInstanceKlass* super = self->super();
coleenp@360 200 if (super == NULL || super->nof_nonstatic_fields() == 0 ||
coleenp@360 201 !super->contains_field_offset(offset)) {
duke@1 202 return self;
duke@1 203 } else {
duke@1 204 self = super; // return super->get_canonical_holder(offset)
duke@1 205 }
duke@1 206 }
duke@1 207 }
duke@1 208
duke@1 209 // ------------------------------------------------------------------
duke@1 210 // ciInstanceKlass::is_java_lang_Object
duke@1 211 //
duke@1 212 // Is this klass java.lang.Object?
coleenp@13728 213 bool ciInstanceKlass::is_java_lang_Object() const {
duke@1 214 return equals(CURRENT_ENV->Object_klass());
duke@1 215 }
duke@1 216
duke@1 217 // ------------------------------------------------------------------
duke@1 218 // ciInstanceKlass::uses_default_loader
kvn@17383 219 bool ciInstanceKlass::uses_default_loader() const {
twisti@4567 220 // Note: We do not need to resolve the handle or enter the VM
twisti@4567 221 // in order to test null-ness.
twisti@4567 222 return _loader == NULL;
twisti@4567 223 }
twisti@4567 224
twisti@4567 225 // ------------------------------------------------------------------
kvn@17383 226
kvn@17383 227 /**
kvn@17383 228 * Return basic type of boxed value for box klass or T_OBJECT if not.
kvn@17383 229 */
kvn@17383 230 BasicType ciInstanceKlass::box_klass_type() const {
kvn@17383 231 if (uses_default_loader() && is_loaded()) {
kvn@17383 232 return SystemDictionary::box_klass_type(get_Klass());
kvn@17383 233 } else {
kvn@17383 234 return T_OBJECT;
kvn@17383 235 }
kvn@17383 236 }
kvn@17383 237
kvn@17383 238 /**
kvn@17383 239 * Is this boxing klass?
kvn@17383 240 */
kvn@17383 241 bool ciInstanceKlass::is_box_klass() const {
kvn@17383 242 return is_java_primitive(box_klass_type());
kvn@17383 243 }
kvn@17383 244
kvn@17383 245 /**
kvn@17383 246 * Is this boxed value offset?
kvn@17383 247 */
kvn@17383 248 bool ciInstanceKlass::is_boxed_value_offset(int offset) const {
kvn@17383 249 BasicType bt = box_klass_type();
kvn@17383 250 return is_java_primitive(bt) &&
kvn@17383 251 (offset == java_lang_boxing_object::value_offset_in_bytes(bt));
kvn@17383 252 }
kvn@17383 253
kvn@17383 254 // ------------------------------------------------------------------
twisti@4567 255 // ciInstanceKlass::is_in_package
twisti@4567 256 //
twisti@4567 257 // Is this klass in the given package?
twisti@4567 258 bool ciInstanceKlass::is_in_package(const char* packagename, int len) {
twisti@4567 259 // To avoid class loader mischief, this test always rejects application classes.
twisti@4567 260 if (!uses_default_loader())
twisti@4567 261 return false;
twisti@4567 262 GUARDED_VM_ENTRY(
twisti@4567 263 return is_in_package_impl(packagename, len);
twisti@4567 264 )
twisti@4567 265 }
twisti@4567 266
twisti@4567 267 bool ciInstanceKlass::is_in_package_impl(const char* packagename, int len) {
twisti@4567 268 ASSERT_IN_VM;
twisti@4567 269
twisti@4567 270 // If packagename contains trailing '/' exclude it from the
twisti@4567 271 // prefix-test since we test for it explicitly.
twisti@4567 272 if (packagename[len - 1] == '/')
twisti@4567 273 len--;
twisti@4567 274
twisti@4567 275 if (!name()->starts_with(packagename, len))
twisti@4567 276 return false;
twisti@4567 277
twisti@4567 278 // Test if the class name is something like "java/lang".
twisti@4567 279 if ((len + 1) > name()->utf8_length())
twisti@4567 280 return false;
twisti@4567 281
twisti@4567 282 // Test for trailing '/'
twisti@4567 283 if ((char) name()->byte_at(len) != '/')
twisti@4567 284 return false;
twisti@4567 285
twisti@4567 286 // Make sure it's not actually in a subpackage:
twisti@4567 287 if (name()->index_of_at(len+1, "/", 1) >= 0)
twisti@4567 288 return false;
twisti@4567 289
twisti@4567 290 return true;
duke@1 291 }
duke@1 292
duke@1 293 // ------------------------------------------------------------------
duke@1 294 // ciInstanceKlass::print_impl
duke@1 295 //
duke@1 296 // Implementation of the print method.
duke@1 297 void ciInstanceKlass::print_impl(outputStream* st) {
duke@1 298 ciKlass::print_impl(st);
drchase@24424 299 GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i((address)loader()));)
duke@1 300 if (is_loaded()) {
duke@1 301 st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
duke@1 302 bool_to_str(is_initialized()),
duke@1 303 bool_to_str(has_finalizer()),
duke@1 304 bool_to_str(has_subklass()),
duke@1 305 layout_helper());
duke@1 306
duke@1 307 _flags.print_klass_flags();
duke@1 308
duke@1 309 if (_super) {
duke@1 310 st->print(" super=");
duke@1 311 _super->print_name();
duke@1 312 }
duke@1 313 if (_java_mirror) {
duke@1 314 st->print(" mirror=PRESENT");
duke@1 315 }
duke@1 316 } else {
duke@1 317 st->print(" loaded=false");
duke@1 318 }
duke@1 319 }
duke@1 320
duke@1 321 // ------------------------------------------------------------------
duke@1 322 // ciInstanceKlass::super
duke@1 323 //
duke@1 324 // Get the superklass of this klass.
duke@1 325 ciInstanceKlass* ciInstanceKlass::super() {
duke@1 326 assert(is_loaded(), "must be loaded");
duke@1 327 if (_super == NULL && !is_java_lang_Object()) {
duke@1 328 GUARDED_VM_ENTRY(
coleenp@13728 329 Klass* super_klass = get_instanceKlass()->super();
coleenp@13728 330 _super = CURRENT_ENV->get_instance_klass(super_klass);
duke@1 331 )
duke@1 332 }
duke@1 333 return _super;
duke@1 334 }
duke@1 335
duke@1 336 // ------------------------------------------------------------------
duke@1 337 // ciInstanceKlass::java_mirror
duke@1 338 //
duke@1 339 // Get the instance of java.lang.Class corresponding to this klass.
jrose@5884 340 // Cache it on this->_java_mirror.
duke@1 341 ciInstance* ciInstanceKlass::java_mirror() {
never@8725 342 if (is_shared()) {
never@8725 343 return ciKlass::java_mirror();
never@8725 344 }
duke@1 345 if (_java_mirror == NULL) {
jrose@5884 346 _java_mirror = ciKlass::java_mirror();
duke@1 347 }
duke@1 348 return _java_mirror;
duke@1 349 }
duke@1 350
duke@1 351 // ------------------------------------------------------------------
duke@1 352 // ciInstanceKlass::unique_concrete_subklass
duke@1 353 ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() {
duke@1 354 if (!is_loaded()) return NULL; // No change if class is not loaded
duke@1 355 if (!is_abstract()) return NULL; // Only applies to abstract classes.
duke@1 356 if (!has_subklass()) return NULL; // Must have at least one subklass.
duke@1 357 VM_ENTRY_MARK;
coleenp@13728 358 InstanceKlass* ik = get_instanceKlass();
duke@1 359 Klass* up = ik->up_cast_abstract();
coleenp@33611 360 assert(up->is_instance_klass(), "must be InstanceKlass");
duke@1 361 if (ik == up) {
duke@1 362 return NULL;
duke@1 363 }
coleenp@13728 364 return CURRENT_THREAD_ENV->get_instance_klass(up);
duke@1 365 }
duke@1 366
duke@1 367 // ------------------------------------------------------------------
duke@1 368 // ciInstanceKlass::has_finalizable_subclass
duke@1 369 bool ciInstanceKlass::has_finalizable_subclass() {
duke@1 370 if (!is_loaded()) return true;
duke@1 371 VM_ENTRY_MARK;
duke@1 372 return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
duke@1 373 }
duke@1 374
duke@1 375 // ------------------------------------------------------------------
duke@1 376 // ciInstanceKlass::get_field_by_offset
duke@1 377 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
duke@1 378 if (!is_static) {
duke@1 379 for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
duke@1 380 ciField* field = _nonstatic_fields->at(i);
duke@1 381 int field_off = field->offset_in_bytes();
duke@1 382 if (field_off == field_offset)
duke@1 383 return field;
duke@1 384 if (field_off > field_offset)
duke@1 385 break;
duke@1 386 // could do binary search or check bins, but probably not worth it
duke@1 387 }
duke@1 388 return NULL;
duke@1 389 }
duke@1 390 VM_ENTRY_MARK;
coleenp@13728 391 InstanceKlass* k = get_instanceKlass();
duke@1 392 fieldDescriptor fd;
duke@1 393 if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
duke@1 394 return NULL;
duke@1 395 }
duke@1 396 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
duke@1 397 return field;
duke@1 398 }
duke@1 399
kvn@217 400 // ------------------------------------------------------------------
never@4450 401 // ciInstanceKlass::get_field_by_name
never@4450 402 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
never@4450 403 VM_ENTRY_MARK;
coleenp@13728 404 InstanceKlass* k = get_instanceKlass();
never@4450 405 fieldDescriptor fd;
coleenp@13728 406 Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
never@4450 407 if (def == NULL) {
never@4450 408 return NULL;
never@4450 409 }
never@4450 410 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
never@4450 411 return field;
never@4450 412 }
never@4450 413
kvn@217 414
duke@1 415 static int sort_field_by_offset(ciField** a, ciField** b) {
duke@1 416 return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
duke@1 417 // (no worries about 32-bit overflow...)
duke@1 418 }
duke@1 419
duke@1 420 // ------------------------------------------------------------------
duke@1 421 // ciInstanceKlass::compute_nonstatic_fields
duke@1 422 int ciInstanceKlass::compute_nonstatic_fields() {
duke@1 423 assert(is_loaded(), "must be loaded");
duke@1 424
duke@1 425 if (_nonstatic_fields != NULL)
duke@1 426 return _nonstatic_fields->length();
duke@1 427
coleenp@360 428 if (!has_nonstatic_fields()) {
duke@1 429 Arena* arena = CURRENT_ENV->arena();
duke@1 430 _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
duke@1 431 return 0;
duke@1 432 }
duke@1 433 assert(!is_java_lang_Object(), "bootstrap OK");
duke@1 434
coleenp@360 435 // Size in bytes of my fields, including inherited fields.
kvn@591 436 int fsize = nonstatic_field_size() * heapOopSize;
coleenp@360 437
duke@1 438 ciInstanceKlass* super = this->super();
duke@1 439 GrowableArray<ciField*>* super_fields = NULL;
coleenp@360 440 if (super != NULL && super->has_nonstatic_fields()) {
kvn@591 441 int super_fsize = super->nonstatic_field_size() * heapOopSize;
coleenp@360 442 int super_flen = super->nof_nonstatic_fields();
duke@1 443 super_fields = super->_nonstatic_fields;
duke@1 444 assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
coleenp@360 445 // See if I am no larger than my super; if so, I can use his fields.
coleenp@360 446 if (fsize == super_fsize) {
coleenp@360 447 _nonstatic_fields = super_fields;
coleenp@360 448 return super_fields->length();
coleenp@360 449 }
duke@1 450 }
duke@1 451
duke@1 452 GrowableArray<ciField*>* fields = NULL;
duke@1 453 GUARDED_VM_ENTRY({
duke@1 454 fields = compute_nonstatic_fields_impl(super_fields);
duke@1 455 });
duke@1 456
duke@1 457 if (fields == NULL) {
duke@1 458 // This can happen if this class (java.lang.Class) has invisible fields.
vlivanov@31037 459 if (super_fields != NULL) {
vlivanov@31037 460 _nonstatic_fields = super_fields;
vlivanov@31037 461 return super_fields->length();
vlivanov@31037 462 } else {
vlivanov@31037 463 return 0;
vlivanov@31037 464 }
duke@1 465 }
duke@1 466
duke@1 467 int flen = fields->length();
duke@1 468
duke@1 469 // Now sort them by offset, ascending.
duke@1 470 // (In principle, they could mix with superclass fields.)
duke@1 471 fields->sort(sort_field_by_offset);
duke@1 472 _nonstatic_fields = fields;
duke@1 473 return flen;
duke@1 474 }
duke@1 475
duke@1 476 GrowableArray<ciField*>*
duke@1 477 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
duke@1 478 super_fields) {
duke@1 479 ASSERT_IN_VM;
duke@1 480 Arena* arena = CURRENT_ENV->arena();
duke@1 481 int flen = 0;
duke@1 482 GrowableArray<ciField*>* fields = NULL;
coleenp@13728 483 InstanceKlass* k = get_instanceKlass();
never@10546 484 for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
never@10546 485 if (fs.access_flags().is_static()) continue;
never@10546 486 flen += 1;
never@10546 487 }
duke@1 488
never@10546 489 // allocate the array:
never@10546 490 if (flen == 0) {
never@10546 491 return NULL; // return nothing if none are locally declared
never@10546 492 }
never@10546 493 if (super_fields != NULL) {
never@10546 494 flen += super_fields->length();
never@10546 495 }
never@10546 496 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
never@10546 497 if (super_fields != NULL) {
never@10546 498 fields->appendAll(super_fields);
never@10546 499 }
never@10546 500
never@10546 501 for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
never@10546 502 if (fs.access_flags().is_static()) continue;
drchase@20017 503 fieldDescriptor& fd = fs.field_descriptor();
never@10546 504 ciField* field = new (arena) ciField(&fd);
never@10546 505 fields->append(field);
duke@1 506 }
duke@1 507 assert(fields->length() == flen, "sanity");
duke@1 508 return fields;
duke@1 509 }
duke@1 510
roland@28933 511 bool ciInstanceKlass::compute_injected_fields_helper() {
roland@28396 512 ASSERT_IN_VM;
roland@28396 513 InstanceKlass* k = get_instanceKlass();
roland@28396 514
roland@28396 515 for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
roland@28396 516 if (fs.access_flags().is_static()) continue;
roland@28933 517 return true;
roland@28396 518 }
roland@28933 519 return false;
roland@28396 520 }
roland@28396 521
roland@28933 522 void ciInstanceKlass::compute_injected_fields() {
roland@28396 523 assert(is_loaded(), "must be loaded");
roland@28396 524
roland@28933 525 int has_injected_fields = 0;
roland@28396 526 if (super() != NULL && super()->has_injected_fields()) {
roland@28933 527 has_injected_fields = 1;
roland@28933 528 } else {
roland@28933 529 GUARDED_VM_ENTRY({
roland@28933 530 has_injected_fields = compute_injected_fields_helper() ? 1 : 0;
roland@28933 531 });
roland@28396 532 }
roland@28933 533 // may be concurrently initialized for shared ciInstanceKlass objects
roland@28933 534 assert(_has_injected_fields == -1 || _has_injected_fields == has_injected_fields, "broken concurrent initialization");
roland@28933 535 _has_injected_fields = has_injected_fields;
roland@28396 536 }
roland@28396 537
duke@1 538 // ------------------------------------------------------------------
duke@1 539 // ciInstanceKlass::find_method
duke@1 540 //
duke@1 541 // Find a method in this klass.
duke@1 542 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
duke@1 543 VM_ENTRY_MARK;
coleenp@13728 544 InstanceKlass* k = get_instanceKlass();
coleenp@8076 545 Symbol* name_sym = name->get_symbol();
coleenp@8076 546 Symbol* sig_sym= signature->get_symbol();
duke@1 547
coleenp@13728 548 Method* m = k->find_method(name_sym, sig_sym);
duke@1 549 if (m == NULL) return NULL;
duke@1 550
coleenp@13728 551 return CURRENT_THREAD_ENV->get_method(m);
duke@1 552 }
duke@1 553
duke@1 554 // ------------------------------------------------------------------
duke@1 555 // ciInstanceKlass::is_leaf_type
duke@1 556 bool ciInstanceKlass::is_leaf_type() {
duke@1 557 assert(is_loaded(), "must be loaded");
duke@1 558 if (is_shared()) {
duke@1 559 return is_final(); // approximately correct
duke@1 560 } else {
jiangli@12369 561 return !_has_subklass && (nof_implementors() == 0);
duke@1 562 }
duke@1 563 }
duke@1 564
duke@1 565 // ------------------------------------------------------------------
duke@1 566 // ciInstanceKlass::implementor
duke@1 567 //
duke@1 568 // Report an implementor of this interface.
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
coleenp@13728 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.
jiangli@12369 574 ciInstanceKlass* ciInstanceKlass::implementor() {
jiangli@12369 575 ciInstanceKlass* impl = _implementor;
duke@1 576 if (impl == NULL) {
duke@1 577 // Go into the VM to fetch the implementor.
duke@1 578 {
duke@1 579 VM_ENTRY_MARK;
coleenp@13728 580 Klass* k = get_instanceKlass()->implementor();
duke@1 581 if (k != NULL) {
coleenp@13728 582 if (k == get_instanceKlass()) {
jiangli@12369 583 // More than one implementors. Use 'this' in this case.
jiangli@12369 584 impl = this;
jiangli@12369 585 } else {
coleenp@13728 586 impl = CURRENT_THREAD_ENV->get_instance_klass(k);
jiangli@12369 587 }
duke@1 588 }
duke@1 589 }
duke@1 590 // Memoize this result.
duke@1 591 if (!is_shared()) {
jiangli@12369 592 _implementor = impl;
duke@1 593 }
duke@1 594 }
duke@1 595 return impl;
duke@1 596 }
minqi@14477 597
coleenp@44738 598 ciInstanceKlass* ciInstanceKlass::host_klass() {
coleenp@44738 599 assert(is_loaded(), "must be loaded");
coleenp@44738 600 if (is_anonymous()) {
coleenp@44738 601 VM_ENTRY_MARK
coleenp@44738 602 Klass* host_klass = get_instanceKlass()->host_klass();
coleenp@44738 603 return CURRENT_ENV->get_instance_klass(host_klass);
coleenp@44738 604 }
coleenp@44738 605 return NULL;
coleenp@44738 606 }
coleenp@44738 607
minqi@14477 608 // Utility class for printing of the contents of the static fields for
minqi@14477 609 // use by compilation replay. It only prints out the information that
minqi@14477 610 // could be consumed by the compiler, so for primitive types it prints
minqi@14477 611 // out the actual value. For Strings it's the actual string value.
minqi@14477 612 // For array types it it's first level array size since that's the
minqi@14477 613 // only value which statically unchangeable. For all other reference
minqi@14477 614 // types it simply prints out the dynamic type.
minqi@14477 615
minqi@14477 616 class StaticFinalFieldPrinter : public FieldClosure {
minqi@14477 617 outputStream* _out;
minqi@14477 618 const char* _holder;
minqi@14477 619 public:
minqi@14477 620 StaticFinalFieldPrinter(outputStream* out, const char* holder) :
minqi@14477 621 _out(out),
minqi@14477 622 _holder(holder) {
minqi@14477 623 }
minqi@14477 624 void do_field(fieldDescriptor* fd) {
minqi@14477 625 if (fd->is_final() && !fd->has_initial_value()) {
vlivanov@15471 626 ResourceMark rm;
minqi@14477 627 oop mirror = fd->field_holder()->java_mirror();
minqi@14477 628 _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii());
minqi@14477 629 switch (fd->field_type()) {
minqi@14477 630 case T_BYTE: _out->print_cr("%d", mirror->byte_field(fd->offset())); break;
minqi@14477 631 case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset())); break;
minqi@14477 632 case T_SHORT: _out->print_cr("%d", mirror->short_field(fd->offset())); break;
minqi@14477 633 case T_CHAR: _out->print_cr("%d", mirror->char_field(fd->offset())); break;
minqi@14477 634 case T_INT: _out->print_cr("%d", mirror->int_field(fd->offset())); break;
drchase@24424 635 case T_LONG: _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset()))); break;
minqi@14477 636 case T_FLOAT: {
minqi@14477 637 float f = mirror->float_field(fd->offset());
minqi@14477 638 _out->print_cr("%d", *(int*)&f);
minqi@14477 639 break;
minqi@14477 640 }
minqi@14477 641 case T_DOUBLE: {
minqi@14477 642 double d = mirror->double_field(fd->offset());
drchase@24424 643 _out->print_cr(INT64_FORMAT, *(int64_t*)&d);
minqi@14477 644 break;
minqi@14477 645 }
minqi@14477 646 case T_ARRAY: {
minqi@14477 647 oop value = mirror->obj_field_acquire(fd->offset());
minqi@14477 648 if (value == NULL) {
minqi@14477 649 _out->print_cr("null");
minqi@14477 650 } else {
minqi@14477 651 typeArrayOop ta = (typeArrayOop)value;
minqi@14477 652 _out->print("%d", ta->length());
minqi@14477 653 if (value->is_objArray()) {
minqi@14477 654 objArrayOop oa = (objArrayOop)value;
minqi@14477 655 const char* klass_name = value->klass()->name()->as_quoted_ascii();
minqi@14477 656 _out->print(" %s", klass_name);
minqi@14477 657 }
minqi@14477 658 _out->cr();
minqi@14477 659 }
minqi@14477 660 break;
minqi@14477 661 }
minqi@14477 662 case T_OBJECT: {
minqi@14477 663 oop value = mirror->obj_field_acquire(fd->offset());
minqi@14477 664 if (value == NULL) {
minqi@14477 665 _out->print_cr("null");
minqi@14477 666 } else if (value->is_instance()) {
minqi@14477 667 if (value->is_a(SystemDictionary::String_klass())) {
minqi@14477 668 _out->print("\"");
minqi@14477 669 _out->print_raw(java_lang_String::as_quoted_ascii(value));
minqi@14477 670 _out->print_cr("\"");
minqi@14477 671 } else {
minqi@14477 672 const char* klass_name = value->klass()->name()->as_quoted_ascii();
drchase@24424 673 _out->print_cr("%s", klass_name);
minqi@14477 674 }
minqi@14477 675 } else {
minqi@14477 676 ShouldNotReachHere();
minqi@14477 677 }
minqi@14477 678 break;
minqi@14477 679 }
minqi@14477 680 default:
minqi@14477 681 ShouldNotReachHere();
minqi@14477 682 }
minqi@14477 683 }
minqi@14477 684 }
minqi@14477 685 };
minqi@14477 686
minqi@14477 687
minqi@14477 688 void ciInstanceKlass::dump_replay_data(outputStream* out) {
vlivanov@15471 689 ResourceMark rm;
vlivanov@15471 690
minqi@14477 691 InstanceKlass* ik = get_instanceKlass();
minqi@14477 692 ConstantPool* cp = ik->constants();
minqi@14477 693
minqi@14477 694 // Try to record related loaded classes
minqi@14477 695 Klass* sub = ik->subklass();
minqi@14477 696 while (sub != NULL) {
coleenp@33611 697 if (sub->is_instance_klass()) {
minqi@14477 698 out->print_cr("instanceKlass %s", sub->name()->as_quoted_ascii());
minqi@14477 699 }
minqi@14477 700 sub = sub->next_sibling();
minqi@14477 701 }
minqi@14477 702
minqi@14477 703 // Dump out the state of the constant pool tags. During replay the
minqi@14477 704 // tags will be validated for things which shouldn't change and
minqi@14477 705 // classes will be resolved if the tags indicate that they were
minqi@14477 706 // resolved at compile time.
minqi@14477 707 out->print("ciInstanceKlass %s %d %d %d", ik->name()->as_quoted_ascii(),
minqi@14477 708 is_linked(), is_initialized(), cp->length());
minqi@14477 709 for (int index = 1; index < cp->length(); index++) {
minqi@14477 710 out->print(" %d", cp->tags()->at(index));
minqi@14477 711 }
minqi@14477 712 out->cr();
minqi@14477 713 if (is_initialized()) {
minqi@14477 714 // Dump out the static final fields in case the compilation relies
minqi@14477 715 // on their value for correct replay.
minqi@14477 716 StaticFinalFieldPrinter sffp(out, ik->name()->as_quoted_ascii());
minqi@14477 717 ik->do_local_static_fields(&sffp);
minqi@14477 718 }
minqi@14477 719 }