8336401: Remove the option onjcmd from the jdwp agent
Reviewed-by: cjplummer, mbaesken
This commit is contained in:
parent
401d0d6b09
commit
309b929147
@ -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"
|
||||
@ -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
|
||||
@ -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"),
|
||||
|
@ -886,27 +886,6 @@ public:
|
||||
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;
|
||||
|
@ -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
|
||||
*/
|
||||
@ -983,7 +980,6 @@ parseOptions(char *options)
|
||||
int length;
|
||||
char *str;
|
||||
char *errmsg;
|
||||
jboolean onJcmd = JNI_FALSE;
|
||||
|
||||
/* Set defaults */
|
||||
gdata->assertOn = DEFAULT_ASSERT_ON;
|
||||
@ -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;
|
||||
}
|
||||
@ -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:
|
||||
@ -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;
|
||||
}
|
||||
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018 SAP SE. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8214892
|
||||
* @summary Test that the onjcmd option of the jdwp agent works.
|
||||
*
|
||||
* @author Ralf Schmelter
|
||||
*
|
||||
* @library /test/lib
|
||||
* @run compile --add-exports java.base/jdk.internal.vm=ALL-UNNAMED -g OnJcmdTest.java
|
||||
* @run main/othervm --add-exports java.base/jdk.internal.vm=ALL-UNNAMED -agentlib:jdwp=transport=dt_socket,address=localhost:0,onjcmd=y,server=y OnJcmdTest
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Properties;
|
||||
|
||||
import jdk.internal.vm.VMSupport;
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
public class OnJcmdTest {
|
||||
|
||||
private static String getListenerAddress() throws Exception {
|
||||
Properties props = VMSupport.getAgentProperties();
|
||||
return props.getProperty("sun.jdwp.listenerAddress", null);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// First check if we get the expected errors.
|
||||
OutputAnalyzer output = ProcessTools.executeTestJava(
|
||||
"-agentlib:jdwp=transport=dt_socket,address=any,onjcmd=y");
|
||||
output.shouldContain("Can only use onjcmd with server=y");
|
||||
output.shouldHaveExitValue(1);
|
||||
|
||||
output = ProcessTools.executeTestJava(
|
||||
"-agentlib:jdwp=transport=dt_socket,address=any,onjcmd=y,onthrow=a,launch=a");
|
||||
output.shouldContain("Cannot combine onjcmd and launch suboptions");
|
||||
output.shouldHaveExitValue(1);
|
||||
|
||||
// Make sure debugging is not yet started.
|
||||
String prop = getListenerAddress();
|
||||
|
||||
if (prop != null) {
|
||||
throw new RuntimeException("Listener address was set to " + prop);
|
||||
}
|
||||
|
||||
// Now start it (test that it is OK to do this more than once).
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
String jcmd = JDKToolFinder.getJDKTool("jcmd");
|
||||
output = ProcessTools.executeProcess(jcmd,
|
||||
Long.toString(ProcessTools.getProcessId()),
|
||||
"VM.start_java_debugging");
|
||||
|
||||
String exp_str = i == 0 ? "Debugging has been started." :
|
||||
"Debugging is already active.";
|
||||
output.shouldContain(exp_str);
|
||||
output.shouldContain("Transport : dt_socket");
|
||||
output.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
// Now the property should be set, as the jdwp agent waits for a
|
||||
// connection.
|
||||
long t1 = System.currentTimeMillis();
|
||||
long t2 = t1;
|
||||
|
||||
while(t2 - t1 < 4000) {
|
||||
prop = getListenerAddress();
|
||||
|
||||
if (prop != null) {
|
||||
if (prop.equals("localhost:0")) {
|
||||
throw new RuntimeException("Port was not expanded");
|
||||
} else if (!prop.startsWith("dt_socket:")) {
|
||||
throw new RuntimeException("Invalid transport prop " + prop);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.sleep(50);
|
||||
t2 = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
throw new RuntimeException("Debugging backend didn't start");
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@ import jdk.test.lib.jfr.TestClassLoader;
|
||||
* 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
|
||||
*/
|
||||
@ -122,7 +122,7 @@ public final class TestAgentEvent {
|
||||
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())) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user