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 "profiler_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 ParsedOptions* Create(const RuntimeOptions& options, bool ignore_unrecognized,
54                                RuntimeArgumentMap* runtime_options);
55 
56   bool (*hook_is_sensitive_thread_)();
57   jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap);
58   void (*hook_exit_)(jint status);
59   void (*hook_abort_)();
60 
61  private:
62   ParsedOptions();
63 
64   bool ProcessSpecialOptions(const RuntimeOptions& options,
65                              RuntimeArgumentMap* runtime_options,
66                              std::vector<std::string>* out_options);
67 
68   void Usage(const char* fmt, ...);
69   void UsageMessage(FILE* stream, const char* fmt, ...);
70   void UsageMessageV(FILE* stream, const char* fmt, va_list ap);
71 
72   void Exit(int status);
73   void Abort();
74 
75   bool Parse(const RuntimeOptions& options,  bool ignore_unrecognized,
76              RuntimeArgumentMap* runtime_options);
77 };
78 
79 }  // namespace art
80 
81 #endif  // ART_RUNTIME_PARSED_OPTIONS_H_
82