/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
class BytecodeParseHistogram; class InlineTree; class Parse; class SwitchRange;
//------------------------------InlineTree------------------------------------- class InlineTree : public AnyObj { friendclass VMStructs;
Compile* C; // cache
JVMState* _caller_jvms; // state of caller
ciMethod* _method; // method being called by the caller_jvms bool _late_inline; // method is inlined incrementally
InlineTree* _caller_tree;
uint _count_inline_bcs; // Accumulated count of inlined bytecodes constint _max_inline_level; // the maximum inline level for this sub-tree (may be adjusted)
GrowableArray<InlineTree*> _subtrees;
bool pass_initial_checks(ciMethod* caller_method, int caller_bci, ciMethod* callee_method);
void print_impl(outputStream* stj, int indent) const PRODUCT_RETURN; constchar* _msg; protected:
InlineTree(Compile* C, const InlineTree* caller_tree,
ciMethod* callee_method,
JVMState* caller_jvms, int caller_bci, int max_inline_level);
InlineTree *build_inline_tree_for_callee(ciMethod* callee_method,
JVMState* caller_jvms, int caller_bci); bool try_to_inline(ciMethod* callee_method,
ciMethod* caller_method, int caller_bci,
JVMState* jvms,
ciCallProfile& profile, bool& should_delay); bool should_inline(ciMethod* callee_method,
ciMethod* caller_method, int caller_bci,
NOT_PRODUCT_ARG(bool& should_delay)
ciCallProfile& profile); bool should_not_inline(ciMethod* callee_method,
ciMethod* caller_method, int caller_bci,
NOT_PRODUCT_ARG(bool& should_delay)
ciCallProfile& profile); bool is_not_reached(ciMethod* callee_method,
ciMethod* caller_method, int caller_bci,
ciCallProfile& profile); void print_inlining(ciMethod* callee_method, int caller_bci,
ciMethod* caller_method, bool success) const;
// See if it is OK to inline. // The receiver is the inline tree for the caller. // // The result is a temperature indication. If it is hot or cold, // inlining is immediate or undesirable. Otherwise, the info block // returned is newly allocated and may be enqueued. // // If the method is inlinable, a new inline subtree is created on the fly, // and may be accessed by find_subtree_from_root. // The call_method is the dest_method for a special or static invocation. // The call_method is an optimized virtual method candidate otherwise. bool ok_to_inline(ciMethod *call_method, JVMState* caller_jvms, ciCallProfile& profile, bool& should_delay);
bool _forced_inline; // Inlining was forced by CompilerOracle, ciReplay or annotation bool forced_inline() const { return _forced_inline; } // Count number of nodes in this subtree int count() const; // Dump inlining replay data to the stream. void dump_replay_data(outputStream* out, int depth_adjust = 0);
};
//----------------------------------------------------------------------------- //------------------------------Parse------------------------------------------ // Parse bytecodes, build a Graph class Parse : public GraphKit { public: // Per-block information needed by the parser: class Block { private:
ciTypeFlow::Block* _flow; int _pred_count; // how many predecessors in CFG? int _preds_parsed; // how many of these have been parsed?
uint _count; // how many times executed? Currently only set by _goto's bool _is_parsed; // has this block been parsed yet? bool _is_handler; // is this block an exception handler? bool _has_merged_backedge; // does this block have merged backedge?
SafePointNode* _start_map; // all values flowing into this block
MethodLivenessResult _live_locals; // lazily initialized liveness bitmap bool _has_predicates; // Were predicates added before parsing of the loop head?
int _num_successors; // Includes only normal control flow. int _all_successors; // Include exception paths also.
Block** _successors;
public:
// Set up the block data structure itself.
Block(Parse* outer, int rpo);
// Set up the block's relations to other blocks. void init_graph(Parse* outer);
// Call this just before parsing a block. void mark_parsed() {
assert(!_is_parsed, "must parse each block exactly once");
_is_parsed = true;
}
// Return the phi/region input index for the "current" pred, // and bump the pred number. For historical reasons these index // numbers are handed out in descending order. The last index is // always PhiNode::Input (i.e., 1). The value returned is known // as a "path number" because it distinguishes by which path we are // entering the block. int next_path_num() {
assert(preds_parsed() < pred_count(), "too many preds?"); return pred_count() - _preds_parsed++;
}
// Add a previously unaccounted predecessor to this block. // This operates by increasing the size of the block's region // and all its phi nodes (if any). The value returned is a // path number ("pnum"). int add_new_path();
// Initialize me by recording the parser's map. My own map must be NULL. void record_state(Parse* outer);
};
#ifndef PRODUCT // BytecodeParseHistogram collects number of bytecodes parsed, nodes constructed, and transformations. class BytecodeParseHistogram : public ArenaObj { private: enum BPHType {
BPH_transforms,
BPH_values
}; staticbool _initialized; static uint _bytecodes_parsed [Bytecodes::number_of_codes]; static uint _nodes_constructed[Bytecodes::number_of_codes]; static uint _nodes_transformed[Bytecodes::number_of_codes]; static uint _new_values [Bytecodes::number_of_codes];
Bytecodes::Code _initial_bytecode; int _initial_node_count; int _initial_transforms; int _initial_values;
Parse *_parser;
Compile *_compiler;
// Initialization staticvoid reset();
// Return info being collected, select with global flag 'BytecodeParseInfo' int current_count(BPHType info_selector);
// Record info when starting to parse one bytecode void set_initial_state( Bytecodes::Code bc ); // Record results of parsing one bytecode void record_change();
public: // Record work done during parsing
BytecodeParseHistogram* _parse_histogram; void set_parse_histogram(BytecodeParseHistogram *bph) { _parse_histogram = bph; }
BytecodeParseHistogram* parse_histogram() { return _parse_histogram; } #endif
private: friendclass Block;
// Variables which characterize this compilation as a whole:
JVMState* _caller; // JVMS which carries incoming args & state. float _expected_uses; // expected number of calls to this code float _prof_factor; // discount applied to my profile counts int _depth; // Inline tree depth, for debug printouts const TypeFunc*_tf; // My kind of function type int _entry_bci; // the osr bci or InvocationEntryBci
ciTypeFlow* _flow; // Results of previous flow pass.
Block* _blocks; // Array of basic-block structs. int _block_count; // Number of elements in _blocks.
GraphKit _exits; // Record all normal returns and throws here. bool _wrote_final; // Did we write a final field? bool _wrote_volatile; // Did we write a volatile field? bool _wrote_stable; // Did we write a @Stable field? bool _wrote_fields; // Did we write any field?
Node* _alloc_with_final; // An allocation node with final field
// Variables which track Java semantics during bytecode parsing:
Block* _block; // block currently getting parsed
ciBytecodeStream _iter; // stream of this method's bytecodes
const FastLockNode* _synch_lock; // FastLockNode for synchronized method
#ifndef PRODUCT int _max_switch_depth; // Debugging SwitchRanges. int _est_switch_depth; // Debugging SwitchRanges. #endif
bool _first_return; // true if return is the first to be parsed bool _replaced_nodes_for_exceptions; // needs processing of replaced nodes in exception paths?
uint _new_idx; // any node with _idx above were new during this parsing. Used to trim the replaced nodes list.
// Functions for managing basic blocks: void init_blocks(); void load_state_from(Block* b); void store_state_to(Block* b) { b->record_state(this); }
// Parse all the basic blocks. void do_all_blocks();
// Parse the current basic block void do_one_block();
// Raise an error if we get a bad ciTypeFlow CFG. void handle_missing_successor(int bci);
// first actions (before BCI 0) void do_method_entry();
// implementation of monitorenter/monitorexit void do_monitor_enter(); void do_monitor_exit();
// Eagerly create phie throughout the state, to cope with back edges. void ensure_phis_everywhere();
// Merge the current mapping into the basic block starting at bci void merge( int target_bci); // Same as plain merge, except that it allocates a new path number. void merge_new_path( int target_bci); // Merge the current mapping into an exception handler. void merge_exception(int target_bci); // Helper: Merge the current mapping into the given basic block void merge_common(Block* target, int pnum); // Helper functions for merging individual cells.
PhiNode *ensure_phi( int idx, bool nocreate = false);
PhiNode *ensure_memory_phi(int idx, bool nocreate = false); // Helper to merge the current memory state into the given basic block void merge_memory_edges(MergeMemNode* n, int pnum, bool nophi);
// Parse this bytecode, and alter the Parsers JVM->Node mapping void do_one_bytecode();
// helper function to generate array store check void array_store_check(); // Helper function to generate array load void array_load(BasicType etype); // Helper function to generate array store void array_store(BasicType etype); // Helper function to compute array addressing
Node* array_addressing(BasicType type, int vals, const Type*& elemtype);
void clinit_deopt();
void rtm_deopt();
// Pass current map to exits void return_current(Node* value);
// Register finalizers on return from Object.<init> void call_register_finalizer();
// Insert a compiler safepoint into the graph void add_safepoint();
// Insert a compiler safepoint into the graph, if there is a back-branch. void maybe_add_safepoint(int target_bci) { if (target_bci <= bci()) {
add_safepoint();
}
}
// Note: Intrinsic generation routines may be found in library_call.cpp.
// Helper function to setup Ideal Call nodes void do_call();
// Helper function to uncommon-trap or bailout for non-compilable call-sites bool can_not_compile_call_site(ciMethod *dest_method, ciInstanceKlass *klass);
// Helper functions for type checking bytecodes: void do_checkcast(); void do_instanceof();
// common code for making initial checks and forming addresses void do_field_access(bool is_get, bool is_field);
// common code for actually performing the load or store void do_get_xxx(Node* obj, ciField* field, bool is_field); void do_put_xxx(Node* obj, ciField* field, bool is_field);
// implementation of object creation bytecodes void do_new(); void do_newarray(BasicType elemtype); void do_anewarray(); void do_multianewarray();
Node* expand_multianewarray(ciArrayKlass* array_klass, Node* *lengths, int ndimensions, int nargs);
// implementation of jsr/ret void do_jsr(); void do_ret();
// Helper functions for handling normal and abnormal exits. void build_exits();
// Fix up all exceptional control flow exiting a single bytecode. void do_exceptions();
// Fix up all exiting control flow at the end of the parse. void do_exits();
// Add Catch/CatchProjs // The call is either a Java call or the VM's rethrow stub void catch_call_exceptions(ciExceptionHandlerStream&);
// Handle all exceptions thrown by the inlined method. // Also handles exceptions for individual bytecodes. void catch_inline_exceptions(SafePointNode* ex_map);
// Merge the given map into correct exceptional exit state. // Assumes that there is no applicable local handler. void throw_to_exit(SafePointNode* ex_map);
// Use speculative type to optimize CmpP node
Node* optimize_cmp_with_klass(Node* c);
// Specialized uncommon_trap of unstable_if. C2 uses next_bci of path to update the live locals of it. class UnstableIfTrap {
CallStaticJavaNode* const _unc; bool _modified; // modified locals based on next_bci() int _next_bci;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.