Skip to content
Permalink
Browse files
8277919: OldObjectSample event causing bloat in the class constant po…
…ol in JFR recording

Backport-of: 475ec8e6c5abc3431344d69bd46395e8c4b46e4c
  • Loading branch information
Jaroslav Bachorik committed Jan 6, 2022
1 parent ca59b64 commit 4a188e9112b9670964842a61262ae06703d66ca4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
@@ -202,7 +202,7 @@ static void prepare_for_resolution() {

static bool stack_trace_precondition(const ObjectSample* sample) {
assert(sample != NULL, "invariant");
return sample->has_stack_trace_id() && !sample->is_dead();
return sample->has_stack_trace_id() && !sample->is_dead() && !sample->stacktrace().valid();
}

class StackTraceBlobInstaller {
@@ -249,7 +249,7 @@ void StackTraceBlobInstaller::install(ObjectSample* sample) {
writer.write_type(TYPE_STACKTRACE);
writer.write_count(1);
ObjectSampleCheckpoint::write_stacktrace(stack_trace, writer);
blob = writer.copy();
blob = writer.move();
_cache.put(sample, blob);
sample->set_stacktrace(blob);
}
@@ -278,7 +278,7 @@ void ObjectSampleCheckpoint::on_rotation(const ObjectSampler* sampler) {
}

static bool is_klass_unloaded(traceid klass_id) {
assert(ClassLoaderDataGraph_lock->owned_by_self(), "invariant");
assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
return JfrKlassUnloading::is_unloaded(klass_id);
}

@@ -381,6 +381,12 @@ void ObjectSampleCheckpoint::write(const ObjectSampler* sampler, EdgeStore* edge
assert(sampler != NULL, "invariant");
assert(edge_store != NULL, "invariant");
assert(thread != NULL, "invariant");
{
// First install stacktrace blobs for the most recently added candidates.
MutexLocker lock(SafepointSynchronize::is_at_safepoint() ? nullptr : ClassLoaderDataGraph_lock);
// the lock is needed to ensure the unload lists do not grow in the middle of inspection.
install_stack_traces(sampler);
}
write_sample_blobs(sampler, emit_all, thread);
// write reference chains
if (!edge_store->is_empty()) {
@@ -243,6 +243,7 @@ int write__klass(JfrCheckpointWriter* writer, const void* k) {
int write__klass__leakp(JfrCheckpointWriter* writer, const void* k) {
assert(k != NULL, "invariant");
KlassPtr klass = (KlassPtr)k;
CLEAR_LEAKP(klass);
return write_klass(writer, klass, true);
}

@@ -848,7 +849,7 @@ class MethodIteratorHost {
private:
MethodCallback _method_cb;
KlassCallback _klass_cb;
MethodUsedPredicate<leakp> _method_used_predicate;
MethodUsedPredicate _method_used_predicate;
MethodFlagPredicate<leakp> _method_flag_predicate;
public:
MethodIteratorHost(JfrCheckpointWriter* writer,
@@ -146,16 +146,12 @@ class SymbolPredicate {
}
};

template <bool leakp>
class MethodUsedPredicate {
bool _current_epoch;
public:
MethodUsedPredicate(bool current_epoch) : _current_epoch(current_epoch) {}
bool operator()(const Klass* klass) {
if (_current_epoch) {
return leakp ? IS_LEAKP(klass) : METHOD_USED_THIS_EPOCH(klass);
}
return leakp ? IS_LEAKP(klass) : METHOD_USED_PREVIOUS_EPOCH(klass);
return _current_epoch ? METHOD_USED_THIS_EPOCH(klass) : METHOD_USED_PREVIOUS_EPOCH(klass);
}
};

1 comment on commit 4a188e9

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 4a188e9 Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.