1/*
2 * Copyright (c) 2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20/*
21    Environment.h
22    Environment Variables
23    Copyright (c) 2004-2011 Apple Inc. All rights reserved.
24 */
25
26#pragma
27#ifndef __AUTO_ENVIRONMENT__
28#define __AUTO_ENVIRONMENT__
29
30namespace Auto {
31
32
33    class Environment {
34
35      public:
36#if defined(DEBUG)
37        static bool clear_all_new;                          // clear all new blocks
38        static bool dirty_all_new;                          // dirty all new blocks
39        static bool print_stats;                            // print statistics after collection
40        static bool print_scan_stats;                       // print scanning statistics
41        static bool print_allocs;                           // print vm and malloc allocations and deallocations
42        static bool unscanned_store_warning;                // warn when GC-managed pointers stored in unscanned memory.
43#else
44        enum {
45            clear_all_new = 0,                              // clear all new blocks
46            dirty_all_new = 0,                              // dirty all new blocks
47            print_stats = 0,                                // print statistics after collection
48            print_scan_stats = 0,                           // print scanning statistics
49            print_allocs = 0,                               // print vm and malloc allocations and deallocation
50            unscanned_store_warning = 0,                    // warn when GC-managed pointers stored in unscanned memory.
51        };
52#endif
53        static bool guard_pages;                            // create guard pages for blocks >= page_size
54        static bool dirty_all_deleted;                      // dirty all deleted blocks
55        static bool thread_collections;                     // enable thread local collections
56        static bool log_reference_counting;                 // log reference counting activity
57        static bool log_compactions;                        // log compaction activity
58        static bool scramble_heap;                          // move all possible objects when compacting.
59        static uint32_t exhaustive_collection_limit;        // max # of full collections in an exhaustive collection
60        static bool resurrection_is_fatal;                  // true if resurrection is a fatal error
61        static bool environ_has_auto_prefix;                // true if any strings in environ have the AUTO_ prefix.
62        static bool environ_has_malloc_prefix;              // true if any strings in environ have the Malloc prefix.
63        static double default_duty_cycle;                   // default collector duty cycle
64
65        //
66        // initialize
67        //
68        // Reads the environment variables values.
69        //
70        static void initialize();
71
72        //
73        // get
74        //
75        // Bottleneck for all calls to getenv().
76        //
77        static const char *get(const char *name);
78
79        //
80        // read_long
81        //
82        // Read a long (integer) value from the environment variable given by var.
83        // Return the value, or returns default_value if var is unset.
84        // msg is an optional descriptive message indicating the effect of a non-default value for var
85        //
86        static long read_long(const char *var, long default_value, const char *msg = NULL);
87
88        //
89        // read_bool
90        //
91        // Read a boolean value from the environment variable given by var.
92        // Returns default_value if var is not set in the environment.
93        // Returns true if var is set to an empty string
94        // Returns true if var is set to "yes" or "true" (case insensitive).
95        // Returns false if var is set to "no" or "false".
96        // msg is an optional descriptive message indicating the effect of a non-default value for var
97        //
98        static bool read_bool(const char *var, bool default_value = false, const char *msg = NULL);
99
100    };
101};
102
103#endif // __AUTO_ENVIRONMENT__
104