Path: blob/master/src/hotspot/share/opto/compile.cpp
40930 views
/*1* Copyright (c) 1997, 2021, 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#include "precompiled.hpp"25#include "jvm_io.h"26#include "asm/macroAssembler.hpp"27#include "asm/macroAssembler.inline.hpp"28#include "ci/ciReplay.hpp"29#include "classfile/javaClasses.hpp"30#include "code/exceptionHandlerTable.hpp"31#include "code/nmethod.hpp"32#include "compiler/compileBroker.hpp"33#include "compiler/compileLog.hpp"34#include "compiler/disassembler.hpp"35#include "compiler/oopMap.hpp"36#include "gc/shared/barrierSet.hpp"37#include "gc/shared/c2/barrierSetC2.hpp"38#include "jfr/jfrEvents.hpp"39#include "memory/resourceArea.hpp"40#include "opto/addnode.hpp"41#include "opto/block.hpp"42#include "opto/c2compiler.hpp"43#include "opto/callGenerator.hpp"44#include "opto/callnode.hpp"45#include "opto/castnode.hpp"46#include "opto/cfgnode.hpp"47#include "opto/chaitin.hpp"48#include "opto/compile.hpp"49#include "opto/connode.hpp"50#include "opto/convertnode.hpp"51#include "opto/divnode.hpp"52#include "opto/escape.hpp"53#include "opto/idealGraphPrinter.hpp"54#include "opto/loopnode.hpp"55#include "opto/machnode.hpp"56#include "opto/macro.hpp"57#include "opto/matcher.hpp"58#include "opto/mathexactnode.hpp"59#include "opto/memnode.hpp"60#include "opto/mulnode.hpp"61#include "opto/narrowptrnode.hpp"62#include "opto/node.hpp"63#include "opto/opcodes.hpp"64#include "opto/output.hpp"65#include "opto/parse.hpp"66#include "opto/phaseX.hpp"67#include "opto/rootnode.hpp"68#include "opto/runtime.hpp"69#include "opto/stringopts.hpp"70#include "opto/type.hpp"71#include "opto/vector.hpp"72#include "opto/vectornode.hpp"73#include "runtime/globals_extension.hpp"74#include "runtime/sharedRuntime.hpp"75#include "runtime/signature.hpp"76#include "runtime/stubRoutines.hpp"77#include "runtime/timer.hpp"78#include "utilities/align.hpp"79#include "utilities/copy.hpp"80#include "utilities/macros.hpp"81#include "utilities/resourceHash.hpp"828384// -------------------- Compile::mach_constant_base_node -----------------------85// Constant table base node singleton.86MachConstantBaseNode* Compile::mach_constant_base_node() {87if (_mach_constant_base_node == NULL) {88_mach_constant_base_node = new MachConstantBaseNode();89_mach_constant_base_node->add_req(C->root());90}91return _mach_constant_base_node;92}939495/// Support for intrinsics.9697// Return the index at which m must be inserted (or already exists).98// The sort order is by the address of the ciMethod, with is_virtual as minor key.99class IntrinsicDescPair {100private:101ciMethod* _m;102bool _is_virtual;103public:104IntrinsicDescPair(ciMethod* m, bool is_virtual) : _m(m), _is_virtual(is_virtual) {}105static int compare(IntrinsicDescPair* const& key, CallGenerator* const& elt) {106ciMethod* m= elt->method();107ciMethod* key_m = key->_m;108if (key_m < m) return -1;109else if (key_m > m) return 1;110else {111bool is_virtual = elt->is_virtual();112bool key_virtual = key->_is_virtual;113if (key_virtual < is_virtual) return -1;114else if (key_virtual > is_virtual) return 1;115else return 0;116}117}118};119int Compile::intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found) {120#ifdef ASSERT121for (int i = 1; i < _intrinsics.length(); i++) {122CallGenerator* cg1 = _intrinsics.at(i-1);123CallGenerator* cg2 = _intrinsics.at(i);124assert(cg1->method() != cg2->method()125? cg1->method() < cg2->method()126: cg1->is_virtual() < cg2->is_virtual(),127"compiler intrinsics list must stay sorted");128}129#endif130IntrinsicDescPair pair(m, is_virtual);131return _intrinsics.find_sorted<IntrinsicDescPair*, IntrinsicDescPair::compare>(&pair, found);132}133134void Compile::register_intrinsic(CallGenerator* cg) {135bool found = false;136int index = intrinsic_insertion_index(cg->method(), cg->is_virtual(), found);137assert(!found, "registering twice");138_intrinsics.insert_before(index, cg);139assert(find_intrinsic(cg->method(), cg->is_virtual()) == cg, "registration worked");140}141142CallGenerator* Compile::find_intrinsic(ciMethod* m, bool is_virtual) {143assert(m->is_loaded(), "don't try this on unloaded methods");144if (_intrinsics.length() > 0) {145bool found = false;146int index = intrinsic_insertion_index(m, is_virtual, found);147if (found) {148return _intrinsics.at(index);149}150}151// Lazily create intrinsics for intrinsic IDs well-known in the runtime.152if (m->intrinsic_id() != vmIntrinsics::_none &&153m->intrinsic_id() <= vmIntrinsics::LAST_COMPILER_INLINE) {154CallGenerator* cg = make_vm_intrinsic(m, is_virtual);155if (cg != NULL) {156// Save it for next time:157register_intrinsic(cg);158return cg;159} else {160gather_intrinsic_statistics(m->intrinsic_id(), is_virtual, _intrinsic_disabled);161}162}163return NULL;164}165166// Compile::make_vm_intrinsic is defined in library_call.cpp.167168#ifndef PRODUCT169// statistics gathering...170171juint Compile::_intrinsic_hist_count[vmIntrinsics::number_of_intrinsics()] = {0};172jubyte Compile::_intrinsic_hist_flags[vmIntrinsics::number_of_intrinsics()] = {0};173174inline int as_int(vmIntrinsics::ID id) {175return vmIntrinsics::as_int(id);176}177178bool Compile::gather_intrinsic_statistics(vmIntrinsics::ID id, bool is_virtual, int flags) {179assert(id > vmIntrinsics::_none && id < vmIntrinsics::ID_LIMIT, "oob");180int oflags = _intrinsic_hist_flags[as_int(id)];181assert(flags != 0, "what happened?");182if (is_virtual) {183flags |= _intrinsic_virtual;184}185bool changed = (flags != oflags);186if ((flags & _intrinsic_worked) != 0) {187juint count = (_intrinsic_hist_count[as_int(id)] += 1);188if (count == 1) {189changed = true; // first time190}191// increment the overall count also:192_intrinsic_hist_count[as_int(vmIntrinsics::_none)] += 1;193}194if (changed) {195if (((oflags ^ flags) & _intrinsic_virtual) != 0) {196// Something changed about the intrinsic's virtuality.197if ((flags & _intrinsic_virtual) != 0) {198// This is the first use of this intrinsic as a virtual call.199if (oflags != 0) {200// We already saw it as a non-virtual, so note both cases.201flags |= _intrinsic_both;202}203} else if ((oflags & _intrinsic_both) == 0) {204// This is the first use of this intrinsic as a non-virtual205flags |= _intrinsic_both;206}207}208_intrinsic_hist_flags[as_int(id)] = (jubyte) (oflags | flags);209}210// update the overall flags also:211_intrinsic_hist_flags[as_int(vmIntrinsics::_none)] |= (jubyte) flags;212return changed;213}214215static char* format_flags(int flags, char* buf) {216buf[0] = 0;217if ((flags & Compile::_intrinsic_worked) != 0) strcat(buf, ",worked");218if ((flags & Compile::_intrinsic_failed) != 0) strcat(buf, ",failed");219if ((flags & Compile::_intrinsic_disabled) != 0) strcat(buf, ",disabled");220if ((flags & Compile::_intrinsic_virtual) != 0) strcat(buf, ",virtual");221if ((flags & Compile::_intrinsic_both) != 0) strcat(buf, ",nonvirtual");222if (buf[0] == 0) strcat(buf, ",");223assert(buf[0] == ',', "must be");224return &buf[1];225}226227void Compile::print_intrinsic_statistics() {228char flagsbuf[100];229ttyLocker ttyl;230if (xtty != NULL) xtty->head("statistics type='intrinsic'");231tty->print_cr("Compiler intrinsic usage:");232juint total = _intrinsic_hist_count[as_int(vmIntrinsics::_none)];233if (total == 0) total = 1; // avoid div0 in case of no successes234#define PRINT_STAT_LINE(name, c, f) \235tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(c), ((c) * 100.0) / total, name, f);236for (auto id : EnumRange<vmIntrinsicID>{}) {237int flags = _intrinsic_hist_flags[as_int(id)];238juint count = _intrinsic_hist_count[as_int(id)];239if ((flags | count) != 0) {240PRINT_STAT_LINE(vmIntrinsics::name_at(id), count, format_flags(flags, flagsbuf));241}242}243PRINT_STAT_LINE("total", total, format_flags(_intrinsic_hist_flags[as_int(vmIntrinsics::_none)], flagsbuf));244if (xtty != NULL) xtty->tail("statistics");245}246247void Compile::print_statistics() {248{ ttyLocker ttyl;249if (xtty != NULL) xtty->head("statistics type='opto'");250Parse::print_statistics();251PhaseCCP::print_statistics();252PhaseRegAlloc::print_statistics();253PhaseOutput::print_statistics();254PhasePeephole::print_statistics();255PhaseIdealLoop::print_statistics();256if (xtty != NULL) xtty->tail("statistics");257}258if (_intrinsic_hist_flags[as_int(vmIntrinsics::_none)] != 0) {259// put this under its own <statistics> element.260print_intrinsic_statistics();261}262}263#endif //PRODUCT264265void Compile::gvn_replace_by(Node* n, Node* nn) {266for (DUIterator_Last imin, i = n->last_outs(imin); i >= imin; ) {267Node* use = n->last_out(i);268bool is_in_table = initial_gvn()->hash_delete(use);269uint uses_found = 0;270for (uint j = 0; j < use->len(); j++) {271if (use->in(j) == n) {272if (j < use->req())273use->set_req(j, nn);274else275use->set_prec(j, nn);276uses_found++;277}278}279if (is_in_table) {280// reinsert into table281initial_gvn()->hash_find_insert(use);282}283record_for_igvn(use);284i -= uses_found; // we deleted 1 or more copies of this edge285}286}287288289// Identify all nodes that are reachable from below, useful.290// Use breadth-first pass that records state in a Unique_Node_List,291// recursive traversal is slower.292void Compile::identify_useful_nodes(Unique_Node_List &useful) {293int estimated_worklist_size = live_nodes();294useful.map( estimated_worklist_size, NULL ); // preallocate space295296// Initialize worklist297if (root() != NULL) { useful.push(root()); }298// If 'top' is cached, declare it useful to preserve cached node299if( cached_top_node() ) { useful.push(cached_top_node()); }300301// Push all useful nodes onto the list, breadthfirst302for( uint next = 0; next < useful.size(); ++next ) {303assert( next < unique(), "Unique useful nodes < total nodes");304Node *n = useful.at(next);305uint max = n->len();306for( uint i = 0; i < max; ++i ) {307Node *m = n->in(i);308if (not_a_node(m)) continue;309useful.push(m);310}311}312}313314// Update dead_node_list with any missing dead nodes using useful315// list. Consider all non-useful nodes to be useless i.e., dead nodes.316void Compile::update_dead_node_list(Unique_Node_List &useful) {317uint max_idx = unique();318VectorSet& useful_node_set = useful.member_set();319320for (uint node_idx = 0; node_idx < max_idx; node_idx++) {321// If node with index node_idx is not in useful set,322// mark it as dead in dead node list.323if (!useful_node_set.test(node_idx)) {324record_dead_node(node_idx);325}326}327}328329void Compile::remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Unique_Node_List &useful) {330int shift = 0;331for (int i = 0; i < inlines->length(); i++) {332CallGenerator* cg = inlines->at(i);333if (useful.member(cg->call_node())) {334if (shift > 0) {335inlines->at_put(i - shift, cg);336}337} else {338shift++; // skip over the dead element339}340}341if (shift > 0) {342inlines->trunc_to(inlines->length() - shift); // remove last elements from compacted array343}344}345346void Compile::remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Node* dead) {347assert(dead != NULL && dead->is_Call(), "sanity");348int found = 0;349for (int i = 0; i < inlines->length(); i++) {350if (inlines->at(i)->call_node() == dead) {351inlines->remove_at(i);352found++;353NOT_DEBUG( break; ) // elements are unique, so exit early354}355}356assert(found <= 1, "not unique");357}358359void Compile::remove_useless_nodes(GrowableArray<Node*>& node_list, Unique_Node_List& useful) {360for (int i = node_list.length() - 1; i >= 0; i--) {361Node* n = node_list.at(i);362if (!useful.member(n)) {363node_list.delete_at(i); // replaces i-th with last element which is known to be useful (already processed)364}365}366}367368void Compile::remove_useless_node(Node* dead) {369remove_modified_node(dead);370371// Constant node that has no out-edges and has only one in-edge from372// root is usually dead. However, sometimes reshaping walk makes373// it reachable by adding use edges. So, we will NOT count Con nodes374// as dead to be conservative about the dead node count at any375// given time.376if (!dead->is_Con()) {377record_dead_node(dead->_idx);378}379if (dead->is_macro()) {380remove_macro_node(dead);381}382if (dead->is_expensive()) {383remove_expensive_node(dead);384}385if (dead->Opcode() == Op_Opaque4) {386remove_skeleton_predicate_opaq(dead);387}388if (dead->for_post_loop_opts_igvn()) {389remove_from_post_loop_opts_igvn(dead);390}391if (dead->is_Call()) {392remove_useless_late_inlines( &_late_inlines, dead);393remove_useless_late_inlines( &_string_late_inlines, dead);394remove_useless_late_inlines( &_boxing_late_inlines, dead);395remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);396}397BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();398bs->unregister_potential_barrier_node(dead);399}400401// Disconnect all useless nodes by disconnecting those at the boundary.402void Compile::remove_useless_nodes(Unique_Node_List &useful) {403uint next = 0;404while (next < useful.size()) {405Node *n = useful.at(next++);406if (n->is_SafePoint()) {407// We're done with a parsing phase. Replaced nodes are not valid408// beyond that point.409n->as_SafePoint()->delete_replaced_nodes();410}411// Use raw traversal of out edges since this code removes out edges412int max = n->outcnt();413for (int j = 0; j < max; ++j) {414Node* child = n->raw_out(j);415if (!useful.member(child)) {416assert(!child->is_top() || child != top(),417"If top is cached in Compile object it is in useful list");418// Only need to remove this out-edge to the useless node419n->raw_del_out(j);420--j;421--max;422}423}424if (n->outcnt() == 1 && n->has_special_unique_user()) {425record_for_igvn(n->unique_out());426}427}428429remove_useless_nodes(_macro_nodes, useful); // remove useless macro nodes430remove_useless_nodes(_predicate_opaqs, useful); // remove useless predicate opaque nodes431remove_useless_nodes(_skeleton_predicate_opaqs, useful);432remove_useless_nodes(_expensive_nodes, useful); // remove useless expensive nodes433remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass434435BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();436bs->eliminate_useless_gc_barriers(useful, this);437// clean up the late inline lists438remove_useless_late_inlines( &_late_inlines, useful);439remove_useless_late_inlines( &_string_late_inlines, useful);440remove_useless_late_inlines( &_boxing_late_inlines, useful);441remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);442debug_only(verify_graph_edges(true/*check for no_dead_code*/);)443}444445// ============================================================================446//------------------------------CompileWrapper---------------------------------447class CompileWrapper : public StackObj {448Compile *const _compile;449public:450CompileWrapper(Compile* compile);451452~CompileWrapper();453};454455CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {456// the Compile* pointer is stored in the current ciEnv:457ciEnv* env = compile->env();458assert(env == ciEnv::current(), "must already be a ciEnv active");459assert(env->compiler_data() == NULL, "compile already active?");460env->set_compiler_data(compile);461assert(compile == Compile::current(), "sanity");462463compile->set_type_dict(NULL);464compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));465compile->clone_map().set_clone_idx(0);466compile->set_type_last_size(0);467compile->set_last_tf(NULL, NULL);468compile->set_indexSet_arena(NULL);469compile->set_indexSet_free_block_list(NULL);470compile->init_type_arena();471Type::Initialize(compile);472_compile->begin_method();473_compile->clone_map().set_debug(_compile->has_method() && _compile->directive()->CloneMapDebugOption);474}475CompileWrapper::~CompileWrapper() {476_compile->end_method();477_compile->env()->set_compiler_data(NULL);478}479480481//----------------------------print_compile_messages---------------------------482void Compile::print_compile_messages() {483#ifndef PRODUCT484// Check if recompiling485if (_subsume_loads == false && PrintOpto) {486// Recompiling without allowing machine instructions to subsume loads487tty->print_cr("*********************************************************");488tty->print_cr("** Bailout: Recompile without subsuming loads **");489tty->print_cr("*********************************************************");490}491if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {492// Recompiling without escape analysis493tty->print_cr("*********************************************************");494tty->print_cr("** Bailout: Recompile without escape analysis **");495tty->print_cr("*********************************************************");496}497if (_eliminate_boxing != EliminateAutoBox && PrintOpto) {498// Recompiling without boxing elimination499tty->print_cr("*********************************************************");500tty->print_cr("** Bailout: Recompile without boxing elimination **");501tty->print_cr("*********************************************************");502}503if (env()->break_at_compile()) {504// Open the debugger when compiling this method.505tty->print("### Breaking when compiling: ");506method()->print_short_name();507tty->cr();508BREAKPOINT;509}510511if( PrintOpto ) {512if (is_osr_compilation()) {513tty->print("[OSR]%3d", _compile_id);514} else {515tty->print("%3d", _compile_id);516}517}518#endif519}520521// ============================================================================522//------------------------------Compile standard-------------------------------523debug_only( int Compile::_debug_idx = 100000; )524525// Compile a method. entry_bci is -1 for normal compilations and indicates526// the continuation bci for on stack replacement.527528529Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,530bool subsume_loads, bool do_escape_analysis, bool eliminate_boxing, bool install_code, DirectiveSet* directive)531: Phase(Compiler),532_compile_id(ci_env->compile_id()),533_subsume_loads(subsume_loads),534_do_escape_analysis(do_escape_analysis),535_install_code(install_code),536_eliminate_boxing(eliminate_boxing),537_method(target),538_entry_bci(osr_bci),539_stub_function(NULL),540_stub_name(NULL),541_stub_entry_point(NULL),542_max_node_limit(MaxNodeLimit),543_post_loop_opts_phase(false),544_inlining_progress(false),545_inlining_incrementally(false),546_do_cleanup(false),547_has_reserved_stack_access(target->has_reserved_stack_access()),548#ifndef PRODUCT549_igv_idx(0),550_trace_opto_output(directive->TraceOptoOutputOption),551_print_ideal(directive->PrintIdealOption),552#endif553_has_method_handle_invokes(false),554_clinit_barrier_on_entry(false),555_stress_seed(0),556_comp_arena(mtCompiler),557_barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),558_env(ci_env),559_directive(directive),560_log(ci_env->log()),561_failure_reason(NULL),562_intrinsics (comp_arena(), 0, 0, NULL),563_macro_nodes (comp_arena(), 8, 0, NULL),564_predicate_opaqs (comp_arena(), 8, 0, NULL),565_skeleton_predicate_opaqs (comp_arena(), 8, 0, NULL),566_expensive_nodes (comp_arena(), 8, 0, NULL),567_for_post_loop_igvn(comp_arena(), 8, 0, NULL),568_congraph(NULL),569NOT_PRODUCT(_printer(NULL) COMMA)570_dead_node_list(comp_arena()),571_dead_node_count(0),572_node_arena(mtCompiler),573_old_arena(mtCompiler),574_mach_constant_base_node(NULL),575_Compile_types(mtCompiler),576_initial_gvn(NULL),577_for_igvn(NULL),578_late_inlines(comp_arena(), 2, 0, NULL),579_string_late_inlines(comp_arena(), 2, 0, NULL),580_boxing_late_inlines(comp_arena(), 2, 0, NULL),581_vector_reboxing_late_inlines(comp_arena(), 2, 0, NULL),582_late_inlines_pos(0),583_number_of_mh_late_inlines(0),584_native_invokers(comp_arena(), 1, 0, NULL),585_print_inlining_stream(NULL),586_print_inlining_list(NULL),587_print_inlining_idx(0),588_print_inlining_output(NULL),589_replay_inline_data(NULL),590_java_calls(0),591_inner_loops(0),592_interpreter_frame_size(0)593#ifndef PRODUCT594, _in_dump_cnt(0)595#endif596{597C = this;598CompileWrapper cw(this);599600if (CITimeVerbose) {601tty->print(" ");602target->holder()->name()->print();603tty->print(".");604target->print_short_name();605tty->print(" ");606}607TraceTime t1("Total compilation time", &_t_totalCompilation, CITime, CITimeVerbose);608TraceTime t2(NULL, &_t_methodCompilation, CITime, false);609610#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)611bool print_opto_assembly = directive->PrintOptoAssemblyOption;612// We can always print a disassembly, either abstract (hex dump) or613// with the help of a suitable hsdis library. Thus, we should not614// couple print_assembly and print_opto_assembly controls.615// But: always print opto and regular assembly on compile command 'print'.616bool print_assembly = directive->PrintAssemblyOption;617set_print_assembly(print_opto_assembly || print_assembly);618#else619set_print_assembly(false); // must initialize.620#endif621622#ifndef PRODUCT623set_parsed_irreducible_loop(false);624625if (directive->ReplayInlineOption) {626_replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());627}628#endif629set_print_inlining(directive->PrintInliningOption || PrintOptoInlining);630set_print_intrinsics(directive->PrintIntrinsicsOption);631set_has_irreducible_loop(true); // conservative until build_loop_tree() reset it632633if (ProfileTraps RTM_OPT_ONLY( || UseRTMLocking )) {634// Make sure the method being compiled gets its own MDO,635// so we can at least track the decompile_count().636// Need MDO to record RTM code generation state.637method()->ensure_method_data();638}639640Init(::AliasLevel);641642643print_compile_messages();644645_ilt = InlineTree::build_inline_tree_root();646647// Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice648assert(num_alias_types() >= AliasIdxRaw, "");649650#define MINIMUM_NODE_HASH 1023651// Node list that Iterative GVN will start with652Unique_Node_List for_igvn(comp_arena());653set_for_igvn(&for_igvn);654655// GVN that will be run immediately on new nodes656uint estimated_size = method()->code_size()*4+64;657estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);658PhaseGVN gvn(node_arena(), estimated_size);659set_initial_gvn(&gvn);660661print_inlining_init();662{ // Scope for timing the parser663TracePhase tp("parse", &timers[_t_parser]);664665// Put top into the hash table ASAP.666initial_gvn()->transform_no_reclaim(top());667668// Set up tf(), start(), and find a CallGenerator.669CallGenerator* cg = NULL;670if (is_osr_compilation()) {671const TypeTuple *domain = StartOSRNode::osr_domain();672const TypeTuple *range = TypeTuple::make_range(method()->signature());673init_tf(TypeFunc::make(domain, range));674StartNode* s = new StartOSRNode(root(), domain);675initial_gvn()->set_type_bottom(s);676init_start(s);677cg = CallGenerator::for_osr(method(), entry_bci());678} else {679// Normal case.680init_tf(TypeFunc::make(method()));681StartNode* s = new StartNode(root(), tf()->domain());682initial_gvn()->set_type_bottom(s);683init_start(s);684if (method()->intrinsic_id() == vmIntrinsics::_Reference_get) {685// With java.lang.ref.reference.get() we must go through the686// intrinsic - even when get() is the root687// method of the compile - so that, if necessary, the value in688// the referent field of the reference object gets recorded by689// the pre-barrier code.690cg = find_intrinsic(method(), false);691}692if (cg == NULL) {693float past_uses = method()->interpreter_invocation_count();694float expected_uses = past_uses;695cg = CallGenerator::for_inline(method(), expected_uses);696}697}698if (failing()) return;699if (cg == NULL) {700record_method_not_compilable("cannot parse method");701return;702}703JVMState* jvms = build_start_state(start(), tf());704if ((jvms = cg->generate(jvms)) == NULL) {705if (!failure_reason_is(C2Compiler::retry_class_loading_during_parsing())) {706record_method_not_compilable("method parse failed");707}708return;709}710GraphKit kit(jvms);711712if (!kit.stopped()) {713// Accept return values, and transfer control we know not where.714// This is done by a special, unique ReturnNode bound to root.715return_values(kit.jvms());716}717718if (kit.has_exceptions()) {719// Any exceptions that escape from this call must be rethrown720// to whatever caller is dynamically above us on the stack.721// This is done by a special, unique RethrowNode bound to root.722rethrow_exceptions(kit.transfer_exceptions_into_jvms());723}724725assert(IncrementalInline || (_late_inlines.length() == 0 && !has_mh_late_inlines()), "incremental inlining is off");726727if (_late_inlines.length() == 0 && !has_mh_late_inlines() && !failing() && has_stringbuilder()) {728inline_string_calls(true);729}730731if (failing()) return;732733print_method(PHASE_BEFORE_REMOVEUSELESS, 3);734735// Remove clutter produced by parsing.736if (!failing()) {737ResourceMark rm;738PhaseRemoveUseless pru(initial_gvn(), &for_igvn);739}740}741742// Note: Large methods are capped off in do_one_bytecode().743if (failing()) return;744745// After parsing, node notes are no longer automagic.746// They must be propagated by register_new_node_with_optimizer(),747// clone(), or the like.748set_default_node_notes(NULL);749750#ifndef PRODUCT751if (should_print(1)) {752_printer->print_inlining();753}754#endif755756if (failing()) return;757NOT_PRODUCT( verify_graph_edges(); )758759// If any phase is randomized for stress testing, seed random number760// generation and log the seed for repeatability.761if (StressLCM || StressGCM || StressIGVN || StressCCP) {762_stress_seed = FLAG_IS_DEFAULT(StressSeed) ?763static_cast<uint>(Ticks::now().nanoseconds()) : StressSeed;764if (_log != NULL) {765_log->elem("stress_test seed='%u'", _stress_seed);766}767}768769// Now optimize770Optimize();771if (failing()) return;772NOT_PRODUCT( verify_graph_edges(); )773774#ifndef PRODUCT775if (print_ideal()) {776ttyLocker ttyl; // keep the following output all in one block777// This output goes directly to the tty, not the compiler log.778// To enable tools to match it up with the compilation activity,779// be sure to tag this tty output with the compile ID.780if (xtty != NULL) {781xtty->head("ideal compile_id='%d'%s", compile_id(),782is_osr_compilation() ? " compile_kind='osr'" :783"");784}785root()->dump(9999);786if (xtty != NULL) {787xtty->tail("ideal");788}789}790#endif791792#ifdef ASSERT793BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();794bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);795#endif796797// Dump compilation data to replay it.798if (directive->DumpReplayOption) {799env()->dump_replay_data(_compile_id);800}801if (directive->DumpInlineOption && (ilt() != NULL)) {802env()->dump_inline_data(_compile_id);803}804805// Now that we know the size of all the monitors we can add a fixed slot806// for the original deopt pc.807int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);808set_fixed_slots(next_slot);809810// Compute when to use implicit null checks. Used by matching trap based811// nodes and NullCheck optimization.812set_allowed_deopt_reasons();813814// Now generate code815Code_Gen();816}817818//------------------------------Compile----------------------------------------819// Compile a runtime stub820Compile::Compile( ciEnv* ci_env,821TypeFunc_generator generator,822address stub_function,823const char *stub_name,824int is_fancy_jump,825bool pass_tls,826bool return_pc,827DirectiveSet* directive)828: Phase(Compiler),829_compile_id(0),830_subsume_loads(true),831_do_escape_analysis(false),832_install_code(true),833_eliminate_boxing(false),834_method(NULL),835_entry_bci(InvocationEntryBci),836_stub_function(stub_function),837_stub_name(stub_name),838_stub_entry_point(NULL),839_max_node_limit(MaxNodeLimit),840_post_loop_opts_phase(false),841_inlining_progress(false),842_inlining_incrementally(false),843_has_reserved_stack_access(false),844#ifndef PRODUCT845_igv_idx(0),846_trace_opto_output(directive->TraceOptoOutputOption),847_print_ideal(directive->PrintIdealOption),848#endif849_has_method_handle_invokes(false),850_clinit_barrier_on_entry(false),851_stress_seed(0),852_comp_arena(mtCompiler),853_barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),854_env(ci_env),855_directive(directive),856_log(ci_env->log()),857_failure_reason(NULL),858_congraph(NULL),859NOT_PRODUCT(_printer(NULL) COMMA)860_dead_node_list(comp_arena()),861_dead_node_count(0),862_node_arena(mtCompiler),863_old_arena(mtCompiler),864_mach_constant_base_node(NULL),865_Compile_types(mtCompiler),866_initial_gvn(NULL),867_for_igvn(NULL),868_number_of_mh_late_inlines(0),869_native_invokers(),870_print_inlining_stream(NULL),871_print_inlining_list(NULL),872_print_inlining_idx(0),873_print_inlining_output(NULL),874_replay_inline_data(NULL),875_java_calls(0),876_inner_loops(0),877_interpreter_frame_size(0),878#ifndef PRODUCT879_in_dump_cnt(0),880#endif881_allowed_reasons(0) {882C = this;883884TraceTime t1(NULL, &_t_totalCompilation, CITime, false);885TraceTime t2(NULL, &_t_stubCompilation, CITime, false);886887#ifndef PRODUCT888set_print_assembly(PrintFrameConverterAssembly);889set_parsed_irreducible_loop(false);890#else891set_print_assembly(false); // Must initialize.892#endif893set_has_irreducible_loop(false); // no loops894895CompileWrapper cw(this);896Init(/*AliasLevel=*/ 0);897init_tf((*generator)());898899{900// The following is a dummy for the sake of GraphKit::gen_stub901Unique_Node_List for_igvn(comp_arena());902set_for_igvn(&for_igvn); // not used, but some GraphKit guys push on this903PhaseGVN gvn(Thread::current()->resource_area(),255);904set_initial_gvn(&gvn); // not significant, but GraphKit guys use it pervasively905gvn.transform_no_reclaim(top());906907GraphKit kit;908kit.gen_stub(stub_function, stub_name, is_fancy_jump, pass_tls, return_pc);909}910911NOT_PRODUCT( verify_graph_edges(); )912913Code_Gen();914}915916//------------------------------Init-------------------------------------------917// Prepare for a single compilation918void Compile::Init(int aliaslevel) {919_unique = 0;920_regalloc = NULL;921922_tf = NULL; // filled in later923_top = NULL; // cached later924_matcher = NULL; // filled in later925_cfg = NULL; // filled in later926927IA32_ONLY( set_24_bit_selection_and_mode(true, false); )928929_node_note_array = NULL;930_default_node_notes = NULL;931DEBUG_ONLY( _modified_nodes = NULL; ) // Used in Optimize()932933_immutable_memory = NULL; // filled in at first inquiry934935// Globally visible Nodes936// First set TOP to NULL to give safe behavior during creation of RootNode937set_cached_top_node(NULL);938set_root(new RootNode());939// Now that you have a Root to point to, create the real TOP940set_cached_top_node( new ConNode(Type::TOP) );941set_recent_alloc(NULL, NULL);942943// Create Debug Information Recorder to record scopes, oopmaps, etc.944env()->set_oop_recorder(new OopRecorder(env()->arena()));945env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));946env()->set_dependencies(new Dependencies(env()));947948_fixed_slots = 0;949set_has_split_ifs(false);950set_has_loops(false); // first approximation951set_has_stringbuilder(false);952set_has_boxed_value(false);953_trap_can_recompile = false; // no traps emitted yet954_major_progress = true; // start out assuming good things will happen955set_has_unsafe_access(false);956set_max_vector_size(0);957set_clear_upper_avx(false); //false as default for clear upper bits of ymm registers958Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));959set_decompile_count(0);960961set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);962_loop_opts_cnt = LoopOptsCount;963set_do_inlining(Inline);964set_max_inline_size(MaxInlineSize);965set_freq_inline_size(FreqInlineSize);966set_do_scheduling(OptoScheduling);967968set_do_vector_loop(false);969970if (AllowVectorizeOnDemand) {971if (has_method() && (_directive->VectorizeOption || _directive->VectorizeDebugOption)) {972set_do_vector_loop(true);973NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n", method()->name()->as_quoted_ascii());})974} else if (has_method() && method()->name() != 0 &&975method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {976set_do_vector_loop(true);977}978}979set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally980NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n", method()->name()->as_quoted_ascii());})981982set_age_code(has_method() && method()->profile_aging());983set_rtm_state(NoRTM); // No RTM lock eliding by default984_max_node_limit = _directive->MaxNodeLimitOption;985986#if INCLUDE_RTM_OPT987if (UseRTMLocking && has_method() && (method()->method_data_or_null() != NULL)) {988int rtm_state = method()->method_data()->rtm_state();989if (method_has_option(CompileCommand::NoRTMLockEliding) || ((rtm_state & NoRTM) != 0)) {990// Don't generate RTM lock eliding code.991set_rtm_state(NoRTM);992} else if (method_has_option(CompileCommand::UseRTMLockEliding) || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {993// Generate RTM lock eliding code without abort ratio calculation code.994set_rtm_state(UseRTM);995} else if (UseRTMDeopt) {996// Generate RTM lock eliding code and include abort ratio calculation997// code if UseRTMDeopt is on.998set_rtm_state(ProfileRTM);999}1000}1001#endif1002if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() && method()->needs_clinit_barrier()) {1003set_clinit_barrier_on_entry(true);1004}1005if (debug_info()->recording_non_safepoints()) {1006set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>1007(comp_arena(), 8, 0, NULL));1008set_default_node_notes(Node_Notes::make(this));1009}10101011// // -- Initialize types before each compile --1012// // Update cached type information1013// if( _method && _method->constants() )1014// Type::update_loaded_types(_method, _method->constants());10151016// Init alias_type map.1017if (!_do_escape_analysis && aliaslevel == 3)1018aliaslevel = 2; // No unique types without escape analysis1019_AliasLevel = aliaslevel;1020const int grow_ats = 16;1021_max_alias_types = grow_ats;1022_alias_types = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);1023AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, grow_ats);1024Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);1025{1026for (int i = 0; i < grow_ats; i++) _alias_types[i] = &ats[i];1027}1028// Initialize the first few types.1029_alias_types[AliasIdxTop]->Init(AliasIdxTop, NULL);1030_alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);1031_alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);1032_num_alias_types = AliasIdxRaw+1;1033// Zero out the alias type cache.1034Copy::zero_to_bytes(_alias_cache, sizeof(_alias_cache));1035// A NULL adr_type hits in the cache right away. Preload the right answer.1036probe_alias_cache(NULL)->_index = AliasIdxTop;10371038#ifdef ASSERT1039_type_verify_symmetry = true;1040_phase_optimize_finished = false;1041_exception_backedge = false;1042#endif1043}10441045//---------------------------init_start----------------------------------------1046// Install the StartNode on this compile object.1047void Compile::init_start(StartNode* s) {1048if (failing())1049return; // already failing1050assert(s == start(), "");1051}10521053/**1054* Return the 'StartNode'. We must not have a pending failure, since the ideal graph1055* can be in an inconsistent state, i.e., we can get segmentation faults when traversing1056* the ideal graph.1057*/1058StartNode* Compile::start() const {1059assert (!failing(), "Must not have pending failure. Reason is: %s", failure_reason());1060for (DUIterator_Fast imax, i = root()->fast_outs(imax); i < imax; i++) {1061Node* start = root()->fast_out(i);1062if (start->is_Start()) {1063return start->as_Start();1064}1065}1066fatal("Did not find Start node!");1067return NULL;1068}10691070//-------------------------------immutable_memory-------------------------------------1071// Access immutable memory1072Node* Compile::immutable_memory() {1073if (_immutable_memory != NULL) {1074return _immutable_memory;1075}1076StartNode* s = start();1077for (DUIterator_Fast imax, i = s->fast_outs(imax); true; i++) {1078Node *p = s->fast_out(i);1079if (p != s && p->as_Proj()->_con == TypeFunc::Memory) {1080_immutable_memory = p;1081return _immutable_memory;1082}1083}1084ShouldNotReachHere();1085return NULL;1086}10871088//----------------------set_cached_top_node------------------------------------1089// Install the cached top node, and make sure Node::is_top works correctly.1090void Compile::set_cached_top_node(Node* tn) {1091if (tn != NULL) verify_top(tn);1092Node* old_top = _top;1093_top = tn;1094// Calling Node::setup_is_top allows the nodes the chance to adjust1095// their _out arrays.1096if (_top != NULL) _top->setup_is_top();1097if (old_top != NULL) old_top->setup_is_top();1098assert(_top == NULL || top()->is_top(), "");1099}11001101#ifdef ASSERT1102uint Compile::count_live_nodes_by_graph_walk() {1103Unique_Node_List useful(comp_arena());1104// Get useful node list by walking the graph.1105identify_useful_nodes(useful);1106return useful.size();1107}11081109void Compile::print_missing_nodes() {11101111// Return if CompileLog is NULL and PrintIdealNodeCount is false.1112if ((_log == NULL) && (! PrintIdealNodeCount)) {1113return;1114}11151116// This is an expensive function. It is executed only when the user1117// specifies VerifyIdealNodeCount option or otherwise knows the1118// additional work that needs to be done to identify reachable nodes1119// by walking the flow graph and find the missing ones using1120// _dead_node_list.11211122Unique_Node_List useful(comp_arena());1123// Get useful node list by walking the graph.1124identify_useful_nodes(useful);11251126uint l_nodes = C->live_nodes();1127uint l_nodes_by_walk = useful.size();11281129if (l_nodes != l_nodes_by_walk) {1130if (_log != NULL) {1131_log->begin_head("mismatched_nodes count='%d'", abs((int) (l_nodes - l_nodes_by_walk)));1132_log->stamp();1133_log->end_head();1134}1135VectorSet& useful_member_set = useful.member_set();1136int last_idx = l_nodes_by_walk;1137for (int i = 0; i < last_idx; i++) {1138if (useful_member_set.test(i)) {1139if (_dead_node_list.test(i)) {1140if (_log != NULL) {1141_log->elem("mismatched_node_info node_idx='%d' type='both live and dead'", i);1142}1143if (PrintIdealNodeCount) {1144// Print the log message to tty1145tty->print_cr("mismatched_node idx='%d' both live and dead'", i);1146useful.at(i)->dump();1147}1148}1149}1150else if (! _dead_node_list.test(i)) {1151if (_log != NULL) {1152_log->elem("mismatched_node_info node_idx='%d' type='neither live nor dead'", i);1153}1154if (PrintIdealNodeCount) {1155// Print the log message to tty1156tty->print_cr("mismatched_node idx='%d' type='neither live nor dead'", i);1157}1158}1159}1160if (_log != NULL) {1161_log->tail("mismatched_nodes");1162}1163}1164}1165void Compile::record_modified_node(Node* n) {1166if (_modified_nodes != NULL && !_inlining_incrementally && !n->is_Con()) {1167_modified_nodes->push(n);1168}1169}11701171void Compile::remove_modified_node(Node* n) {1172if (_modified_nodes != NULL) {1173_modified_nodes->remove(n);1174}1175}1176#endif11771178#ifndef PRODUCT1179void Compile::verify_top(Node* tn) const {1180if (tn != NULL) {1181assert(tn->is_Con(), "top node must be a constant");1182assert(((ConNode*)tn)->type() == Type::TOP, "top node must have correct type");1183assert(tn->in(0) != NULL, "must have live top node");1184}1185}1186#endif118711881189///-------------------Managing Per-Node Debug & Profile Info-------------------11901191void Compile::grow_node_notes(GrowableArray<Node_Notes*>* arr, int grow_by) {1192guarantee(arr != NULL, "");1193int num_blocks = arr->length();1194if (grow_by < num_blocks) grow_by = num_blocks;1195int num_notes = grow_by * _node_notes_block_size;1196Node_Notes* notes = NEW_ARENA_ARRAY(node_arena(), Node_Notes, num_notes);1197Copy::zero_to_bytes(notes, num_notes * sizeof(Node_Notes));1198while (num_notes > 0) {1199arr->append(notes);1200notes += _node_notes_block_size;1201num_notes -= _node_notes_block_size;1202}1203assert(num_notes == 0, "exact multiple, please");1204}12051206bool Compile::copy_node_notes_to(Node* dest, Node* source) {1207if (source == NULL || dest == NULL) return false;12081209if (dest->is_Con())1210return false; // Do not push debug info onto constants.12111212#ifdef ASSERT1213// Leave a bread crumb trail pointing to the original node:1214if (dest != NULL && dest != source && dest->debug_orig() == NULL) {1215dest->set_debug_orig(source);1216}1217#endif12181219if (node_note_array() == NULL)1220return false; // Not collecting any notes now.12211222// This is a copy onto a pre-existing node, which may already have notes.1223// If both nodes have notes, do not overwrite any pre-existing notes.1224Node_Notes* source_notes = node_notes_at(source->_idx);1225if (source_notes == NULL || source_notes->is_clear()) return false;1226Node_Notes* dest_notes = node_notes_at(dest->_idx);1227if (dest_notes == NULL || dest_notes->is_clear()) {1228return set_node_notes_at(dest->_idx, source_notes);1229}12301231Node_Notes merged_notes = (*source_notes);1232// The order of operations here ensures that dest notes will win...1233merged_notes.update_from(dest_notes);1234return set_node_notes_at(dest->_idx, &merged_notes);1235}123612371238//--------------------------allow_range_check_smearing-------------------------1239// Gating condition for coalescing similar range checks.1240// Sometimes we try 'speculatively' replacing a series of a range checks by a1241// single covering check that is at least as strong as any of them.1242// If the optimization succeeds, the simplified (strengthened) range check1243// will always succeed. If it fails, we will deopt, and then give up1244// on the optimization.1245bool Compile::allow_range_check_smearing() const {1246// If this method has already thrown a range-check,1247// assume it was because we already tried range smearing1248// and it failed.1249uint already_trapped = trap_count(Deoptimization::Reason_range_check);1250return !already_trapped;1251}125212531254//------------------------------flatten_alias_type-----------------------------1255const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {1256int offset = tj->offset();1257TypePtr::PTR ptr = tj->ptr();12581259// Known instance (scalarizable allocation) alias only with itself.1260bool is_known_inst = tj->isa_oopptr() != NULL &&1261tj->is_oopptr()->is_known_instance();12621263// Process weird unsafe references.1264if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {1265assert(InlineUnsafeOps, "indeterminate pointers come only from unsafe ops");1266assert(!is_known_inst, "scalarizable allocation should not have unsafe references");1267tj = TypeOopPtr::BOTTOM;1268ptr = tj->ptr();1269offset = tj->offset();1270}12711272// Array pointers need some flattening1273const TypeAryPtr *ta = tj->isa_aryptr();1274if (ta && ta->is_stable()) {1275// Erase stability property for alias analysis.1276tj = ta = ta->cast_to_stable(false);1277}1278if( ta && is_known_inst ) {1279if ( offset != Type::OffsetBot &&1280offset > arrayOopDesc::length_offset_in_bytes() ) {1281offset = Type::OffsetBot; // Flatten constant access into array body only1282tj = ta = TypeAryPtr::make(ptr, ta->ary(), ta->klass(), true, offset, ta->instance_id());1283}1284} else if( ta && _AliasLevel >= 2 ) {1285// For arrays indexed by constant indices, we flatten the alias1286// space to include all of the array body. Only the header, klass1287// and array length can be accessed un-aliased.1288if( offset != Type::OffsetBot ) {1289if( ta->const_oop() ) { // MethodData* or Method*1290offset = Type::OffsetBot; // Flatten constant access into array body1291tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),ta->ary(),ta->klass(),false,offset);1292} else if( offset == arrayOopDesc::length_offset_in_bytes() ) {1293// range is OK as-is.1294tj = ta = TypeAryPtr::RANGE;1295} else if( offset == oopDesc::klass_offset_in_bytes() ) {1296tj = TypeInstPtr::KLASS; // all klass loads look alike1297ta = TypeAryPtr::RANGE; // generic ignored junk1298ptr = TypePtr::BotPTR;1299} else if( offset == oopDesc::mark_offset_in_bytes() ) {1300tj = TypeInstPtr::MARK;1301ta = TypeAryPtr::RANGE; // generic ignored junk1302ptr = TypePtr::BotPTR;1303} else { // Random constant offset into array body1304offset = Type::OffsetBot; // Flatten constant access into array body1305tj = ta = TypeAryPtr::make(ptr,ta->ary(),ta->klass(),false,offset);1306}1307}1308// Arrays of fixed size alias with arrays of unknown size.1309if (ta->size() != TypeInt::POS) {1310const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);1311tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,ta->klass(),false,offset);1312}1313// Arrays of known objects become arrays of unknown objects.1314if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {1315const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());1316tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);1317}1318if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {1319const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());1320tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);1321}1322// Arrays of bytes and of booleans both use 'bastore' and 'baload' so1323// cannot be distinguished by bytecode alone.1324if (ta->elem() == TypeInt::BOOL) {1325const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());1326ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);1327tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset);1328}1329// During the 2nd round of IterGVN, NotNull castings are removed.1330// Make sure the Bottom and NotNull variants alias the same.1331// Also, make sure exact and non-exact variants alias the same.1332if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != NULL) {1333tj = ta = TypeAryPtr::make(TypePtr::BotPTR,ta->ary(),ta->klass(),false,offset);1334}1335}13361337// Oop pointers need some flattening1338const TypeInstPtr *to = tj->isa_instptr();1339if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {1340ciInstanceKlass *k = to->klass()->as_instance_klass();1341if( ptr == TypePtr::Constant ) {1342if (to->klass() != ciEnv::current()->Class_klass() ||1343offset < k->size_helper() * wordSize) {1344// No constant oop pointers (such as Strings); they alias with1345// unknown strings.1346assert(!is_known_inst, "not scalarizable allocation");1347tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);1348}1349} else if( is_known_inst ) {1350tj = to; // Keep NotNull and klass_is_exact for instance type1351} else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {1352// During the 2nd round of IterGVN, NotNull castings are removed.1353// Make sure the Bottom and NotNull variants alias the same.1354// Also, make sure exact and non-exact variants alias the same.1355tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);1356}1357if (to->speculative() != NULL) {1358tj = to = TypeInstPtr::make(to->ptr(),to->klass(),to->klass_is_exact(),to->const_oop(),to->offset(), to->instance_id());1359}1360// Canonicalize the holder of this field1361if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {1362// First handle header references such as a LoadKlassNode, even if the1363// object's klass is unloaded at compile time (4965979).1364if (!is_known_inst) { // Do it only for non-instance types1365tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset);1366}1367} else if (offset < 0 || offset >= k->size_helper() * wordSize) {1368// Static fields are in the space above the normal instance1369// fields in the java.lang.Class instance.1370if (to->klass() != ciEnv::current()->Class_klass()) {1371to = NULL;1372tj = TypeOopPtr::BOTTOM;1373offset = tj->offset();1374}1375} else {1376ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);1377if (!k->equals(canonical_holder) || tj->offset() != offset) {1378if( is_known_inst ) {1379tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL, offset, to->instance_id());1380} else {1381tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL, offset);1382}1383}1384}1385}13861387// Klass pointers to object array klasses need some flattening1388const TypeKlassPtr *tk = tj->isa_klassptr();1389if( tk ) {1390// If we are referencing a field within a Klass, we need1391// to assume the worst case of an Object. Both exact and1392// inexact types must flatten to the same alias class so1393// use NotNull as the PTR.1394if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {13951396tj = tk = TypeKlassPtr::make(TypePtr::NotNull,1397TypeKlassPtr::OBJECT->klass(),1398offset);1399}14001401ciKlass* klass = tk->klass();1402if( klass->is_obj_array_klass() ) {1403ciKlass* k = TypeAryPtr::OOPS->klass();1404if( !k || !k->is_loaded() ) // Only fails for some -Xcomp runs1405k = TypeInstPtr::BOTTOM->klass();1406tj = tk = TypeKlassPtr::make( TypePtr::NotNull, k, offset );1407}14081409// Check for precise loads from the primary supertype array and force them1410// to the supertype cache alias index. Check for generic array loads from1411// the primary supertype array and also force them to the supertype cache1412// alias index. Since the same load can reach both, we need to merge1413// these 2 disparate memories into the same alias class. Since the1414// primary supertype array is read-only, there's no chance of confusion1415// where we bypass an array load and an array store.1416int primary_supers_offset = in_bytes(Klass::primary_supers_offset());1417if (offset == Type::OffsetBot ||1418(offset >= primary_supers_offset &&1419offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||1420offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {1421offset = in_bytes(Klass::secondary_super_cache_offset());1422tj = tk = TypeKlassPtr::make( TypePtr::NotNull, tk->klass(), offset );1423}1424}14251426// Flatten all Raw pointers together.1427if (tj->base() == Type::RawPtr)1428tj = TypeRawPtr::BOTTOM;14291430if (tj->base() == Type::AnyPtr)1431tj = TypePtr::BOTTOM; // An error, which the caller must check for.14321433// Flatten all to bottom for now1434switch( _AliasLevel ) {1435case 0:1436tj = TypePtr::BOTTOM;1437break;1438case 1: // Flatten to: oop, static, field or array1439switch (tj->base()) {1440//case Type::AryPtr: tj = TypeAryPtr::RANGE; break;1441case Type::RawPtr: tj = TypeRawPtr::BOTTOM; break;1442case Type::AryPtr: // do not distinguish arrays at all1443case Type::InstPtr: tj = TypeInstPtr::BOTTOM; break;1444case Type::KlassPtr: tj = TypeKlassPtr::OBJECT; break;1445case Type::AnyPtr: tj = TypePtr::BOTTOM; break; // caller checks it1446default: ShouldNotReachHere();1447}1448break;1449case 2: // No collapsing at level 2; keep all splits1450case 3: // No collapsing at level 3; keep all splits1451break;1452default:1453Unimplemented();1454}14551456offset = tj->offset();1457assert( offset != Type::OffsetTop, "Offset has fallen from constant" );14581459assert( (offset != Type::OffsetBot && tj->base() != Type::AryPtr) ||1460(offset == Type::OffsetBot && tj->base() == Type::AryPtr) ||1461(offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) ||1462(offset == Type::OffsetBot && tj == TypePtr::BOTTOM) ||1463(offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) ||1464(offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) ||1465(offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr),1466"For oops, klasses, raw offset must be constant; for arrays the offset is never known" );1467assert( tj->ptr() != TypePtr::TopPTR &&1468tj->ptr() != TypePtr::AnyNull &&1469tj->ptr() != TypePtr::Null, "No imprecise addresses" );1470// assert( tj->ptr() != TypePtr::Constant ||1471// tj->base() == Type::RawPtr ||1472// tj->base() == Type::KlassPtr, "No constant oop addresses" );14731474return tj;1475}14761477void Compile::AliasType::Init(int i, const TypePtr* at) {1478assert(AliasIdxTop <= i && i < Compile::current()->_max_alias_types, "Invalid alias index");1479_index = i;1480_adr_type = at;1481_field = NULL;1482_element = NULL;1483_is_rewritable = true; // default1484const TypeOopPtr *atoop = (at != NULL) ? at->isa_oopptr() : NULL;1485if (atoop != NULL && atoop->is_known_instance()) {1486const TypeOopPtr *gt = atoop->cast_to_instance_id(TypeOopPtr::InstanceBot);1487_general_index = Compile::current()->get_alias_index(gt);1488} else {1489_general_index = 0;1490}1491}14921493BasicType Compile::AliasType::basic_type() const {1494if (element() != NULL) {1495const Type* element = adr_type()->is_aryptr()->elem();1496return element->isa_narrowoop() ? T_OBJECT : element->array_element_basic_type();1497} if (field() != NULL) {1498return field()->layout_type();1499} else {1500return T_ILLEGAL; // unknown1501}1502}15031504//---------------------------------print_on------------------------------------1505#ifndef PRODUCT1506void Compile::AliasType::print_on(outputStream* st) {1507if (index() < 10)1508st->print("@ <%d> ", index());1509else st->print("@ <%d>", index());1510st->print(is_rewritable() ? " " : " RO");1511int offset = adr_type()->offset();1512if (offset == Type::OffsetBot)1513st->print(" +any");1514else st->print(" +%-3d", offset);1515st->print(" in ");1516adr_type()->dump_on(st);1517const TypeOopPtr* tjp = adr_type()->isa_oopptr();1518if (field() != NULL && tjp) {1519if (tjp->klass() != field()->holder() ||1520tjp->offset() != field()->offset_in_bytes()) {1521st->print(" != ");1522field()->print();1523st->print(" ***");1524}1525}1526}15271528void print_alias_types() {1529Compile* C = Compile::current();1530tty->print_cr("--- Alias types, AliasIdxBot .. %d", C->num_alias_types()-1);1531for (int idx = Compile::AliasIdxBot; idx < C->num_alias_types(); idx++) {1532C->alias_type(idx)->print_on(tty);1533tty->cr();1534}1535}1536#endif153715381539//----------------------------probe_alias_cache--------------------------------1540Compile::AliasCacheEntry* Compile::probe_alias_cache(const TypePtr* adr_type) {1541intptr_t key = (intptr_t) adr_type;1542key ^= key >> logAliasCacheSize;1543return &_alias_cache[key & right_n_bits(logAliasCacheSize)];1544}154515461547//-----------------------------grow_alias_types--------------------------------1548void Compile::grow_alias_types() {1549const int old_ats = _max_alias_types; // how many before?1550const int new_ats = old_ats; // how many more?1551const int grow_ats = old_ats+new_ats; // how many now?1552_max_alias_types = grow_ats;1553_alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);1554AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);1555Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);1556for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];1557}155815591560//--------------------------------find_alias_type------------------------------1561Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {1562if (_AliasLevel == 0)1563return alias_type(AliasIdxBot);15641565AliasCacheEntry* ace = probe_alias_cache(adr_type);1566if (ace->_adr_type == adr_type) {1567return alias_type(ace->_index);1568}15691570// Handle special cases.1571if (adr_type == NULL) return alias_type(AliasIdxTop);1572if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot);15731574// Do it the slow way.1575const TypePtr* flat = flatten_alias_type(adr_type);15761577#ifdef ASSERT1578{1579ResourceMark rm;1580assert(flat == flatten_alias_type(flat), "not idempotent: adr_type = %s; flat = %s => %s",1581Type::str(adr_type), Type::str(flat), Type::str(flatten_alias_type(flat)));1582assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr: adr_type = %s",1583Type::str(adr_type));1584if (flat->isa_oopptr() && !flat->isa_klassptr()) {1585const TypeOopPtr* foop = flat->is_oopptr();1586// Scalarizable allocations have exact klass always.1587bool exact = !foop->klass_is_exact() || foop->is_known_instance();1588const TypePtr* xoop = foop->cast_to_exactness(exact)->is_ptr();1589assert(foop == flatten_alias_type(xoop), "exactness must not affect alias type: foop = %s; xoop = %s",1590Type::str(foop), Type::str(xoop));1591}1592}1593#endif15941595int idx = AliasIdxTop;1596for (int i = 0; i < num_alias_types(); i++) {1597if (alias_type(i)->adr_type() == flat) {1598idx = i;1599break;1600}1601}16021603if (idx == AliasIdxTop) {1604if (no_create) return NULL;1605// Grow the array if necessary.1606if (_num_alias_types == _max_alias_types) grow_alias_types();1607// Add a new alias type.1608idx = _num_alias_types++;1609_alias_types[idx]->Init(idx, flat);1610if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);1611if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);1612if (flat->isa_instptr()) {1613if (flat->offset() == java_lang_Class::klass_offset()1614&& flat->is_instptr()->klass() == env()->Class_klass())1615alias_type(idx)->set_rewritable(false);1616}1617if (flat->isa_aryptr()) {1618#ifdef ASSERT1619const int header_size_min = arrayOopDesc::base_offset_in_bytes(T_BYTE);1620// (T_BYTE has the weakest alignment and size restrictions...)1621assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");1622#endif1623if (flat->offset() == TypePtr::OffsetBot) {1624alias_type(idx)->set_element(flat->is_aryptr()->elem());1625}1626}1627if (flat->isa_klassptr()) {1628if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))1629alias_type(idx)->set_rewritable(false);1630if (flat->offset() == in_bytes(Klass::modifier_flags_offset()))1631alias_type(idx)->set_rewritable(false);1632if (flat->offset() == in_bytes(Klass::access_flags_offset()))1633alias_type(idx)->set_rewritable(false);1634if (flat->offset() == in_bytes(Klass::java_mirror_offset()))1635alias_type(idx)->set_rewritable(false);1636if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))1637alias_type(idx)->set_rewritable(false);1638}1639// %%% (We would like to finalize JavaThread::threadObj_offset(),1640// but the base pointer type is not distinctive enough to identify1641// references into JavaThread.)16421643// Check for final fields.1644const TypeInstPtr* tinst = flat->isa_instptr();1645if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {1646ciField* field;1647if (tinst->const_oop() != NULL &&1648tinst->klass() == ciEnv::current()->Class_klass() &&1649tinst->offset() >= (tinst->klass()->as_instance_klass()->size_helper() * wordSize)) {1650// static field1651ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();1652field = k->get_field_by_offset(tinst->offset(), true);1653} else {1654ciInstanceKlass *k = tinst->klass()->as_instance_klass();1655field = k->get_field_by_offset(tinst->offset(), false);1656}1657assert(field == NULL ||1658original_field == NULL ||1659(field->holder() == original_field->holder() &&1660field->offset() == original_field->offset() &&1661field->is_static() == original_field->is_static()), "wrong field?");1662// Set field() and is_rewritable() attributes.1663if (field != NULL) alias_type(idx)->set_field(field);1664}1665}16661667// Fill the cache for next time.1668ace->_adr_type = adr_type;1669ace->_index = idx;1670assert(alias_type(adr_type) == alias_type(idx), "type must be installed");16711672// Might as well try to fill the cache for the flattened version, too.1673AliasCacheEntry* face = probe_alias_cache(flat);1674if (face->_adr_type == NULL) {1675face->_adr_type = flat;1676face->_index = idx;1677assert(alias_type(flat) == alias_type(idx), "flat type must work too");1678}16791680return alias_type(idx);1681}168216831684Compile::AliasType* Compile::alias_type(ciField* field) {1685const TypeOopPtr* t;1686if (field->is_static())1687t = TypeInstPtr::make(field->holder()->java_mirror());1688else1689t = TypeOopPtr::make_from_klass_raw(field->holder());1690AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);1691assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");1692return atp;1693}169416951696//------------------------------have_alias_type--------------------------------1697bool Compile::have_alias_type(const TypePtr* adr_type) {1698AliasCacheEntry* ace = probe_alias_cache(adr_type);1699if (ace->_adr_type == adr_type) {1700return true;1701}17021703// Handle special cases.1704if (adr_type == NULL) return true;1705if (adr_type == TypePtr::BOTTOM) return true;17061707return find_alias_type(adr_type, true, NULL) != NULL;1708}17091710//-----------------------------must_alias--------------------------------------1711// True if all values of the given address type are in the given alias category.1712bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) {1713if (alias_idx == AliasIdxBot) return true; // the universal category1714if (adr_type == NULL) return true; // NULL serves as TypePtr::TOP1715if (alias_idx == AliasIdxTop) return false; // the empty category1716if (adr_type->base() == Type::AnyPtr) return false; // TypePtr::BOTTOM or its twins17171718// the only remaining possible overlap is identity1719int adr_idx = get_alias_index(adr_type);1720assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "");1721assert(adr_idx == alias_idx ||1722(alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM1723&& adr_type != TypeOopPtr::BOTTOM),1724"should not be testing for overlap with an unsafe pointer");1725return adr_idx == alias_idx;1726}17271728//------------------------------can_alias--------------------------------------1729// True if any values of the given address type are in the given alias category.1730bool Compile::can_alias(const TypePtr* adr_type, int alias_idx) {1731if (alias_idx == AliasIdxTop) return false; // the empty category1732if (adr_type == NULL) return false; // NULL serves as TypePtr::TOP1733// Known instance doesn't alias with bottom memory1734if (alias_idx == AliasIdxBot) return !adr_type->is_known_instance(); // the universal category1735if (adr_type->base() == Type::AnyPtr) return !C->get_adr_type(alias_idx)->is_known_instance(); // TypePtr::BOTTOM or its twins17361737// the only remaining possible overlap is identity1738int adr_idx = get_alias_index(adr_type);1739assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "");1740return adr_idx == alias_idx;1741}17421743//---------------------cleanup_loop_predicates-----------------------1744// Remove the opaque nodes that protect the predicates so that all unused1745// checks and uncommon_traps will be eliminated from the ideal graph1746void Compile::cleanup_loop_predicates(PhaseIterGVN &igvn) {1747if (predicate_count()==0) return;1748for (int i = predicate_count(); i > 0; i--) {1749Node * n = predicate_opaque1_node(i-1);1750assert(n->Opcode() == Op_Opaque1, "must be");1751igvn.replace_node(n, n->in(1));1752}1753assert(predicate_count()==0, "should be clean!");1754}17551756void Compile::record_for_post_loop_opts_igvn(Node* n) {1757if (!n->for_post_loop_opts_igvn()) {1758assert(!_for_post_loop_igvn.contains(n), "duplicate");1759n->add_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);1760_for_post_loop_igvn.append(n);1761}1762}17631764void Compile::remove_from_post_loop_opts_igvn(Node* n) {1765n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);1766_for_post_loop_igvn.remove(n);1767}17681769void Compile::process_for_post_loop_opts_igvn(PhaseIterGVN& igvn) {1770// Verify that all previous optimizations produced a valid graph1771// at least to this point, even if no loop optimizations were done.1772PhaseIdealLoop::verify(igvn);17731774C->set_post_loop_opts_phase(); // no more loop opts allowed17751776assert(!C->major_progress(), "not cleared");17771778if (_for_post_loop_igvn.length() > 0) {1779while (_for_post_loop_igvn.length() > 0) {1780Node* n = _for_post_loop_igvn.pop();1781n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);1782igvn._worklist.push(n);1783}1784igvn.optimize();1785assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed");17861787// Sometimes IGVN sets major progress (e.g., when processing loop nodes).1788if (C->major_progress()) {1789C->clear_major_progress(); // ensure that major progress is now clear1790}1791}1792}17931794// StringOpts and late inlining of string methods1795void Compile::inline_string_calls(bool parse_time) {1796{1797// remove useless nodes to make the usage analysis simpler1798ResourceMark rm;1799PhaseRemoveUseless pru(initial_gvn(), for_igvn());1800}18011802{1803ResourceMark rm;1804print_method(PHASE_BEFORE_STRINGOPTS, 3);1805PhaseStringOpts pso(initial_gvn(), for_igvn());1806print_method(PHASE_AFTER_STRINGOPTS, 3);1807}18081809// now inline anything that we skipped the first time around1810if (!parse_time) {1811_late_inlines_pos = _late_inlines.length();1812}18131814while (_string_late_inlines.length() > 0) {1815CallGenerator* cg = _string_late_inlines.pop();1816cg->do_late_inline();1817if (failing()) return;1818}1819_string_late_inlines.trunc_to(0);1820}18211822// Late inlining of boxing methods1823void Compile::inline_boxing_calls(PhaseIterGVN& igvn) {1824if (_boxing_late_inlines.length() > 0) {1825assert(has_boxed_value(), "inconsistent");18261827PhaseGVN* gvn = initial_gvn();1828set_inlining_incrementally(true);18291830assert( igvn._worklist.size() == 0, "should be done with igvn" );1831for_igvn()->clear();1832gvn->replace_with(&igvn);18331834_late_inlines_pos = _late_inlines.length();18351836while (_boxing_late_inlines.length() > 0) {1837CallGenerator* cg = _boxing_late_inlines.pop();1838cg->do_late_inline();1839if (failing()) return;1840}1841_boxing_late_inlines.trunc_to(0);18421843inline_incrementally_cleanup(igvn);18441845set_inlining_incrementally(false);1846}1847}18481849bool Compile::inline_incrementally_one() {1850assert(IncrementalInline, "incremental inlining should be on");18511852TracePhase tp("incrementalInline_inline", &timers[_t_incrInline_inline]);18531854set_inlining_progress(false);1855set_do_cleanup(false);18561857for (int i = 0; i < _late_inlines.length(); i++) {1858_late_inlines_pos = i+1;1859CallGenerator* cg = _late_inlines.at(i);1860bool does_dispatch = cg->is_virtual_late_inline() || cg->is_mh_late_inline();1861if (inlining_incrementally() || does_dispatch) { // a call can be either inlined or strength-reduced to a direct call1862cg->do_late_inline();1863assert(_late_inlines.at(i) == cg, "no insertions before current position allowed");1864if (failing()) {1865return false;1866} else if (inlining_progress()) {1867_late_inlines_pos = i+1; // restore the position in case new elements were inserted1868print_method(PHASE_INCREMENTAL_INLINE_STEP, cg->call_node(), 3);1869break; // process one call site at a time1870}1871} else {1872// Ignore late inline direct calls when inlining is not allowed.1873// They are left in the late inline list when node budget is exhausted until the list is fully drained.1874}1875}1876// Remove processed elements.1877_late_inlines.remove_till(_late_inlines_pos);1878_late_inlines_pos = 0;18791880assert(inlining_progress() || _late_inlines.length() == 0, "no progress");18811882bool needs_cleanup = do_cleanup() || over_inlining_cutoff();18831884set_inlining_progress(false);1885set_do_cleanup(false);18861887bool force_cleanup = directive()->IncrementalInlineForceCleanupOption;1888return (_late_inlines.length() > 0) && !needs_cleanup && !force_cleanup;1889}18901891void Compile::inline_incrementally_cleanup(PhaseIterGVN& igvn) {1892{1893TracePhase tp("incrementalInline_pru", &timers[_t_incrInline_pru]);1894ResourceMark rm;1895PhaseRemoveUseless pru(initial_gvn(), for_igvn());1896}1897{1898TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);1899igvn = PhaseIterGVN(initial_gvn());1900igvn.optimize();1901}1902print_method(PHASE_INCREMENTAL_INLINE_CLEANUP, 3);1903}19041905// Perform incremental inlining until bound on number of live nodes is reached1906void Compile::inline_incrementally(PhaseIterGVN& igvn) {1907TracePhase tp("incrementalInline", &timers[_t_incrInline]);19081909set_inlining_incrementally(true);1910uint low_live_nodes = 0;19111912while (_late_inlines.length() > 0) {1913if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {1914if (low_live_nodes < (uint)LiveNodeCountInliningCutoff * 8 / 10) {1915TracePhase tp("incrementalInline_ideal", &timers[_t_incrInline_ideal]);1916// PhaseIdealLoop is expensive so we only try it once we are1917// out of live nodes and we only try it again if the previous1918// helped got the number of nodes down significantly1919PhaseIdealLoop::optimize(igvn, LoopOptsNone);1920if (failing()) return;1921low_live_nodes = live_nodes();1922_major_progress = true;1923}19241925if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {1926bool do_print_inlining = print_inlining() || print_intrinsics();1927if (do_print_inlining || log() != NULL) {1928// Print inlining message for candidates that we couldn't inline for lack of space.1929for (int i = 0; i < _late_inlines.length(); i++) {1930CallGenerator* cg = _late_inlines.at(i);1931const char* msg = "live nodes > LiveNodeCountInliningCutoff";1932if (do_print_inlining) {1933cg->print_inlining_late(msg);1934}1935log_late_inline_failure(cg, msg);1936}1937}1938break; // finish1939}1940}19411942for_igvn()->clear();1943initial_gvn()->replace_with(&igvn);19441945while (inline_incrementally_one()) {1946assert(!failing(), "inconsistent");1947}1948if (failing()) return;19491950inline_incrementally_cleanup(igvn);19511952print_method(PHASE_INCREMENTAL_INLINE_STEP, 3);19531954if (failing()) return;19551956if (_late_inlines.length() == 0) {1957break; // no more progress1958}1959}1960assert( igvn._worklist.size() == 0, "should be done with igvn" );19611962if (_string_late_inlines.length() > 0) {1963assert(has_stringbuilder(), "inconsistent");1964for_igvn()->clear();1965initial_gvn()->replace_with(&igvn);19661967inline_string_calls(false);19681969if (failing()) return;19701971inline_incrementally_cleanup(igvn);1972}19731974set_inlining_incrementally(false);1975}19761977void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {1978// "inlining_incrementally() == false" is used to signal that no inlining is allowed1979// (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).1980// Tracking and verification of modified nodes is disabled by setting "_modified_nodes == NULL"1981// as if "inlining_incrementally() == true" were set.1982assert(inlining_incrementally() == false, "not allowed");1983assert(_modified_nodes == NULL, "not allowed");1984assert(_late_inlines.length() > 0, "sanity");19851986while (_late_inlines.length() > 0) {1987for_igvn()->clear();1988initial_gvn()->replace_with(&igvn);19891990while (inline_incrementally_one()) {1991assert(!failing(), "inconsistent");1992}1993if (failing()) return;19941995inline_incrementally_cleanup(igvn);1996}1997}19981999bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {2000if (_loop_opts_cnt > 0) {2001debug_only( int cnt = 0; );2002while (major_progress() && (_loop_opts_cnt > 0)) {2003TracePhase tp("idealLoop", &timers[_t_idealLoop]);2004assert( cnt++ < 40, "infinite cycle in loop optimization" );2005PhaseIdealLoop::optimize(igvn, mode);2006_loop_opts_cnt--;2007if (failing()) return false;2008if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);2009}2010}2011return true;2012}20132014// Remove edges from "root" to each SafePoint at a backward branch.2015// They were inserted during parsing (see add_safepoint()) to make2016// infinite loops without calls or exceptions visible to root, i.e.,2017// useful.2018void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {2019Node *r = root();2020if (r != NULL) {2021for (uint i = r->req(); i < r->len(); ++i) {2022Node *n = r->in(i);2023if (n != NULL && n->is_SafePoint()) {2024r->rm_prec(i);2025if (n->outcnt() == 0) {2026igvn.remove_dead_node(n);2027}2028--i;2029}2030}2031// Parsing may have added top inputs to the root node (Path2032// leading to the Halt node proven dead). Make sure we get a2033// chance to clean them up.2034igvn._worklist.push(r);2035igvn.optimize();2036}2037}20382039//------------------------------Optimize---------------------------------------2040// Given a graph, optimize it.2041void Compile::Optimize() {2042TracePhase tp("optimizer", &timers[_t_optimizer]);20432044#ifndef PRODUCT2045if (env()->break_at_compile()) {2046BREAKPOINT;2047}20482049#endif20502051BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();2052#ifdef ASSERT2053bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);2054#endif20552056ResourceMark rm;20572058print_inlining_reinit();20592060NOT_PRODUCT( verify_graph_edges(); )20612062print_method(PHASE_AFTER_PARSING);20632064{2065// Iterative Global Value Numbering, including ideal transforms2066// Initialize IterGVN with types and values from parse-time GVN2067PhaseIterGVN igvn(initial_gvn());2068#ifdef ASSERT2069_modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());2070#endif2071{2072TracePhase tp("iterGVN", &timers[_t_iterGVN]);2073igvn.optimize();2074}20752076if (failing()) return;20772078print_method(PHASE_ITER_GVN1, 2);20792080inline_incrementally(igvn);20812082print_method(PHASE_INCREMENTAL_INLINE, 2);20832084if (failing()) return;20852086if (eliminate_boxing()) {2087// Inline valueOf() methods now.2088inline_boxing_calls(igvn);20892090if (AlwaysIncrementalInline) {2091inline_incrementally(igvn);2092}20932094print_method(PHASE_INCREMENTAL_BOXING_INLINE, 2);20952096if (failing()) return;2097}20982099// Now that all inlining is over, cut edge from root to loop2100// safepoints2101remove_root_to_sfpts_edges(igvn);21022103// Remove the speculative part of types and clean up the graph from2104// the extra CastPP nodes whose only purpose is to carry them. Do2105// that early so that optimizations are not disrupted by the extra2106// CastPP nodes.2107remove_speculative_types(igvn);21082109// No more new expensive nodes will be added to the list from here2110// so keep only the actual candidates for optimizations.2111cleanup_expensive_nodes(igvn);21122113assert(EnableVectorSupport || !has_vbox_nodes(), "sanity");2114if (EnableVectorSupport && has_vbox_nodes()) {2115TracePhase tp("", &timers[_t_vector]);2116PhaseVector pv(igvn);2117pv.optimize_vector_boxes();21182119print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);2120}2121assert(!has_vbox_nodes(), "sanity");21222123if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {2124Compile::TracePhase tp("", &timers[_t_renumberLive]);2125initial_gvn()->replace_with(&igvn);2126for_igvn()->clear();2127Unique_Node_List new_worklist(C->comp_arena());2128{2129ResourceMark rm;2130PhaseRenumberLive prl = PhaseRenumberLive(initial_gvn(), for_igvn(), &new_worklist);2131}2132Unique_Node_List* save_for_igvn = for_igvn();2133set_for_igvn(&new_worklist);2134igvn = PhaseIterGVN(initial_gvn());2135igvn.optimize();2136set_for_igvn(save_for_igvn);2137}21382139// Perform escape analysis2140if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {2141if (has_loops()) {2142// Cleanup graph (remove dead nodes).2143TracePhase tp("idealLoop", &timers[_t_idealLoop]);2144PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);2145if (major_progress()) print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);2146if (failing()) return;2147}2148ConnectionGraph::do_analysis(this, &igvn);21492150if (failing()) return;21512152// Optimize out fields loads from scalar replaceable allocations.2153igvn.optimize();2154print_method(PHASE_ITER_GVN_AFTER_EA, 2);21552156if (failing()) return;21572158if (congraph() != NULL && macro_count() > 0) {2159TracePhase tp("macroEliminate", &timers[_t_macroEliminate]);2160PhaseMacroExpand mexp(igvn);2161mexp.eliminate_macro_nodes();2162igvn.set_delay_transform(false);21632164igvn.optimize();2165print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);21662167if (failing()) return;2168}2169}21702171// Loop transforms on the ideal graph. Range Check Elimination,2172// peeling, unrolling, etc.21732174// Set loop opts counter2175if((_loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {2176{2177TracePhase tp("idealLoop", &timers[_t_idealLoop]);2178PhaseIdealLoop::optimize(igvn, LoopOptsDefault);2179_loop_opts_cnt--;2180if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);2181if (failing()) return;2182}2183// Loop opts pass if partial peeling occurred in previous pass2184if(PartialPeelLoop && major_progress() && (_loop_opts_cnt > 0)) {2185TracePhase tp("idealLoop", &timers[_t_idealLoop]);2186PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);2187_loop_opts_cnt--;2188if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);2189if (failing()) return;2190}2191// Loop opts pass for loop-unrolling before CCP2192if(major_progress() && (_loop_opts_cnt > 0)) {2193TracePhase tp("idealLoop", &timers[_t_idealLoop]);2194PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);2195_loop_opts_cnt--;2196if (major_progress()) print_method(PHASE_PHASEIDEALLOOP3, 2);2197}2198if (!failing()) {2199// Verify that last round of loop opts produced a valid graph2200PhaseIdealLoop::verify(igvn);2201}2202}2203if (failing()) return;22042205// Conditional Constant Propagation;2206PhaseCCP ccp( &igvn );2207assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");2208{2209TracePhase tp("ccp", &timers[_t_ccp]);2210ccp.do_transform();2211}2212print_method(PHASE_CPP1, 2);22132214assert( true, "Break here to ccp.dump_old2new_map()");22152216// Iterative Global Value Numbering, including ideal transforms2217{2218TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);2219igvn = ccp;2220igvn.optimize();2221}2222print_method(PHASE_ITER_GVN2, 2);22232224if (failing()) return;22252226// Loop transforms on the ideal graph. Range Check Elimination,2227// peeling, unrolling, etc.2228if (!optimize_loops(igvn, LoopOptsDefault)) {2229return;2230}22312232if (failing()) return;22332234C->clear_major_progress(); // ensure that major progress is now clear22352236process_for_post_loop_opts_igvn(igvn);22372238#ifdef ASSERT2239bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);2240#endif22412242{2243TracePhase tp("macroExpand", &timers[_t_macroExpand]);2244PhaseMacroExpand mex(igvn);2245if (mex.expand_macro_nodes()) {2246assert(failing(), "must bail out w/ explicit message");2247return;2248}2249print_method(PHASE_MACRO_EXPANSION, 2);2250}22512252{2253TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);2254if (bs->expand_barriers(this, igvn)) {2255assert(failing(), "must bail out w/ explicit message");2256return;2257}2258print_method(PHASE_BARRIER_EXPANSION, 2);2259}22602261if (C->max_vector_size() > 0) {2262C->optimize_logic_cones(igvn);2263igvn.optimize();2264}22652266DEBUG_ONLY( _modified_nodes = NULL; )22672268assert(igvn._worklist.size() == 0, "not empty");22692270assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");22712272if (_late_inlines.length() > 0) {2273// More opportunities to optimize virtual and MH calls.2274// Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.2275process_late_inline_calls_no_inline(igvn);2276}2277} // (End scope of igvn; run destructor if necessary for asserts.)22782279check_no_dead_use();22802281process_print_inlining();22822283// A method with only infinite loops has no edges entering loops from root2284{2285TracePhase tp("graphReshape", &timers[_t_graphReshaping]);2286if (final_graph_reshaping()) {2287assert(failing(), "must bail out w/ explicit message");2288return;2289}2290}22912292print_method(PHASE_OPTIMIZE_FINISHED, 2);2293DEBUG_ONLY(set_phase_optimize_finished();)2294}22952296#ifdef ASSERT2297void Compile::check_no_dead_use() const {2298ResourceMark rm;2299Unique_Node_List wq;2300wq.push(root());2301for (uint i = 0; i < wq.size(); ++i) {2302Node* n = wq.at(i);2303for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {2304Node* u = n->fast_out(j);2305if (u->outcnt() == 0 && !u->is_Con()) {2306u->dump();2307fatal("no reachable node should have no use");2308}2309wq.push(u);2310}2311}2312}2313#endif23142315void Compile::inline_vector_reboxing_calls() {2316if (C->_vector_reboxing_late_inlines.length() > 0) {2317_late_inlines_pos = C->_late_inlines.length();2318while (_vector_reboxing_late_inlines.length() > 0) {2319CallGenerator* cg = _vector_reboxing_late_inlines.pop();2320cg->do_late_inline();2321if (failing()) return;2322print_method(PHASE_INLINE_VECTOR_REBOX, cg->call_node());2323}2324_vector_reboxing_late_inlines.trunc_to(0);2325}2326}23272328bool Compile::has_vbox_nodes() {2329if (C->_vector_reboxing_late_inlines.length() > 0) {2330return true;2331}2332for (int macro_idx = C->macro_count() - 1; macro_idx >= 0; macro_idx--) {2333Node * n = C->macro_node(macro_idx);2334assert(n->is_macro(), "only macro nodes expected here");2335if (n->Opcode() == Op_VectorUnbox || n->Opcode() == Op_VectorBox || n->Opcode() == Op_VectorBoxAllocate) {2336return true;2337}2338}2339return false;2340}23412342//---------------------------- Bitwise operation packing optimization ---------------------------23432344static bool is_vector_unary_bitwise_op(Node* n) {2345return n->Opcode() == Op_XorV &&2346VectorNode::is_vector_bitwise_not_pattern(n);2347}23482349static bool is_vector_binary_bitwise_op(Node* n) {2350switch (n->Opcode()) {2351case Op_AndV:2352case Op_OrV:2353return true;23542355case Op_XorV:2356return !is_vector_unary_bitwise_op(n);23572358default:2359return false;2360}2361}23622363static bool is_vector_ternary_bitwise_op(Node* n) {2364return n->Opcode() == Op_MacroLogicV;2365}23662367static bool is_vector_bitwise_op(Node* n) {2368return is_vector_unary_bitwise_op(n) ||2369is_vector_binary_bitwise_op(n) ||2370is_vector_ternary_bitwise_op(n);2371}23722373static bool is_vector_bitwise_cone_root(Node* n) {2374if (n->bottom_type()->isa_vectmask() || !is_vector_bitwise_op(n)) {2375return false;2376}2377for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {2378if (is_vector_bitwise_op(n->fast_out(i))) {2379return false;2380}2381}2382return true;2383}23842385static uint collect_unique_inputs(Node* n, Unique_Node_List& partition, Unique_Node_List& inputs) {2386uint cnt = 0;2387if (is_vector_bitwise_op(n)) {2388if (VectorNode::is_vector_bitwise_not_pattern(n)) {2389for (uint i = 1; i < n->req(); i++) {2390Node* in = n->in(i);2391bool skip = VectorNode::is_all_ones_vector(in);2392if (!skip && !inputs.member(in)) {2393inputs.push(in);2394cnt++;2395}2396}2397assert(cnt <= 1, "not unary");2398} else {2399uint last_req = n->req();2400if (is_vector_ternary_bitwise_op(n)) {2401last_req = n->req() - 1; // skip last input2402}2403for (uint i = 1; i < last_req; i++) {2404Node* def = n->in(i);2405if (!inputs.member(def)) {2406inputs.push(def);2407cnt++;2408}2409}2410}2411partition.push(n);2412} else { // not a bitwise operations2413if (!inputs.member(n)) {2414inputs.push(n);2415cnt++;2416}2417}2418return cnt;2419}24202421void Compile::collect_logic_cone_roots(Unique_Node_List& list) {2422Unique_Node_List useful_nodes;2423C->identify_useful_nodes(useful_nodes);24242425for (uint i = 0; i < useful_nodes.size(); i++) {2426Node* n = useful_nodes.at(i);2427if (is_vector_bitwise_cone_root(n)) {2428list.push(n);2429}2430}2431}24322433Node* Compile::xform_to_MacroLogicV(PhaseIterGVN& igvn,2434const TypeVect* vt,2435Unique_Node_List& partition,2436Unique_Node_List& inputs) {2437assert(partition.size() == 2 || partition.size() == 3, "not supported");2438assert(inputs.size() == 2 || inputs.size() == 3, "not supported");2439assert(Matcher::match_rule_supported_vector(Op_MacroLogicV, vt->length(), vt->element_basic_type()), "not supported");24402441Node* in1 = inputs.at(0);2442Node* in2 = inputs.at(1);2443Node* in3 = (inputs.size() == 3 ? inputs.at(2) : in2);24442445uint func = compute_truth_table(partition, inputs);2446return igvn.transform(MacroLogicVNode::make(igvn, in3, in2, in1, func, vt));2447}24482449static uint extract_bit(uint func, uint pos) {2450return (func & (1 << pos)) >> pos;2451}24522453//2454// A macro logic node represents a truth table. It has 4 inputs,2455// First three inputs corresponds to 3 columns of a truth table2456// and fourth input captures the logic function.2457//2458// eg. fn = (in1 AND in2) OR in3;2459//2460// MacroNode(in1,in2,in3,fn)2461//2462// -----------------2463// in1 in2 in3 fn2464// -----------------2465// 0 0 0 02466// 0 0 1 12467// 0 1 0 02468// 0 1 1 12469// 1 0 0 02470// 1 0 1 12471// 1 1 0 12472// 1 1 1 12473//24742475uint Compile::eval_macro_logic_op(uint func, uint in1 , uint in2, uint in3) {2476int res = 0;2477for (int i = 0; i < 8; i++) {2478int bit1 = extract_bit(in1, i);2479int bit2 = extract_bit(in2, i);2480int bit3 = extract_bit(in3, i);24812482int func_bit_pos = (bit1 << 2 | bit2 << 1 | bit3);2483int func_bit = extract_bit(func, func_bit_pos);24842485res |= func_bit << i;2486}2487return res;2488}24892490static uint eval_operand(Node* n, ResourceHashtable<Node*,uint>& eval_map) {2491assert(n != NULL, "");2492assert(eval_map.contains(n), "absent");2493return *(eval_map.get(n));2494}24952496static void eval_operands(Node* n,2497uint& func1, uint& func2, uint& func3,2498ResourceHashtable<Node*,uint>& eval_map) {2499assert(is_vector_bitwise_op(n), "");25002501if (is_vector_unary_bitwise_op(n)) {2502Node* opnd = n->in(1);2503if (VectorNode::is_vector_bitwise_not_pattern(n) && VectorNode::is_all_ones_vector(opnd)) {2504opnd = n->in(2);2505}2506func1 = eval_operand(opnd, eval_map);2507} else if (is_vector_binary_bitwise_op(n)) {2508func1 = eval_operand(n->in(1), eval_map);2509func2 = eval_operand(n->in(2), eval_map);2510} else {2511assert(is_vector_ternary_bitwise_op(n), "unknown operation");2512func1 = eval_operand(n->in(1), eval_map);2513func2 = eval_operand(n->in(2), eval_map);2514func3 = eval_operand(n->in(3), eval_map);2515}2516}25172518uint Compile::compute_truth_table(Unique_Node_List& partition, Unique_Node_List& inputs) {2519assert(inputs.size() <= 3, "sanity");2520ResourceMark rm;2521uint res = 0;2522ResourceHashtable<Node*,uint> eval_map;25232524// Populate precomputed functions for inputs.2525// Each input corresponds to one column of 3 input truth-table.2526uint input_funcs[] = { 0xAA, // (_, _, a) -> a25270xCC, // (_, b, _) -> b25280xF0 }; // (c, _, _) -> c2529for (uint i = 0; i < inputs.size(); i++) {2530eval_map.put(inputs.at(i), input_funcs[i]);2531}25322533for (uint i = 0; i < partition.size(); i++) {2534Node* n = partition.at(i);25352536uint func1 = 0, func2 = 0, func3 = 0;2537eval_operands(n, func1, func2, func3, eval_map);25382539switch (n->Opcode()) {2540case Op_OrV:2541assert(func3 == 0, "not binary");2542res = func1 | func2;2543break;2544case Op_AndV:2545assert(func3 == 0, "not binary");2546res = func1 & func2;2547break;2548case Op_XorV:2549if (VectorNode::is_vector_bitwise_not_pattern(n)) {2550assert(func2 == 0 && func3 == 0, "not unary");2551res = (~func1) & 0xFF;2552} else {2553assert(func3 == 0, "not binary");2554res = func1 ^ func2;2555}2556break;2557case Op_MacroLogicV:2558// Ordering of inputs may change during evaluation of sub-tree2559// containing MacroLogic node as a child node, thus a re-evaluation2560// makes sure that function is evaluated in context of current2561// inputs.2562res = eval_macro_logic_op(n->in(4)->get_int(), func1, func2, func3);2563break;25642565default: assert(false, "not supported: %s", n->Name());2566}2567assert(res <= 0xFF, "invalid");2568eval_map.put(n, res);2569}2570return res;2571}25722573bool Compile::compute_logic_cone(Node* n, Unique_Node_List& partition, Unique_Node_List& inputs) {2574assert(partition.size() == 0, "not empty");2575assert(inputs.size() == 0, "not empty");2576if (is_vector_ternary_bitwise_op(n)) {2577return false;2578}25792580bool is_unary_op = is_vector_unary_bitwise_op(n);2581if (is_unary_op) {2582assert(collect_unique_inputs(n, partition, inputs) == 1, "not unary");2583return false; // too few inputs2584}25852586assert(is_vector_binary_bitwise_op(n), "not binary");2587Node* in1 = n->in(1);2588Node* in2 = n->in(2);25892590int in1_unique_inputs_cnt = collect_unique_inputs(in1, partition, inputs);2591int in2_unique_inputs_cnt = collect_unique_inputs(in2, partition, inputs);2592partition.push(n);25932594// Too many inputs?2595if (inputs.size() > 3) {2596partition.clear();2597inputs.clear();2598{ // Recompute in2 inputs2599Unique_Node_List not_used;2600in2_unique_inputs_cnt = collect_unique_inputs(in2, not_used, not_used);2601}2602// Pick the node with minimum number of inputs.2603if (in1_unique_inputs_cnt >= 3 && in2_unique_inputs_cnt >= 3) {2604return false; // still too many inputs2605}2606// Recompute partition & inputs.2607Node* child = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in1 : in2);2608collect_unique_inputs(child, partition, inputs);26092610Node* other_input = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in2 : in1);2611inputs.push(other_input);26122613partition.push(n);2614}26152616return (partition.size() == 2 || partition.size() == 3) &&2617(inputs.size() == 2 || inputs.size() == 3);2618}261926202621void Compile::process_logic_cone_root(PhaseIterGVN &igvn, Node *n, VectorSet &visited) {2622assert(is_vector_bitwise_op(n), "not a root");26232624visited.set(n->_idx);26252626// 1) Do a DFS walk over the logic cone.2627for (uint i = 1; i < n->req(); i++) {2628Node* in = n->in(i);2629if (!visited.test(in->_idx) && is_vector_bitwise_op(in)) {2630process_logic_cone_root(igvn, in, visited);2631}2632}26332634// 2) Bottom up traversal: Merge node[s] with2635// the parent to form macro logic node.2636Unique_Node_List partition;2637Unique_Node_List inputs;2638if (compute_logic_cone(n, partition, inputs)) {2639const TypeVect* vt = n->bottom_type()->is_vect();2640Node* macro_logic = xform_to_MacroLogicV(igvn, vt, partition, inputs);2641igvn.replace_node(n, macro_logic);2642}2643}26442645void Compile::optimize_logic_cones(PhaseIterGVN &igvn) {2646ResourceMark rm;2647if (Matcher::match_rule_supported(Op_MacroLogicV)) {2648Unique_Node_List list;2649collect_logic_cone_roots(list);26502651while (list.size() > 0) {2652Node* n = list.pop();2653const TypeVect* vt = n->bottom_type()->is_vect();2654bool supported = Matcher::match_rule_supported_vector(Op_MacroLogicV, vt->length(), vt->element_basic_type());2655if (supported) {2656VectorSet visited(comp_arena());2657process_logic_cone_root(igvn, n, visited);2658}2659}2660}2661}26622663//------------------------------Code_Gen---------------------------------------2664// Given a graph, generate code for it2665void Compile::Code_Gen() {2666if (failing()) {2667return;2668}26692670// Perform instruction selection. You might think we could reclaim Matcher2671// memory PDQ, but actually the Matcher is used in generating spill code.2672// Internals of the Matcher (including some VectorSets) must remain live2673// for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage2674// set a bit in reclaimed memory.26752676// In debug mode can dump m._nodes.dump() for mapping of ideal to machine2677// nodes. Mapping is only valid at the root of each matched subtree.2678NOT_PRODUCT( verify_graph_edges(); )26792680Matcher matcher;2681_matcher = &matcher;2682{2683TracePhase tp("matcher", &timers[_t_matcher]);2684matcher.match();2685if (failing()) {2686return;2687}2688}2689// In debug mode can dump m._nodes.dump() for mapping of ideal to machine2690// nodes. Mapping is only valid at the root of each matched subtree.2691NOT_PRODUCT( verify_graph_edges(); )26922693// If you have too many nodes, or if matching has failed, bail out2694check_node_count(0, "out of nodes matching instructions");2695if (failing()) {2696return;2697}26982699print_method(PHASE_MATCHING, 2);27002701// Build a proper-looking CFG2702PhaseCFG cfg(node_arena(), root(), matcher);2703_cfg = &cfg;2704{2705TracePhase tp("scheduler", &timers[_t_scheduler]);2706bool success = cfg.do_global_code_motion();2707if (!success) {2708return;2709}27102711print_method(PHASE_GLOBAL_CODE_MOTION, 2);2712NOT_PRODUCT( verify_graph_edges(); )2713cfg.verify();2714}27152716PhaseChaitin regalloc(unique(), cfg, matcher, false);2717_regalloc = ®alloc;2718{2719TracePhase tp("regalloc", &timers[_t_registerAllocation]);2720// Perform register allocation. After Chaitin, use-def chains are2721// no longer accurate (at spill code) and so must be ignored.2722// Node->LRG->reg mappings are still accurate.2723_regalloc->Register_Allocate();27242725// Bail out if the allocator builds too many nodes2726if (failing()) {2727return;2728}2729}27302731// Prior to register allocation we kept empty basic blocks in case the2732// the allocator needed a place to spill. After register allocation we2733// are not adding any new instructions. If any basic block is empty, we2734// can now safely remove it.2735{2736TracePhase tp("blockOrdering", &timers[_t_blockOrdering]);2737cfg.remove_empty_blocks();2738if (do_freq_based_layout()) {2739PhaseBlockLayout layout(cfg);2740} else {2741cfg.set_loop_alignment();2742}2743cfg.fixup_flow();2744}27452746// Apply peephole optimizations2747if( OptoPeephole ) {2748TracePhase tp("peephole", &timers[_t_peephole]);2749PhasePeephole peep( _regalloc, cfg);2750peep.do_transform();2751}27522753// Do late expand if CPU requires this.2754if (Matcher::require_postalloc_expand) {2755TracePhase tp("postalloc_expand", &timers[_t_postalloc_expand]);2756cfg.postalloc_expand(_regalloc);2757}27582759// Convert Nodes to instruction bits in a buffer2760{2761TracePhase tp("output", &timers[_t_output]);2762PhaseOutput output;2763output.Output();2764if (failing()) return;2765output.install();2766}27672768print_method(PHASE_FINAL_CODE);27692770// He's dead, Jim.2771_cfg = (PhaseCFG*)((intptr_t)0xdeadbeef);2772_regalloc = (PhaseChaitin*)((intptr_t)0xdeadbeef);2773}27742775//------------------------------Final_Reshape_Counts---------------------------2776// This class defines counters to help identify when a method2777// may/must be executed using hardware with only 24-bit precision.2778struct Final_Reshape_Counts : public StackObj {2779int _call_count; // count non-inlined 'common' calls2780int _float_count; // count float ops requiring 24-bit precision2781int _double_count; // count double ops requiring more precision2782int _java_call_count; // count non-inlined 'java' calls2783int _inner_loop_count; // count loops which need alignment2784VectorSet _visited; // Visitation flags2785Node_List _tests; // Set of IfNodes & PCTableNodes27862787Final_Reshape_Counts() :2788_call_count(0), _float_count(0), _double_count(0),2789_java_call_count(0), _inner_loop_count(0) { }27902791void inc_call_count () { _call_count ++; }2792void inc_float_count () { _float_count ++; }2793void inc_double_count() { _double_count++; }2794void inc_java_call_count() { _java_call_count++; }2795void inc_inner_loop_count() { _inner_loop_count++; }27962797int get_call_count () const { return _call_count ; }2798int get_float_count () const { return _float_count ; }2799int get_double_count() const { return _double_count; }2800int get_java_call_count() const { return _java_call_count; }2801int get_inner_loop_count() const { return _inner_loop_count; }2802};28032804// Eliminate trivially redundant StoreCMs and accumulate their2805// precedence edges.2806void Compile::eliminate_redundant_card_marks(Node* n) {2807assert(n->Opcode() == Op_StoreCM, "expected StoreCM");2808if (n->in(MemNode::Address)->outcnt() > 1) {2809// There are multiple users of the same address so it might be2810// possible to eliminate some of the StoreCMs2811Node* mem = n->in(MemNode::Memory);2812Node* adr = n->in(MemNode::Address);2813Node* val = n->in(MemNode::ValueIn);2814Node* prev = n;2815bool done = false;2816// Walk the chain of StoreCMs eliminating ones that match. As2817// long as it's a chain of single users then the optimization is2818// safe. Eliminating partially redundant StoreCMs would require2819// cloning copies down the other paths.2820while (mem->Opcode() == Op_StoreCM && mem->outcnt() == 1 && !done) {2821if (adr == mem->in(MemNode::Address) &&2822val == mem->in(MemNode::ValueIn)) {2823// redundant StoreCM2824if (mem->req() > MemNode::OopStore) {2825// Hasn't been processed by this code yet.2826n->add_prec(mem->in(MemNode::OopStore));2827} else {2828// Already converted to precedence edge2829for (uint i = mem->req(); i < mem->len(); i++) {2830// Accumulate any precedence edges2831if (mem->in(i) != NULL) {2832n->add_prec(mem->in(i));2833}2834}2835// Everything above this point has been processed.2836done = true;2837}2838// Eliminate the previous StoreCM2839prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));2840assert(mem->outcnt() == 0, "should be dead");2841mem->disconnect_inputs(this);2842} else {2843prev = mem;2844}2845mem = prev->in(MemNode::Memory);2846}2847}2848}28492850//------------------------------final_graph_reshaping_impl----------------------2851// Implement items 1-5 from final_graph_reshaping below.2852void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {28532854if ( n->outcnt() == 0 ) return; // dead node2855uint nop = n->Opcode();28562857// Check for 2-input instruction with "last use" on right input.2858// Swap to left input. Implements item (2).2859if( n->req() == 3 && // two-input instruction2860n->in(1)->outcnt() > 1 && // left use is NOT a last use2861(!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop2862n->in(2)->outcnt() == 1 &&// right use IS a last use2863!n->in(2)->is_Con() ) { // right use is not a constant2864// Check for commutative opcode2865switch( nop ) {2866case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:2867case Op_MaxI: case Op_MaxL: case Op_MaxF: case Op_MaxD:2868case Op_MinI: case Op_MinL: case Op_MinF: case Op_MinD:2869case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:2870case Op_AndL: case Op_XorL: case Op_OrL:2871case Op_AndI: case Op_XorI: case Op_OrI: {2872// Move "last use" input to left by swapping inputs2873n->swap_edges(1, 2);2874break;2875}2876default:2877break;2878}2879}28802881#ifdef ASSERT2882if( n->is_Mem() ) {2883int alias_idx = get_alias_index(n->as_Mem()->adr_type());2884assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||2885// oop will be recorded in oop map if load crosses safepoint2886n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||2887LoadNode::is_immutable_value(n->in(MemNode::Address))),2888"raw memory operations should have control edge");2889}2890if (n->is_MemBar()) {2891MemBarNode* mb = n->as_MemBar();2892if (mb->trailing_store() || mb->trailing_load_store()) {2893assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");2894Node* mem = BarrierSet::barrier_set()->barrier_set_c2()->step_over_gc_barrier(mb->in(MemBarNode::Precedent));2895assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||2896(mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");2897} else if (mb->leading()) {2898assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");2899}2900}2901#endif2902// Count FPU ops and common calls, implements item (3)2903bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->final_graph_reshaping(this, n, nop);2904if (!gc_handled) {2905final_graph_reshaping_main_switch(n, frc, nop);2906}29072908// Collect CFG split points2909if (n->is_MultiBranch() && !n->is_RangeCheck()) {2910frc._tests.push(n);2911}2912}29132914void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop) {2915switch( nop ) {2916// Count all float operations that may use FPU2917case Op_AddF:2918case Op_SubF:2919case Op_MulF:2920case Op_DivF:2921case Op_NegF:2922case Op_ModF:2923case Op_ConvI2F:2924case Op_ConF:2925case Op_CmpF:2926case Op_CmpF3:2927case Op_StoreF:2928case Op_LoadF:2929// case Op_ConvL2F: // longs are split into 32-bit halves2930frc.inc_float_count();2931break;29322933case Op_ConvF2D:2934case Op_ConvD2F:2935frc.inc_float_count();2936frc.inc_double_count();2937break;29382939// Count all double operations that may use FPU2940case Op_AddD:2941case Op_SubD:2942case Op_MulD:2943case Op_DivD:2944case Op_NegD:2945case Op_ModD:2946case Op_ConvI2D:2947case Op_ConvD2I:2948// case Op_ConvL2D: // handled by leaf call2949// case Op_ConvD2L: // handled by leaf call2950case Op_ConD:2951case Op_CmpD:2952case Op_CmpD3:2953case Op_StoreD:2954case Op_LoadD:2955case Op_LoadD_unaligned:2956frc.inc_double_count();2957break;2958case Op_Opaque1: // Remove Opaque Nodes before matching2959case Op_Opaque2: // Remove Opaque Nodes before matching2960case Op_Opaque3:2961n->subsume_by(n->in(1), this);2962break;2963case Op_CallStaticJava:2964case Op_CallJava:2965case Op_CallDynamicJava:2966frc.inc_java_call_count(); // Count java call site;2967case Op_CallRuntime:2968case Op_CallLeaf:2969case Op_CallLeafVector:2970case Op_CallNative:2971case Op_CallLeafNoFP: {2972assert (n->is_Call(), "");2973CallNode *call = n->as_Call();2974// Count call sites where the FP mode bit would have to be flipped.2975// Do not count uncommon runtime calls:2976// uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,2977// _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...2978if (!call->is_CallStaticJava() || !call->as_CallStaticJava()->_name) {2979frc.inc_call_count(); // Count the call site2980} else { // See if uncommon argument is shared2981Node *n = call->in(TypeFunc::Parms);2982int nop = n->Opcode();2983// Clone shared simple arguments to uncommon calls, item (1).2984if (n->outcnt() > 1 &&2985!n->is_Proj() &&2986nop != Op_CreateEx &&2987nop != Op_CheckCastPP &&2988nop != Op_DecodeN &&2989nop != Op_DecodeNKlass &&2990!n->is_Mem() &&2991!n->is_Phi()) {2992Node *x = n->clone();2993call->set_req(TypeFunc::Parms, x);2994}2995}2996break;2997}29982999case Op_StoreCM:3000{3001// Convert OopStore dependence into precedence edge3002Node* prec = n->in(MemNode::OopStore);3003n->del_req(MemNode::OopStore);3004n->add_prec(prec);3005eliminate_redundant_card_marks(n);3006}30073008// fall through30093010case Op_StoreB:3011case Op_StoreC:3012case Op_StorePConditional:3013case Op_StoreI:3014case Op_StoreL:3015case Op_StoreIConditional:3016case Op_StoreLConditional:3017case Op_CompareAndSwapB:3018case Op_CompareAndSwapS:3019case Op_CompareAndSwapI:3020case Op_CompareAndSwapL:3021case Op_CompareAndSwapP:3022case Op_CompareAndSwapN:3023case Op_WeakCompareAndSwapB:3024case Op_WeakCompareAndSwapS:3025case Op_WeakCompareAndSwapI:3026case Op_WeakCompareAndSwapL:3027case Op_WeakCompareAndSwapP:3028case Op_WeakCompareAndSwapN:3029case Op_CompareAndExchangeB:3030case Op_CompareAndExchangeS:3031case Op_CompareAndExchangeI:3032case Op_CompareAndExchangeL:3033case Op_CompareAndExchangeP:3034case Op_CompareAndExchangeN:3035case Op_GetAndAddS:3036case Op_GetAndAddB:3037case Op_GetAndAddI:3038case Op_GetAndAddL:3039case Op_GetAndSetS:3040case Op_GetAndSetB:3041case Op_GetAndSetI:3042case Op_GetAndSetL:3043case Op_GetAndSetP:3044case Op_GetAndSetN:3045case Op_StoreP:3046case Op_StoreN:3047case Op_StoreNKlass:3048case Op_LoadB:3049case Op_LoadUB:3050case Op_LoadUS:3051case Op_LoadI:3052case Op_LoadKlass:3053case Op_LoadNKlass:3054case Op_LoadL:3055case Op_LoadL_unaligned:3056case Op_LoadPLocked:3057case Op_LoadP:3058case Op_LoadN:3059case Op_LoadRange:3060case Op_LoadS:3061break;30623063case Op_AddP: { // Assert sane base pointers3064Node *addp = n->in(AddPNode::Address);3065assert( !addp->is_AddP() ||3066addp->in(AddPNode::Base)->is_top() || // Top OK for allocation3067addp->in(AddPNode::Base) == n->in(AddPNode::Base),3068"Base pointers must match (addp %u)", addp->_idx );3069#ifdef _LP643070if ((UseCompressedOops || UseCompressedClassPointers) &&3071addp->Opcode() == Op_ConP &&3072addp == n->in(AddPNode::Base) &&3073n->in(AddPNode::Offset)->is_Con()) {3074// If the transformation of ConP to ConN+DecodeN is beneficial depends3075// on the platform and on the compressed oops mode.3076// Use addressing with narrow klass to load with offset on x86.3077// Some platforms can use the constant pool to load ConP.3078// Do this transformation here since IGVN will convert ConN back to ConP.3079const Type* t = addp->bottom_type();3080bool is_oop = t->isa_oopptr() != NULL;3081bool is_klass = t->isa_klassptr() != NULL;30823083if ((is_oop && Matcher::const_oop_prefer_decode() ) ||3084(is_klass && Matcher::const_klass_prefer_decode())) {3085Node* nn = NULL;30863087int op = is_oop ? Op_ConN : Op_ConNKlass;30883089// Look for existing ConN node of the same exact type.3090Node* r = root();3091uint cnt = r->outcnt();3092for (uint i = 0; i < cnt; i++) {3093Node* m = r->raw_out(i);3094if (m!= NULL && m->Opcode() == op &&3095m->bottom_type()->make_ptr() == t) {3096nn = m;3097break;3098}3099}3100if (nn != NULL) {3101// Decode a narrow oop to match address3102// [R12 + narrow_oop_reg<<3 + offset]3103if (is_oop) {3104nn = new DecodeNNode(nn, t);3105} else {3106nn = new DecodeNKlassNode(nn, t);3107}3108// Check for succeeding AddP which uses the same Base.3109// Otherwise we will run into the assertion above when visiting that guy.3110for (uint i = 0; i < n->outcnt(); ++i) {3111Node *out_i = n->raw_out(i);3112if (out_i && out_i->is_AddP() && out_i->in(AddPNode::Base) == addp) {3113out_i->set_req(AddPNode::Base, nn);3114#ifdef ASSERT3115for (uint j = 0; j < out_i->outcnt(); ++j) {3116Node *out_j = out_i->raw_out(j);3117assert(out_j == NULL || !out_j->is_AddP() || out_j->in(AddPNode::Base) != addp,3118"more than 2 AddP nodes in a chain (out_j %u)", out_j->_idx);3119}3120#endif3121}3122}3123n->set_req(AddPNode::Base, nn);3124n->set_req(AddPNode::Address, nn);3125if (addp->outcnt() == 0) {3126addp->disconnect_inputs(this);3127}3128}3129}3130}3131#endif3132break;3133}31343135case Op_CastPP: {3136// Remove CastPP nodes to gain more freedom during scheduling but3137// keep the dependency they encode as control or precedence edges3138// (if control is set already) on memory operations. Some CastPP3139// nodes don't have a control (don't carry a dependency): skip3140// those.3141if (n->in(0) != NULL) {3142ResourceMark rm;3143Unique_Node_List wq;3144wq.push(n);3145for (uint next = 0; next < wq.size(); ++next) {3146Node *m = wq.at(next);3147for (DUIterator_Fast imax, i = m->fast_outs(imax); i < imax; i++) {3148Node* use = m->fast_out(i);3149if (use->is_Mem() || use->is_EncodeNarrowPtr()) {3150use->ensure_control_or_add_prec(n->in(0));3151} else {3152switch(use->Opcode()) {3153case Op_AddP:3154case Op_DecodeN:3155case Op_DecodeNKlass:3156case Op_CheckCastPP:3157case Op_CastPP:3158wq.push(use);3159break;3160}3161}3162}3163}3164}3165const bool is_LP64 = LP64_ONLY(true) NOT_LP64(false);3166if (is_LP64 && n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) {3167Node* in1 = n->in(1);3168const Type* t = n->bottom_type();3169Node* new_in1 = in1->clone();3170new_in1->as_DecodeN()->set_type(t);31713172if (!Matcher::narrow_oop_use_complex_address()) {3173//3174// x86, ARM and friends can handle 2 adds in addressing mode3175// and Matcher can fold a DecodeN node into address by using3176// a narrow oop directly and do implicit NULL check in address:3177//3178// [R12 + narrow_oop_reg<<3 + offset]3179// NullCheck narrow_oop_reg3180//3181// On other platforms (Sparc) we have to keep new DecodeN node and3182// use it to do implicit NULL check in address:3183//3184// decode_not_null narrow_oop_reg, base_reg3185// [base_reg + offset]3186// NullCheck base_reg3187//3188// Pin the new DecodeN node to non-null path on these platform (Sparc)3189// to keep the information to which NULL check the new DecodeN node3190// corresponds to use it as value in implicit_null_check().3191//3192new_in1->set_req(0, n->in(0));3193}31943195n->subsume_by(new_in1, this);3196if (in1->outcnt() == 0) {3197in1->disconnect_inputs(this);3198}3199} else {3200n->subsume_by(n->in(1), this);3201if (n->outcnt() == 0) {3202n->disconnect_inputs(this);3203}3204}3205break;3206}3207#ifdef _LP643208case Op_CmpP:3209// Do this transformation here to preserve CmpPNode::sub() and3210// other TypePtr related Ideal optimizations (for example, ptr nullness).3211if (n->in(1)->is_DecodeNarrowPtr() || n->in(2)->is_DecodeNarrowPtr()) {3212Node* in1 = n->in(1);3213Node* in2 = n->in(2);3214if (!in1->is_DecodeNarrowPtr()) {3215in2 = in1;3216in1 = n->in(2);3217}3218assert(in1->is_DecodeNarrowPtr(), "sanity");32193220Node* new_in2 = NULL;3221if (in2->is_DecodeNarrowPtr()) {3222assert(in2->Opcode() == in1->Opcode(), "must be same node type");3223new_in2 = in2->in(1);3224} else if (in2->Opcode() == Op_ConP) {3225const Type* t = in2->bottom_type();3226if (t == TypePtr::NULL_PTR) {3227assert(in1->is_DecodeN(), "compare klass to null?");3228// Don't convert CmpP null check into CmpN if compressed3229// oops implicit null check is not generated.3230// This will allow to generate normal oop implicit null check.3231if (Matcher::gen_narrow_oop_implicit_null_checks())3232new_in2 = ConNode::make(TypeNarrowOop::NULL_PTR);3233//3234// This transformation together with CastPP transformation above3235// will generated code for implicit NULL checks for compressed oops.3236//3237// The original code after Optimize()3238//3239// LoadN memory, narrow_oop_reg3240// decode narrow_oop_reg, base_reg3241// CmpP base_reg, NULL3242// CastPP base_reg // NotNull3243// Load [base_reg + offset], val_reg3244//3245// after these transformations will be3246//3247// LoadN memory, narrow_oop_reg3248// CmpN narrow_oop_reg, NULL3249// decode_not_null narrow_oop_reg, base_reg3250// Load [base_reg + offset], val_reg3251//3252// and the uncommon path (== NULL) will use narrow_oop_reg directly3253// since narrow oops can be used in debug info now (see the code in3254// final_graph_reshaping_walk()).3255//3256// At the end the code will be matched to3257// on x86:3258//3259// Load_narrow_oop memory, narrow_oop_reg3260// Load [R12 + narrow_oop_reg<<3 + offset], val_reg3261// NullCheck narrow_oop_reg3262//3263// and on sparc:3264//3265// Load_narrow_oop memory, narrow_oop_reg3266// decode_not_null narrow_oop_reg, base_reg3267// Load [base_reg + offset], val_reg3268// NullCheck base_reg3269//3270} else if (t->isa_oopptr()) {3271new_in2 = ConNode::make(t->make_narrowoop());3272} else if (t->isa_klassptr()) {3273new_in2 = ConNode::make(t->make_narrowklass());3274}3275}3276if (new_in2 != NULL) {3277Node* cmpN = new CmpNNode(in1->in(1), new_in2);3278n->subsume_by(cmpN, this);3279if (in1->outcnt() == 0) {3280in1->disconnect_inputs(this);3281}3282if (in2->outcnt() == 0) {3283in2->disconnect_inputs(this);3284}3285}3286}3287break;32883289case Op_DecodeN:3290case Op_DecodeNKlass:3291assert(!n->in(1)->is_EncodeNarrowPtr(), "should be optimized out");3292// DecodeN could be pinned when it can't be fold into3293// an address expression, see the code for Op_CastPP above.3294assert(n->in(0) == NULL || (UseCompressedOops && !Matcher::narrow_oop_use_complex_address()), "no control");3295break;32963297case Op_EncodeP:3298case Op_EncodePKlass: {3299Node* in1 = n->in(1);3300if (in1->is_DecodeNarrowPtr()) {3301n->subsume_by(in1->in(1), this);3302} else if (in1->Opcode() == Op_ConP) {3303const Type* t = in1->bottom_type();3304if (t == TypePtr::NULL_PTR) {3305assert(t->isa_oopptr(), "null klass?");3306n->subsume_by(ConNode::make(TypeNarrowOop::NULL_PTR), this);3307} else if (t->isa_oopptr()) {3308n->subsume_by(ConNode::make(t->make_narrowoop()), this);3309} else if (t->isa_klassptr()) {3310n->subsume_by(ConNode::make(t->make_narrowklass()), this);3311}3312}3313if (in1->outcnt() == 0) {3314in1->disconnect_inputs(this);3315}3316break;3317}33183319case Op_Proj: {3320if (OptimizeStringConcat || IncrementalInline) {3321ProjNode* proj = n->as_Proj();3322if (proj->_is_io_use) {3323assert(proj->_con == TypeFunc::I_O || proj->_con == TypeFunc::Memory, "");3324// Separate projections were used for the exception path which3325// are normally removed by a late inline. If it wasn't inlined3326// then they will hang around and should just be replaced with3327// the original one. Merge them.3328Node* non_io_proj = proj->in(0)->as_Multi()->proj_out_or_null(proj->_con, false /*is_io_use*/);3329if (non_io_proj != NULL) {3330proj->subsume_by(non_io_proj , this);3331}3332}3333}3334break;3335}33363337case Op_Phi:3338if (n->as_Phi()->bottom_type()->isa_narrowoop() || n->as_Phi()->bottom_type()->isa_narrowklass()) {3339// The EncodeP optimization may create Phi with the same edges3340// for all paths. It is not handled well by Register Allocator.3341Node* unique_in = n->in(1);3342assert(unique_in != NULL, "");3343uint cnt = n->req();3344for (uint i = 2; i < cnt; i++) {3345Node* m = n->in(i);3346assert(m != NULL, "");3347if (unique_in != m)3348unique_in = NULL;3349}3350if (unique_in != NULL) {3351n->subsume_by(unique_in, this);3352}3353}3354break;33553356#endif33573358#ifdef ASSERT3359case Op_CastII:3360// Verify that all range check dependent CastII nodes were removed.3361if (n->isa_CastII()->has_range_check()) {3362n->dump(3);3363assert(false, "Range check dependent CastII node was not removed");3364}3365break;3366#endif33673368case Op_ModI:3369if (UseDivMod) {3370// Check if a%b and a/b both exist3371Node* d = n->find_similar(Op_DivI);3372if (d) {3373// Replace them with a fused divmod if supported3374if (Matcher::has_match_rule(Op_DivModI)) {3375DivModINode* divmod = DivModINode::make(n);3376d->subsume_by(divmod->div_proj(), this);3377n->subsume_by(divmod->mod_proj(), this);3378} else {3379// replace a%b with a-((a/b)*b)3380Node* mult = new MulINode(d, d->in(2));3381Node* sub = new SubINode(d->in(1), mult);3382n->subsume_by(sub, this);3383}3384}3385}3386break;33873388case Op_ModL:3389if (UseDivMod) {3390// Check if a%b and a/b both exist3391Node* d = n->find_similar(Op_DivL);3392if (d) {3393// Replace them with a fused divmod if supported3394if (Matcher::has_match_rule(Op_DivModL)) {3395DivModLNode* divmod = DivModLNode::make(n);3396d->subsume_by(divmod->div_proj(), this);3397n->subsume_by(divmod->mod_proj(), this);3398} else {3399// replace a%b with a-((a/b)*b)3400Node* mult = new MulLNode(d, d->in(2));3401Node* sub = new SubLNode(d->in(1), mult);3402n->subsume_by(sub, this);3403}3404}3405}3406break;34073408case Op_LoadVector:3409case Op_StoreVector:3410case Op_LoadVectorGather:3411case Op_StoreVectorScatter:3412case Op_VectorMaskGen:3413case Op_LoadVectorMasked:3414case Op_StoreVectorMasked:3415break;34163417case Op_AddReductionVI:3418case Op_AddReductionVL:3419case Op_AddReductionVF:3420case Op_AddReductionVD:3421case Op_MulReductionVI:3422case Op_MulReductionVL:3423case Op_MulReductionVF:3424case Op_MulReductionVD:3425case Op_MinReductionV:3426case Op_MaxReductionV:3427case Op_AndReductionV:3428case Op_OrReductionV:3429case Op_XorReductionV:3430break;34313432case Op_PackB:3433case Op_PackS:3434case Op_PackI:3435case Op_PackF:3436case Op_PackL:3437case Op_PackD:3438if (n->req()-1 > 2) {3439// Replace many operand PackNodes with a binary tree for matching3440PackNode* p = (PackNode*) n;3441Node* btp = p->binary_tree_pack(1, n->req());3442n->subsume_by(btp, this);3443}3444break;3445case Op_Loop:3446assert(!n->as_Loop()->is_transformed_long_inner_loop() || _loop_opts_cnt == 0, "should have been turned into a counted loop");3447case Op_CountedLoop:3448case Op_LongCountedLoop:3449case Op_OuterStripMinedLoop:3450if (n->as_Loop()->is_inner_loop()) {3451frc.inc_inner_loop_count();3452}3453n->as_Loop()->verify_strip_mined(0);3454break;3455case Op_LShiftI:3456case Op_RShiftI:3457case Op_URShiftI:3458case Op_LShiftL:3459case Op_RShiftL:3460case Op_URShiftL:3461if (Matcher::need_masked_shift_count) {3462// The cpu's shift instructions don't restrict the count to the3463// lower 5/6 bits. We need to do the masking ourselves.3464Node* in2 = n->in(2);3465juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1);3466const TypeInt* t = in2->find_int_type();3467if (t != NULL && t->is_con()) {3468juint shift = t->get_con();3469if (shift > mask) { // Unsigned cmp3470n->set_req(2, ConNode::make(TypeInt::make(shift & mask)));3471}3472} else {3473if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) {3474Node* shift = new AndINode(in2, ConNode::make(TypeInt::make(mask)));3475n->set_req(2, shift);3476}3477}3478if (in2->outcnt() == 0) { // Remove dead node3479in2->disconnect_inputs(this);3480}3481}3482break;3483case Op_MemBarStoreStore:3484case Op_MemBarRelease:3485// Break the link with AllocateNode: it is no longer useful and3486// confuses register allocation.3487if (n->req() > MemBarNode::Precedent) {3488n->set_req(MemBarNode::Precedent, top());3489}3490break;3491case Op_MemBarAcquire: {3492if (n->as_MemBar()->trailing_load() && n->req() > MemBarNode::Precedent) {3493// At parse time, the trailing MemBarAcquire for a volatile load3494// is created with an edge to the load. After optimizations,3495// that input may be a chain of Phis. If those phis have no3496// other use, then the MemBarAcquire keeps them alive and3497// register allocation can be confused.3498ResourceMark rm;3499Unique_Node_List wq;3500wq.push(n->in(MemBarNode::Precedent));3501n->set_req(MemBarNode::Precedent, top());3502while (wq.size() > 0) {3503Node* m = wq.pop();3504if (m->outcnt() == 0) {3505for (uint j = 0; j < m->req(); j++) {3506Node* in = m->in(j);3507if (in != NULL) {3508wq.push(in);3509}3510}3511m->disconnect_inputs(this);3512}3513}3514}3515break;3516}3517case Op_Blackhole:3518break;3519case Op_RangeCheck: {3520RangeCheckNode* rc = n->as_RangeCheck();3521Node* iff = new IfNode(rc->in(0), rc->in(1), rc->_prob, rc->_fcnt);3522n->subsume_by(iff, this);3523frc._tests.push(iff);3524break;3525}3526case Op_ConvI2L: {3527if (!Matcher::convi2l_type_required) {3528// Code generation on some platforms doesn't need accurate3529// ConvI2L types. Widening the type can help remove redundant3530// address computations.3531n->as_Type()->set_type(TypeLong::INT);3532ResourceMark rm;3533Unique_Node_List wq;3534wq.push(n);3535for (uint next = 0; next < wq.size(); next++) {3536Node *m = wq.at(next);35373538for(;;) {3539// Loop over all nodes with identical inputs edges as m3540Node* k = m->find_similar(m->Opcode());3541if (k == NULL) {3542break;3543}3544// Push their uses so we get a chance to remove node made3545// redundant3546for (DUIterator_Fast imax, i = k->fast_outs(imax); i < imax; i++) {3547Node* u = k->fast_out(i);3548if (u->Opcode() == Op_LShiftL ||3549u->Opcode() == Op_AddL ||3550u->Opcode() == Op_SubL ||3551u->Opcode() == Op_AddP) {3552wq.push(u);3553}3554}3555// Replace all nodes with identical edges as m with m3556k->subsume_by(m, this);3557}3558}3559}3560break;3561}3562case Op_CmpUL: {3563if (!Matcher::has_match_rule(Op_CmpUL)) {3564// No support for unsigned long comparisons3565ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));3566Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);3567Node* orl = new OrLNode(n->in(1), sign_bit_mask);3568ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));3569Node* andl = new AndLNode(orl, remove_sign_mask);3570Node* cmp = new CmpLNode(andl, n->in(2));3571n->subsume_by(cmp, this);3572}3573break;3574}3575default:3576assert(!n->is_Call(), "");3577assert(!n->is_Mem(), "");3578assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");3579break;3580}3581}35823583//------------------------------final_graph_reshaping_walk---------------------3584// Replacing Opaque nodes with their input in final_graph_reshaping_impl(),3585// requires that the walk visits a node's inputs before visiting the node.3586void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {3587Unique_Node_List sfpt;35883589frc._visited.set(root->_idx); // first, mark node as visited3590uint cnt = root->req();3591Node *n = root;3592uint i = 0;3593while (true) {3594if (i < cnt) {3595// Place all non-visited non-null inputs onto stack3596Node* m = n->in(i);3597++i;3598if (m != NULL && !frc._visited.test_set(m->_idx)) {3599if (m->is_SafePoint() && m->as_SafePoint()->jvms() != NULL) {3600// compute worst case interpreter size in case of a deoptimization3601update_interpreter_frame_size(m->as_SafePoint()->jvms()->interpreter_frame_size());36023603sfpt.push(m);3604}3605cnt = m->req();3606nstack.push(n, i); // put on stack parent and next input's index3607n = m;3608i = 0;3609}3610} else {3611// Now do post-visit work3612final_graph_reshaping_impl( n, frc );3613if (nstack.is_empty())3614break; // finished3615n = nstack.node(); // Get node from stack3616cnt = n->req();3617i = nstack.index();3618nstack.pop(); // Shift to the next node on stack3619}3620}36213622// Skip next transformation if compressed oops are not used.3623if ((UseCompressedOops && !Matcher::gen_narrow_oop_implicit_null_checks()) ||3624(!UseCompressedOops && !UseCompressedClassPointers))3625return;36263627// Go over safepoints nodes to skip DecodeN/DecodeNKlass nodes for debug edges.3628// It could be done for an uncommon traps or any safepoints/calls3629// if the DecodeN/DecodeNKlass node is referenced only in a debug info.3630while (sfpt.size() > 0) {3631n = sfpt.pop();3632JVMState *jvms = n->as_SafePoint()->jvms();3633assert(jvms != NULL, "sanity");3634int start = jvms->debug_start();3635int end = n->req();3636bool is_uncommon = (n->is_CallStaticJava() &&3637n->as_CallStaticJava()->uncommon_trap_request() != 0);3638for (int j = start; j < end; j++) {3639Node* in = n->in(j);3640if (in->is_DecodeNarrowPtr()) {3641bool safe_to_skip = true;3642if (!is_uncommon ) {3643// Is it safe to skip?3644for (uint i = 0; i < in->outcnt(); i++) {3645Node* u = in->raw_out(i);3646if (!u->is_SafePoint() ||3647(u->is_Call() && u->as_Call()->has_non_debug_use(n))) {3648safe_to_skip = false;3649}3650}3651}3652if (safe_to_skip) {3653n->set_req(j, in->in(1));3654}3655if (in->outcnt() == 0) {3656in->disconnect_inputs(this);3657}3658}3659}3660}3661}36623663//------------------------------final_graph_reshaping--------------------------3664// Final Graph Reshaping.3665//3666// (1) Clone simple inputs to uncommon calls, so they can be scheduled late3667// and not commoned up and forced early. Must come after regular3668// optimizations to avoid GVN undoing the cloning. Clone constant3669// inputs to Loop Phis; these will be split by the allocator anyways.3670// Remove Opaque nodes.3671// (2) Move last-uses by commutative operations to the left input to encourage3672// Intel update-in-place two-address operations and better register usage3673// on RISCs. Must come after regular optimizations to avoid GVN Ideal3674// calls canonicalizing them back.3675// (3) Count the number of double-precision FP ops, single-precision FP ops3676// and call sites. On Intel, we can get correct rounding either by3677// forcing singles to memory (requires extra stores and loads after each3678// FP bytecode) or we can set a rounding mode bit (requires setting and3679// clearing the mode bit around call sites). The mode bit is only used3680// if the relative frequency of single FP ops to calls is low enough.3681// This is a key transform for SPEC mpeg_audio.3682// (4) Detect infinite loops; blobs of code reachable from above but not3683// below. Several of the Code_Gen algorithms fail on such code shapes,3684// so we simply bail out. Happens a lot in ZKM.jar, but also happens3685// from time to time in other codes (such as -Xcomp finalizer loops, etc).3686// Detection is by looking for IfNodes where only 1 projection is3687// reachable from below or CatchNodes missing some targets.3688// (5) Assert for insane oop offsets in debug mode.36893690bool Compile::final_graph_reshaping() {3691// an infinite loop may have been eliminated by the optimizer,3692// in which case the graph will be empty.3693if (root()->req() == 1) {3694record_method_not_compilable("trivial infinite loop");3695return true;3696}36973698// Expensive nodes have their control input set to prevent the GVN3699// from freely commoning them. There's no GVN beyond this point so3700// no need to keep the control input. We want the expensive nodes to3701// be freely moved to the least frequent code path by gcm.3702assert(OptimizeExpensiveOps || expensive_count() == 0, "optimization off but list non empty?");3703for (int i = 0; i < expensive_count(); i++) {3704_expensive_nodes.at(i)->set_req(0, NULL);3705}37063707Final_Reshape_Counts frc;37083709// Visit everybody reachable!3710// Allocate stack of size C->live_nodes()/2 to avoid frequent realloc3711Node_Stack nstack(live_nodes() >> 1);3712final_graph_reshaping_walk(nstack, root(), frc);37133714// Check for unreachable (from below) code (i.e., infinite loops).3715for( uint i = 0; i < frc._tests.size(); i++ ) {3716MultiBranchNode *n = frc._tests[i]->as_MultiBranch();3717// Get number of CFG targets.3718// Note that PCTables include exception targets after calls.3719uint required_outcnt = n->required_outcnt();3720if (n->outcnt() != required_outcnt) {3721// Check for a few special cases. Rethrow Nodes never take the3722// 'fall-thru' path, so expected kids is 1 less.3723if (n->is_PCTable() && n->in(0) && n->in(0)->in(0)) {3724if (n->in(0)->in(0)->is_Call()) {3725CallNode *call = n->in(0)->in(0)->as_Call();3726if (call->entry_point() == OptoRuntime::rethrow_stub()) {3727required_outcnt--; // Rethrow always has 1 less kid3728} else if (call->req() > TypeFunc::Parms &&3729call->is_CallDynamicJava()) {3730// Check for null receiver. In such case, the optimizer has3731// detected that the virtual call will always result in a null3732// pointer exception. The fall-through projection of this CatchNode3733// will not be populated.3734Node *arg0 = call->in(TypeFunc::Parms);3735if (arg0->is_Type() &&3736arg0->as_Type()->type()->higher_equal(TypePtr::NULL_PTR)) {3737required_outcnt--;3738}3739} else if (call->entry_point() == OptoRuntime::new_array_Java() &&3740call->req() > TypeFunc::Parms+1 &&3741call->is_CallStaticJava()) {3742// Check for negative array length. In such case, the optimizer has3743// detected that the allocation attempt will always result in an3744// exception. There is no fall-through projection of this CatchNode .3745Node *arg1 = call->in(TypeFunc::Parms+1);3746if (arg1->is_Type() &&3747arg1->as_Type()->type()->join(TypeInt::POS)->empty()) {3748required_outcnt--;3749}3750}3751}3752}3753// Recheck with a better notion of 'required_outcnt'3754if (n->outcnt() != required_outcnt) {3755record_method_not_compilable("malformed control flow");3756return true; // Not all targets reachable!3757}3758}3759// Check that I actually visited all kids. Unreached kids3760// must be infinite loops.3761for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++)3762if (!frc._visited.test(n->fast_out(j)->_idx)) {3763record_method_not_compilable("infinite loop");3764return true; // Found unvisited kid; must be unreach3765}37663767// Here so verification code in final_graph_reshaping_walk()3768// always see an OuterStripMinedLoopEnd3769if (n->is_OuterStripMinedLoopEnd() || n->is_LongCountedLoopEnd()) {3770IfNode* init_iff = n->as_If();3771Node* iff = new IfNode(init_iff->in(0), init_iff->in(1), init_iff->_prob, init_iff->_fcnt);3772n->subsume_by(iff, this);3773}3774}37753776#ifdef IA323777// If original bytecodes contained a mixture of floats and doubles3778// check if the optimizer has made it homogenous, item (3).3779if (UseSSE == 0 &&3780frc.get_float_count() > 32 &&3781frc.get_double_count() == 0 &&3782(10 * frc.get_call_count() < frc.get_float_count()) ) {3783set_24_bit_selection_and_mode(false, true);3784}3785#endif // IA3237863787set_java_calls(frc.get_java_call_count());3788set_inner_loops(frc.get_inner_loop_count());37893790// No infinite loops, no reason to bail out.3791return false;3792}37933794//-----------------------------too_many_traps----------------------------------3795// Report if there are too many traps at the current method and bci.3796// Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.3797bool Compile::too_many_traps(ciMethod* method,3798int bci,3799Deoptimization::DeoptReason reason) {3800ciMethodData* md = method->method_data();3801if (md->is_empty()) {3802// Assume the trap has not occurred, or that it occurred only3803// because of a transient condition during start-up in the interpreter.3804return false;3805}3806ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL;3807if (md->has_trap_at(bci, m, reason) != 0) {3808// Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.3809// Also, if there are multiple reasons, or if there is no per-BCI record,3810// assume the worst.3811if (log())3812log()->elem("observe trap='%s' count='%d'",3813Deoptimization::trap_reason_name(reason),3814md->trap_count(reason));3815return true;3816} else {3817// Ignore method/bci and see if there have been too many globally.3818return too_many_traps(reason, md);3819}3820}38213822// Less-accurate variant which does not require a method and bci.3823bool Compile::too_many_traps(Deoptimization::DeoptReason reason,3824ciMethodData* logmd) {3825if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) {3826// Too many traps globally.3827// Note that we use cumulative trap_count, not just md->trap_count.3828if (log()) {3829int mcount = (logmd == NULL)? -1: (int)logmd->trap_count(reason);3830log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",3831Deoptimization::trap_reason_name(reason),3832mcount, trap_count(reason));3833}3834return true;3835} else {3836// The coast is clear.3837return false;3838}3839}38403841//--------------------------too_many_recompiles--------------------------------3842// Report if there are too many recompiles at the current method and bci.3843// Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.3844// Is not eager to return true, since this will cause the compiler to use3845// Action_none for a trap point, to avoid too many recompilations.3846bool Compile::too_many_recompiles(ciMethod* method,3847int bci,3848Deoptimization::DeoptReason reason) {3849ciMethodData* md = method->method_data();3850if (md->is_empty()) {3851// Assume the trap has not occurred, or that it occurred only3852// because of a transient condition during start-up in the interpreter.3853return false;3854}3855// Pick a cutoff point well within PerBytecodeRecompilationCutoff.3856uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8;3857uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero3858Deoptimization::DeoptReason per_bc_reason3859= Deoptimization::reason_recorded_per_bytecode_if_any(reason);3860ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL;3861if ((per_bc_reason == Deoptimization::Reason_none3862|| md->has_trap_at(bci, m, reason) != 0)3863// The trap frequency measure we care about is the recompile count:3864&& md->trap_recompiled_at(bci, m)3865&& md->overflow_recompile_count() >= bc_cutoff) {3866// Do not emit a trap here if it has already caused recompilations.3867// Also, if there are multiple reasons, or if there is no per-BCI record,3868// assume the worst.3869if (log())3870log()->elem("observe trap='%s recompiled' count='%d' recompiles2='%d'",3871Deoptimization::trap_reason_name(reason),3872md->trap_count(reason),3873md->overflow_recompile_count());3874return true;3875} else if (trap_count(reason) != 03876&& decompile_count() >= m_cutoff) {3877// Too many recompiles globally, and we have seen this sort of trap.3878// Use cumulative decompile_count, not just md->decompile_count.3879if (log())3880log()->elem("observe trap='%s' count='%d' mcount='%d' decompiles='%d' mdecompiles='%d'",3881Deoptimization::trap_reason_name(reason),3882md->trap_count(reason), trap_count(reason),3883md->decompile_count(), decompile_count());3884return true;3885} else {3886// The coast is clear.3887return false;3888}3889}38903891// Compute when not to trap. Used by matching trap based nodes and3892// NullCheck optimization.3893void Compile::set_allowed_deopt_reasons() {3894_allowed_reasons = 0;3895if (is_method_compilation()) {3896for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {3897assert(rs < BitsPerInt, "recode bit map");3898if (!too_many_traps((Deoptimization::DeoptReason) rs)) {3899_allowed_reasons |= nth_bit(rs);3900}3901}3902}3903}39043905bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {3906return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);3907}39083909bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {3910return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);3911}39123913bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {3914if (holder->is_initialized()) {3915return false;3916}3917if (holder->is_being_initialized()) {3918if (accessing_method->holder() == holder) {3919// Access inside a class. The barrier can be elided when access happens in <clinit>,3920// <init>, or a static method. In all those cases, there was an initialization3921// barrier on the holder klass passed.3922if (accessing_method->is_static_initializer() ||3923accessing_method->is_object_initializer() ||3924accessing_method->is_static()) {3925return false;3926}3927} else if (accessing_method->holder()->is_subclass_of(holder)) {3928// Access from a subclass. The barrier can be elided only when access happens in <clinit>.3929// In case of <init> or a static method, the barrier is on the subclass is not enough:3930// child class can become fully initialized while its parent class is still being initialized.3931if (accessing_method->is_static_initializer()) {3932return false;3933}3934}3935ciMethod* root = method(); // the root method of compilation3936if (root != accessing_method) {3937return needs_clinit_barrier(holder, root); // check access in the context of compilation root3938}3939}3940return true;3941}39423943#ifndef PRODUCT3944//------------------------------verify_graph_edges---------------------------3945// Walk the Graph and verify that there is a one-to-one correspondence3946// between Use-Def edges and Def-Use edges in the graph.3947void Compile::verify_graph_edges(bool no_dead_code) {3948if (VerifyGraphEdges) {3949Unique_Node_List visited;3950// Call recursive graph walk to check edges3951_root->verify_edges(visited);3952if (no_dead_code) {3953// Now make sure that no visited node is used by an unvisited node.3954bool dead_nodes = false;3955Unique_Node_List checked;3956while (visited.size() > 0) {3957Node* n = visited.pop();3958checked.push(n);3959for (uint i = 0; i < n->outcnt(); i++) {3960Node* use = n->raw_out(i);3961if (checked.member(use)) continue; // already checked3962if (visited.member(use)) continue; // already in the graph3963if (use->is_Con()) continue; // a dead ConNode is OK3964// At this point, we have found a dead node which is DU-reachable.3965if (!dead_nodes) {3966tty->print_cr("*** Dead nodes reachable via DU edges:");3967dead_nodes = true;3968}3969use->dump(2);3970tty->print_cr("---");3971checked.push(use); // No repeats; pretend it is now checked.3972}3973}3974assert(!dead_nodes, "using nodes must be reachable from root");3975}3976}3977}3978#endif39793980// The Compile object keeps track of failure reasons separately from the ciEnv.3981// This is required because there is not quite a 1-1 relation between the3982// ciEnv and its compilation task and the Compile object. Note that one3983// ciEnv might use two Compile objects, if C2Compiler::compile_method decides3984// to backtrack and retry without subsuming loads. Other than this backtracking3985// behavior, the Compile's failure reason is quietly copied up to the ciEnv3986// by the logic in C2Compiler.3987void Compile::record_failure(const char* reason) {3988if (log() != NULL) {3989log()->elem("failure reason='%s' phase='compile'", reason);3990}3991if (_failure_reason == NULL) {3992// Record the first failure reason.3993_failure_reason = reason;3994}39953996if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) {3997C->print_method(PHASE_FAILURE);3998}3999_root = NULL; // flush the graph, too4000}40014002Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator)4003: TraceTime(name, accumulator, CITime, CITimeVerbose),4004_phase_name(name), _dolog(CITimeVerbose)4005{4006if (_dolog) {4007C = Compile::current();4008_log = C->log();4009} else {4010C = NULL;4011_log = NULL;4012}4013if (_log != NULL) {4014_log->begin_head("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());4015_log->stamp();4016_log->end_head();4017}4018}40194020Compile::TracePhase::~TracePhase() {40214022C = Compile::current();4023if (_dolog) {4024_log = C->log();4025} else {4026_log = NULL;4027}40284029#ifdef ASSERT4030if (PrintIdealNodeCount) {4031tty->print_cr("phase name='%s' nodes='%d' live='%d' live_graph_walk='%d'",4032_phase_name, C->unique(), C->live_nodes(), C->count_live_nodes_by_graph_walk());4033}40344035if (VerifyIdealNodeCount) {4036Compile::current()->print_missing_nodes();4037}4038#endif40394040if (_log != NULL) {4041_log->done("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());4042}4043}40444045//----------------------------static_subtype_check-----------------------------4046// Shortcut important common cases when superklass is exact:4047// (0) superklass is java.lang.Object (can occur in reflective code)4048// (1) subklass is already limited to a subtype of superklass => always ok4049// (2) subklass does not overlap with superklass => always fail4050// (3) superklass has NO subtypes and we can check with a simple compare.4051int Compile::static_subtype_check(ciKlass* superk, ciKlass* subk) {4052if (StressReflectiveCode) {4053return SSC_full_test; // Let caller generate the general case.4054}40554056if (superk == env()->Object_klass()) {4057return SSC_always_true; // (0) this test cannot fail4058}40594060ciType* superelem = superk;4061ciType* subelem = subk;4062if (superelem->is_array_klass()) {4063superelem = superelem->as_array_klass()->base_element_type();4064}4065if (subelem->is_array_klass()) {4066subelem = subelem->as_array_klass()->base_element_type();4067}40684069if (!subk->is_interface()) { // cannot trust static interface types yet4070if (subk->is_subtype_of(superk)) {4071return SSC_always_true; // (1) false path dead; no dynamic test needed4072}4073if (!(superelem->is_klass() && superelem->as_klass()->is_interface()) &&4074!(subelem->is_klass() && subelem->as_klass()->is_interface()) &&4075!superk->is_subtype_of(subk)) {4076return SSC_always_false; // (2) true path dead; no dynamic test needed4077}4078}40794080// If casting to an instance klass, it must have no subtypes4081if (superk->is_interface()) {4082// Cannot trust interfaces yet.4083// %%% S.B. superk->nof_implementors() == 14084} else if (superelem->is_instance_klass()) {4085ciInstanceKlass* ik = superelem->as_instance_klass();4086if (!ik->has_subklass() && !ik->is_interface()) {4087if (!ik->is_final()) {4088// Add a dependency if there is a chance of a later subclass.4089dependencies()->assert_leaf_type(ik);4090}4091return SSC_easy_test; // (3) caller can do a simple ptr comparison4092}4093} else {4094// A primitive array type has no subtypes.4095return SSC_easy_test; // (3) caller can do a simple ptr comparison4096}40974098return SSC_full_test;4099}41004101Node* Compile::conv_I2X_index(PhaseGVN* phase, Node* idx, const TypeInt* sizetype, Node* ctrl) {4102#ifdef _LP644103// The scaled index operand to AddP must be a clean 64-bit value.4104// Java allows a 32-bit int to be incremented to a negative4105// value, which appears in a 64-bit register as a large4106// positive number. Using that large positive number as an4107// operand in pointer arithmetic has bad consequences.4108// On the other hand, 32-bit overflow is rare, and the possibility4109// can often be excluded, if we annotate the ConvI2L node with4110// a type assertion that its value is known to be a small positive4111// number. (The prior range check has ensured this.)4112// This assertion is used by ConvI2LNode::Ideal.4113int index_max = max_jint - 1; // array size is max_jint, index is one less4114if (sizetype != NULL) index_max = sizetype->_hi - 1;4115const TypeInt* iidxtype = TypeInt::make(0, index_max, Type::WidenMax);4116idx = constrained_convI2L(phase, idx, iidxtype, ctrl);4117#endif4118return idx;4119}41204121// Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)4122Node* Compile::constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency) {4123if (ctrl != NULL) {4124// Express control dependency by a CastII node with a narrow type.4125value = new CastIINode(value, itype, carry_dependency, true /* range check dependency */);4126// Make the CastII node dependent on the control input to prevent the narrowed ConvI2L4127// node from floating above the range check during loop optimizations. Otherwise, the4128// ConvI2L node may be eliminated independently of the range check, causing the data path4129// to become TOP while the control path is still there (although it's unreachable).4130value->set_req(0, ctrl);4131value = phase->transform(value);4132}4133const TypeLong* ltype = TypeLong::make(itype->_lo, itype->_hi, itype->_widen);4134return phase->transform(new ConvI2LNode(value, ltype));4135}41364137void Compile::print_inlining_stream_free() {4138if (_print_inlining_stream != NULL) {4139_print_inlining_stream->~stringStream();4140_print_inlining_stream = NULL;4141}4142}41434144// The message about the current inlining is accumulated in4145// _print_inlining_stream and transfered into the _print_inlining_list4146// once we know whether inlining succeeds or not. For regular4147// inlining, messages are appended to the buffer pointed by4148// _print_inlining_idx in the _print_inlining_list. For late inlining,4149// a new buffer is added after _print_inlining_idx in the list. This4150// way we can update the inlining message for late inlining call site4151// when the inlining is attempted again.4152void Compile::print_inlining_init() {4153if (print_inlining() || print_intrinsics()) {4154// print_inlining_init is actually called several times.4155print_inlining_stream_free();4156_print_inlining_stream = new stringStream();4157_print_inlining_list = new (comp_arena())GrowableArray<PrintInliningBuffer*>(comp_arena(), 1, 1, new PrintInliningBuffer());4158}4159}41604161void Compile::print_inlining_reinit() {4162if (print_inlining() || print_intrinsics()) {4163print_inlining_stream_free();4164// Re allocate buffer when we change ResourceMark4165_print_inlining_stream = new stringStream();4166}4167}41684169void Compile::print_inlining_reset() {4170_print_inlining_stream->reset();4171}41724173void Compile::print_inlining_commit() {4174assert(print_inlining() || print_intrinsics(), "PrintInlining off?");4175// Transfer the message from _print_inlining_stream to the current4176// _print_inlining_list buffer and clear _print_inlining_stream.4177_print_inlining_list->at(_print_inlining_idx)->ss()->write(_print_inlining_stream->base(), _print_inlining_stream->size());4178print_inlining_reset();4179}41804181void Compile::print_inlining_push() {4182// Add new buffer to the _print_inlining_list at current position4183_print_inlining_idx++;4184_print_inlining_list->insert_before(_print_inlining_idx, new PrintInliningBuffer());4185}41864187Compile::PrintInliningBuffer* Compile::print_inlining_current() {4188return _print_inlining_list->at(_print_inlining_idx);4189}41904191void Compile::print_inlining_update(CallGenerator* cg) {4192if (print_inlining() || print_intrinsics()) {4193if (cg->is_late_inline()) {4194if (print_inlining_current()->cg() != cg &&4195(print_inlining_current()->cg() != NULL ||4196print_inlining_current()->ss()->size() != 0)) {4197print_inlining_push();4198}4199print_inlining_commit();4200print_inlining_current()->set_cg(cg);4201} else {4202if (print_inlining_current()->cg() != NULL) {4203print_inlining_push();4204}4205print_inlining_commit();4206}4207}4208}42094210void Compile::print_inlining_move_to(CallGenerator* cg) {4211// We resume inlining at a late inlining call site. Locate the4212// corresponding inlining buffer so that we can update it.4213if (print_inlining() || print_intrinsics()) {4214for (int i = 0; i < _print_inlining_list->length(); i++) {4215if (_print_inlining_list->at(i)->cg() == cg) {4216_print_inlining_idx = i;4217return;4218}4219}4220ShouldNotReachHere();4221}4222}42234224void Compile::print_inlining_update_delayed(CallGenerator* cg) {4225if (print_inlining() || print_intrinsics()) {4226assert(_print_inlining_stream->size() > 0, "missing inlining msg");4227assert(print_inlining_current()->cg() == cg, "wrong entry");4228// replace message with new message4229_print_inlining_list->at_put(_print_inlining_idx, new PrintInliningBuffer());4230print_inlining_commit();4231print_inlining_current()->set_cg(cg);4232}4233}42344235void Compile::print_inlining_assert_ready() {4236assert(!_print_inlining || _print_inlining_stream->size() == 0, "loosing data");4237}42384239void Compile::process_print_inlining() {4240assert(_late_inlines.length() == 0, "not drained yet");4241if (print_inlining() || print_intrinsics()) {4242ResourceMark rm;4243stringStream ss;4244assert(_print_inlining_list != NULL, "process_print_inlining should be called only once.");4245for (int i = 0; i < _print_inlining_list->length(); i++) {4246PrintInliningBuffer* pib = _print_inlining_list->at(i);4247ss.print("%s", pib->ss()->as_string());4248delete pib;4249DEBUG_ONLY(_print_inlining_list->at_put(i, NULL));4250}4251// Reset _print_inlining_list, it only contains destructed objects.4252// It is on the arena, so it will be freed when the arena is reset.4253_print_inlining_list = NULL;4254// _print_inlining_stream won't be used anymore, either.4255print_inlining_stream_free();4256size_t end = ss.size();4257_print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1);4258strncpy(_print_inlining_output, ss.base(), end+1);4259_print_inlining_output[end] = 0;4260}4261}42624263void Compile::dump_print_inlining() {4264if (_print_inlining_output != NULL) {4265tty->print_raw(_print_inlining_output);4266}4267}42684269void Compile::log_late_inline(CallGenerator* cg) {4270if (log() != NULL) {4271log()->head("late_inline method='%d' inline_id='" JLONG_FORMAT "'", log()->identify(cg->method()),4272cg->unique_id());4273JVMState* p = cg->call_node()->jvms();4274while (p != NULL) {4275log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));4276p = p->caller();4277}4278log()->tail("late_inline");4279}4280}42814282void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {4283log_late_inline(cg);4284if (log() != NULL) {4285log()->inline_fail(msg);4286}4287}42884289void Compile::log_inline_id(CallGenerator* cg) {4290if (log() != NULL) {4291// The LogCompilation tool needs a unique way to identify late4292// inline call sites. This id must be unique for this call site in4293// this compilation. Try to have it unique across compilations as4294// well because it can be convenient when grepping through the log4295// file.4296// Distinguish OSR compilations from others in case CICountOSR is4297// on.4298jlong id = ((jlong)unique()) + (((jlong)compile_id()) << 33) + (CICountOSR && is_osr_compilation() ? ((jlong)1) << 32 : 0);4299cg->set_unique_id(id);4300log()->elem("inline_id id='" JLONG_FORMAT "'", id);4301}4302}43034304void Compile::log_inline_failure(const char* msg) {4305if (C->log() != NULL) {4306C->log()->inline_fail(msg);4307}4308}430943104311// Dump inlining replay data to the stream.4312// Don't change thread state and acquire any locks.4313void Compile::dump_inline_data(outputStream* out) {4314InlineTree* inl_tree = ilt();4315if (inl_tree != NULL) {4316out->print(" inline %d", inl_tree->count());4317inl_tree->dump_replay_data(out);4318}4319}43204321int Compile::cmp_expensive_nodes(Node* n1, Node* n2) {4322if (n1->Opcode() < n2->Opcode()) return -1;4323else if (n1->Opcode() > n2->Opcode()) return 1;43244325assert(n1->req() == n2->req(), "can't compare %s nodes: n1->req() = %d, n2->req() = %d", NodeClassNames[n1->Opcode()], n1->req(), n2->req());4326for (uint i = 1; i < n1->req(); i++) {4327if (n1->in(i) < n2->in(i)) return -1;4328else if (n1->in(i) > n2->in(i)) return 1;4329}43304331return 0;4332}43334334int Compile::cmp_expensive_nodes(Node** n1p, Node** n2p) {4335Node* n1 = *n1p;4336Node* n2 = *n2p;43374338return cmp_expensive_nodes(n1, n2);4339}43404341void Compile::sort_expensive_nodes() {4342if (!expensive_nodes_sorted()) {4343_expensive_nodes.sort(cmp_expensive_nodes);4344}4345}43464347bool Compile::expensive_nodes_sorted() const {4348for (int i = 1; i < _expensive_nodes.length(); i++) {4349if (cmp_expensive_nodes(_expensive_nodes.adr_at(i), _expensive_nodes.adr_at(i-1)) < 0) {4350return false;4351}4352}4353return true;4354}43554356bool Compile::should_optimize_expensive_nodes(PhaseIterGVN &igvn) {4357if (_expensive_nodes.length() == 0) {4358return false;4359}43604361assert(OptimizeExpensiveOps, "optimization off?");43624363// Take this opportunity to remove dead nodes from the list4364int j = 0;4365for (int i = 0; i < _expensive_nodes.length(); i++) {4366Node* n = _expensive_nodes.at(i);4367if (!n->is_unreachable(igvn)) {4368assert(n->is_expensive(), "should be expensive");4369_expensive_nodes.at_put(j, n);4370j++;4371}4372}4373_expensive_nodes.trunc_to(j);43744375// Then sort the list so that similar nodes are next to each other4376// and check for at least two nodes of identical kind with same data4377// inputs.4378sort_expensive_nodes();43794380for (int i = 0; i < _expensive_nodes.length()-1; i++) {4381if (cmp_expensive_nodes(_expensive_nodes.adr_at(i), _expensive_nodes.adr_at(i+1)) == 0) {4382return true;4383}4384}43854386return false;4387}43884389void Compile::cleanup_expensive_nodes(PhaseIterGVN &igvn) {4390if (_expensive_nodes.length() == 0) {4391return;4392}43934394assert(OptimizeExpensiveOps, "optimization off?");43954396// Sort to bring similar nodes next to each other and clear the4397// control input of nodes for which there's only a single copy.4398sort_expensive_nodes();43994400int j = 0;4401int identical = 0;4402int i = 0;4403bool modified = false;4404for (; i < _expensive_nodes.length()-1; i++) {4405assert(j <= i, "can't write beyond current index");4406if (_expensive_nodes.at(i)->Opcode() == _expensive_nodes.at(i+1)->Opcode()) {4407identical++;4408_expensive_nodes.at_put(j++, _expensive_nodes.at(i));4409continue;4410}4411if (identical > 0) {4412_expensive_nodes.at_put(j++, _expensive_nodes.at(i));4413identical = 0;4414} else {4415Node* n = _expensive_nodes.at(i);4416igvn.replace_input_of(n, 0, NULL);4417igvn.hash_insert(n);4418modified = true;4419}4420}4421if (identical > 0) {4422_expensive_nodes.at_put(j++, _expensive_nodes.at(i));4423} else if (_expensive_nodes.length() >= 1) {4424Node* n = _expensive_nodes.at(i);4425igvn.replace_input_of(n, 0, NULL);4426igvn.hash_insert(n);4427modified = true;4428}4429_expensive_nodes.trunc_to(j);4430if (modified) {4431igvn.optimize();4432}4433}44344435void Compile::add_expensive_node(Node * n) {4436assert(!_expensive_nodes.contains(n), "duplicate entry in expensive list");4437assert(n->is_expensive(), "expensive nodes with non-null control here only");4438assert(!n->is_CFG() && !n->is_Mem(), "no cfg or memory nodes here");4439if (OptimizeExpensiveOps) {4440_expensive_nodes.append(n);4441} else {4442// Clear control input and let IGVN optimize expensive nodes if4443// OptimizeExpensiveOps is off.4444n->set_req(0, NULL);4445}4446}44474448/**4449* Remove the speculative part of types and clean up the graph4450*/4451void Compile::remove_speculative_types(PhaseIterGVN &igvn) {4452if (UseTypeSpeculation) {4453Unique_Node_List worklist;4454worklist.push(root());4455int modified = 0;4456// Go over all type nodes that carry a speculative type, drop the4457// speculative part of the type and enqueue the node for an igvn4458// which may optimize it out.4459for (uint next = 0; next < worklist.size(); ++next) {4460Node *n = worklist.at(next);4461if (n->is_Type()) {4462TypeNode* tn = n->as_Type();4463const Type* t = tn->type();4464const Type* t_no_spec = t->remove_speculative();4465if (t_no_spec != t) {4466bool in_hash = igvn.hash_delete(n);4467assert(in_hash, "node should be in igvn hash table");4468tn->set_type(t_no_spec);4469igvn.hash_insert(n);4470igvn._worklist.push(n); // give it a chance to go away4471modified++;4472}4473}4474uint max = n->len();4475for( uint i = 0; i < max; ++i ) {4476Node *m = n->in(i);4477if (not_a_node(m)) continue;4478worklist.push(m);4479}4480}4481// Drop the speculative part of all types in the igvn's type table4482igvn.remove_speculative_types();4483if (modified > 0) {4484igvn.optimize();4485}4486#ifdef ASSERT4487// Verify that after the IGVN is over no speculative type has resurfaced4488worklist.clear();4489worklist.push(root());4490for (uint next = 0; next < worklist.size(); ++next) {4491Node *n = worklist.at(next);4492const Type* t = igvn.type_or_null(n);4493assert((t == NULL) || (t == t->remove_speculative()), "no more speculative types");4494if (n->is_Type()) {4495t = n->as_Type()->type();4496assert(t == t->remove_speculative(), "no more speculative types");4497}4498uint max = n->len();4499for( uint i = 0; i < max; ++i ) {4500Node *m = n->in(i);4501if (not_a_node(m)) continue;4502worklist.push(m);4503}4504}4505igvn.check_no_speculative_types();4506#endif4507}4508}45094510// Auxiliary methods to support randomized stressing/fuzzing.45114512int Compile::random() {4513_stress_seed = os::next_random(_stress_seed);4514return static_cast<int>(_stress_seed);4515}45164517// This method can be called the arbitrary number of times, with current count4518// as the argument. The logic allows selecting a single candidate from the4519// running list of candidates as follows:4520// int count = 0;4521// Cand* selected = null;4522// while(cand = cand->next()) {4523// if (randomized_select(++count)) {4524// selected = cand;4525// }4526// }4527//4528// Including count equalizes the chances any candidate is "selected".4529// This is useful when we don't have the complete list of candidates to choose4530// from uniformly. In this case, we need to adjust the randomicity of the4531// selection, or else we will end up biasing the selection towards the latter4532// candidates.4533//4534// Quick back-envelope calculation shows that for the list of n candidates4535// the equal probability for the candidate to persist as "best" can be4536// achieved by replacing it with "next" k-th candidate with the probability4537// of 1/k. It can be easily shown that by the end of the run, the4538// probability for any candidate is converged to 1/n, thus giving the4539// uniform distribution among all the candidates.4540//4541// We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.4542#define RANDOMIZED_DOMAIN_POW 294543#define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW)4544#define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)4545bool Compile::randomized_select(int count) {4546assert(count > 0, "only positive");4547return (random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);4548}45494550CloneMap& Compile::clone_map() { return _clone_map; }4551void Compile::set_clone_map(Dict* d) { _clone_map._dict = d; }45524553void NodeCloneInfo::dump() const {4554tty->print(" {%d:%d} ", idx(), gen());4555}45564557void CloneMap::clone(Node* old, Node* nnn, int gen) {4558uint64_t val = value(old->_idx);4559NodeCloneInfo cio(val);4560assert(val != 0, "old node should be in the map");4561NodeCloneInfo cin(cio.idx(), gen + cio.gen());4562insert(nnn->_idx, cin.get());4563#ifndef PRODUCT4564if (is_debug()) {4565tty->print_cr("CloneMap::clone inserted node %d info {%d:%d} into CloneMap", nnn->_idx, cin.idx(), cin.gen());4566}4567#endif4568}45694570void CloneMap::verify_insert_and_clone(Node* old, Node* nnn, int gen) {4571NodeCloneInfo cio(value(old->_idx));4572if (cio.get() == 0) {4573cio.set(old->_idx, 0);4574insert(old->_idx, cio.get());4575#ifndef PRODUCT4576if (is_debug()) {4577tty->print_cr("CloneMap::verify_insert_and_clone inserted node %d info {%d:%d} into CloneMap", old->_idx, cio.idx(), cio.gen());4578}4579#endif4580}4581clone(old, nnn, gen);4582}45834584int CloneMap::max_gen() const {4585int g = 0;4586DictI di(_dict);4587for(; di.test(); ++di) {4588int t = gen(di._key);4589if (g < t) {4590g = t;4591#ifndef PRODUCT4592if (is_debug()) {4593tty->print_cr("CloneMap::max_gen() update max=%d from %d", g, _2_node_idx_t(di._key));4594}4595#endif4596}4597}4598return g;4599}46004601void CloneMap::dump(node_idx_t key) const {4602uint64_t val = value(key);4603if (val != 0) {4604NodeCloneInfo ni(val);4605ni.dump();4606}4607}46084609// Move Allocate nodes to the start of the list4610void Compile::sort_macro_nodes() {4611int count = macro_count();4612int allocates = 0;4613for (int i = 0; i < count; i++) {4614Node* n = macro_node(i);4615if (n->is_Allocate()) {4616if (i != allocates) {4617Node* tmp = macro_node(allocates);4618_macro_nodes.at_put(allocates, n);4619_macro_nodes.at_put(i, tmp);4620}4621allocates++;4622}4623}4624}46254626void Compile::print_method(CompilerPhaseType cpt, const char *name, int level) {4627EventCompilerPhase event;4628if (event.should_commit()) {4629CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, cpt, C->_compile_id, level);4630}4631#ifndef PRODUCT4632if (should_print(level)) {4633_printer->print_method(name, level);4634}4635#endif4636C->_latest_stage_start_counter.stamp();4637}46384639void Compile::print_method(CompilerPhaseType cpt, int level, int idx) {4640char output[1024];4641#ifndef PRODUCT4642if (idx != 0) {4643jio_snprintf(output, sizeof(output), "%s:%d", CompilerPhaseTypeHelper::to_string(cpt), idx);4644} else {4645jio_snprintf(output, sizeof(output), "%s", CompilerPhaseTypeHelper::to_string(cpt));4646}4647#endif4648print_method(cpt, output, level);4649}46504651void Compile::print_method(CompilerPhaseType cpt, Node* n, int level) {4652ResourceMark rm;4653stringStream ss;4654ss.print_raw(CompilerPhaseTypeHelper::to_string(cpt));4655if (n != NULL) {4656ss.print(": %d %s ", n->_idx, NodeClassNames[n->Opcode()]);4657} else {4658ss.print_raw(": NULL");4659}4660C->print_method(cpt, ss.as_string(), level);4661}46624663void Compile::end_method(int level) {4664EventCompilerPhase event;4665if (event.should_commit()) {4666CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, PHASE_END, C->_compile_id, level);4667}46684669#ifndef PRODUCT4670if (_method != NULL && should_print(level)) {4671_printer->end_method();4672}4673#endif4674}467546764677#ifndef PRODUCT4678IdealGraphPrinter* Compile::_debug_file_printer = NULL;4679IdealGraphPrinter* Compile::_debug_network_printer = NULL;46804681// Called from debugger. Prints method to the default file with the default phase name.4682// This works regardless of any Ideal Graph Visualizer flags set or not.4683void igv_print() {4684Compile::current()->igv_print_method_to_file();4685}46864687// Same as igv_print() above but with a specified phase name.4688void igv_print(const char* phase_name) {4689Compile::current()->igv_print_method_to_file(phase_name);4690}46914692// Called from debugger. Prints method with the default phase name to the default network or the one specified with4693// the network flags for the Ideal Graph Visualizer, or to the default file depending on the 'network' argument.4694// This works regardless of any Ideal Graph Visualizer flags set or not.4695void igv_print(bool network) {4696if (network) {4697Compile::current()->igv_print_method_to_network();4698} else {4699Compile::current()->igv_print_method_to_file();4700}4701}47024703// Same as igv_print(bool network) above but with a specified phase name.4704void igv_print(bool network, const char* phase_name) {4705if (network) {4706Compile::current()->igv_print_method_to_network(phase_name);4707} else {4708Compile::current()->igv_print_method_to_file(phase_name);4709}4710}47114712// Called from debugger. Normal write to the default _printer. Only works if Ideal Graph Visualizer printing flags are set.4713void igv_print_default() {4714Compile::current()->print_method(PHASE_DEBUG, 0);4715}47164717// Called from debugger, especially when replaying a trace in which the program state cannot be altered like with rr replay.4718// A method is appended to an existing default file with the default phase name. This means that igv_append() must follow4719// an earlier igv_print(*) call which sets up the file. This works regardless of any Ideal Graph Visualizer flags set or not.4720void igv_append() {4721Compile::current()->igv_print_method_to_file("Debug", true);4722}47234724// Same as igv_append() above but with a specified phase name.4725void igv_append(const char* phase_name) {4726Compile::current()->igv_print_method_to_file(phase_name, true);4727}47284729void Compile::igv_print_method_to_file(const char* phase_name, bool append) {4730const char* file_name = "custom_debug.xml";4731if (_debug_file_printer == NULL) {4732_debug_file_printer = new IdealGraphPrinter(C, file_name, append);4733} else {4734_debug_file_printer->update_compiled_method(C->method());4735}4736tty->print_cr("Method %s to %s", append ? "appended" : "printed", file_name);4737_debug_file_printer->print(phase_name, (Node*)C->root());4738}47394740void Compile::igv_print_method_to_network(const char* phase_name) {4741if (_debug_network_printer == NULL) {4742_debug_network_printer = new IdealGraphPrinter(C);4743} else {4744_debug_network_printer->update_compiled_method(C->method());4745}4746tty->print_cr("Method printed over network stream to IGV");4747_debug_network_printer->print(phase_name, (Node*)C->root());4748}4749#endif47504751void Compile::add_native_invoker(RuntimeStub* stub) {4752_native_invokers.append(stub);4753}47544755Node* Compile::narrow_value(BasicType bt, Node* value, const Type* type, PhaseGVN* phase, bool transform_res) {4756if (type != NULL && phase->type(value)->higher_equal(type)) {4757return value;4758}4759Node* result = NULL;4760if (bt == T_BYTE) {4761result = phase->transform(new LShiftINode(value, phase->intcon(24)));4762result = new RShiftINode(result, phase->intcon(24));4763} else if (bt == T_BOOLEAN) {4764result = new AndINode(value, phase->intcon(0xFF));4765} else if (bt == T_CHAR) {4766result = new AndINode(value,phase->intcon(0xFFFF));4767} else {4768assert(bt == T_SHORT, "unexpected narrow type");4769result = phase->transform(new LShiftINode(value, phase->intcon(16)));4770result = new RShiftINode(result, phase->intcon(16));4771}4772if (transform_res) {4773result = phase->transform(result);4774}4775return result;4776}4777477847794780