Skip to content

Commit

Permalink
Don't use Thread.stop() in clinit tests, to support jdk20+
Browse files Browse the repository at this point in the history
Issue #16213

Signed-off-by: Peter Shipton <Peter_Shipton@ca.ibm.com>
  • Loading branch information
pshipton committed Nov 1, 2022
1 parent 366c9e3 commit 564643b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2021 IBM Corp. and others
* Copyright (c) 2001, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -39,6 +39,8 @@ class GetStaticTestHelper {
try {
Thread.sleep(1000000);
} catch(InterruptedException e) {
GetStaticDuringClinit.interrupted = true;
break;
}
}
}
Expand All @@ -48,7 +50,8 @@ public class GetStaticDuringClinit {
public static Object lock = new Object();
public static boolean runBlocker = false;
public static boolean threadsReady = false;
public static boolean passed = true;
public static volatile boolean passed = true;
public static volatile boolean interrupted = false;

public static String jitRead() {
return GetStaticTestHelper.i;
Expand Down Expand Up @@ -87,9 +90,11 @@ public void run() {
lock.notifyAll();
}
String value = jitRead();
// <clinit> for GetStaticTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid getstatic.
passed = false;
if (!interrupted) {
// <clinit> for GetStaticTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid getstatic.
passed = false;
}
}
};
initializer.start();
Expand All @@ -109,8 +114,8 @@ public void run() {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
initializer.stop();
blocker.stop();
initializer.interrupt();
blocker.interrupt();
try {
initializer.join();
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2019 IBM Corp. and others
* Copyright (c) 2001, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -39,6 +39,8 @@ public static void staticMethod() {
try {
Thread.sleep(1000000);
} catch(InterruptedException e) {
InvokeStaticDuringClinit.interrupted = true;
break;
}
}
}
Expand All @@ -48,7 +50,8 @@ public class InvokeStaticDuringClinit {
public static Object lock = new Object();
public static boolean runBlocker = false;
public static boolean threadsReady = false;
public static boolean passed = true;
public static volatile boolean passed = true;
public static volatile boolean interrupted = false;

public static void staticMethod() {
}
Expand Down Expand Up @@ -82,9 +85,11 @@ public void run() {
lock.notifyAll();
}
jitSend();
// <clinit> for InvokeStaticTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid invokestatic.
passed = false;
if (!interrupted) {
// <clinit> for InvokeStaticTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid invokestatic.
passed = false;
}
}
};
initializer.start();
Expand All @@ -104,8 +109,8 @@ public void run() {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
initializer.stop();
blocker.stop();
initializer.interrupt();
blocker.interrupt();
try {
initializer.join();
} catch (InterruptedException e) {
Expand Down
19 changes: 12 additions & 7 deletions test/functional/VM_Test/src/j9vm/test/clinit/NewDuringClinit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2018 IBM Corp. and others
* Copyright (c) 2001, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -38,6 +38,8 @@ class NewTestHelper {
try {
Thread.sleep(1000000);
} catch(InterruptedException e) {
NewDuringClinit.interrupted = true;
break;
}
}
}
Expand All @@ -47,7 +49,8 @@ public class NewDuringClinit {
public static Object lock = new Object();
public static boolean runBlocker = false;
public static boolean threadsReady = false;
public static boolean passed = true;
public static volatile boolean passed = true;
public static volatile boolean interrupted = false;

public static void jitNew() {
try {
Expand Down Expand Up @@ -83,9 +86,11 @@ public void run() {
lock.notifyAll();
}
jitNew();
// <clinit> for NewTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid new.
passed = false;
if (!interrupted) {
// <clinit> for NewTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid new.
passed = false;
}
}
};
initializer.start();
Expand All @@ -105,8 +110,8 @@ public void run() {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
initializer.stop();
blocker.stop();
initializer.interrupt();
blocker.interrupt();
try {
initializer.join();
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2021 IBM Corp. and others
* Copyright (c) 2018, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -39,6 +39,8 @@ class PutStaticTestHelper {
try {
Thread.sleep(1000000);
} catch(InterruptedException e) {
PutStaticDuringClinit.interrupted = true;
break;
}
}
}
Expand All @@ -48,7 +50,8 @@ public class PutStaticDuringClinit {
public static Object lock = new Object();
public static boolean runBlocker = false;
public static boolean threadsReady = false;
public static boolean passed = true;
public static volatile boolean passed = true;
public static volatile boolean interrupted = false;

public static void jitWrite(String x) {
// https://github.com/eclipse-openj9/openj9/pull/2794
Expand Down Expand Up @@ -83,9 +86,11 @@ public void run() {
lock.notifyAll();
}
jitWrite("whatever");
// <clinit> for PutStaticTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid putstatic.
passed = false;
if (!interrupted) {
// <clinit> for PutStaticTestHelper never returns, so if execution reaches
// here, the VM has allowed an invalid putstatic.
passed = false;
}
}
};
initializer.start();
Expand All @@ -105,8 +110,8 @@ public void run() {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
initializer.stop();
blocker.stop();
initializer.interrupt();
blocker.interrupt();
try {
initializer.join();
} catch (InterruptedException e) {
Expand Down

0 comments on commit 564643b

Please sign in to comment.