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