Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_GraphBuilder.hpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_C1_C1_GRAPHBUILDER_HPP25#define SHARE_VM_C1_C1_GRAPHBUILDER_HPP2627#include "c1/c1_IR.hpp"28#include "c1/c1_Instruction.hpp"29#include "c1/c1_ValueMap.hpp"30#include "c1/c1_ValueStack.hpp"31#include "ci/ciMethodData.hpp"32#include "ci/ciStreams.hpp"33#include "compiler/compileLog.hpp"3435class MemoryBuffer;3637class GraphBuilder VALUE_OBJ_CLASS_SPEC {38private:39// Per-scope data. These are pushed and popped as we descend into40// inlined methods. Currently in order to generate good code in the41// inliner we have to attempt to inline methods directly into the42// basic block we are parsing; this adds complexity.43class ScopeData: public CompilationResourceObj {44private:45ScopeData* _parent;46// bci-to-block mapping47BlockList* _bci2block;48// Scope49IRScope* _scope;50// Whether this scope or any parent scope has exception handlers51bool _has_handler;52// The bytecodes53ciBytecodeStream* _stream;5455// Work list56BlockList* _work_list;5758// Maximum inline size for this scope59intx _max_inline_size;60// Expression stack depth at point where inline occurred61int _caller_stack_size;6263// The continuation point for the inline. Currently only used in64// multi-block inlines, but eventually would like to use this for65// all inlines for uniformity and simplicity; in this case would66// get the continuation point from the BlockList instead of67// fabricating it anew because Invokes would be considered to be68// BlockEnds.69BlockBegin* _continuation;7071// Was this ScopeData created only for the parsing and inlining of72// a jsr?73bool _parsing_jsr;74// We track the destination bci of the jsr only to determine75// bailout conditions, since we only handle a subset of all of the76// possible jsr-ret control structures. Recursive invocations of a77// jsr are disallowed by the verifier.78int _jsr_entry_bci;79// We need to track the local variable in which the return address80// was stored to ensure we can handle inlining the jsr, because we81// don't handle arbitrary jsr/ret constructs.82int _jsr_ret_addr_local;83// If we are parsing a jsr, the continuation point for rets84BlockBegin* _jsr_continuation;85// Cloned XHandlers for jsr-related ScopeDatas86XHandlers* _jsr_xhandlers;8788// Number of returns seen in this scope89int _num_returns;9091// In order to generate profitable code for inlining, we currently92// have to perform an optimization for single-block inlined93// methods where we continue parsing into the same block. This94// allows us to perform CSE across inlined scopes and to avoid95// storing parameters to the stack. Having a global register96// allocator and being able to perform global CSE would allow this97// code to be removed and thereby simplify the inliner.98BlockBegin* _cleanup_block; // The block to which the return was added99Instruction* _cleanup_return_prev; // Instruction before return instruction100ValueStack* _cleanup_state; // State of that block (not yet pinned)101102public:103ScopeData(ScopeData* parent);104105ScopeData* parent() const { return _parent; }106107BlockList* bci2block() const { return _bci2block; }108void set_bci2block(BlockList* bci2block) { _bci2block = bci2block; }109110// NOTE: this has a different effect when parsing jsrs111BlockBegin* block_at(int bci);112113IRScope* scope() const { return _scope; }114// Has side-effect of setting has_handler flag115void set_scope(IRScope* scope);116117// Whether this or any parent scope has exception handlers118bool has_handler() const { return _has_handler; }119void set_has_handler() { _has_handler = true; }120121// Exception handlers list to be used for this scope122XHandlers* xhandlers() const;123124// How to get a block to be parsed125void add_to_work_list(BlockBegin* block);126// How to remove the next block to be parsed; returns NULL if none left127BlockBegin* remove_from_work_list();128// Indicates parse is over129bool is_work_list_empty() const;130131ciBytecodeStream* stream() { return _stream; }132void set_stream(ciBytecodeStream* stream) { _stream = stream; }133134intx max_inline_size() const { return _max_inline_size; }135136BlockBegin* continuation() const { return _continuation; }137void set_continuation(BlockBegin* cont) { _continuation = cont; }138139// Indicates whether this ScopeData was pushed only for the140// parsing and inlining of a jsr141bool parsing_jsr() const { return _parsing_jsr; }142void set_parsing_jsr() { _parsing_jsr = true; }143int jsr_entry_bci() const { return _jsr_entry_bci; }144void set_jsr_entry_bci(int bci) { _jsr_entry_bci = bci; }145void set_jsr_return_address_local(int local_no){ _jsr_ret_addr_local = local_no; }146int jsr_return_address_local() const { return _jsr_ret_addr_local; }147// Must be called after scope is set up for jsr ScopeData148void setup_jsr_xhandlers();149150// The jsr continuation is only used when parsing_jsr is true, and151// is different from the "normal" continuation since we can end up152// doing a return (rather than a ret) from within a subroutine153BlockBegin* jsr_continuation() const { return _jsr_continuation; }154void set_jsr_continuation(BlockBegin* cont) { _jsr_continuation = cont; }155156int num_returns();157void incr_num_returns();158159void set_inline_cleanup_info(BlockBegin* block,160Instruction* return_prev,161ValueStack* return_state);162BlockBegin* inline_cleanup_block() const { return _cleanup_block; }163Instruction* inline_cleanup_return_prev() const{ return _cleanup_return_prev; }164ValueStack* inline_cleanup_state() const { return _cleanup_state; }165};166167// for all GraphBuilders168static bool _can_trap[Bytecodes::number_of_java_codes];169170// for each instance of GraphBuilder171ScopeData* _scope_data; // Per-scope data; used for inlining172Compilation* _compilation; // the current compilation173ValueMap* _vmap; // the map of values encountered (for CSE)174MemoryBuffer* _memory;175const char* _inline_bailout_msg; // non-null if most recent inline attempt failed176int _instruction_count; // for bailing out in pathological jsr/ret cases177BlockBegin* _start; // the start block178BlockBegin* _osr_entry; // the osr entry block block179ValueStack* _initial_state; // The state for the start block180181// for each call to connect_to_end; can also be set by inliner182BlockBegin* _block; // the current block183ValueStack* _state; // the current execution state184Instruction* _last; // the last instruction added185bool _skip_block; // skip processing of the rest of this block186187// accessors188ScopeData* scope_data() const { return _scope_data; }189Compilation* compilation() const { return _compilation; }190BlockList* bci2block() const { return scope_data()->bci2block(); }191ValueMap* vmap() const { assert(UseLocalValueNumbering, "should not access otherwise"); return _vmap; }192bool has_handler() const { return scope_data()->has_handler(); }193194BlockBegin* block() const { return _block; }195ValueStack* state() const { return _state; }196void set_state(ValueStack* state) { _state = state; }197IRScope* scope() const { return scope_data()->scope(); }198ciMethod* method() const { return scope()->method(); }199ciBytecodeStream* stream() const { return scope_data()->stream(); }200Instruction* last() const { return _last; }201Bytecodes::Code code() const { return stream()->cur_bc(); }202int bci() const { return stream()->cur_bci(); }203int next_bci() const { return stream()->next_bci(); }204205// unified bailout support206void bailout(const char* msg) const { compilation()->bailout(msg); }207bool bailed_out() const { return compilation()->bailed_out(); }208209// stack manipulation helpers210void ipush(Value t) const { state()->ipush(t); }211void lpush(Value t) const { state()->lpush(t); }212void fpush(Value t) const { state()->fpush(t); }213void dpush(Value t) const { state()->dpush(t); }214void apush(Value t) const { state()->apush(t); }215void push(ValueType* type, Value t) const { state()-> push(type, t); }216217Value ipop() { return state()->ipop(); }218Value lpop() { return state()->lpop(); }219Value fpop() { return state()->fpop(); }220Value dpop() { return state()->dpop(); }221Value apop() { return state()->apop(); }222Value pop(ValueType* type) { return state()-> pop(type); }223224// instruction helpers225void load_constant();226void load_local(ValueType* type, int index);227void store_local(ValueType* type, int index);228void store_local(ValueStack* state, Value value, int index);229void load_indexed (BasicType type);230void store_indexed(BasicType type);231void stack_op(Bytecodes::Code code);232void arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* state_before = NULL);233void negate_op(ValueType* type);234void shift_op(ValueType* type, Bytecodes::Code code);235void logic_op(ValueType* type, Bytecodes::Code code);236void compare_op(ValueType* type, Bytecodes::Code code);237void convert(Bytecodes::Code op, BasicType from, BasicType to);238void increment();239void _goto(int from_bci, int to_bci);240void if_node(Value x, If::Condition cond, Value y, ValueStack* stack_before);241void if_zero(ValueType* type, If::Condition cond);242void if_null(ValueType* type, If::Condition cond);243void if_same(ValueType* type, If::Condition cond);244void jsr(int dest);245void ret(int local_index);246void table_switch();247void lookup_switch();248void method_return(Value x);249void call_register_finalizer();250void access_field(Bytecodes::Code code);251void invoke(Bytecodes::Code code);252void new_instance(int klass_index);253void new_type_array();254void new_object_array();255void check_cast(int klass_index);256void instance_of(int klass_index);257void monitorenter(Value x, int bci);258void monitorexit(Value x, int bci);259void new_multi_array(int dimensions);260void throw_op(int bci);261Value round_fp(Value fp_value);262263// stack/code manipulation helpers264Instruction* append_with_bci(Instruction* instr, int bci);265Instruction* append(Instruction* instr);266Instruction* append_split(StateSplit* instr);267268// other helpers269BlockBegin* block_at(int bci) { return scope_data()->block_at(bci); }270XHandlers* handle_exception(Instruction* instruction);271void connect_to_end(BlockBegin* beg);272void null_check(Value value);273void eliminate_redundant_phis(BlockBegin* start);274BlockEnd* iterate_bytecodes_for_block(int bci);275void iterate_all_blocks(bool start_in_current_block_for_inlining = false);276Dependencies* dependency_recorder() const; // = compilation()->dependencies()277bool direct_compare(ciKlass* k);278279void kill_all();280281// use of state copy routines (try to minimize unnecessary state282// object allocations):283284// - if the instruction unconditionally needs a full copy of the285// state (for patching for example), then use copy_state_before*286287// - if the instruction needs a full copy of the state only for288// handler generation (Instruction::needs_exception_state() returns289// false) then use copy_state_exhandling*290291// - if the instruction needs either a full copy of the state for292// handler generation and a least a minimal copy of the state (as293// returned by Instruction::exception_state()) for debug info294// generation (that is when Instruction::needs_exception_state()295// returns true) then use copy_state_for_exception*296297ValueStack* copy_state_before_with_bci(int bci);298ValueStack* copy_state_before();299ValueStack* copy_state_exhandling_with_bci(int bci);300ValueStack* copy_state_exhandling();301ValueStack* copy_state_for_exception_with_bci(int bci);302ValueStack* copy_state_for_exception();303ValueStack* copy_state_if_bb(bool is_bb) { return (is_bb || compilation()->is_optimistic()) ? copy_state_before() : NULL; }304ValueStack* copy_state_indexed_access() { return compilation()->is_optimistic() ? copy_state_before() : copy_state_for_exception(); }305306//307// Inlining support308//309310// accessors311bool parsing_jsr() const { return scope_data()->parsing_jsr(); }312BlockBegin* continuation() const { return scope_data()->continuation(); }313BlockBegin* jsr_continuation() const { return scope_data()->jsr_continuation(); }314void set_continuation(BlockBegin* continuation) { scope_data()->set_continuation(continuation); }315void set_inline_cleanup_info(BlockBegin* block,316Instruction* return_prev,317ValueStack* return_state) { scope_data()->set_inline_cleanup_info(block,318return_prev,319return_state); }320void set_inline_cleanup_info() {321set_inline_cleanup_info(_block, _last, _state);322}323BlockBegin* inline_cleanup_block() const { return scope_data()->inline_cleanup_block(); }324Instruction* inline_cleanup_return_prev() const { return scope_data()->inline_cleanup_return_prev(); }325ValueStack* inline_cleanup_state() const { return scope_data()->inline_cleanup_state(); }326void restore_inline_cleanup_info() {327_block = inline_cleanup_block();328_last = inline_cleanup_return_prev();329_state = inline_cleanup_state();330}331void incr_num_returns() { scope_data()->incr_num_returns(); }332int num_returns() const { return scope_data()->num_returns(); }333intx max_inline_size() const { return scope_data()->max_inline_size(); }334int inline_level() const { return scope()->level(); }335int recursive_inline_level(ciMethod* callee) const;336337// inlining of synchronized methods338void inline_sync_entry(Value lock, BlockBegin* sync_handler);339void fill_sync_handler(Value lock, BlockBegin* sync_handler, bool default_handler = false);340341// inliners342bool try_inline( ciMethod* callee, bool holder_known, Bytecodes::Code bc = Bytecodes::_illegal, Value receiver = NULL);343bool try_inline_intrinsics(ciMethod* callee);344bool try_inline_full( ciMethod* callee, bool holder_known, Bytecodes::Code bc = Bytecodes::_illegal, Value receiver = NULL);345bool try_inline_jsr(int jsr_dest_bci);346347const char* check_can_parse(ciMethod* callee) const;348const char* should_not_inline(ciMethod* callee) const;349350// JSR 292 support351bool try_method_handle_inline(ciMethod* callee);352353// helpers354void inline_bailout(const char* msg);355BlockBegin* header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state);356BlockBegin* setup_start_block(int osr_bci, BlockBegin* std_entry, BlockBegin* osr_entry, ValueStack* init_state);357void setup_osr_entry_block();358void clear_inline_bailout();359ValueStack* state_at_entry();360void push_root_scope(IRScope* scope, BlockList* bci2block, BlockBegin* start);361void push_scope(ciMethod* callee, BlockBegin* continuation);362void push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci);363void pop_scope();364void pop_scope_for_jsr();365366bool append_unsafe_get_obj(ciMethod* callee, BasicType t, bool is_volatile);367bool append_unsafe_put_obj(ciMethod* callee, BasicType t, bool is_volatile);368bool append_unsafe_get_raw(ciMethod* callee, BasicType t);369bool append_unsafe_put_raw(ciMethod* callee, BasicType t);370bool append_unsafe_prefetch(ciMethod* callee, bool is_store, bool is_static);371void append_unsafe_CAS(ciMethod* callee);372bool append_unsafe_get_and_set_obj(ciMethod* callee, bool is_add);373374void print_inlining(ciMethod* callee, const char* msg = NULL, bool success = true);375376void profile_call(ciMethod* callee, Value recv, ciKlass* predicted_holder, Values* obj_args, bool inlined);377void profile_return_type(Value ret, ciMethod* callee, ciMethod* m = NULL, int bci = -1);378void profile_invocation(ciMethod* inlinee, ValueStack* state);379380// Shortcuts to profiling control.381bool is_profiling() { return _compilation->is_profiling(); }382bool count_invocations() { return _compilation->count_invocations(); }383bool count_backedges() { return _compilation->count_backedges(); }384bool profile_branches() { return _compilation->profile_branches(); }385bool profile_calls() { return _compilation->profile_calls(); }386bool profile_inlined_calls() { return _compilation->profile_inlined_calls(); }387bool profile_checkcasts() { return _compilation->profile_checkcasts(); }388bool profile_parameters() { return _compilation->profile_parameters(); }389bool profile_arguments() { return _compilation->profile_arguments(); }390bool profile_return() { return _compilation->profile_return(); }391392Values* args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver);393Values* collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver);394void check_args_for_profiling(Values* obj_args, int expected);395396public:397NOT_PRODUCT(void print_stats();)398399// initialization400static void initialize();401402// public403static bool can_trap(ciMethod* method, Bytecodes::Code code) {404assert(0 <= code && code < Bytecodes::number_of_java_codes, "illegal bytecode");405if (_can_trap[code]) return true;406// special handling for finalizer registration407return code == Bytecodes::_return && method->intrinsic_id() == vmIntrinsics::_Object_init;408}409410// creation411GraphBuilder(Compilation* compilation, IRScope* scope);412static void sort_top_into_worklist(BlockList* worklist, BlockBegin* top);413414BlockBegin* start() const { return _start; }415};416417#endif // SHARE_VM_C1_C1_GRAPHBUILDER_HPP418419420