src/share/vm/services/diagnosticFramework.cpp
Print this page
@@ -357,28 +357,29 @@
int idx = 0;
GenDCmdArgument* arg = _arguments_list;
while (arg != NULL) {
array->append(new DCmdArgumentInfo(arg->name(), arg->description(),
arg->type(), arg->default_string(), arg->is_mandatory(),
- false, idx));
+ false, arg->allow_multiple(), idx));
idx++;
arg = arg->next();
}
arg = _options;
while (arg != NULL) {
array->append(new DCmdArgumentInfo(arg->name(), arg->description(),
arg->type(), arg->default_string(), arg->is_mandatory(),
- true));
+ true, arg->allow_multiple()));
arg = arg->next();
}
return array;
}
DCmdFactory* DCmdFactory::_DCmdFactoryList = NULL;
+bool DCmdFactory::_has_pending_jmx_notification = false;
-void DCmd::parse_and_execute(outputStream* out, const char* cmdline,
- char delim, TRAPS) {
+void DCmd::parse_and_execute(DCmdSource source, outputStream* out,
+ const char* cmdline, char delim, TRAPS) {
if (cmdline == NULL) return; // Nothing to do!
DCmdIter iter(cmdline, '\n');
while (iter.has_next()) {
@@ -385,15 +386,15 @@
CmdLine line = iter.next();
if (line.is_stop()) {
break;
}
if (line.is_executable()) {
- DCmd* command = DCmdFactory::create_local_DCmd(line, out, CHECK);
+ DCmd* command = DCmdFactory::create_local_DCmd(source, line, out, CHECK);
assert(command != NULL, "command error must be handled before this line");
DCmdMark mark(command);
command->parse(&line, delim, CHECK);
- command->execute(CHECK);
+ command->execute(source, CHECK);
}
}
}
void DCmdWithParser::parse(CmdLine* line, char delim, TRAPS) {
@@ -418,34 +419,104 @@
GrowableArray<DCmdArgumentInfo*>* DCmdWithParser::argument_info_array() {
return _dcmdparser.argument_info_array();
}
+void DCmdFactory::push_jmx_notification_request() {
+ MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
+ _has_pending_jmx_notification = true;
+ Service_lock->notify_all();
+}
+
+void DCmdFactory::send_notification(TRAPS) {
+ DCmdFactory::send_notification_internal(THREAD);
+ // Clearing pending exception to avoid premature termination of
+ // the service thread
+ if (HAS_PENDING_EXCEPTION) {
+ // Just for testing
+ java_lang_Throwable::print(PENDING_EXCEPTION, tty);
+ CLEAR_PENDING_EXCEPTION;
+ }
+}
+void DCmdFactory::send_notification_internal(TRAPS) {
+ ResourceMark rm(THREAD);
+ HandleMark hm(THREAD);
+ bool notif = false;
+ {
+ MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
+ notif = _has_pending_jmx_notification;
+ _has_pending_jmx_notification = false;
+ }
+ if (notif) {
+
+ Klass* k = Management::sun_management_ManagementFactoryHelper_klass(CHECK);
+ instanceKlassHandle mgmt_factory_helper_klass(THREAD, k);
+
+ JavaValue result(T_OBJECT);
+ JavaCalls::call_static(&result,
+ mgmt_factory_helper_klass,
+ vmSymbols::getDiagnosticCommandMBean_name(),
+ vmSymbols::getDiagnosticCommandMBean_signature(),
+ CHECK);
+
+ instanceOop m = (instanceOop) result.get_jobject();
+ instanceHandle dcmd_mbean_h(THREAD, m);
+
+ Klass* k2 = Management::sun_management_DiagnosticCommandImpl_klass(CHECK);
+ instanceKlassHandle dcmd_mbean_klass(THREAD, k2);
+
+ if (!dcmd_mbean_h->is_a(k2)) {
+ THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+ "ManagementFactory.getDiagnosticCommandMBean didn't return a DiagnosticCommandMBean instance");
+ }
+
+ JavaValue result2(T_VOID);
+ JavaCallArguments args2(dcmd_mbean_h);
+
+ JavaCalls::call_virtual(&result2,
+ dcmd_mbean_klass,
+ vmSymbols::createDiagnosticFrameworkNotification_name(),
+ vmSymbols::void_method_signature(),
+ &args2,
+ CHECK);
+ }
+}
+
Mutex* DCmdFactory::_dcmdFactory_lock = new Mutex(Mutex::leaf, "DCmdFactory", true);
+bool DCmdFactory::_send_jmx_notification = false;
-DCmdFactory* DCmdFactory::factory(const char* name, size_t len) {
+DCmdFactory* DCmdFactory::factory(DCmdSource source, const char* name, size_t len) {
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
DCmdFactory* factory = _DCmdFactoryList;
while (factory != NULL) {
if (strlen(factory->name()) == len &&
strncmp(name, factory->name(), len) == 0) {
+ if(factory->export_flags() & source) {
return factory;
+ } else {
+ return NULL;
}
+ }
factory = factory->_next;
}
return NULL;
}
int DCmdFactory::register_DCmdFactory(DCmdFactory* factory) {
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
factory->_next = _DCmdFactoryList;
_DCmdFactoryList = factory;
+ if (_send_jmx_notification && !factory->_hidden
+ && factory->_export_flags&DCmd_Source_MBean) {
+ DCmdFactory::push_jmx_notification_request();
+ }
return 0; // Actually, there's no checks for duplicates
}
-DCmd* DCmdFactory::create_global_DCmd(CmdLine &line, outputStream* out, TRAPS) {
- DCmdFactory* f = factory(line.cmd_addr(), line.cmd_len());
+DCmd* DCmdFactory::create_global_DCmd(DCmdSource source, CmdLine &line,
+ outputStream* out, TRAPS) {
+ DCmdFactory* f = factory(source, line.cmd_addr(), line.cmd_len());
if (f != NULL) {
if (f->is_enabled()) {
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
f->disabled_message());
}
@@ -453,12 +524,13 @@
}
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
"Unknown diagnostic command");
}
-DCmd* DCmdFactory::create_local_DCmd(CmdLine &line, outputStream* out, TRAPS) {
- DCmdFactory* f = factory(line.cmd_addr(), line.cmd_len());
+DCmd* DCmdFactory::create_local_DCmd(DCmdSource source, CmdLine &line,
+ outputStream* out, TRAPS) {
+ DCmdFactory* f = factory(source, line.cmd_addr(), line.cmd_len());
if (f != NULL) {
if (!f->is_enabled()) {
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
f->disabled_message());
}
@@ -466,32 +538,33 @@
}
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
"Unknown diagnostic command");
}
-GrowableArray<const char*>* DCmdFactory::DCmd_list() {
+GrowableArray<const char*>* DCmdFactory::DCmd_list(DCmdSource source) {
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
GrowableArray<const char*>* array = new GrowableArray<const char*>();
DCmdFactory* factory = _DCmdFactoryList;
while (factory != NULL) {
- if (!factory->is_hidden()) {
+ if (!factory->is_hidden() && (factory->export_flags() & source)) {
array->append(factory->name());
}
factory = factory->next();
}
return array;
}
-GrowableArray<DCmdInfo*>* DCmdFactory::DCmdInfo_list() {
+GrowableArray<DCmdInfo*>* DCmdFactory::DCmdInfo_list(DCmdSource source ) {
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
GrowableArray<DCmdInfo*>* array = new GrowableArray<DCmdInfo*>();
DCmdFactory* factory = _DCmdFactoryList;
while (factory != NULL) {
- if (!factory->is_hidden()) {
+ if (!factory->is_hidden() && (factory->export_flags() & source)) {
array->append(new DCmdInfo(factory->name(),
factory->description(), factory->impact(),
- factory->num_arguments(), factory->is_enabled()));
+ factory->permission(), factory->num_arguments(),
+ factory->is_enabled()));
}
factory = factory->next();
}
return array;
}