11/*
2- * Copyright (c) 2014, 2016 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2014, 2020 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2323
2424/*
2525 * @test RandomAllocationTest
26- * @key stress
26+ * @key stress randomness
2727 * @summary stressing code cache by allocating randomly sized "dummy" code blobs
2828 * @library /test/lib /
2929 * @modules java.base/jdk.internal.misc
4949import sun .hotspot .code .BlobType ;
5050
5151import java .util .ArrayList ;
52+ import java .util .Random ;
53+ import jdk .test .lib .Utils ;
5254
5355public class RandomAllocationTest implements Runnable {
5456 private static final long CODE_CACHE_SIZE
5557 = Helper .WHITE_BOX .getUintxVMFlag ("ReservedCodeCacheSize" );
5658 private static final int MAX_BLOB_SIZE = (int ) (CODE_CACHE_SIZE >> 7 );
5759 private static final BlobType [] BLOB_TYPES
5860 = BlobType .getAvailable ().toArray (new BlobType [0 ]);
61+ private final Random rng = Utils .getRandomInstance ();
5962
6063 public static void main (String [] args ) {
6164 new CodeCacheStressRunner (new RandomAllocationTest ()).runTest ();
@@ -64,16 +67,16 @@ public static void main(String[] args) {
6467 private final ArrayList <Long > blobs = new ArrayList <>();
6568 @ Override
6669 public void run () {
67- boolean allocate = blobs .isEmpty () || Helper . RNG .nextBoolean ();
70+ boolean allocate = blobs .isEmpty () || rng .nextBoolean ();
6871 if (allocate ) {
69- int type = Helper . RNG .nextInt (BLOB_TYPES .length );
72+ int type = rng .nextInt (BLOB_TYPES .length );
7073 long addr = Helper .WHITE_BOX .allocateCodeBlob (
71- Helper . RNG .nextInt (MAX_BLOB_SIZE ), BLOB_TYPES [type ].id );
74+ rng .nextInt (MAX_BLOB_SIZE ), BLOB_TYPES [type ].id );
7275 if (addr != 0 ) {
7376 blobs .add (addr );
7477 }
7578 } else {
76- int index = Helper . RNG .nextInt (blobs .size ());
79+ int index = rng .nextInt (blobs .size ());
7780 Helper .WHITE_BOX .freeCodeBlob (blobs .remove (index ));
7881 }
7982 }
0 commit comments