8214124: [TESTBUG] Bugs in runtime/NMT/MallocStressTest.java
authorzgu
Tue, 20 Nov 2018 20:09:11 -0500
changeset 52629 2fbe6f9975cf
parent 52628 639a3e43f5b7
child 52630 68d450652337
8214124: [TESTBUG] Bugs in runtime/NMT/MallocStressTest.java Summary: Fix possible negative size and index that can cause the test to fail Reviewed-by: stuefe, shade
test/hotspot/jtreg/runtime/NMT/MallocStressTest.java
--- a/test/hotspot/jtreg/runtime/NMT/MallocStressTest.java	Tue Nov 20 22:59:27 2018 +0100
+++ b/test/hotspot/jtreg/runtime/NMT/MallocStressTest.java	Tue Nov 20 20:09:11 2018 -0500
@@ -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 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 @@
             }
             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();