1
1
/*
2
- * Copyright (c) 1999, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1999, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -1263,21 +1263,36 @@ void IR::print(bool cfg_only, bool live_only) {
1263
1263
tty->print_cr (" invalid IR" );
1264
1264
}
1265
1265
}
1266
+ #endif // PRODUCT
1266
1267
1268
+ #ifdef ASSERT
1267
1269
class EndNotNullValidator : public BlockClosure {
1268
1270
public:
1269
- EndNotNullValidator (IR* hir ) {
1270
- hir-> start ()-> iterate_postorder ( this );
1271
+ virtual void block_do (BlockBegin* block ) {
1272
+ assert (block-> end () != NULL , " Expect block end to exist. " );
1271
1273
}
1274
+ };
1272
1275
1273
- void block_do (BlockBegin* block) {
1274
- assert (block->end () != NULL , " Expect block end to exist." );
1276
+ class XentryFlagValidator : public BlockClosure {
1277
+ public:
1278
+ virtual void block_do (BlockBegin* block) {
1279
+ for (int i = 0 ; i < block->end ()->number_of_sux (); i++) {
1280
+ assert (!block->end ()->sux_at (i)->is_set (BlockBegin::exception_entry_flag), " must not be xhandler" );
1281
+ }
1282
+ for (int i = 0 ; i < block->number_of_exception_handlers (); i++) {
1283
+ assert (block->exception_handler_at (i)->is_set (BlockBegin::exception_entry_flag), " must be xhandler" );
1284
+ }
1275
1285
}
1276
1286
};
1277
1287
1278
1288
typedef GrowableArray<BlockList*> BlockListList;
1279
1289
1280
- class PredecessorValidator : public BlockClosure {
1290
+ // Validation goals:
1291
+ // - code() length == blocks length
1292
+ // - code() contents == blocks content
1293
+ // - Each block's computed predecessors match sux lists (length)
1294
+ // - Each block's computed predecessors match sux lists (set content)
1295
+ class PredecessorAndCodeValidator : public BlockClosure {
1281
1296
private:
1282
1297
BlockListList* _predecessors; // Each index i will hold predecessors of block with id i
1283
1298
BlockList* _blocks;
@@ -1287,7 +1302,7 @@ class PredecessorValidator : public BlockClosure {
1287
1302
}
1288
1303
1289
1304
public:
1290
- PredecessorValidator (IR* hir) {
1305
+ PredecessorAndCodeValidator (IR* hir) {
1291
1306
ResourceMark rm;
1292
1307
_predecessors = new BlockListList (BlockBegin::number_of_blocks (), BlockBegin::number_of_blocks (), NULL );
1293
1308
_blocks = new BlockList (BlockBegin::number_of_blocks ());
@@ -1308,20 +1323,10 @@ class PredecessorValidator : public BlockClosure {
1308
1323
1309
1324
virtual void block_do (BlockBegin* block) {
1310
1325
_blocks->append (block);
1311
- verify_successor_xentry_flag (block);
1312
1326
collect_predecessors (block);
1313
1327
}
1314
1328
1315
1329
private:
1316
- void verify_successor_xentry_flag (const BlockBegin* block) const {
1317
- for (int i = 0 ; i < block->end ()->number_of_sux (); i++) {
1318
- assert (!block->end ()->sux_at (i)->is_set (BlockBegin::exception_entry_flag), " must not be xhandler" );
1319
- }
1320
- for (int i = 0 ; i < block->number_of_exception_handlers (); i++) {
1321
- assert (block->exception_handler_at (i)->is_set (BlockBegin::exception_entry_flag), " must be xhandler" );
1322
- }
1323
- }
1324
-
1325
1330
void collect_predecessors (BlockBegin* block) {
1326
1331
for (int i = 0 ; i < block->end ()->number_of_sux (); i++) {
1327
1332
collect_predecessor (block, block->end ()->sux_at (i));
@@ -1363,26 +1368,87 @@ class PredecessorValidator : public BlockClosure {
1363
1368
};
1364
1369
1365
1370
class VerifyBlockBeginField : public BlockClosure {
1366
-
1367
1371
public:
1368
-
1369
- virtual void block_do (BlockBegin *block) {
1370
- for ( Instruction *cur = block; cur != NULL ; cur = cur->next ()) {
1372
+ virtual void block_do (BlockBegin* block) {
1373
+ for (Instruction* cur = block; cur != NULL ; cur = cur->next ()) {
1371
1374
assert (cur->block () == block, " Block begin is not correct" );
1372
1375
}
1373
1376
}
1374
1377
};
1375
1378
1376
- void IR::verify () {
1377
- #ifdef ASSERT
1378
- PredecessorValidator pv (this );
1379
- EndNotNullValidator (this );
1379
+ class ValidateEdgeMutuality : public BlockClosure {
1380
+ public:
1381
+ virtual void block_do (BlockBegin* block) {
1382
+ for (int i = 0 ; i < block->end ()->number_of_sux (); i++) {
1383
+ assert (block->end ()->sux_at (i)->is_predecessor (block), " Block's successor should have it as predecessor" );
1384
+ }
1385
+
1386
+ for (int i = 0 ; i < block->number_of_exception_handlers (); i++) {
1387
+ assert (block->exception_handler_at (i)->is_predecessor (block), " Block's exception handler should have it as predecessor" );
1388
+ }
1389
+
1390
+ for (int i = 0 ; i < block->number_of_preds (); i++) {
1391
+ assert (block->pred_at (i) != NULL , " Predecessor must exist" );
1392
+ assert (block->pred_at (i)->end () != NULL , " Predecessor end must exist" );
1393
+ bool is_sux = block->pred_at (i)->end ()->is_sux (block);
1394
+ bool is_xhandler = block->pred_at (i)->is_exception_handler (block);
1395
+ assert (is_sux || is_xhandler, " Block's predecessor should have it as successor or xhandler" );
1396
+ }
1397
+ }
1398
+ };
1399
+
1400
+ void IR::expand_with_neighborhood (BlockList& blocks) {
1401
+ int original_size = blocks.length ();
1402
+ for (int h = 0 ; h < original_size; h++) {
1403
+ BlockBegin* block = blocks.at (h);
1404
+
1405
+ for (int i = 0 ; i < block->end ()->number_of_sux (); i++) {
1406
+ if (!blocks.contains (block->end ()->sux_at (i))) {
1407
+ blocks.append (block->end ()->sux_at (i));
1408
+ }
1409
+ }
1410
+
1411
+ for (int i = 0 ; i < block->number_of_preds (); i++) {
1412
+ if (!blocks.contains (block->pred_at (i))) {
1413
+ blocks.append (block->pred_at (i));
1414
+ }
1415
+ }
1416
+
1417
+ for (int i = 0 ; i < block->number_of_exception_handlers (); i++) {
1418
+ if (!blocks.contains (block->exception_handler_at (i))) {
1419
+ blocks.append (block->exception_handler_at (i));
1420
+ }
1421
+ }
1422
+ }
1423
+ }
1424
+
1425
+ void IR::verify_local (BlockList& blocks) {
1426
+ EndNotNullValidator ennv;
1427
+ blocks.iterate_forward (&ennv);
1428
+
1429
+ ValidateEdgeMutuality vem;
1430
+ blocks.iterate_forward (&vem);
1431
+
1380
1432
VerifyBlockBeginField verifier;
1381
- this ->iterate_postorder (&verifier);
1382
- #endif
1433
+ blocks.iterate_forward (&verifier);
1383
1434
}
1384
1435
1385
- #endif // PRODUCT
1436
+ void IR::verify () {
1437
+ XentryFlagValidator xe;
1438
+ iterate_postorder (&xe);
1439
+
1440
+ PredecessorAndCodeValidator pv (this );
1441
+
1442
+ EndNotNullValidator ennv;
1443
+ iterate_postorder (&ennv);
1444
+
1445
+ ValidateEdgeMutuality vem;
1446
+ iterate_postorder (&vem);
1447
+
1448
+ VerifyBlockBeginField verifier;
1449
+ iterate_postorder (&verifier);
1450
+ }
1451
+ #endif // ASSERT
1386
1452
1387
1453
void SubstitutionResolver::visit (Value* v) {
1388
1454
Value v0 = *v;
0 commit comments