Skip to content

Commit ecd9e62

Browse files
authored
Merge pull request #12 from keithc-ca/alloc-quick
Avoid linear search if OMRPORT_VMEM_ALLOC_QUICK option is specified
2 parents a088c1d + 9427461 commit ecd9e62

File tree

6 files changed

+277
-286
lines changed

6 files changed

+277
-286
lines changed

fvtest/porttest/omrmemTest.cpp

Lines changed: 90 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 1991, 2017 IBM Corp. and others
2+
* Copyright (c) 1991, 2018 IBM Corp. and others
33
*
44
* This program and the accompanying materials are made available under
55
* 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
9999
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
100100
const char testCharA = 'A';
101101
const char testCharC = 'c';
102-
uintptr_t testSize;
102+
uintptr_t testSize = 0;
103103
char stackMemory[MAX_ALLOC_SIZE];
104104

105105
if (NULL == memPtr) {
@@ -218,7 +218,7 @@ TEST(PortMemTest, mem_test1)
218218
{
219219
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
220220
const char *testName = "omrmem_test1";
221-
char *memPtr;
221+
char *memPtr = NULL;
222222

223223
reportTestEntry(OMRPORTLIB, testName);
224224

@@ -258,9 +258,9 @@ TEST(PortMemTest, mem_test2)
258258
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
259259
const char *testName = "omrmem_test2";
260260

261-
char *memPtr;
261+
char *memPtr = NULL;
262262
char allocName[allocNameSize];
263-
uint32_t byteAmount;
263+
uint32_t byteAmount = 0;
264264

265265
reportTestEntry(OMRPORTLIB, testName);
266266

@@ -328,11 +328,11 @@ TEST(PortMemTest, mem_test4)
328328
* outside the portlibrary?
329329
*/
330330
#if 0
331-
void *memPtr;
332-
void *saveMemPtr;
331+
void *memPtr = 0;
332+
void *saveMemPtr = NULL;
333333
char allocName[allocNameSize];
334-
int32_t rc;
335-
uint32_t byteAmount;
334+
int32_t rc = 0;
335+
uint32_t byteAmount = 0;
336336

337337
reportTestEntry(OMRPORTLIB, testName);
338338

@@ -415,7 +415,7 @@ TEST(PortMemTest, mem_test5)
415415
* outside the portlibrary?
416416
*/
417417
#if 0
418-
OMRPortLibrary *memPtr;
418+
OMRPortLibrary *memPtr = NULL;
419419

420420
reportTestEntry(OMRPORTLIB, testName);
421421

@@ -468,10 +468,10 @@ TEST(PortMemTest, mem_test6)
468468
* outside the portlibrary?
469469
*/
470470
#if 0
471-
char *memPtr;
471+
char *memPtr = NULL;
472472
char allocName[allocNameSize];
473-
int32_t rc;
474-
uint32_t byteAmount;
473+
int32_t rc = 0;
474+
uint32_t byteAmount = 0;
475475

476476
reportTestEntry(OMRPORTLIB, testName);
477477

@@ -530,7 +530,7 @@ TEST(PortMemTest, mem_test6)
530530
static void
531531
shuffleArray(struct OMRPortLibrary *portLibrary, uintptr_t *array, uintptr_t length)
532532
{
533-
uintptr_t i;
533+
uintptr_t i = 0;
534534

535535
for (i = 0; i < length; i++) {
536536
intptr_t randNum = (intptr_t)(rand() % length);
@@ -561,33 +561,29 @@ shuffleArray(struct OMRPortLibrary *portLibrary, uintptr_t *array, uintptr_t len
561561
TEST(PortMemTest, mem_test7_allocate32)
562562
{
563563
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
564-
void *pointer;
564+
void *pointer = NULL;
565565
#if defined(OMR_ENV_DATA64)
566-
uintptr_t finalAllocSize;
566+
uintptr_t finalAllocSize = 0;
567567
#endif
568568
char allocName[allocNameSize];
569569
const char *testName = "omrmem_test7_allocate32";
570570
int randomSeed = 0;
571571
char rand[99] = "";
572-
int i;
572+
int i = 0;
573573

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,
577576
#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+
};
586583
uintptr_t allocBlockSizesLength = sizeof(allocBlockSizes) / sizeof(allocBlockSizes[0]);
587584
void *allocBlockReturnPtrs[sizeof(allocBlockSizes) / sizeof(allocBlockSizes[0])];
588585
uintptr_t allocBlockCursor = 0;
589586

590-
591587
reportTestEntry(OMRPORTLIB, testName);
592588

593589
for (i = 1; i < portTestEnv->_argc; i += 1) {
@@ -631,6 +627,7 @@ TEST(PortMemTest, mem_test7_allocate32)
631627
omrstr_printf(allocName, allocNameSize, "\nomrmem_allocate_memory32(%d)", finalAllocSize);
632628
pointer = omrmem_allocate_memory32(finalAllocSize, OMRMEM_CATEGORY_PORT_LIBRARY);
633629
verifyMemory(OMRPORTLIB, testName, (char *)pointer, finalAllocSize, allocName);
630+
omrmem_free_memory32(pointer);
634631
#endif
635632

636633
/* should not result in a crash */
@@ -670,7 +667,6 @@ struct CategoriesState {
670667
BOOLEAN unused32bitSlabWalked;
671668
#endif
672669

673-
674670
BOOLEAN otherError;
675671

676672
uintptr_t dummyCategoryOneBytes;
@@ -873,13 +869,13 @@ TEST(PortMemTest, mem_test8_categories)
873869

874870
/* Try allocating under the port library category and check the block and byte counters are incremented */
875871
{
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;
883879

884880
getCategoriesState(OMRPORTLIB, &categoriesState);
885881
initialBlocks = categoriesState.portLibraryBlocks;
@@ -939,13 +935,13 @@ TEST(PortMemTest, mem_test8_categories)
939935

940936
/* Try allocating with a user category code - having not registered any categories. Check it maps to unknown */
941937
{
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;
949945

950946
getCategoriesState(OMRPORTLIB, &categoriesState);
951947
initialBlocks = categoriesState.unknownBlocks;
@@ -1006,13 +1002,13 @@ TEST(PortMemTest, mem_test8_categories)
10061002

10071003
/* Try allocating to one of our user category codes - check the arithmetic is done correctly */
10081004
{
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;
10161012

10171013
getCategoriesState(OMRPORTLIB, &categoriesState);
10181014
initialBlocks = categoriesState.dummyCategoryOneBlocks;
@@ -1072,13 +1068,13 @@ TEST(PortMemTest, mem_test8_categories)
10721068
#if !(defined(OSX) && defined(OMR_ENV_DATA64))
10731069
/* Try allocating with allocate32 */
10741070
{
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;
10821078

10831079
getCategoriesState(OMRPORTLIB, &categoriesState);
10841080
initialBlocks = categoriesState.dummyCategoryOneBlocks;
@@ -1138,18 +1134,18 @@ TEST(PortMemTest, mem_test8_categories)
11381134
/* n.b. we're reliant on previous tests having initialized the 32bithelpers. */
11391135
#if defined(OMR_ENV_DATA64)
11401136
{
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;
11531149

11541150
getCategoriesState(OMRPORTLIB, &categoriesState);
11551151
initialBlocks = categoriesState.dummyCategoryOneBlocks;
@@ -1235,19 +1231,19 @@ TEST(PortMemTest, mem_test8_categories)
12351231

12361232
/* Try allocating and reallocating */
12371233
{
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;
12511247

12521248
getCategoriesState(OMRPORTLIB, &categoriesState);
12531249
initialBlocksCat1 = categoriesState.dummyCategoryOneBlocks;
@@ -1353,17 +1349,15 @@ TEST(PortMemTest, mem_test8_categories)
13531349
}
13541350
}
13551351

1356-
1357-
13581352
/* Try allocating to an unknown category code - check it maps to unknown properly */
13591353
{
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;
13671361

13681362
getCategoriesState(OMRPORTLIB, &categoriesState);
13691363
initialBlocks = categoriesState.unknownBlocks;
@@ -1387,10 +1381,12 @@ TEST(PortMemTest, mem_test8_categories)
13871381
finalBytes = categoriesState.unknownBytes;
13881382
if (!categoriesState.unknownWalked) {
13891383
outputErrorMessage(PORTTEST_ERROR_ARGS, "Category walk didn't cover unknown category.\n");
1384+
omrmem_free_memory(ptr);
13901385
goto end;
13911386
}
13921387
if (categoriesState.otherError) {
13931388
outputErrorMessage(PORTTEST_ERROR_ARGS, "Some other error hit while walking categories (see messages above).\n");
1389+
omrmem_free_memory(ptr);
13941390
goto end;
13951391
}
13961392

@@ -1482,13 +1478,12 @@ TEST(PortMemTest, mem_test9_category_walk)
14821478
static void
14831479
freeMemPointers(struct OMRPortLibrary *portLibrary, void **memPtrs, uintptr_t length)
14841480
{
1485-
void *mem32Ptr = NULL;
1486-
uintptr_t i;
1481+
uintptr_t i = 0;
14871482

14881483
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
14891484

14901485
for (i = 0; i < length; i++) {
1491-
mem32Ptr = memPtrs[i];
1486+
void *mem32Ptr = memPtrs[i];
14921487
omrmem_free_memory32(mem32Ptr);
14931488
}
14941489
}

0 commit comments

Comments
 (0)