8180709: java -javaagent:agent.jar with run-time that does not contain java.instrument prints confusing error
Reviewed-by: cjplummer, sspitsyn
--- a/src/hotspot/share/runtime/arguments.cpp Wed Dec 20 11:30:23 2017 -0800
+++ b/src/hotspot/share/runtime/arguments.cpp Wed Dec 20 13:41:40 2017 -0500
@@ -200,7 +200,9 @@
_writeable = writeable;
}
-AgentLibrary::AgentLibrary(const char* name, const char* options, bool is_absolute_path, void* os_lib) {
+AgentLibrary::AgentLibrary(const char* name, const char* options,
+ bool is_absolute_path, void* os_lib,
+ bool instrument_lib) {
_name = AllocateHeap(strlen(name)+1, mtArguments);
strcpy(_name, name);
if (options == NULL) {
@@ -214,6 +216,7 @@
_next = NULL;
_state = agent_invalid;
_is_static_lib = false;
+ _is_instrument_lib = instrument_lib;
}
// Check if head of 'option' matches 'name', and sets 'tail' to the remaining
@@ -290,6 +293,10 @@
_agentList.add(new AgentLibrary(name, options, absolute_path, NULL));
}
+void Arguments::add_instrument_agent(const char* name, char* options, bool absolute_path) {
+ _agentList.add(new AgentLibrary(name, options, absolute_path, NULL, true));
+}
+
// Late-binding agents not started via arguments
void Arguments::add_loaded_agent(AgentLibrary *agentLib) {
_agentList.add(agentLib);
@@ -2791,7 +2798,7 @@
size_t length = strlen(tail) + 1;
char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
jio_snprintf(options, length, "%s", tail);
- add_init_agent("instrument", options, false);
+ add_instrument_agent("instrument", options, false);
// java agents need module java.instrument
if (!create_numbered_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
return JNI_ENOMEM;
--- a/src/hotspot/share/runtime/arguments.hpp Wed Dec 20 11:30:23 2017 -0800
+++ b/src/hotspot/share/runtime/arguments.hpp Wed Dec 20 13:41:40 2017 -0500
@@ -142,6 +142,7 @@
void* _os_lib;
bool _is_absolute_path;
bool _is_static_lib;
+ bool _is_instrument_lib;
AgentState _state;
AgentLibrary* _next;
@@ -154,13 +155,15 @@
void set_os_lib(void* os_lib) { _os_lib = os_lib; }
AgentLibrary* next() const { return _next; }
bool is_static_lib() const { return _is_static_lib; }
+ bool is_instrument_lib() const { return _is_instrument_lib; }
void set_static_lib(bool is_static_lib) { _is_static_lib = is_static_lib; }
bool valid() { return (_state == agent_valid); }
void set_valid() { _state = agent_valid; }
void set_invalid() { _state = agent_invalid; }
// Constructor
- AgentLibrary(const char* name, const char* options, bool is_absolute_path, void* os_lib);
+ AgentLibrary(const char* name, const char* options, bool is_absolute_path,
+ void* os_lib, bool instrument_lib=false);
};
// maintain an order of entry list of AgentLibrary
@@ -337,6 +340,7 @@
// -agentlib and -agentpath arguments
static AgentLibraryList _agentList;
static void add_init_agent(const char* name, char* options, bool absolute_path);
+ static void add_instrument_agent(const char* name, char* options, bool absolute_path);
// Late-binding agents not started via arguments
static void add_loaded_agent(AgentLibrary *agentLib);
--- a/src/hotspot/share/runtime/thread.cpp Wed Dec 20 11:30:23 2017 -0800
+++ b/src/hotspot/share/runtime/thread.cpp Wed Dec 20 13:41:40 2017 -0500
@@ -4038,9 +4038,16 @@
}
if (library == NULL) {
const char *sub_msg = " on the library path, with error: ";
- size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1;
+ const char *sub_msg2 = "\nModule java.instrument may be missing from runtime image.";
+
+ size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) +
+ strlen(ebuf) + strlen(sub_msg2) + 1;
char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread);
- jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf);
+ if (!agent->is_instrument_lib()) {
+ jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf);
+ } else {
+ jio_snprintf(buf, len, "%s%s%s%s%s", msg, name, sub_msg, ebuf, sub_msg2);
+ }
// If we can't find the agent, exit.
vm_exit_during_initialization(buf, NULL);
FREE_C_HEAP_ARRAY(char, buf);