Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8255277: randomDelay in DrainDeadlockT and LoggingDeadlock do not ran…
…domly delay

Reviewed-by: lancea
  • Loading branch information
dfuch committed Nov 26, 2020
1 parent 2d30a10 commit a93841a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions test/jdk/java/util/logging/DrainFindDeadlockTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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,9 +25,11 @@
import java.lang.Thread.State;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Random;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.Map;
import jdk.test.lib.RandomFactory;

/**
* @test
Expand All @@ -36,6 +38,7 @@
* @author jim.gish@oracle.com
* @modules java.logging
* java.management
* @library /test/lib
* @build DrainFindDeadlockTest
* @run main/othervm DrainFindDeadlockTest
* @key randomness
Expand All @@ -50,6 +53,8 @@
public class DrainFindDeadlockTest {
private LogManager mgr = LogManager.getLogManager();
private static final int MAX_ITERATIONS = 100;
private static final Random random = RandomFactory.getRandom();
private static int preventLoopElision;

// Get a ThreadMXBean so we can check for deadlock. N.B. this may
// not be supported on all platforms, which means we will have to
Expand All @@ -66,12 +71,13 @@ public static void main(String... args) throws IOException, Exception {
}

public static void randomDelay() {
int runs = (int) Math.random() * 1000000;
int runs = random.nextInt(1000000);
int c = 0;

for (int i=0; i<runs; ++i) {
c=c+i;
}
preventLoopElision = c;
}

public void testForDeadlock() throws IOException, Exception {
Expand Down
11 changes: 9 additions & 2 deletions test/jdk/java/util/logging/LoggingDeadlock.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 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 Down Expand Up @@ -28,6 +28,7 @@
* @summary deadlock in LogManager
* @author Serguei Spitsyn / SAP
*
* @library /test/lib
* @build LoggingDeadlock
* @run main/timeout=15 LoggingDeadlock
* @key randomness
Expand All @@ -53,18 +54,24 @@
*/


import java.util.Random;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import jdk.test.lib.RandomFactory;

public class LoggingDeadlock {

private static int preventLoopElision;
private static final Random random = RandomFactory.getRandom();

public static void randomDelay() {
int runs = (int) Math.random() * 1000000;
int runs = random.nextInt(1000000);
int c = 0;

for (int i = 0; i < runs; ++i) {
c = c + i;
}
preventLoopElision = c;
}

public static void main(String[] args) throws InterruptedException{
Expand Down

1 comment on commit a93841a

@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.