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

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
child 9861
a248d0be1309
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

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) {
apetushkov@9858 191 // XXX TODO?
apetushkov@9858 192 // static const u4 nof_entries = G1HeapRegionTraceType::G1HeapRegionTypeEndSentinel;
apetushkov@9858 193 // writer.write_count(nof_entries);
apetushkov@9858 194 // for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 195 // writer.write_key(i);
apetushkov@9858 196 // writer.write(G1HeapRegionTraceType::to_string((G1HeapRegionTraceType::Type)i));
apetushkov@9858 197 // }
apetushkov@9858 198 }
apetushkov@9858 199
apetushkov@9858 200 void GCThresholdUpdaterConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 201 static const u4 nof_entries = MetaspaceGCThresholdUpdater::Last;
apetushkov@9858 202 writer.write_count(nof_entries);
apetushkov@9858 203 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 204 writer.write_key(i);
apetushkov@9858 205 writer.write(MetaspaceGCThresholdUpdater::to_string((MetaspaceGCThresholdUpdater::Type)i));
apetushkov@9858 206 }
apetushkov@9858 207 }
apetushkov@9858 208
apetushkov@9858 209 void MetadataTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 210 static const u4 nof_entries = Metaspace::MetadataTypeCount;
apetushkov@9858 211 writer.write_count(nof_entries);
apetushkov@9858 212 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 213 writer.write_key(i);
apetushkov@9858 214 writer.write(Metaspace::metadata_type_name((Metaspace::MetadataType)i));
apetushkov@9858 215 }
apetushkov@9858 216 }
apetushkov@9858 217
apetushkov@9858 218 void MetaspaceObjectTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 219 static const u4 nof_entries = MetaspaceObj::_number_of_types;
apetushkov@9858 220 writer.write_count(nof_entries);
apetushkov@9858 221 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 222 writer.write_key(i);
apetushkov@9858 223 writer.write(MetaspaceObj::type_name((MetaspaceObj::Type)i));
apetushkov@9858 224 }
apetushkov@9858 225 }
apetushkov@9858 226
apetushkov@9858 227 void G1YCTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 228 #if INCLUDE_ALL_GCS
apetushkov@9858 229 static const u4 nof_entries = G1YCTypeEndSentinel;
apetushkov@9858 230 writer.write_count(nof_entries);
apetushkov@9858 231 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 232 writer.write_key(i);
apetushkov@9858 233 writer.write(G1YCTypeHelper::to_string((G1YCType)i));
apetushkov@9858 234 }
apetushkov@9858 235 #endif
apetushkov@9858 236 }
apetushkov@9858 237
apetushkov@9858 238 static const char* reference_type_to_string(ReferenceType rt) {
apetushkov@9858 239 switch (rt) {
apetushkov@9858 240 case REF_NONE: return "None reference";
apetushkov@9858 241 case REF_OTHER: return "Other reference";
apetushkov@9858 242 case REF_SOFT: return "Soft reference";
apetushkov@9858 243 case REF_WEAK: return "Weak reference";
apetushkov@9858 244 case REF_FINAL: return "Final reference";
apetushkov@9858 245 case REF_PHANTOM: return "Phantom reference";
apetushkov@9858 246 default:
apetushkov@9858 247 ShouldNotReachHere();
apetushkov@9858 248 return NULL;
apetushkov@9858 249 }
apetushkov@9858 250 }
apetushkov@9858 251
apetushkov@9858 252 void ReferenceTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 253 static const u4 nof_entries = REF_PHANTOM + 1;
apetushkov@9858 254 writer.write_count(nof_entries);
apetushkov@9858 255 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 256 writer.write_key(i);
apetushkov@9858 257 writer.write(reference_type_to_string((ReferenceType)i));
apetushkov@9858 258 }
apetushkov@9858 259 }
apetushkov@9858 260
apetushkov@9858 261 void NarrowOopModeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 262 static const u4 nof_entries = Universe::HeapBasedNarrowOop + 1;
apetushkov@9858 263 writer.write_count(nof_entries);
apetushkov@9858 264 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 265 writer.write_key(i);
apetushkov@9858 266 writer.write(Universe::narrow_oop_mode_to_string((Universe::NARROW_OOP_MODE)i));
apetushkov@9858 267 }
apetushkov@9858 268 }
apetushkov@9858 269
apetushkov@9858 270 void CompilerPhaseTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 271 #ifdef COMPILER2
apetushkov@9858 272 static const u4 nof_entries = PHASE_NUM_TYPES;
apetushkov@9858 273 writer.write_count(nof_entries);
apetushkov@9858 274 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 275 writer.write_key(i);
apetushkov@9858 276 writer.write(CompilerPhaseTypeHelper::to_string((CompilerPhaseType)i));
apetushkov@9858 277 }
apetushkov@9858 278 #endif
apetushkov@9858 279 }
apetushkov@9858 280
apetushkov@9858 281 void CodeBlobTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 282 // XXX no code blob types. need to send any stub value?
apetushkov@9858 283 // static const u4 nof_entries = CodeBlobType::NumTypes;
apetushkov@9858 284 // writer.write_count(nof_entries);
apetushkov@9858 285 // for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 286 // writer.write_key(i);
apetushkov@9858 287 // writer.write(CodeCache::get_code_heap_name(i));
apetushkov@9858 288 // }
apetushkov@9858 289 };
apetushkov@9858 290
apetushkov@9858 291 void VMOperationTypeConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 292 static const u4 nof_entries = VM_Operation::VMOp_Terminating;
apetushkov@9858 293 writer.write_count(nof_entries);
apetushkov@9858 294 for (u4 i = 0; i < nof_entries; ++i) {
apetushkov@9858 295 writer.write_key(i);
apetushkov@9858 296 writer.write(VM_Operation::name(VM_Operation::VMOp_Type(i)));
apetushkov@9858 297 }
apetushkov@9858 298 }
apetushkov@9858 299
apetushkov@9858 300 class TypeSetSerialization {
apetushkov@9858 301 private:
apetushkov@9858 302 bool _class_unload;
apetushkov@9858 303 public:
apetushkov@9858 304 explicit TypeSetSerialization(bool class_unload) : _class_unload(class_unload) {}
apetushkov@9858 305 void write(JfrCheckpointWriter& writer, JfrCheckpointWriter* leakp_writer) {
apetushkov@9858 306 JfrTypeSet::serialize(&writer, leakp_writer, _class_unload);
apetushkov@9858 307 }
apetushkov@9858 308 };
apetushkov@9858 309
apetushkov@9858 310 void ClassUnloadTypeSet::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 311 TypeSetSerialization type_set(true);
apetushkov@9858 312 if (LeakProfiler::is_running()) {
apetushkov@9858 313 JfrCheckpointWriter leakp_writer(false, true, Thread::current());
apetushkov@9858 314 type_set.write(writer, &leakp_writer);
apetushkov@9858 315 ObjectSampleCheckpoint::install(leakp_writer, true, true);
apetushkov@9858 316 return;
apetushkov@9858 317 }
apetushkov@9858 318 type_set.write(writer, NULL);
apetushkov@9858 319 };
apetushkov@9858 320
apetushkov@9858 321 void TypeSet::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 322 TypeSetSerialization type_set(false);
apetushkov@9858 323 if (LeakProfiler::is_suspended()) {
apetushkov@9858 324 JfrCheckpointWriter leakp_writer(false, true, Thread::current());
apetushkov@9858 325 type_set.write(writer, &leakp_writer);
apetushkov@9858 326 ObjectSampleCheckpoint::install(leakp_writer, false, true);
apetushkov@9858 327 return;
apetushkov@9858 328 }
apetushkov@9858 329 type_set.write(writer, NULL);
apetushkov@9858 330 };
apetushkov@9858 331
apetushkov@9858 332 void ThreadStateConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 333 JfrThreadState::serialize(writer);
apetushkov@9858 334 }
apetushkov@9858 335
apetushkov@9858 336 void JfrThreadConstant::serialize(JfrCheckpointWriter& writer) {
apetushkov@9858 337 assert(_thread != NULL, "invariant");
apetushkov@9858 338 assert(_thread == Thread::current(), "invariant");
apetushkov@9858 339 assert(_thread->is_Java_thread(), "invariant");
apetushkov@9858 340 assert(!_thread->jfr_thread_local()->has_thread_checkpoint(), "invariant");
apetushkov@9858 341 ResourceMark rm(_thread);
apetushkov@9858 342 const oop threadObj = _thread->threadObj();
apetushkov@9858 343 assert(threadObj != NULL, "invariant");
apetushkov@9858 344 const u8 java_lang_thread_id = java_lang_Thread::thread_id(threadObj);
apetushkov@9858 345 const char* const thread_name = _thread->name();
apetushkov@9858 346 const traceid thread_group_id = JfrThreadGroup::thread_group_id(_thread);
apetushkov@9858 347 writer.write_count(1);
apetushkov@9858 348 writer.write_key(_thread->jfr_thread_local()->thread_id());
apetushkov@9858 349 writer.write(thread_name);
apetushkov@9858 350 writer.write((traceid)_thread->osthread()->thread_id());
apetushkov@9858 351 writer.write(thread_name);
apetushkov@9858 352 writer.write(java_lang_thread_id);
apetushkov@9858 353 writer.write(thread_group_id);
apetushkov@9858 354 JfrThreadGroup::serialize(&writer, thread_group_id);
apetushkov@9858 355 }

mercurial