85 return JfrTime::initialize(); |
85 return JfrTime::initialize(); |
86 } |
86 } |
87 |
87 |
88 static JfrStartFlightRecordingDCmd* _startup_recording = NULL; |
88 static JfrStartFlightRecordingDCmd* _startup_recording = NULL; |
89 |
89 |
|
90 static void release_startup_recording() { |
|
91 if (_startup_recording != NULL) { |
|
92 delete _startup_recording; |
|
93 _startup_recording = NULL; |
|
94 } |
|
95 } |
|
96 |
|
97 static void teardown_startup_support() { |
|
98 release_startup_recording(); |
|
99 JfrOptionSet::release_startup_recordings(); |
|
100 } |
|
101 |
|
102 |
90 // Parsing options here to detect errors as soon as possible |
103 // Parsing options here to detect errors as soon as possible |
91 static bool parse_startup_recording(TRAPS) { |
104 static bool parse_recording_options(const char* options, TRAPS) { |
92 assert(StartFlightRecording != NULL, "invariant"); |
105 assert(options != NULL, "invariant"); |
93 CmdLine cmdline(StartFlightRecording, strlen(StartFlightRecording), true); |
106 if (_startup_recording != NULL) { |
|
107 delete _startup_recording; |
|
108 } |
|
109 CmdLine cmdline(options, strlen(options), true); |
|
110 _startup_recording = new (ResourceObj::C_HEAP, mtTracing) JfrStartFlightRecordingDCmd(tty, true); |
|
111 assert(_startup_recording != NULL, "invariant"); |
94 _startup_recording->parse(&cmdline, ',', THREAD); |
112 _startup_recording->parse(&cmdline, ',', THREAD); |
95 if (HAS_PENDING_EXCEPTION) { |
113 if (HAS_PENDING_EXCEPTION) { |
96 java_lang_Throwable::print(PENDING_EXCEPTION, tty); |
114 java_lang_Throwable::print(PENDING_EXCEPTION, tty); |
97 CLEAR_PENDING_EXCEPTION; |
115 CLEAR_PENDING_EXCEPTION; |
98 return false; |
116 return false; |
99 } |
117 } |
100 return true; |
118 return true; |
101 } |
119 } |
102 |
120 |
103 static bool initialize_startup_recording(TRAPS) { |
121 static bool validate_recording_options(TRAPS) { |
104 if (StartFlightRecording != NULL) { |
122 const GrowableArray<const char*>* startup_options = JfrOptionSet::startup_recordings(); |
105 _startup_recording = new (ResourceObj::C_HEAP, mtTracing) JfrStartFlightRecordingDCmd(tty, true); |
123 if (startup_options == NULL) { |
106 return _startup_recording != NULL && parse_startup_recording(THREAD); |
|
107 } |
|
108 return true; |
|
109 } |
|
110 |
|
111 static bool startup_recording(TRAPS) { |
|
112 if (_startup_recording == NULL) { |
|
113 return true; |
124 return true; |
114 } |
125 } |
115 log_trace(jfr, system)("Starting up Jfr startup recording"); |
126 const int length = startup_options->length(); |
|
127 assert(length >= 1, "invariant"); |
|
128 for (int i = 0; i < length; ++i) { |
|
129 if (!parse_recording_options(startup_options->at(i), THREAD)) { |
|
130 return false; |
|
131 } |
|
132 } |
|
133 return true; |
|
134 } |
|
135 |
|
136 static bool launch_recording(TRAPS) { |
|
137 assert(_startup_recording != NULL, "invariant"); |
|
138 log_trace(jfr, system)("Starting a recording"); |
116 _startup_recording->execute(DCmd_Source_Internal, Thread::current()); |
139 _startup_recording->execute(DCmd_Source_Internal, Thread::current()); |
117 delete _startup_recording; |
|
118 _startup_recording = NULL; |
|
119 if (HAS_PENDING_EXCEPTION) { |
140 if (HAS_PENDING_EXCEPTION) { |
120 log_debug(jfr, system)("Exception while starting Jfr startup recording"); |
141 log_debug(jfr, system)("Exception while starting a recording"); |
121 CLEAR_PENDING_EXCEPTION; |
142 CLEAR_PENDING_EXCEPTION; |
122 return false; |
143 return false; |
123 } |
144 } |
124 log_trace(jfr, system)("Finished starting Jfr startup recording"); |
145 log_trace(jfr, system)("Finished starting a recording"); |
125 return true; |
146 return true; |
|
147 } |
|
148 |
|
149 static bool launch_recordings(const GrowableArray<const char*>* startup_options, TRAPS) { |
|
150 assert(startup_options != NULL, "invariant"); |
|
151 const int length = startup_options->length(); |
|
152 assert(length >= 1, "invariant"); |
|
153 if (length == 1) { |
|
154 // already parsed and ready, launch it |
|
155 return launch_recording(THREAD); |
|
156 } |
|
157 for (int i = 0; i < length; ++i) { |
|
158 parse_recording_options(startup_options->at(i), THREAD); |
|
159 if (!launch_recording(THREAD)) { |
|
160 return false; |
|
161 } |
|
162 } |
|
163 return true; |
|
164 } |
|
165 |
|
166 static bool startup_recordings(TRAPS) { |
|
167 const GrowableArray<const char*>* startup_options = JfrOptionSet::startup_recordings(); |
|
168 if (startup_options == NULL) { |
|
169 return true; |
|
170 } |
|
171 const bool ret = launch_recordings(startup_options, THREAD); |
|
172 teardown_startup_support(); |
|
173 return ret; |
126 } |
174 } |
127 |
175 |
128 static void log_jdk_jfr_module_resolution_error(TRAPS) { |
176 static void log_jdk_jfr_module_resolution_error(TRAPS) { |
129 LogTarget(Error, jfr, system) lt_error; |
177 LogTarget(Error, jfr, system) lt_error; |
130 LogTargetHandle handle(lt_error); |
178 LogTargetHandle handle(lt_error); |