< prev index next >

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

Print this page
rev 9061 : 8227011: Starting a JFR recording in response to JVMTI VMInit and / or Java agent premain corrupts memory
Reviewed-by: egahlin, rwestberg


 172 bool JfrRecorder::on_vm_start() {
 173   if (is_cds_dump_requested()) {
 174     return true;
 175   }
 176   Thread* const thread = Thread::current();
 177   if (!JfrJavaEventWriter::has_required_classes(thread)) {
 178     // assume it is compact profile of jfr.jar is missed for some reasons
 179     // skip further initialization.
 180     return true;
 181   }
 182   if (!JfrOptionSet::initialize(thread)) {
 183     return false;
 184   }
 185   if (!register_jfr_dcmds()) {
 186     return false;
 187   }
 188 
 189   if (!validate_recording_options(thread)) {
 190     return false;
 191   }
 192   if (!JfrJavaEventWriter::initialize()) {
 193     return false;
 194   }
 195   if (!JfrOptionSet::configure(thread)) {
 196     return false;
 197   }
 198 
 199   if (!is_enabled()) {
 200     return true;
 201   }
 202 
 203   return launch_recordings(thread);
 204 }
 205 
 206 static bool _created = false;
 207 
 208 //
 209 // Main entry point for starting Jfr functionality.
 210 // Non-protected initializations assume single-threaded setup.
 211 //
 212 bool JfrRecorder::create(bool simulate_failure) {
 213   assert(!is_disabled(), "invariant");
 214   assert(!is_created(), "invariant");


 218   if (!create_components() || simulate_failure) {
 219     destroy_components();
 220     return false;
 221   }
 222   if (!create_recorder_thread()) {
 223     destroy_components();
 224     return false;
 225   }
 226   _created = true;
 227   return true;
 228 }
 229 
 230 bool JfrRecorder::is_created() {
 231   return _created;
 232 }
 233 
 234 bool JfrRecorder::create_components() {
 235   ResourceMark rm;
 236   HandleMark hm;
 237 



 238   if (!create_jvmti_agent()) {
 239     return false;
 240   }
 241   if (!create_post_box()) {
 242     return false;
 243   }
 244   if (!create_chunk_repository()) {
 245     return false;
 246   }
 247   if (!create_storage()) {
 248     return false;
 249   }
 250   if (!create_checkpoint_manager()) {
 251     return false;
 252   }
 253   if (!create_stacktrace_repository()) {
 254     return false;
 255   }
 256   if (!create_os_interface()) {
 257     return false;
 258   }
 259   if (!create_stringpool()) {
 260     return false;
 261   }
 262   if (!create_thread_sampling()) {
 263     return false;
 264   }
 265   return true;
 266 }
 267 
 268 // subsystems
 269 static JfrJvmtiAgent* _jvmti_agent = NULL;
 270 static JfrPostBox* _post_box = NULL;
 271 static JfrStorage* _storage = NULL;
 272 static JfrCheckpointManager* _checkpoint_manager = NULL;
 273 static JfrRepository* _repository = NULL;
 274 static JfrStackTraceRepository* _stack_trace_repository;
 275 static JfrStringPool* _stringpool = NULL;
 276 static JfrOSInterface* _os_interface = NULL;
 277 static JfrThreadSampling* _thread_sampling = NULL;




 278 
 279 bool JfrRecorder::create_jvmti_agent() {
 280   return JfrOptionSet::allow_retransforms() ? JfrJvmtiAgent::create() : true;
 281 }
 282 
 283 bool JfrRecorder::create_post_box() {
 284   assert(_post_box == NULL, "invariant");
 285   _post_box = JfrPostBox::create();
 286   return _post_box != NULL;
 287 }
 288 
 289 bool JfrRecorder::create_chunk_repository() {
 290   assert(_repository == NULL, "invariant");
 291   assert(_post_box != NULL, "invariant");
 292   _repository = JfrRepository::create(*_post_box);
 293   return _repository != NULL && _repository->initialize();
 294 }
 295 
 296 bool JfrRecorder::create_os_interface() {
 297   assert(_os_interface == NULL, "invariant");




 172 bool JfrRecorder::on_vm_start() {
 173   if (is_cds_dump_requested()) {
 174     return true;
 175   }
 176   Thread* const thread = Thread::current();
 177   if (!JfrJavaEventWriter::has_required_classes(thread)) {
 178     // assume it is compact profile of jfr.jar is missed for some reasons
 179     // skip further initialization.
 180     return true;
 181   }
 182   if (!JfrOptionSet::initialize(thread)) {
 183     return false;
 184   }
 185   if (!register_jfr_dcmds()) {
 186     return false;
 187   }
 188 
 189   if (!validate_recording_options(thread)) {
 190     return false;
 191   }



 192   if (!JfrOptionSet::configure(thread)) {
 193     return false;
 194   }
 195 
 196   if (!is_enabled()) {
 197     return true;
 198   }
 199 
 200   return launch_recordings(thread);
 201 }
 202 
 203 static bool _created = false;
 204 
 205 //
 206 // Main entry point for starting Jfr functionality.
 207 // Non-protected initializations assume single-threaded setup.
 208 //
 209 bool JfrRecorder::create(bool simulate_failure) {
 210   assert(!is_disabled(), "invariant");
 211   assert(!is_created(), "invariant");


 215   if (!create_components() || simulate_failure) {
 216     destroy_components();
 217     return false;
 218   }
 219   if (!create_recorder_thread()) {
 220     destroy_components();
 221     return false;
 222   }
 223   _created = true;
 224   return true;
 225 }
 226 
 227 bool JfrRecorder::is_created() {
 228   return _created;
 229 }
 230 
 231 bool JfrRecorder::create_components() {
 232   ResourceMark rm;
 233   HandleMark hm;
 234 
 235   if (!create_java_event_writer()) {
 236     return false;
 237   }
 238   if (!create_jvmti_agent()) {
 239     return false;
 240   }
 241   if (!create_post_box()) {
 242     return false;
 243   }
 244   if (!create_chunk_repository()) {
 245     return false;
 246   }
 247   if (!create_storage()) {
 248     return false;
 249   }
 250   if (!create_checkpoint_manager()) {
 251     return false;
 252   }
 253   if (!create_stacktrace_repository()) {
 254     return false;
 255   }
 256   if (!create_os_interface()) {
 257     return false;
 258   }
 259   if (!create_stringpool()) {
 260     return false;
 261   }
 262   if (!create_thread_sampling()) {
 263     return false;
 264   }
 265   return true;
 266 }
 267 
 268 // subsystems
 269 static JfrJvmtiAgent* _jvmti_agent = NULL;
 270 static JfrPostBox* _post_box = NULL;
 271 static JfrStorage* _storage = NULL;
 272 static JfrCheckpointManager* _checkpoint_manager = NULL;
 273 static JfrRepository* _repository = NULL;
 274 static JfrStackTraceRepository* _stack_trace_repository;
 275 static JfrStringPool* _stringpool = NULL;
 276 static JfrOSInterface* _os_interface = NULL;
 277 static JfrThreadSampling* _thread_sampling = NULL;
 278 
 279 bool JfrRecorder::create_java_event_writer() {
 280   return JfrJavaEventWriter::initialize();
 281 }
 282 
 283 bool JfrRecorder::create_jvmti_agent() {
 284   return JfrOptionSet::allow_retransforms() ? JfrJvmtiAgent::create() : true;
 285 }
 286 
 287 bool JfrRecorder::create_post_box() {
 288   assert(_post_box == NULL, "invariant");
 289   _post_box = JfrPostBox::create();
 290   return _post_box != NULL;
 291 }
 292 
 293 bool JfrRecorder::create_chunk_repository() {
 294   assert(_repository == NULL, "invariant");
 295   assert(_post_box != NULL, "invariant");
 296   _repository = JfrRepository::create(*_post_box);
 297   return _repository != NULL && _repository->initialize();
 298 }
 299 
 300 bool JfrRecorder::create_os_interface() {
 301   assert(_os_interface == NULL, "invariant");


< prev index next >