bcEscapeAnalyzer.cpp revision 1568
0N/A/*
1472N/A * Copyright (c) 2005, 2009, 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/A
0N/A#include "incls/_precompiled.incl"
0N/A#include "incls/_bcEscapeAnalyzer.cpp.incl"
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/A #define TRACE_BCEA(level, code) \
0N/A if (EstimateArgEscape && BCEATraceLevel >= level) { \
0N/A code; \
0N/A }
0N/A#else
0N/A #define TRACE_BCEA(level, code)
0N/A#endif
0N/A
0N/A// Maintain a map of which aguments a local variable or
0N/A// stack slot may contain. In addition to tracking
0N/A// arguments, it tracks two special values, "allocated"
0N/A// which represents any object allocated in the current
0N/A// method, and "unknown" which is any other object.
0N/A// Up to 30 arguments are handled, with the last one
0N/A// representing summary information for any extra arguments
0N/Aclass BCEscapeAnalyzer::ArgumentMap {
0N/A uint _bits;
0N/A enum {MAXBIT = 29,
0N/A ALLOCATED = 1,
0N/A UNKNOWN = 2};
0N/A
0N/A uint int_to_bit(uint e) const {
0N/A if (e > MAXBIT)
0N/A e = MAXBIT;
0N/A return (1 << (e + 2));
0N/A }
0N/A
0N/Apublic:
0N/A ArgumentMap() { _bits = 0;}
0N/A void set_bits(uint bits) { _bits = bits;}
0N/A uint get_bits() const { return _bits;}
0N/A void clear() { _bits = 0;}
0N/A void set_all() { _bits = ~0u; }
0N/A bool is_empty() const { return _bits == 0; }
0N/A bool contains(uint var) const { return (_bits & int_to_bit(var)) != 0; }
0N/A bool is_singleton(uint var) const { return (_bits == int_to_bit(var)); }
0N/A bool contains_unknown() const { return (_bits & UNKNOWN) != 0; }
0N/A bool contains_allocated() const { return (_bits & ALLOCATED) != 0; }
0N/A bool contains_vars() const { return (_bits & (((1 << MAXBIT) -1) << 2)) != 0; }
0N/A void set(uint var) { _bits = int_to_bit(var); }
0N/A void add(uint var) { _bits |= int_to_bit(var); }
0N/A void add_unknown() { _bits = UNKNOWN; }
0N/A void add_allocated() { _bits = ALLOCATED; }
0N/A void set_union(const ArgumentMap &am) { _bits |= am._bits; }
0N/A void set_intersect(const ArgumentMap &am) { _bits |= am._bits; }
0N/A void set_difference(const ArgumentMap &am) { _bits &= ~am._bits; }
0N/A void operator=(const ArgumentMap &am) { _bits = am._bits; }
0N/A bool operator==(const ArgumentMap &am) { return _bits == am._bits; }
0N/A bool operator!=(const ArgumentMap &am) { return _bits != am._bits; }
0N/A};
0N/A
0N/Aclass BCEscapeAnalyzer::StateInfo {
0N/Apublic:
0N/A ArgumentMap *_vars;
0N/A ArgumentMap *_stack;
0N/A short _stack_height;
0N/A short _max_stack;
0N/A bool _initialized;
0N/A ArgumentMap empty_map;
0N/A
0N/A StateInfo() {
0N/A empty_map.clear();
0N/A }
0N/A
0N/A ArgumentMap raw_pop() { assert(_stack_height > 0, "stack underflow"); return _stack[--_stack_height]; }
0N/A ArgumentMap apop() { return raw_pop(); }
0N/A void spop() { raw_pop(); }
0N/A void lpop() { spop(); spop(); }
0N/A void raw_push(ArgumentMap i) { assert(_stack_height < _max_stack, "stack overflow"); _stack[_stack_height++] = i; }
0N/A void apush(ArgumentMap i) { raw_push(i); }
0N/A void spush() { raw_push(empty_map); }
0N/A void lpush() { spush(); spush(); }
0N/A
0N/A};
0N/A
0N/Avoid BCEscapeAnalyzer::set_returned(ArgumentMap vars) {
45N/A for (int i = 0; i < _arg_size; i++) {
0N/A if (vars.contains(i))
1568N/A _arg_returned.set(i);
0N/A }
0N/A _return_local = _return_local && !(vars.contains_unknown() || vars.contains_allocated());
0N/A _return_allocated = _return_allocated && vars.contains_allocated() && !(vars.contains_unknown() || vars.contains_vars());
0N/A}
0N/A
0N/A// return true if any element of vars is an argument
0N/Abool BCEscapeAnalyzer::is_argument(ArgumentMap vars) {
45N/A for (int i = 0; i < _arg_size; i++) {
0N/A if (vars.contains(i))
0N/A return true;
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A// return true if any element of vars is an arg_stack argument
0N/Abool BCEscapeAnalyzer::is_arg_stack(ArgumentMap vars){
0N/A if (_conservative)
0N/A return true;
45N/A for (int i = 0; i < _arg_size; i++) {
1568N/A if (vars.contains(i) && _arg_stack.test(i))
0N/A return true;
0N/A }
0N/A return false;
0N/A}
0N/A
1568N/Avoid BCEscapeAnalyzer::clear_bits(ArgumentMap vars, VectorSet &bm) {
45N/A for (int i = 0; i < _arg_size; i++) {
0N/A if (vars.contains(i)) {
1568N/A bm >>= i;
0N/A }
0N/A }
0N/A}
45N/A
0N/Avoid BCEscapeAnalyzer::set_method_escape(ArgumentMap vars) {
0N/A clear_bits(vars, _arg_local);
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::set_global_escape(ArgumentMap vars) {
0N/A clear_bits(vars, _arg_local);
0N/A clear_bits(vars, _arg_stack);
0N/A if (vars.contains_allocated())
0N/A _allocated_escapes = true;
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::set_dirty(ArgumentMap vars) {
0N/A clear_bits(vars, _dirty);
0N/A}
0N/A
45N/Avoid BCEscapeAnalyzer::set_modified(ArgumentMap vars, int offs, int size) {
45N/A
45N/A for (int i = 0; i < _arg_size; i++) {
45N/A if (vars.contains(i)) {
45N/A set_arg_modified(i, offs, size);
45N/A }
45N/A }
45N/A if (vars.contains_unknown())
45N/A _unknown_modified = true;
45N/A}
45N/A
0N/Abool BCEscapeAnalyzer::is_recursive_call(ciMethod* callee) {
0N/A for (BCEscapeAnalyzer* scope = this; scope != NULL; scope = scope->_parent) {
0N/A if (scope->method() == callee) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A}
0N/A
45N/Abool BCEscapeAnalyzer::is_arg_modified(int arg, int offset, int size_in_bytes) {
45N/A if (offset == OFFSET_ANY)
45N/A return _arg_modified[arg] != 0;
45N/A assert(arg >= 0 && arg < _arg_size, "must be an argument.");
45N/A bool modified = false;
45N/A int l = offset / HeapWordSize;
45N/A int h = round_to(offset + size_in_bytes, HeapWordSize) / HeapWordSize;
45N/A if (l > ARG_OFFSET_MAX)
45N/A l = ARG_OFFSET_MAX;
45N/A if (h > ARG_OFFSET_MAX+1)
45N/A h = ARG_OFFSET_MAX + 1;
45N/A for (int i = l; i < h; i++) {
45N/A modified = modified || (_arg_modified[arg] & (1 << i)) != 0;
45N/A }
45N/A return modified;
45N/A}
45N/A
45N/Avoid BCEscapeAnalyzer::set_arg_modified(int arg, int offset, int size_in_bytes) {
45N/A if (offset == OFFSET_ANY) {
45N/A _arg_modified[arg] = (uint) -1;
45N/A return;
45N/A }
45N/A assert(arg >= 0 && arg < _arg_size, "must be an argument.");
45N/A int l = offset / HeapWordSize;
45N/A int h = round_to(offset + size_in_bytes, HeapWordSize) / HeapWordSize;
45N/A if (l > ARG_OFFSET_MAX)
45N/A l = ARG_OFFSET_MAX;
45N/A if (h > ARG_OFFSET_MAX+1)
45N/A h = ARG_OFFSET_MAX + 1;
45N/A for (int i = l; i < h; i++) {
45N/A _arg_modified[arg] |= (1 << i);
45N/A }
45N/A}
45N/A
0N/Avoid BCEscapeAnalyzer::invoke(StateInfo &state, Bytecodes::Code code, ciMethod* target, ciKlass* holder) {
0N/A int i;
0N/A
0N/A // retrieve information about the callee
0N/A ciInstanceKlass* klass = target->holder();
0N/A ciInstanceKlass* calling_klass = method()->holder();
0N/A ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
0N/A ciInstanceKlass* actual_recv = callee_holder;
0N/A
154N/A // some methods are obviously bindable without any type checks so
154N/A // convert them directly to an invokespecial.
154N/A if (target->is_loaded() && !target->is_abstract() &&
154N/A target->can_be_statically_bound() && code == Bytecodes::_invokevirtual) {
154N/A code = Bytecodes::_invokespecial;
154N/A }
154N/A
0N/A // compute size of arguments
0N/A int arg_size = target->arg_size();
0N/A if (!target->is_loaded() && code == Bytecodes::_invokestatic) {
0N/A arg_size--;
0N/A }
0N/A int arg_base = MAX2(state._stack_height - arg_size, 0);
0N/A
0N/A // direct recursive calls are skipped if they can be bound statically without introducing
0N/A // dependencies and if parameters are passed at the same position as in the current method
0N/A // other calls are skipped if there are no unescaped arguments passed to them
0N/A bool directly_recursive = (method() == target) &&
0N/A (code != Bytecodes::_invokevirtual || target->is_final_method() || state._stack[arg_base] .is_empty());
0N/A
0N/A // check if analysis of callee can safely be skipped
0N/A bool skip_callee = true;
0N/A for (i = state._stack_height - 1; i >= arg_base && skip_callee; i--) {
0N/A ArgumentMap arg = state._stack[i];
0N/A skip_callee = !is_argument(arg) || !is_arg_stack(arg) || (directly_recursive && arg.is_singleton(i - arg_base));
0N/A }
0N/A if (skip_callee) {
0N/A TRACE_BCEA(3, tty->print_cr("[EA] skipping method %s::%s", holder->name()->as_utf8(), target->name()->as_utf8()));
0N/A for (i = 0; i < arg_size; i++) {
0N/A set_method_escape(state.raw_pop());
0N/A }
45N/A _unknown_modified = true; // assume the worst since we don't analyze the called method
0N/A return;
0N/A }
0N/A
0N/A // determine actual method (use CHA if necessary)
0N/A ciMethod* inline_target = NULL;
0N/A if (target->is_loaded() && klass->is_loaded()
0N/A && (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
0N/A && target->will_link(klass, callee_holder, code)) {
0N/A if (code == Bytecodes::_invokestatic
0N/A || code == Bytecodes::_invokespecial
0N/A || code == Bytecodes::_invokevirtual && target->is_final_method()) {
0N/A inline_target = target;
0N/A } else {
0N/A inline_target = target->find_monomorphic_target(calling_klass, callee_holder, actual_recv);
0N/A }
0N/A }
0N/A
0N/A if (inline_target != NULL && !is_recursive_call(inline_target)) {
0N/A // analyze callee
0N/A BCEscapeAnalyzer analyzer(inline_target, this);
0N/A
0N/A // adjust escape state of actual parameters
0N/A bool must_record_dependencies = false;
0N/A for (i = arg_size - 1; i >= 0; i--) {
0N/A ArgumentMap arg = state.raw_pop();
0N/A if (!is_argument(arg))
0N/A continue;
45N/A for (int j = 0; j < _arg_size; j++) {
45N/A if (arg.contains(j)) {
45N/A _arg_modified[j] |= analyzer._arg_modified[i];
45N/A }
45N/A }
0N/A if (!is_arg_stack(arg)) {
0N/A // arguments have already been recognized as escaping
0N/A } else if (analyzer.is_arg_stack(i) && !analyzer.is_arg_returned(i)) {
0N/A set_method_escape(arg);
0N/A must_record_dependencies = true;
0N/A } else {
0N/A set_global_escape(arg);
0N/A }
0N/A }
45N/A _unknown_modified = _unknown_modified || analyzer.has_non_arg_side_affects();
0N/A
0N/A // record dependencies if at least one parameter retained stack-allocatable
0N/A if (must_record_dependencies) {
0N/A if (code == Bytecodes::_invokeinterface || code == Bytecodes::_invokevirtual && !target->is_final_method()) {
0N/A _dependencies.append(actual_recv);
0N/A _dependencies.append(inline_target);
0N/A }
0N/A _dependencies.appendAll(analyzer.dependencies());
0N/A }
0N/A } else {
0N/A TRACE_BCEA(1, tty->print_cr("[EA] virtual method %s is not monomorphic.",
0N/A target->name()->as_utf8()));
0N/A // conservatively mark all actual parameters as escaping globally
0N/A for (i = 0; i < arg_size; i++) {
0N/A ArgumentMap arg = state.raw_pop();
0N/A if (!is_argument(arg))
0N/A continue;
45N/A set_modified(arg, OFFSET_ANY, type2size[T_INT]*HeapWordSize);
0N/A set_global_escape(arg);
0N/A }
45N/A _unknown_modified = true; // assume the worst since we don't know the called method
0N/A }
0N/A}
0N/A
0N/Abool BCEscapeAnalyzer::contains(uint arg_set1, uint arg_set2) {
0N/A return ((~arg_set1) | arg_set2) == 0;
0N/A}
0N/A
0N/A
0N/Avoid BCEscapeAnalyzer::iterate_one_block(ciBlock *blk, StateInfo &state, GrowableArray<ciBlock *> &successors) {
0N/A
0N/A blk->set_processed();
0N/A ciBytecodeStream s(method());
0N/A int limit_bci = blk->limit_bci();
0N/A bool fall_through = false;
0N/A ArgumentMap allocated_obj;
0N/A allocated_obj.add_allocated();
0N/A ArgumentMap unknown_obj;
0N/A unknown_obj.add_unknown();
0N/A ArgumentMap empty_map;
0N/A
0N/A s.reset_to_bci(blk->start_bci());
0N/A while (s.next() != ciBytecodeStream::EOBC() && s.cur_bci() < limit_bci) {
0N/A fall_through = true;
0N/A switch (s.cur_bc()) {
0N/A case Bytecodes::_nop:
0N/A break;
0N/A case Bytecodes::_aconst_null:
0N/A state.apush(empty_map);
0N/A break;
0N/A case Bytecodes::_iconst_m1:
0N/A case Bytecodes::_iconst_0:
0N/A case Bytecodes::_iconst_1:
0N/A case Bytecodes::_iconst_2:
0N/A case Bytecodes::_iconst_3:
0N/A case Bytecodes::_iconst_4:
0N/A case Bytecodes::_iconst_5:
0N/A case Bytecodes::_fconst_0:
0N/A case Bytecodes::_fconst_1:
0N/A case Bytecodes::_fconst_2:
0N/A case Bytecodes::_bipush:
0N/A case Bytecodes::_sipush:
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_lconst_0:
0N/A case Bytecodes::_lconst_1:
0N/A case Bytecodes::_dconst_0:
0N/A case Bytecodes::_dconst_1:
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_ldc:
0N/A case Bytecodes::_ldc_w:
0N/A case Bytecodes::_ldc2_w:
0N/A if (type2size[s.get_constant().basic_type()] == 1) {
0N/A state.spush();
0N/A } else {
0N/A state.lpush();
0N/A }
0N/A break;
0N/A case Bytecodes::_aload:
0N/A state.apush(state._vars[s.get_index()]);
0N/A break;
0N/A case Bytecodes::_iload:
0N/A case Bytecodes::_fload:
0N/A case Bytecodes::_iload_0:
0N/A case Bytecodes::_iload_1:
0N/A case Bytecodes::_iload_2:
0N/A case Bytecodes::_iload_3:
0N/A case Bytecodes::_fload_0:
0N/A case Bytecodes::_fload_1:
0N/A case Bytecodes::_fload_2:
0N/A case Bytecodes::_fload_3:
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_lload:
0N/A case Bytecodes::_dload:
0N/A case Bytecodes::_lload_0:
0N/A case Bytecodes::_lload_1:
0N/A case Bytecodes::_lload_2:
0N/A case Bytecodes::_lload_3:
0N/A case Bytecodes::_dload_0:
0N/A case Bytecodes::_dload_1:
0N/A case Bytecodes::_dload_2:
0N/A case Bytecodes::_dload_3:
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_aload_0:
0N/A state.apush(state._vars[0]);
0N/A break;
0N/A case Bytecodes::_aload_1:
0N/A state.apush(state._vars[1]);
0N/A break;
0N/A case Bytecodes::_aload_2:
0N/A state.apush(state._vars[2]);
0N/A break;
0N/A case Bytecodes::_aload_3:
0N/A state.apush(state._vars[3]);
0N/A break;
0N/A case Bytecodes::_iaload:
0N/A case Bytecodes::_faload:
0N/A case Bytecodes::_baload:
0N/A case Bytecodes::_caload:
0N/A case Bytecodes::_saload:
0N/A state.spop();
0N/A set_method_escape(state.apop());
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_laload:
0N/A case Bytecodes::_daload:
0N/A state.spop();
0N/A set_method_escape(state.apop());
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_aaload:
0N/A { state.spop();
0N/A ArgumentMap array = state.apop();
0N/A set_method_escape(array);
0N/A state.apush(unknown_obj);
0N/A set_dirty(array);
0N/A }
0N/A break;
0N/A case Bytecodes::_istore:
0N/A case Bytecodes::_fstore:
0N/A case Bytecodes::_istore_0:
0N/A case Bytecodes::_istore_1:
0N/A case Bytecodes::_istore_2:
0N/A case Bytecodes::_istore_3:
0N/A case Bytecodes::_fstore_0:
0N/A case Bytecodes::_fstore_1:
0N/A case Bytecodes::_fstore_2:
0N/A case Bytecodes::_fstore_3:
0N/A state.spop();
0N/A break;
0N/A case Bytecodes::_lstore:
0N/A case Bytecodes::_dstore:
0N/A case Bytecodes::_lstore_0:
0N/A case Bytecodes::_lstore_1:
0N/A case Bytecodes::_lstore_2:
0N/A case Bytecodes::_lstore_3:
0N/A case Bytecodes::_dstore_0:
0N/A case Bytecodes::_dstore_1:
0N/A case Bytecodes::_dstore_2:
0N/A case Bytecodes::_dstore_3:
0N/A state.lpop();
0N/A break;
0N/A case Bytecodes::_astore:
0N/A state._vars[s.get_index()] = state.apop();
0N/A break;
0N/A case Bytecodes::_astore_0:
0N/A state._vars[0] = state.apop();
0N/A break;
0N/A case Bytecodes::_astore_1:
0N/A state._vars[1] = state.apop();
0N/A break;
0N/A case Bytecodes::_astore_2:
0N/A state._vars[2] = state.apop();
0N/A break;
0N/A case Bytecodes::_astore_3:
0N/A state._vars[3] = state.apop();
0N/A break;
0N/A case Bytecodes::_iastore:
0N/A case Bytecodes::_fastore:
0N/A case Bytecodes::_bastore:
0N/A case Bytecodes::_castore:
0N/A case Bytecodes::_sastore:
0N/A {
0N/A state.spop();
0N/A state.spop();
0N/A ArgumentMap arr = state.apop();
0N/A set_method_escape(arr);
45N/A set_modified(arr, OFFSET_ANY, type2size[T_INT]*HeapWordSize);
0N/A break;
0N/A }
0N/A case Bytecodes::_lastore:
0N/A case Bytecodes::_dastore:
0N/A {
0N/A state.lpop();
0N/A state.spop();
0N/A ArgumentMap arr = state.apop();
0N/A set_method_escape(arr);
45N/A set_modified(arr, OFFSET_ANY, type2size[T_LONG]*HeapWordSize);
0N/A break;
0N/A }
0N/A case Bytecodes::_aastore:
0N/A {
0N/A set_global_escape(state.apop());
0N/A state.spop();
0N/A ArgumentMap arr = state.apop();
45N/A set_modified(arr, OFFSET_ANY, type2size[T_OBJECT]*HeapWordSize);
0N/A break;
0N/A }
0N/A case Bytecodes::_pop:
0N/A state.raw_pop();
0N/A break;
0N/A case Bytecodes::_pop2:
0N/A state.raw_pop();
0N/A state.raw_pop();
0N/A break;
0N/A case Bytecodes::_dup:
0N/A { ArgumentMap w1 = state.raw_pop();
0N/A state.raw_push(w1);
0N/A state.raw_push(w1);
0N/A }
0N/A break;
0N/A case Bytecodes::_dup_x1:
0N/A { ArgumentMap w1 = state.raw_pop();
0N/A ArgumentMap w2 = state.raw_pop();
0N/A state.raw_push(w1);
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A }
0N/A break;
0N/A case Bytecodes::_dup_x2:
0N/A { ArgumentMap w1 = state.raw_pop();
0N/A ArgumentMap w2 = state.raw_pop();
0N/A ArgumentMap w3 = state.raw_pop();
0N/A state.raw_push(w1);
0N/A state.raw_push(w3);
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A }
0N/A break;
0N/A case Bytecodes::_dup2:
0N/A { ArgumentMap w1 = state.raw_pop();
0N/A ArgumentMap w2 = state.raw_pop();
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A }
0N/A break;
0N/A case Bytecodes::_dup2_x1:
0N/A { ArgumentMap w1 = state.raw_pop();
0N/A ArgumentMap w2 = state.raw_pop();
0N/A ArgumentMap w3 = state.raw_pop();
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A state.raw_push(w3);
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A }
0N/A break;
0N/A case Bytecodes::_dup2_x2:
0N/A { ArgumentMap w1 = state.raw_pop();
0N/A ArgumentMap w2 = state.raw_pop();
0N/A ArgumentMap w3 = state.raw_pop();
0N/A ArgumentMap w4 = state.raw_pop();
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A state.raw_push(w4);
0N/A state.raw_push(w3);
0N/A state.raw_push(w2);
0N/A state.raw_push(w1);
0N/A }
0N/A break;
0N/A case Bytecodes::_swap:
0N/A { ArgumentMap w1 = state.raw_pop();
0N/A ArgumentMap w2 = state.raw_pop();
0N/A state.raw_push(w1);
0N/A state.raw_push(w2);
0N/A }
0N/A break;
0N/A case Bytecodes::_iadd:
0N/A case Bytecodes::_fadd:
0N/A case Bytecodes::_isub:
0N/A case Bytecodes::_fsub:
0N/A case Bytecodes::_imul:
0N/A case Bytecodes::_fmul:
0N/A case Bytecodes::_idiv:
0N/A case Bytecodes::_fdiv:
0N/A case Bytecodes::_irem:
0N/A case Bytecodes::_frem:
0N/A case Bytecodes::_iand:
0N/A case Bytecodes::_ior:
0N/A case Bytecodes::_ixor:
0N/A state.spop();
0N/A state.spop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_ladd:
0N/A case Bytecodes::_dadd:
0N/A case Bytecodes::_lsub:
0N/A case Bytecodes::_dsub:
0N/A case Bytecodes::_lmul:
0N/A case Bytecodes::_dmul:
0N/A case Bytecodes::_ldiv:
0N/A case Bytecodes::_ddiv:
0N/A case Bytecodes::_lrem:
0N/A case Bytecodes::_drem:
0N/A case Bytecodes::_land:
0N/A case Bytecodes::_lor:
0N/A case Bytecodes::_lxor:
0N/A state.lpop();
0N/A state.lpop();
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_ishl:
0N/A case Bytecodes::_ishr:
0N/A case Bytecodes::_iushr:
0N/A state.spop();
0N/A state.spop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_lshl:
0N/A case Bytecodes::_lshr:
0N/A case Bytecodes::_lushr:
0N/A state.spop();
0N/A state.lpop();
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_ineg:
0N/A case Bytecodes::_fneg:
0N/A state.spop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_lneg:
0N/A case Bytecodes::_dneg:
0N/A state.lpop();
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_iinc:
0N/A break;
0N/A case Bytecodes::_i2l:
0N/A case Bytecodes::_i2d:
0N/A case Bytecodes::_f2l:
0N/A case Bytecodes::_f2d:
0N/A state.spop();
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_i2f:
0N/A case Bytecodes::_f2i:
0N/A state.spop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_l2i:
0N/A case Bytecodes::_l2f:
0N/A case Bytecodes::_d2i:
0N/A case Bytecodes::_d2f:
0N/A state.lpop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_l2d:
0N/A case Bytecodes::_d2l:
0N/A state.lpop();
0N/A state.lpush();
0N/A break;
0N/A case Bytecodes::_i2b:
0N/A case Bytecodes::_i2c:
0N/A case Bytecodes::_i2s:
0N/A state.spop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_lcmp:
0N/A case Bytecodes::_dcmpl:
0N/A case Bytecodes::_dcmpg:
0N/A state.lpop();
0N/A state.lpop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_fcmpl:
0N/A case Bytecodes::_fcmpg:
0N/A state.spop();
0N/A state.spop();
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_ifeq:
0N/A case Bytecodes::_ifne:
0N/A case Bytecodes::_iflt:
0N/A case Bytecodes::_ifge:
0N/A case Bytecodes::_ifgt:
0N/A case Bytecodes::_ifle:
0N/A {
0N/A state.spop();
0N/A int dest_bci = s.get_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A break;
0N/A }
0N/A case Bytecodes::_if_icmpeq:
0N/A case Bytecodes::_if_icmpne:
0N/A case Bytecodes::_if_icmplt:
0N/A case Bytecodes::_if_icmpge:
0N/A case Bytecodes::_if_icmpgt:
0N/A case Bytecodes::_if_icmple:
0N/A {
0N/A state.spop();
0N/A state.spop();
0N/A int dest_bci = s.get_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A break;
0N/A }
0N/A case Bytecodes::_if_acmpeq:
0N/A case Bytecodes::_if_acmpne:
0N/A {
0N/A set_method_escape(state.apop());
0N/A set_method_escape(state.apop());
0N/A int dest_bci = s.get_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A break;
0N/A }
0N/A case Bytecodes::_goto:
0N/A {
0N/A int dest_bci = s.get_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A fall_through = false;
0N/A break;
0N/A }
0N/A case Bytecodes::_jsr:
0N/A {
0N/A int dest_bci = s.get_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A state.apush(empty_map);
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A fall_through = false;
0N/A break;
0N/A }
0N/A case Bytecodes::_ret:
0N/A // we don't track the destination of a "ret" instruction
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A fall_through = false;
0N/A break;
0N/A case Bytecodes::_return:
0N/A assert(s.next_bci() == limit_bci, "return must end block");
0N/A fall_through = false;
0N/A break;
0N/A case Bytecodes::_tableswitch:
0N/A {
0N/A state.spop();
0N/A Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(s.cur_bcp());
0N/A int len = switch_->length();
0N/A int dest_bci;
0N/A for (int i = 0; i < len; i++) {
0N/A dest_bci = s.cur_bci() + switch_->dest_offset_at(i);
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A }
0N/A dest_bci = s.cur_bci() + switch_->default_offset();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A fall_through = false;
0N/A break;
0N/A }
0N/A case Bytecodes::_lookupswitch:
0N/A {
0N/A state.spop();
0N/A Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(s.cur_bcp());
0N/A int len = switch_->number_of_pairs();
0N/A int dest_bci;
0N/A for (int i = 0; i < len; i++) {
0N/A dest_bci = s.cur_bci() + switch_->pair_at(i)->offset();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A }
0N/A dest_bci = s.cur_bci() + switch_->default_offset();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A fall_through = false;
0N/A break;
0N/A }
0N/A case Bytecodes::_ireturn:
0N/A case Bytecodes::_freturn:
0N/A state.spop();
0N/A fall_through = false;
0N/A break;
0N/A case Bytecodes::_lreturn:
0N/A case Bytecodes::_dreturn:
0N/A state.lpop();
0N/A fall_through = false;
0N/A break;
0N/A case Bytecodes::_areturn:
0N/A set_returned(state.apop());
0N/A fall_through = false;
0N/A break;
0N/A case Bytecodes::_getstatic:
0N/A case Bytecodes::_getfield:
0N/A { bool will_link;
0N/A ciField* field = s.get_field(will_link);
0N/A BasicType field_type = field->type()->basic_type();
0N/A if (s.cur_bc() != Bytecodes::_getstatic) {
0N/A set_method_escape(state.apop());
0N/A }
0N/A if (field_type == T_OBJECT || field_type == T_ARRAY) {
0N/A state.apush(unknown_obj);
0N/A } else if (type2size[field_type] == 1) {
0N/A state.spush();
0N/A } else {
0N/A state.lpush();
0N/A }
0N/A }
0N/A break;
0N/A case Bytecodes::_putstatic:
0N/A case Bytecodes::_putfield:
0N/A { bool will_link;
0N/A ciField* field = s.get_field(will_link);
0N/A BasicType field_type = field->type()->basic_type();
0N/A if (field_type == T_OBJECT || field_type == T_ARRAY) {
0N/A set_global_escape(state.apop());
0N/A } else if (type2size[field_type] == 1) {
0N/A state.spop();
0N/A } else {
0N/A state.lpop();
0N/A }
0N/A if (s.cur_bc() != Bytecodes::_putstatic) {
0N/A ArgumentMap p = state.apop();
0N/A set_method_escape(p);
45N/A set_modified(p, will_link ? field->offset() : OFFSET_ANY, type2size[field_type]*HeapWordSize);
0N/A }
0N/A }
0N/A break;
0N/A case Bytecodes::_invokevirtual:
0N/A case Bytecodes::_invokespecial:
0N/A case Bytecodes::_invokestatic:
726N/A case Bytecodes::_invokedynamic:
0N/A case Bytecodes::_invokeinterface:
0N/A { bool will_link;
0N/A ciMethod* target = s.get_method(will_link);
0N/A ciKlass* holder = s.get_declared_method_holder();
0N/A invoke(state, s.cur_bc(), target, holder);
0N/A ciType* return_type = target->return_type();
0N/A if (!return_type->is_primitive_type()) {
0N/A state.apush(unknown_obj);
0N/A } else if (return_type->is_one_word()) {
0N/A state.spush();
0N/A } else if (return_type->is_two_word()) {
0N/A state.lpush();
0N/A }
0N/A }
0N/A break;
0N/A case Bytecodes::_new:
0N/A state.apush(allocated_obj);
0N/A break;
0N/A case Bytecodes::_newarray:
0N/A case Bytecodes::_anewarray:
0N/A state.spop();
0N/A state.apush(allocated_obj);
0N/A break;
0N/A case Bytecodes::_multianewarray:
0N/A { int i = s.cur_bcp()[3];
0N/A while (i-- > 0) state.spop();
0N/A state.apush(allocated_obj);
0N/A }
0N/A break;
0N/A case Bytecodes::_arraylength:
0N/A set_method_escape(state.apop());
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_athrow:
0N/A set_global_escape(state.apop());
0N/A fall_through = false;
0N/A break;
0N/A case Bytecodes::_checkcast:
0N/A { ArgumentMap obj = state.apop();
0N/A set_method_escape(obj);
0N/A state.apush(obj);
0N/A }
0N/A break;
0N/A case Bytecodes::_instanceof:
0N/A set_method_escape(state.apop());
0N/A state.spush();
0N/A break;
0N/A case Bytecodes::_monitorenter:
0N/A case Bytecodes::_monitorexit:
0N/A state.apop();
0N/A break;
0N/A case Bytecodes::_wide:
0N/A ShouldNotReachHere();
0N/A break;
0N/A case Bytecodes::_ifnull:
0N/A case Bytecodes::_ifnonnull:
0N/A {
0N/A set_method_escape(state.apop());
0N/A int dest_bci = s.get_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A break;
0N/A }
0N/A case Bytecodes::_goto_w:
0N/A {
0N/A int dest_bci = s.get_far_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A fall_through = false;
0N/A break;
0N/A }
0N/A case Bytecodes::_jsr_w:
0N/A {
0N/A int dest_bci = s.get_far_dest();
0N/A assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
0N/A assert(s.next_bci() == limit_bci, "branch must end block");
0N/A state.apush(empty_map);
0N/A successors.push(_methodBlocks->block_containing(dest_bci));
0N/A fall_through = false;
0N/A break;
0N/A }
0N/A case Bytecodes::_breakpoint:
0N/A break;
0N/A default:
0N/A ShouldNotReachHere();
0N/A break;
0N/A }
0N/A
0N/A }
0N/A if (fall_through) {
0N/A int fall_through_bci = s.cur_bci();
0N/A if (fall_through_bci < _method->code_size()) {
0N/A assert(_methodBlocks->is_block_start(fall_through_bci), "must fall through to block start.");
0N/A successors.push(_methodBlocks->block_containing(fall_through_bci));
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::merge_block_states(StateInfo *blockstates, ciBlock *dest, StateInfo *s_state) {
45N/A StateInfo *d_state = blockstates + dest->index();
0N/A int nlocals = _method->max_locals();
0N/A
0N/A // exceptions may cause transfer of control to handlers in the middle of a
0N/A // block, so we don't merge the incoming state of exception handlers
0N/A if (dest->is_handler())
0N/A return;
0N/A if (!d_state->_initialized ) {
0N/A // destination not initialized, just copy
0N/A for (int i = 0; i < nlocals; i++) {
0N/A d_state->_vars[i] = s_state->_vars[i];
0N/A }
0N/A for (int i = 0; i < s_state->_stack_height; i++) {
0N/A d_state->_stack[i] = s_state->_stack[i];
0N/A }
0N/A d_state->_stack_height = s_state->_stack_height;
0N/A d_state->_max_stack = s_state->_max_stack;
0N/A d_state->_initialized = true;
0N/A } else if (!dest->processed()) {
0N/A // we have not yet walked the bytecodes of dest, we can merge
0N/A // the states
0N/A assert(d_state->_stack_height == s_state->_stack_height, "computed stack heights must match");
0N/A for (int i = 0; i < nlocals; i++) {
0N/A d_state->_vars[i].set_union(s_state->_vars[i]);
0N/A }
0N/A for (int i = 0; i < s_state->_stack_height; i++) {
0N/A d_state->_stack[i].set_union(s_state->_stack[i]);
0N/A }
0N/A } else {
0N/A // the bytecodes of dest have already been processed, mark any
0N/A // arguments in the source state which are not in the dest state
0N/A // as global escape.
0N/A // Future refinement: we only need to mark these variable to the
0N/A // maximum escape of any variables in dest state
0N/A assert(d_state->_stack_height == s_state->_stack_height, "computed stack heights must match");
0N/A ArgumentMap extra_vars;
0N/A for (int i = 0; i < nlocals; i++) {
0N/A ArgumentMap t;
0N/A t = s_state->_vars[i];
0N/A t.set_difference(d_state->_vars[i]);
0N/A extra_vars.set_union(t);
0N/A }
0N/A for (int i = 0; i < s_state->_stack_height; i++) {
0N/A ArgumentMap t;
45N/A //extra_vars |= !d_state->_vars[i] & s_state->_vars[i];
0N/A t.clear();
0N/A t = s_state->_stack[i];
0N/A t.set_difference(d_state->_stack[i]);
0N/A extra_vars.set_union(t);
0N/A }
0N/A set_global_escape(extra_vars);
0N/A }
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::iterate_blocks(Arena *arena) {
0N/A int numblocks = _methodBlocks->num_blocks();
0N/A int stkSize = _method->max_stack();
0N/A int numLocals = _method->max_locals();
0N/A StateInfo state;
0N/A
0N/A int datacount = (numblocks + 1) * (stkSize + numLocals);
0N/A int datasize = datacount * sizeof(ArgumentMap);
45N/A StateInfo *blockstates = (StateInfo *) arena->Amalloc(numblocks * sizeof(StateInfo));
0N/A ArgumentMap *statedata = (ArgumentMap *) arena->Amalloc(datasize);
0N/A for (int i = 0; i < datacount; i++) ::new ((void*)&statedata[i]) ArgumentMap();
0N/A ArgumentMap *dp = statedata;
0N/A state._vars = dp;
0N/A dp += numLocals;
0N/A state._stack = dp;
0N/A dp += stkSize;
0N/A state._initialized = false;
0N/A state._max_stack = stkSize;
0N/A for (int i = 0; i < numblocks; i++) {
0N/A blockstates[i]._vars = dp;
0N/A dp += numLocals;
0N/A blockstates[i]._stack = dp;
0N/A dp += stkSize;
0N/A blockstates[i]._initialized = false;
0N/A blockstates[i]._stack_height = 0;
0N/A blockstates[i]._max_stack = stkSize;
0N/A }
0N/A GrowableArray<ciBlock *> worklist(arena, numblocks / 4, 0, NULL);
0N/A GrowableArray<ciBlock *> successors(arena, 4, 0, NULL);
0N/A
0N/A _methodBlocks->clear_processed();
0N/A
0N/A // initialize block 0 state from method signature
0N/A ArgumentMap allVars; // all oop arguments to method
0N/A ciSignature* sig = method()->signature();
0N/A int j = 0;
45N/A ciBlock* first_blk = _methodBlocks->block_containing(0);
45N/A int fb_i = first_blk->index();
0N/A if (!method()->is_static()) {
0N/A // record information for "this"
45N/A blockstates[fb_i]._vars[j].set(j);
0N/A allVars.add(j);
0N/A j++;
0N/A }
0N/A for (int i = 0; i < sig->count(); i++) {
0N/A ciType* t = sig->type_at(i);
0N/A if (!t->is_primitive_type()) {
45N/A blockstates[fb_i]._vars[j].set(j);
0N/A allVars.add(j);
0N/A }
0N/A j += t->size();
0N/A }
45N/A blockstates[fb_i]._initialized = true;
0N/A assert(j == _arg_size, "just checking");
0N/A
0N/A ArgumentMap unknown_map;
0N/A unknown_map.add_unknown();
0N/A
45N/A worklist.push(first_blk);
0N/A while(worklist.length() > 0) {
0N/A ciBlock *blk = worklist.pop();
45N/A StateInfo *blkState = blockstates + blk->index();
0N/A if (blk->is_handler() || blk->is_ret_target()) {
0N/A // for an exception handler or a target of a ret instruction, we assume the worst case,
45N/A // that any variable could contain any argument
0N/A for (int i = 0; i < numLocals; i++) {
0N/A state._vars[i] = allVars;
0N/A }
0N/A if (blk->is_handler()) {
0N/A state._stack_height = 1;
0N/A } else {
0N/A state._stack_height = blkState->_stack_height;
0N/A }
0N/A for (int i = 0; i < state._stack_height; i++) {
45N/A// ??? should this be unknown_map ???
0N/A state._stack[i] = allVars;
0N/A }
0N/A } else {
0N/A for (int i = 0; i < numLocals; i++) {
0N/A state._vars[i] = blkState->_vars[i];
0N/A }
0N/A for (int i = 0; i < blkState->_stack_height; i++) {
0N/A state._stack[i] = blkState->_stack[i];
0N/A }
0N/A state._stack_height = blkState->_stack_height;
0N/A }
0N/A iterate_one_block(blk, state, successors);
0N/A // if this block has any exception handlers, push them
0N/A // onto successor list
0N/A if (blk->has_handler()) {
0N/A DEBUG_ONLY(int handler_count = 0;)
0N/A int blk_start = blk->start_bci();
0N/A int blk_end = blk->limit_bci();
0N/A for (int i = 0; i < numblocks; i++) {
0N/A ciBlock *b = _methodBlocks->block(i);
0N/A if (b->is_handler()) {
0N/A int ex_start = b->ex_start_bci();
0N/A int ex_end = b->ex_limit_bci();
0N/A if ((ex_start >= blk_start && ex_start < blk_end) ||
0N/A (ex_end > blk_start && ex_end <= blk_end)) {
0N/A successors.push(b);
0N/A }
0N/A DEBUG_ONLY(handler_count++;)
0N/A }
0N/A }
0N/A assert(handler_count > 0, "must find at least one handler");
0N/A }
0N/A // merge computed variable state with successors
0N/A while(successors.length() > 0) {
0N/A ciBlock *succ = successors.pop();
0N/A merge_block_states(blockstates, succ, &state);
0N/A if (!succ->processed())
0N/A worklist.push(succ);
0N/A }
0N/A }
0N/A}
0N/A
0N/Abool BCEscapeAnalyzer::do_analysis() {
0N/A Arena* arena = CURRENT_ENV->arena();
0N/A // identify basic blocks
0N/A _methodBlocks = _method->get_method_blocks();
0N/A
0N/A iterate_blocks(arena);
0N/A // TEMPORARY
0N/A return true;
0N/A}
0N/A
0N/AvmIntrinsics::ID BCEscapeAnalyzer::known_intrinsic() {
0N/A vmIntrinsics::ID iid = method()->intrinsic_id();
0N/A
0N/A if (iid == vmIntrinsics::_getClass ||
45N/A iid == vmIntrinsics::_fillInStackTrace ||
0N/A iid == vmIntrinsics::_hashCode)
0N/A return iid;
0N/A else
0N/A return vmIntrinsics::_none;
0N/A}
0N/A
0N/Abool BCEscapeAnalyzer::compute_escape_for_intrinsic(vmIntrinsics::ID iid) {
45N/A ArgumentMap arg;
45N/A arg.clear();
0N/A switch (iid) {
0N/A case vmIntrinsics::_getClass:
0N/A _return_local = false;
0N/A break;
45N/A case vmIntrinsics::_fillInStackTrace:
45N/A arg.set(0); // 'this'
45N/A set_returned(arg);
45N/A break;
0N/A case vmIntrinsics::_hashCode:
0N/A // initialized state is correct
0N/A break;
0N/A default:
0N/A assert(false, "unexpected intrinsic");
0N/A }
0N/A return true;
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::initialize() {
0N/A int i;
0N/A
0N/A // clear escape information (method may have been deoptimized)
0N/A methodData()->clear_escape_info();
0N/A
0N/A // initialize escape state of object parameters
0N/A ciSignature* sig = method()->signature();
0N/A int j = 0;
0N/A if (!method()->is_static()) {
1568N/A _arg_local.set(0);
1568N/A _arg_stack.set(0);
0N/A j++;
0N/A }
0N/A for (i = 0; i < sig->count(); i++) {
0N/A ciType* t = sig->type_at(i);
0N/A if (!t->is_primitive_type()) {
1568N/A _arg_local.set(j);
1568N/A _arg_stack.set(j);
0N/A }
0N/A j += t->size();
0N/A }
0N/A assert(j == _arg_size, "just checking");
0N/A
0N/A // start with optimistic assumption
0N/A ciType *rt = _method->return_type();
0N/A if (rt->is_primitive_type()) {
0N/A _return_local = false;
0N/A _return_allocated = false;
0N/A } else {
0N/A _return_local = true;
0N/A _return_allocated = true;
0N/A }
0N/A _allocated_escapes = false;
45N/A _unknown_modified = false;
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::clear_escape_info() {
0N/A ciSignature* sig = method()->signature();
0N/A int arg_count = sig->count();
0N/A ArgumentMap var;
45N/A if (!method()->is_static()) {
45N/A arg_count++; // allow for "this"
45N/A }
0N/A for (int i = 0; i < arg_count; i++) {
45N/A set_arg_modified(i, OFFSET_ANY, 4);
0N/A var.clear();
0N/A var.set(i);
45N/A set_modified(var, OFFSET_ANY, 4);
0N/A set_global_escape(var);
0N/A }
1568N/A _arg_local.Clear();
1568N/A _arg_stack.Clear();
1568N/A _arg_returned.Clear();
0N/A _return_local = false;
0N/A _return_allocated = false;
0N/A _allocated_escapes = true;
45N/A _unknown_modified = true;
0N/A}
0N/A
0N/A
0N/Avoid BCEscapeAnalyzer::compute_escape_info() {
0N/A int i;
0N/A assert(!methodData()->has_escape_info(), "do not overwrite escape info");
0N/A
0N/A vmIntrinsics::ID iid = known_intrinsic();
0N/A
0N/A // check if method can be analyzed
0N/A if (iid == vmIntrinsics::_none && (method()->is_abstract() || method()->is_native() || !method()->holder()->is_initialized()
0N/A || _level > MaxBCEAEstimateLevel
0N/A || method()->code_size() > MaxBCEAEstimateSize)) {
0N/A if (BCEATraceLevel >= 1) {
0N/A tty->print("Skipping method because: ");
0N/A if (method()->is_abstract())
0N/A tty->print_cr("method is abstract.");
0N/A else if (method()->is_native())
0N/A tty->print_cr("method is native.");
0N/A else if (!method()->holder()->is_initialized())
0N/A tty->print_cr("class of method is not initialized.");
0N/A else if (_level > MaxBCEAEstimateLevel)
0N/A tty->print_cr("level (%d) exceeds MaxBCEAEstimateLevel (%d).",
0N/A _level, MaxBCEAEstimateLevel);
0N/A else if (method()->code_size() > MaxBCEAEstimateSize)
0N/A tty->print_cr("code size (%d) exceeds MaxBCEAEstimateSize.",
0N/A method()->code_size(), MaxBCEAEstimateSize);
0N/A else
0N/A ShouldNotReachHere();
0N/A }
0N/A clear_escape_info();
0N/A
0N/A return;
0N/A }
0N/A
0N/A if (BCEATraceLevel >= 1) {
0N/A tty->print("[EA] estimating escape information for");
0N/A if (iid != vmIntrinsics::_none)
0N/A tty->print(" intrinsic");
0N/A method()->print_short_name();
0N/A tty->print_cr(" (%d bytes)", method()->code_size());
0N/A }
0N/A
0N/A bool success;
0N/A
0N/A initialize();
0N/A
78N/A // Do not scan method if it has no object parameters and
78N/A // does not returns an object (_return_allocated is set in initialize()).
1568N/A if (_arg_local.Size() == 0 && !_return_allocated) {
78N/A // Clear all info since method's bytecode was not analysed and
78N/A // set pessimistic escape information.
78N/A clear_escape_info();
78N/A methodData()->set_eflag(methodDataOopDesc::allocated_escapes);
78N/A methodData()->set_eflag(methodDataOopDesc::unknown_modified);
0N/A methodData()->set_eflag(methodDataOopDesc::estimated);
0N/A return;
0N/A }
0N/A
0N/A if (iid != vmIntrinsics::_none)
0N/A success = compute_escape_for_intrinsic(iid);
0N/A else {
0N/A success = do_analysis();
0N/A }
0N/A
78N/A // don't store interprocedural escape information if it introduces
78N/A // dependencies or if method data is empty
0N/A //
0N/A if (!has_dependencies() && !methodData()->is_empty()) {
0N/A for (i = 0; i < _arg_size; i++) {
1568N/A if (_arg_local.test(i)) {
1568N/A assert(_arg_stack.test(i), "inconsistent escape info");
0N/A methodData()->set_arg_local(i);
0N/A methodData()->set_arg_stack(i);
1568N/A } else if (_arg_stack.test(i)) {
0N/A methodData()->set_arg_stack(i);
0N/A }
1568N/A if (_arg_returned.test(i)) {
0N/A methodData()->set_arg_returned(i);
0N/A }
45N/A methodData()->set_arg_modified(i, _arg_modified[i]);
0N/A }
0N/A if (_return_local) {
0N/A methodData()->set_eflag(methodDataOopDesc::return_local);
0N/A }
78N/A if (_return_allocated) {
78N/A methodData()->set_eflag(methodDataOopDesc::return_allocated);
78N/A }
78N/A if (_allocated_escapes) {
78N/A methodData()->set_eflag(methodDataOopDesc::allocated_escapes);
78N/A }
78N/A if (_unknown_modified) {
78N/A methodData()->set_eflag(methodDataOopDesc::unknown_modified);
78N/A }
0N/A methodData()->set_eflag(methodDataOopDesc::estimated);
0N/A }
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::read_escape_info() {
0N/A assert(methodData()->has_escape_info(), "no escape info available");
0N/A
0N/A // read escape information from method descriptor
0N/A for (int i = 0; i < _arg_size; i++) {
1568N/A if (methodData()->is_arg_local(i))
1568N/A _arg_local.set(i);
1568N/A if (methodData()->is_arg_stack(i))
1568N/A _arg_stack.set(i);
1568N/A if (methodData()->is_arg_returned(i))
1568N/A _arg_returned.set(i);
45N/A _arg_modified[i] = methodData()->arg_modified(i);
0N/A }
0N/A _return_local = methodData()->eflag_set(methodDataOopDesc::return_local);
78N/A _return_allocated = methodData()->eflag_set(methodDataOopDesc::return_allocated);
78N/A _allocated_escapes = methodData()->eflag_set(methodDataOopDesc::allocated_escapes);
78N/A _unknown_modified = methodData()->eflag_set(methodDataOopDesc::unknown_modified);
0N/A
0N/A}
0N/A
78N/A#ifndef PRODUCT
78N/Avoid BCEscapeAnalyzer::dump() {
78N/A tty->print("[EA] estimated escape information for");
78N/A method()->print_short_name();
78N/A tty->print_cr(has_dependencies() ? " (not stored)" : "");
78N/A tty->print(" non-escaping args: ");
78N/A _arg_local.print_on(tty);
78N/A tty->print(" stack-allocatable args: ");
78N/A _arg_stack.print_on(tty);
78N/A if (_return_local) {
78N/A tty->print(" returned args: ");
78N/A _arg_returned.print_on(tty);
78N/A } else if (is_return_allocated()) {
78N/A tty->print_cr(" return allocated value");
78N/A } else {
78N/A tty->print_cr(" return non-local value");
78N/A }
78N/A tty->print(" modified args: ");
78N/A for (int i = 0; i < _arg_size; i++) {
78N/A if (_arg_modified[i] == 0)
78N/A tty->print(" 0");
78N/A else
78N/A tty->print(" 0x%x", _arg_modified[i]);
78N/A }
78N/A tty->cr();
78N/A tty->print(" flags: ");
78N/A if (_return_allocated)
78N/A tty->print(" return_allocated");
78N/A if (_allocated_escapes)
78N/A tty->print(" allocated_escapes");
78N/A if (_unknown_modified)
78N/A tty->print(" unknown_modified");
78N/A tty->cr();
78N/A}
78N/A#endif
0N/A
0N/ABCEscapeAnalyzer::BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent)
0N/A : _conservative(method == NULL || !EstimateArgEscape)
1568N/A , _arena(CURRENT_ENV->arena())
0N/A , _method(method)
0N/A , _methodData(method ? method->method_data() : NULL)
0N/A , _arg_size(method ? method->arg_size() : 0)
1568N/A , _arg_local(_arena)
1568N/A , _arg_stack(_arena)
1568N/A , _arg_returned(_arena)
1568N/A , _dirty(_arena)
0N/A , _return_local(false)
0N/A , _return_allocated(false)
0N/A , _allocated_escapes(false)
45N/A , _unknown_modified(false)
1568N/A , _dependencies(_arena, 4, 0, NULL)
0N/A , _parent(parent)
0N/A , _level(parent == NULL ? 0 : parent->level() + 1) {
0N/A if (!_conservative) {
1568N/A _arg_local.Clear();
1568N/A _arg_stack.Clear();
1568N/A _arg_returned.Clear();
1568N/A _dirty.Clear();
0N/A Arena* arena = CURRENT_ENV->arena();
45N/A _arg_modified = (uint *) arena->Amalloc(_arg_size * sizeof(uint));
45N/A Copy::zero_to_bytes(_arg_modified, _arg_size * sizeof(uint));
0N/A
0N/A if (methodData() == NULL)
0N/A return;
0N/A bool printit = _method->should_print_assembly();
0N/A if (methodData()->has_escape_info()) {
0N/A TRACE_BCEA(2, tty->print_cr("[EA] Reading previous results for %s.%s",
0N/A method->holder()->name()->as_utf8(),
0N/A method->name()->as_utf8()));
0N/A read_escape_info();
0N/A } else {
0N/A TRACE_BCEA(2, tty->print_cr("[EA] computing results for %s.%s",
0N/A method->holder()->name()->as_utf8(),
0N/A method->name()->as_utf8()));
0N/A
0N/A compute_escape_info();
0N/A methodData()->update_escape_info();
0N/A }
78N/A#ifndef PRODUCT
78N/A if (BCEATraceLevel >= 3) {
78N/A // dump escape information
78N/A dump();
78N/A }
78N/A#endif
0N/A }
0N/A}
0N/A
0N/Avoid BCEscapeAnalyzer::copy_dependencies(Dependencies *deps) {
1397N/A if (ciEnv::current()->jvmti_can_hotswap_or_post_breakpoint()) {
1397N/A // Also record evol dependencies so redefinition of the
1397N/A // callee will trigger recompilation.
1397N/A deps->assert_evol_method(method());
1397N/A }
0N/A for (int i = 0; i < _dependencies.length(); i+=2) {
1568N/A ciKlass *k = _dependencies.at(i)->as_klass();
1568N/A ciMethod *m = _dependencies.at(i+1)->as_method();
0N/A deps->assert_unique_concrete_method(k, m);
0N/A }
0N/A}