Skip to content

Commit

Permalink
Merge pull request #13205 from EricYangIBM/fixJDK17CloseScopeTestFailure
Browse files Browse the repository at this point in the history
Fix close scope test failure jdk17
  • Loading branch information
llxia committed Nov 18, 2021
2 parents 9a78143 + 2c09951 commit d03f3b8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
2 changes: 2 additions & 0 deletions test/functional/Java16andUp/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<property name="module_src_root" location="modules" />
<property name="module_bin_root" location="module_bin" />
<property name="dest_module_bin" location="${DEST}/module_bin" />
<property name="TestUtilities" location="../TestUtilities/src"/>
<property name="LIB" value="asm,testng,jcommander" />
<import file="${TEST_ROOT}/TKG/scripts/getDependencies.xml" />

Expand Down Expand Up @@ -95,6 +96,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<javac srcdir="${src}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1">
<src path="${src}" />
<src path="${src_160}" />
<src path="${TestUtilities}" />
<exclude name="**/modules/**" />
<compilerarg line='--enable-preview --source ${JDK_VERSION}' />
<compilerarg line='--add-modules jdk.incubator.foreign' />
Expand Down
10 changes: 2 additions & 8 deletions test/functional/Java16andUp/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@
</test>
<test>
<testCaseName>CloseScope0Tests</testCaseName>
<disables>
<disable>
<comment>https://github.com/eclipse-openj9/openj9/issues/13195</comment>
<version>17</version>
</disable>
</disables>
<variations>
<variation>--enable-preview</variation>
</variations>
Expand All @@ -143,7 +137,7 @@
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-modules jdk.incubator.foreign \
-cp $(Q)$(LIB_DIR)$(D)asm.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng_160.xml$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) \
-testnames CloseScope0Tests \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
Expand All @@ -156,7 +150,7 @@
<group>functional</group>
</groups>
<versions>
<version>16</version>
<version>16+</version>
</versions>
</test>
<test>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import org.testng.Assert;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import org.openj9.test.util.VersionCheck;

import java.lang.reflect.*;
import java.lang.ref.Cleaner;
import jdk.internal.misc.ScopedMemoryAccess.*;

import org.objectweb.asm.*;
import static org.objectweb.asm.Opcodes.*;
Expand Down Expand Up @@ -83,14 +85,25 @@ public static byte[] dump() throws Exception {
@Test(expectedExceptions=java.lang.IllegalStateException.class)
public static void closeScopeDuringAccess() throws Throwable {
/* Reflect setup */
Class c = Class.forName("jdk.internal.foreign.MemoryScope");
Method createShared = c.getDeclaredMethod("createShared", new Class[] {Object.class, Runnable.class, Cleaner.class});
createShared.setAccessible(true);
Method close = c.getDeclaredMethod("close");
Class memoryOrResourceScope;
Method createShared;
Method close;
Object scope;

int version = VersionCheck.major();
if (version == 16) {
memoryOrResourceScope = Class.forName("jdk.internal.foreign.MemoryScope");
createShared = memoryOrResourceScope.getDeclaredMethod("createShared", new Class[] {Object.class, Runnable.class, Cleaner.class});
createShared.setAccessible(true);
scope = createShared.invoke(null, null, new Thread(), null);
} else {
memoryOrResourceScope = Class.forName("jdk.internal.foreign.ResourceScopeImpl");
createShared = memoryOrResourceScope.getDeclaredMethod("createShared", new Class[] {Cleaner.class});
createShared.setAccessible(true);
scope = createShared.invoke(null, Cleaner.create());
}
close = memoryOrResourceScope.getDeclaredMethod("close");
close.setAccessible(true);
final Object scope = createShared.invoke(null, null, new Thread(), null);

Class Scope = Class.forName("jdk.internal.misc.ScopedMemoryAccess$Scope");
/* End Reflect setup */

/* ASM setup */
Expand All @@ -99,15 +112,15 @@ public static void closeScopeDuringAccess() throws Throwable {
ClassLoader loader = ClassLoader.getSystemClassLoader();
Class cls = Class.forName("java.lang.ClassLoader");
Method defineClass = cls.getDeclaredMethod(
"defineClass",
"defineClass",
new Class[] { String.class, byte[].class, int.class, int.class });
defineClass.setAccessible(true);

Object[] dcArgs = new Object[] {"jdk.internal.misc.RunInScoped", classBytes, 0, classBytes.length};
Class RunInScoped = (Class)defineClass.invoke(loader, dcArgs);
Method runInScoped = RunInScoped.getDeclaredMethod("runInScoped", new Class[] {Runnable.class, Scope});
Method runInScoped = RunInScoped.getDeclaredMethod("runInScoped", new Class[] {Runnable.class, Scope.class});
/* End ASM setup */

Synch synch1 = new Synch();
Synch synch2 = new Synch();

Expand All @@ -132,7 +145,7 @@ public static void closeScopeDuringAccess() throws Throwable {
}
}
}, "ScopeCloserThread");

class MyRunnable implements Runnable {
public void run() {
try {
Expand All @@ -151,7 +164,7 @@ public void run() {
}
}
}

MyRunnable r = new MyRunnable();
Thread t2 = new Thread(()->{
try {
Expand Down
5 changes: 5 additions & 0 deletions test/functional/Java16andUp/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
<class name="org.openj9.test.java.lang.Test_Class"/>
</classes>
</test>
<test name="CloseScope0Tests">
<classes>
<class name="org.openj9.test.foreignMemoryAccess.TestCloseScope0"/>
</classes>
</test>
</suite>
5 changes: 0 additions & 5 deletions test/functional/Java16andUp/testng_160.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,4 @@
<class name="org.openj9.test.jep389.downcall.PrimitiveTypeTests"/>
</classes>
</test>
<test name="CloseScope0Tests">
<classes>
<class name="org.openj9.test.foreignMemoryAccess.TestCloseScope0"/>
</classes>
</test>
</suite>

0 comments on commit d03f3b8

Please sign in to comment.