Skip to content

Commit

Permalink
8222884: ConcurrentClassDescLookup.java times out intermittently
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr
Backport-of: bd046d9b9e79e4eea89c72af358961ef6e98e660
  • Loading branch information
RealCLanger committed Jun 25, 2024
1 parent fa7521b commit 08c7c38
Showing 1 changed file with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2024, 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 @@
*/

import java.io.*;
import java.util.concurrent.CountDownLatch;

class Good implements Serializable {
private static final long serialVersionUID = 6319710844400051132L;
Expand All @@ -51,19 +52,20 @@ class Bad implements Serializable {
class SuccessfulLookup extends Thread {
Class<?> cl;
long suid;
Object barrier;
final CountDownLatch lookupLatch;
boolean ok;

SuccessfulLookup(Class<?> cl, long suid, Object barrier) {
SuccessfulLookup(Class<?> cl, long suid, CountDownLatch lookupLatch) {
this.cl = cl;
this.suid = suid;
this.barrier = barrier;
this.lookupLatch = lookupLatch;
}

public void run() {
synchronized (barrier) {
try { barrier.wait(); } catch (InterruptedException ex) {}
}
lookupLatch.countDown(); // let others know we are ready
try {
lookupLatch.await(); // await for others
} catch (InterruptedException ex) {}
for (int i = 0; i < 100; i++) {
if (ObjectStreamClass.lookup(cl).getSerialVersionUID() != suid) {
return;
Expand All @@ -75,18 +77,19 @@ public void run() {

class FailingLookup extends Thread {
Class<?> cl;
final Object barrier;
final CountDownLatch lookupLatch;
boolean ok;

FailingLookup(Class<?> cl, Object barrier) {
FailingLookup(Class<?> cl, CountDownLatch lookupLatch) {
this.cl = cl;
this.barrier = barrier;
this.lookupLatch = lookupLatch;
}

public void run() {
synchronized (barrier) {
try { barrier.wait(); } catch (InterruptedException ex) {}
}
lookupLatch.countDown(); // let others know we are ready
try {
lookupLatch.await(); // await for others
} catch (InterruptedException ex) {}
for (int i = 0; i < 100; i++) {
try {
ObjectStreamClass.lookup(cl);
Expand All @@ -102,39 +105,36 @@ public class ConcurrentClassDescLookup {
public static void main(String[] args) throws Exception {
ClassLoader loader = ConcurrentClassDescLookup.class.getClassLoader();
Class<?> cl = Class.forName("Good", false, loader);
Object barrier = new Object();
SuccessfulLookup[] slookups = new SuccessfulLookup[50];
int numSuccessfulLookups = 50;
CountDownLatch sLookupLatch = new CountDownLatch(numSuccessfulLookups);
SuccessfulLookup[] slookups = new SuccessfulLookup[numSuccessfulLookups];
for (int i = 0; i < slookups.length; i++) {
slookups[i] =
new SuccessfulLookup(cl, 6319710844400051132L, barrier);
slookups[i] = new SuccessfulLookup(cl, 6319710844400051132L, sLookupLatch);
slookups[i].start();
}
Thread.sleep(1000);
synchronized (barrier) {
barrier.notifyAll();
}
System.out.println("awaiting completion of " + slookups.length + " SuccessfulLookup");
for (int i = 0; i < slookups.length; i++) {
slookups[i].join();
if (!slookups[i].ok) {
throw new Error();
}
}

System.out.println("all " + slookups.length + " SuccessfulLookup completed");
cl = Class.forName("Bad", false, loader);
FailingLookup[] flookups = new FailingLookup[50];
int numFailingLookups = 50;
CountDownLatch fLookupLatch = new CountDownLatch(numFailingLookups);
FailingLookup[] flookups = new FailingLookup[numFailingLookups];
for (int i = 0; i < flookups.length; i++) {
flookups[i] = new FailingLookup(cl, barrier);
flookups[i] = new FailingLookup(cl, fLookupLatch);
flookups[i].start();
}
Thread.sleep(1000);
synchronized (barrier) {
barrier.notifyAll();
}
for (int i = 0; i < slookups.length; i++) {
System.out.println("awaiting completion of " + flookups.length + " FailingLookup");
for (int i = 0; i < flookups.length; i++) {
flookups[i].join();
if (!flookups[i].ok) {
throw new Error();
}
}
System.out.println("all " + flookups.length + " FailingLookup completed");
}
}

0 comments on commit 08c7c38

Please sign in to comment.