23
23
*/
24
24
25
25
#include " precompiled.hpp"
26
+ #include " cds/archiveBuilder.hpp"
26
27
#include " cds/heapShared.hpp"
27
28
#include " classfile/resolutionErrors.hpp"
28
29
#include " classfile/systemDictionary.hpp"
@@ -683,30 +684,30 @@ void ConstantPoolCache::record_gc_epoch() {
683
684
_gc_epoch = Continuations::gc_epoch ();
684
685
}
685
686
686
- void ConstantPoolCache::save_for_archive () {
687
+ void ConstantPoolCache::save_for_archive (TRAPS ) {
687
688
#if INCLUDE_CDS
688
- ConstantPoolCacheEntry* copy = NEW_C_HEAP_ARRAY (ConstantPoolCacheEntry, length (), mtClassShared);
689
+ ClassLoaderData* loader_data = constant_pool ()->pool_holder ()->class_loader_data ();
690
+ _initial_entries = MetadataFactory::new_array<ConstantPoolCacheEntry>(loader_data, length (), CHECK);
689
691
for (int i = 0 ; i < length (); i++) {
690
- copy[i] = *entry_at (i);
692
+ _initial_entries-> at_put (i, *entry_at (i) );
691
693
}
692
-
693
- SystemDictionaryShared::set_saved_cpcache_entries (this , copy);
694
694
#endif
695
695
}
696
696
697
697
void ConstantPoolCache::remove_unshareable_info () {
698
698
#if INCLUDE_CDS
699
699
Arguments::assert_is_dumping_archive ();
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 );
700
+ // <this> is the copy to be written into the archive. It's in the ArchiveBuilder's "buffer space".
701
+ // However, this->_initial_entries was not copied/relocated by the ArchiveBuilder, so it's
702
+ // still pointing to the array allocated inside save_for_archive() .
703
+ assert (_initial_entries != NULL , " archived cpcache must have been initialized " );
704
+ assert (! ArchiveBuilder::current ()-> is_in_buffer_space (_initial_entries), " must be " );
705
705
for (int i=0 ; i<length (); i++) {
706
706
// Restore each entry to the initial state -- just after Rewriter::make_constant_pool_cache()
707
707
// has finished.
708
- *entry_at (i) = saved[i] ;
708
+ *entry_at (i) = _initial_entries-> at (i) ;
709
709
}
710
+ _initial_entries = NULL ;
710
711
#endif
711
712
}
712
713
@@ -716,10 +717,11 @@ void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
716
717
set_resolved_references (OopHandle ());
717
718
MetadataFactory::free_array<u2>(data, _reference_map);
718
719
set_reference_map (NULL );
719
-
720
720
#if INCLUDE_CDS
721
- if (Arguments::is_dumping_archive ()) {
722
- SystemDictionaryShared::remove_saved_cpcache_entries (this );
721
+ if (_initial_entries != NULL ) {
722
+ Arguments::assert_is_dumping_archive ();
723
+ MetadataFactory::free_array<ConstantPoolCacheEntry>(data, _initial_entries);
724
+ _initial_entries = NULL ;
723
725
}
724
726
#endif
725
727
}
0 commit comments