Skip to content

Commit f978f6f

Browse files
committed
8252689: Classes are loaded from jrt:/java.base even when CDS is used
Reviewed-by: iklam, ccheung
1 parent c5e63b6 commit f978f6f

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/hotspot/share/classfile/systemDictionaryShared.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,22 @@ static RunTimeSharedDictionary _unregistered_dictionary;
655655
static RunTimeSharedDictionary _dynamic_builtin_dictionary;
656656
static RunTimeSharedDictionary _dynamic_unregistered_dictionary;
657657

658+
659+
Handle SystemDictionaryShared::create_jar_manifest(const char* manifest_chars, size_t size, TRAPS) {
660+
typeArrayOop buf = oopFactory::new_byteArray((int)size, CHECK_NH);
661+
typeArrayHandle bufhandle(THREAD, buf);
662+
ArrayAccess<>::arraycopy_from_native(reinterpret_cast<const jbyte*>(manifest_chars),
663+
buf, typeArrayOopDesc::element_offset<jbyte>(0), size);
664+
Handle bais = JavaCalls::construct_new_instance(SystemDictionary::ByteArrayInputStream_klass(),
665+
vmSymbols::byte_array_void_signature(),
666+
bufhandle, CHECK_NH);
667+
// manifest = new Manifest(ByteArrayInputStream)
668+
Handle manifest = JavaCalls::construct_new_instance(SystemDictionary::Jar_Manifest_klass(),
669+
vmSymbols::input_stream_void_signature(),
670+
bais, CHECK_NH);
671+
return manifest;
672+
}
673+
658674
oop SystemDictionaryShared::shared_protection_domain(int index) {
659675
return ((objArrayOop)_shared_protection_domains.resolve())->obj_at(index);
660676
}
@@ -671,30 +687,17 @@ Handle SystemDictionaryShared::get_shared_jar_manifest(int shared_path_index, TR
671687
Handle manifest ;
672688
if (shared_jar_manifest(shared_path_index) == NULL) {
673689
SharedClassPathEntry* ent = FileMapInfo::shared_path(shared_path_index);
674-
long size = ent->manifest_size();
675-
if (size <= 0) {
690+
size_t size = (size_t)ent->manifest_size();
691+
if (size == 0) {
676692
return Handle();
677693
}
678694

679695
// ByteArrayInputStream bais = new ByteArrayInputStream(buf);
680696
const char* src = ent->manifest();
681697
assert(src != NULL, "No Manifest data");
682-
typeArrayOop buf = oopFactory::new_byteArray(size, CHECK_NH);
683-
typeArrayHandle bufhandle(THREAD, buf);
684-
ArrayAccess<>::arraycopy_from_native(reinterpret_cast<const jbyte*>(src),
685-
buf, typeArrayOopDesc::element_offset<jbyte>(0), size);
686-
687-
Handle bais = JavaCalls::construct_new_instance(SystemDictionary::ByteArrayInputStream_klass(),
688-
vmSymbols::byte_array_void_signature(),
689-
bufhandle, CHECK_NH);
690-
691-
// manifest = new Manifest(bais)
692-
manifest = JavaCalls::construct_new_instance(SystemDictionary::Jar_Manifest_klass(),
693-
vmSymbols::input_stream_void_signature(),
694-
bais, CHECK_NH);
698+
manifest = create_jar_manifest(src, size, THREAD);
695699
atomic_set_shared_jar_manifest(shared_path_index, manifest());
696700
}
697-
698701
manifest = Handle(THREAD, shared_jar_manifest(shared_path_index));
699702
assert(manifest.not_null(), "sanity");
700703
return manifest;

src/hotspot/share/classfile/systemDictionaryShared.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ class SystemDictionaryShared: public SystemDictionary {
320320
static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
321321
static bool empty_dumptime_table() NOT_CDS_RETURN_(true);
322322
static void start_dumping() NOT_CDS_RETURN;
323+
static Handle create_jar_manifest(const char* man, size_t size, TRAPS) NOT_CDS_RETURN_(NULL);
323324

324325
DEBUG_ONLY(static bool no_class_loading_should_happen() {return _no_class_loading_should_happen;})
325326

src/hotspot/share/memory/metaspaceShared.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,8 @@ void MetaspaceShared::preload_and_dump(TRAPS) {
10891089

10901090
HeapShared::init_for_dumping(THREAD);
10911091

1092+
// exercise the manifest processing code to ensure classes used by CDS are always archived
1093+
SystemDictionaryShared::create_jar_manifest("Manifest-Version: 1.0\n", strlen("Manifest-Version: 1.0\n"), THREAD);
10921094
// Rewrite and link classes
10931095
log_info(cds)("Rewriting and linking classes ...");
10941096

0 commit comments

Comments
 (0)