Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8242311: use reproducible random in hotspot runtime tests
Reviewed-by: mdoerr
Backport-of: c73934d
  • Loading branch information
GoeLin committed Mar 24, 2022
1 parent d064d8e commit c152474
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
5 changes: 3 additions & 2 deletions test/hotspot/jtreg/runtime/NMT/HugeArenaTracking.java
Expand Up @@ -24,7 +24,7 @@

/*
* @test
* @key nmt jcmd
* @key nmt jcmd randomness
* @library /test/lib
* @requires vm.bits == 64
* @modules java.base/jdk.internal.misc
Expand All @@ -39,6 +39,7 @@
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Utils;
import sun.hotspot.WhiteBox;

public class HugeArenaTracking {
Expand All @@ -60,7 +61,7 @@ public static void main(String args[]) throws Exception {
output = new OutputAnalyzer(pb.start());
output.shouldContain("Test (reserved=2KB, committed=2KB)");

Random rand = new Random();
Random rand = Utils.getRandomInstance();

// Allocate 2GB+ from arena
long total = 0;
Expand Down
9 changes: 5 additions & 4 deletions test/hotspot/jtreg/runtime/NMT/MallocStressTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -24,7 +24,7 @@
/*
* @test
* @summary Stress test for malloc tracking
* @key nmt jcmd stress
* @key nmt jcmd stress randomness
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
Expand All @@ -39,6 +39,7 @@
import java.util.Random;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import sun.hotspot.WhiteBox;
Expand Down Expand Up @@ -159,14 +160,14 @@ static class MallocMemory {
}

static class AllocThread extends Thread {
private final Random random = new Random(Utils.getRandomInstance().nextLong());
AllocThread() {
this.setName("MallocThread");
this.start();
}

// AllocThread only runs "Alloc" phase
public void run() {
Random random = new Random();
// MallocStressTest.phase == TestPhase.alloc
for (int loops = 0; loops < 100; loops++) {
int r = random.nextInt(Integer.MAX_VALUE);
Expand Down Expand Up @@ -201,7 +202,7 @@ public void run() {
}

static class ReleaseThread extends Thread {
private Random random = new Random();
private final Random random = new Random(Utils.getRandomInstance().nextLong());
ReleaseThread() {
this.setName("ReleaseThread");
this.start();
Expand Down
7 changes: 4 additions & 3 deletions test/hotspot/jtreg/runtime/NMT/MallocTrackingVerify.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand All @@ -25,7 +25,7 @@
* @test
* @bug 8054836
* @summary Test to verify correctness of malloc tracking
* @key nmt jcmd
* @key nmt jcmd randomness
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
Expand All @@ -41,6 +41,7 @@
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Utils;

import sun.hotspot.WhiteBox;

Expand All @@ -58,7 +59,7 @@ public static void main(String args[]) throws Exception {
String pid = Long.toString(ProcessTools.getProcessId());
ProcessBuilder pb = new ProcessBuilder();

Random random = new Random();
Random random = Utils.getRandomInstance();
// Allocate small amounts of memory with random pseudo call stack
while (mallocd_total < MAX_ALLOC) {
int size = random.nextInt(31) + 1;
Expand Down
Expand Up @@ -24,6 +24,7 @@

/*
* @test
* @key randomness
* @summary SharedArchiveConsistency
* @requires vm.cds
* @library /test/lib
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, 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
Expand All @@ -24,6 +24,7 @@

import java.io.*;
import java.util.*;
import jdk.test.lib.Utils;
import sun.hotspot.WhiteBox;

// All strings in archived classes are shared
Expand All @@ -43,7 +44,7 @@ static String get_shared_string1() {

static void allocAlot() {
try {
Random random = new Random();
Random random = Utils.getRandomInstance();
for (int i = 0; i < 1024 * 1024; i++) {
int len = random.nextInt(10000);
arr = new int[len];
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, 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
Expand All @@ -24,15 +24,16 @@

/*
* @test
* @key randomness
* @summary
* @requires vm.cds.archived.java.heap
* @library /test/lib /test/hotspot/jtreg/runtime/appcds
* @modules java.base/jdk.internal.misc
* @modules java.management
* jdk.jartool/sun.tools.jar
* @build sun.hotspot.WhiteBox
* @build sun.hotspot.WhiteBox jdk.test.lib.Utils
* @compile GCStressApp.java
* @run driver ClassFileInstaller -jar gcstress.jar GCStressApp
* @run driver ClassFileInstaller -jar gcstress.jar GCStressApp jdk.test.lib.Utils
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run main GCStressTest
*/
Expand Down

1 comment on commit c152474

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.