]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | package org.apache.arrow.memory; | |
19 | ||
20 | /** | |
21 | * Configuration class to determine if bounds checking should be turned on or off. | |
22 | * | |
23 | * <p> | |
24 | * Bounds checking is on by default. You can disable it by setting either the system property or | |
25 | * the environmental variable to "true". The system property can be "arrow.enable_unsafe_memory_access" | |
26 | * or "drill.enable_unsafe_memory_access". The latter is deprecated. The environmental variable is named | |
27 | * "ARROW_ENABLE_UNSAFE_MEMORY_ACCESS". | |
28 | * When both the system property and the environmental variable are set, the system property takes precedence. | |
29 | * </p> | |
30 | */ | |
31 | public class BoundsChecking { | |
32 | ||
33 | public static final boolean BOUNDS_CHECKING_ENABLED; | |
34 | static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BoundsChecking.class); | |
35 | ||
36 | static { | |
37 | String envProperty = System.getenv("ARROW_ENABLE_UNSAFE_MEMORY_ACCESS"); | |
38 | String oldProperty = System.getProperty("drill.enable_unsafe_memory_access"); | |
39 | if (oldProperty != null) { | |
40 | logger.warn("\"drill.enable_unsafe_memory_access\" has been renamed to \"arrow.enable_unsafe_memory_access\""); | |
41 | logger.warn("\"arrow.enable_unsafe_memory_access\" can be set to: " + | |
42 | " true (to not check) or false (to check, default)"); | |
43 | } | |
44 | String newProperty = System.getProperty("arrow.enable_unsafe_memory_access"); | |
45 | ||
46 | // The priority of determining the unsafe flag: | |
47 | // 1. The system properties take precedence over the environmental variable. | |
48 | // 2. The new system property takes precedence over the new system property. | |
49 | String unsafeFlagValue = newProperty; | |
50 | if (unsafeFlagValue == null) { | |
51 | unsafeFlagValue = oldProperty; | |
52 | } | |
53 | if (unsafeFlagValue == null) { | |
54 | unsafeFlagValue = envProperty; | |
55 | } | |
56 | ||
57 | BOUNDS_CHECKING_ENABLED = !"true".equals(unsafeFlagValue); | |
58 | } | |
59 | ||
60 | private BoundsChecking() { | |
61 | } | |
62 | ||
63 | } |