comparison src/share/vm/runtime/thread.cpp @ 12117:f92b82d454fa

8014135: The JVMTI specification does not conform to recent changes in JNI specification Summary: Added support for statically linked agents Reviewed-by: sspitsyn, bobv, coleenp
author bpittore
date Fri, 23 Aug 2013 20:33:02 -0400
parents 02d7aa1456c9
children 27ffd1c4537b 623d923529df e2722a66aba7
comparison
equal deleted inserted replaced
12094:73921c720b94 12117:f92b82d454fa
3694 // Find a command line agent library and return its entry point for 3694 // Find a command line agent library and return its entry point for
3695 // -agentlib: -agentpath: -Xrun 3695 // -agentlib: -agentpath: -Xrun
3696 // num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array. 3696 // num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array.
3697 static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) { 3697 static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) {
3698 OnLoadEntry_t on_load_entry = NULL; 3698 OnLoadEntry_t on_load_entry = NULL;
3699 void *library = agent->os_lib(); // check if we have looked it up before 3699 void *library = NULL;
3700 3700
3701 if (library == NULL) { 3701 if (!agent->valid()) {
3702 char buffer[JVM_MAXPATHLEN]; 3702 char buffer[JVM_MAXPATHLEN];
3703 char ebuf[1024]; 3703 char ebuf[1024];
3704 const char *name = agent->name(); 3704 const char *name = agent->name();
3705 const char *msg = "Could not find agent library "; 3705 const char *msg = "Could not find agent library ";
3706 3706
3707 if (agent->is_absolute_path()) { 3707 // First check to see if agent is statcally linked into executable
3708 if (os::find_builtin_agent(agent, on_load_symbols, num_symbol_entries)) {
3709 library = agent->os_lib();
3710 } else if (agent->is_absolute_path()) {
3708 library = os::dll_load(name, ebuf, sizeof ebuf); 3711 library = os::dll_load(name, ebuf, sizeof ebuf);
3709 if (library == NULL) { 3712 if (library == NULL) {
3710 const char *sub_msg = " in absolute path, with error: "; 3713 const char *sub_msg = " in absolute path, with error: ";
3711 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; 3714 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1;
3712 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread); 3715 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread);
3736 FREE_C_HEAP_ARRAY(char, buf, mtThread); 3739 FREE_C_HEAP_ARRAY(char, buf, mtThread);
3737 } 3740 }
3738 } 3741 }
3739 } 3742 }
3740 agent->set_os_lib(library); 3743 agent->set_os_lib(library);
3744 agent->set_valid();
3741 } 3745 }
3742 3746
3743 // Find the OnLoad function. 3747 // Find the OnLoad function.
3744 for (size_t symbol_index = 0; symbol_index < num_symbol_entries; symbol_index++) { 3748 on_load_entry =
3745 on_load_entry = CAST_TO_FN_PTR(OnLoadEntry_t, os::dll_lookup(library, on_load_symbols[symbol_index])); 3749 CAST_TO_FN_PTR(OnLoadEntry_t, os::find_agent_function(agent,
3746 if (on_load_entry != NULL) break; 3750 false,
3747 } 3751 on_load_symbols,
3752 num_symbol_entries));
3748 return on_load_entry; 3753 return on_load_entry;
3749 } 3754 }
3750 3755
3751 // Find the JVM_OnLoad entry point 3756 // Find the JVM_OnLoad entry point
3752 static OnLoadEntry_t lookup_jvm_on_load(AgentLibrary* agent) { 3757 static OnLoadEntry_t lookup_jvm_on_load(AgentLibrary* agent) {
3817 } 3822 }
3818 3823
3819 void Threads::shutdown_vm_agents() { 3824 void Threads::shutdown_vm_agents() {
3820 // Send any Agent_OnUnload notifications 3825 // Send any Agent_OnUnload notifications
3821 const char *on_unload_symbols[] = AGENT_ONUNLOAD_SYMBOLS; 3826 const char *on_unload_symbols[] = AGENT_ONUNLOAD_SYMBOLS;
3827 size_t num_symbol_entries = ARRAY_SIZE(on_unload_symbols);
3822 extern struct JavaVM_ main_vm; 3828 extern struct JavaVM_ main_vm;
3823 for (AgentLibrary* agent = Arguments::agents(); agent != NULL; agent = agent->next()) { 3829 for (AgentLibrary* agent = Arguments::agents(); agent != NULL; agent = agent->next()) {
3824 3830
3825 // Find the Agent_OnUnload function. 3831 // Find the Agent_OnUnload function.
3826 for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_unload_symbols); symbol_index++) { 3832 Agent_OnUnload_t unload_entry = CAST_TO_FN_PTR(Agent_OnUnload_t,
3827 Agent_OnUnload_t unload_entry = CAST_TO_FN_PTR(Agent_OnUnload_t, 3833 os::find_agent_function(agent,
3828 os::dll_lookup(agent->os_lib(), on_unload_symbols[symbol_index])); 3834 false,
3829 3835 on_unload_symbols,
3830 // Invoke the Agent_OnUnload function 3836 num_symbol_entries));
3831 if (unload_entry != NULL) { 3837
3832 JavaThread* thread = JavaThread::current(); 3838 // Invoke the Agent_OnUnload function
3833 ThreadToNativeFromVM ttn(thread); 3839 if (unload_entry != NULL) {
3834 HandleMark hm(thread); 3840 JavaThread* thread = JavaThread::current();
3835 (*unload_entry)(&main_vm); 3841 ThreadToNativeFromVM ttn(thread);
3836 break; 3842 HandleMark hm(thread);
3837 } 3843 (*unload_entry)(&main_vm);
3838 } 3844 }
3839 } 3845 }
3840 } 3846 }
3841 3847
3842 // Called for after the VM is initialized for -Xrun libraries which have not been converted to agent libraries 3848 // Called for after the VM is initialized for -Xrun libraries which have not been converted to agent libraries