1 /*
2  * Copyright (C) 2016 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_COMPILER_OPTIMIZING_ESCAPE_H_
18 #define ART_COMPILER_OPTIMIZING_ESCAPE_H_
19 
20 namespace art {
21 
22 class HInstruction;
23 
24 /*
25  * Methods related to escape analysis, i.e. determining whether an object
26  * allocation is visible outside ('escapes') its immediate method context.
27  */
28 
29 /*
30  * Performs escape analysis on the given instruction, typically a reference to an
31  * allocation. The method assigns true to parameter 'is_singleton' if the reference
32  * is the only name that can refer to its value during the lifetime of the method,
33  * meaning that the reference is not aliased with something else, is not stored to
34  * heap memory, and not passed to another method. In addition, the method assigns
35  * true to parameter 'is_singleton_and_not_returned' if the reference is a singleton
36  * and not returned to the caller and to parameter 'is_singleton_and_not_deopt_visible'
37  * if the reference is a singleton and not used as an environment local of an
38  * HDeoptimize instruction (clients of the final value must run after BCE to ensure
39  * all such instructions have been introduced already).
40  *
41  * Note that being visible to a HDeoptimize instruction does not count for ordinary
42  * escape analysis, since switching between compiled code and interpreted code keeps
43  * non escaping references restricted to the lifetime of the method and the thread
44  * executing it. This property only concerns optimizations that are interested in
45  * escape analysis with respect to the *compiled* code (such as LSE).
46  *
47  * When set, the no_escape function is applied to any use of the allocation instruction
48  * prior to any built-in escape analysis. This allows clients to define better escape
49  * analysis in certain case-specific circumstances. If 'no_escape(reference, user)'
50  * returns true, the user is assumed *not* to cause any escape right away. The return
51  * value false means the client cannot provide a definite answer and built-in escape
52  * analysis is applied to the user instead.
53  */
54 void CalculateEscape(HInstruction* reference,
55                      bool (*no_escape)(HInstruction*, HInstruction*),
56                      /*out*/ bool* is_singleton,
57                      /*out*/ bool* is_singleton_and_not_returned,
58                      /*out*/ bool* is_singleton_and_not_deopt_visible);
59 
60 /*
61  * Convenience method for testing the singleton and not returned properties at once.
62  * Callers should be aware that this method invokes the full analysis at each call.
63  */
64 bool DoesNotEscape(HInstruction* reference, bool (*no_escape)(HInstruction*, HInstruction*));
65 
66 }  // namespace art
67 
68 #endif  // ART_COMPILER_OPTIMIZING_ESCAPE_H_
69