Thu, 24 May 2018 18:41:44 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_CI_BCESCAPEANALYZER_HPP |
aoqi@0 | 26 | #define SHARE_VM_CI_BCESCAPEANALYZER_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #ifdef COMPILER2 |
aoqi@0 | 29 | #include "ci/ciObject.hpp" |
aoqi@0 | 30 | #include "ci/ciMethod.hpp" |
aoqi@0 | 31 | #include "ci/ciMethodData.hpp" |
aoqi@0 | 32 | #include "code/dependencies.hpp" |
aoqi@0 | 33 | #include "libadt/vectset.hpp" |
aoqi@0 | 34 | #include "memory/allocation.hpp" |
aoqi@0 | 35 | #include "utilities/growableArray.hpp" |
aoqi@0 | 36 | #endif |
aoqi@0 | 37 | |
aoqi@0 | 38 | // This class implements a fast, conservative analysis of effect of methods |
aoqi@0 | 39 | // on the escape state of their arguments. The analysis is at the bytecode |
aoqi@0 | 40 | // level. |
aoqi@0 | 41 | |
aoqi@0 | 42 | class ciMethodBlocks; |
aoqi@0 | 43 | class ciBlock; |
aoqi@0 | 44 | |
aoqi@0 | 45 | class BCEscapeAnalyzer : public ResourceObj { |
aoqi@0 | 46 | private: |
aoqi@0 | 47 | Arena* _arena; // ciEnv arena |
aoqi@0 | 48 | |
aoqi@0 | 49 | bool _conservative; // If true, return maximally |
aoqi@0 | 50 | // conservative results. |
aoqi@0 | 51 | ciMethod* _method; |
aoqi@0 | 52 | ciMethodData* _methodData; |
aoqi@0 | 53 | int _arg_size; |
aoqi@0 | 54 | VectorSet _arg_local; |
aoqi@0 | 55 | VectorSet _arg_stack; |
aoqi@0 | 56 | VectorSet _arg_returned; |
aoqi@0 | 57 | VectorSet _dirty; |
aoqi@0 | 58 | enum{ ARG_OFFSET_MAX = 31}; |
aoqi@0 | 59 | uint *_arg_modified; |
aoqi@0 | 60 | |
aoqi@0 | 61 | bool _return_local; |
aoqi@0 | 62 | bool _return_allocated; |
aoqi@0 | 63 | bool _allocated_escapes; |
aoqi@0 | 64 | bool _unknown_modified; |
aoqi@0 | 65 | |
aoqi@0 | 66 | GrowableArray<ciMetadata *> _dependencies; |
aoqi@0 | 67 | |
aoqi@0 | 68 | ciMethodBlocks *_methodBlocks; |
aoqi@0 | 69 | |
aoqi@0 | 70 | BCEscapeAnalyzer* _parent; |
aoqi@0 | 71 | int _level; |
aoqi@0 | 72 | |
aoqi@0 | 73 | public: |
aoqi@0 | 74 | class ArgumentMap; |
aoqi@0 | 75 | class StateInfo; |
aoqi@0 | 76 | |
aoqi@0 | 77 | private: |
aoqi@0 | 78 | // helper functions |
aoqi@0 | 79 | bool is_argument(int i) { return i >= 0 && i < _arg_size; } |
aoqi@0 | 80 | void set_returned(ArgumentMap vars); |
aoqi@0 | 81 | bool is_argument(ArgumentMap vars); |
aoqi@0 | 82 | bool is_arg_stack(ArgumentMap vars); |
aoqi@0 | 83 | bool returns_all(ArgumentMap vars); |
aoqi@0 | 84 | void clear_bits(ArgumentMap vars, VectorSet &bs); |
aoqi@0 | 85 | void set_method_escape(ArgumentMap vars); |
aoqi@0 | 86 | void set_global_escape(ArgumentMap vars, bool merge = false); |
aoqi@0 | 87 | void set_dirty(ArgumentMap vars); |
aoqi@0 | 88 | void set_modified(ArgumentMap vars, int offs, int size); |
aoqi@0 | 89 | |
aoqi@0 | 90 | bool is_recursive_call(ciMethod* callee); |
aoqi@0 | 91 | void add_dependence(ciKlass *klass, ciMethod *meth); |
aoqi@0 | 92 | void propagate_dependencies(ciMethod *meth); |
aoqi@0 | 93 | void invoke(StateInfo &state, Bytecodes::Code code, ciMethod* target, ciKlass* holder); |
aoqi@0 | 94 | |
aoqi@0 | 95 | void iterate_one_block(ciBlock *blk, StateInfo &state, GrowableArray<ciBlock *> &successors); |
aoqi@0 | 96 | void iterate_blocks(Arena *); |
aoqi@0 | 97 | void merge_block_states(StateInfo *blockstates, ciBlock *dest, StateInfo *s_state); |
aoqi@0 | 98 | |
aoqi@0 | 99 | // analysis |
aoqi@0 | 100 | void initialize(); |
aoqi@0 | 101 | void clear_escape_info(); |
aoqi@0 | 102 | void compute_escape_info(); |
aoqi@0 | 103 | vmIntrinsics::ID known_intrinsic(); |
aoqi@0 | 104 | bool compute_escape_for_intrinsic(vmIntrinsics::ID iid); |
aoqi@0 | 105 | bool do_analysis(); |
aoqi@0 | 106 | |
aoqi@0 | 107 | void read_escape_info(); |
aoqi@0 | 108 | |
aoqi@0 | 109 | bool contains(uint arg_set1, uint arg_set2); |
aoqi@0 | 110 | |
aoqi@0 | 111 | public: |
aoqi@0 | 112 | BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent = NULL); |
aoqi@0 | 113 | |
aoqi@0 | 114 | // accessors |
aoqi@0 | 115 | ciMethod* method() const { return _method; } |
aoqi@0 | 116 | ciMethodData* methodData() const { return _methodData; } |
aoqi@0 | 117 | BCEscapeAnalyzer* parent() const { return _parent; } |
aoqi@0 | 118 | int level() const { return _level; } |
aoqi@0 | 119 | GrowableArray<ciMetadata *>* dependencies() { return &_dependencies; } |
aoqi@0 | 120 | bool has_dependencies() const { return !_dependencies.is_empty(); } |
aoqi@0 | 121 | |
aoqi@0 | 122 | // retrieval of interprocedural escape information |
aoqi@0 | 123 | |
aoqi@0 | 124 | // The given argument does not escape the callee. |
aoqi@0 | 125 | bool is_arg_local(int i) const { |
aoqi@0 | 126 | return !_conservative && _arg_local.test(i); |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | // The given argument escapes the callee, but does not become globally |
aoqi@0 | 130 | // reachable. |
aoqi@0 | 131 | bool is_arg_stack(int i) const { |
aoqi@0 | 132 | return !_conservative && _arg_stack.test(i); |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
aoqi@0 | 135 | // The given argument does not escape globally, and may be returned. |
aoqi@0 | 136 | bool is_arg_returned(int i) const { |
aoqi@0 | 137 | return !_conservative && _arg_returned.test(i); } |
aoqi@0 | 138 | |
aoqi@0 | 139 | // True iff only input arguments are returned. |
aoqi@0 | 140 | bool is_return_local() const { |
aoqi@0 | 141 | return !_conservative && _return_local; |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | // True iff only newly allocated unescaped objects are returned. |
aoqi@0 | 145 | bool is_return_allocated() const { |
aoqi@0 | 146 | return !_conservative && _return_allocated && !_allocated_escapes; |
aoqi@0 | 147 | } |
aoqi@0 | 148 | |
aoqi@0 | 149 | // Tracking of argument modification |
aoqi@0 | 150 | |
aoqi@0 | 151 | enum {OFFSET_ANY = -1}; |
aoqi@0 | 152 | bool is_arg_modified(int arg, int offset, int size_in_bytes); |
aoqi@0 | 153 | void set_arg_modified(int arg, int offset, int size_in_bytes); |
aoqi@0 | 154 | bool has_non_arg_side_affects() { return _unknown_modified; } |
aoqi@0 | 155 | |
aoqi@0 | 156 | // Copy dependencies from this analysis into "deps" |
aoqi@0 | 157 | void copy_dependencies(Dependencies *deps); |
aoqi@0 | 158 | |
aoqi@0 | 159 | #ifndef PRODUCT |
aoqi@0 | 160 | // dump escape information |
aoqi@0 | 161 | void dump(); |
aoqi@0 | 162 | #endif |
aoqi@0 | 163 | }; |
aoqi@0 | 164 | |
aoqi@0 | 165 | #endif // SHARE_VM_CI_BCESCAPEANALYZER_HPP |