src/share/vm/runtime/os.cpp

Print this page

        

@@ -441,10 +441,70 @@
     }
   }
   return _native_java_library;
 }
 
+/*
+ * Support for finding Agent_On(Un)Load/Attach_<lib_name> if it exists.
+ * If libName == NULL then just find normal Agent_On(Un)Load/Attach entry point
+ * If check_lib == true then we are looking for an
+ * Agent_OnLoad_libname or Agent_OnAttach_libname function to determine if
+ * this library is statically linked into the image.
+ */
+void* os::findAgentFunction(AgentLibrary *agentLib, bool checkLib,
+                            const char *syms[], size_t symsLen) {
+  const char *name;
+  void *handle = agentLib->os_lib();
+  void *entryName = NULL;
+  char *agentFunctionName;
+  size_t i;
+
+  // If checking then use the agent name otherwise test is_static_lib() to
+  // see how to process this lookup
+  name = ((checkLib || agentLib->is_static_lib()) ? agentLib->name() : NULL);
+  for (i = 0; i < symsLen; i++) {
+    agentFunctionName = buildAgentFunctionName(syms[i], name, agentLib->is_absolute_path());
+    if (agentFunctionName == NULL) {
+      break;
+    }
+    entryName = dll_lookup(handle, agentFunctionName);
+    FREE_C_HEAP_ARRAY(char, agentFunctionName, mtThread);
+    if(entryName != NULL) {
+      break;
+    }
+  }
+  return entryName;
+}
+
+// See if the passed in agent is statically linked into the VM image.
+bool os::findBuiltinAgent(AgentLibrary *agentLib, const char *syms[],
+                          size_t symsLen) {
+  void *ret;
+  void *procHandle;
+  void * saveHandle;
+  const char *name = agentLib->name();
+
+  if (name == NULL) {
+    return false;
+  }
+  procHandle = getDefaultProcessHandle();
+  // Check for Agent_OnLoad/Attach_libname function
+  saveHandle = agentLib->os_lib();
+  // We want to look in this process' symbol table.
+  agentLib->set_os_lib(procHandle);
+  ret = findAgentFunction(agentLib, true, syms, symsLen);
+  agentLib->set_os_lib(saveHandle);
+  if (ret != NULL) {
+    // Found an entry point like Agent_OnLoad_libname so we have a static agent
+    agentLib->set_os_lib(procHandle);
+    agentLib->set_valid();
+    agentLib->set_static_lib(true);
+    return true;
+  }
+  return false;
+}
+
 // --------------------- heap allocation utilities ---------------------
 
 char *os::strdup(const char *str, MEMFLAGS flags) {
   size_t size = strlen(str);
   char *dup_str = (char *)malloc(size + 1, flags);