1 /*
2  * Copyright (C) 2011 The Android Open Source Project
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 #ifndef ART_RUNTIME_PARSED_OPTIONS_H_
18 #define ART_RUNTIME_PARSED_OPTIONS_H_
19 
20 #include <string>
21 #include <string_view>
22 #include <vector>
23 
24 #include <jni.h>
25 
26 #include "arch/instruction_set.h"
27 #include "gc/collector_type.h"
28 #include "gc/space/image_space_loading_order.h"
29 #include "gc/space/large_object_space.h"
30 // #include "jit/profile_saver_options.h"
31 #include "runtime_globals.h"
32 #include "runtime_options.h"
33 
34 namespace art {
35 
36 class CompilerCallbacks;
37 class DexFile;
38 struct RuntimeArgumentMap;
39 
40 typedef std::vector<std::pair<std::string, const void*>> RuntimeOptions;
41 
42 template <typename TVariantMap,
43           template <typename TKeyValue> class TVariantMapKey>
44 struct CmdlineParser;
45 
46 class ParsedOptions {
47  public:
48   using RuntimeParser = CmdlineParser<RuntimeArgumentMap, RuntimeArgumentMap::Key>;
49   // Create a parser that can turn user-defined input into a RuntimeArgumentMap.
50   // This visibility is effectively for testing-only, and normal code does not
51   // need to create its own parser.
52   static std::unique_ptr<RuntimeParser> MakeParser(bool ignore_unrecognized);
53 
54   // returns true if parsing succeeds, and stores the resulting options into runtime_options
55   static bool Parse(const RuntimeOptions& options,
56                     bool ignore_unrecognized,
57                     RuntimeArgumentMap* runtime_options);
58 
59   bool (*hook_is_sensitive_thread_)();
60   jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap);
61   void (*hook_exit_)(jint status);
62   void (*hook_abort_)();
63 
64  private:
65   ParsedOptions();
66 
67   bool ProcessSpecialOptions(const RuntimeOptions& options,
68                              RuntimeArgumentMap* runtime_options,
69                              std::vector<std::string>* out_options);
70 
71   void Usage(const char* fmt, ...);
72   void UsageMessage(FILE* stream, const char* fmt, ...);
73   void UsageMessageV(FILE* stream, const char* fmt, va_list ap);
74 
75   void Exit(int status);
76   void Abort();
77 
78   bool DoParse(const RuntimeOptions& options,
79                bool ignore_unrecognized,
80                RuntimeArgumentMap* runtime_options);
81 };
82 
83 }  // namespace art
84 
85 #endif  // ART_RUNTIME_PARSED_OPTIONS_H_
86