xref: /aosp_15_r20/external/jazzer-api/launcher/jvm_tooling.h (revision 33edd6723662ea34453766bfdca85dbfdd5342b8)
1 /*
2  * Copyright 2021 Code Intelligence GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <jni.h>
20 
21 #include <string>
22 
23 extern std::string FLAGS_cp;
24 extern std::string FLAGS_jvm_args;
25 extern std::string FLAGS_additional_jvm_args;
26 extern std::string FLAGS_agent_path;
27 
28 namespace jazzer {
29 
30 void DumpJvmStackTraces();
31 
32 // JVM is a thin wrapper around JNI_CreateJavaVM and DestroyJavaVM. The JVM
33 // instance is created inside the constructor with some default JNI options
34 // + options which can be added to via command line flags.
35 class JVM {
36  private:
37   JavaVM *jvm_;
38   JNIEnv *env_;
39 
40  public:
41   // Creates a JVM instance with default options + options that were provided as
42   // command line flags.
43   explicit JVM();
44 
45   // Destroy the running JVM instance.
46   ~JVM();
47 
48   // Get the JNI environment for interaction with the running JVM instance.
49   JNIEnv &GetEnv() const;
50 };
51 } /* namespace jazzer */
52