26
26
#include " cds/heapShared.hpp"
27
27
#include " classfile/resolutionErrors.hpp"
28
28
#include " classfile/systemDictionary.hpp"
29
+ #include " classfile/systemDictionaryShared.hpp"
29
30
#include " classfile/vmClasses.hpp"
30
31
#include " interpreter/bytecodeStream.hpp"
31
32
#include " interpreter/bytecodes.hpp"
@@ -62,24 +63,6 @@ void ConstantPoolCacheEntry::initialize_entry(int index) {
62
63
assert (constant_pool_index () == index , " " );
63
64
}
64
65
65
- void ConstantPoolCacheEntry::verify_just_initialized (bool f2_used) {
66
- assert ((_indices & (~cp_index_mask)) == 0 , " sanity" );
67
- assert (_f1 == NULL , " sanity" );
68
- assert (_flags == 0 , " sanity" );
69
- if (!f2_used) {
70
- assert (_f2 == 0 , " sanity" );
71
- }
72
- }
73
-
74
- void ConstantPoolCacheEntry::reinitialize (bool f2_used) {
75
- _indices &= cp_index_mask;
76
- _f1 = NULL ;
77
- _flags = 0 ;
78
- if (!f2_used) {
79
- _f2 = 0 ;
80
- }
81
- }
82
-
83
66
int ConstantPoolCacheEntry::make_flags (TosState state,
84
67
int option_bits,
85
68
int field_index_or_method_params) {
@@ -700,66 +683,31 @@ void ConstantPoolCache::record_gc_epoch() {
700
683
_gc_epoch = Continuations::gc_epoch ();
701
684
}
702
685
703
- void ConstantPoolCache::verify_just_initialized () {
704
- DEBUG_ONLY (walk_entries_for_initialization (/* check_only = */ true ));
705
- }
686
+ void ConstantPoolCache::save_for_archive () {
687
+ #if INCLUDE_CDS
688
+ ConstantPoolCacheEntry* copy = NEW_C_HEAP_ARRAY (ConstantPoolCacheEntry, length (), mtClassShared);
689
+ for (int i = 0 ; i < length (); i++) {
690
+ copy[i] = *entry_at (i);
691
+ }
706
692
707
- void ConstantPoolCache::remove_unshareable_info () {
708
- walk_entries_for_initialization ( /* check_only = */ false );
693
+ SystemDictionaryShared::set_saved_cpcache_entries ( this , copy);
694
+ # endif
709
695
}
710
696
711
- void ConstantPoolCache::walk_entries_for_initialization (bool check_only) {
697
+ void ConstantPoolCache::remove_unshareable_info () {
698
+ #if INCLUDE_CDS
712
699
Arguments::assert_is_dumping_archive ();
713
- // When dumping the archive, we want to clean up the ConstantPoolCache
714
- // to remove any effect of linking due to the execution of Java code --
715
- // each ConstantPoolCacheEntry will have the same contents as if
716
- // ConstantPoolCache::initialize has just returned:
717
- //
718
- // - We keep the ConstantPoolCache::constant_pool_index() bits for all entries.
719
- // - We keep the "f2" field for entries used by invokedynamic and invokehandle
720
- // - All other bits in the entries are cleared to zero.
721
- ResourceMark rm;
722
-
723
- InstanceKlass* ik = constant_pool ()->pool_holder ();
724
- bool * f2_used = NEW_RESOURCE_ARRAY (bool , length ());
725
- memset (f2_used, 0 , sizeof (bool ) * length ());
726
-
727
- Thread* current = Thread::current ();
728
-
729
- // Find all the slots that we need to preserve f2
730
- for (int i = 0 ; i < ik->methods ()->length (); i++) {
731
- Method* m = ik->methods ()->at (i);
732
- RawBytecodeStream bcs (methodHandle (current, m));
733
- while (!bcs.is_last_bytecode ()) {
734
- Bytecodes::Code opcode = bcs.raw_next ();
735
- switch (opcode) {
736
- case Bytecodes::_invokedynamic: {
737
- int index = Bytes::get_native_u4 (bcs.bcp () + 1 );
738
- int cp_cache_index = constant_pool ()->invokedynamic_cp_cache_index (index );
739
- f2_used[cp_cache_index] = 1 ;
740
- }
741
- break ;
742
- case Bytecodes::_invokehandle: {
743
- int cp_cache_index = Bytes::get_native_u2 (bcs.bcp () + 1 );
744
- f2_used[cp_cache_index] = 1 ;
745
- }
746
- break ;
747
- default :
748
- break ;
749
- }
750
- }
751
- }
752
-
753
- if (check_only) {
754
- DEBUG_ONLY (
755
- for (int i=0 ; i<length (); i++) {
756
- entry_at (i)->verify_just_initialized (f2_used[i]);
757
- })
758
- } else {
759
- for (int i=0 ; i<length (); i++) {
760
- entry_at (i)->reinitialize (f2_used[i]);
761
- }
700
+ // <this> is the copy to be written into the archive. It's in
701
+ // the ArchiveBuilder's "buffer space". However, the saved_cpcache_entries
702
+ // are recorded with the original ConstantPoolCache object.
703
+ ConstantPoolCache* orig_cpc = ArchiveBuilder::current ()->get_src_obj (this );
704
+ ConstantPoolCacheEntry* saved = SystemDictionaryShared::get_saved_cpcache_entries_locked (orig_cpc);
705
+ for (int i=0 ; i<length (); i++) {
706
+ // Restore each entry to the initial state -- just after Rewriter::make_constant_pool_cache()
707
+ // has finished.
708
+ *entry_at (i) = saved[i];
762
709
}
710
+ #endif
763
711
}
764
712
765
713
void ConstantPoolCache::deallocate_contents (ClassLoaderData* data) {
@@ -768,6 +716,12 @@ void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
768
716
set_resolved_references (OopHandle ());
769
717
MetadataFactory::free_array<u2>(data, _reference_map);
770
718
set_reference_map (NULL );
719
+
720
+ #if INCLUDE_CDS
721
+ if (Arguments::is_dumping_archive ()) {
722
+ SystemDictionaryShared::remove_saved_cpcache_entries (this );
723
+ }
724
+ #endif
771
725
}
772
726
773
727
#if INCLUDE_CDS_JAVA_HEAP
0 commit comments