src/share/vm/jfr/recorder/checkpoint/types/jfrType.cpp

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 9858
b985cbb00e68
child 9862
f162232da105
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

apetushkov@9858 1 /*
apetushkov@9858 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
apetushkov@9858 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
apetushkov@9858 4 *
apetushkov@9858 5 * This code is free software; you can redistribute it and/or modify it
apetushkov@9858 6 * under the terms of the GNU General Public License version 2 only, as
apetushkov@9858 7 * published by the Free Software Foundation.
apetushkov@9858 8 *
apetushkov@9858 9 * This code is distributed in the hope that it will be useful, but WITHOUT
apetushkov@9858 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
apetushkov@9858 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
apetushkov@9858 12 * version 2 for more details (a copy is included in the LICENSE file that
apetushkov@9858 13 * accompanied this code).
apetushkov@9858 14 *
apetushkov@9858 15 * You should have received a copy of the GNU General Public License version
apetushkov@9858 16 * 2 along with this work; if not, write to the Free Software Foundation,
apetushkov@9858 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
apetushkov@9858 18 *
apetushkov@9858 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
apetushkov@9858 20 * or visit www.oracle.com if you need additional information or have any
apetushkov@9858 21 * questions.
apetushkov@9858 22 *
apetushkov@9858 23 */
apetushkov@9858 24
apetushkov@9858 25 #include "precompiled.hpp"
apetushkov@9858 26 #include "classfile/javaClasses.hpp"
apetushkov@9858 27 #include "code/codeBlob.hpp"
apetushkov@9858 28 #include "code/codeCache.hpp"
apetushkov@9858 29 #include "gc_interface/gcCause.hpp"
apetushkov@9858 30 #include "gc_interface/gcName.hpp"
apetushkov@9858 31 #include "gc_implementation/shared/gcTrace.hpp"
apetushkov@9858 32 #include "gc_implementation/shared/gcWhen.hpp"
apetushkov@9858 33 #include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp"
apetushkov@9858 34 #include "jfr/leakprofiler/leakProfiler.hpp"
apetushkov@9858 35 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
apetushkov@9858 36 #include "jfr/recorder/checkpoint/types/jfrType.hpp"
apetushkov@9858 37 #include "jfr/recorder/jfrRecorder.hpp"
apetushkov@9858 38 #include "jfr/recorder/checkpoint/types/jfrThreadGroup.hpp"
apetushkov@9858 39 #include "jfr/recorder/checkpoint/types/jfrThreadState.hpp"
apetushkov@9858 40 #include "jfr/recorder/checkpoint/types/jfrTypeSet.hpp"
apetushkov@9858 41 #include "jfr/support/jfrThreadLocal.hpp"
apetushkov@9858 42 #include "jfr/writers/jfrJavaEventWriter.hpp"
apetushkov@9858 43 #include "memory/metaspaceGCThresholdUpdater.hpp"
apetushkov@9858 44 #include "memory/referenceType.hpp"
apetushkov@9858 45 #include "memory/universe.hpp"
apetushkov@9858 46 #include "runtime/mutexLocker.hpp"
apetushkov@9858 47 #include "runtime/osThread.hpp"
apetushkov@9858 48 #include "runtime/safepoint.hpp"
apetushkov@9858 49 #include "runtime/synchronizer.hpp"
apetushkov@9858 50 #include "runtime/thread.inline.hpp"
apetushkov@9858 51 #include "runtime/vm_operations.hpp"
apetushkov@9858 52
apetushkov@9858 53 #ifdef COMPILER2
apetushkov@9858 54 #include "opto/compile.hpp"
apetushkov@9858 55 #include "opto/node.hpp"
apetushkov@9858 56 #endif
apetushkov@9858 57 #if INCLUDE_ALL_GCS
apetushkov@9858 58 //#include "gc_implementation/g1/g1HeapRegionTraceType.hpp"
apetushkov@9858 59 #include "gc_implementation/g1/g1YCTypes.hpp"
apetushkov@9858 60 #endif
apetushkov@9858 61
apetushkov@9858 62 // Requires a ResourceMark for get_thread_name/as_utf8
apetushkov@9858 63 class JfrCheckpointThreadClosure : public ThreadClosure {
apetushkov@9858 64 private:
apetushkov@9858 65 JfrCheckpointWriter& _writer;
apetushkov@9858 66 JfrCheckpointContext _ctx;
apetushkov@9858 67 const intptr_t _count_position;
apetushkov@9858 68 Thread* const _curthread;
apetushkov@9858 69 u4 _count;
apetushkov@9858 70
apetushkov@9858 71 public:
apetushkov@9858 72 JfrCheckpointThreadClosure(JfrCheckpointWriter& writer) : _writer(writer),
apetushkov@9858 73 _ctx(writer.context()),
apetushkov@9858 74 _count_position(writer.reserve(sizeof(u4))),
apetushkov@9858 75 _curthread(Thread::current()),
apetushkov@9858 76 _count(0) {
apetushkov@9858 77 }
apetushkov@9858 78
apetushkov@9858 79 ~JfrCheckpointThreadClosure() {
apetushkov@9858 80 if (_count == 0) {
apetushkov@9858 81 // restore
apetushkov@9858 82 _writer.set_context(_ctx);
apetushkov@9858 83 return;
apetushkov@9858 84 }
apetushkov@9858 85 _writer.write_count(_count, _count_position);
apetushkov@9858 86 }
apetushkov@9858 87
apetushkov@9858 88 void do_thread(Thread* t);
apetushkov@9858 89 };
apetushkov@9858 90
apetushkov@9858 91 // Requires a ResourceMark for get_thread_name/as_utf8
apetushkov@9858 92 void JfrCheckpointThreadClosure::do_thread(Thread* t) {
apetushkov@9858 93 assert(t != NULL, "invariant");
apetushkov@9858 94 assert_locked_or_safepoint(Threads_lock);
apetushkov@9858 95 const JfrThreadLocal* const tl = t->jfr_thread_local();
apetushkov@9858 96 assert(tl != NULL, "invariant");
apetushkov@9858 97 if (tl->is_dead()) {
apetushkov@9858 98 return;
apetushkov@9858 99 }
apetushkov@9858 100 ++_count;
apetushkov@9858 101 _writer.write_key(tl->thread_id());
apetushkov@9858 102 _writer.write(t->name());
apetushkov@9858 103 const OSThread* const os_thread = t->osthread();
apetushkov@9858 104 _writer.write<traceid>(os_thread != NULL ? os_thread->thread_id() : 0);
apetushkov@9858 105 if (t->is_Java_thread()) {
apetushkov@9858 106 JavaThread* const jt = (JavaThread*)t;
apetushkov@9858 107 _writer.write(jt->name());
apetushkov@9858 108 _writer.write(java_lang_Thread::thread_id(jt->threadObj()));
apetushkov@9858 109 _writer.write(JfrThreadGroup::thread_group_id(jt, _curthread));
apetushkov@9858 110 // since we are iterating threads during a safepoint, also issue notification
apetushkov@9858 111 JfrJavaEventWriter::notify(jt);
apetushkov@9858 112 return;
apetushkov@9858 113 }
apetushkov@9858 114 _writer.write((const char*)NULL); // java name
apetushkov@9858 115 _writer.write((traceid)0); // java thread id
apetushkov@9858 116 _writer.write((traceid)0); // java thread group
apetushkov@9858 117 }
apetushkov@9858 118
apetushkov@9858 119 void JfrThreadConstantSet::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 120 assert(SafepointSynchronize::is_at_safepoint(), "invariant");
apetushkov@9858 121 JfrCheckpointThreadClosure tc(writer);
apetushkov@9858 122 Threads::threads_do(&tc);
apetushkov@9858 123 }
apetushkov@9858 124
apetushkov@9858 125 void JfrThreadGroupConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 126 assert(SafepointSynchronize::is_at_safepoint(), "invariant");
apetushkov@9858 127 JfrThreadGroup::serialize(writer);
apetushkov@9858 128 }
apetushkov@9858 129
apetushkov@9858 130 static const char* flag_value_origin_to_string(Flag::Flags origin) {
apetushkov@9858 131 switch (origin) {
apetushkov@9858 132 case Flag::DEFAULT: return "Default";
apetushkov@9858 133 case Flag::COMMAND_LINE: return "Command line";
apetushkov@9858 134 case Flag::ENVIRON_VAR: return "Environment variable";
apetushkov@9858 135 case Flag::CONFIG_FILE: return "Config file";
apetushkov@9858 136 case Flag::MANAGEMENT: return "Management";
apetushkov@9858 137 case Flag::ERGONOMIC: return "Ergonomic";
apetushkov@9858 138 case Flag::ATTACH_ON_DEMAND: return "Attach on demand";
apetushkov@9858 139 case Flag::INTERNAL: return "Internal";
apetushkov@9858 140 default: ShouldNotReachHere(); return "";
apetushkov@9858 141 }
apetushkov@9858 142 }
apetushkov@9858 143
apetushkov@9858 144 void FlagValueOriginConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 145 static const u4 nof_entries = Flag::LAST_VALUE_ORIGIN + 1;
apetushkov@9858 146 writer.write_count(nof_entries);
apetushkov@9858 147 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 148 writer.write_key(i);
apetushkov@9858 149 writer.write(flag_value_origin_to_string((Flag::Flags)i));
apetushkov@9858 150 }
apetushkov@9858 151 }
apetushkov@9858 152
apetushkov@9858 153 void MonitorInflateCauseConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 154 // XXX no such counters. implement?
apetushkov@9858 155 // static const u4 nof_entries = ObjectSynchronizer::inflate_cause_nof;
apetushkov@9858 156 // writer.write_count(nof_entries);
apetushkov@9858 157 // for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 158 // writer.write_key(i);
apetushkov@9858 159 // writer.write(ObjectSynchronizer::inflate_cause_name((ObjectSynchronizer::InflateCause)i));
apetushkov@9858 160 // }
apetushkov@9858 161 }
apetushkov@9858 162
apetushkov@9858 163 void GCCauseConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 164 static const u4 nof_entries = GCCause::_last_gc_cause;
apetushkov@9858 165 writer.write_count(nof_entries);
apetushkov@9858 166 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 167 writer.write_key(i);
apetushkov@9858 168 writer.write(GCCause::to_string((GCCause::Cause)i));
apetushkov@9858 169 }
apetushkov@9858 170 }
apetushkov@9858 171
apetushkov@9858 172 void GCNameConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 173 static const u4 nof_entries = GCNameEndSentinel;
apetushkov@9858 174 writer.write_count(nof_entries);
apetushkov@9858 175 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 176 writer.write_key(i);
apetushkov@9858 177 writer.write(GCNameHelper::to_string((GCName)i));
apetushkov@9858 178 }
apetushkov@9858 179 }
apetushkov@9858 180
apetushkov@9858 181 void GCWhenConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 182 static const u4 nof_entries = GCWhen::GCWhenEndSentinel;
apetushkov@9858 183 writer.write_count(nof_entries);
apetushkov@9858 184 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 185 writer.write_key(i);
apetushkov@9858 186 writer.write(GCWhen::to_string((GCWhen::Type)i));
apetushkov@9858 187 }
apetushkov@9858 188 }
apetushkov@9858 189
apetushkov@9858 190 void G1HeapRegionTypeConstant::serialize(JfrCheckpointWriter& writer) {
neugens@9861 191 static const u4 nof_entries = G1HeapRegionTraceType::G1HeapRegionTypeEndSentinel;
neugens@9861 192 writer.write_count(nof_entries);
neugens@9861 193 for (u4 i = 0; i < nof_entries; ++i) {
neugens@9861 194 writer.write_key(i);
neugens@9861 195 writer.write(G1HeapRegionTraceType::to_string((G1HeapRegionTraceType::Type)i));
neugens@9861 196 }
apetushkov@9858 197 }
apetushkov@9858 198
apetushkov@9858 199 void GCThresholdUpdaterConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 200 static const u4 nof_entries = MetaspaceGCThresholdUpdater::Last;
apetushkov@9858 201 writer.write_count(nof_entries);
apetushkov@9858 202 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 203 writer.write_key(i);
apetushkov@9858 204 writer.write(MetaspaceGCThresholdUpdater::to_string((MetaspaceGCThresholdUpdater::Type)i));
apetushkov@9858 205 }
apetushkov@9858 206 }
apetushkov@9858 207
apetushkov@9858 208 void MetadataTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 209 static const u4 nof_entries = Metaspace::MetadataTypeCount;
apetushkov@9858 210 writer.write_count(nof_entries);
apetushkov@9858 211 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 212 writer.write_key(i);
apetushkov@9858 213 writer.write(Metaspace::metadata_type_name((Metaspace::MetadataType)i));
apetushkov@9858 214 }
apetushkov@9858 215 }
apetushkov@9858 216
apetushkov@9858 217 void MetaspaceObjectTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 218 static const u4 nof_entries = MetaspaceObj::_number_of_types;
apetushkov@9858 219 writer.write_count(nof_entries);
apetushkov@9858 220 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 221 writer.write_key(i);
apetushkov@9858 222 writer.write(MetaspaceObj::type_name((MetaspaceObj::Type)i));
apetushkov@9858 223 }
apetushkov@9858 224 }
apetushkov@9858 225
apetushkov@9858 226 void G1YCTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 227 #if INCLUDE_ALL_GCS
apetushkov@9858 228 static const u4 nof_entries = G1YCTypeEndSentinel;
apetushkov@9858 229 writer.write_count(nof_entries);
apetushkov@9858 230 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 231 writer.write_key(i);
apetushkov@9858 232 writer.write(G1YCTypeHelper::to_string((G1YCType)i));
apetushkov@9858 233 }
apetushkov@9858 234 #endif
apetushkov@9858 235 }
apetushkov@9858 236
apetushkov@9858 237 static const char* reference_type_to_string(ReferenceType rt) {
apetushkov@9858 238 switch (rt) {
apetushkov@9858 239 case REF_NONE: return "None reference";
apetushkov@9858 240 case REF_OTHER: return "Other reference";
apetushkov@9858 241 case REF_SOFT: return "Soft reference";
apetushkov@9858 242 case REF_WEAK: return "Weak reference";
apetushkov@9858 243 case REF_FINAL: return "Final reference";
apetushkov@9858 244 case REF_PHANTOM: return "Phantom reference";
apetushkov@9858 245 default:
apetushkov@9858 246 ShouldNotReachHere();
apetushkov@9858 247 return NULL;
apetushkov@9858 248 }
apetushkov@9858 249 }
apetushkov@9858 250
apetushkov@9858 251 void ReferenceTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 252 static const u4 nof_entries = REF_PHANTOM + 1;
apetushkov@9858 253 writer.write_count(nof_entries);
apetushkov@9858 254 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 255 writer.write_key(i);
apetushkov@9858 256 writer.write(reference_type_to_string((ReferenceType)i));
apetushkov@9858 257 }
apetushkov@9858 258 }
apetushkov@9858 259
apetushkov@9858 260 void NarrowOopModeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 261 static const u4 nof_entries = Universe::HeapBasedNarrowOop + 1;
apetushkov@9858 262 writer.write_count(nof_entries);
apetushkov@9858 263 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 264 writer.write_key(i);
apetushkov@9858 265 writer.write(Universe::narrow_oop_mode_to_string((Universe::NARROW_OOP_MODE)i));
apetushkov@9858 266 }
apetushkov@9858 267 }
apetushkov@9858 268
apetushkov@9858 269 void CompilerPhaseTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 270 #ifdef COMPILER2
apetushkov@9858 271 static const u4 nof_entries = PHASE_NUM_TYPES;
apetushkov@9858 272 writer.write_count(nof_entries);
apetushkov@9858 273 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 274 writer.write_key(i);
apetushkov@9858 275 writer.write(CompilerPhaseTypeHelper::to_string((CompilerPhaseType)i));
apetushkov@9858 276 }
apetushkov@9858 277 #endif
apetushkov@9858 278 }
apetushkov@9858 279
apetushkov@9858 280 void CodeBlobTypeConstant::serialize(JfrCheckpointWriter& writer) {
neugens@9861 281 static const u4 nof_entries = CodeBlobType::NumTypes;
neugens@9861 282 writer.write_count(nof_entries);
neugens@9861 283 writer.write_key((u4)CodeBlobType::All);
neugens@9861 284 writer.write("CodeCache");
apetushkov@9858 285 };
apetushkov@9858 286
apetushkov@9858 287 void VMOperationTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 288 static const u4 nof_entries = VM_Operation::VMOp_Terminating;
apetushkov@9858 289 writer.write_count(nof_entries);
apetushkov@9858 290 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 291 writer.write_key(i);
apetushkov@9858 292 writer.write(VM_Operation::name(VM_Operation::VMOp_Type(i)));
apetushkov@9858 293 }
apetushkov@9858 294 }
apetushkov@9858 295
apetushkov@9858 296 class TypeSetSerialization {
apetushkov@9858 297 private:
apetushkov@9858 298 bool _class_unload;
apetushkov@9858 299 public:
apetushkov@9858 300 explicit TypeSetSerialization(bool class_unload) : _class_unload(class_unload) {}
apetushkov@9858 301 void write(JfrCheckpointWriter& writer, JfrCheckpointWriter* leakp_writer) {
apetushkov@9858 302 JfrTypeSet::serialize(&writer, leakp_writer, _class_unload);
apetushkov@9858 303 }
apetushkov@9858 304 };
apetushkov@9858 305
apetushkov@9858 306 void ClassUnloadTypeSet::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 307 TypeSetSerialization type_set(true);
apetushkov@9858 308 if (LeakProfiler::is_running()) {
apetushkov@9858 309 JfrCheckpointWriter leakp_writer(false, true, Thread::current());
apetushkov@9858 310 type_set.write(writer, &leakp_writer);
apetushkov@9858 311 ObjectSampleCheckpoint::install(leakp_writer, true, true);
apetushkov@9858 312 return;
apetushkov@9858 313 }
apetushkov@9858 314 type_set.write(writer, NULL);
apetushkov@9858 315 };
apetushkov@9858 316
apetushkov@9858 317 void TypeSet::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 318 TypeSetSerialization type_set(false);
apetushkov@9858 319 if (LeakProfiler::is_suspended()) {
apetushkov@9858 320 JfrCheckpointWriter leakp_writer(false, true, Thread::current());
apetushkov@9858 321 type_set.write(writer, &leakp_writer);
apetushkov@9858 322 ObjectSampleCheckpoint::install(leakp_writer, false, true);
apetushkov@9858 323 return;
apetushkov@9858 324 }
apetushkov@9858 325 type_set.write(writer, NULL);
apetushkov@9858 326 };
apetushkov@9858 327
apetushkov@9858 328 void ThreadStateConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 329 JfrThreadState::serialize(writer);
apetushkov@9858 330 }
apetushkov@9858 331
apetushkov@9858 332 void JfrThreadConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 333 assert(_thread != NULL, "invariant");
apetushkov@9858 334 assert(_thread == Thread::current(), "invariant");
apetushkov@9858 335 assert(_thread->is_Java_thread(), "invariant");
apetushkov@9858 336 assert(!_thread->jfr_thread_local()->has_thread_checkpoint(), "invariant");
apetushkov@9858 337 ResourceMark rm(_thread);
apetushkov@9858 338 const oop threadObj = _thread->threadObj();
apetushkov@9858 339 assert(threadObj != NULL, "invariant");
apetushkov@9858 340 const u8 java_lang_thread_id = java_lang_Thread::thread_id(threadObj);
apetushkov@9858 341 const char* const thread_name = _thread->name();
apetushkov@9858 342 const traceid thread_group_id = JfrThreadGroup::thread_group_id(_thread);
apetushkov@9858 343 writer.write_count(1);
apetushkov@9858 344 writer.write_key(_thread->jfr_thread_local()->thread_id());
apetushkov@9858 345 writer.write(thread_name);
apetushkov@9858 346 writer.write((traceid)_thread->osthread()->thread_id());
apetushkov@9858 347 writer.write(thread_name);
apetushkov@9858 348 writer.write(java_lang_thread_id);
apetushkov@9858 349 writer.write(thread_group_id);
apetushkov@9858 350 JfrThreadGroup::serialize(&writer, thread_group_id);
apetushkov@9858 351 }

mercurial