8214124: [TESTBUG] Bugs in runtime/NMT/MallocStressTest.java

Fix possible negative size and index that can cause the test to fail

Reviewed-by: stuefe, shade
This commit is contained in:
Zhengyu Gu 2018-11-20 20:09:11 -05:00
parent a264dac26c
commit 44ddbe3370

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -175,7 +175,7 @@ public class MallocStressTest {
public void run() {
Random random = new Random();
while (MallocStressTest.phase == TestPhase.alloc) {
int r = Math.abs(random.nextInt());
int r = random.nextInt(Integer.MAX_VALUE);
// Only malloc small amount to avoid OOM
int size = r % 32;
if (is_64_bit_system()) {
@ -259,7 +259,7 @@ public class MallocStressTest {
}
synchronized(MallocStressTest.mallocd_memory) {
if (MallocStressTest.mallocd_memory.isEmpty()) return;
int n = Math.abs(random.nextInt()) % MallocStressTest.mallocd_memory.size();
int n = random.nextInt(MallocStressTest.mallocd_memory.size());
MallocMemory mem = mallocd_memory.remove(n);
MallocStressTest.whiteBox.NMTFree(mem.addr());
MallocStressTest.mallocd_total -= mem.size();