Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/opto/buildOopMap.cpp
32285 views
/*1* Copyright (c) 2002, 2018, 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 "compiler/oopMap.hpp"26#include "opto/addnode.hpp"27#include "opto/callnode.hpp"28#include "opto/compile.hpp"29#include "opto/machnode.hpp"30#include "opto/matcher.hpp"31#include "opto/phase.hpp"32#include "opto/regalloc.hpp"33#include "opto/rootnode.hpp"34#ifdef TARGET_ARCH_x8635# include "vmreg_x86.inline.hpp"36#endif37#ifdef TARGET_ARCH_aarch3238# include "vmreg_aarch32.inline.hpp"39#endif40#ifdef TARGET_ARCH_aarch6441# include "vmreg_aarch64.inline.hpp"42#endif43#ifdef TARGET_ARCH_sparc44# include "vmreg_sparc.inline.hpp"45#endif46#ifdef TARGET_ARCH_zero47# include "vmreg_zero.inline.hpp"48#endif49#ifdef TARGET_ARCH_arm50# include "vmreg_arm.inline.hpp"51#endif52#ifdef TARGET_ARCH_ppc53# include "vmreg_ppc.inline.hpp"54#endif5556// The functions in this file builds OopMaps after all scheduling is done.57//58// OopMaps contain a list of all registers and stack-slots containing oops (so59// they can be updated by GC). OopMaps also contain a list of derived-pointer60// base-pointer pairs. When the base is moved, the derived pointer moves to61// follow it. Finally, any registers holding callee-save values are also62// recorded. These might contain oops, but only the caller knows.63//64// BuildOopMaps implements a simple forward reaching-defs solution. At each65// GC point we'll have the reaching-def Nodes. If the reaching Nodes are66// typed as pointers (no offset), then they are oops. Pointers+offsets are67// derived pointers, and bases can be found from them. Finally, we'll also68// track reaching callee-save values. Note that a copy of a callee-save value69// "kills" it's source, so that only 1 copy of a callee-save value is alive at70// a time.71//72// We run a simple bitvector liveness pass to help trim out dead oops. Due to73// irreducible loops, we can have a reaching def of an oop that only reaches74// along one path and no way to know if it's valid or not on the other path.75// The bitvectors are quite dense and the liveness pass is fast.76//77// At GC points, we consult this information to build OopMaps. All reaching78// defs typed as oops are added to the OopMap. Only 1 instance of a79// callee-save register can be recorded. For derived pointers, we'll have to80// find and record the register holding the base.81//82// The reaching def's is a simple 1-pass worklist approach. I tried a clever83// breadth-first approach but it was worse (showed O(n^2) in the84// pick-next-block code).85//86// The relevant data is kept in a struct of arrays (it could just as well be87// an array of structs, but the struct-of-arrays is generally a little more88// efficient). The arrays are indexed by register number (including89// stack-slots as registers) and so is bounded by 200 to 300 elements in90// practice. One array will map to a reaching def Node (or NULL for91// conflict/dead). The other array will map to a callee-saved register or92// OptoReg::Bad for not-callee-saved.939495// Structure to pass around96struct OopFlow : public ResourceObj {97short *_callees; // Array mapping register to callee-saved98Node **_defs; // array mapping register to reaching def99// or NULL if dead/conflict100// OopFlow structs, when not being actively modified, describe the _end_ of101// this block.102Block *_b; // Block for this struct103OopFlow *_next; // Next free OopFlow104// or NULL if dead/conflict105Compile* C;106107OopFlow( short *callees, Node **defs, Compile* c ) : _callees(callees), _defs(defs),108_b(NULL), _next(NULL), C(c) { }109110// Given reaching-defs for this block start, compute it for this block end111void compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash );112113// Merge these two OopFlows into the 'this' pointer.114void merge( OopFlow *flow, int max_reg );115116// Copy a 'flow' over an existing flow117void clone( OopFlow *flow, int max_size);118119// Make a new OopFlow from scratch120static OopFlow *make( Arena *A, int max_size, Compile* C );121122// Build an oopmap from the current flow info123OopMap *build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live );124};125126// Given reaching-defs for this block start, compute it for this block end127void OopFlow::compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ) {128129for( uint i=0; i<_b->number_of_nodes(); i++ ) {130Node *n = _b->get_node(i);131132if( n->jvms() ) { // Build an OopMap here?133JVMState *jvms = n->jvms();134// no map needed for leaf calls135if( n->is_MachSafePoint() && !n->is_MachCallLeaf() ) {136int *live = (int*) (*safehash)[n];137assert( live, "must find live" );138n->as_MachSafePoint()->set_oop_map( build_oop_map(n,max_reg,regalloc, live) );139}140}141142// Assign new reaching def's.143// Note that I padded the _defs and _callees arrays so it's legal144// to index at _defs[OptoReg::Bad].145OptoReg::Name first = regalloc->get_reg_first(n);146OptoReg::Name second = regalloc->get_reg_second(n);147_defs[first] = n;148_defs[second] = n;149150// Pass callee-save info around copies151int idx = n->is_Copy();152if( idx ) { // Copies move callee-save info153OptoReg::Name old_first = regalloc->get_reg_first(n->in(idx));154OptoReg::Name old_second = regalloc->get_reg_second(n->in(idx));155int tmp_first = _callees[old_first];156int tmp_second = _callees[old_second];157_callees[old_first] = OptoReg::Bad; // callee-save is moved, dead in old location158_callees[old_second] = OptoReg::Bad;159_callees[first] = tmp_first;160_callees[second] = tmp_second;161} else if( n->is_Phi() ) { // Phis do not mod callee-saves162assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(1))], "" );163assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(1))], "" );164assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(n->req()-1))], "" );165assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(n->req()-1))], "" );166} else {167_callees[first] = OptoReg::Bad; // No longer holding a callee-save value168_callees[second] = OptoReg::Bad;169170// Find base case for callee saves171if( n->is_Proj() && n->in(0)->is_Start() ) {172if( OptoReg::is_reg(first) &&173regalloc->_matcher.is_save_on_entry(first) )174_callees[first] = first;175if( OptoReg::is_reg(second) &&176regalloc->_matcher.is_save_on_entry(second) )177_callees[second] = second;178}179}180}181}182183// Merge the given flow into the 'this' flow184void OopFlow::merge( OopFlow *flow, int max_reg ) {185assert( _b == NULL, "merging into a happy flow" );186assert( flow->_b, "this flow is still alive" );187assert( flow != this, "no self flow" );188189// Do the merge. If there are any differences, drop to 'bottom' which190// is OptoReg::Bad or NULL depending.191for( int i=0; i<max_reg; i++ ) {192// Merge the callee-save's193if( _callees[i] != flow->_callees[i] )194_callees[i] = OptoReg::Bad;195// Merge the reaching defs196if( _defs[i] != flow->_defs[i] )197_defs[i] = NULL;198}199200}201202void OopFlow::clone( OopFlow *flow, int max_size ) {203_b = flow->_b;204memcpy( _callees, flow->_callees, sizeof(short)*max_size);205memcpy( _defs , flow->_defs , sizeof(Node*)*max_size);206}207208OopFlow *OopFlow::make( Arena *A, int max_size, Compile* C ) {209short *callees = NEW_ARENA_ARRAY(A,short,max_size+1);210Node **defs = NEW_ARENA_ARRAY(A,Node*,max_size+1);211debug_only( memset(defs,0,(max_size+1)*sizeof(Node*)) );212OopFlow *flow = new (A) OopFlow(callees+1, defs+1, C);213assert( &flow->_callees[OptoReg::Bad] == callees, "Ok to index at OptoReg::Bad" );214assert( &flow->_defs [OptoReg::Bad] == defs , "Ok to index at OptoReg::Bad" );215return flow;216}217218static int get_live_bit( int *live, int reg ) {219return live[reg>>LogBitsPerInt] & (1<<(reg&(BitsPerInt-1))); }220static void set_live_bit( int *live, int reg ) {221live[reg>>LogBitsPerInt] |= (1<<(reg&(BitsPerInt-1))); }222static void clr_live_bit( int *live, int reg ) {223live[reg>>LogBitsPerInt] &= ~(1<<(reg&(BitsPerInt-1))); }224225// Build an oopmap from the current flow info226OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ) {227int framesize = regalloc->_framesize;228int max_inarg_slot = OptoReg::reg2stack(regalloc->_matcher._new_SP);229debug_only( char *dup_check = NEW_RESOURCE_ARRAY(char,OptoReg::stack0());230memset(dup_check,0,OptoReg::stack0()) );231232OopMap *omap = new OopMap( framesize, max_inarg_slot );233MachCallNode *mcall = n->is_MachCall() ? n->as_MachCall() : NULL;234JVMState* jvms = n->jvms();235236// For all registers do...237for( int reg=0; reg<max_reg; reg++ ) {238if( get_live_bit(live,reg) == 0 )239continue; // Ignore if not live240241// %%% C2 can use 2 OptoRegs when the physical register is only one 64bit242// register in that case we'll get an non-concrete register for the second243// half. We only need to tell the map the register once!244//245// However for the moment we disable this change and leave things as they246// were.247248VMReg r = OptoReg::as_VMReg(OptoReg::Name(reg), framesize, max_inarg_slot);249250if (false && r->is_reg() && !r->is_concrete()) {251continue;252}253254// See if dead (no reaching def).255Node *def = _defs[reg]; // Get reaching def256assert( def, "since live better have reaching def" );257258// Classify the reaching def as oop, derived, callee-save, dead, or other259const Type *t = def->bottom_type();260if( t->isa_oop_ptr() ) { // Oop or derived?261assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );262#ifdef _LP64263// 64-bit pointers record oop-ishness on 2 aligned adjacent registers.264// Make sure both are record from the same reaching def, but do not265// put both into the oopmap.266if( (reg&1) == 1 ) { // High half of oop-pair?267assert( _defs[reg-1] == _defs[reg], "both halves from same reaching def" );268continue; // Do not record high parts in oopmap269}270#endif271272// Check for a legal reg name in the oopMap and bailout if it is not.273if (!omap->legal_vm_reg_name(r)) {274regalloc->C->record_method_not_compilable("illegal oopMap register name");275continue;276}277if( t->is_ptr()->_offset == 0 ) { // Not derived?278if( mcall ) {279// Outgoing argument GC mask responsibility belongs to the callee,280// not the caller. Inspect the inputs to the call, to see if281// this live-range is one of them.282uint cnt = mcall->tf()->domain()->cnt();283uint j;284for( j = TypeFunc::Parms; j < cnt; j++)285if( mcall->in(j) == def )286break; // reaching def is an argument oop287if( j < cnt ) // arg oops dont go in GC map288continue; // Continue on to the next register289}290omap->set_oop(r);291} else { // Else it's derived.292// Find the base of the derived value.293uint i;294// Fast, common case, scan295for( i = jvms->oopoff(); i < n->req(); i+=2 )296if( n->in(i) == def ) break; // Common case297if( i == n->req() ) { // Missed, try a more generous scan298// Scan again, but this time peek through copies299for( i = jvms->oopoff(); i < n->req(); i+=2 ) {300Node *m = n->in(i); // Get initial derived value301while( 1 ) {302Node *d = def; // Get initial reaching def303while( 1 ) { // Follow copies of reaching def to end304if( m == d ) goto found; // breaks 3 loops305int idx = d->is_Copy();306if( !idx ) break;307d = d->in(idx); // Link through copy308}309int idx = m->is_Copy();310if( !idx ) break;311m = m->in(idx);312}313}314guarantee( 0, "must find derived/base pair" );315}316found: ;317Node *base = n->in(i+1); // Base is other half of pair318int breg = regalloc->get_reg_first(base);319VMReg b = OptoReg::as_VMReg(OptoReg::Name(breg), framesize, max_inarg_slot);320321// I record liveness at safepoints BEFORE I make the inputs322// live. This is because argument oops are NOT live at a323// safepoint (or at least they cannot appear in the oopmap).324// Thus bases of base/derived pairs might not be in the325// liveness data but they need to appear in the oopmap.326if( get_live_bit(live,breg) == 0 ) {// Not live?327// Flag it, so next derived pointer won't re-insert into oopmap328set_live_bit(live,breg);329// Already missed our turn?330if( breg < reg ) {331if (b->is_stack() || b->is_concrete() || true ) {332omap->set_oop( b);333}334}335}336if (b->is_stack() || b->is_concrete() || true ) {337omap->set_derived_oop( r, b);338}339}340341} else if( t->isa_narrowoop() ) {342assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );343// Check for a legal reg name in the oopMap and bailout if it is not.344if (!omap->legal_vm_reg_name(r)) {345regalloc->C->record_method_not_compilable("illegal oopMap register name");346continue;347}348if( mcall ) {349// Outgoing argument GC mask responsibility belongs to the callee,350// not the caller. Inspect the inputs to the call, to see if351// this live-range is one of them.352uint cnt = mcall->tf()->domain()->cnt();353uint j;354for( j = TypeFunc::Parms; j < cnt; j++)355if( mcall->in(j) == def )356break; // reaching def is an argument oop357if( j < cnt ) // arg oops dont go in GC map358continue; // Continue on to the next register359}360omap->set_narrowoop(r);361} else if( OptoReg::is_valid(_callees[reg])) { // callee-save?362// It's a callee-save value363assert( dup_check[_callees[reg]]==0, "trying to callee save same reg twice" );364debug_only( dup_check[_callees[reg]]=1; )365VMReg callee = OptoReg::as_VMReg(OptoReg::Name(_callees[reg]));366if ( callee->is_concrete() || true ) {367omap->set_callee_saved( r, callee);368}369370} else {371// Other - some reaching non-oop value372omap->set_value( r);373#ifdef ASSERT374if( t->isa_rawptr() && C->cfg()->_raw_oops.member(def) ) {375def->dump();376n->dump();377assert(false, "there should be a oop in OopMap instead of a live raw oop at safepoint");378}379#endif380}381382}383384#ifdef ASSERT385/* Nice, Intel-only assert386int cnt_callee_saves=0;387int reg2 = 0;388while (OptoReg::is_reg(reg2)) {389if( dup_check[reg2] != 0) cnt_callee_saves++;390assert( cnt_callee_saves==3 || cnt_callee_saves==5, "missed some callee-save" );391reg2++;392}393*/394#endif395396#ifdef ASSERT397for( OopMapStream oms1(omap, OopMapValue::derived_oop_value); !oms1.is_done(); oms1.next()) {398OopMapValue omv1 = oms1.current();399bool found = false;400for( OopMapStream oms2(omap,OopMapValue::oop_value); !oms2.is_done(); oms2.next()) {401if( omv1.content_reg() == oms2.current().reg() ) {402found = true;403break;404}405}406assert( found, "derived with no base in oopmap" );407}408#endif409410return omap;411}412413// Compute backwards liveness on registers414static void do_liveness(PhaseRegAlloc* regalloc, PhaseCFG* cfg, Block_List* worklist, int max_reg_ints, Arena* A, Dict* safehash) {415int* live = NEW_ARENA_ARRAY(A, int, (cfg->number_of_blocks() + 1) * max_reg_ints);416int* tmp_live = &live[cfg->number_of_blocks() * max_reg_ints];417Node* root = cfg->get_root_node();418// On CISC platforms, get the node representing the stack pointer that regalloc419// used for spills420Node *fp = NodeSentinel;421if (UseCISCSpill && root->req() > 1) {422fp = root->in(1)->in(TypeFunc::FramePtr);423}424memset(live, 0, cfg->number_of_blocks() * (max_reg_ints << LogBytesPerInt));425// Push preds onto worklist426for (uint i = 1; i < root->req(); i++) {427Block* block = cfg->get_block_for_node(root->in(i));428worklist->push(block);429}430431// ZKM.jar includes tiny infinite loops which are unreached from below.432// If we missed any blocks, we'll retry here after pushing all missed433// blocks on the worklist. Normally this outer loop never trips more434// than once.435while (1) {436437while( worklist->size() ) { // Standard worklist algorithm438Block *b = worklist->rpop();439440// Copy first successor into my tmp_live space441int s0num = b->_succs[0]->_pre_order;442int *t = &live[s0num*max_reg_ints];443for( int i=0; i<max_reg_ints; i++ )444tmp_live[i] = t[i];445446// OR in the remaining live registers447for( uint j=1; j<b->_num_succs; j++ ) {448uint sjnum = b->_succs[j]->_pre_order;449int *t = &live[sjnum*max_reg_ints];450for( int i=0; i<max_reg_ints; i++ )451tmp_live[i] |= t[i];452}453454// Now walk tmp_live up the block backwards, computing live455for( int k=b->number_of_nodes()-1; k>=0; k-- ) {456Node *n = b->get_node(k);457// KILL def'd bits458int first = regalloc->get_reg_first(n);459int second = regalloc->get_reg_second(n);460if( OptoReg::is_valid(first) ) clr_live_bit(tmp_live,first);461if( OptoReg::is_valid(second) ) clr_live_bit(tmp_live,second);462463MachNode *m = n->is_Mach() ? n->as_Mach() : NULL;464465// Check if m is potentially a CISC alternate instruction (i.e, possibly466// synthesized by RegAlloc from a conventional instruction and a467// spilled input)468bool is_cisc_alternate = false;469if (UseCISCSpill && m) {470is_cisc_alternate = m->is_cisc_alternate();471}472473// GEN use'd bits474for( uint l=1; l<n->req(); l++ ) {475Node *def = n->in(l);476assert(def != 0, "input edge required");477int first = regalloc->get_reg_first(def);478int second = regalloc->get_reg_second(def);479if( OptoReg::is_valid(first) ) set_live_bit(tmp_live,first);480if( OptoReg::is_valid(second) ) set_live_bit(tmp_live,second);481// If we use the stack pointer in a cisc-alternative instruction,482// check for use as a memory operand. Then reconstruct the RegName483// for this stack location, and set the appropriate bit in the484// live vector 4987749.485if (is_cisc_alternate && def == fp) {486const TypePtr *adr_type = NULL;487intptr_t offset;488const Node* base = m->get_base_and_disp(offset, adr_type);489if (base == NodeSentinel) {490// Machnode has multiple memory inputs. We are unable to reason491// with these, but are presuming (with trepidation) that not any of492// them are oops. This can be fixed by making get_base_and_disp()493// look at a specific input instead of all inputs.494assert(!def->bottom_type()->isa_oop_ptr(), "expecting non-oop mem input");495} else if (base != fp || offset == Type::OffsetBot) {496// Do nothing: the fp operand is either not from a memory use497// (base == NULL) OR the fp is used in a non-memory context498// (base is some other register) OR the offset is not constant,499// so it is not a stack slot.500} else {501assert(offset >= 0, "unexpected negative offset");502offset -= (offset % jintSize); // count the whole word503int stack_reg = regalloc->offset2reg(offset);504if (OptoReg::is_stack(stack_reg)) {505set_live_bit(tmp_live, stack_reg);506} else {507assert(false, "stack_reg not on stack?");508}509}510}511}512513if( n->jvms() ) { // Record liveness at safepoint514515// This placement of this stanza means inputs to calls are516// considered live at the callsite's OopMap. Argument oops are517// hence live, but NOT included in the oopmap. See cutout in518// build_oop_map. Debug oops are live (and in OopMap).519int *n_live = NEW_ARENA_ARRAY(A, int, max_reg_ints);520for( int l=0; l<max_reg_ints; l++ )521n_live[l] = tmp_live[l];522safehash->Insert(n,n_live);523}524525}526527// Now at block top, see if we have any changes. If so, propagate528// to prior blocks.529int *old_live = &live[b->_pre_order*max_reg_ints];530int l;531for( l=0; l<max_reg_ints; l++ )532if( tmp_live[l] != old_live[l] )533break;534if( l<max_reg_ints ) { // Change!535// Copy in new value536for( l=0; l<max_reg_ints; l++ )537old_live[l] = tmp_live[l];538// Push preds onto worklist539for (l = 1; l < (int)b->num_preds(); l++) {540Block* block = cfg->get_block_for_node(b->pred(l));541worklist->push(block);542}543}544}545546// Scan for any missing safepoints. Happens to infinite loops547// ala ZKM.jar548uint i;549for (i = 1; i < cfg->number_of_blocks(); i++) {550Block* block = cfg->get_block(i);551uint j;552for (j = 1; j < block->number_of_nodes(); j++) {553if (block->get_node(j)->jvms() && (*safehash)[block->get_node(j)] == NULL) {554break;555}556}557if (j < block->number_of_nodes()) {558break;559}560}561if (i == cfg->number_of_blocks()) {562break; // Got 'em all563}564#ifndef PRODUCT565if( PrintOpto && Verbose )566tty->print_cr("retripping live calc");567#endif568// Force the issue (expensively): recheck everybody569for (i = 1; i < cfg->number_of_blocks(); i++) {570worklist->push(cfg->get_block(i));571}572}573}574575// Collect GC mask info - where are all the OOPs?576void Compile::BuildOopMaps() {577NOT_PRODUCT( TracePhase t3("bldOopMaps", &_t_buildOopMaps, TimeCompiler); )578// Can't resource-mark because I need to leave all those OopMaps around,579// or else I need to resource-mark some arena other than the default.580// ResourceMark rm; // Reclaim all OopFlows when done581int max_reg = _regalloc->_max_reg; // Current array extent582583Arena *A = Thread::current()->resource_area();584Block_List worklist; // Worklist of pending blocks585586int max_reg_ints = round_to(max_reg, BitsPerInt)>>LogBitsPerInt;587Dict *safehash = NULL; // Used for assert only588// Compute a backwards liveness per register. Needs a bitarray of589// #blocks x (#registers, rounded up to ints)590safehash = new Dict(cmpkey,hashkey,A);591do_liveness( _regalloc, _cfg, &worklist, max_reg_ints, A, safehash );592OopFlow *free_list = NULL; // Free, unused593594// Array mapping blocks to completed oopflows595OopFlow **flows = NEW_ARENA_ARRAY(A, OopFlow*, _cfg->number_of_blocks());596memset( flows, 0, _cfg->number_of_blocks() * sizeof(OopFlow*) );597598599// Do the first block 'by hand' to prime the worklist600Block *entry = _cfg->get_block(1);601OopFlow *rootflow = OopFlow::make(A,max_reg,this);602// Initialize to 'bottom' (not 'top')603memset( rootflow->_callees, OptoReg::Bad, max_reg*sizeof(short) );604memset( rootflow->_defs , 0, max_reg*sizeof(Node*) );605flows[entry->_pre_order] = rootflow;606607// Do the first block 'by hand' to prime the worklist608rootflow->_b = entry;609rootflow->compute_reach( _regalloc, max_reg, safehash );610for( uint i=0; i<entry->_num_succs; i++ )611worklist.push(entry->_succs[i]);612613// Now worklist contains blocks which have some, but perhaps not all,614// predecessors visited.615while( worklist.size() ) {616// Scan for a block with all predecessors visited, or any randoms slob617// otherwise. All-preds-visited order allows me to recycle OopFlow618// structures rapidly and cut down on the memory footprint.619// Note: not all predecessors might be visited yet (must happen for620// irreducible loops). This is OK, since every live value must have the621// SAME reaching def for the block, so any reaching def is OK.622uint i;623624Block *b = worklist.pop();625// Ignore root block626if (b == _cfg->get_root_block()) {627continue;628}629// Block is already done? Happens if block has several predecessors,630// he can get on the worklist more than once.631if( flows[b->_pre_order] ) continue;632633// If this block has a visited predecessor AND that predecessor has this634// last block as his only undone child, we can move the OopFlow from the635// pred to this block. Otherwise we have to grab a new OopFlow.636OopFlow *flow = NULL; // Flag for finding optimized flow637Block *pred = (Block*)((intptr_t)0xdeadbeef);638// Scan this block's preds to find a done predecessor639for (uint j = 1; j < b->num_preds(); j++) {640Block* p = _cfg->get_block_for_node(b->pred(j));641OopFlow *p_flow = flows[p->_pre_order];642if( p_flow ) { // Predecessor is done643assert( p_flow->_b == p, "cross check" );644pred = p; // Record some predecessor645// If all successors of p are done except for 'b', then we can carry646// p_flow forward to 'b' without copying, otherwise we have to draw647// from the free_list and clone data.648uint k;649for( k=0; k<p->_num_succs; k++ )650if( !flows[p->_succs[k]->_pre_order] &&651p->_succs[k] != b )652break;653654// Either carry-forward the now-unused OopFlow for b's use655// or draw a new one from the free list656if( k==p->_num_succs ) {657flow = p_flow;658break; // Found an ideal pred, use him659}660}661}662663if( flow ) {664// We have an OopFlow that's the last-use of a predecessor.665// Carry it forward.666} else { // Draw a new OopFlow from the freelist667if( !free_list )668free_list = OopFlow::make(A,max_reg,C);669flow = free_list;670assert( flow->_b == NULL, "oopFlow is not free" );671free_list = flow->_next;672flow->_next = NULL;673674// Copy/clone over the data675flow->clone(flows[pred->_pre_order], max_reg);676}677678// Mark flow for block. Blocks can only be flowed over once,679// because after the first time they are guarded from entering680// this code again.681assert( flow->_b == pred, "have some prior flow" );682flow->_b = NULL;683684// Now push flow forward685flows[b->_pre_order] = flow;// Mark flow for this block686flow->_b = b;687flow->compute_reach( _regalloc, max_reg, safehash );688689// Now push children onto worklist690for( i=0; i<b->_num_succs; i++ )691worklist.push(b->_succs[i]);692693}694}695696697