Skip to content

Commit

Permalink
[Backport] 8231081: TestMetadataRetention fails due to missing symbol id
Browse files Browse the repository at this point in the history
Summary:

Test Plan: jdk/jfr

Reviewed-by: yuleil

Issue: dragonwell-project/dragonwell8#112
  • Loading branch information
D-D-H committed Jul 31, 2020
1 parent 0912115 commit c6607db
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 157 deletions.
37 changes: 32 additions & 5 deletions src/share/vm/jfr/recorder/checkpoint/jfrCheckpointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@

#include "precompiled.hpp"
#include "classfile/javaClasses.hpp"
#include "jfr/recorder/jfrRecorder.hpp"
#include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp"
#include "jfr/leakprofiler/leakProfiler.hpp"
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
#include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp"
#include "jfr/recorder/checkpoint/types/jfrTypeSet.hpp"
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdEpoch.hpp"
#include "jfr/recorder/jfrRecorder.hpp"
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
#include "jfr/recorder/service/jfrOptionSet.hpp"
#include "jfr/recorder/storage/jfrMemorySpace.inline.hpp"
#include "jfr/recorder/storage/jfrStorageUtils.inline.hpp"
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
#include "jfr/utilities/jfrBigEndian.hpp"
#include "jfr/utilities/jfrTypes.hpp"
#include "memory/resourceArea.hpp"
Expand Down Expand Up @@ -80,7 +83,7 @@ JfrCheckpointManager::~JfrCheckpointManager() {
if (_lock != NULL) {
delete _lock;
}
JfrTypeManager::clear();
JfrTypeManager::destroy();
}

