1.1 --- a/src/share/vm/services/attachListener.cpp Fri Dec 09 06:46:57 2011 -0800 1.2 +++ b/src/share/vm/services/attachListener.cpp Wed Dec 14 04:30:57 2011 -0800 1.3 @@ -34,6 +34,7 @@ 1.4 #include "runtime/javaCalls.hpp" 1.5 #include "runtime/os.hpp" 1.6 #include "services/attachListener.hpp" 1.7 +#include "services/diagnosticCommand.hpp" 1.8 #include "services/heapDumper.hpp" 1.9 1.10 volatile bool AttachListener::_initialized; 1.11 @@ -148,6 +149,24 @@ 1.12 return JNI_OK; 1.13 } 1.14 1.15 +// A jcmd attach operation request was received, which will now 1.16 +// dispatch to the diagnostic commands used for serviceability functions. 1.17 +static jint jcmd(AttachOperation* op, outputStream* out) { 1.18 + Thread* THREAD = Thread::current(); 1.19 + // All the supplied jcmd arguments are stored as a single 1.20 + // string (op->arg(0)). This is parsed by the Dcmd framework. 1.21 + DCmd::parse_and_execute(out, op->arg(0), ' ', THREAD); 1.22 + if (HAS_PENDING_EXCEPTION) { 1.23 + java_lang_Throwable::print(PENDING_EXCEPTION, out); 1.24 + CLEAR_PENDING_EXCEPTION; 1.25 + // The exception has been printed on the output stream 1.26 + // If the JVM returns JNI_ERR, the attachAPI throws a generic I/O 1.27 + // exception and the content of the output stream is not processed. 1.28 + // By returning JNI_OK, the exception will be displayed on the client side 1.29 + } 1.30 + return JNI_OK; 1.31 +} 1.32 + 1.33 #ifndef SERVICES_KERNEL // Heap dumping not supported 1.34 // Implementation of "dumpheap" command. 1.35 // 1.36 @@ -366,6 +385,7 @@ 1.37 { "inspectheap", heap_inspection }, 1.38 { "setflag", set_flag }, 1.39 { "printflag", print_flag }, 1.40 + { "jcmd", jcmd }, 1.41 { NULL, NULL } 1.42 }; 1.43