Java Code Examples for jdk.test.lib.Utils#getRandomInstance()
The following examples show how to use
jdk.test.lib.Utils#getRandomInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestFalseDeadLock.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public void run() { Random r = Utils.getRandomInstance(); while (running) { try { synchronized (this) { wait(r.nextInt(1000) + 1); } } catch (InterruptedException ex) { } recurse(2000); } if (bean.findDeadlockedThreads() != null) { System.out.println("FOUND!"); found = true; } }
Example 2
Source File: PolynomialRoot.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(final String [] args) { if (System.getProperty("os.arch").equals("x86") || System.getProperty("os.arch").equals("amd64") || System.getProperty("os.arch").equals("x86_64")){ final long t0=System.currentTimeMillis(); final double eps=1e-6; //checkRoots(); final Random r = Utils.getRandomInstance(); printSpecialValues(); final int n_tests=100000; //testRoots(2,n_tests,r,eps); //testRoots(3,n_tests,r,eps); testRoots(4,n_tests,r,eps); final long t1=System.currentTimeMillis(); System.err.println("PolynomialRoot.main: "+n_tests+" tests OK done in "+(t1-t0)+" milliseconds. ver=$Id: PolynomialRoot.java,v 1.105 2012/08/18 00:00:05 mal Exp $"); System.out.println("PASSED"); } else { System.out.println("PASS test for non-x86"); } }
Example 3
Source File: SegmentedCodeCacheDtraceTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static TestCombination generateUniqueCombination( int[] availableLevels, Set<TestCombination> combinations) { int len = availableLevels.length; /* first, check if we're out of combinations. */ int maxCombinationsCount = (1 << WORKER_METHODS_COUNT) * (int) Math.pow(len, WORKER_METHODS_COUNT); if (combinations.size() == maxCombinationsCount) { return null; } Random r = Utils.getRandomInstance(); while (combinations.size() < maxCombinationsCount) { int levels[] = new int[WORKER_METHODS_COUNT]; boolean inlines[] = new boolean[WORKER_METHODS_COUNT]; for (int i = 0; i < WORKER_METHODS_COUNT; i++) { levels[i] = availableLevels[r.nextInt(len)]; inlines[i] = r.nextBoolean(); } TestCombination tc = new TestCombination(levels, inlines); if (combinations.add(tc)) { return tc; } } return null; }
Example 4
Source File: MulExactIRepeatTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void runTest(Verify.BinaryMethod method) { Random rnd = Utils.getRandomInstance(); for (int i = 0; i < 50000; ++i) { int x = Integer.MAX_VALUE - 10; int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5); int c = rnd.nextInt() / 10; int d = rnd.nextInt(9); int a = catchingExact(x, y, method); if (a != 36) { throw new RuntimeException("a != 36 : " + a); } int b = nonExact(c, d, method); int n = exact(c, d, method); if (n != b) { throw new RuntimeException("n != b : " + n + " != " + b); } } }
Example 5
Source File: AddExactIRepeatTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void runTest(Verify.BinaryMethod method) { Random rnd = Utils.getRandomInstance(); for (int i = 0; i < 50000; ++i) { int x = Integer.MAX_VALUE - 10; int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5); int c = rnd.nextInt() / 2; int d = rnd.nextInt() / 2; int a = catchingExact(x, y, method); if (a != 36) { throw new RuntimeException("a != 36 : " + a); } int b = nonExact(c, d, method); int n = exact(c, d, method); if (n != b) { throw new RuntimeException("n != b : " + n + " != " + b); } } }
Example 6
Source File: SubExactIRepeatTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void runTest(Verify.BinaryMethod method) { Random rnd = Utils.getRandomInstance(); for (int i = 0; i < 50000; ++i) { int x = Integer.MIN_VALUE + 10; int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5); int c = rnd.nextInt() / 2; int d = rnd.nextInt() / 2; int a = catchingExact(x, y, method); if (a != 36) { throw new RuntimeException("a != 36 : " + a); } int b = nonExact(c, d, method); int n = exact(c, d, method); if (n != b) { throw new RuntimeException("n != b : " + n + " != " + b); } } }
Example 7
Source File: RandomGeneratorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { StringBuilder sb = new StringBuilder(); Random rng = Utils.getRandomInstance(); for (int i = 0; i < COUNT; i++) { sb.append(rng.nextLong()).append(' '); } try (PrintWriter pw = new PrintWriter(new FileWriter(args[0]))) { pw.write(sb.toString()); } catch (IOException ioe) { throw new Error("TESTBUG: Problem during IO operation with file: " + args[0], ioe); } }
Example 8
Source File: DummyClass.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private double randomProfile() { String str1 = "123123123"; double x = 3.14; int y = Integer.parseInt(str1); Random rnd = Utils.getRandomInstance(); if (rnd.nextDouble() > 0.2) { return y / (int) x; } else { return x / y; } }
Example 9
Source File: JVMStartupRunner.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Returns {@code unscaledSize} value scaled by a random factor from * range (1, 2). If {@code unscaledSize} is not 0, then this * method will return value that won't be equal to {@code unscaledSize}. * * @param unscaledSize The value to be scaled. * @return {@code unscaledSize} value scaled by a factor from range (1, 2). */ private static long scaleCodeHeapSize(long unscaledSize) { Random random = Utils.getRandomInstance(); long scaledSize = unscaledSize; while (scaledSize == unscaledSize && unscaledSize != 0) { float scale = 1.0f + random.nextFloat(); scaledSize = (long) Math.ceil(scale * unscaledSize); } return scaledSize; }
Example 10
Source File: Test7100757.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { BitSet bs = new BitSet(NBITS); Random rnd = Utils.getRandomInstance(); long[] ra = new long[(NBITS+63)/64]; for(int l=0; l < 5000000; l++) { for(int r = 0; r < ra.length; r++) { ra[r] = rnd.nextLong(); } test(ra, bs); } }
Example 11
Source File: TestHumongousMovement.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { int g1RegionSize = WB.g1RegionSize(); int byteArrayMemoryOverhead = Helpers.detectByteArrayAllocationOverhead(); System.out.println("Total " + WB.g1NumMaxRegions() + " regions"); System.out.println("Total " + WB.g1NumFreeRegions() + " free regions"); int regionsToAllocate = (int) (WB.g1NumFreeRegions() * ALLOCATED_HUMONGOUS_REGIONS_FACTOR); // Sanity check Asserts.assertGreaterThan(regionsToAllocate, 0, "Test Bug: no regions to allocate"); System.out.println("Allocating " + regionsToAllocate + " humongous objects, each 90% of g1 region size"); List<AllocationData> allocations = new ArrayList<>(); // 90 % of maximum byte[] that takes one region int hSize = (int) ((g1RegionSize - byteArrayMemoryOverhead) * 0.9); // Sanity check Asserts.assertGreaterThan(hSize, g1RegionSize / 2, "Test Bug: allocation size is not humongous"); for (int i = 0; i < regionsToAllocate; ++i) { allocations.add(new AllocationData(new byte[hSize])); } Random rnd = Utils.getRandomInstance(); int toDelete = (int) (allocations.size() * HUMONGOUS_OBJECTS_DELETED_FACTOR); for (int i = 0; i < toDelete; ++i) { allocations.remove(rnd.nextInt(allocations.size())); } WB.fullGC(); List<AllocationData> movedObjects = allocations.stream() .filter(AllocationData::isAddressChanged) .collect(Collectors.toList()); if (movedObjects.size() > 0) { System.out.println("Test failed - some humongous objects moved after Full GC"); movedObjects.stream().forEach(a -> a.printDetails(System.out)); throw new Error("Test failed - some humongous objects moved after Full GC"); } else { System.out.println("Passed"); } }
Example 12
Source File: UnsafeRaw.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Unsafe unsafe = Unsafe.getUnsafe(); final int array_size = 128; final int element_size = 4; final int magic = 0x12345678; Random rnd = Utils.getRandomInstance(); long array = unsafe.allocateMemory(array_size * element_size); // 128 ints long addr = array + array_size * element_size / 2; // something in the middle to work with unsafe.putInt(addr, magic); for (int j = 0; j < 100000; j++) { if (Tests.int_index(unsafe, addr, 0) != magic) throw new Exception(); if (Tests.long_index(unsafe, addr, 0) != magic) throw new Exception(); if (Tests.int_index_mul(unsafe, addr, 0) != magic) throw new Exception(); if (Tests.long_index_mul(unsafe, addr, 0) != magic) throw new Exception(); { long idx1 = rnd.nextLong(); long addr1 = addr - (idx1 << 2); if (Tests.long_index(unsafe, addr1, idx1) != magic) throw new Exception(); } { long idx2 = rnd.nextLong(); long addr2 = addr - (idx2 >> 2); if (Tests.long_index_back_ashift(unsafe, addr2, idx2) != magic) throw new Exception(); } { long idx3 = rnd.nextLong(); long addr3 = addr - (idx3 >>> 2); if (Tests.long_index_back_lshift(unsafe, addr3, idx3) != magic) throw new Exception(); } { long idx4 = 0x12345678; long addr4 = addr - idx4; if (Tests.int_const_12345678_index(unsafe, addr4) != magic) throw new Exception(); } { long idx5 = 0x1234567890abcdefL; long addr5 = addr - idx5; if (Tests.long_const_1234567890abcdef_index(unsafe, addr5) != magic) throw new Exception(); } { int idx6 = rnd.nextInt(); long addr6 = addr - (idx6 >> 2); if (Tests.int_index_back_ashift(unsafe, addr6, idx6) != magic) throw new Exception(); } { int idx7 = rnd.nextInt(); long addr7 = addr - (idx7 >>> 2); if (Tests.int_index_back_lshift(unsafe, addr7, idx7) != magic) throw new Exception(); } { int idx8 = rnd.nextInt(); long addr8 = addr - (idx8 * 16); if (Tests.int_index_mul_scale_16(unsafe, addr8, idx8) != magic) throw new Exception(); } { long idx9 = rnd.nextLong(); long addr9 = addr - (idx9 * 16); if (Tests.long_index_mul_scale_16(unsafe, addr9, idx9) != magic) throw new Exception(); } } }