1
1
/* ******************************************************************************
2
- * Copyright (c) 1991, 2017 IBM Corp. and others
2
+ * Copyright (c) 1991, 2018 IBM Corp. and others
3
3
*
4
4
* This program and the accompanying materials are made available under
5
5
* the terms of the Eclipse Public License 2.0 which accompanies this
@@ -99,7 +99,7 @@ verifyMemory(struct OMRPortLibrary *portLibrary, const char *testName, char *mem
99
99
OMRPORT_ACCESS_FROM_OMRPORT (portLibrary);
100
100
const char testCharA = ' A' ;
101
101
const char testCharC = ' c' ;
102
- uintptr_t testSize;
102
+ uintptr_t testSize = 0 ;
103
103
char stackMemory[MAX_ALLOC_SIZE];
104
104
105
105
if (NULL == memPtr) {
@@ -218,7 +218,7 @@ TEST(PortMemTest, mem_test1)
218
218
{
219
219
OMRPORT_ACCESS_FROM_OMRPORT (portTestEnv->getPortLibrary ());
220
220
const char *testName = " omrmem_test1" ;
221
- char *memPtr;
221
+ char *memPtr = NULL ;
222
222
223
223
reportTestEntry (OMRPORTLIB, testName);
224
224
@@ -258,9 +258,9 @@ TEST(PortMemTest, mem_test2)
258
258
OMRPORT_ACCESS_FROM_OMRPORT (portTestEnv->getPortLibrary ());
259
259
const char *testName = " omrmem_test2" ;
260
260
261
- char *memPtr;
261
+ char *memPtr = NULL ;
262
262
char allocName[allocNameSize];
263
- uint32_t byteAmount;
263
+ uint32_t byteAmount = 0 ;
264
264
265
265
reportTestEntry (OMRPORTLIB, testName);
266
266
@@ -328,11 +328,11 @@ TEST(PortMemTest, mem_test4)
328
328
* outside the portlibrary?
329
329
*/
330
330
#if 0
331
- void *memPtr;
332
- void *saveMemPtr;
331
+ void *memPtr = 0 ;
332
+ void *saveMemPtr = NULL ;
333
333
char allocName[allocNameSize];
334
- int32_t rc;
335
- uint32_t byteAmount;
334
+ int32_t rc = 0 ;
335
+ uint32_t byteAmount = 0 ;
336
336
337
337
reportTestEntry(OMRPORTLIB, testName);
338
338
@@ -415,7 +415,7 @@ TEST(PortMemTest, mem_test5)
415
415
* outside the portlibrary?
416
416
*/
417
417
#if 0
418
- OMRPortLibrary *memPtr;
418
+ OMRPortLibrary *memPtr = NULL ;
419
419
420
420
reportTestEntry(OMRPORTLIB, testName);
421
421
@@ -468,10 +468,10 @@ TEST(PortMemTest, mem_test6)
468
468
* outside the portlibrary?
469
469
*/
470
470
#if 0
471
- char *memPtr;
471
+ char *memPtr = NULL ;
472
472
char allocName[allocNameSize];
473
- int32_t rc;
474
- uint32_t byteAmount;
473
+ int32_t rc = 0 ;
474
+ uint32_t byteAmount = 0 ;
475
475
476
476
reportTestEntry(OMRPORTLIB, testName);
477
477
@@ -530,7 +530,7 @@ TEST(PortMemTest, mem_test6)
530
530
static void
531
531
shuffleArray (struct OMRPortLibrary *portLibrary, uintptr_t *array, uintptr_t length)
532
532
{
533
- uintptr_t i;
533
+ uintptr_t i = 0 ;
534
534
535
535
for (i = 0 ; i < length; i++) {
536
536
intptr_t randNum = (intptr_t )(rand () % length);
@@ -561,33 +561,29 @@ shuffleArray(struct OMRPortLibrary *portLibrary, uintptr_t *array, uintptr_t len
561
561
TEST (PortMemTest, mem_test7_allocate32)
562
562
{
563
563
OMRPORT_ACCESS_FROM_OMRPORT (portTestEnv->getPortLibrary ());
564
- void *pointer;
564
+ void *pointer = NULL ;
565
565
#if defined(OMR_ENV_DATA64)
566
- uintptr_t finalAllocSize;
566
+ uintptr_t finalAllocSize = 0 ;
567
567
#endif
568
568
char allocName[allocNameSize];
569
569
const char *testName = " omrmem_test7_allocate32" ;
570
570
int randomSeed = 0 ;
571
571
char rand[99 ] = " " ;
572
- int i;
572
+ int i = 0 ;
573
573
574
- /* Use a more exhausive size array for 64 bit platforms to exercise the omrheap API.
575
- * Retain the old sizes for regular 32 bit VMs, including ME platforms with very limited amount of physical memory.
576
- */
574
+ uintptr_t allocBlockSizes[] = {
575
+ 0 , 1 , 512 , 4096 , 1024 * 1024 ,
577
576
#if defined(OMR_ENV_DATA64)
578
- uintptr_t allocBlockSizes[] = {0 , 1 , 512 , 4096 , 1024 * 1024 ,
579
- HEAP_SIZE_BYTES / 8 , HEAP_SIZE_BYTES / 4 , HEAP_SIZE_BYTES / 3 , HEAP_SIZE_BYTES / 2 ,
580
- HEAP_SIZE_BYTES - 6 , HEAP_SIZE_BYTES - 10 ,
581
- HEAP_SIZE_BYTES, HEAP_SIZE_BYTES + 6
582
- };
583
- #else
584
- uintptr_t allocBlockSizes[] = {0 , 1 , 512 , 4096 , 4096 * 1024 };
585
- #endif
577
+ /* Extra sizes for 64-bit platforms to exercise the omrheap API. */
578
+ HEAP_SIZE_BYTES / 8 , HEAP_SIZE_BYTES / 4 , HEAP_SIZE_BYTES / 3 , HEAP_SIZE_BYTES / 2 ,
579
+ HEAP_SIZE_BYTES - 6 , HEAP_SIZE_BYTES - 10 ,
580
+ HEAP_SIZE_BYTES, HEAP_SIZE_BYTES + 6
581
+ #endif /* OMR_ENV_DATA64 */
582
+ };
586
583
uintptr_t allocBlockSizesLength = sizeof (allocBlockSizes) / sizeof (allocBlockSizes[0 ]);
587
584
void *allocBlockReturnPtrs[sizeof (allocBlockSizes) / sizeof (allocBlockSizes[0 ])];
588
585
uintptr_t allocBlockCursor = 0 ;
589
586
590
-
591
587
reportTestEntry (OMRPORTLIB, testName);
592
588
593
589
for (i = 1 ; i < portTestEnv->_argc ; i += 1 ) {
@@ -631,6 +627,7 @@ TEST(PortMemTest, mem_test7_allocate32)
631
627
omrstr_printf (allocName, allocNameSize, " \n omrmem_allocate_memory32(%d)" , finalAllocSize);
632
628
pointer = omrmem_allocate_memory32 (finalAllocSize, OMRMEM_CATEGORY_PORT_LIBRARY);
633
629
verifyMemory (OMRPORTLIB, testName, (char *)pointer, finalAllocSize, allocName);
630
+ omrmem_free_memory32 (pointer);
634
631
#endif
635
632
636
633
/* should not result in a crash */
@@ -670,7 +667,6 @@ struct CategoriesState {
670
667
BOOLEAN unused32bitSlabWalked;
671
668
#endif
672
669
673
-
674
670
BOOLEAN otherError;
675
671
676
672
uintptr_t dummyCategoryOneBytes;
@@ -873,13 +869,13 @@ TEST(PortMemTest, mem_test8_categories)
873
869
874
870
/* Try allocating under the port library category and check the block and byte counters are incremented */
875
871
{
876
- uintptr_t initialBlocks;
877
- uintptr_t initialBytes;
878
- uintptr_t finalBlocks;
879
- uintptr_t finalBytes;
880
- uintptr_t expectedBlocks;
881
- uintptr_t expectedBytes;
882
- void *ptr;
872
+ uintptr_t initialBlocks = 0 ;
873
+ uintptr_t initialBytes = 0 ;
874
+ uintptr_t finalBlocks = 0 ;
875
+ uintptr_t finalBytes = 0 ;
876
+ uintptr_t expectedBlocks = 0 ;
877
+ uintptr_t expectedBytes = 0 ;
878
+ void *ptr = NULL ;
883
879
884
880
getCategoriesState (OMRPORTLIB, &categoriesState);
885
881
initialBlocks = categoriesState.portLibraryBlocks ;
@@ -939,13 +935,13 @@ TEST(PortMemTest, mem_test8_categories)
939
935
940
936
/* Try allocating with a user category code - having not registered any categories. Check it maps to unknown */
941
937
{
942
- uintptr_t initialBlocks;
943
- uintptr_t initialBytes;
944
- uintptr_t finalBlocks;
945
- uintptr_t finalBytes;
946
- uintptr_t expectedBlocks;
947
- uintptr_t expectedBytes;
948
- void *ptr;
938
+ uintptr_t initialBlocks = 0 ;
939
+ uintptr_t initialBytes = 0 ;
940
+ uintptr_t finalBlocks = 0 ;
941
+ uintptr_t finalBytes = 0 ;
942
+ uintptr_t expectedBlocks = 0 ;
943
+ uintptr_t expectedBytes = 0 ;
944
+ void *ptr = NULL ;
949
945
950
946
getCategoriesState (OMRPORTLIB, &categoriesState);
951
947
initialBlocks = categoriesState.unknownBlocks ;
@@ -1006,13 +1002,13 @@ TEST(PortMemTest, mem_test8_categories)
1006
1002
1007
1003
/* Try allocating to one of our user category codes - check the arithmetic is done correctly */
1008
1004
{
1009
- uintptr_t initialBlocks;
1010
- uintptr_t initialBytes;
1011
- uintptr_t finalBlocks;
1012
- uintptr_t finalBytes;
1013
- uintptr_t expectedBlocks;
1014
- uintptr_t expectedBytes;
1015
- void *ptr;
1005
+ uintptr_t initialBlocks = 0 ;
1006
+ uintptr_t initialBytes = 0 ;
1007
+ uintptr_t finalBlocks = 0 ;
1008
+ uintptr_t finalBytes = 0 ;
1009
+ uintptr_t expectedBlocks = 0 ;
1010
+ uintptr_t expectedBytes = 0 ;
1011
+ void *ptr = NULL ;
1016
1012
1017
1013
getCategoriesState (OMRPORTLIB, &categoriesState);
1018
1014
initialBlocks = categoriesState.dummyCategoryOneBlocks ;
@@ -1072,13 +1068,13 @@ TEST(PortMemTest, mem_test8_categories)
1072
1068
#if !(defined(OSX) && defined(OMR_ENV_DATA64))
1073
1069
/* Try allocating with allocate32 */
1074
1070
{
1075
- uintptr_t initialBlocks;
1076
- uintptr_t initialBytes;
1077
- uintptr_t finalBlocks;
1078
- uintptr_t finalBytes;
1079
- uintptr_t expectedBlocks;
1080
- uintptr_t expectedBytes;
1081
- void *ptr;
1071
+ uintptr_t initialBlocks = 0 ;
1072
+ uintptr_t initialBytes = 0 ;
1073
+ uintptr_t finalBlocks = 0 ;
1074
+ uintptr_t finalBytes = 0 ;
1075
+ uintptr_t expectedBlocks = 0 ;
1076
+ uintptr_t expectedBytes = 0 ;
1077
+ void *ptr = NULL ;
1082
1078
1083
1079
getCategoriesState (OMRPORTLIB, &categoriesState);
1084
1080
initialBlocks = categoriesState.dummyCategoryOneBlocks ;
@@ -1138,18 +1134,18 @@ TEST(PortMemTest, mem_test8_categories)
1138
1134
/* n.b. we're reliant on previous tests having initialized the 32bithelpers. */
1139
1135
#if defined(OMR_ENV_DATA64)
1140
1136
{
1141
- uintptr_t initialBlocks;
1142
- uintptr_t initialBytes;
1143
- uintptr_t finalBlocks;
1144
- uintptr_t finalBytes;
1145
- uintptr_t expectedBlocks;
1146
- uintptr_t expectedBytes;
1147
- uintptr_t initialUnused32BitSlabBytes;
1148
- uintptr_t initialUnused32BitSlabBlocks;
1149
- uintptr_t minimumExpectedUnused32BitSlabBytes;
1150
- uintptr_t finalUnused32BitSlabBytes;
1151
- uintptr_t finalUnused32BitSlabBlocks;
1152
- void *ptr;
1137
+ uintptr_t initialBlocks = 0 ;
1138
+ uintptr_t initialBytes = 0 ;
1139
+ uintptr_t finalBlocks = 0 ;
1140
+ uintptr_t finalBytes = 0 ;
1141
+ uintptr_t expectedBlocks = 0 ;
1142
+ uintptr_t expectedBytes = 0 ;
1143
+ uintptr_t initialUnused32BitSlabBytes = 0 ;
1144
+ uintptr_t initialUnused32BitSlabBlocks = 0 ;
1145
+ uintptr_t minimumExpectedUnused32BitSlabBytes = 0 ;
1146
+ uintptr_t finalUnused32BitSlabBytes = 0 ;
1147
+ uintptr_t finalUnused32BitSlabBlocks = 0 ;
1148
+ void *ptr = NULL ;
1153
1149
1154
1150
getCategoriesState (OMRPORTLIB, &categoriesState);
1155
1151
initialBlocks = categoriesState.dummyCategoryOneBlocks ;
@@ -1235,19 +1231,19 @@ TEST(PortMemTest, mem_test8_categories)
1235
1231
1236
1232
/* Try allocating and reallocating */
1237
1233
{
1238
- uintptr_t initialBlocksCat1;
1239
- uintptr_t initialBytesCat1;
1240
- uintptr_t initialBlocksCat2;
1241
- uintptr_t initialBytesCat2;
1242
- uintptr_t finalBlocksCat1;
1243
- uintptr_t finalBytesCat1;
1244
- uintptr_t finalBlocksCat2;
1245
- uintptr_t finalBytesCat2;
1246
- uintptr_t expectedBlocks1;
1247
- uintptr_t expectedBytes1;
1248
- uintptr_t expectedBlocks2;
1249
- uintptr_t expectedBytes2;
1250
- void *ptr;
1234
+ uintptr_t initialBlocksCat1 = 0 ;
1235
+ uintptr_t initialBytesCat1 = 0 ;
1236
+ uintptr_t initialBlocksCat2 = 0 ;
1237
+ uintptr_t initialBytesCat2 = 0 ;
1238
+ uintptr_t finalBlocksCat1 = 0 ;
1239
+ uintptr_t finalBytesCat1 = 0 ;
1240
+ uintptr_t finalBlocksCat2 = 0 ;
1241
+ uintptr_t finalBytesCat2 = 0 ;
1242
+ uintptr_t expectedBlocks1 = 0 ;
1243
+ uintptr_t expectedBytes1 = 0 ;
1244
+ uintptr_t expectedBlocks2 = 0 ;
1245
+ uintptr_t expectedBytes2 = 0 ;
1246
+ void *ptr = NULL ;
1251
1247
1252
1248
getCategoriesState (OMRPORTLIB, &categoriesState);
1253
1249
initialBlocksCat1 = categoriesState.dummyCategoryOneBlocks ;
@@ -1353,17 +1349,15 @@ TEST(PortMemTest, mem_test8_categories)
1353
1349
}
1354
1350
}
1355
1351
1356
-
1357
-
1358
1352
/* Try allocating to an unknown category code - check it maps to unknown properly */
1359
1353
{
1360
- uintptr_t initialBlocks;
1361
- uintptr_t initialBytes;
1362
- uintptr_t finalBlocks;
1363
- uintptr_t finalBytes;
1364
- uintptr_t expectedBlocks;
1365
- uintptr_t expectedBytes;
1366
- void *ptr;
1354
+ uintptr_t initialBlocks = 0 ;
1355
+ uintptr_t initialBytes = 0 ;
1356
+ uintptr_t finalBlocks = 0 ;
1357
+ uintptr_t finalBytes = 0 ;
1358
+ uintptr_t expectedBlocks = 0 ;
1359
+ uintptr_t expectedBytes = 0 ;
1360
+ void *ptr = NULL ;
1367
1361
1368
1362
getCategoriesState (OMRPORTLIB, &categoriesState);
1369
1363
initialBlocks = categoriesState.unknownBlocks ;
@@ -1387,10 +1381,12 @@ TEST(PortMemTest, mem_test8_categories)
1387
1381
finalBytes = categoriesState.unknownBytes ;
1388
1382
if (!categoriesState.unknownWalked ) {
1389
1383
outputErrorMessage (PORTTEST_ERROR_ARGS, " Category walk didn't cover unknown category.\n " );
1384
+ omrmem_free_memory (ptr);
1390
1385
goto end;
1391
1386
}
1392
1387
if (categoriesState.otherError ) {
1393
1388
outputErrorMessage (PORTTEST_ERROR_ARGS, " Some other error hit while walking categories (see messages above).\n " );
1389
+ omrmem_free_memory (ptr);
1394
1390
goto end;
1395
1391
}
1396
1392
@@ -1482,13 +1478,12 @@ TEST(PortMemTest, mem_test9_category_walk)
1482
1478
static void
1483
1479
freeMemPointers (struct OMRPortLibrary *portLibrary, void **memPtrs, uintptr_t length)
1484
1480
{
1485
- void *mem32Ptr = NULL ;
1486
- uintptr_t i;
1481
+ uintptr_t i = 0 ;
1487
1482
1488
1483
OMRPORT_ACCESS_FROM_OMRPORT (portLibrary);
1489
1484
1490
1485
for (i = 0 ; i < length; i++) {
1491
- mem32Ptr = memPtrs[i];
1486
+ void * mem32Ptr = memPtrs[i];
1492
1487
omrmem_free_memory32 (mem32Ptr);
1493
1488
}
1494
1489
}
0 commit comments