aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_CI_BCESCAPEANALYZER_HPP aoqi@0: #define SHARE_VM_CI_BCESCAPEANALYZER_HPP aoqi@0: aoqi@0: #ifdef COMPILER2 aoqi@0: #include "ci/ciObject.hpp" aoqi@0: #include "ci/ciMethod.hpp" aoqi@0: #include "ci/ciMethodData.hpp" aoqi@0: #include "code/dependencies.hpp" aoqi@0: #include "libadt/vectset.hpp" aoqi@0: #include "memory/allocation.hpp" aoqi@0: #include "utilities/growableArray.hpp" aoqi@0: #endif aoqi@0: aoqi@0: // This class implements a fast, conservative analysis of effect of methods aoqi@0: // on the escape state of their arguments. The analysis is at the bytecode aoqi@0: // level. aoqi@0: aoqi@0: class ciMethodBlocks; aoqi@0: class ciBlock; aoqi@0: aoqi@0: class BCEscapeAnalyzer : public ResourceObj { aoqi@0: private: aoqi@0: Arena* _arena; // ciEnv arena aoqi@0: aoqi@0: bool _conservative; // If true, return maximally aoqi@0: // conservative results. aoqi@0: ciMethod* _method; aoqi@0: ciMethodData* _methodData; aoqi@0: int _arg_size; aoqi@0: VectorSet _arg_local; aoqi@0: VectorSet _arg_stack; aoqi@0: VectorSet _arg_returned; aoqi@0: VectorSet _dirty; aoqi@0: enum{ ARG_OFFSET_MAX = 31}; aoqi@0: uint *_arg_modified; aoqi@0: aoqi@0: bool _return_local; aoqi@0: bool _return_allocated; aoqi@0: bool _allocated_escapes; aoqi@0: bool _unknown_modified; aoqi@0: aoqi@0: GrowableArray _dependencies; aoqi@0: aoqi@0: ciMethodBlocks *_methodBlocks; aoqi@0: aoqi@0: BCEscapeAnalyzer* _parent; aoqi@0: int _level; aoqi@0: aoqi@0: public: aoqi@0: class ArgumentMap; aoqi@0: class StateInfo; aoqi@0: aoqi@0: private: aoqi@0: // helper functions aoqi@0: bool is_argument(int i) { return i >= 0 && i < _arg_size; } aoqi@0: void set_returned(ArgumentMap vars); aoqi@0: bool is_argument(ArgumentMap vars); aoqi@0: bool is_arg_stack(ArgumentMap vars); aoqi@0: bool returns_all(ArgumentMap vars); aoqi@0: void clear_bits(ArgumentMap vars, VectorSet &bs); aoqi@0: void set_method_escape(ArgumentMap vars); aoqi@0: void set_global_escape(ArgumentMap vars, bool merge = false); aoqi@0: void set_dirty(ArgumentMap vars); aoqi@0: void set_modified(ArgumentMap vars, int offs, int size); aoqi@0: aoqi@0: bool is_recursive_call(ciMethod* callee); aoqi@0: void add_dependence(ciKlass *klass, ciMethod *meth); aoqi@0: void propagate_dependencies(ciMethod *meth); aoqi@0: void invoke(StateInfo &state, Bytecodes::Code code, ciMethod* target, ciKlass* holder); aoqi@0: aoqi@0: void iterate_one_block(ciBlock *blk, StateInfo &state, GrowableArray &successors); aoqi@0: void iterate_blocks(Arena *); aoqi@0: void merge_block_states(StateInfo *blockstates, ciBlock *dest, StateInfo *s_state); aoqi@0: aoqi@0: // analysis aoqi@0: void initialize(); aoqi@0: void clear_escape_info(); aoqi@0: void compute_escape_info(); aoqi@0: vmIntrinsics::ID known_intrinsic(); aoqi@0: bool compute_escape_for_intrinsic(vmIntrinsics::ID iid); aoqi@0: bool do_analysis(); aoqi@0: aoqi@0: void read_escape_info(); aoqi@0: aoqi@0: bool contains(uint arg_set1, uint arg_set2); aoqi@0: aoqi@0: public: aoqi@0: BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent = NULL); aoqi@0: aoqi@0: // accessors aoqi@0: ciMethod* method() const { return _method; } aoqi@0: ciMethodData* methodData() const { return _methodData; } aoqi@0: BCEscapeAnalyzer* parent() const { return _parent; } aoqi@0: int level() const { return _level; } aoqi@0: GrowableArray* dependencies() { return &_dependencies; } aoqi@0: bool has_dependencies() const { return !_dependencies.is_empty(); } aoqi@0: aoqi@0: // retrieval of interprocedural escape information aoqi@0: aoqi@0: // The given argument does not escape the callee. aoqi@0: bool is_arg_local(int i) const { aoqi@0: return !_conservative && _arg_local.test(i); aoqi@0: } aoqi@0: aoqi@0: // The given argument escapes the callee, but does not become globally aoqi@0: // reachable. aoqi@0: bool is_arg_stack(int i) const { aoqi@0: return !_conservative && _arg_stack.test(i); aoqi@0: } aoqi@0: aoqi@0: // The given argument does not escape globally, and may be returned. aoqi@0: bool is_arg_returned(int i) const { aoqi@0: return !_conservative && _arg_returned.test(i); } aoqi@0: aoqi@0: // True iff only input arguments are returned. aoqi@0: bool is_return_local() const { aoqi@0: return !_conservative && _return_local; aoqi@0: } aoqi@0: aoqi@0: // True iff only newly allocated unescaped objects are returned. aoqi@0: bool is_return_allocated() const { aoqi@0: return !_conservative && _return_allocated && !_allocated_escapes; aoqi@0: } aoqi@0: aoqi@0: // Tracking of argument modification aoqi@0: aoqi@0: enum {OFFSET_ANY = -1}; aoqi@0: bool is_arg_modified(int arg, int offset, int size_in_bytes); aoqi@0: void set_arg_modified(int arg, int offset, int size_in_bytes); aoqi@0: bool has_non_arg_side_affects() { return _unknown_modified; } aoqi@0: aoqi@0: // Copy dependencies from this analysis into "deps" aoqi@0: void copy_dependencies(Dependencies *deps); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: // dump escape information aoqi@0: void dump(); aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_CI_BCESCAPEANALYZER_HPP