# HG changeset patch # User zgu # Date 1542762551 18000 # Node ID 2fbe6f9975cfefa9d1f2846e64432018d1f5db30 # Parent 639a3e43f5b76e2da649eb417204ed0e777bc4ec 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 diff -r 639a3e43f5b7 -r 2fbe6f9975cf 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();