Append the javaagent arg to JAVA_TOOL_OPTIONS to load jamm.
| 348 | |
| 349 | // Append the javaagent arg to JAVA_TOOL_OPTIONS to load jamm. |
| 350 | static Status JavaAddJammAgent() { |
| 351 | stringstream val_out; |
| 352 | char* current_val_c = getenv("JAVA_TOOL_OPTIONS"); |
| 353 | if (current_val_c != NULL) { |
| 354 | val_out << current_val_c << " "; |
| 355 | } |
| 356 | |
| 357 | istringstream classpath {getenv("CLASSPATH")}; |
| 358 | string jamm_path, test_path; |
| 359 | while (getline(classpath, test_path, ':')) { |
| 360 | Status status = FileSystemUtil::FindFileInPath(test_path, "jamm-.*.jar", &jamm_path); |
| 361 | // Error during FindFileInPath is not fatal if jamm path is found in another path. |
| 362 | if (!status.ok()) { |
| 363 | LOG(ERROR) << "Error when processing class path: " << status.msg().msg(); |
| 364 | } |
| 365 | if (!jamm_path.empty()) break; |
| 366 | } |
| 367 | if (jamm_path.empty()) { |
| 368 | return Status("Could not find jamm-*.jar in Java CLASSPATH"); |
| 369 | } |
| 370 | val_out << "-javaagent:" << jamm_path; |
| 371 | |
| 372 | if (setenv("JAVA_TOOL_OPTIONS", val_out.str().c_str(), 1) < 0) { |
| 373 | return Status(Substitute("Could not update JAVA_TOOL_OPTIONS: $0", GetStrErrMsg())); |
| 374 | } |
| 375 | return Status::OK(); |
| 376 | } |
| 377 | |
| 378 | // Append add-opens args to JAVA_TOOL_OPTIONS for ehcache and jamm. |
| 379 | static Status JavaAddOpens(bool useSizeOf) { |
no test coverage detected