6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "cds/archiveBuilder.hpp"
27 #include "cds/cdsConfig.hpp"
28 #include "cds/classPrelinker.hpp"
29 #include "cds/heapShared.hpp"
30 #include "classfile/resolutionErrors.hpp"
31 #include "classfile/systemDictionary.hpp"
32 #include "classfile/systemDictionaryShared.hpp"
33 #include "classfile/vmClasses.hpp"
34 #include "code/codeCache.hpp"
35 #include "interpreter/bytecodeStream.hpp"
36 #include "interpreter/bytecodes.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "interpreter/linkResolver.hpp"
39 #include "interpreter/rewriter.hpp"
40 #include "logging/log.hpp"
41 #include "logging/logStream.hpp"
42 #include "memory/metadataFactory.hpp"
43 #include "memory/metaspaceClosure.hpp"
44 #include "memory/resourceArea.hpp"
45 #include "oops/access.inline.hpp"
46 #include "oops/compressedOops.hpp"
47 #include "oops/constantPool.inline.hpp"
48 #include "oops/cpCache.inline.hpp"
49 #include "oops/method.inline.hpp"
50 #include "oops/objArrayOop.inline.hpp"
51 #include "oops/oop.inline.hpp"
52 #include "oops/resolvedFieldEntry.hpp"
53 #include "oops/resolvedIndyEntry.hpp"
54 #include "oops/resolvedMethodEntry.hpp"
55 #include "prims/methodHandles.hpp"
56 #include "runtime/arguments.hpp"
57 #include "runtime/atomic.hpp"
58 #include "runtime/handles.inline.hpp"
59 #include "runtime/mutexLocker.hpp"
60 #include "runtime/synchronizer.hpp"
61 #include "runtime/vm_version.hpp"
62 #include "utilities/macros.hpp"
63
64 // Implementation of ConstantPoolCache
65
66 template <class T>
67 static Array<T>* initialize_resolved_entries_array(ClassLoaderData* loader_data, GrowableArray<T> entries, TRAPS) {
68 Array<T>* resolved_entries;
69 if (entries.length() != 0) {
70 resolved_entries = MetadataFactory::new_array<T>(loader_data, entries.length(), CHECK_NULL);
71 for (int i = 0; i < entries.length(); i++) {
159 }
160 default:
161 ShouldNotReachHere();
162 break;
163 }
164
165 // Note: byte_no also appears in TemplateTable::resolve.
166 if (byte_no == 1) {
167 assert(invoke_code != Bytecodes::_invokevirtual &&
168 invoke_code != Bytecodes::_invokeinterface, "");
169 bool do_resolve = true;
170 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver
171 // has to be checked that it is a subclass of the current class every time this bytecode
172 // is executed.
173 if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
174 method->name() != vmSymbols::object_initializer_name()) {
175 do_resolve = false;
176 }
177 if (invoke_code == Bytecodes::_invokestatic) {
178 assert(method->method_holder()->is_initialized() ||
179 method->method_holder()->is_reentrant_initialization(JavaThread::current()),
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, "");
384
385 // Initialize resolved entry arrays with available data
386 Array<ResolvedFieldEntry>* resolved_field_entries = initialize_resolved_entries_array(loader_data, field_entries, CHECK_NULL);
387 Array<ResolvedIndyEntry>* resolved_indy_entries = initialize_resolved_entries_array(loader_data, indy_entries, CHECK_NULL);
388 Array<ResolvedMethodEntry>* resolved_method_entries = initialize_resolved_entries_array(loader_data, method_entries, CHECK_NULL);
389
390 return new (loader_data, size, MetaspaceObj::ConstantPoolCacheType, THREAD)
391 ConstantPoolCache(invokedynamic_map, resolved_indy_entries, resolved_field_entries, resolved_method_entries);
392 }
393
394 // Record the GC marking cycle when redefined vs. when found in the loom stack chunks.
395 void ConstantPoolCache::record_gc_epoch() {
396 _gc_epoch = CodeCache::gc_epoch();
397 }
398
399 #if INCLUDE_CDS
400 void ConstantPoolCache::remove_unshareable_info() {
401 assert(CDSConfig::is_dumping_archive(), "sanity");
402
403 if (_resolved_indy_entries != nullptr) {
404 for (int i = 0; i < _resolved_indy_entries->length(); i++) {
405 resolved_indy_entry_at(i)->remove_unshareable_info();
406 }
407 }
408 if (_resolved_field_entries != nullptr) {
409 remove_resolved_field_entries_if_non_deterministic();
410 }
411 if (_resolved_method_entries != nullptr) {
412 remove_resolved_method_entries_if_non_deterministic();
413 }
414 }
415
416 void ConstantPoolCache::remove_resolved_field_entries_if_non_deterministic() {
417 ConstantPool* cp = constant_pool();
418 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
419 for (int i = 0; i < _resolved_field_entries->length(); i++) {
420 ResolvedFieldEntry* rfi = _resolved_field_entries->adr_at(i);
421 int cp_index = rfi->constant_pool_index();
422 bool archived = false;
423 bool resolved = rfi->is_resolved(Bytecodes::_getfield) ||
424 rfi->is_resolved(Bytecodes::_putfield);
425 if (resolved && ClassPrelinker::is_resolution_deterministic(src_cp, cp_index)) {
426 rfi->mark_and_relocate();
427 archived = true;
428 } else {
429 rfi->remove_unshareable_info();
430 }
431 if (resolved) {
432 LogStreamHandle(Trace, cds, resolve) log;
433 if (log.is_enabled()) {
434 ResourceMark rm;
435 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
436 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
437 Symbol* name = cp->uncached_name_ref_at(cp_index);
438 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
439 log.print("%s field CP entry [%3d]: %s %s %s.%s:%s",
440 (archived ? "archived" : "reverted"),
441 cp_index,
442 cp->pool_holder()->name()->as_C_string(),
443 (archived ? "=>" : " "),
444 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
445 }
446 }
447 ArchiveBuilder::alloc_stats()->record_field_cp_entry(archived, resolved && !archived);
448 }
449 }
450
451 void ConstantPoolCache::remove_resolved_method_entries_if_non_deterministic() {
452 ConstantPool* cp = constant_pool();
453 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
454 for (int i = 0; i < _resolved_method_entries->length(); i++) {
455 ResolvedMethodEntry* rme = _resolved_method_entries->adr_at(i);
456 int cp_index = rme->constant_pool_index();
457 bool archived = false;
458 bool resolved = rme->is_resolved(Bytecodes::_invokevirtual) ||
459 rme->is_resolved(Bytecodes::_invokespecial) ||
460 rme->is_resolved(Bytecodes::_invokeinterface);
461
462 // Just for safety -- this should not happen, but do not archive if we ever see this.
463 resolved &= !(rme->is_resolved(Bytecodes::_invokehandle) ||
464 rme->is_resolved(Bytecodes::_invokestatic));
465
466 if (resolved && can_archive_resolved_method(rme)) {
467 rme->mark_and_relocate(src_cp);
468 archived = true;
469 } else {
470 rme->remove_unshareable_info();
471 }
472 if (resolved) {
473 LogStreamHandle(Trace, cds, resolve) log;
474 if (log.is_enabled()) {
475 ResourceMark rm;
476 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
477 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
478 Symbol* name = cp->uncached_name_ref_at(cp_index);
479 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
480 log.print("%s%s method CP entry [%3d]: %s %s.%s:%s",
481 (archived ? "archived" : "reverted"),
482 (rme->is_resolved(Bytecodes::_invokeinterface) ? " interface" : ""),
483 cp_index,
484 cp->pool_holder()->name()->as_C_string(),
485 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
486 if (archived) {
487 Klass* resolved_klass = cp->resolved_klass_at(klass_cp_index);
488 log.print(" => %s%s",
489 resolved_klass->name()->as_C_string(),
490 (rme->is_resolved(Bytecodes::_invokestatic) ? " *** static" : ""));
491 }
492 }
493 ArchiveBuilder::alloc_stats()->record_method_cp_entry(archived, resolved && !archived);
494 }
495 }
496 }
497
498 bool ConstantPoolCache::can_archive_resolved_method(ResolvedMethodEntry* method_entry) {
499 InstanceKlass* pool_holder = constant_pool()->pool_holder();
500 if (!(pool_holder->is_shared_boot_class() || pool_holder->is_shared_platform_class() ||
501 pool_holder->is_shared_app_class())) {
502 // Archiving resolved cp entries for classes from non-builtin loaders
503 // is not yet supported.
504 return false;
505 }
506
507 if (CDSConfig::is_dumping_dynamic_archive()) {
508 // InstanceKlass::methods() has been resorted. We need to
509 // update the vtable_index in method_entry (not implemented)
510 return false;
511 }
512
513 if (!method_entry->is_resolved(Bytecodes::_invokevirtual)) {
514 if (method_entry->method() == nullptr) {
515 return false;
516 }
517 if (method_entry->method()->is_continuation_native_intrinsic()) {
518 return false; // FIXME: corresponding stub is generated on demand during method resolution (see LinkResolver::resolve_static_call).
519 }
520 }
521
522 int cp_index = method_entry->constant_pool_index();
523 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(constant_pool());
524 assert(src_cp->tag_at(cp_index).is_method() || src_cp->tag_at(cp_index).is_interface_method(), "sanity");
525
526 if (!ClassPrelinker::is_resolution_deterministic(src_cp, cp_index)) {
527 return false;
528 }
529
530 if (method_entry->is_resolved(Bytecodes::_invokeinterface) ||
531 method_entry->is_resolved(Bytecodes::_invokevirtual) ||
532 method_entry->is_resolved(Bytecodes::_invokespecial)) {
533 return true;
534 } else {
535 // invokestatic and invokehandle are not supported yet.
536 return false;
537 }
538
539 }
540 #endif // INCLUDE_CDS
541
542 void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
543 assert(!is_shared(), "shared caches are not deallocated");
544 data->remove_handle(_resolved_references);
545 set_resolved_references(OopHandle());
546 MetadataFactory::free_array<u2>(data, _reference_map);
547 set_reference_map(nullptr);
548 #if INCLUDE_CDS
549 if (_resolved_indy_entries != nullptr) {
550 MetadataFactory::free_array<ResolvedIndyEntry>(data, _resolved_indy_entries);
551 _resolved_indy_entries = nullptr;
552 }
553 if (_resolved_field_entries != nullptr) {
554 MetadataFactory::free_array<ResolvedFieldEntry>(data, _resolved_field_entries);
555 _resolved_field_entries = nullptr;
556 }
557 if (_resolved_method_entries != nullptr) {
558 MetadataFactory::free_array<ResolvedMethodEntry>(data, _resolved_method_entries);
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "cds/aotConstantPoolResolver.hpp"
27 #include "cds/archiveBuilder.hpp"
28 #include "cds/cdsConfig.hpp"
29 #include "cds/heapShared.hpp"
30 #include "classfile/resolutionErrors.hpp"
31 #include "classfile/systemDictionary.hpp"
32 #include "classfile/systemDictionaryShared.hpp"
33 #include "classfile/vmClasses.hpp"
34 #include "code/codeCache.hpp"
35 #include "interpreter/bytecodeStream.hpp"
36 #include "interpreter/bytecodes.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "interpreter/linkResolver.hpp"
39 #include "interpreter/rewriter.hpp"
40 #include "logging/log.hpp"
41 #include "logging/logStream.hpp"
42 #include "memory/metadataFactory.hpp"
43 #include "memory/metaspaceClosure.hpp"
44 #include "memory/resourceArea.hpp"
45 #include "oops/access.inline.hpp"
46 #include "oops/compressedOops.hpp"
47 #include "oops/constantPool.inline.hpp"
48 #include "oops/cpCache.inline.hpp"
49 #include "oops/method.inline.hpp"
50 #include "oops/objArrayOop.inline.hpp"
51 #include "oops/oop.inline.hpp"
52 #include "oops/method.inline.hpp"
53 #include "oops/resolvedFieldEntry.hpp"
54 #include "oops/resolvedIndyEntry.hpp"
55 #include "oops/resolvedMethodEntry.hpp"
56 #include "prims/methodHandles.hpp"
57 #include "runtime/arguments.hpp"
58 #include "runtime/atomic.hpp"
59 #include "runtime/handles.inline.hpp"
60 #include "runtime/mutexLocker.hpp"
61 #include "runtime/synchronizer.hpp"
62 #include "runtime/vm_version.hpp"
63 #include "utilities/macros.hpp"
64
65 // Implementation of ConstantPoolCache
66
67 template <class T>
68 static Array<T>* initialize_resolved_entries_array(ClassLoaderData* loader_data, GrowableArray<T> entries, TRAPS) {
69 Array<T>* resolved_entries;
70 if (entries.length() != 0) {
71 resolved_entries = MetadataFactory::new_array<T>(loader_data, entries.length(), CHECK_NULL);
72 for (int i = 0; i < entries.length(); i++) {
160 }
161 default:
162 ShouldNotReachHere();
163 break;
164 }
165
166 // Note: byte_no also appears in TemplateTable::resolve.
167 if (byte_no == 1) {
168 assert(invoke_code != Bytecodes::_invokevirtual &&
169 invoke_code != Bytecodes::_invokeinterface, "");
170 bool do_resolve = true;
171 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver
172 // has to be checked that it is a subclass of the current class every time this bytecode
173 // is executed.
174 if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
175 method->name() != vmSymbols::object_initializer_name()) {
176 do_resolve = false;
177 }
178 if (invoke_code == Bytecodes::_invokestatic) {
179 assert(method->method_holder()->is_initialized() ||
180 method->method_holder()->is_reentrant_initialization(JavaThread::current()) ||
181 (CDSConfig::is_dumping_archive() && VM_Version::supports_fast_class_init_checks()),
182 "invalid class initialization state for invoke_static");
183
184 if (!VM_Version::supports_fast_class_init_checks() && method->needs_clinit_barrier()) {
185 // Don't mark invokestatic to method as resolved if the holder class has not yet completed
186 // initialization. An invokestatic must only proceed if the class is initialized, but if
187 // we resolve it before then that class initialization check is skipped.
188 //
189 // When fast class initialization checks are supported (VM_Version::supports_fast_class_init_checks() == true),
190 // template interpreter supports fast class initialization check for
191 // invokestatic which doesn't require call site re-resolution to
192 // enforce class initialization barrier.
193 do_resolve = false;
194 }
195 }
196 if (do_resolve) {
197 method_entry->set_bytecode1(invoke_code);
198 }
199 } else if (byte_no == 2) {
200 if (change_to_virtual) {
201 assert(invoke_code == Bytecodes::_invokeinterface, "");
386
387 // Initialize resolved entry arrays with available data
388 Array<ResolvedFieldEntry>* resolved_field_entries = initialize_resolved_entries_array(loader_data, field_entries, CHECK_NULL);
389 Array<ResolvedIndyEntry>* resolved_indy_entries = initialize_resolved_entries_array(loader_data, indy_entries, CHECK_NULL);
390 Array<ResolvedMethodEntry>* resolved_method_entries = initialize_resolved_entries_array(loader_data, method_entries, CHECK_NULL);
391
392 return new (loader_data, size, MetaspaceObj::ConstantPoolCacheType, THREAD)
393 ConstantPoolCache(invokedynamic_map, resolved_indy_entries, resolved_field_entries, resolved_method_entries);
394 }
395
396 // Record the GC marking cycle when redefined vs. when found in the loom stack chunks.
397 void ConstantPoolCache::record_gc_epoch() {
398 _gc_epoch = CodeCache::gc_epoch();
399 }
400
401 #if INCLUDE_CDS
402 void ConstantPoolCache::remove_unshareable_info() {
403 assert(CDSConfig::is_dumping_archive(), "sanity");
404
405 if (_resolved_indy_entries != nullptr) {
406 remove_resolved_indy_entries_if_non_deterministic();
407 }
408 if (_resolved_field_entries != nullptr) {
409 remove_resolved_field_entries_if_non_deterministic();
410 }
411 if (_resolved_method_entries != nullptr) {
412 remove_resolved_method_entries_if_non_deterministic();
413 }
414 }
415
416 void ConstantPoolCache::remove_resolved_field_entries_if_non_deterministic() {
417 ConstantPool* cp = constant_pool();
418 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
419 for (int i = 0; i < _resolved_field_entries->length(); i++) {
420 ResolvedFieldEntry* rfi = _resolved_field_entries->adr_at(i);
421 int cp_index = rfi->constant_pool_index();
422 bool archived = false;
423 bool resolved = rfi->is_resolved(Bytecodes::_getstatic) ||
424 rfi->is_resolved(Bytecodes::_putstatic) ||
425 rfi->is_resolved(Bytecodes::_getfield) ||
426 rfi->is_resolved(Bytecodes::_putfield);
427 if (resolved && AOTConstantPoolResolver::is_resolution_deterministic(src_cp, cp_index)) {
428 rfi->mark_and_relocate();
429 archived = true;
430 } else {
431 rfi->remove_unshareable_info();
432 }
433 if (resolved) {
434 LogStreamHandle(Trace, cds, resolve) log;
435 if (log.is_enabled()) {
436 ResourceMark rm;
437 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
438 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
439 Symbol* name = cp->uncached_name_ref_at(cp_index);
440 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
441 log.print("%s field CP entry [%3d]: %s => %s.%s:%s",
442 (archived ? "archived" : "reverted"),
443 cp_index,
444 cp->pool_holder()->name()->as_C_string(),
445 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
446 }
447 }
448 ArchiveBuilder::alloc_stats()->record_field_cp_entry(archived, resolved && !archived);
449 }
450 }
451
452 void ConstantPoolCache::remove_resolved_method_entries_if_non_deterministic() {
453 ConstantPool* cp = constant_pool();
454 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
455 for (int i = 0; i < _resolved_method_entries->length(); i++) {
456 ResolvedMethodEntry* rme = _resolved_method_entries->adr_at(i);
457 int cp_index = rme->constant_pool_index();
458 bool archived = false;
459 bool resolved = rme->is_resolved(Bytecodes::_invokevirtual) ||
460 rme->is_resolved(Bytecodes::_invokespecial) ||
461 rme->is_resolved(Bytecodes::_invokestatic) ||
462 rme->is_resolved(Bytecodes::_invokeinterface) ||
463 rme->is_resolved(Bytecodes::_invokehandle);
464 if (resolved && can_archive_resolved_method(src_cp, rme)) {
465 rme->mark_and_relocate(src_cp);
466 archived = true;
467 } else {
468 rme->remove_unshareable_info();
469 }
470 if (resolved) {
471 LogStreamHandle(Trace, cds, resolve) log;
472 if (log.is_enabled()) {
473 ResourceMark rm;
474 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
475 Symbol* klass_name = cp->klass_name_at(klass_cp_index);
476 Symbol* name = cp->uncached_name_ref_at(cp_index);
477 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
478 log.print("%s%s method CP entry [%3d]: %s %s.%s:%s",
479 (archived ? "archived" : "reverted"),
480 (rme->is_resolved(Bytecodes::_invokeinterface) ? " interface" : ""),
481 cp_index,
482 cp->pool_holder()->name()->as_C_string(),
483 klass_name->as_C_string(), name->as_C_string(), signature->as_C_string());
484 if (archived) {
485 Klass* resolved_klass = cp->resolved_klass_at(klass_cp_index);
486 log.print(" => %s%s",
487 resolved_klass->name()->as_C_string(),
488 (rme->is_resolved(Bytecodes::_invokestatic) ? " *** static" : ""));
489 }
490 }
491 ArchiveBuilder::alloc_stats()->record_method_cp_entry(archived, resolved && !archived);
492 }
493 }
494 }
495
496 void ConstantPoolCache::remove_resolved_indy_entries_if_non_deterministic() {
497 ConstantPool* cp = constant_pool();
498 ConstantPool* src_cp = ArchiveBuilder::current()->get_source_addr(cp);
499 for (int i = 0; i < _resolved_indy_entries->length(); i++) {
500 ResolvedIndyEntry* rei = _resolved_indy_entries->adr_at(i);
501 int cp_index = rei->constant_pool_index();
502 bool archived = false;
503 bool resolved = rei->is_resolved();
504 if (resolved && AOTConstantPoolResolver::is_resolution_deterministic(src_cp, cp_index)) {
505 rei->mark_and_relocate();
506 archived = true;
507 } else {
508 rei->remove_unshareable_info();
509 }
510 if (resolved) {
511 LogStreamHandle(Trace, cds, resolve) log;
512 if (log.is_enabled()) {
513 ResourceMark rm;
514 int bsm = cp->bootstrap_method_ref_index_at(cp_index);
515 int bsm_ref = cp->method_handle_index_at(bsm);
516 Symbol* bsm_name = cp->uncached_name_ref_at(bsm_ref);
517 Symbol* bsm_signature = cp->uncached_signature_ref_at(bsm_ref);
518 Symbol* bsm_klass = cp->klass_name_at(cp->uncached_klass_ref_index_at(bsm_ref));
519 log.print("%s indy CP entry [%3d]: %s (%d)",
520 (archived ? "archived" : "reverted"),
521 cp_index, cp->pool_holder()->name()->as_C_string(), i);
522 log.print(" %s %s.%s:%s", (archived ? "=>" : " "), bsm_klass->as_C_string(),
523 bsm_name->as_C_string(), bsm_signature->as_C_string());
524 }
525 ArchiveBuilder::alloc_stats()->record_indy_cp_entry(archived, resolved && !archived);
526 }
527 }
528 }
529
530 bool ConstantPoolCache::can_archive_invokehandle(ResolvedMethodEntry* rme) {
531 ConstantPool* cp = constant_pool();
532 assert(rme->is_resolved(Bytecodes::_invokehandle), "sanity");
533
534 int cp_index = rme->constant_pool_index();
535 int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
536 Klass* resolved_klass = cp->resolved_klass_at(klass_cp_index);
537 if (!resolved_klass->is_instance_klass()) {
538 // FIXME: can this ever happen?
539 return false;
540 }
541 // FIXME -- any class referenced by the archived CP entries should be added to ArchiveBuilder::classes, or should be
542 // filtered out.
543 return true;
544 }
545
546 bool ConstantPoolCache::can_archive_resolved_method(ConstantPool* src_cp, ResolvedMethodEntry* method_entry) {
547 InstanceKlass* pool_holder = constant_pool()->pool_holder();
548 if (!(pool_holder->is_shared_boot_class() || pool_holder->is_shared_platform_class() ||
549 pool_holder->is_shared_app_class())) {
550 // Archiving resolved cp entries for classes from non-builtin loaders
551 // is not yet supported.
552 return false;
553 }
554
555 if (CDSConfig::is_dumping_dynamic_archive()) {
556 // InstanceKlass::methods() has been resorted. We need to
557 // update the vtable_index in method_entry (not implemented)
558 return false;
559 }
560
561 if (!method_entry->is_resolved(Bytecodes::_invokevirtual)) {
562 if (method_entry->method() == nullptr) {
563 return false;
564 }
565 if (method_entry->method()->is_continuation_native_intrinsic()) {
566 return false; // FIXME: corresponding stub is generated on demand during method resolution (see LinkResolver::resolve_static_call).
567 }
568 }
569
570 int cp_index = method_entry->constant_pool_index();
571 assert(src_cp->tag_at(cp_index).is_method() || src_cp->tag_at(cp_index).is_interface_method(), "sanity");
572
573 if (!AOTConstantPoolResolver::is_resolution_deterministic(src_cp, cp_index)) {
574 return false;
575 }
576
577 if (method_entry->is_resolved(Bytecodes::_invokestatic) ||
578 method_entry->is_resolved(Bytecodes::_invokeinterface) ||
579 method_entry->is_resolved(Bytecodes::_invokevirtual) ||
580 method_entry->is_resolved(Bytecodes::_invokespecial)) {
581 return true;
582 } else if (method_entry->is_resolved(Bytecodes::_invokehandle)) {
583 if (CDSConfig::is_dumping_invokedynamic() && can_archive_invokehandle(method_entry)) {
584 // invokehandle depends on archived MethodType and LambdaForms.
585 return true;
586 } else {
587 return false;
588 }
589 } else {
590 return false;
591 }
592 }
593 #endif // INCLUDE_CDS
594
595 void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
596 assert(!is_shared(), "shared caches are not deallocated");
597 data->remove_handle(_resolved_references);
598 set_resolved_references(OopHandle());
599 MetadataFactory::free_array<u2>(data, _reference_map);
600 set_reference_map(nullptr);
601 #if INCLUDE_CDS
602 if (_resolved_indy_entries != nullptr) {
603 MetadataFactory::free_array<ResolvedIndyEntry>(data, _resolved_indy_entries);
604 _resolved_indy_entries = nullptr;
605 }
606 if (_resolved_field_entries != nullptr) {
607 MetadataFactory::free_array<ResolvedFieldEntry>(data, _resolved_field_entries);
608 _resolved_field_entries = nullptr;
609 }
610 if (_resolved_method_entries != nullptr) {
611 MetadataFactory::free_array<ResolvedMethodEntry>(data, _resolved_method_entries);
|