Skip to content

Commit

Permalink
8336401: Remove the option onjcmd from the jdwp agent
Browse files Browse the repository at this point in the history
Reviewed-by: cjplummer, mbaesken
  • Loading branch information
parttimenerd committed Oct 18, 2024
1 parent 401d0d6 commit 309b929
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 241 deletions.
45 changes: 0 additions & 45 deletions src/hotspot/share/services/diagnosticCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#include "runtime/fieldDescriptor.inline.hpp"
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/interfaceSupport.inline.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/jniHandles.hpp"
#include "runtime/os.hpp"
Expand Down Expand Up @@ -160,11 +159,6 @@ void DCmd::register_dcmds(){
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));

// Debug on cmd (only makes sense with JVMTI since the agentlib needs it).
#if INCLUDE_JVMTI
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DebugOnCmdStartDCmd>(full_export, true, true));
#endif // INCLUDE_JVMTI

#if INCLUDE_CDS
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DumpSharedArchiveDCmd>(full_export, true, false));
#endif // INCLUDE_CDS
Expand Down Expand Up @@ -1058,45 +1052,6 @@ void DumpSharedArchiveDCmd::execute(DCmdSource source, TRAPS) {
}
#endif // INCLUDE_CDS

#if INCLUDE_JVMTI
extern "C" typedef char const* (JNICALL *debugInit_startDebuggingViaCommandPtr)(JNIEnv* env, jthread thread, char const** transport_name,
char const** address, jboolean* first_start);
static debugInit_startDebuggingViaCommandPtr dvc_start_ptr = nullptr;

void DebugOnCmdStartDCmd::execute(DCmdSource source, TRAPS) {
char const* transport = nullptr;
char const* addr = nullptr;
jboolean is_first_start = JNI_FALSE;
JavaThread* thread = THREAD;
jthread jt = JNIHandles::make_local(thread->threadObj());
ThreadToNativeFromVM ttn(thread);
const char *error = "Could not find jdwp agent.";

if (!dvc_start_ptr) {
JvmtiAgentList::Iterator it = JvmtiAgentList::agents();
while (it.has_next()) {
JvmtiAgent* agent = it.next();
if ((strcmp("jdwp", agent->name()) == 0) && (dvc_start_ptr == nullptr)) {
char const* func = "debugInit_startDebuggingViaCommand";
dvc_start_ptr = (debugInit_startDebuggingViaCommandPtr) os::find_agent_function(agent, false, &func, 1);
}
}
}

if (dvc_start_ptr) {
error = dvc_start_ptr(thread->jni_environment(), jt, &transport, &addr, &is_first_start);
}

if (error != nullptr) {
output()->print_cr("Debugging has not been started: %s", error);
} else {
output()->print_cr(is_first_start ? "Debugging has been started." : "Debugging is already active.");
output()->print_cr("Transport : %s", transport ? transport : "#unknown");
output()->print_cr("Address : %s", addr ? addr : "#unknown");
}
}
#endif // INCLUDE_JVMTI

ThreadDumpToFileDCmd::ThreadDumpToFileDCmd(outputStream* output, bool heap) :
DCmdWithParser(output, heap),
_overwrite("-overwrite", "May overwrite existing file", "BOOLEAN", false, "false"),
Expand Down
21 changes: 0 additions & 21 deletions src/hotspot/share/services/diagnosticCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,27 +886,6 @@ class ClassesDCmd : public DCmdWithParser {
virtual void execute(DCmdSource source, TRAPS);
};

#if INCLUDE_JVMTI
class DebugOnCmdStartDCmd : public DCmd {
public:
DebugOnCmdStartDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
static const char* name() {
return "VM.start_java_debugging";
}
static const char* description() {
return "Starts up the Java debugging if the jdwp agentlib was enabled with the option onjcmd=y.";
}
static const char* impact() {
return "High: Switches the VM into Java debug mode.";
}
static const JavaPermission permission() {
JavaPermission p = { "java.lang.management.ManagementPermission", "control", nullptr };
return p;
}
virtual void execute(DCmdSource source, TRAPS);
};
#endif // INCLUDE_JVMTI

