| 221 | } |
| 222 | |
| 223 | JVM::JVM() { |
| 224 | std::string class_path = GetClassPath(); |
| 225 | |
| 226 | std::vector<JavaVMOption> options; |
| 227 | options.push_back(JavaVMOption{const_cast<char *>(class_path.c_str())}); |
| 228 | |
| 229 | #if !defined(__ANDROID__) |
| 230 | // Set the maximum heap size to a value that is slightly smaller than |
| 231 | // libFuzzer's default rss_limit_mb. This prevents erroneous oom reports. |
| 232 | // Note: This approach is deprecated and only kept here for backwards |
| 233 | // compatibility. The new approach is to set -rss_limit_mb to a |
| 234 | // suitable value based on the JVM heap size when starting libFuzzer |
| 235 | // as part of the Jazzer driver. |
| 236 | options.push_back(JavaVMOption{(char *)"-Xmx1800m"}); |
| 237 | // Preserve and emit stack trace information even on hot paths. |
| 238 | // This may hurt performance, but also helps find flaky bugs. |
| 239 | options.push_back(JavaVMOption{(char *)"-XX:-OmitStackTraceInFastThrow"}); |
| 240 | // Optimize GC for high throughput rather than low latency. |
| 241 | options.push_back(JavaVMOption{(char *)"-XX:+UseParallelGC"}); |
| 242 | // CriticalJNINatives has been removed in JDK 18, EnableDynamicAgentLoading |
| 243 | // has been added in JDK 9. |
| 244 | options.push_back(JavaVMOption{(char *)"-XX:+IgnoreUnrecognizedVMOptions"}); |
| 245 | options.push_back(JavaVMOption{(char *)"-XX:+CriticalJNINatives"}); |
| 246 | options.push_back(JavaVMOption{(char *)"-XX:+EnableDynamicAgentLoading"}); |
| 247 | #endif |
| 248 | |
| 249 | std::vector<std::string> java_opts_args; |
| 250 | const char *java_opts = std::getenv("JAVA_OPTS"); |
| 251 | if (java_opts != nullptr) { |
| 252 | // Mimic the behavior of the JVM when it sees JAVA_TOOL_OPTIONS. |
| 253 | std::cerr << "Picked up JAVA_OPTS: " << java_opts << std::endl; |
| 254 | |
| 255 | java_opts_args = absl::StrSplit(java_opts, ' '); |
| 256 | for (const std::string &java_opt : java_opts_args) { |
| 257 | options.push_back(JavaVMOption{const_cast<char *>(java_opt.c_str())}); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | // Add additional jvm options set through command line flags. |
| 262 | // Keep the vectors in scope as they contain the strings backing the C strings |
| 263 | // added to options. |
| 264 | std::vector<std::string> jvm_args; |
| 265 | if (!FLAGS_jvm_args.empty()) { |
| 266 | jvm_args = splitEscaped(FLAGS_jvm_args); |
| 267 | for (const auto &arg : jvm_args) { |
| 268 | options.push_back(JavaVMOption{const_cast<char *>(arg.c_str())}); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | std::vector<std::string> additional_jvm_args; |
| 273 | if (!FLAGS_additional_jvm_args.empty()) { |
| 274 | additional_jvm_args = splitEscaped(FLAGS_additional_jvm_args); |
| 275 | for (const auto &arg : additional_jvm_args) { |
| 276 | options.push_back(JavaVMOption{const_cast<char *>(arg.c_str())}); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | #if !defined(__ANDROID__) |
nothing calls this directly
no test coverage detected