17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 */ 22 23 /* 24 * This file is available under and governed by the GNU General Public 25 * License version 2 only, as published by the Free Software Foundation. 26 * However, the following notice accompanied the original version of this 27 * file: 28 * 29 * Written by Doug Lea with assistance from members of JCP JSR-166 30 * Expert Group and released to the public domain, as explained at 31 * http://creativecommons.org/licenses/publicdomain 32 */ 33 34 /* 35 * @test 36 * @bug 4486658 37 * @compile MapLoops.java 38 * @run main/timeout=4700 MapLoops 39 * @summary Exercise multithreaded maps, by default ConcurrentHashMap. 40 * Multithreaded hash table test. Each thread does a random walk 41 * though elements of "key" array. On each iteration, it checks if 42 * table includes key. If absent, with probability pinsert it 43 * inserts it, and if present, with probability premove it removes 44 * it. (pinsert and premove are expressed as percentages to simplify 45 * parsing from command line.) 46 */ 47 48 import java.util.*; 49 import java.util.concurrent.*; 50 51 public class MapLoops { 52 static final int NKEYS = 100000; 53 static int pinsert = 60; 54 static int premove = 2; 55 static int maxThreads = 5; 56 static int nops = 1000000; 57 static int removesPerMaxRandom; 58 static int insertsPerMaxRandom; 59 60 static final ExecutorService pool = Executors.newCachedThreadPool(); 61 62 public static void main(String[] args) throws Exception { 63 64 Class mapClass = null; 65 if (args.length > 0) { 66 try { 67 mapClass = Class.forName(args[0]); 68 } catch(ClassNotFoundException e) { 69 throw new RuntimeException("Class " + args[0] + " not found."); 70 } 71 } 72 else 73 mapClass = RWMap.class; 74 75 if (args.length > 1) 76 maxThreads = Integer.parseInt(args[1]); 77 78 if (args.length > 2) 79 nops = Integer.parseInt(args[2]); 80 81 if (args.length > 3) 82 pinsert = Integer.parseInt(args[3]); 83 84 if (args.length > 4) 85 premove = Integer.parseInt(args[4]); 86 87 // normalize probabilities wrt random number generator 88 removesPerMaxRandom = (int)(((double)premove/100.0 * 0x7FFFFFFFL)); | 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 */ 22 23 /* 24 * This file is available under and governed by the GNU General Public 25 * License version 2 only, as published by the Free Software Foundation. 26 * However, the following notice accompanied the original version of this 27 * file: 28 * 29 * Written by Doug Lea with assistance from members of JCP JSR-166 30 * Expert Group and released to the public domain, as explained at 31 * http://creativecommons.org/licenses/publicdomain 32 */ 33 34 /* 35 * @test 36 * @bug 4486658 37 * @compile -source 1.5 MapLoops.java 38 * @run main/timeout=4700 MapLoops 39 * @summary Exercise multithreaded maps, by default ConcurrentHashMap. 40 * Multithreaded hash table test. Each thread does a random walk 41 * though elements of "key" array. On each iteration, it checks if 42 * table includes key. If absent, with probability pinsert it 43 * inserts it, and if present, with probability premove it removes 44 * it. (pinsert and premove are expressed as percentages to simplify 45 * parsing from command line.) 46 */ 47 48 import java.util.*; 49 import java.util.concurrent.*; 50 51 public class MapLoops { 52 static final int NKEYS = 100000; 53 static int pinsert = 60; 54 static int premove = 2; 55 static int maxThreads = 5; 56 static int nops = 1000000; 57 static int removesPerMaxRandom; 58 static int insertsPerMaxRandom; 59 60 static final ExecutorService pool = Executors.newCachedThreadPool(); 61 62 public static void main(String[] args) throws Exception { 63 64 Class mapClass = null; 65 if (args.length > 0) { 66 try { 67 mapClass = Class.forName(args[0]); 68 } catch (ClassNotFoundException e) { 69 throw new RuntimeException("Class " + args[0] + " not found."); 70 } 71 } 72 else 73 mapClass = RWMap.class; 74 75 if (args.length > 1) 76 maxThreads = Integer.parseInt(args[1]); 77 78 if (args.length > 2) 79 nops = Integer.parseInt(args[2]); 80 81 if (args.length > 3) 82 pinsert = Integer.parseInt(args[3]); 83 84 if (args.length > 4) 85 premove = Integer.parseInt(args[4]); 86 87 // normalize probabilities wrt random number generator 88 removesPerMaxRandom = (int)(((double)premove/100.0 * 0x7FFFFFFFL)); |