class EventLogDCmd : public DCmdWithParser {
protected:
DCmdArgument<char*> _log;
Expand Down
64 changes: 0 additions & 64 deletions src/jdk.jdwp.agent/share/native/libjdwp/debugInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ static unsigned logflags = 0; /* Log flags */

static char *names; /* strings derived from OnLoad options */

static jboolean allowStartViaJcmd = JNI_FALSE; /* if true we allow the debugging to be started via a jcmd */
static jboolean startedViaJcmd = JNI_FALSE; /* if false, we have not yet started debugging via a jcmd */

/*
* Elements of the transports bag
*/
Expand Down Expand Up @@ -983,7 +980,6 @@ parseOptions(char *options)
int length;
char *str;
char *errmsg;
jboolean onJcmd = JNI_FALSE;

/* Set defaults */
gdata->assertOn = DEFAULT_ASSERT_ON;
Expand Down Expand Up @@ -1231,10 +1227,6 @@ parseOptions(char *options)
if ( !get_boolean(&str, &useStandardAlloc) ) {
goto syntax_error;
}
} else if (strcmp(buf, "onjcmd") == 0) {
if (!get_boolean(&str, &onJcmd)) {
goto syntax_error;
}
} else {
goto syntax_error;
}
Expand Down Expand Up @@ -1285,20 +1277,6 @@ parseOptions(char *options)
}
}

if (onJcmd) {
if (launchOnInit != NULL) {
errmsg = "Cannot combine onjcmd and launch suboptions";
goto bad_option_with_errmsg;
}
if (!isServer) {
errmsg = "Can only use onjcmd with server=y";
goto bad_option_with_errmsg;
}
suspendOnInit = JNI_FALSE;
initOnStartup = JNI_FALSE;
allowStartViaJcmd = JNI_TRUE;
}

return JNI_TRUE;

syntax_error:
Expand Down Expand Up @@ -1367,45 +1345,3 @@ debugInit_exit(jvmtiError error, const char *msg)
// Last chance to die, this kills the entire process.
forceExit(EXIT_JVMTI_ERROR);
}

static jboolean getFirstTransport(void *item, void *arg)
{
TransportSpec** store = arg;
*store = item;

return JNI_FALSE; /* Want the first */
}

/* Call to start up debugging. */
JNIEXPORT char const* JNICALL debugInit_startDebuggingViaCommand(JNIEnv* env, jthread thread, char const** transport_name,
char const** address, jboolean* first_start) {
jboolean is_first_start = JNI_FALSE;
TransportSpec* spec = NULL;

if (!vmInitialized) {
return "Not yet initialized. Try again later.";
}

if (!allowStartViaJcmd) {
return "Starting debugging via jcmd was not enabled via the onjcmd option of the jdwp agent.";
}

if (!startedViaJcmd) {
startedViaJcmd = JNI_TRUE;
is_first_start = JNI_TRUE;
initialize(env, thread, EI_VM_INIT, NULL);
}

bagEnumerateOver(transports, getFirstTransport, &spec);

if ((spec != NULL) && (transport_name != NULL) && (address != NULL)) {
*transport_name = spec->name;
*address = spec->address;
}

if (first_start != NULL) {
*first_start = is_first_start;
}

return NULL;
}
109 changes: 0 additions & 109 deletions test/jdk/com/sun/jdi/OnJcmdTest.java

This file was deleted.

4 changes: 2 additions & 2 deletions test/jdk/jdk/jfr/event/runtime/TestAgentEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* jdk.jfr.event.runtime.TestAgentEvent
* testJavaDynamic
*
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -agentlib:jdwp=transport=dt_socket,server=y,address=any,onjcmd=y
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0
* jdk.jfr.event.runtime.TestAgentEvent
* testNativeStatic
*/
Expand Down Expand Up @@ -122,7 +122,7 @@ private static void testNativeStatic() throws Throwable {
RecordedEvent e = events.get(1);
System.out.println(e);
Events.assertField(e, "name").equal("jdwp");
Events.assertField(e, "options").equal("transport=dt_socket,server=y,address=any,onjcmd=y");
Events.assertField(e, "options").equal("transport=dt_socket,server=y,suspend=n,address=0");
Events.assertField(e, "dynamic").equal(false);
Instant initializationTime = e.getInstant("initializationTime");
if (initializationTime.isAfter(interval.getStartTime())) {
Expand Down

0 comments on commit 309b929

Please sign in to comment.