158 }
159 default:
160 ShouldNotReachHere();
161 break;
162 }
163
164 // Note: byte_no also appears in TemplateTable::resolve.
165 if (byte_no == 1) {
166 assert(invoke_code != Bytecodes::_invokevirtual &&
167 invoke_code != Bytecodes::_invokeinterface, "");
168 bool do_resolve = true;
169 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver
170 // has to be checked that it is a subclass of the current class every time this bytecode
171 // is executed.
172 if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
173 method->name() != vmSymbols::object_initializer_name()) {
174 do_resolve = false;
175 }
176 if (invoke_code == Bytecodes::_invokestatic) {
177 assert(method->method_holder()->is_initialized() ||
178 method->method_holder()->is_reentrant_initialization(JavaThread::current()),
179 "invalid class initialization state for invoke_static");
180
181 if (!VM_Version::supports_fast_class_init_checks() && method->needs_clinit_barrier()) {
182 // Don't mark invokestatic to method as resolved if the holder class has not yet completed
183 // initialization. An invokestatic must only proceed if the class is initialized, but if
184 // we resolve it before then that class initialization check is skipped.
185 //
186 // When fast class initialization checks are supported (VM_Version::supports_fast_class_init_checks() == true),
187 // template interpreter supports fast class initialization check for
188 // invokestatic which doesn't require call site re-resolution to
189 // enforce class initialization barrier.
190 do_resolve = false;
191 }
192 }
193 if (do_resolve) {
194 method_entry->set_bytecode1(invoke_code);
195 }
196 } else if (byte_no == 2) {
197 if (change_to_virtual) {
198 assert(invoke_code == Bytecodes::_invokeinterface, "");
411
412 #if INCLUDE_CDS_JAVA_HEAP
413 _archived_references_index = -1;
414 if (CDSConfig::is_dumping_heap()) {
415 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(constant_pool());
416 oop rr = HeapShared::scratch_resolved_references(src_cp);
417 if (rr != nullptr) {
418 _archived_references_index = HeapShared::append_root(rr);
419 }
420 }
421 #endif
422 }
423
424 void ConstantPoolCache::remove_resolved_field_entries_if_non_deterministic() {
425 ConstantPool* cp = constant_pool();
426 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
427 for (int i = 0; i < _resolved_field_entries->length(); i++) {
428 ResolvedFieldEntry* rfi = _resolved_field_entries->adr_at(i);
429 int cp_index = rfi->constant_pool_index();
430 bool archived = false;
431 bool resolved = rfi->is_resolved(Bytecodes::_getfield) ||
432 rfi->is_resolved(Bytecodes::_putfield);
433 if (resolved && AOTConstantPoolResolver::is_resolution_deterministic(src_cp, cp_index)) {
434 rfi->mark_and_relocate();
435 archived = true;
436 } else {
437 rfi->remove_unshareable_info();
438 }
439 if (resolved) {
440 LogStreamHandle(Trace, aot, resolve) log;
441 if (log.is_enabled()) {
442 ResourceMark rm;
443 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
444 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
445 Symbol* name = cp->uncached_name_ref_at(cp_index);
446 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
447 log.print("%s field CP entry [%3d]: %s => %s.%s:%s",
448 (archived ? "archived" : "reverted"),
449 cp_index,
450 cp->pool_holder()->name()->as_C_string(),
451 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
452 }
453 }
454 ArchiveBuilder::alloc_stats()->record_field_cp_entry(archived, resolved && !archived);
455 }
456 }
457
458 void ConstantPoolCache::remove_resolved_method_entries_if_non_deterministic() {
459 ConstantPool* cp = constant_pool();
460 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
461 for (int i = 0; i < _resolved_method_entries->length(); i++) {
462 ResolvedMethodEntry* rme = _resolved_method_entries->adr_at(i);
463 int cp_index = rme->constant_pool_index();
464 bool archived = false;
465 bool resolved = rme->is_resolved(Bytecodes::_invokevirtual) ||
466 rme->is_resolved(Bytecodes::_invokespecial) ||
467 rme->is_resolved(Bytecodes::_invokeinterface) ||
468 rme->is_resolved(Bytecodes::_invokehandle);
469
470 // Just for safety -- this should not happen, but do not archive if we ever see this.
471 resolved &= !(rme->is_resolved(Bytecodes::_invokestatic));
472
473 if (resolved && can_archive_resolved_method(src_cp, rme)) {
474 rme->mark_and_relocate(src_cp);
475 archived = true;
476 } else {
477 rme->remove_unshareable_info();
478 }
479 if (resolved) {
480 LogStreamHandle(Trace, aot, resolve) log;
481 if (log.is_enabled()) {
482 ResourceMark rm;
483 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
484 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
485 Symbol* name = cp->uncached_name_ref_at(cp_index);
486 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
487 log.print("%s%s method CP entry [%3d]: %s %s.%s:%s",
488 (archived ? "archived" : "reverted"),
489 (rme->is_resolved(Bytecodes::_invokeinterface) ? " interface" : ""),
490 cp_index,
491 cp->pool_holder()->name()->as_C_string(),
492 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
549 // update the vtable_index in method_entry (not implemented)
550 return false;
551 }
552
553 if (!method_entry->is_resolved(Bytecodes::_invokevirtual)) {
554 if (method_entry->method() == nullptr) {
555 return false;
556 }
557 if (method_entry->method()->is_continuation_native_intrinsic()) {
558 return false; // FIXME: corresponding stub is generated on demand during method resolution (see LinkResolver::resolve_static_call).
559 }
560 }
561
562 int cp_index = method_entry->constant_pool_index();
563 assert(src_cp->tag_at(cp_index).is_method() || src_cp->tag_at(cp_index).is_interface_method(), "sanity");
564
565 if (!AOTConstantPoolResolver::is_resolution_deterministic(src_cp, cp_index)) {
566 return false;
567 }
568
569 if (method_entry->is_resolved(Bytecodes::_invokeinterface) ||
570 method_entry->is_resolved(Bytecodes::_invokevirtual) ||
571 method_entry->is_resolved(Bytecodes::_invokespecial)) {
572 return true;
573 } else if (method_entry->is_resolved(Bytecodes::_invokehandle)) {
574 if (CDSConfig::is_dumping_method_handles()) {
575 // invokehandle depends on archived MethodType and LambdaForms.
576 return true;
577 } else {
578 return false;
579 }
580 } else {
581 return false;
582 }
583 }
584 #endif // INCLUDE_CDS
585
586 void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
587 assert(!is_shared(), "shared caches are not deallocated");
588 data->remove_handle(_resolved_references);
589 set_resolved_references(OopHandle());
|
158 }
159 default:
160 ShouldNotReachHere();
161 break;
162 }
163
164 // Note: byte_no also appears in TemplateTable::resolve.
165 if (byte_no == 1) {
166 assert(invoke_code != Bytecodes::_invokevirtual &&
167 invoke_code != Bytecodes::_invokeinterface, "");
168 bool do_resolve = true;
169 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver
170 // has to be checked that it is a subclass of the current class every time this bytecode
171 // is executed.
172 if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
173 method->name() != vmSymbols::object_initializer_name()) {
174 do_resolve = false;
175 }
176 if (invoke_code == Bytecodes::_invokestatic) {
177 assert(method->method_holder()->is_initialized() ||
178 method->method_holder()->is_reentrant_initialization(JavaThread::current()) ||
179 (CDSConfig::is_dumping_archive() && VM_Version::supports_fast_class_init_checks()),
180 "invalid class initialization state for invoke_static");
181
182 if (!VM_Version::supports_fast_class_init_checks() && method->needs_clinit_barrier()) {
183 // Don't mark invokestatic to method as resolved if the holder class has not yet completed
184 // initialization. An invokestatic must only proceed if the class is initialized, but if
185 // we resolve it before then that class initialization check is skipped.
186 //
187 // When fast class initialization checks are supported (VM_Version::supports_fast_class_init_checks() == true),
188 // template interpreter supports fast class initialization check for
189 // invokestatic which doesn't require call site re-resolution to
190 // enforce class initialization barrier.
191 do_resolve = false;
192 }
193 }
194 if (do_resolve) {
195 method_entry->set_bytecode1(invoke_code);
196 }
197 } else if (byte_no == 2) {
198 if (change_to_virtual) {
199 assert(invoke_code == Bytecodes::_invokeinterface, "");
412
413 #if INCLUDE_CDS_JAVA_HEAP
414 _archived_references_index = -1;
415 if (CDSConfig::is_dumping_heap()) {
416 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(constant_pool());
417 oop rr = HeapShared::scratch_resolved_references(src_cp);
418 if (rr != nullptr) {
419 _archived_references_index = HeapShared::append_root(rr);
420 }
421 }
422 #endif
423 }
424
425 void ConstantPoolCache::remove_resolved_field_entries_if_non_deterministic() {
426 ConstantPool* cp = constant_pool();
427 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
428 for (int i = 0; i < _resolved_field_entries->length(); i++) {
429 ResolvedFieldEntry* rfi = _resolved_field_entries->adr_at(i);
430 int cp_index = rfi->constant_pool_index();
431 bool archived = false;
432 bool resolved = rfi->is_resolved(Bytecodes::_getstatic) ||
433 rfi->is_resolved(Bytecodes::_putstatic) ||
434 rfi->is_resolved(Bytecodes::_getfield) ||
435 rfi->is_resolved(Bytecodes::_putfield);
436 if (resolved && AOTConstantPoolResolver::is_resolution_deterministic(src_cp, cp_index)) {
437 rfi->mark_and_relocate();
438 archived = true;
439 } else {
440 rfi->remove_unshareable_info();
441 }
442 if (resolved) {
443 LogStreamHandle(Trace, aot, resolve) log;
444 if (log.is_enabled()) {
445 ResourceMark rm;
446 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
447 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
448 Symbol* name = cp->uncached_name_ref_at(cp_index);
449 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
450 log.print("%s field CP entry [%3d]: %s => %s.%s:%s",
451 (archived ? "archived" : "reverted"),
452 cp_index,
453 cp->pool_holder()->name()->as_C_string(),
454 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
455 }
456 }
457 ArchiveBuilder::alloc_stats()->record_field_cp_entry(archived, resolved && !archived);
458 }
459 }
460
461 void ConstantPoolCache::remove_resolved_method_entries_if_non_deterministic() {
462 ConstantPool* cp = constant_pool();
463 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
464 for (int i = 0; i < _resolved_method_entries->length(); i++) {
465 ResolvedMethodEntry* rme = _resolved_method_entries->adr_at(i);
466 int cp_index = rme->constant_pool_index();
467 bool archived = false;
468 bool resolved = rme->is_resolved(Bytecodes::_invokevirtual) ||
469 rme->is_resolved(Bytecodes::_invokespecial) ||
470 //rme->is_resolved(Bytecodes::_invokestatic) || // FIXME -- leyden+JEP483 merge
471 rme->is_resolved(Bytecodes::_invokeinterface) ||
472 rme->is_resolved(Bytecodes::_invokehandle);
473 if (resolved && can_archive_resolved_method(src_cp, rme)) {
474 rme->mark_and_relocate(src_cp);
475 archived = true;
476 } else {
477 rme->remove_unshareable_info();
478 }
479 if (resolved) {
480 LogStreamHandle(Trace, aot, resolve) log;
481 if (log.is_enabled()) {
482 ResourceMark rm;
483 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
484 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
485 Symbol* name = cp->uncached_name_ref_at(cp_index);
486 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
487 log.print("%s%s method CP entry [%3d]: %s %s.%s:%s",
488 (archived ? "archived" : "reverted"),
489 (rme->is_resolved(Bytecodes::_invokeinterface) ? " interface" : ""),
490 cp_index,
491 cp->pool_holder()->name()->as_C_string(),
492 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
549 // update the vtable_index in method_entry (not implemented)
550 return false;
551 }
552
553 if (!method_entry->is_resolved(Bytecodes::_invokevirtual)) {
554 if (method_entry->method() == nullptr) {
555 return false;
556 }
557 if (method_entry->method()->is_continuation_native_intrinsic()) {
558 return false; // FIXME: corresponding stub is generated on demand during method resolution (see LinkResolver::resolve_static_call).
559 }
560 }
561
562 int cp_index = method_entry->constant_pool_index();
563 assert(src_cp->tag_at(cp_index).is_method() || src_cp->tag_at(cp_index).is_interface_method(), "sanity");
564
565 if (!AOTConstantPoolResolver::is_resolution_deterministic(src_cp, cp_index)) {
566 return false;
567 }
568
569 if (method_entry->is_resolved(Bytecodes::_invokestatic) ||
570 method_entry->is_resolved(Bytecodes::_invokeinterface) ||
571 method_entry->is_resolved(Bytecodes::_invokevirtual) ||
572 method_entry->is_resolved(Bytecodes::_invokespecial)) {
573 return true;
574 } else if (method_entry->is_resolved(Bytecodes::_invokehandle)) {
575 if (CDSConfig::is_dumping_method_handles()) {
576 // invokehandle depends on archived MethodType and LambdaForms.
577 return true;
578 } else {
579 return false;
580 }
581 } else {
582 return false;
583 }
584 }
585 #endif // INCLUDE_CDS
586
587 void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
588 assert(!is_shared(), "shared caches are not deallocated");
589 data->remove_handle(_resolved_references);
590 set_resolved_references(OopHandle());
|