Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
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 a93841ac9cbf69dc7484e96a16cb64988c50f98d
Showing with 17 additions and 4 deletions.
  1. +8 −2 test/jdk/java/util/logging/DrainFindDeadlockTest.java
  2. +9 −2 test/jdk/java/util/logging/LoggingDeadlock.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
@@ -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
@@ -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
@@ -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
@@ -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 {
@@ -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
@@ -28,6 +28,7 @@
* @summary deadlock in LogManager
* @author Serguei Spitsyn / SAP
*
* @library /test/lib
* @build LoggingDeadlock
* @run main/timeout=15 LoggingDeadlock
* @key randomness
@@ -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{

0 comments on commit a93841a

Please sign in to comment.