changeset 53597:2fbe6f9975cf

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
author zgu
date Tue, 20 Nov 2018 20:09:11 -0500
parents 639a3e43f5b7
children 68d450652337
files test/hotspot/jtreg/runtime/NMT/MallocStressTest.java
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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();