Skip to content

Commit 51f762d

Browse files
committedOct 9, 2023
Merge branch 'premain' into premain-precompile
2 parents a7ba4d6 + 4c252ff commit 51f762d

File tree

6 files changed

+84
-23
lines changed

6 files changed

+84
-23
lines changed
 

‎src/hotspot/share/cds/heapShared.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ class ArchivedObjectPermanentIndexTable: public ResourceHashtable<OopHandle, int
300300
static ArchivedObjectPermanentIndexTable* _permanent_index_table = nullptr;
301301

302302
int HeapShared::get_archived_object_permanent_index(oop obj) {
303+
if (CDSConfig::is_dumping_final_static_archive()) {
304+
log_warning(cds)("HeapShared::get_archived_object_permanent_index is not supported in new workflow yet");
305+
return -1;
306+
}
307+
303308
if (_permobj_segments <= 0) {
304309
return -1;
305310
}

‎src/hotspot/share/cds/metaspaceShared.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static void tmp_test_aot(ArchiveBuilder* builder, TRAPS) {
735735
}
736736
}
737737

738+
void test_cds_heap_access_api(TRAPS);
739+
738740
// Preload classes from a list, populate the shared spaces and dump to a
739741
// file.
740742
void MetaspaceShared::preload_and_dump() {
@@ -758,6 +760,9 @@ void MetaspaceShared::preload_and_dump() {
758760
if (CDSConfig::is_dumping_final_static_archive() && StoreCachedCode && CachedCodeFile != nullptr) {
759761
// We have just created the final image. Let's run the AOT compiler
760762
CDSConfig::enable_dumping_cached_code();
763+
if (log_is_enabled(Info, cds, jit)) {
764+
test_cds_heap_access_api(THREAD);
765+
}
761766
int count = MAX2(1, (int)(NewCodeParameter & 0x7fffffff));
762767
for (int i = 0; i < count; i++) {
763768
tmp_test_aot(&builder, CHECK);
@@ -916,7 +921,7 @@ void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS
916921
st.print("%s%sbin%sjava", Arguments::get_java_home(), os::file_separator(), os::file_separator());
917922
const char* cp = Arguments::get_appclasspath();
918923
if (cp != nullptr && strlen(cp) > 0 && strcmp(cp, ".") != 0) {
919-
st.print(" -cp %s", cp);
924+
st.print(" -cp "); st.print_raw(cp);
920925
}
921926
for (int i = 0; i < Arguments::num_jvm_flags(); i++) {
922927
st.print(" %s", Arguments::jvm_flags_array()[i]);
@@ -930,7 +935,7 @@ void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS
930935
if (CDSManualFinalImage) {
931936
tty->print_cr("-XX:+CDSManualFinalImage is specified");
932937
tty->print_cr("Please manually execute the following command to create the final CDS image:");
933-
tty->print_cr(" %s", cmd);
938+
tty->print(" "); tty->print_raw_cr(cmd);
934939
} else {
935940
log_info(cds)("Launching child process to create final CDS image:");
936941
log_info(cds)(" %s", cmd);

‎src/hotspot/share/classfile/systemDictionaryShared.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread(
204204
// k must not be a shared class.
205205
DumpTimeClassInfo* SystemDictionaryShared::get_info(InstanceKlass* k) {
206206
MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
207-
assert(!k->is_shared(), "sanity");
207+
//assert(!k->is_shared(), "sanity"); // FIXME new workflow
208208
return get_info_locked(k);
209209
}
210210

211211
DumpTimeClassInfo* SystemDictionaryShared::get_info_locked(InstanceKlass* k) {
212212
assert_lock_strong(DumpTimeTable_lock);
213-
//assert(!k->is_shared(), "sanity");
213+
//assert(!k->is_shared(), "sanity"); // FIXME new workflow
214214
DumpTimeClassInfo* info = _dumptime_table->get_info(k);
215215
assert(info != nullptr, "must be");
216216
return info;

‎src/hotspot/share/classfile/vmClasses.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void vmClasses::resolve_until(vmClassID limit_id, vmClassID &start_id, TRAPS) {
122122

123123
// TEMP: examples for using the HeapShared::get_archived_object_permanent_index() and HeapShared::get_archived_object()
124124
// APIs for the AOT compiler.
125-
static void test_cds_heap_access_api(TRAPS) {
125+
void test_cds_heap_access_api(TRAPS) {
126126
#ifdef INCLUDE_CDS_JAVA_HEAP
127127
const char* tests[] = {
128128
"",

‎src/hotspot/share/oops/constantPool.cpp

+28-12
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,10 @@ void ConstantPool::remove_unshareable_info() {
420420
// we always set _on_stack to true to avoid having to change _flags during runtime.
421421
_flags |= (_on_stack | _is_shared);
422422

423-
// FIXME-hack
424-
if (CDSPreimage == nullptr) {
425423
if (!ArchiveBuilder::current()->get_source_addr(_pool_holder)->is_linked()) {
426424
return;
427425
}
428-
}
426+
429427
if (is_for_method_handle_intrinsic()) {
430428
// This CP was created by Method::make_method_handle_intrinsic() and has nothing
431429
// that need to be removed/restored. It has no cpCache since the intrinsic methods
@@ -447,12 +445,14 @@ void ConstantPool::remove_unshareable_info() {
447445
}
448446

449447
void ConstantPool::archive_entries() {
450-
InstanceKlass* src_holder = ArchiveBuilder::current()->get_source_addr(_pool_holder);
448+
InstanceKlass* src_holder = ArchiveBuilder::current()->get_source_addr(pool_holder());
451449
assert(src_holder->is_linked(), "must be");
452450
ResourceMark rm;
453451
GrowableArray<bool> keep_cpcache(cache()->length(), cache()->length(), false);
454452
bool archived = false;
455453
int method_cpcache_index = 0; // cpcache index for Methodref/InterfaceMethodref
454+
bool preresolve = pool_holder()->is_shared_boot_class() || pool_holder()->is_shared_platform_class() ||
455+
pool_holder()->is_shared_app_class();
456456
for (int cp_index = 1; cp_index < length(); cp_index++) { // cp_index 0 is unused
457457
int cp_tag = tag_at(cp_index).value();
458458
switch (cp_tag) {
@@ -473,19 +473,30 @@ void ConstantPool::archive_entries() {
473473
tag_at_put(cp_index, JVM_CONSTANT_Dynamic);
474474
break;
475475
case JVM_CONSTANT_Class:
476-
archived = maybe_archive_resolved_klass_at(cp_index);
476+
if (preresolve) {
477+
archived = maybe_archive_resolved_klass_at(cp_index);
478+
} else {
479+
archived = false;
480+
}
481+
if (!archived) {
482+
// This referenced class cannot be archived. Revert the tag to UnresolvedClass,
483+
// so that the proper class loading and initialization can happen at runtime.
484+
int resolved_klass_index = klass_slot_at(cp_index).resolved_klass_index();
485+
resolved_klasses()->at_put(resolved_klass_index, nullptr);
486+
tag_at_put(cp_index, JVM_CONSTANT_UnresolvedClass);
487+
}
477488
ArchiveBuilder::alloc_stats()->record_klass_cp_entry(archived);
478489
break;
479490
case JVM_CONSTANT_Methodref:
480-
if (ArchiveMethodReferences) {
491+
if (ArchiveMethodReferences && preresolve) {
481492
archived = maybe_archive_resolved_method_ref_at(cp_index, method_cpcache_index, cp_tag);
482493
} else {
483494
archived = false;
484495
}
485496
ArchiveBuilder::alloc_stats()->record_method_cp_entry(archived);
486497
break;
487498
case JVM_CONSTANT_InterfaceMethodref:
488-
archived = false;
499+
archived = false; // FIXME: TODO
489500
ArchiveBuilder::alloc_stats()->record_method_cp_entry(archived);
490501
break;
491502
default:
@@ -510,6 +521,7 @@ void ConstantPool::archive_entries() {
510521
}
511522
}
512523

524+
#if 0
513525
static const char* get_type(Klass* buffered_k) {
514526
const char* type;
515527
Klass* src_k = ArchiveBuilder::current()->get_source_addr(buffered_k);
@@ -537,6 +549,7 @@ static const char* get_type(Klass* buffered_k) {
537549

538550
return type;
539551
}
552+
#endif
540553

541554
bool ConstantPool::maybe_archive_resolved_klass_at(int cp_index) {
542555
assert(ArchiveBuilder::current()->is_in_buffer_space(this), "must be");
@@ -560,19 +573,22 @@ bool ConstantPool::maybe_archive_resolved_klass_at(int cp_index) {
560573
if (ClassPrelinker::can_archive_resolved_klass(src_cp, cp_index)) {
561574
if (log_is_enabled(Debug, cds, resolve)) {
562575
ResourceMark rm;
576+
#if 0
577+
// FIXME: get_type() fails with runtime/cds/appcds/loaderConstraints/DynamicLoaderConstraintsTest.java
563578
log_debug(cds, resolve)("archived klass CP entry [%3d]: %s %s => %s %s%s", cp_index,
564579
get_type(pool_holder()), pool_holder()->name()->as_C_string(),
565580
get_type(k), k->name()->as_C_string(),
566581
pool_holder()->is_subtype_of(k) ? "" : " (not supertype)");
582+
#else
583+
log_debug(cds, resolve)("archived klass CP entry [%3d]: %s => %s%s", cp_index,
584+
pool_holder()->name()->as_C_string(),
585+
k->name()->as_C_string(),
586+
pool_holder()->is_subtype_of(k) ? "" : " (not supertype)");
587+
#endif
567588
}
568589
return true;
569590
}
570591
}
571-
572-
// This referenced class cannot be archived. Revert the tag to UnresolvedClass,
573-
// so that the proper class loading and initialization can happen at runtime.
574-
resolved_klasses()->at_put(resolved_klass_index, nullptr);
575-
tag_at_put(cp_index, JVM_CONSTANT_UnresolvedClass);
576592
return false;
577593
}
578594

‎test/hotspot/jtreg/premain/spring-petclinic/Makefile

+41-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#
3939
# *** NOTE: JDK 17 (or 21??) is needed to build spring-petclinic-3.1.0-SNAPSHOT.jar
4040
JDK17_HOME = /jdk3/official/jdk17
41-
PREMAIN_HOME = /jdk3/bld/le3/images/jdk
41+
PREMAIN_HOME = /jdk3/bld/le4/images/jdk
4242
#===============================================================================
4343

4444
# Usually there's no need to change the following
@@ -55,7 +55,12 @@ PC_STATIC_JSA = spring-petclinic.static.jsa
5555
PC_DYNAMIC_JSA = spring-petclinic.dynamic.jsa
5656
PC_CACHED_CODE = spring-petclinic.code.jsa
5757

58-
UNPACKED_CMDLINE = -cp @${PC_APP_UNPACKED}/classpath -DautoQuit=true -Dspring.aot.enabled=true ${PC_MAIN_CLASS}
58+
# new workflow
59+
PC_CDS_PREIMAGE = spring-petclinic.cds.preimage
60+
PC_CDS = spring-petclinic.cds
61+
62+
HEAP_SIZE = -Xmx2g
63+
UNPACKED_CMDLINE = $(HEAP_SIZE) -cp @${PC_APP_UNPACKED}/classpath -DautoQuit=true -Dspring.aot.enabled=true ${PC_MAIN_CLASS}
5964

6065
all: check git app aot
6166

@@ -111,23 +116,25 @@ ${PC_APP_UNPACKED}: ${PC_APP_JAR}
111116
| sed -e 's/ /:/g' > ${PC_APP_UNPACKED}/classpath
112117
$(MAKE) run17
113118

119+
#uncomment this to see the generated classes for dynamic proxies
120+
#SAVE_GEN_FILES=-Djdk.proxy.ProxyGenerator.saveGeneratedFiles=true
114121

115122
${PC_CLASSLIST}: ${PC_APP_UNPACKED}
116123
${PREMAIN_JAVA} -Xshare:off -XX:DumpLoadedClassList=${PC_CLASSLIST} \
117-
-Xlog:class+load=debug:file=spring-petclinic.classload.log \
124+
-Xlog:class+load=debug:file=spring-petclinic.classload.log ${SAVE_GEN_FILES} \
118125
${UNPACKED_CMDLINE}
119126
wc -lc ${PC_CLASSLIST}
120127

121128
${PC_STATIC_JSA}: ${PC_CLASSLIST}
122129
rm -f ${PC_STATIC_JSA}.log
123-
${PREMAIN_JAVA} -Xshare:dump -XX:SharedClassListFile=${PC_CLASSLIST} -cp @${PC_APP_UNPACKED}/classpath \
124-
-XX:SharedArchiveFile=${PC_STATIC_JSA} -XX:+ArchiveInvokeDynamic -Xlog:cds=debug,cds+heap=warning,cds+resolve=debug:file=${PC_STATIC_JSA}.log
130+
${PREMAIN_JAVA} -Xshare:dump -XX:SharedClassListFile=${PC_CLASSLIST} $(HEAP_SIZE) -cp @${PC_APP_UNPACKED}/classpath \
131+
-XX:SharedArchiveFile=${PC_STATIC_JSA} -XX:+ArchiveInvokeDynamic -Xlog:cds=debug,cds+class=debug,cds+heap=warning,cds+resolve=debug:file=${PC_STATIC_JSA}.log
125132
ls -l ${PC_STATIC_JSA}
126133

127134
${PC_DYNAMIC_JSA}: ${PC_STATIC_JSA}
128135
rm -f ${PC_DYNAMIC_JSA} ${PC_DYNAMIC_JSA}.log
129136
${PREMAIN_JAVA} -XX:SharedArchiveFile=${PC_STATIC_JSA} -XX:ArchiveClassesAtExit=${PC_DYNAMIC_JSA} \
130-
-Xlog:cds:file=${PC_DYNAMIC_JSA}.log \
137+
-Xlog:cds=debug,cds+class=debug:file=${PC_DYNAMIC_JSA}.log \
131138
-XX:+RecordTraining ${UNPACKED_CMDLINE}
132139
ls -l ${PC_DYNAMIC_JSA}
133140

@@ -146,13 +153,41 @@ runs: ${PC_STATIC_JSA}
146153
time ${PREMAIN_JAVA} -XX:SharedArchiveFile=${PC_STATIC_JSA} \
147154
-Xlog:init ${UNPACKED_CMDLINE}
148155

156+
# run with just dynamic CDS archive
157+
rund: ${PC_DYNAMIC_JSA}
158+
time ${PREMAIN_JAVA} -XX:SharedArchiveFile=${PC_DYNAMIC_JSA} \
159+
-Xlog:init ${UNPACKED_CMDLINE}
160+
149161
# run WITHOUT premain optimizatipn
150162
run0: ${PC_APP_UNPACKED}
151163
time ${PREMAIN_JAVA} -Xlog:init ${UNPACKED_CMDLINE}
152164

153165
run17: ${PC_APP_UNPACKED}
154166
${JDK17_JAVA} ${UNPACKED_CMDLINE}
155167

168+
#======================================== new workflow
169+
pre: ${PC_CDS_PREIMAGE}
170+
cds: ${PC_CDS}
171+
172+
${PC_CDS_PREIMAGE}: ${PC_APP_UNPACKED}
173+
rm -f ${PC_CDS_PREIMAGE} ${PC_CDS}
174+
${PREMAIN_JAVA} -XX:+ArchiveInvokeDynamic -XX:+UnlockDiagnosticVMOptions -XX:+CDSManualFinalImage -XX:CacheDataStore=${PC_CDS} \
175+
-Xlog:cds=debug,cds+class=debug,cds+heap=warning,cds+resolve=debug:file=${PC_CDS_PREIMAGE}.log \
176+
${UNPACKED_CMDLINE}
177+
ls -l ${PC_CDS_PREIMAGE}
178+
179+
${PC_CDS}: ${PC_CDS_PREIMAGE}
180+
rm -f ${PC_CDS}
181+
${PREMAIN_JAVA} -XX:+ArchiveInvokeDynamic -XX:+UnlockDiagnosticVMOptions -XX:CDSPreimage=${PC_CDS_PREIMAGE} -XX:CacheDataStore=${PC_CDS} \
182+
-Xlog:cds=debug,cds+class=debug,cds+heap=warning,cds+resolve=debug:file=${PC_CDS}.log \
183+
${UNPACKED_CMDLINE}
184+
ls -l ${PC_CDS}
185+
186+
# run with NEW workflow
187+
runn: ${PC_CDS}
188+
time ${PREMAIN_JAVA} -XX:SharedArchiveFile=${PC_CDS} -XX:+ReplayTraining -XX:+LoadCachedCode \
189+
-XX:CachedCodeFile=${PC_CDS}.jsa -Xlog:init -Xlog:scc=error ${UNPACKED_CMDLINE}
190+
156191
clean: clean0
157192
rm -rf *~ ${PC_REPO}
158193

0 commit comments

Comments
 (0)
Please sign in to comment.