src/share/vm/runtime/os.cpp

changeset 6239
2a907fd129cb
parent 6238
7ccce1a6fa4d
parent 5585
f92b82d454fa
child 6240
9b4ce069642e
     1.1 --- a/src/share/vm/runtime/os.cpp	Thu Sep 05 10:29:00 2013 -0400
     1.2 +++ b/src/share/vm/runtime/os.cpp	Fri Sep 06 09:55:38 2013 +0100
     1.3 @@ -443,6 +443,67 @@
     1.4    return _native_java_library;
     1.5  }
     1.6  
     1.7 +/*
     1.8 + * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists.
     1.9 + * If check_lib == true then we are looking for an
    1.10 + * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if
    1.11 + * this library is statically linked into the image.
    1.12 + * If check_lib == false then we will look for the appropriate symbol in the
    1.13 + * executable if agent_lib->is_static_lib() == true or in the shared library
    1.14 + * referenced by 'handle'.
    1.15 + */
    1.16 +void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib,
    1.17 +                              const char *syms[], size_t syms_len) {
    1.18 +  const char *lib_name;
    1.19 +  void *handle = agent_lib->os_lib();
    1.20 +  void *entryName = NULL;
    1.21 +  char *agent_function_name;
    1.22 +  size_t i;
    1.23 +
    1.24 +  // If checking then use the agent name otherwise test is_static_lib() to
    1.25 +  // see how to process this lookup
    1.26 +  lib_name = ((check_lib || agent_lib->is_static_lib()) ? agent_lib->name() : NULL);
    1.27 +  for (i = 0; i < syms_len; i++) {
    1.28 +    agent_function_name = build_agent_function_name(syms[i], lib_name, agent_lib->is_absolute_path());
    1.29 +    if (agent_function_name == NULL) {
    1.30 +      break;
    1.31 +    }
    1.32 +    entryName = dll_lookup(handle, agent_function_name);
    1.33 +    FREE_C_HEAP_ARRAY(char, agent_function_name, mtThread);
    1.34 +    if (entryName != NULL) {
    1.35 +      break;
    1.36 +    }
    1.37 +  }
    1.38 +  return entryName;
    1.39 +}
    1.40 +
    1.41 +// See if the passed in agent is statically linked into the VM image.
    1.42 +bool os::find_builtin_agent(AgentLibrary *agent_lib, const char *syms[],
    1.43 +                            size_t syms_len) {
    1.44 +  void *ret;
    1.45 +  void *proc_handle;
    1.46 +  void *save_handle;
    1.47 +
    1.48 +  if (agent_lib->name() == NULL) {
    1.49 +    return false;
    1.50 +  }
    1.51 +  proc_handle = get_default_process_handle();
    1.52 +  // Check for Agent_OnLoad/Attach_lib_name function
    1.53 +  save_handle = agent_lib->os_lib();
    1.54 +  // We want to look in this process' symbol table.
    1.55 +  agent_lib->set_os_lib(proc_handle);
    1.56 +  ret = find_agent_function(agent_lib, true, syms, syms_len);
    1.57 +  agent_lib->set_os_lib(save_handle);
    1.58 +  if (ret != NULL) {
    1.59 +    // Found an entry point like Agent_OnLoad_lib_name so we have a static agent
    1.60 +    agent_lib->set_os_lib(proc_handle);
    1.61 +    agent_lib->set_valid();
    1.62 +    agent_lib->set_static_lib(true);
    1.63 +    return true;
    1.64 +  }
    1.65 +  return false;
    1.66 +}
    1.67 +
    1.68  // --------------------- heap allocation utilities ---------------------
    1.69  
    1.70  char *os::strdup(const char *str, MEMFLAGS flags) {

mercurial