mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 12:04:39 +02:00
8255277: randomDelay in DrainDeadlockT and LoggingDeadlock do not randomly delay
Reviewed-by: lancea
This commit is contained in:
parent
2d30a10138
commit
a93841ac9c
2 changed files with 17 additions and 4 deletions
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -25,9 +25,11 @@ import java.lang.management.ThreadMXBean;
|
||||||
import java.lang.Thread.State;
|
import java.lang.Thread.State;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import jdk.test.lib.RandomFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
@ -36,6 +38,7 @@ import java.util.Map;
|
||||||
* @author jim.gish@oracle.com
|
* @author jim.gish@oracle.com
|
||||||
* @modules java.logging
|
* @modules java.logging
|
||||||
* java.management
|
* java.management
|
||||||
|
* @library /test/lib
|
||||||
* @build DrainFindDeadlockTest
|
* @build DrainFindDeadlockTest
|
||||||
* @run main/othervm DrainFindDeadlockTest
|
* @run main/othervm DrainFindDeadlockTest
|
||||||
* @key randomness
|
* @key randomness
|
||||||
|
@ -50,6 +53,8 @@ import java.util.Map;
|
||||||
public class DrainFindDeadlockTest {
|
public class DrainFindDeadlockTest {
|
||||||
private LogManager mgr = LogManager.getLogManager();
|
private LogManager mgr = LogManager.getLogManager();
|
||||||
private static final int MAX_ITERATIONS = 100;
|
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
|
// 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
|
// not be supported on all platforms, which means we will have to
|
||||||
|
@ -66,12 +71,13 @@ public class DrainFindDeadlockTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void randomDelay() {
|
public static void randomDelay() {
|
||||||
int runs = (int) Math.random() * 1000000;
|
int runs = random.nextInt(1000000);
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
for (int i=0; i<runs; ++i) {
|
for (int i=0; i<runs; ++i) {
|
||||||
c=c+i;
|
c=c+i;
|
||||||
}
|
}
|
||||||
|
preventLoopElision = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testForDeadlock() throws IOException, Exception {
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -28,6 +28,7 @@
|
||||||
* @summary deadlock in LogManager
|
* @summary deadlock in LogManager
|
||||||
* @author Serguei Spitsyn / SAP
|
* @author Serguei Spitsyn / SAP
|
||||||
*
|
*
|
||||||
|
* @library /test/lib
|
||||||
* @build LoggingDeadlock
|
* @build LoggingDeadlock
|
||||||
* @run main/timeout=15 LoggingDeadlock
|
* @run main/timeout=15 LoggingDeadlock
|
||||||
* @key randomness
|
* @key randomness
|
||||||
|
@ -53,18 +54,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import jdk.test.lib.RandomFactory;
|
||||||
|
|
||||||
public class LoggingDeadlock {
|
public class LoggingDeadlock {
|
||||||
|
|
||||||
|
private static int preventLoopElision;
|
||||||
|
private static final Random random = RandomFactory.getRandom();
|
||||||
|
|
||||||
public static void randomDelay() {
|
public static void randomDelay() {
|
||||||
int runs = (int) Math.random() * 1000000;
|
int runs = random.nextInt(1000000);
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
for (int i = 0; i < runs; ++i) {
|
for (int i = 0; i < runs; ++i) {
|
||||||
c = c + i;
|
c = c + i;
|
||||||
}
|
}
|
||||||
|
preventLoopElision = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException{
|
public static void main(String[] args) throws InterruptedException{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue