src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp
changeset 50664 857ce291c70c
parent 50113 caf115bb98ad
child 50851 b1b5306fadea
equal deleted inserted replaced
50663:0e9d1d4ab692 50664:857ce291c70c
    32 #include "memory/resourceArea.hpp"
    32 #include "memory/resourceArea.hpp"
    33 #include "runtime/java.hpp"
    33 #include "runtime/java.hpp"
    34 #include "runtime/thread.inline.hpp"
    34 #include "runtime/thread.inline.hpp"
    35 #include "services/diagnosticArgument.hpp"
    35 #include "services/diagnosticArgument.hpp"
    36 #include "services/diagnosticFramework.hpp"
    36 #include "services/diagnosticFramework.hpp"
       
    37 #include "utilities/growableArray.hpp"
    37 #include "utilities/ostream.hpp"
    38 #include "utilities/ostream.hpp"
    38 
    39 
    39 struct ObsoleteOption {
    40 struct ObsoleteOption {
    40   const char* name;
    41   const char* name;
    41   const char* message;
    42   const char* message;
   662   }
   663   }
   663   post_process_adjusted_memory_options(options);
   664   post_process_adjusted_memory_options(options);
   664   return true;
   665   return true;
   665 }
   666 }
   666 
   667 
   667 /*
   668 static GrowableArray<const char*>* startup_recording_array = NULL;
   668 
       
   669 to support starting multiple startup recordings
       
   670 
       
   671 static const char* start_flight_recording_option_original = NULL;
       
   672 static const char* flight_recorder_option_original = NULL;
       
   673 
       
   674 static void copy_option_string(const JavaVMOption* option, const char** addr) {
       
   675   assert(option != NULL, "invariant");
       
   676   assert(option->optionString != NULL, "invariant");
       
   677   const size_t length = strlen(option->optionString);
       
   678   *addr = JfrCHeapObj::new_array<char>(length + 1);
       
   679   assert(*addr != NULL, "invarinat");
       
   680   strncpy((char*)*addr, option->optionString, length + 1);
       
   681   assert(strncmp(*addr, option->optionString, length + 1) == 0, "invariant");
       
   682 }
       
   683 
       
   684 copy_option_string(*option, &start_flight_recording_option_original);
       
   685 copy_option_string(*option, &flight_recorder_option_original);
       
   686 */
       
   687 
   669 
   688 bool JfrOptionSet::parse_start_flight_recording_option(const JavaVMOption** option, char* tail) {
   670 bool JfrOptionSet::parse_start_flight_recording_option(const JavaVMOption** option, char* tail) {
   689   assert(option != NULL, "invariant");
   671   assert(option != NULL, "invariant");
   690   assert(tail != NULL, "invariant");
   672   assert(tail != NULL, "invariant");
   691   assert((*option)->optionString != NULL, "invariant");
   673   assert((*option)->optionString != NULL, "invariant");
   692   assert(strncmp((*option)->optionString, "-XX:StartFlightRecording", 24) == 0, "invariant");
   674   assert(strncmp((*option)->optionString, "-XX:StartFlightRecording", 24) == 0, "invariant");
       
   675   const char* param_string = NULL;
   693   if (*tail == '\0') {
   676   if (*tail == '\0') {
   694     // Add dummy dumponexit=false so -XX:StartFlightRecording can be used without a parameter.
   677     // Add dummy dumponexit=false so -XX:StartFlightRecording can be used without a parameter.
   695     // The existing option->optionString points to stack memory so no need to deallocate.
   678     // The existing option->optionString points to stack memory so no need to deallocate.
   696     const_cast<JavaVMOption*>(*option)->optionString = (char*)"-XX:StartFlightRecording=dumponexit=false";
   679     const_cast<JavaVMOption*>(*option)->optionString = (char*)"-XX:StartFlightRecording=dumponexit=false";
       
   680     param_string = (*option)->optionString + 25;
   697   } else {
   681   } else {
   698     *tail = '='; // ":" -> "="
   682     *tail = '='; // ":" -> "="
   699   }
   683     param_string = tail + 1;
       
   684   }
       
   685   assert(param_string != NULL, "invariant");
       
   686   const size_t param_length = strlen(param_string);
       
   687 
       
   688   if (startup_recording_array == NULL) {
       
   689     startup_recording_array = new (ResourceObj::C_HEAP, mtTracing) GrowableArray<const char*>(8, true, mtTracing);
       
   690   }
       
   691   assert(startup_recording_array != NULL, "invariant");
       
   692   char* startup_options = NEW_C_HEAP_ARRAY(char, param_length + 1, mtTracing);
       
   693   strncpy(startup_options, param_string, strlen(param_string) + 1);
       
   694   assert(strncmp(param_string, startup_options, param_length) == 0, "invariant");
       
   695   startup_recording_array->append(startup_options);
   700   return false;
   696   return false;
       
   697 }
       
   698 
       
   699 const GrowableArray<const char*>* JfrOptionSet::startup_recordings() {
       
   700   return startup_recording_array;
       
   701 }
       
   702 
       
   703 void JfrOptionSet::release_startup_recordings() {
       
   704   if (startup_recording_array != NULL) {
       
   705     for (int i = 0; i < startup_recording_array->length(); ++i) {
       
   706       FREE_C_HEAP_ARRAY(char, startup_recording_array->at(i));
       
   707     }
       
   708   }
       
   709   delete startup_recording_array;
       
   710   DEBUG_ONLY(startup_recording_array = NULL;)
   701 }
   711 }
   702 
   712 
   703 bool JfrOptionSet::parse_flight_recorder_option(const JavaVMOption** option, char* tail) {
   713 bool JfrOptionSet::parse_flight_recorder_option(const JavaVMOption** option, char* tail) {
   704   assert(option != NULL, "invariant");
   714   assert(option != NULL, "invariant");
   705   assert(tail != NULL, "invariant");
   715   assert(tail != NULL, "invariant");