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