Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp
41152 views
1
/*
2
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
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 "classfile/vmSymbols.hpp"
28
#include "jfr/jfr.hpp"
29
#include "jfr/dcmd/jfrDcmds.hpp"
30
#include "jfr/jni/jfrJavaSupport.hpp"
31
#include "jfr/recorder/jfrRecorder.hpp"
32
#include "jfr/recorder/service/jfrOptionSet.hpp"
33
#include "logging/log.hpp"
34
#include "logging/logConfiguration.hpp"
35
#include "logging/logMessage.hpp"
36
#include "memory/resourceArea.hpp"
37
#include "oops/objArrayOop.inline.hpp"
38
#include "oops/oop.inline.hpp"
39
#include "oops/symbol.hpp"
40
#include "runtime/handles.inline.hpp"
41
#include "runtime/jniHandles.hpp"
42
#include "services/diagnosticArgument.hpp"
43
#include "services/diagnosticFramework.hpp"
44
#include "utilities/globalDefinitions.hpp"
45
46
#ifdef _WINDOWS
47
#define JFR_FILENAME_EXAMPLE "C:\\Users\\user\\My Recording.jfr"
48
#endif
49
50
#ifdef __APPLE__
51
#define JFR_FILENAME_EXAMPLE "/Users/user/My Recording.jfr"
52
#endif
53
54
#ifndef JFR_FILENAME_EXAMPLE
55
#define JFR_FILENAME_EXAMPLE "/home/user/My Recording.jfr"
56
#endif
57
58
// JNIHandle management
59
60
// ------------------------------------------------------------------
61
// push_jni_handle_block
62
//
63
// Push on a new block of JNI handles.
64
static void push_jni_handle_block(JavaThread* const thread) {
65
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));
66
67
// Allocate a new block for JNI handles.
68
// Inlined code from jni_PushLocalFrame()
69
JNIHandleBlock* prev_handles = thread->active_handles();
70
JNIHandleBlock* entry_handles = JNIHandleBlock::allocate_block(thread);
71
assert(entry_handles != NULL && prev_handles != NULL, "should not be NULL");
72
entry_handles->set_pop_frame_link(prev_handles); // make sure prev handles get gc'd.
73
thread->set_active_handles(entry_handles);
74
}
75
76
// ------------------------------------------------------------------
77
// pop_jni_handle_block
78
//
79
// Pop off the current block of JNI handles.
80
static void pop_jni_handle_block(JavaThread* const thread) {
81
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));
82
83
// Release our JNI handle block
84
JNIHandleBlock* entry_handles = thread->active_handles();
85
JNIHandleBlock* prev_handles = entry_handles->pop_frame_link();
86
// restore
87
thread->set_active_handles(prev_handles);
88
entry_handles->set_pop_frame_link(NULL);
89
JNIHandleBlock::release_block(entry_handles, thread); // may block
90
}
91
92
class JNIHandleBlockManager : public StackObj {
93
private:
94
JavaThread* const _thread;
95
public:
96
JNIHandleBlockManager(JavaThread* thread) : _thread(thread) {
97
push_jni_handle_block(_thread);
98
}
99
100
~JNIHandleBlockManager() {
101
pop_jni_handle_block(_thread);
102
}
103
};
104
105
static bool is_module_available(outputStream* output, TRAPS) {
106
return JfrJavaSupport::is_jdk_jfr_module_available(output, THREAD);
107
}
108
109
static bool is_disabled(outputStream* output) {
110
if (Jfr::is_disabled()) {
111
if (output != NULL) {
112
output->print_cr("Flight Recorder is disabled.\n");
113
}
114
return true;
115
}
116
return false;
117
}
118
119
static bool is_recorder_instance_created(outputStream* output) {
120
if (!JfrRecorder::is_created()) {
121
if (output != NULL) {
122
output->print_cr("No available recordings.\n");
123
output->print_cr("Use JFR.start to start a recording.\n");
124
}
125
return false;
126
}
127
return true;
128
}
129
130
static bool invalid_state(outputStream* out, TRAPS) {
131
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
132
return is_disabled(out) || !is_module_available(out, THREAD);
133
}
134
135
static void handle_pending_exception(outputStream* output, bool startup, oop throwable) {
136
assert(throwable != NULL, "invariant");
137
138
oop msg = java_lang_Throwable::message(throwable);
139
if (msg == NULL) {
140
return;
141
}
142
char* text = java_lang_String::as_utf8_string(msg);
143
if (text != NULL) {
144
if (startup) {
145
log_error(jfr,startup)("%s", text);
146
} else {
147
output->print_cr("%s", text);
148
}
149
}
150
}
151
152
static void print_message(outputStream* output, oop content, TRAPS) {
153
objArrayOop lines = objArrayOop(content);
154
assert(lines != NULL, "invariant");
155
assert(lines->is_array(), "must be array");
156
const int length = lines->length();
157
for (int i = 0; i < length; ++i) {
158
const char* text = JfrJavaSupport::c_str(lines->obj_at(i), THREAD);
159
if (text == NULL) {
160
// An oome has been thrown and is pending.
161
break;
162
}
163
output->print_cr("%s", text);
164
}
165
}
166
167
static void log(oop content, TRAPS) {
168
LogMessage(jfr,startup) msg;
169
objArrayOop lines = objArrayOop(content);
170
assert(lines != NULL, "invariant");
171
assert(lines->is_array(), "must be array");
172
const int length = lines->length();
173
for (int i = 0; i < length; ++i) {
174
const char* text = JfrJavaSupport::c_str(lines->obj_at(i), THREAD);
175
if (text == NULL) {
176
// An oome has been thrown and is pending.
177
break;
178
}
179
msg.info("%s", text);
180
}
181
}
182
183
static void handle_dcmd_result(outputStream* output,
184
const oop result,
185
const DCmdSource source,
186
TRAPS) {
187
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
188
assert(output != NULL, "invariant");
189
const bool startup = DCmd_Source_Internal == source;
190
if (HAS_PENDING_EXCEPTION) {
191
handle_pending_exception(output, startup, PENDING_EXCEPTION);
192
// Don't clear excption on startup, JVM should fail initialization.
193
if (!startup) {
194
CLEAR_PENDING_EXCEPTION;
195
}
196
return;
197
}
198
199
assert(!HAS_PENDING_EXCEPTION, "invariant");
200
201
if (startup) {
202
if (log_is_enabled(Warning, jfr, startup)) {
203
// if warning is set, assume user hasn't configured log level
204
// Log to Info and reset to Warning. This way user can disable
205
// default output by setting -Xlog:jfr+startup=error/off
206
LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(jfr, startup));
207
log(result, THREAD);
208
LogConfiguration::configure_stdout(LogLevel::Warning, true, LOG_TAGS(jfr, startup));
209
} else {
210
log(result, THREAD);
211
}
212
} else {
213
// Print output for jcmd or MXBean
214
print_message(output, result, THREAD);
215
}
216
}
217
218
static oop construct_dcmd_instance(JfrJavaArguments* args, TRAPS) {
219
assert(args != NULL, "invariant");
220
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
221
assert(args->klass() != NULL, "invariant");
222
args->set_name("<init>");
223
args->set_signature("()V");
224
JfrJavaSupport::new_object(args, CHECK_NULL);
225
return args->result()->get_oop();
226
}
227
228
JfrDumpFlightRecordingDCmd::JfrDumpFlightRecordingDCmd(outputStream* output,
229
bool heap) : DCmdWithParser(output, heap),
230
_name("name", "Recording name, e.g. \\\"My Recording\\\"", "STRING", false, NULL),
231
_filename("filename", "Copy recording data to file, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false),
232
_maxage("maxage", "Maximum duration to dump, in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 60m, or 0 for no limit", "NANOTIME", false, "0"),
233
_maxsize("maxsize", "Maximum amount of bytes to dump, in (M)B or (G)B, e.g. 500M, or 0 for no limit", "MEMORY SIZE", false, "0"),
234
_begin("begin", "Point in time to dump data from, e.g. 09:00, 21:35:00, 2018-06-03T18:12:56.827Z, 2018-06-03T20:13:46.832, -10m, -3h, or -1d", "STRING", false),
235
_end("end", "Point in time to dump data to, e.g. 09:00, 21:35:00, 2018-06-03T18:12:56.827Z, 2018-06-03T20:13:46.832, -10m, -3h, or -1d", "STRING", false),
236
_path_to_gc_roots("path-to-gc-roots", "Collect path to GC roots", "BOOLEAN", false, "false") {
237
_dcmdparser.add_dcmd_option(&_name);
238
_dcmdparser.add_dcmd_option(&_filename);
239
_dcmdparser.add_dcmd_option(&_maxage);
240
_dcmdparser.add_dcmd_option(&_maxsize);
241
_dcmdparser.add_dcmd_option(&_begin);
242
_dcmdparser.add_dcmd_option(&_end);
243
_dcmdparser.add_dcmd_option(&_path_to_gc_roots);
244
};
245
246
int JfrDumpFlightRecordingDCmd::num_arguments() {
247
ResourceMark rm;
248
JfrDumpFlightRecordingDCmd* dcmd = new JfrDumpFlightRecordingDCmd(NULL, false);
249
if (dcmd != NULL) {
250
DCmdMark mark(dcmd);
251
return dcmd->_dcmdparser.num_arguments();
252
}
253
return 0;
254
}
255
256
void JfrDumpFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {
257
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
258
259
if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) {
260
return;
261
}
262
263
ResourceMark rm(THREAD);
264
HandleMark hm(THREAD);
265
JNIHandleBlockManager jni_handle_management(THREAD);
266
267
JavaValue result(T_OBJECT);
268
JfrJavaArguments constructor_args(&result);
269
constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdDump", CHECK);
270
const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);
271
Handle h_dcmd_instance(THREAD, dcmd);
272
assert(h_dcmd_instance.not_null(), "invariant");
273
274
jstring name = NULL;
275
if (_name.is_set() && _name.value() != NULL) {
276
name = JfrJavaSupport::new_string(_name.value(), CHECK);
277
}
278
279
jstring filepath = NULL;
280
if (_filename.is_set() && _filename.value() != NULL) {
281
filepath = JfrJavaSupport::new_string(_filename.value(), CHECK);
282
}
283
284
jobject maxage = NULL;
285
if (_maxage.is_set()) {
286
maxage = JfrJavaSupport::new_java_lang_Long(_maxage.value()._nanotime, CHECK);
287
}
288
289
jobject maxsize = NULL;
290
if (_maxsize.is_set()) {
291
maxsize = JfrJavaSupport::new_java_lang_Long(_maxsize.value()._size, CHECK);
292
}
293
294
jstring begin = NULL;
295
if (_begin.is_set() && _begin.value() != NULL) {
296
begin = JfrJavaSupport::new_string(_begin.value(), CHECK);
297
}
298
299
jstring end = NULL;
300
if (_end.is_set() && _end.value() != NULL) {
301
end = JfrJavaSupport::new_string(_end.value(), CHECK);
302
}
303
304
jobject path_to_gc_roots = NULL;
305
if (_path_to_gc_roots.is_set()) {
306
path_to_gc_roots = JfrJavaSupport::new_java_lang_Boolean(_path_to_gc_roots.value(), CHECK);
307
}
308
309
static const char klass[] = "jdk/jfr/internal/dcmd/DCmdDump";
310
static const char method[] = "execute";
311
static const char signature[] = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;)[Ljava/lang/String;";
312
313
JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);
314
execute_args.set_receiver(h_dcmd_instance);
315
316
// arguments
317
execute_args.push_jobject(name);
318
execute_args.push_jobject(filepath);
319
execute_args.push_jobject(maxage);
320
execute_args.push_jobject(maxsize);
321
execute_args.push_jobject(begin);
322
execute_args.push_jobject(end);
323
execute_args.push_jobject(path_to_gc_roots);
324
325
JfrJavaSupport::call_virtual(&execute_args, THREAD);
326
handle_dcmd_result(output(), result.get_oop(), source, THREAD);
327
}
328
329
JfrCheckFlightRecordingDCmd::JfrCheckFlightRecordingDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
330
_name("name","Recording name, e.g. \\\"My Recording\\\" or omit to see all recordings","STRING",false, NULL),
331
_verbose("verbose","Print event settings for the recording(s)","BOOLEAN",
332
false, "false") {
333
_dcmdparser.add_dcmd_option(&_name);
334
_dcmdparser.add_dcmd_option(&_verbose);
335
};
336
337
int JfrCheckFlightRecordingDCmd::num_arguments() {
338
ResourceMark rm;
339
JfrCheckFlightRecordingDCmd* dcmd = new JfrCheckFlightRecordingDCmd(NULL, false);
340
if (dcmd != NULL) {
341
DCmdMark mark(dcmd);
342
return dcmd->_dcmdparser.num_arguments();
343
}
344
return 0;
345
}
346
347
void JfrCheckFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {
348
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
349
350
if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) {
351
return;
352
}
353
354
ResourceMark rm(THREAD);
355
HandleMark hm(THREAD);
356
JNIHandleBlockManager jni_handle_management(THREAD);
357
358
JavaValue result(T_OBJECT);
359
JfrJavaArguments constructor_args(&result);
360
constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdCheck", CHECK);
361
const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);
362
Handle h_dcmd_instance(THREAD, dcmd);
363
assert(h_dcmd_instance.not_null(), "invariant");
364
365
jstring name = NULL;
366
if (_name.is_set() && _name.value() != NULL) {
367
name = JfrJavaSupport::new_string(_name.value(), CHECK);
368
}
369
370
jobject verbose = NULL;
371
if (_verbose.is_set()) {
372
verbose = JfrJavaSupport::new_java_lang_Boolean(_verbose.value(), CHECK);
373
}
374
375
static const char klass[] = "jdk/jfr/internal/dcmd/DCmdCheck";
376
static const char method[] = "execute";
377
static const char signature[] = "(Ljava/lang/String;Ljava/lang/Boolean;)[Ljava/lang/String;";
378
379
JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);
380
execute_args.set_receiver(h_dcmd_instance);
381
382
// arguments
383
execute_args.push_jobject(name);
384
execute_args.push_jobject(verbose);
385
386
JfrJavaSupport::call_virtual(&execute_args, THREAD);
387
handle_dcmd_result(output(), result.get_oop(), source, THREAD);
388
}
389
390
JfrStartFlightRecordingDCmd::JfrStartFlightRecordingDCmd(outputStream* output,
391
bool heap) : DCmdWithParser(output, heap),
392
_name("name", "Name that can be used to identify recording, e.g. \\\"My Recording\\\"", "STRING", false, NULL),
393
_settings("settings", "Settings file(s), e.g. profile or default. See JAVA_HOME/lib/jfr", "STRING SET", false),
394
_delay("delay", "Delay recording start with (s)econds, (m)inutes), (h)ours), or (d)ays, e.g. 5h.", "NANOTIME", false, "0"),
395
_duration("duration", "Duration of recording in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 300s.", "NANOTIME", false, "0"),
396
_disk("disk", "Recording should be persisted to disk", "BOOLEAN", false),
397
_filename("filename", "Resulting recording filename, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false),
398
_maxage("maxage", "Maximum time to keep recorded data (on disk) in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 60m, or 0 for no limit", "NANOTIME", false, "0"),
399
_maxsize("maxsize", "Maximum amount of bytes to keep (on disk) in (k)B, (M)B or (G)B, e.g. 500M, or 0 for no limit", "MEMORY SIZE", false, "0"),
400
_flush_interval("flush-interval", "Minimum time before flushing buffers, measured in (s)econds, e.g. 4 s, or 0 for flushing when a recording ends", "NANOTIME", false, "1s"),
401
_dump_on_exit("dumponexit", "Dump running recording when JVM shuts down", "BOOLEAN", false),
402
_path_to_gc_roots("path-to-gc-roots", "Collect path to GC roots", "BOOLEAN", false, "false") {
403
_dcmdparser.add_dcmd_option(&_name);
404
_dcmdparser.add_dcmd_option(&_settings);
405
_dcmdparser.add_dcmd_option(&_delay);
406
_dcmdparser.add_dcmd_option(&_duration);
407
_dcmdparser.add_dcmd_option(&_disk);
408
_dcmdparser.add_dcmd_option(&_filename);
409
_dcmdparser.add_dcmd_option(&_maxage);
410
_dcmdparser.add_dcmd_option(&_maxsize);
411
_dcmdparser.add_dcmd_option(&_flush_interval);
412
_dcmdparser.add_dcmd_option(&_dump_on_exit);
413
_dcmdparser.add_dcmd_option(&_path_to_gc_roots);
414
};
415
416
int JfrStartFlightRecordingDCmd::num_arguments() {
417
ResourceMark rm;
418
JfrStartFlightRecordingDCmd* dcmd = new JfrStartFlightRecordingDCmd(NULL, false);
419
if (dcmd != NULL) {
420
DCmdMark mark(dcmd);
421
return dcmd->_dcmdparser.num_arguments();
422
}
423
return 0;
424
}
425
426
void JfrStartFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {
427
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
428
429
if (invalid_state(output(), THREAD)) {
430
return;
431
}
432
433
ResourceMark rm(THREAD);
434
HandleMark hm(THREAD);
435
JNIHandleBlockManager jni_handle_management(THREAD);
436
437
JavaValue result(T_OBJECT);
438
JfrJavaArguments constructor_args(&result);
439
constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdStart", THREAD);
440
const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);
441
Handle h_dcmd_instance(THREAD, dcmd);
442
assert(h_dcmd_instance.not_null(), "invariant");
443
444
jstring name = NULL;
445
if (_name.is_set() && _name.value() != NULL) {
446
name = JfrJavaSupport::new_string(_name.value(), CHECK);
447
}
448
449
jstring filename = NULL;
450
if (_filename.is_set() && _filename.value() != NULL) {
451
filename = JfrJavaSupport::new_string(_filename.value(), CHECK);
452
}
453
454
jobject maxage = NULL;
455
if (_maxage.is_set()) {
456
maxage = JfrJavaSupport::new_java_lang_Long(_maxage.value()._nanotime, CHECK);
457
}
458
459
jobject maxsize = NULL;
460
if (_maxsize.is_set()) {
461
maxsize = JfrJavaSupport::new_java_lang_Long(_maxsize.value()._size, CHECK);
462
}
463
464
jobject flush_interval = NULL;
465
if (_flush_interval.is_set()) {
466
flush_interval = JfrJavaSupport::new_java_lang_Long(_flush_interval.value()._nanotime, CHECK);
467
}
468
jobject duration = NULL;
469
if (_duration.is_set()) {
470
duration = JfrJavaSupport::new_java_lang_Long(_duration.value()._nanotime, CHECK);
471
}
472
473
jobject delay = NULL;
474
if (_delay.is_set()) {
475
delay = JfrJavaSupport::new_java_lang_Long(_delay.value()._nanotime, CHECK);
476
}
477
478
jobject disk = NULL;
479
if (_disk.is_set()) {
480
disk = JfrJavaSupport::new_java_lang_Boolean(_disk.value(), CHECK);
481
}
482
483
jobject dump_on_exit = NULL;
484
if (_dump_on_exit.is_set()) {
485
dump_on_exit = JfrJavaSupport::new_java_lang_Boolean(_dump_on_exit.value(), CHECK);
486
}
487
488
jobject path_to_gc_roots = NULL;
489
if (_path_to_gc_roots.is_set()) {
490
path_to_gc_roots = JfrJavaSupport::new_java_lang_Boolean(_path_to_gc_roots.value(), CHECK);
491
}
492
493
jobjectArray settings = NULL;
494
if (_settings.is_set()) {
495
int length = _settings.value()->array()->length();
496
if (length == 1) {
497
const char* c_str = _settings.value()->array()->at(0);
498
if (strcmp(c_str, "none") == 0) {
499
length = 0;
500
}
501
}
502
settings = JfrJavaSupport::new_string_array(length, CHECK);
503
assert(settings != NULL, "invariant");
504
for (int i = 0; i < length; ++i) {
505
jobject element = JfrJavaSupport::new_string(_settings.value()->array()->at(i), CHECK);
506
assert(element != NULL, "invariant");
507
JfrJavaSupport::set_array_element(settings, element, i, CHECK);
508
}
509
} else {
510
settings = JfrJavaSupport::new_string_array(1, CHECK);
511
assert(settings != NULL, "invariant");
512
jobject element = JfrJavaSupport::new_string("default", CHECK);
513
assert(element != NULL, "invariant");
514
JfrJavaSupport::set_array_element(settings, element, 0, CHECK);
515
}
516
517
static const char klass[] = "jdk/jfr/internal/dcmd/DCmdStart";
518
static const char method[] = "execute";
519
static const char signature[] = "(Ljava/lang/String;[Ljava/lang/String;Ljava/lang/Long;"
520
"Ljava/lang/Long;Ljava/lang/Boolean;Ljava/lang/String;"
521
"Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Boolean;Ljava/lang/Boolean;)[Ljava/lang/String;";
522
523
JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);
524
execute_args.set_receiver(h_dcmd_instance);
525
526
// arguments
527
execute_args.push_jobject(name);
528
execute_args.push_jobject(settings);
529
execute_args.push_jobject(delay);
530
execute_args.push_jobject(duration);
531
execute_args.push_jobject(disk);
532
execute_args.push_jobject(filename);
533
execute_args.push_jobject(maxage);
534
execute_args.push_jobject(maxsize);
535
execute_args.push_jobject(flush_interval);
536
execute_args.push_jobject(dump_on_exit);
537
execute_args.push_jobject(path_to_gc_roots);
538
539
JfrJavaSupport::call_virtual(&execute_args, THREAD);
540
handle_dcmd_result(output(), result.get_oop(), source, THREAD);
541
}
542
543
JfrStopFlightRecordingDCmd::JfrStopFlightRecordingDCmd(outputStream* output,
544
bool heap) : DCmdWithParser(output, heap),
545
_name("name", "Recording text,.e.g \\\"My Recording\\\"", "STRING", true, NULL),
546
_filename("filename", "Copy recording data to file, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false, NULL) {
547
_dcmdparser.add_dcmd_option(&_name);
548
_dcmdparser.add_dcmd_option(&_filename);
549
};
550
551
int JfrStopFlightRecordingDCmd::num_arguments() {
552
ResourceMark rm;
553
JfrStopFlightRecordingDCmd* dcmd = new JfrStopFlightRecordingDCmd(NULL, false);
554
if (dcmd != NULL) {
555
DCmdMark mark(dcmd);
556
return dcmd->_dcmdparser.num_arguments();
557
}
558
return 0;
559
}
560
561
void JfrStopFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {
562
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
563
564
if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) {
565
return;
566
}
567
568
ResourceMark rm(THREAD);
569
HandleMark hm(THREAD);
570
JNIHandleBlockManager jni_handle_management(THREAD);
571
572
JavaValue result(T_OBJECT);
573
JfrJavaArguments constructor_args(&result);
574
constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdStop", CHECK);
575
const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);
576
Handle h_dcmd_instance(THREAD, dcmd);
577
assert(h_dcmd_instance.not_null(), "invariant");
578
579
jstring name = NULL;
580
if (_name.is_set() && _name.value() != NULL) {
581
name = JfrJavaSupport::new_string(_name.value(), CHECK);
582
}
583
584
jstring filepath = NULL;
585
if (_filename.is_set() && _filename.value() != NULL) {
586
filepath = JfrJavaSupport::new_string(_filename.value(), CHECK);
587
}
588
589
static const char klass[] = "jdk/jfr/internal/dcmd/DCmdStop";
590
static const char method[] = "execute";
591
static const char signature[] = "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;";
592
593
JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);
594
execute_args.set_receiver(h_dcmd_instance);
595
596
// arguments
597
execute_args.push_jobject(name);
598
execute_args.push_jobject(filepath);
599
600
JfrJavaSupport::call_virtual(&execute_args, THREAD);
601
handle_dcmd_result(output(), result.get_oop(), source, THREAD);
602
}
603
604
JfrConfigureFlightRecorderDCmd::JfrConfigureFlightRecorderDCmd(outputStream* output,
605
bool heap) : DCmdWithParser(output, heap),
606
_repository_path("repositorypath", "Path to repository,.e.g \\\"My Repository\\\"", "STRING", false, NULL),
607
_dump_path("dumppath", "Path to dump,.e.g \\\"My Dump path\\\"", "STRING", false, NULL),
608
_stack_depth("stackdepth", "Stack Depth", "JULONG", false, "64"),
609
_global_buffer_count("globalbuffercount", "Number of global buffers,", "JULONG", false, "20"),
610
_global_buffer_size("globalbuffersize", "Size of a global buffers,", "MEMORY SIZE", false, "512k"),
611
_thread_buffer_size("thread_buffer_size", "Size of a thread buffer", "MEMORY SIZE", false, "8k"),
612
_memory_size("memorysize", "Overall memory size, ", "MEMORY SIZE", false, "10m"),
613
_max_chunk_size("maxchunksize", "Size of an individual disk chunk", "MEMORY SIZE", false, "12m"),
614
_sample_threads("samplethreads", "Activate Thread sampling", "BOOLEAN", false, "true"),
615
_verbose(true) {
616
_dcmdparser.add_dcmd_option(&_repository_path);
617
_dcmdparser.add_dcmd_option(&_dump_path);
618
_dcmdparser.add_dcmd_option(&_stack_depth);
619
_dcmdparser.add_dcmd_option(&_global_buffer_count);
620
_dcmdparser.add_dcmd_option(&_global_buffer_size);
621
_dcmdparser.add_dcmd_option(&_thread_buffer_size);
622
_dcmdparser.add_dcmd_option(&_memory_size);
623
_dcmdparser.add_dcmd_option(&_max_chunk_size);
624
_dcmdparser.add_dcmd_option(&_sample_threads);
625
};
626
627
int JfrConfigureFlightRecorderDCmd::num_arguments() {
628
ResourceMark rm;
629
JfrConfigureFlightRecorderDCmd* dcmd = new JfrConfigureFlightRecorderDCmd(NULL, false);
630
if (dcmd != NULL) {
631
DCmdMark mark(dcmd);
632
return dcmd->_dcmdparser.num_arguments();
633
}
634
return 0;
635
}
636
637
void JfrConfigureFlightRecorderDCmd::execute(DCmdSource source, TRAPS) {
638
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
639
640
if (invalid_state(output(), THREAD)) {
641
return;
642
}
643
644
ResourceMark rm(THREAD);
645
HandleMark hm(THREAD);
646
JNIHandleBlockManager jni_handle_management(THREAD);
647
648
JavaValue result(T_OBJECT);
649
JfrJavaArguments constructor_args(&result);
650
constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdConfigure", CHECK);
651
const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);
652
Handle h_dcmd_instance(THREAD, dcmd);
653
assert(h_dcmd_instance.not_null(), "invariant");
654
655
jstring repository_path = NULL;
656
if (_repository_path.is_set() && _repository_path.value() != NULL) {
657
repository_path = JfrJavaSupport::new_string(_repository_path.value(), CHECK);
658
}
659
660
jstring dump_path = NULL;
661
if (_dump_path.is_set() && _dump_path.value() != NULL) {
662
dump_path = JfrJavaSupport::new_string(_dump_path.value(), CHECK);
663
}
664
665
jobject stack_depth = NULL;
666
if (_stack_depth.is_set()) {
667
stack_depth = JfrJavaSupport::new_java_lang_Integer((jint)_stack_depth.value(), CHECK);
668
}
669
670
jobject global_buffer_count = NULL;
671
if (_global_buffer_count.is_set()) {
672
global_buffer_count = JfrJavaSupport::new_java_lang_Long(_global_buffer_count.value(), CHECK);
673
}
674
675
jobject global_buffer_size = NULL;
676
if (_global_buffer_size.is_set()) {
677
global_buffer_size = JfrJavaSupport::new_java_lang_Long(_global_buffer_size.value()._size, CHECK);
678
}
679
680
jobject thread_buffer_size = NULL;
681
if (_thread_buffer_size.is_set()) {
682
thread_buffer_size = JfrJavaSupport::new_java_lang_Long(_thread_buffer_size.value()._size, CHECK);
683
}
684
685
jobject max_chunk_size = NULL;
686
if (_max_chunk_size.is_set()) {
687
max_chunk_size = JfrJavaSupport::new_java_lang_Long(_max_chunk_size.value()._size, CHECK);
688
}
689
690
jobject memory_size = NULL;
691
if (_memory_size.is_set()) {
692
memory_size = JfrJavaSupport::new_java_lang_Long(_memory_size.value()._size, CHECK);
693
}
694
695
jobject sample_threads = NULL;
696
if (_sample_threads.is_set()) {
697
sample_threads = JfrJavaSupport::new_java_lang_Boolean(_sample_threads.value(), CHECK);
698
}
699
700
static const char klass[] = "jdk/jfr/internal/dcmd/DCmdConfigure";
701
static const char method[] = "execute";
702
static const char signature[] = "(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/Integer;"
703
"Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;"
704
"Ljava/lang/Long;Ljava/lang/Boolean;)[Ljava/lang/String;";
705
706
JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);
707
execute_args.set_receiver(h_dcmd_instance);
708
709
// params
710
execute_args.push_int(_verbose ? 1 : 0);
711
execute_args.push_jobject(repository_path);
712
execute_args.push_jobject(dump_path);
713
execute_args.push_jobject(stack_depth);
714
execute_args.push_jobject(global_buffer_count);
715
execute_args.push_jobject(global_buffer_size);
716
execute_args.push_jobject(thread_buffer_size);
717
execute_args.push_jobject(memory_size);
718
execute_args.push_jobject(max_chunk_size);
719
execute_args.push_jobject(sample_threads);
720
721
JfrJavaSupport::call_virtual(&execute_args, THREAD);
722
handle_dcmd_result(output(), result.get_oop(), source, THREAD);
723
}
724
725
bool register_jfr_dcmds() {
726
uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI | DCmd_Source_MBean;
727
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrCheckFlightRecordingDCmd>(full_export, true, false));
728
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrDumpFlightRecordingDCmd>(full_export, true, false));
729
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrStartFlightRecordingDCmd>(full_export, true, false));
730
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrStopFlightRecordingDCmd>(full_export, true, false));
731
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrConfigureFlightRecorderDCmd>(full_export, true, false));
732
return true;
733
}
734
735