< prev index next >

src/hotspot/share/jfr/recorder/jfrRecorder.cpp

Print this page

 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/javaClasses.hpp"
 27 #include "jfr/dcmd/jfrDcmds.hpp"
 28 #include "jfr/instrumentation/jfrJvmtiAgent.hpp"
 29 #include "jfr/jni/jfrJavaSupport.hpp"
 30 #include "jfr/leakprofiler/sampling/objectSampler.hpp"
 31 #include "jfr/periodic/jfrOSInterface.hpp"
 32 #include "jfr/periodic/sampling/jfrThreadSampler.hpp"
 33 #include "jfr/recorder/jfrRecorder.hpp"
 34 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"

 35 #include "jfr/recorder/repository/jfrRepository.hpp"
 36 #include "jfr/recorder/service/jfrEventThrottler.hpp"
 37 #include "jfr/recorder/service/jfrOptionSet.hpp"
 38 #include "jfr/recorder/service/jfrPostBox.hpp"
 39 #include "jfr/recorder/service/jfrRecorderService.hpp"
 40 #include "jfr/recorder/service/jfrRecorderThread.hpp"
 41 #include "jfr/recorder/storage/jfrStorage.hpp"
 42 #include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp"
 43 #include "jfr/recorder/stringpool/jfrStringPool.hpp"

 44 #include "jfr/utilities/jfrTime.hpp"
 45 #include "jfr/writers/jfrJavaEventWriter.hpp"
 46 #include "logging/log.hpp"
 47 #include "logging/logStream.hpp"
 48 #include "memory/resourceArea.inline.hpp"
 49 #include "runtime/handles.inline.hpp"
 50 #include "runtime/globals_extension.hpp"
 51 #include "utilities/growableArray.hpp"
 52 #ifdef ASSERT
 53 #include "prims/jvmtiEnvBase.hpp"
 54 #endif
 55 
 56 bool JfrRecorder::is_disabled() {
 57   // True if -XX:-FlightRecorder has been explicitly set on the
 58   // command line
 59   return FLAG_IS_CMDLINE(FlightRecorder) ? !FlightRecorder : false;
 60 }
 61 
 62 static bool _enabled = false;
 63 

179   LogTarget(Error, jfr, system) lt_error;
180   LogTargetHandle handle(lt_error);
181   LogStream stream(handle);
182   JfrJavaSupport::is_jdk_jfr_module_available(&stream, THREAD);
183 }
184 
185 static bool is_cds_dump_requested() {
186   // we will not be able to launch recordings on startup if a cds dump is being requested
187   if (Arguments::is_dumping_archive() && JfrOptionSet::start_flight_recording_options() != NULL) {
188     warning("JFR will be disabled during CDS dumping");
189     teardown_startup_support();
190     return true;
191   }
192   return false;
193 }
194 
195 bool JfrRecorder::on_create_vm_2() {
196   if (is_cds_dump_requested()) {
197     return true;
198   }



199   JavaThread* const thread = JavaThread::current();
200   if (!JfrOptionSet::initialize(thread)) {
201     return false;
202   }
203   if (!register_jfr_dcmds()) {
204     return false;
205   }
206   const bool in_graph = JfrJavaSupport::is_jdk_jfr_module_available();
207   if (in_graph) {
208     if (!validate_recording_options(thread)) {
209       return false;
210     }
211     if (!JfrOptionSet::configure(thread)) {
212       return false;
213     }
214   }
215   if (!is_enabled()) {
216     return true;
217   }
218   if (!in_graph) {

276     return false;
277   }
278   if (!create_checkpoint_manager()) {
279     return false;
280   }
281   if (!create_stacktrace_repository()) {
282     return false;
283   }
284   if (!create_os_interface()) {
285     return false;
286   }
287   if (!create_stringpool()) {
288     return false;
289   }
290   if (!create_thread_sampling()) {
291     return false;
292   }
293   if (!create_event_throttler()) {
294     return false;
295   }



296   return true;
297 }
298 
299 // subsystems
300 static JfrPostBox* _post_box = NULL;
301 static JfrStorage* _storage = NULL;
302 static JfrCheckpointManager* _checkpoint_manager = NULL;
303 static JfrRepository* _repository = NULL;
304 static JfrStackTraceRepository* _stack_trace_repository;
305 static JfrStringPool* _stringpool = NULL;
306 static JfrOSInterface* _os_interface = NULL;
307 static JfrThreadSampling* _thread_sampling = NULL;
308 
309 bool JfrRecorder::create_java_event_writer() {
310   return JfrJavaEventWriter::initialize();
311 }
312 
313 bool JfrRecorder::create_jvmti_agent() {
314   return JfrOptionSet::allow_retransforms() ? JfrJvmtiAgent::create() : true;
315 }

