Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/opto/buildOopMap.cpp
32285 views
1
/*
2
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "compiler/oopMap.hpp"
27
#include "opto/addnode.hpp"
28
#include "opto/callnode.hpp"
29
#include "opto/compile.hpp"
30
#include "opto/machnode.hpp"
31
#include "opto/matcher.hpp"
32
#include "opto/phase.hpp"
33
#include "opto/regalloc.hpp"
34
#include "opto/rootnode.hpp"
35
#ifdef TARGET_ARCH_x86
36
# include "vmreg_x86.inline.hpp"
37
#endif
38
#ifdef TARGET_ARCH_aarch32
39
# include "vmreg_aarch32.inline.hpp"
40
#endif
41
#ifdef TARGET_ARCH_aarch64
42
# include "vmreg_aarch64.inline.hpp"
43
#endif
44
#ifdef TARGET_ARCH_sparc
45
# include "vmreg_sparc.inline.hpp"
46
#endif
47
#ifdef TARGET_ARCH_zero
48
# include "vmreg_zero.inline.hpp"
49
#endif
50
#ifdef TARGET_ARCH_arm
51
# include "vmreg_arm.inline.hpp"
52
#endif
53
#ifdef TARGET_ARCH_ppc
54
# include "vmreg_ppc.inline.hpp"
55
#endif
56
57
// The functions in this file builds OopMaps after all scheduling is done.
58
//
59
// OopMaps contain a list of all registers and stack-slots containing oops (so
60
// they can be updated by GC). OopMaps also contain a list of derived-pointer
61
// base-pointer pairs. When the base is moved, the derived pointer moves to
62
// follow it. Finally, any registers holding callee-save values are also
63
// recorded. These might contain oops, but only the caller knows.
64
//
65
// BuildOopMaps implements a simple forward reaching-defs solution. At each
66
// GC point we'll have the reaching-def Nodes. If the reaching Nodes are
67
// typed as pointers (no offset), then they are oops. Pointers+offsets are
68
// derived pointers, and bases can be found from them. Finally, we'll also
69
// track reaching callee-save values. Note that a copy of a callee-save value
70
// "kills" it's source, so that only 1 copy of a callee-save value is alive at
71
// a time.
72
//
73
// We run a simple bitvector liveness pass to help trim out dead oops. Due to
74
// irreducible loops, we can have a reaching def of an oop that only reaches
75
// along one path and no way to know if it's valid or not on the other path.
76
// The bitvectors are quite dense and the liveness pass is fast.
77
//
78
// At GC points, we consult this information to build OopMaps. All reaching
79
// defs typed as oops are added to the OopMap. Only 1 instance of a
80
// callee-save register can be recorded. For derived pointers, we'll have to
81
// find and record the register holding the base.
82
//
83
// The reaching def's is a simple 1-pass worklist approach. I tried a clever
84
// breadth-first approach but it was worse (showed O(n^2) in the
85
// pick-next-block code).
86
//
87
// The relevant data is kept in a struct of arrays (it could just as well be
88
// an array of structs, but the struct-of-arrays is generally a little more
89
// efficient). The arrays are indexed by register number (including
90
// stack-slots as registers) and so is bounded by 200 to 300 elements in
91
// practice. One array will map to a reaching def Node (or NULL for
92
// conflict/dead). The other array will map to a callee-saved register or
93
// OptoReg::Bad for not-callee-saved.
94
95
96
// Structure to pass around
97
struct OopFlow : public ResourceObj {
98
short *_callees; // Array mapping register to callee-saved
99
Node **_defs; // array mapping register to reaching def
100
// or NULL if dead/conflict
101
// OopFlow structs, when not being actively modified, describe the _end_ of
102
// this block.
103
Block *_b; // Block for this struct
104
OopFlow *_next; // Next free OopFlow
105
// or NULL if dead/conflict
106
Compile* C;
107
108
OopFlow( short *callees, Node **defs, Compile* c ) : _callees(callees), _defs(defs),
109
_b(NULL), _next(NULL), C(c) { }
110
111
// Given reaching-defs for this block start, compute it for this block end
112
void compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash );
113
114
// Merge these two OopFlows into the 'this' pointer.
115
void merge( OopFlow *flow, int max_reg );
116
117
// Copy a 'flow' over an existing flow
118
void clone( OopFlow *flow, int max_size);
119
120
// Make a new OopFlow from scratch
121
static OopFlow *make( Arena *A, int max_size, Compile* C );
122
123
// Build an oopmap from the current flow info
124
OopMap *build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live );
125
};
126
127
// Given reaching-defs for this block start, compute it for this block end
128
void OopFlow::compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ) {
129
130
for( uint i=0; i<_b->number_of_nodes(); i++ ) {
131
Node *n = _b->get_node(i);
132
133
if( n->jvms() ) { // Build an OopMap here?
134
JVMState *jvms = n->jvms();
135
// no map needed for leaf calls
136
if( n->is_MachSafePoint() && !n->is_MachCallLeaf() ) {
137
int *live = (int*) (*safehash)[n];
138
assert( live, "must find live" );
139
n->as_MachSafePoint()->set_oop_map( build_oop_map(n,max_reg,regalloc, live) );
140
}
141
}
142
143
// Assign new reaching def's.
144
// Note that I padded the _defs and _callees arrays so it's legal
145
// to index at _defs[OptoReg::Bad].
146
OptoReg::Name first = regalloc->get_reg_first(n);
147
OptoReg::Name second = regalloc->get_reg_second(n);
148
_defs[first] = n;
149
_defs[second] = n;
150
151
// Pass callee-save info around copies
152
int idx = n->is_Copy();
153
if( idx ) { // Copies move callee-save info
154
OptoReg::Name old_first = regalloc->get_reg_first(n->in(idx));
155
OptoReg::Name old_second = regalloc->get_reg_second(n->in(idx));
156
int tmp_first = _callees[old_first];
157
int tmp_second = _callees[old_second];
158
_callees[old_first] = OptoReg::Bad; // callee-save is moved, dead in old location
159
_callees[old_second] = OptoReg::Bad;
160
_callees[first] = tmp_first;
161
_callees[second] = tmp_second;
162
} else if( n->is_Phi() ) { // Phis do not mod callee-saves
163
assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(1))], "" );
164
assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(1))], "" );
165
assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(n->req()-1))], "" );
166
assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(n->req()-1))], "" );
167
} else {
168
_callees[first] = OptoReg::Bad; // No longer holding a callee-save value
169
_callees[second] = OptoReg::Bad;
170
171
// Find base case for callee saves
172
if( n->is_Proj() && n->in(0)->is_Start() ) {
173
if( OptoReg::is_reg(first) &&
174
regalloc->_matcher.is_save_on_entry(first) )
175
_callees[first] = first;
176
if( OptoReg::is_reg(second) &&
177
regalloc->_matcher.is_save_on_entry(second) )
178
_callees[second] = second;
179
}
180
}
181
}
182
}
183
184
// Merge the given flow into the 'this' flow
185
void OopFlow::merge( OopFlow *flow, int max_reg ) {
186
assert( _b == NULL, "merging into a happy flow" );
187
assert( flow->_b, "this flow is still alive" );
188
assert( flow != this, "no self flow" );
189
190
// Do the merge. If there are any differences, drop to 'bottom' which
191
// is OptoReg::Bad or NULL depending.
192
for( int i=0; i<max_reg; i++ ) {
193
// Merge the callee-save's
194
if( _callees[i] != flow->_callees[i] )
195
_callees[i] = OptoReg::Bad;
196
// Merge the reaching defs
197
if( _defs[i] != flow->_defs[i] )
198
_defs[i] = NULL;
199
}
200
201
}
202
203
void OopFlow::clone( OopFlow *flow, int max_size ) {
204
_b = flow->_b;
205
memcpy( _callees, flow->_callees, sizeof(short)*max_size);
206
memcpy( _defs , flow->_defs , sizeof(Node*)*max_size);
207
}
208
209
OopFlow *OopFlow::make( Arena *A, int max_size, Compile* C ) {
210
short *callees = NEW_ARENA_ARRAY(A,short,max_size+1);
211
Node **defs = NEW_ARENA_ARRAY(A,Node*,max_size+1);
212
debug_only( memset(defs,0,(max_size+1)*sizeof(Node*)) );
213
OopFlow *flow = new (A) OopFlow(callees+1, defs+1, C);
214
assert( &flow->_callees[OptoReg::Bad] == callees, "Ok to index at OptoReg::Bad" );
215
assert( &flow->_defs [OptoReg::Bad] == defs , "Ok to index at OptoReg::Bad" );
216
return flow;
217
}
218
219
static int get_live_bit( int *live, int reg ) {
220
return live[reg>>LogBitsPerInt] & (1<<(reg&(BitsPerInt-1))); }
221
static void set_live_bit( int *live, int reg ) {
222
live[reg>>LogBitsPerInt] |= (1<<(reg&(BitsPerInt-1))); }
223
static void clr_live_bit( int *live, int reg ) {
224
live[reg>>LogBitsPerInt] &= ~(1<<(reg&(BitsPerInt-1))); }
225
226
// Build an oopmap from the current flow info
227
OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ) {
228
int framesize = regalloc->_framesize;
229
int max_inarg_slot = OptoReg::reg2stack(regalloc->_matcher._new_SP);
230
debug_only( char *dup_check = NEW_RESOURCE_ARRAY(char,OptoReg::stack0());
231
memset(dup_check,0,OptoReg::stack0()) );
232
233
OopMap *omap = new OopMap( framesize, max_inarg_slot );
234
MachCallNode *mcall = n->is_MachCall() ? n->as_MachCall() : NULL;
235
JVMState* jvms = n->jvms();
236
237
// For all registers do...
238
for( int reg=0; reg<max_reg; reg++ ) {
239
if( get_live_bit(live,reg) == 0 )
240
continue; // Ignore if not live
241
242
// %%% C2 can use 2 OptoRegs when the physical register is only one 64bit
243
// register in that case we'll get an non-concrete register for the second
244
// half. We only need to tell the map the register once!
245
//
246
// However for the moment we disable this change and leave things as they
247
// were.
248
249
VMReg r = OptoReg::as_VMReg(OptoReg::Name(reg), framesize, max_inarg_slot);
250
251
if (false && r->is_reg() && !r->is_concrete()) {
252
continue;
253
}
254
255
// See if dead (no reaching def).
256
Node *def = _defs[reg]; // Get reaching def
257
assert( def, "since live better have reaching def" );
258
259
// Classify the reaching def as oop, derived, callee-save, dead, or other
260
const Type *t = def->bottom_type();
261
if( t->isa_oop_ptr() ) { // Oop or derived?
262
assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );
263
#ifdef _LP64
264
// 64-bit pointers record oop-ishness on 2 aligned adjacent registers.
265
// Make sure both are record from the same reaching def, but do not
266
// put both into the oopmap.
267
if( (reg&1) == 1 ) { // High half of oop-pair?
268
assert( _defs[reg-1] == _defs[reg], "both halves from same reaching def" );
269
continue; // Do not record high parts in oopmap
270
}
271
#endif
272
273
// Check for a legal reg name in the oopMap and bailout if it is not.
274
if (!omap->legal_vm_reg_name(r)) {
275
regalloc->C->record_method_not_compilable("illegal oopMap register name");
276
continue;
277
}
278
if( t->is_ptr()->_offset == 0 ) { // Not derived?
279
if( mcall ) {
280
// Outgoing argument GC mask responsibility belongs to the callee,
281
// not the caller. Inspect the inputs to the call, to see if
282
// this live-range is one of them.
283
uint cnt = mcall->tf()->domain()->cnt();
284
uint j;
285
for( j = TypeFunc::Parms; j < cnt; j++)
286
if( mcall->in(j) == def )
287
break; // reaching def is an argument oop
288
if( j < cnt ) // arg oops dont go in GC map
289
continue; // Continue on to the next register
290
}
291
omap->set_oop(r);
292
} else { // Else it's derived.
293
// Find the base of the derived value.
294
uint i;
295
// Fast, common case, scan
296
for( i = jvms->oopoff(); i < n->req(); i+=2 )
297
if( n->in(i) == def ) break; // Common case
298
if( i == n->req() ) { // Missed, try a more generous scan
299
// Scan again, but this time peek through copies
300
for( i = jvms->oopoff(); i < n->req(); i+=2 ) {
301
Node *m = n->in(i); // Get initial derived value
302
while( 1 ) {
303
Node *d = def; // Get initial reaching def
304
while( 1 ) { // Follow copies of reaching def to end
305
if( m == d ) goto found; // breaks 3 loops
306
int idx = d->is_Copy();
307
if( !idx ) break;
308
d = d->in(idx); // Link through copy
309
}
310
int idx = m->is_Copy();
311
if( !idx ) break;
312
m = m->in(idx);
313
}
314
}
315
guarantee( 0, "must find derived/base pair" );
316
}
317
found: ;
318
Node *base = n->in(i+1); // Base is other half of pair
319
int breg = regalloc->get_reg_first(base);
320
VMReg b = OptoReg::as_VMReg(OptoReg::Name(breg), framesize, max_inarg_slot);
321
322
// I record liveness at safepoints BEFORE I make the inputs
323
// live. This is because argument oops are NOT live at a
324
// safepoint (or at least they cannot appear in the oopmap).
325
// Thus bases of base/derived pairs might not be in the
326
// liveness data but they need to appear in the oopmap.
327
if( get_live_bit(live,breg) == 0 ) {// Not live?
328
// Flag it, so next derived pointer won't re-insert into oopmap
329
set_live_bit(live,breg);
330
// Already missed our turn?
331
if( breg < reg ) {
332
if (b->is_stack() || b->is_concrete() || true ) {
333
omap->set_oop( b);
334
}
335
}
336
}
337
if (b->is_stack() || b->is_concrete() || true ) {
338
omap->set_derived_oop( r, b);
339
}
340
}
341
342
} else if( t->isa_narrowoop() ) {
343
assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );
344
// Check for a legal reg name in the oopMap and bailout if it is not.
345
if (!omap->legal_vm_reg_name(r)) {
346
regalloc->C->record_method_not_compilable("illegal oopMap register name");
347
continue;
348
}
349
if( mcall ) {
350
// Outgoing argument GC mask responsibility belongs to the callee,
351
// not the caller. Inspect the inputs to the call, to see if
352
// this live-range is one of them.
353
uint cnt = mcall->tf()->domain()->cnt();
354
uint j;
355
for( j = TypeFunc::Parms; j < cnt; j++)
356
if( mcall->in(j) == def )
357
break; // reaching def is an argument oop
358
if( j < cnt ) // arg oops dont go in GC map
359
continue; // Continue on to the next register
360
}
361
omap->set_narrowoop(r);
362
} else if( OptoReg::is_valid(_callees[reg])) { // callee-save?
363
// It's a callee-save value
364
assert( dup_check[_callees[reg]]==0, "trying to callee save same reg twice" );
365
debug_only( dup_check[_callees[reg]]=1; )
366
VMReg callee = OptoReg::as_VMReg(OptoReg::Name(_callees[reg]));
367
if ( callee->is_concrete() || true ) {
368
omap->set_callee_saved( r, callee);
369
}
370
371
} else {
372
// Other - some reaching non-oop value
373
omap->set_value( r);
374
#ifdef ASSERT
375
if( t->isa_rawptr() && C->cfg()->_raw_oops.member(def) ) {
376
def->dump();
377
n->dump();
378
assert(false, "there should be a oop in OopMap instead of a live raw oop at safepoint");
379
}
380
#endif
381
}
382
383
}
384
385
#ifdef ASSERT
386
/* Nice, Intel-only assert
387
int cnt_callee_saves=0;
388
int reg2 = 0;
389
while (OptoReg::is_reg(reg2)) {
390
if( dup_check[reg2] != 0) cnt_callee_saves++;
391
assert( cnt_callee_saves==3 || cnt_callee_saves==5, "missed some callee-save" );
392
reg2++;
393
}
394
*/
395
#endif
396
397
#ifdef ASSERT
398
for( OopMapStream oms1(omap, OopMapValue::derived_oop_value); !oms1.is_done(); oms1.next()) {
399
OopMapValue omv1 = oms1.current();
400
bool found = false;
401
for( OopMapStream oms2(omap,OopMapValue::oop_value); !oms2.is_done(); oms2.next()) {
402
if( omv1.content_reg() == oms2.current().reg() ) {
403
found = true;
404
break;
405
}
406
}
407
assert( found, "derived with no base in oopmap" );
408
}
409
#endif
410
411
return omap;
412
}
413
414
// Compute backwards liveness on registers
415
static void do_liveness(PhaseRegAlloc* regalloc, PhaseCFG* cfg, Block_List* worklist, int max_reg_ints, Arena* A, Dict* safehash) {
416
int* live = NEW_ARENA_ARRAY(A, int, (cfg->number_of_blocks() + 1) * max_reg_ints);
417
int* tmp_live = &live[cfg->number_of_blocks() * max_reg_ints];
418
Node* root = cfg->get_root_node();
419
// On CISC platforms, get the node representing the stack pointer that regalloc
420
// used for spills
421
Node *fp = NodeSentinel;
422
if (UseCISCSpill && root->req() > 1) {
423
fp = root->in(1)->in(TypeFunc::FramePtr);
424
}
425
memset(live, 0, cfg->number_of_blocks() * (max_reg_ints << LogBytesPerInt));
426
// Push preds onto worklist
427
for (uint i = 1; i < root->req(); i++) {
428
Block* block = cfg->get_block_for_node(root->in(i));
429
worklist->push(block);
430
}
431
432
// ZKM.jar includes tiny infinite loops which are unreached from below.
433
// If we missed any blocks, we'll retry here after pushing all missed
434
// blocks on the worklist. Normally this outer loop never trips more
435
// than once.
436
while (1) {
437
438
while( worklist->size() ) { // Standard worklist algorithm
439
Block *b = worklist->rpop();
440
441
// Copy first successor into my tmp_live space
442
int s0num = b->_succs[0]->_pre_order;
443
int *t = &live[s0num*max_reg_ints];
444
for( int i=0; i<max_reg_ints; i++ )
445
tmp_live[i] = t[i];
446
447
// OR in the remaining live registers
448
for( uint j=1; j<b->_num_succs; j++ ) {
449
uint sjnum = b->_succs[j]->_pre_order;
450
int *t = &live[sjnum*max_reg_ints];
451
for( int i=0; i<max_reg_ints; i++ )
452
tmp_live[i] |= t[i];
453
}
454
455
// Now walk tmp_live up the block backwards, computing live
456
for( int k=b->number_of_nodes()-1; k>=0; k-- ) {
457
Node *n = b->get_node(k);
458
// KILL def'd bits
459
int first = regalloc->get_reg_first(n);
460
int second = regalloc->get_reg_second(n);
461
if( OptoReg::is_valid(first) ) clr_live_bit(tmp_live,first);
462
if( OptoReg::is_valid(second) ) clr_live_bit(tmp_live,second);
463
464
MachNode *m = n->is_Mach() ? n->as_Mach() : NULL;
465
466
// Check if m is potentially a CISC alternate instruction (i.e, possibly
467
// synthesized by RegAlloc from a conventional instruction and a
468
// spilled input)
469
bool is_cisc_alternate = false;
470
if (UseCISCSpill && m) {
471
is_cisc_alternate = m->is_cisc_alternate();
472
}
473
474
// GEN use'd bits
475
for( uint l=1; l<n->req(); l++ ) {
476
Node *def = n->in(l);
477
assert(def != 0, "input edge required");
478
int first = regalloc->get_reg_first(def);
479
int second = regalloc->get_reg_second(def);
480
if( OptoReg::is_valid(first) ) set_live_bit(tmp_live,first);
481
if( OptoReg::is_valid(second) ) set_live_bit(tmp_live,second);
482
// If we use the stack pointer in a cisc-alternative instruction,
483
// check for use as a memory operand. Then reconstruct the RegName
484
// for this stack location, and set the appropriate bit in the
485
// live vector 4987749.
486
if (is_cisc_alternate && def == fp) {
487
const TypePtr *adr_type = NULL;
488
intptr_t offset;
489
const Node* base = m->get_base_and_disp(offset, adr_type);
490
if (base == NodeSentinel) {
491
// Machnode has multiple memory inputs. We are unable to reason
492
// with these, but are presuming (with trepidation) that not any of
493
// them are oops. This can be fixed by making get_base_and_disp()
494
// look at a specific input instead of all inputs.
495
assert(!def->bottom_type()->isa_oop_ptr(), "expecting non-oop mem input");
496
} else if (base != fp || offset == Type::OffsetBot) {
497
// Do nothing: the fp operand is either not from a memory use
498
// (base == NULL) OR the fp is used in a non-memory context
499
// (base is some other register) OR the offset is not constant,
500
// so it is not a stack slot.
501
} else {
502
assert(offset >= 0, "unexpected negative offset");
503
offset -= (offset % jintSize); // count the whole word
504
int stack_reg = regalloc->offset2reg(offset);
505
if (OptoReg::is_stack(stack_reg)) {
506
set_live_bit(tmp_live, stack_reg);
507
} else {
508
assert(false, "stack_reg not on stack?");
509
}
510
}
511
}
512
}
513
514
if( n->jvms() ) { // Record liveness at safepoint
515
516
// This placement of this stanza means inputs to calls are
517
// considered live at the callsite's OopMap. Argument oops are
518
// hence live, but NOT included in the oopmap. See cutout in
519
// build_oop_map. Debug oops are live (and in OopMap).
520
int *n_live = NEW_ARENA_ARRAY(A, int, max_reg_ints);
521
for( int l=0; l<max_reg_ints; l++ )
522
n_live[l] = tmp_live[l];
523
safehash->Insert(n,n_live);
524
}
525
526
}
527
528
// Now at block top, see if we have any changes. If so, propagate
529
// to prior blocks.
530
int *old_live = &live[b->_pre_order*max_reg_ints];
531
int l;
532
for( l=0; l<max_reg_ints; l++ )
533
if( tmp_live[l] != old_live[l] )
534
break;
535
if( l<max_reg_ints ) { // Change!
536
// Copy in new value
537
for( l=0; l<max_reg_ints; l++ )
538
old_live[l] = tmp_live[l];
539
// Push preds onto worklist
540
for (l = 1; l < (int)b->num_preds(); l++) {
541
Block* block = cfg->get_block_for_node(b->pred(l));
542
worklist->push(block);
543
}
544
}
545
}
546
547
// Scan for any missing safepoints. Happens to infinite loops
548
// ala ZKM.jar
549
uint i;
550
for (i = 1; i < cfg->number_of_blocks(); i++) {
551
Block* block = cfg->get_block(i);
552
uint j;
553
for (j = 1; j < block->number_of_nodes(); j++) {
554
if (block->get_node(j)->jvms() && (*safehash)[block->get_node(j)] == NULL) {
555
break;
556
}
557
}
558
if (j < block->number_of_nodes()) {
559
break;
560
}
561
}
562
if (i == cfg->number_of_blocks()) {
563
break; // Got 'em all
564
}
565
#ifndef PRODUCT
566
if( PrintOpto && Verbose )
567
tty->print_cr("retripping live calc");
568
#endif
569
// Force the issue (expensively): recheck everybody
570
for (i = 1; i < cfg->number_of_blocks(); i++) {
571
worklist->push(cfg->get_block(i));
572
}
573
}
574
}
575
576
// Collect GC mask info - where are all the OOPs?
577
void Compile::BuildOopMaps() {
578
NOT_PRODUCT( TracePhase t3("bldOopMaps", &_t_buildOopMaps, TimeCompiler); )
579
// Can't resource-mark because I need to leave all those OopMaps around,
580
// or else I need to resource-mark some arena other than the default.
581
// ResourceMark rm; // Reclaim all OopFlows when done
582
int max_reg = _regalloc->_max_reg; // Current array extent
583
584
Arena *A = Thread::current()->resource_area();
585
Block_List worklist; // Worklist of pending blocks
586
587
int max_reg_ints = round_to(max_reg, BitsPerInt)>>LogBitsPerInt;
588
Dict *safehash = NULL; // Used for assert only
589
// Compute a backwards liveness per register. Needs a bitarray of
590
// #blocks x (#registers, rounded up to ints)
591
safehash = new Dict(cmpkey,hashkey,A);
592
do_liveness( _regalloc, _cfg, &worklist, max_reg_ints, A, safehash );
593
OopFlow *free_list = NULL; // Free, unused
594
595
// Array mapping blocks to completed oopflows
596
OopFlow **flows = NEW_ARENA_ARRAY(A, OopFlow*, _cfg->number_of_blocks());
597
memset( flows, 0, _cfg->number_of_blocks() * sizeof(OopFlow*) );
598
599
600
// Do the first block 'by hand' to prime the worklist
601
Block *entry = _cfg->get_block(1);
602
OopFlow *rootflow = OopFlow::make(A,max_reg,this);
603
// Initialize to 'bottom' (not 'top')
604
memset( rootflow->_callees, OptoReg::Bad, max_reg*sizeof(short) );
605
memset( rootflow->_defs , 0, max_reg*sizeof(Node*) );
606
flows[entry->_pre_order] = rootflow;
607
608
// Do the first block 'by hand' to prime the worklist
609
rootflow->_b = entry;
610
rootflow->compute_reach( _regalloc, max_reg, safehash );
611
for( uint i=0; i<entry->_num_succs; i++ )
612
worklist.push(entry->_succs[i]);
613
614
// Now worklist contains blocks which have some, but perhaps not all,
615
// predecessors visited.
616
while( worklist.size() ) {
617
// Scan for a block with all predecessors visited, or any randoms slob
618
// otherwise. All-preds-visited order allows me to recycle OopFlow
619
// structures rapidly and cut down on the memory footprint.
620
// Note: not all predecessors might be visited yet (must happen for
621
// irreducible loops). This is OK, since every live value must have the
622
// SAME reaching def for the block, so any reaching def is OK.
623
uint i;
624
625
Block *b = worklist.pop();
626
// Ignore root block
627
if (b == _cfg->get_root_block()) {
628
continue;
629
}
630
// Block is already done? Happens if block has several predecessors,
631
// he can get on the worklist more than once.
632
if( flows[b->_pre_order] ) continue;
633
634
// If this block has a visited predecessor AND that predecessor has this
635
// last block as his only undone child, we can move the OopFlow from the
636
// pred to this block. Otherwise we have to grab a new OopFlow.
637
OopFlow *flow = NULL; // Flag for finding optimized flow
638
Block *pred = (Block*)((intptr_t)0xdeadbeef);
639
// Scan this block's preds to find a done predecessor
640
for (uint j = 1; j < b->num_preds(); j++) {
641
Block* p = _cfg->get_block_for_node(b->pred(j));
642
OopFlow *p_flow = flows[p->_pre_order];
643
if( p_flow ) { // Predecessor is done
644
assert( p_flow->_b == p, "cross check" );
645
pred = p; // Record some predecessor
646
// If all successors of p are done except for 'b', then we can carry
647
// p_flow forward to 'b' without copying, otherwise we have to draw
648
// from the free_list and clone data.
649
uint k;
650
for( k=0; k<p->_num_succs; k++ )
651
if( !flows[p->_succs[k]->_pre_order] &&
652
p->_succs[k] != b )
653
break;
654
655
// Either carry-forward the now-unused OopFlow for b's use
656
// or draw a new one from the free list
657
if( k==p->_num_succs ) {
658
flow = p_flow;
659
break; // Found an ideal pred, use him
660
}
661
}
662
}
663
664
if( flow ) {
665
// We have an OopFlow that's the last-use of a predecessor.
666
// Carry it forward.
667
} else { // Draw a new OopFlow from the freelist
668
if( !free_list )
669
free_list = OopFlow::make(A,max_reg,C);
670
flow = free_list;
671
assert( flow->_b == NULL, "oopFlow is not free" );
672
free_list = flow->_next;
673
flow->_next = NULL;
674
675
// Copy/clone over the data
676
flow->clone(flows[pred->_pre_order], max_reg);
677
}
678
679
// Mark flow for block. Blocks can only be flowed over once,
680
// because after the first time they are guarded from entering
681
// this code again.
682
assert( flow->_b == pred, "have some prior flow" );
683
flow->_b = NULL;
684
685
// Now push flow forward
686
flows[b->_pre_order] = flow;// Mark flow for this block
687
flow->_b = b;
688
flow->compute_reach( _regalloc, max_reg, safehash );
689
690
// Now push children onto worklist
691
for( i=0; i<b->_num_succs; i++ )
692
worklist.push(b->_succs[i]);
693
694
}
695
}
696
697