src/share/vm/runtime/thread.cpp
Print this page
*** 3694,3712 ****
// Find a command line agent library and return its entry point for
// -agentlib: -agentpath: -Xrun
// num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array.
static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) {
OnLoadEntry_t on_load_entry = NULL;
! void *library = agent->os_lib(); // check if we have looked it up before
! if (library == NULL) {
char buffer[JVM_MAXPATHLEN];
char ebuf[1024];
const char *name = agent->name();
const char *msg = "Could not find agent library ";
! if (agent->is_absolute_path()) {
library = os::dll_load(name, ebuf, sizeof ebuf);
if (library == NULL) {
const char *sub_msg = " in absolute path, with error: ";
size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1;
char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread);
--- 3694,3715 ----
// Find a command line agent library and return its entry point for
// -agentlib: -agentpath: -Xrun
// num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array.
static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) {
OnLoadEntry_t on_load_entry = NULL;
! void *library = NULL;
! if (!agent->valid()) {
char buffer[JVM_MAXPATHLEN];
char ebuf[1024];
const char *name = agent->name();
const char *msg = "Could not find agent library ";
! // First check to see if agent is statcally linked into executable
! if (os::find_builtin_agent(agent, on_load_symbols, num_symbol_entries)) {
! library = agent->os_lib();
! } else if (agent->is_absolute_path()) {
library = os::dll_load(name, ebuf, sizeof ebuf);
if (library == NULL) {
const char *sub_msg = " in absolute path, with error: ";
size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1;
char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread);
*** 3736,3752 ****
FREE_C_HEAP_ARRAY(char, buf, mtThread);
}
}
}
agent->set_os_lib(library);
}
// Find the OnLoad function.
! for (size_t symbol_index = 0; symbol_index < num_symbol_entries; symbol_index++) {
! on_load_entry = CAST_TO_FN_PTR(OnLoadEntry_t, os::dll_lookup(library, on_load_symbols[symbol_index]));
! if (on_load_entry != NULL) break;
! }
return on_load_entry;
}
// Find the JVM_OnLoad entry point
static OnLoadEntry_t lookup_jvm_on_load(AgentLibrary* agent) {
--- 3739,3757 ----
FREE_C_HEAP_ARRAY(char, buf, mtThread);
}
}
}
agent->set_os_lib(library);
+ agent->set_valid();
}
// Find the OnLoad function.
! on_load_entry =
! CAST_TO_FN_PTR(OnLoadEntry_t, os::find_agent_function(agent,
! false,
! on_load_symbols,
! num_symbol_entries));
return on_load_entry;
}
// Find the JVM_OnLoad entry point
static OnLoadEntry_t lookup_jvm_on_load(AgentLibrary* agent) {
*** 3817,3842 ****
}
void Threads::shutdown_vm_agents() {
// Send any Agent_OnUnload notifications
const char *on_unload_symbols[] = AGENT_ONUNLOAD_SYMBOLS;
extern struct JavaVM_ main_vm;
for (AgentLibrary* agent = Arguments::agents(); agent != NULL; agent = agent->next()) {
// Find the Agent_OnUnload function.
- for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_unload_symbols); symbol_index++) {
Agent_OnUnload_t unload_entry = CAST_TO_FN_PTR(Agent_OnUnload_t,
! os::dll_lookup(agent->os_lib(), on_unload_symbols[symbol_index]));
// Invoke the Agent_OnUnload function
if (unload_entry != NULL) {
JavaThread* thread = JavaThread::current();
ThreadToNativeFromVM ttn(thread);
HandleMark hm(thread);
(*unload_entry)(&main_vm);
- break;
- }
}
}
}
// Called for after the VM is initialized for -Xrun libraries which have not been converted to agent libraries
--- 3822,3848 ----
}
void Threads::shutdown_vm_agents() {
// Send any Agent_OnUnload notifications
const char *on_unload_symbols[] = AGENT_ONUNLOAD_SYMBOLS;
+ size_t num_symbol_entries = ARRAY_SIZE(on_unload_symbols);
extern struct JavaVM_ main_vm;
for (AgentLibrary* agent = Arguments::agents(); agent != NULL; agent = agent->next()) {
// Find the Agent_OnUnload function.
Agent_OnUnload_t unload_entry = CAST_TO_FN_PTR(Agent_OnUnload_t,
! os::find_agent_function(agent,
! false,
! on_unload_symbols,
! num_symbol_entries));
// Invoke the Agent_OnUnload function
if (unload_entry != NULL) {
JavaThread* thread = JavaThread::current();
ThreadToNativeFromVM ttn(thread);
HandleMark hm(thread);
(*unload_entry)(&main_vm);
}
}
}
// Called for after the VM is initialized for -Xrun libraries which have not been converted to agent libraries