353   return _stack_trace_repository != NULL && _stack_trace_repository->initialize();
354 }
355 
356 bool JfrRecorder::create_stringpool() {
357   assert(_stringpool == NULL, "invariant");
358   assert(_repository != NULL, "invariant");
359   _stringpool = JfrStringPool::create(_repository->chunkwriter());
360   return _stringpool != NULL && _stringpool->initialize();
361 }
362 
363 bool JfrRecorder::create_thread_sampling() {
364   assert(_thread_sampling == NULL, "invariant");
365   _thread_sampling = JfrThreadSampling::create();
366   return _thread_sampling != NULL;
367 }
368 
369 bool JfrRecorder::create_event_throttler() {
370   return JfrEventThrottler::create();
371 }
372 






373 void JfrRecorder::destroy_components() {
374   JfrJvmtiAgent::destroy();
375   if (_post_box != NULL) {
376     JfrPostBox::destroy();
377     _post_box = NULL;
378   }
379   if (_repository != NULL) {
380     JfrRepository::destroy();
381     _repository = NULL;
382   }
383   if (_storage != NULL) {
384     JfrStorage::destroy();
385     _storage = NULL;
386   }
387   if (_checkpoint_manager != NULL) {
388     JfrCheckpointManager::destroy();
389     _checkpoint_manager = NULL;
390   }
391   if (_stack_trace_repository != NULL) {
392     JfrStackTraceRepository::destroy();

 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/javaClasses.hpp"
 27 #include "jfr/dcmd/jfrDcmds.hpp"
 28 #include "jfr/instrumentation/jfrJvmtiAgent.hpp"
 29 #include "jfr/jni/jfrJavaSupport.hpp"
 30 #include "jfr/leakprofiler/sampling/objectSampler.hpp"
 31 #include "jfr/periodic/jfrOSInterface.hpp"
 32 #include "jfr/periodic/sampling/jfrThreadSampler.hpp"
 33 #include "jfr/recorder/jfrRecorder.hpp"
 34 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
 35 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.hpp"
 36 #include "jfr/recorder/repository/jfrRepository.hpp"
 37 #include "jfr/recorder/service/jfrEventThrottler.hpp"
 38 #include "jfr/recorder/service/jfrOptionSet.hpp"
 39 #include "jfr/recorder/service/jfrPostBox.hpp"
 40 #include "jfr/recorder/service/jfrRecorderService.hpp"
 41 #include "jfr/recorder/service/jfrRecorderThread.hpp"
 42 #include "jfr/recorder/storage/jfrStorage.hpp"
 43 #include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp"
 44 #include "jfr/recorder/stringpool/jfrStringPool.hpp"
 45 #include "jfr/support/jfrJavaThread.hpp"
 46 #include "jfr/utilities/jfrTime.hpp"
 47 #include "jfr/writers/jfrJavaEventWriter.hpp"
 48 #include "logging/log.hpp"
 49 #include "logging/logStream.hpp"
 50 #include "memory/resourceArea.inline.hpp"
 51 #include "runtime/handles.inline.hpp"
 52 #include "runtime/globals_extension.hpp"
 53 #include "utilities/growableArray.hpp"
 54 #ifdef ASSERT
 55 #include "prims/jvmtiEnvBase.hpp"
 56 #endif
 57 
 58 bool JfrRecorder::is_disabled() {
 59   // True if -XX:-FlightRecorder has been explicitly set on the
 60   // command line
 61   return FLAG_IS_CMDLINE(FlightRecorder) ? !FlightRecorder : false;
 62 }
 63 
 64 static bool _enabled = false;
 65 

181   LogTarget(Error, jfr, system) lt_error;
182   LogTargetHandle handle(lt_error);
183   LogStream stream(handle);
184   JfrJavaSupport::is_jdk_jfr_module_available(&stream, THREAD);
185 }
186 
187 static bool is_cds_dump_requested() {
188   // we will not be able to launch recordings on startup if a cds dump is being requested
189   if (Arguments::is_dumping_archive() && JfrOptionSet::start_flight_recording_options() != NULL) {
190     warning("JFR will be disabled during CDS dumping");
191     teardown_startup_support();
192     return true;
193   }
194   return false;
195 }
196 
197 bool JfrRecorder::on_create_vm_2() {
198   if (is_cds_dump_requested()) {
199     return true;
200   }
201   if (!JfrTraceId::initialize()) {
202     return false;
203   }
204   JavaThread* const thread = JavaThread::current();
205   if (!JfrOptionSet::initialize(thread)) {
206     return false;
207   }
208   if (!register_jfr_dcmds()) {
209     return false;
210   }
211   const bool in_graph = JfrJavaSupport::is_jdk_jfr_module_available();
212   if (in_graph) {
213     if (!validate_recording_options(thread)) {
214       return false;
215     }
216     if (!JfrOptionSet::configure(thread)) {
217       return false;
218     }
219   }
220   if (!is_enabled()) {
221     return true;
222   }
223   if (!in_graph) {

281     return false;
282   }
283   if (!create_checkpoint_manager()) {
284     return false;
285   }
286   if (!create_stacktrace_repository()) {
287     return false;
288   }
289   if (!create_os_interface()) {
290     return false;
291   }
292   if (!create_stringpool()) {
293     return false;
294   }
295   if (!create_thread_sampling()) {
296     return false;
297   }
298   if (!create_event_throttler()) {
299     return false;
300   }
301   if (!create_virtual_thread_support()) {
302     return false;
303   }
304   return true;
305 }
306 
307 // subsystems
308 static JfrPostBox* _post_box = NULL;
309 static JfrStorage* _storage = NULL;
310 static JfrCheckpointManager* _checkpoint_manager = NULL;
311 static JfrRepository* _repository = NULL;
312 static JfrStackTraceRepository* _stack_trace_repository;
313 static JfrStringPool* _stringpool = NULL;
314 static JfrOSInterface* _os_interface = NULL;
315 static JfrThreadSampling* _thread_sampling = NULL;
316 
317 bool JfrRecorder::create_java_event_writer() {
318   return JfrJavaEventWriter::initialize();
319 }
320 
321 bool JfrRecorder::create_jvmti_agent() {
322   return JfrOptionSet::allow_retransforms() ? JfrJvmtiAgent::create() : true;
323 }

361   return _stack_trace_repository != NULL && _stack_trace_repository->initialize();
362 }
363 
364 bool JfrRecorder::create_stringpool() {
365   assert(_stringpool == NULL, "invariant");
366   assert(_repository != NULL, "invariant");
367   _stringpool = JfrStringPool::create(_repository->chunkwriter());
368   return _stringpool != NULL && _stringpool->initialize();
369 }
370 
371 bool JfrRecorder::create_thread_sampling() {
372   assert(_thread_sampling == NULL, "invariant");
373   _thread_sampling = JfrThreadSampling::create();
374   return _thread_sampling != NULL;
375 }
376 
377 bool JfrRecorder::create_event_throttler() {
378   return JfrEventThrottler::create();
379 }
380 
381 bool JfrRecorder::create_virtual_thread_support() {
382   // bool parameter, notifyJvmti, enables jvmti events related to VirtualThreads.
383   // Thread start events hooks into some of these callbacks for JFR.
384   return JfrJavaThread::initialize(false);
385 }
386 
387 void JfrRecorder::destroy_components() {
388   JfrJvmtiAgent::destroy();
389   if (_post_box != NULL) {
390     JfrPostBox::destroy();
391     _post_box = NULL;
392   }
393   if (_repository != NULL) {
394     JfrRepository::destroy();
395     _repository = NULL;
396   }
397   if (_storage != NULL) {
398     JfrStorage::destroy();
399     _storage = NULL;
400   }
401   if (_checkpoint_manager != NULL) {
402     JfrCheckpointManager::destroy();
403     _checkpoint_manager = NULL;
404   }
405   if (_stack_trace_repository != NULL) {
406     JfrStackTraceRepository::destroy();
< prev index next >