1491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom/*
2491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * Copyright (C) 2011 The Android Open Source Project
3491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom *
4491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License");
5491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * you may not use this file except in compliance with the License.
6491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * You may obtain a copy of the License at
7491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom *
8491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom *      http://www.apache.org/licenses/LICENSE-2.0
9491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom *
10491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * Unless required by applicable law or agreed to in writing, software
11491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS,
12491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * See the License for the specific language governing permissions and
14491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom * limitations under the License.
15491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom */
16491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
17491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom#ifndef ART_RUNTIME_PARSED_OPTIONS_H_
18491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom#define ART_RUNTIME_PARSED_OPTIONS_H_
19491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
20491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom#include <string>
21e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <vector>
22491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
23e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <jni.h>
24e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers
25e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "globals.h"
26576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers#include "gc/collector_type.h"
272dbe627954fd78a3659ab3cd42d2ead5b4529441Mathieu Chartier#include "gc/space/large_object_space.h"
28d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers#include "arch/instruction_set.h"
29e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "profiler_options.h"
30aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin#include "runtime_options.h"
31491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
32491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstromnamespace art {
33491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
34e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersclass CompilerCallbacks;
35e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersclass DexFile;
36aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkinstruct RuntimeArgumentMap;
37e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers
38e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogerstypedef std::vector<std::pair<std::string, const void*>> RuntimeOptions;
39e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers
40aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkintemplate <typename TVariantMap,
41aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin          template <typename TKeyValue> class TVariantMapKey>
42aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkinstruct CmdlineParser;
43aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin
44491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstromclass ParsedOptions {
45491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom public:
46aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  using RuntimeParser = CmdlineParser<RuntimeArgumentMap, RuntimeArgumentMap::Key>;
47aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  // Create a parser that can turn user-defined input into a RuntimeArgumentMap.
48aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  // This visibility is effectively for testing-only, and normal code does not
49aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  // need to create its own parser.
50aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  static std::unique_ptr<RuntimeParser> MakeParser(bool ignore_unrecognized);
51aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin
52aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  // returns true if parsing succeeds, and stores the resulting options into runtime_options
5388b2b80aed15bb1f931cddd40e44ca525ef10018Vladimir Marko  static bool Parse(const RuntimeOptions& options,
5488b2b80aed15bb1f931cddd40e44ca525ef10018Vladimir Marko                    bool ignore_unrecognized,
5588b2b80aed15bb1f931cddd40e44ca525ef10018Vladimir Marko                    RuntimeArgumentMap* runtime_options);
56aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin
57491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  bool (*hook_is_sensitive_thread_)();
58491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap);
59491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  void (*hook_exit_)(jint status);
60491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  void (*hook_abort_)();
610025a86411145eb7cd4971f9234fc21c7b4aced1Nicolas Geoffray
62491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom private:
63313f40345a2bbea299a035d4176272d1a6622afdAndreas Gampe  ParsedOptions();
64491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
65aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin  bool ProcessSpecialOptions(const RuntimeOptions& options,
66aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin                             RuntimeArgumentMap* runtime_options,
67aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin                             std::vector<std::string>* out_options);
68aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin
69491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  void Usage(const char* fmt, ...);
70491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  void UsageMessage(FILE* stream, const char* fmt, ...);
71491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  void UsageMessageV(FILE* stream, const char* fmt, va_list ap);
72491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
73491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  void Exit(int status);
74491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom  void Abort();
75491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
7688b2b80aed15bb1f931cddd40e44ca525ef10018Vladimir Marko  bool DoParse(const RuntimeOptions& options,
7788b2b80aed15bb1f931cddd40e44ca525ef10018Vladimir Marko               bool ignore_unrecognized,
7888b2b80aed15bb1f931cddd40e44ca525ef10018Vladimir Marko               RuntimeArgumentMap* runtime_options);
79491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom};
80491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
81491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom}  // namespace art
82491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom
83491ca9e75fad381468dd7f5fdbff56d1a9738dd7Brian Carlstrom#endif  // ART_RUNTIME_PARSED_OPTIONS_H_
84