static const size_t unlimited_mspace_size = 0;
Expand Down Expand Up @@ -332,6 +335,7 @@ size_t JfrCheckpointManager::write_epoch_transition_mspace() {

typedef DiscardOp<DefaultDiscarder<JfrBuffer> > DiscardOperation;
size_t JfrCheckpointManager::clear() {
JfrTypeSet::clear();
DiscardOperation discarder(mutexed); // mutexed discard mode
process_free_list(discarder, _free_list_mspace);
process_free_list(discarder, _epoch_transition_mspace);
Expand All @@ -353,12 +357,35 @@ size_t JfrCheckpointManager::write_safepoint_types() {
}

void JfrCheckpointManager::write_type_set() {
JfrTypeManager::write_type_set();
assert(!SafepointSynchronize::is_at_safepoint(), "invariant");
// can safepoint here
// TODO: CLDG lock does not exist in 11 - what shall we do?
// MutexLocker cld_lock(ClassLoaderDataGraph_lock);
MutexLocker package_table_lock(PackageTable_lock);
if (!LeakProfiler::is_running()) {
JfrCheckpointWriter writer(true, true, Thread::current());
JfrTypeSet::serialize(&writer, NULL, false);
return;
}
Thread* const t = Thread::current();
JfrCheckpointWriter leakp_writer(false, true, t);
JfrCheckpointWriter writer(false, true, t);
JfrTypeSet::serialize(&writer, &leakp_writer, false);
ObjectSampleCheckpoint::on_type_set(leakp_writer);
}

void JfrCheckpointManager::write_type_set_for_unloaded_classes() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
JfrTypeManager::write_type_set_for_unloaded_classes();
JfrCheckpointWriter writer(false, true, Thread::current());
const JfrCheckpointContext ctx = writer.context();
JfrTypeSet::serialize(&writer, NULL, true);
if (LeakProfiler::is_running()) {
ObjectSampleCheckpoint::on_type_set_unload(writer);
}
if (!JfrRecorder::is_recording()) {
// discard by rewind
writer.set_context(ctx);
}
}

void JfrCheckpointManager::create_thread_blob(JavaThread* jt) {
Expand Down
25 changes: 0 additions & 25 deletions src/share/vm/jfr/recorder/checkpoint/types/jfrType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "jfr/recorder/jfrRecorder.hpp"
#include "jfr/recorder/checkpoint/types/jfrThreadGroup.hpp"
#include "jfr/recorder/checkpoint/types/jfrThreadState.hpp"
#include "jfr/recorder/checkpoint/types/jfrTypeSet.hpp"
#include "jfr/support/jfrThreadLocal.hpp"
#include "jfr/writers/jfrJavaEventWriter.hpp"
#include "memory/metaspaceGCThresholdUpdater.hpp"
Expand Down Expand Up @@ -292,30 +291,6 @@ void VMOperationTypeConstant::serialize(JfrCheckpointWriter& writer) {
}
}

class TypeSetSerialization {
private:
JfrCheckpointWriter* _leakp_writer;
bool _class_unload;
public:
TypeSetSerialization(bool class_unload, JfrCheckpointWriter* leakp_writer = NULL) :
_leakp_writer(leakp_writer), _class_unload(class_unload) {}
void write(JfrCheckpointWriter& writer) {
JfrTypeSet::serialize(&writer, _leakp_writer, _class_unload);
}
};

void ClassUnloadTypeSet::serialize(JfrCheckpointWriter& writer) {
TypeSetSerialization type_set(true);
type_set.write(writer);
};

TypeSet::TypeSet(JfrCheckpointWriter* leakp_writer) : _leakp_writer(leakp_writer) {}

void TypeSet::serialize(JfrCheckpointWriter& writer) {
TypeSetSerialization type_set(false, _leakp_writer);
type_set.write(writer);
};

void ThreadStateConstant::serialize(JfrCheckpointWriter& writer) {
JfrThreadState::serialize(writer);
}
Expand Down
13 changes: 0 additions & 13 deletions src/share/vm/jfr/recorder/checkpoint/types/jfrType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class JfrThreadGroupConstant : public JfrSerializer {
void serialize(JfrCheckpointWriter& writer);
};

class ClassUnloadTypeSet : public JfrSerializer {
public:
void serialize(JfrCheckpointWriter& writer);
};

class FlagValueOriginConstant : public JfrSerializer {
public:
void serialize(JfrCheckpointWriter& writer);
Expand Down Expand Up @@ -117,14 +112,6 @@ class VMOperationTypeConstant : public JfrSerializer {
void serialize(JfrCheckpointWriter& writer);
};

class TypeSet : public JfrSerializer {
private:
JfrCheckpointWriter* _leakp_writer;
public:
explicit TypeSet(JfrCheckpointWriter* leakp_writer = NULL);
void serialize(JfrCheckpointWriter& writer);
};

class ThreadStateConstant : public JfrSerializer {
public:
void serialize(JfrCheckpointWriter& writer);
Expand Down
39 changes: 2 additions & 37 deletions src/share/vm/jfr/recorder/checkpoint/types/jfrTypeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
*/

#include "precompiled.hpp"
#include "jfr/jfr.hpp"
#include "jfr/leakprofiler/leakProfiler.hpp"
#include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp"
#include "jfr/metadata/jfrSerializer.hpp"
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
#include "jfr/recorder/checkpoint/types/jfrType.hpp"
Expand All @@ -35,9 +32,9 @@
#include "memory/resourceArea.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/semaphore.hpp"
#include "runtime/thread.inline.hpp"
#include "utilities/exceptions.hpp"
#include "runtime/semaphore.hpp"

class JfrSerializerRegistration : public JfrCHeapObj {
private:
Expand Down Expand Up @@ -120,7 +117,7 @@ typedef StopOnNullIterator<const List> Iterator;
static List types;
static List safepoint_types;

void JfrTypeManager::clear() {
void JfrTypeManager::destroy() {
SerializerRegistrationGuard guard;
Iterator iter(types);
JfrSerializerRegistration* registration;
Expand Down Expand Up @@ -152,38 +149,6 @@ void JfrTypeManager::write_safepoint_types(JfrCheckpointWriter& writer) {
}
}

void JfrTypeManager::write_type_set() {
assert(!SafepointSynchronize::is_at_safepoint(), "invariant");
// can safepoint here
MutexLocker module_lock(PackageTable_lock);
if (!LeakProfiler::is_running()) {
JfrCheckpointWriter writer(true, true, Thread::current());
TypeSet set;
set.serialize(writer);
return;
}
JfrCheckpointWriter leakp_writer(false, true, Thread::current());
JfrCheckpointWriter writer(false, true, Thread::current());
TypeSet set(&leakp_writer);
set.serialize(writer);
ObjectSampleCheckpoint::on_type_set(leakp_writer);
}

void JfrTypeManager::write_type_set_for_unloaded_classes() {
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
JfrCheckpointWriter writer(false, true, Thread::current());
const JfrCheckpointContext ctx = writer.context();
ClassUnloadTypeSet class_unload_set;
class_unload_set.serialize(writer);
if (LeakProfiler::is_running()) {
ObjectSampleCheckpoint::on_type_set_unload(writer);
}
if (!Jfr::is_recording()) {
// discard anything written
writer.set_context(ctx);
}
}

void JfrTypeManager::create_thread_blob(JavaThread* jt) {
assert(jt != NULL, "invariant");
ResourceMark rm(jt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ class JfrCheckpointWriter;
class JfrTypeManager : public AllStatic {
public:
static bool initialize();
static void clear();
static void destroy();
static void write_types(JfrCheckpointWriter& writer);
static void write_safepoint_types(JfrCheckpointWriter& writer);
static void write_type_set();
static void write_type_set_for_unloaded_classes();
static void create_thread_blob(JavaThread* jt);
static void write_thread_checkpoint(JavaThread* jt);
};
Expand Down
37 changes: 27 additions & 10 deletions src/share/vm/jfr/recorder/checkpoint/types/jfrTypeSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ inline uintptr_t package_name_hash(const char *s) {
return val;
}

/**
static traceid package_id(KlassPtr klass, JfrArtifactSet* artifacts) {
assert(klass != NULL, "invariant");
char* klass_name = klass->name()->as_C_string(); // uses ResourceMark declared in JfrTypeSet::serialize()
Expand All @@ -118,7 +117,6 @@ static traceid package_id(KlassPtr klass, JfrArtifactSet* artifacts) {
}
return CREATE_PACKAGE_ID(artifacts->markPackage(pkg_name, package_name_hash(pkg_name)));
}
*/

static traceid method_id(KlassPtr klass, MethodPtr method) {
assert(klass != NULL, "invariant");
Expand Down Expand Up @@ -170,8 +168,7 @@ static int write_klass(JfrCheckpointWriter* writer, KlassPtr klass, bool leakp)
theklass = obj_arr_klass->bottom_klass();
}
if (theklass->oop_is_instance()) {
// pkg_id = package_id(theklass, _artifacts);
pkg_id = 0;
pkg_id = package_id(theklass, _artifacts);
} else {
assert(theklass->oop_is_typeArray(), "invariant");
}
Expand Down Expand Up @@ -206,9 +203,14 @@ int write__klass__leakp(JfrCheckpointWriter* writer, const void* k) {
return write_klass(writer, klass, true);
}

static bool is_implied(const Klass* klass) {
assert(klass != NULL, "invariant");
return klass->is_subclass_of(SystemDictionary::ClassLoader_klass()) || klass == SystemDictionary::Object_klass();
}

static void do_implied(Klass* klass) {
assert(klass != NULL, "invariant");
if (klass->is_subclass_of(SystemDictionary::ClassLoader_klass()) || klass == SystemDictionary::Object_klass()) {
if (is_implied(klass)) {
if (_leakp_writer != NULL) {
SET_LEAKP(klass);
}
Expand Down Expand Up @@ -261,6 +263,16 @@ typedef JfrTypeWriterHost<KlassWriterImpl, TYPE_CLASS> KlassWriter;
typedef CompositeFunctor<KlassPtr, KlassWriter, KlassArtifactRegistrator> KlassWriterRegistration;
typedef JfrArtifactCallbackHost<KlassPtr, KlassWriterRegistration> KlassCallback;

template <>
class LeakPredicate<const Klass*> {
public:
LeakPredicate(bool class_unload) {}
bool operator()(const Klass* klass) {
assert(klass != NULL, "invariant");
return IS_LEAKP(klass) || is_implied(klass);
}
};

typedef LeakPredicate<KlassPtr> LeakKlassPredicate;
typedef JfrPredicatedTypeWriterImplHost<KlassPtr, LeakKlassPredicate, write__klass__leakp> LeakKlassWriterImpl;
typedef JfrTypeWriterHost<LeakKlassWriterImpl, TYPE_CLASS> LeakKlassWriter;
Expand Down Expand Up @@ -308,7 +320,6 @@ int write__artifact__package(JfrCheckpointWriter* writer, const void* p) {
return 1;
}

/**
typedef JfrTypeWriterImplHost<CStringEntryPtr, write__artifact__package> PackageEntryWriterImpl;
typedef JfrTypeWriterHost<PackageEntryWriterImpl, TYPE_PACKAGE> PackageEntryWriter;

Expand All @@ -318,7 +329,6 @@ void write_packages() {
PackageEntryWriter pw(_writer, _class_unload);
_artifacts->iterate_packages(pw);
}
*/

template <typename T>
static void do_previous_epoch_artifact(JfrArtifactClosure* callback, T* value) {
Expand Down Expand Up @@ -657,6 +667,12 @@ static void write_symbols() {
_artifacts->tally(sw);
}

static bool clear_artifacts = false;

void JfrTypeSet::clear() {
clear_artifacts = true;
}

typedef Wrapper<KlassPtr, ClearArtifact> ClearKlassBits;
typedef Wrapper<MethodPtr, ClearArtifact> ClearMethodFlag;
typedef MethodIteratorHost<ClearMethodFlag, ClearKlassBits, false> ClearKlassAndMethods;
Expand All @@ -668,7 +684,7 @@ static size_t teardown() {
assert(_writer != NULL, "invariant");
ClearKlassAndMethods clear(_writer);
_artifacts->iterate_klasses(clear);
_artifacts->clear();
JfrTypeSet::clear();
++checkpoint_id;
}
return total_count;
Expand All @@ -681,8 +697,9 @@ static void setup(JfrCheckpointWriter* writer, JfrCheckpointWriter* leakp_writer
if (_artifacts == NULL) {
_artifacts = new JfrArtifactSet(class_unload);
} else {
_artifacts->initialize(class_unload);
_artifacts->initialize(class_unload, clear_artifacts);
}
clear_artifacts = false;
assert(_artifacts != NULL, "invariant");
assert(!_artifacts->has_klass_entries(), "invariant");
}
Expand All @@ -699,7 +716,7 @@ size_t JfrTypeSet::serialize(JfrCheckpointWriter* writer, JfrCheckpointWriter* l
if (!write_klasses()) {
return 0;
}
// write_packages();
write_packages();
write_classloaders();
write_methods();
write_symbols();
Expand Down
1 change: 1 addition & 0 deletions src/share/vm/jfr/recorder/checkpoint/types/jfrTypeSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class JfrCheckpointWriter;

class JfrTypeSet : AllStatic {
public:
static void clear();
static size_t serialize(JfrCheckpointWriter* writer, JfrCheckpointWriter* leakp_writer, bool class_unload);
};

Expand Down
Loading

0 comments on commit c6607db

Please sign in to comment.