MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / loadJvmLib

Function loadJvmLib

test/test/nonjava/non_java_app.cpp:87–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87void loadJvmLib() {
88 char* java_home = getenv("TEST_JAVA_HOME");
89 if (java_home == NULL) {
90 std::cerr << "TEST_JAVA_HOME is not set" << std::endl;
91 exit(1);
92 }
93
94 // Check that libjvm is found under the standard path
95 char lib_path[PATH_MAX + 280];
96 snprintf(lib_path, sizeof(lib_path), "%s/%s/%s", java_home, "lib", jvm_lib_path);
97 if ((_jvm_lib = dlopen(lib_path, RTLD_LOCAL | RTLD_NOW)) != NULL) {
98 return;
99 }
100
101 // JDK 8 has different directory layout. libjvm path will be the following:
102 // ${TEST_JAVA_HOME}/lib/${ARCH}/server/libjvm.(so|dylib)
103 char java_lib_home[PATH_MAX];
104 snprintf(java_lib_home, sizeof(java_lib_home), "%s/lib", java_home);
105
106 DIR* dir = opendir(java_lib_home);
107 if (dir == NULL) {
108 std::cerr << "Error opening directory: " << java_lib_home << std::endl;
109 exit(1);
110 }
111
112 struct dirent* entry;
113 while ((entry = readdir(dir)) != NULL) {
114 if (strcmp(entry->d_name, "..") == 0 || strcmp(entry->d_name, ".") == 0) {
115 continue;
116 }
117
118 snprintf(lib_path, sizeof(lib_path), "%s/%s/%s", java_lib_home, entry->d_name, jvm_lib_path);
119 if ((_jvm_lib = dlopen(lib_path, RTLD_LOCAL | RTLD_NOW)) != NULL) {
120 break;
121 }
122 }
123 closedir(dir);
124
125 if (_jvm_lib == NULL) {
126 std::cerr << "Unable to find: libjvm" << std::endl;
127 exit(1);
128 }
129}
130
131void startJvm() {
132 JavaVMInitArgs vm_args;

Callers 4

testFlow1Function · 0.85
testFlow2Function · 0.85
testFlow3Function · 0.85
jvmThreadWrapperFunction · 0.85

Calls 1

dlopenFunction · 0.85

Tested by

no test coverage detected