Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk17 Public archive

Commit bd95c0c

Browse files
author
Markus Grönlund
committed
8269635: Stress test SEGV while emitting OldObjectSample
Reviewed-by: jbachorik
1 parent 00ef65f commit bd95c0c

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleCheckpoint.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,19 @@ Semaphore ThreadIdExclusiveAccess::_mutex_semaphore(1);
6969

7070
static bool has_thread_exited(traceid tid) {
7171
assert(tid != 0, "invariant");
72-
return unloaded_thread_id_set != NULL && JfrPredicate<traceid, compare_traceid>::test(unloaded_thread_id_set, tid);
73-
}
74-
75-
static bool add(GrowableArray<traceid>* set, traceid id) {
76-
assert(set != NULL, "invariant");
77-
return JfrMutablePredicate<traceid, compare_traceid>::test(set, id);
72+
if (unloaded_thread_id_set == NULL) {
73+
return false;
74+
}
75+
ThreadIdExclusiveAccess lock;
76+
return JfrPredicate<traceid, compare_traceid>::test(unloaded_thread_id_set, tid);
7877
}
7978

8079
static void add_to_unloaded_thread_set(traceid tid) {
8180
ThreadIdExclusiveAccess lock;
8281
if (unloaded_thread_id_set == NULL) {
8382
unloaded_thread_id_set = c_heap_allocate_array<traceid>();
8483
}
85-
add(unloaded_thread_id_set, tid);
84+
JfrMutablePredicate<traceid, compare_traceid>::test(unloaded_thread_id_set, tid);
8685
}
8786

8887
void ObjectSampleCheckpoint::on_thread_exit(JavaThread* jt) {
@@ -92,6 +91,15 @@ void ObjectSampleCheckpoint::on_thread_exit(JavaThread* jt) {
9291
}
9392
}
9493

94+
void ObjectSampleCheckpoint::clear() {
95+
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
96+
if (unloaded_thread_id_set != NULL) {
97+
delete unloaded_thread_id_set;
98+
unloaded_thread_id_set = NULL;
99+
}
100+
assert(unloaded_thread_id_set == NULL, "invariant");
101+
}
102+
95103
template <typename Processor>
96104
static void do_samples(ObjectSample* sample, const ObjectSample* end, Processor& processor) {
97105
assert(sample != NULL, "invariant");

src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ class Thread;
4141

4242
class ObjectSampleCheckpoint : AllStatic {
4343
friend class EventEmitter;
44+
friend class ObjectSampler;
4445
friend class PathToGcRootsOperation;
4546
friend class StackTraceBlobInstaller;
4647
private:
4748
static void add_to_leakp_set(const InstanceKlass* ik, traceid method_id);
4849
static int save_mark_words(const ObjectSampler* sampler, ObjectSampleMarker& marker, bool emit_all);
4950
static void write_stacktrace(const JfrStackTrace* trace, JfrCheckpointWriter& writer);
5051
static void write(const ObjectSampler* sampler, EdgeStore* edge_store, bool emit_all, Thread* thread);
52+
static void clear();
5153
public:
5254
static void on_type_set(JfrCheckpointWriter& writer);
5355
static void on_type_set_unload(JfrCheckpointWriter& writer);

src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "gc/shared/oopStorage.hpp"
2828
#include "gc/shared/oopStorageSet.hpp"
2929
#include "jfr/jfrEvents.hpp"
30+
#include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp"
3031
#include "jfr/leakprofiler/sampling/objectSample.hpp"
3132
#include "jfr/leakprofiler/sampling/objectSampler.hpp"
3233
#include "jfr/leakprofiler/sampling/sampleList.hpp"
@@ -107,6 +108,7 @@ ObjectSampler::~ObjectSampler() {
107108
bool ObjectSampler::create(size_t size) {
108109
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
109110
assert(_oop_storage != NULL, "should be already created");
111+
ObjectSampleCheckpoint::clear();
110112
assert(_instance == NULL, "invariant");
111113
_instance = new ObjectSampler(size);
112114
return _instance != NULL;

0 commit comments

Comments
 (0)