Skip to content

Commit 497a182

Browse files
author
Doug Simon
committed
8358254: [AOT] runtime/cds/appcds/applications/JavacBench.java#aot crashes with SEGV in ClassLoaderData::holder
Reviewed-by: never
1 parent c5f235c commit 497a182

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

src/hotspot/share/ci/ciMethodData.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ ciMethodData::ciMethodData(MethodData* md)
5757

5858

5959
static bool is_klass_loaded(Klass* k) {
60-
if (TrainingData::have_data()) {
61-
// If we're running in AOT mode some classes may not be loaded yet
62-
return !k->is_instance_klass() || InstanceKlass::cast(k)->is_loaded();
63-
}
64-
return true;
60+
return TrainingData::is_klass_loaded(k);
6561
}
6662

6763
// Check for entries that reference an unloaded method

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "oops/instanceMirrorKlass.hpp"
5050
#include "oops/method.inline.hpp"
5151
#include "oops/objArrayKlass.inline.hpp"
52+
#include "oops/trainingData.hpp"
5253
#include "oops/typeArrayOop.inline.hpp"
5354
#include "prims/jvmtiExport.hpp"
5455
#include "prims/methodHandles.hpp"
@@ -505,11 +506,15 @@ C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject b
505506
}
506507
} else if (JVMCIENV->isa_HotSpotMethodData(base_object)) {
507508
jlong base_address = (intptr_t) JVMCIENV->asMethodData(base_object);
508-
klass = *((Klass**) (intptr_t) (base_address + offset));
509-
if (klass == nullptr || !klass->is_loader_alive()) {
509+
Klass* k = *((Klass**) (intptr_t) (base_address + offset));
510+
if (k == nullptr || k->class_loader_data() == nullptr || !TrainingData::is_klass_loaded(k)) {
511+
return nullptr;
512+
}
513+
if (!k->is_loader_alive()) {
510514
// Klasses in methodData might be concurrently unloading so return null in that case.
511515
return nullptr;
512516
}
517+
klass = k;
513518
} else {
514519
goto unexpected;
515520
}

src/hotspot/share/oops/trainingData.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ class TrainingData : public Metadata {
283283
static bool need_data() { return AOTRecordTraining; } // Going to write
284284
static bool assembling_data() { return have_data() && CDSConfig::is_dumping_final_static_archive() && CDSConfig::is_dumping_aot_linked_classes(); }
285285

286+
static bool is_klass_loaded(Klass* k) {
287+
if (have_data()) {
288+
// If we're running in AOT mode some classes may not be loaded yet
289+
return !k->is_instance_klass() || InstanceKlass::cast(k)->is_loaded();
290+
}
291+
return true;
292+
}
293+
286294
template<typename Function>
287295
static void iterate(const Function& fn) { iterate(const_cast<Function&>(fn)); }
288296

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,7 @@ public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos)
443443
}
444444
}
445445

446-
static class RawItemProfile<T> {
447-
final int entries;
448-
final T[] items;
449-
final long[] counts;
450-
final long totalCount;
451-
452-
RawItemProfile(int entries, T[] items, long[] counts, long totalCount) {
453-
this.entries = entries;
454-
this.items = items;
455-
this.counts = counts;
456-
this.totalCount = totalCount;
457-
}
458-
}
446+
record RawItemProfile<T>(int entries, T[] items, long[] counts, long totalCount) {}
459447

460448
abstract static class AbstractTypeData extends CounterData {
461449

0 commit comments

Comments
 (0)