Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_IR.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_IR_HPP25#define SHARE_VM_C1_C1_IR_HPP2627#include "c1/c1_Instruction.hpp"28#include "ci/ciExceptionHandler.hpp"29#include "ci/ciMethod.hpp"30#include "ci/ciStreams.hpp"31#include "memory/allocation.hpp"3233// An XHandler is a C1 internal description for an exception handler3435class XHandler: public CompilationResourceObj {36private:37ciExceptionHandler* _desc;3839BlockBegin* _entry_block; // Entry block of xhandler40LIR_List* _entry_code; // LIR-operations that must be executed before jumping to entry_block41int _entry_pco; // pco where entry_code (or entry_block if no entry_code) starts42int _phi_operand; // For resolving of phi functions at begin of entry_block43int _scope_count; // for filling ExceptionRangeEntry::scope_count4445#ifdef ASSERT46int _lir_op_id; // op_id of the LIR-operation throwing to this handler47#endif4849public:50// creation51XHandler(ciExceptionHandler* desc)52: _desc(desc)53, _entry_block(NULL)54, _entry_code(NULL)55, _entry_pco(-1)56, _phi_operand(-1)57, _scope_count(-1)58#ifdef ASSERT59, _lir_op_id(-1)60#endif61{ }6263XHandler(XHandler* other)64: _desc(other->_desc)65, _entry_block(other->_entry_block)66, _entry_code(other->_entry_code)67, _entry_pco(other->_entry_pco)68, _phi_operand(other->_phi_operand)69, _scope_count(other->_scope_count)70#ifdef ASSERT71, _lir_op_id(other->_lir_op_id)72#endif73{ }7475// accessors for data of ciExceptionHandler76int beg_bci() const { return _desc->start(); }77int end_bci() const { return _desc->limit(); }78int handler_bci() const { return _desc->handler_bci(); }79bool is_catch_all() const { return _desc->is_catch_all(); }80int catch_type() const { return _desc->catch_klass_index(); }81ciInstanceKlass* catch_klass() const { return _desc->catch_klass(); }82bool covers(int bci) const { return beg_bci() <= bci && bci < end_bci(); }8384// accessors for additional fields85BlockBegin* entry_block() const { return _entry_block; }86LIR_List* entry_code() const { return _entry_code; }87int entry_pco() const { return _entry_pco; }88int phi_operand() const { assert(_phi_operand != -1, "not set"); return _phi_operand; }89int scope_count() const { assert(_scope_count != -1, "not set"); return _scope_count; }90DEBUG_ONLY(int lir_op_id() const { return _lir_op_id; });9192void set_entry_block(BlockBegin* entry_block) {93assert(entry_block->is_set(BlockBegin::exception_entry_flag), "must be an exception handler entry");94assert(entry_block->bci() == handler_bci(), "bci's must correspond");95_entry_block = entry_block;96}97void set_entry_code(LIR_List* entry_code) { _entry_code = entry_code; }98void set_entry_pco(int entry_pco) { _entry_pco = entry_pco; }99void set_phi_operand(int phi_operand) { _phi_operand = phi_operand; }100void set_scope_count(int scope_count) { _scope_count = scope_count; }101DEBUG_ONLY(void set_lir_op_id(int lir_op_id) { _lir_op_id = lir_op_id; });102103bool equals(XHandler* other) const;104};105106define_array(_XHandlerArray, XHandler*)107define_stack(_XHandlerList, _XHandlerArray)108109110// XHandlers is the C1 internal list of exception handlers for a method111class XHandlers: public CompilationResourceObj {112private:113_XHandlerList _list;114115public:116// creation117XHandlers() : _list() { }118XHandlers(ciMethod* method);119XHandlers(XHandlers* other);120121// accessors122int length() const { return _list.length(); }123XHandler* handler_at(int i) const { return _list.at(i); }124bool has_handlers() const { return _list.length() > 0; }125void append(XHandler* h) { _list.append(h); }126XHandler* remove_last() { return _list.pop(); }127128bool could_catch(ciInstanceKlass* klass, bool type_is_exact) const;129bool equals(XHandlers* others) const;130};131132133class IRScope;134define_array(IRScopeArray, IRScope*)135define_stack(IRScopeList, IRScopeArray)136137class Compilation;138class IRScope: public CompilationResourceObj {139private:140// hierarchy141Compilation* _compilation; // the current compilation142IRScope* _caller; // the caller scope, or NULL143int _level; // the inlining level144ciMethod* _method; // the corresponding method145IRScopeList _callees; // the inlined method scopes146147// graph148XHandlers* _xhandlers; // the exception handlers149int _number_of_locks; // the number of monitor lock slots needed150bool _monitor_pairing_ok; // the monitor pairing info151bool _wrote_final; // has written final field152BlockBegin* _start; // the start block, successsors are method entries153154BitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable155156// helper functions157BlockBegin* build_graph(Compilation* compilation, int osr_bci);158159public:160// creation161IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph = false);162163// accessors164Compilation* compilation() const { return _compilation; }165IRScope* caller() const { return _caller; }166int level() const { return _level; }167ciMethod* method() const { return _method; }168int max_stack() const; // NOTE: expensive169BitMap& requires_phi_function() { return _requires_phi_function; }170171// hierarchy172bool is_top_scope() const { return _caller == NULL; }173void add_callee(IRScope* callee) { _callees.append(callee); }174int number_of_callees() const { return _callees.length(); }175IRScope* callee_no(int i) const { return _callees.at(i); }176177// accessors, graph178bool is_valid() const { return start() != NULL; }179XHandlers* xhandlers() const { return _xhandlers; }180int number_of_locks() const { return _number_of_locks; }181void set_min_number_of_locks(int n) { if (n > _number_of_locks) _number_of_locks = n; }182bool monitor_pairing_ok() const { return _monitor_pairing_ok; }183BlockBegin* start() const { return _start; }184void set_wrote_final() { _wrote_final = true; }185bool wrote_final () const { return _wrote_final; }186};187188189//190// IRScopeDebugInfo records the debug information for a particular IRScope191// in a particular CodeEmitInfo. This allows the information to be computed192// once early enough for the OopMap to be available to the LIR and also to be193// reemited for different pcs using the same CodeEmitInfo without recomputing194// everything.195//196197class IRScopeDebugInfo: public CompilationResourceObj {198private:199IRScope* _scope;200int _bci;201GrowableArray<ScopeValue*>* _locals;202GrowableArray<ScopeValue*>* _expressions;203GrowableArray<MonitorValue*>* _monitors;204IRScopeDebugInfo* _caller;205206public:207IRScopeDebugInfo(IRScope* scope,208int bci,209GrowableArray<ScopeValue*>* locals,210GrowableArray<ScopeValue*>* expressions,211GrowableArray<MonitorValue*>* monitors,212IRScopeDebugInfo* caller):213_scope(scope)214, _locals(locals)215, _bci(bci)216, _expressions(expressions)217, _monitors(monitors)218, _caller(caller) {}219220221IRScope* scope() { return _scope; }222int bci() { return _bci; }223GrowableArray<ScopeValue*>* locals() { return _locals; }224GrowableArray<ScopeValue*>* expressions() { return _expressions; }225GrowableArray<MonitorValue*>* monitors() { return _monitors; }226IRScopeDebugInfo* caller() { return _caller; }227228//Whether we should reexecute this bytecode for deopt229bool should_reexecute();230231void record_debug_info(DebugInformationRecorder* recorder, int pc_offset, bool topmost, bool is_method_handle_invoke = false) {232if (caller() != NULL) {233// Order is significant: Must record caller first.234caller()->record_debug_info(recorder, pc_offset, false/*topmost*/);235}236DebugToken* locvals = recorder->create_scope_values(locals());237DebugToken* expvals = recorder->create_scope_values(expressions());238DebugToken* monvals = recorder->create_monitor_values(monitors());239// reexecute allowed only for the topmost frame240bool reexecute = topmost ? should_reexecute() : false;241bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis.242recorder->describe_scope(pc_offset, scope()->method(), bci(), reexecute, is_method_handle_invoke, return_oop, locvals, expvals, monvals);243}244};245246247class CodeEmitInfo: public CompilationResourceObj {248friend class LinearScan;249private:250IRScopeDebugInfo* _scope_debug_info;251IRScope* _scope;252XHandlers* _exception_handlers;253OopMap* _oop_map;254ValueStack* _stack; // used by deoptimization (contains also monitors255bool _is_method_handle_invoke; // true if the associated call site is a MethodHandle call site.256bool _deoptimize_on_exception;257258FrameMap* frame_map() const { return scope()->compilation()->frame_map(); }259Compilation* compilation() const { return scope()->compilation(); }260261public:262263// use scope from ValueStack264CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers, bool deoptimize_on_exception = false);265266// make a copy267CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack = NULL);268269// accessors270OopMap* oop_map() { return _oop_map; }271ciMethod* method() const { return _scope->method(); }272IRScope* scope() const { return _scope; }273XHandlers* exception_handlers() const { return _exception_handlers; }274ValueStack* stack() const { return _stack; }275bool deoptimize_on_exception() const { return _deoptimize_on_exception; }276277void add_register_oop(LIR_Opr opr);278void record_debug_info(DebugInformationRecorder* recorder, int pc_offset);279280bool is_method_handle_invoke() const { return _is_method_handle_invoke; }281void set_is_method_handle_invoke(bool x) { _is_method_handle_invoke = x; }282283int interpreter_frame_size() const;284};285286287class IR: public CompilationResourceObj {288private:289Compilation* _compilation; // the current compilation290IRScope* _top_scope; // the root of the scope hierarchy291WordSize _locals_size; // the space required for all locals292int _num_loops; // Total number of loops293BlockList* _code; // the blocks in code generation order w/ use counts294295public:296// creation297IR(Compilation* compilation, ciMethod* method, int osr_bci);298299// accessors300bool is_valid() const { return top_scope()->is_valid(); }301Compilation* compilation() const { return _compilation; }302IRScope* top_scope() const { return _top_scope; }303int number_of_locks() const { return top_scope()->number_of_locks(); }304ciMethod* method() const { return top_scope()->method(); }305BlockBegin* start() const { return top_scope()->start(); }306BlockBegin* std_entry() const { return start()->end()->as_Base()->std_entry(); }307BlockBegin* osr_entry() const { return start()->end()->as_Base()->osr_entry(); }308WordSize locals_size() const { return _locals_size; }309int locals_size_in_words() const { return in_words(_locals_size); }310BlockList* code() const { return _code; }311int num_loops() const { return _num_loops; }312int max_stack() const { return top_scope()->max_stack(); } // expensive313314// ir manipulation315void optimize_blocks();316void eliminate_null_checks();317void compute_predecessors();318void split_critical_edges();319void compute_code();320void compute_use_counts();321322// The linear-scan order and the code emission order are equal, but323// this may change in future324BlockList* linear_scan_order() { assert(_code != NULL, "not computed"); return _code; }325326// iteration327void iterate_preorder (BlockClosure* closure);328void iterate_postorder (BlockClosure* closure);329void iterate_linear_scan_order(BlockClosure* closure);330331// debugging332static void print(BlockBegin* start, bool cfg_only, bool live_only = false) PRODUCT_RETURN;333void print(bool cfg_only, bool live_only = false) PRODUCT_RETURN;334void verify() PRODUCT_RETURN;335};336337338// Globally do instruction substitution and remove substituted339// instructions from the instruction list.340//341342class SubstitutionResolver: public BlockClosure, ValueVisitor {343virtual void visit(Value* v);344345public:346SubstitutionResolver(IR* hir) {347hir->iterate_preorder(this);348}349350SubstitutionResolver(BlockBegin* block) {351block->iterate_preorder(this);352}353354virtual void block_do(BlockBegin* block);355};356357#endif // SHARE_VM_C1_C1_IR_HPP358359360