Skip to content

Commit

Permalink
JDK22 new API support
Browse files Browse the repository at this point in the history
Implemented JavaLangAccess APIs: ensureNativeAccess(Module mod, Class<?>
clzOwner, String methodName, Class<?> clzCaller), bytesCompatible(String
str, Charset charset), copyToSegmentRaw(String str, MemorySegment ms,
long offset);
Updated LinkerOptions.isCritical() usage;
Limited JEP 442 tests to JDK21;
Created Java22andUp for JDK22 JEP 454 tests.

Signed-off-by: Jason Feng <fengj@ca.ibm.com>
  • Loading branch information
JasonFengJ9 committed Oct 19, 2023
1 parent 7cf716a commit 77da18f
Show file tree
Hide file tree
Showing 48 changed files with 15,515 additions and 86 deletions.
22 changes: 22 additions & 0 deletions jcl/src/java.base/share/classes/java/lang/Access.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
package java.lang;

import java.lang.annotation.Annotation;
/*[IF JAVA_SPEC_VERSION >= 22]*/
import java.lang.foreign.MemorySegment;
/*[ENDIF] JAVA_SPEC_VERSION >= 22 */
/*[IF JAVA_SPEC_VERSION >= 15]*/
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
Expand Down Expand Up @@ -497,9 +500,16 @@ public String join(String prefix, String suffix, String delimiter, String[] elem
}

/*[IF JAVA_SPEC_VERSION >= 20]*/
@Override
/*[IF JAVA_SPEC_VERSION >= 22]*/
public void ensureNativeAccess(Module mod, Class<?> clsOwner, String methodName, Class<?> clsCaller) {
mod.ensureNativeAccess(clsOwner, methodName, clsCaller);
}
/*[ELSE] JAVA_SPEC_VERSION >= 22 */
public void ensureNativeAccess(Module mod, Class<?> clsOwner, String methodName) {
mod.ensureNativeAccess(clsOwner, methodName);
}
/*[ENDIF] JAVA_SPEC_VERSION >= 22 */

public void addEnableNativeAccessToAllUnnamed() {
Module.implAddEnableNativeAccessToAllUnnamed();
Expand Down Expand Up @@ -727,6 +737,18 @@ public String getLoaderNameID(ClassLoader loader) {
}
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */

/*[IF JAVA_SPEC_VERSION >= 22]*/
@Override
public boolean bytesCompatible(String string, Charset charset) {
return string.bytesCompatible(charset);
}

@Override
public void copyToSegmentRaw(String string, MemorySegment segment, long offset) {
string.copyToSegmentRaw(segment, offset);
}
/*[ENDIF] JAVA_SPEC_VERSION >= 22 */

/*[IF INLINE-TYPES]*/
@Override
public boolean isPrimitiveClass(Class<?> c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,17 @@ Object runNativeMethod(Addressable downcallAddr, SegmentAllocator segmtAllocator
/*[IF JAVA_SPEC_VERSION >= 21]*/
try (Arena arena = Arena.ofConfined()) {
SetDependency(arena.scope());
returnVal = invokeNative(linkerOpts.isTrivial(), getValidDowncallMemAddr(stateSegmt), retMemAddr, getValidDowncallMemAddr(downcallAddr), cifNativeThunkAddr, args);
returnVal = invokeNative(
/*[IF JAVA_SPEC_VERSION >= 22]*/
linkerOpts.isCritical(),
/*[ELSE] JAVA_SPEC_VERSION >= 22 */
linkerOpts.isTrivial(),
/*[ENDIF] JAVA_SPEC_VERSION >= 22 */
getValidDowncallMemAddr(stateSegmt),
retMemAddr,
getValidDowncallMemAddr(downcallAddr),
cifNativeThunkAddr,
args);
}
/*[ELSE] JAVA_SPEC_VERSION >= 21 */
acquireScope();
Expand Down
89 changes: 89 additions & 0 deletions test/functional/Java21Only/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0"?>
<!--
Copyright IBM Corp. and others 2023
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which accompanies this
distribution and is available at https://www.eclipse.org/legal/epl-2.0/
or the Apache License, Version 2.0 which accompanies this distribution and
is available at https://www.apache.org/licenses/LICENSE-2.0.
This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set
forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
General Public License, version 2 with the GNU Classpath
Exception [1] and GNU General Public License, version 2 with the
OpenJDK Assembly Exception [2].
[1] https://www.gnu.org/software/classpath/license.html
[2] https://openjdk.org/legal/assembly-exception.html
SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
-->
<project name="Java21Only" default="build" basedir=".">
<taskdef resource='net/sf/antcontrib/antlib.xml' />
<description>
Tests for Java 21 only
</description>

<!-- set global properties for this build -->
<property name="DEST" value="${BUILD_ROOT}/functional/Java21Only" />

<!--Properties for this particular build-->
<property name="src" location="src" />
<property name="build" location="bin" />
<property name="LIB" value="asm,testng,jcommander" />
<import file="${TEST_ROOT}/TKG/scripts/getDependencies.xml" />
<property name="TestUtilities" location="../TestUtilities/src"/>

<target name="init">
<mkdir dir="${DEST}" />
<mkdir dir="${build}" />
</target>

<target name="compile" depends="init,getDependentLibs" description="Using java ${JDK_VERSION} to compile the source">
<echo>Ant version is ${ant.version}</echo>
<echo>============COMPILER SETTINGS============</echo>
<echo>===fork: yes</echo>
<echo>===executable: ${compiler.javac}</echo>
<echo>===debug: on</echo>
<echo>===destdir: ${DEST}</echo>

<javac srcdir="${src}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" includeAntRuntime="false" encoding="ISO-8859-1">
<src path="${src}" />
<src path="${TestUtilities}" />
<compilerarg line='--enable-preview --source ${JDK_VERSION}' />
<classpath>
<pathelement location="${LIB_DIR}/testng.jar" />
<pathelement location="${LIB_DIR}/jcommander.jar" />
<pathelement location="${LIB_DIR}/asm.jar" />
<pathelement location="${build}" />
</classpath>
</javac>
</target>

<target name="dist" depends="compile" description="generate the distribution">
<mkdir dir="${DEST}" />
<jar jarfile="${DEST}/GeneralTest.jar" filesonly="true">
<fileset dir="${build}" />
<fileset dir="${src}/../" includes="*.properties,*.xml" />
</jar>
<copy todir="${DEST}">
<fileset dir="${src}/../" includes="*.xml" />
<fileset dir="${src}/../" includes="*.mk" />
</copy>
</target>

<target name="build">
<if>
<equals arg1="${JDK_VERSION}" arg2="21" />
<then>
<antcall target="clean" inheritall="true" />
</then>
</if>
</target>

<target name="clean" depends="dist" description="clean up">
<delete dir="${build}" />
</target>
</project>
81 changes: 81 additions & 0 deletions test/functional/Java21Only/playlist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright IBM Corp. and others 2023
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which accompanies this
distribution and is available at https://www.eclipse.org/legal/epl-2.0/
or the Apache License, Version 2.0 which accompanies this distribution and
is available at https://www.apache.org/licenses/LICENSE-2.0.
This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set
forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
General Public License, version 2 with the GNU Classpath
Exception [1] and GNU General Public License, version 2 with the
OpenJDK Assembly Exception [2].
[1] https://www.gnu.org/software/classpath/license.html
[2] https://openjdk.org/legal/assembly-exception.html
SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
-->
<playlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../TestConfig/playlist.xsd">
<test>
<testCaseName>Jep442Tests_testLinkerFfi_DownCall</testCaseName>
<variations>
<variation>--enable-preview</variation>
</variations>
<command>$(ADD_JVM_LIB_DIR_TO_LIBPATH) $(JAVA_COMMAND) $(JVM_OPTIONS) \
--enable-native-access=ALL-UNNAMED \
-Dforeign.restricted=permit \
-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_210.xml$(Q) -testnames Jep442Tests_testLinkerFfi_DownCall \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)
</command>
<platformRequirements>bits.64,^arch.arm,^arch.riscv,^os.zos,^os.sunos</platformRequirements>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<impls>
<impl>openj9</impl>
</impls>
<versions>
<version>21</version>
</versions>
</test>

<test>
<testCaseName>Jep442Tests_testLinkerFfi_UpCall</testCaseName>
<variations>
<variation>--enable-preview</variation>
</variations>
<command>$(ADD_JVM_LIB_DIR_TO_LIBPATH) $(JAVA_COMMAND) $(JVM_OPTIONS) \
--enable-native-access=ALL-UNNAMED \
-Dforeign.restricted=permit \
-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_210.xml$(Q) -testnames Jep442Tests_testLinkerFfi_UpCall \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)
</command>
<platformRequirements>bits.64,^arch.arm,^arch.riscv,^os.zos,^os.sunos</platformRequirements>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<impls>
<impl>openj9</impl>
</impls>
<versions>
<version>21</version>
</versions>
</test>
</playlist>
53 changes: 53 additions & 0 deletions test/functional/Java21Only/testng_210.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright IBM Corp. and others 2023
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which accompanies this
distribution and is available at https://www.eclipse.org/legal/epl-2.0/
or the Apache License, Version 2.0 which accompanies this distribution and
is available at https://www.apache.org/licenses/LICENSE-2.0.
This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set
forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
General Public License, version 2 with the GNU Classpath
Exception [1] and GNU General Public License, version 2 with the
OpenJDK Assembly Exception [2].
[1] https://www.gnu.org/software/classpath/license.html
[2] https://openjdk.org/legal/assembly-exception.html
SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
-->

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Java21 only test suite" parallel="none" verbose="2">
<test name="Jep442Tests_testLinkerFfi_DownCall">
<classes>
<class name="org.openj9.test.jep442.downcall.InvalidDownCallTests"/>
<class name="org.openj9.test.jep442.downcall.MultiCallTests"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests1"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests2"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests3"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests4"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests5"/>
<class name="org.openj9.test.jep442.downcall.PrimitiveTypeTests1"/>
<class name="org.openj9.test.jep442.downcall.PrimitiveTypeTests2"/>
<class name="org.openj9.test.jep442.downcall.StructTests1"/>
<class name="org.openj9.test.jep442.downcall.StructTests2"/>
</classes>
</test>
<test name="Jep442Tests_testLinkerFfi_UpCall">
<classes>
<class name="org.openj9.test.jep442.upcall.InvalidUpCallTests"/>
<class name="org.openj9.test.jep442.upcall.MultiUpcallMHTests"/>
<class name="org.openj9.test.jep442.upcall.MultiUpcallThrdsMHTests1"/>
<class name="org.openj9.test.jep442.upcall.MultiUpcallThrdsMHTests2"/>
<class name="org.openj9.test.jep442.upcall.UpcallMHWithMixedSigStruTests"/>
<class name="org.openj9.test.jep442.upcall.UpcallMHWithPrimTests"/>
<class name="org.openj9.test.jep442.upcall.UpcallMHWithStructTests"/>
</classes>
</test>
</suite>
58 changes: 0 additions & 58 deletions test/functional/Java21andUp/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,62 +55,4 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
<version>21+</version>
</versions>
</test>

<test>
<testCaseName>Jep442Tests_testLinkerFfi_DownCall</testCaseName>
<variations>
<variation>--enable-preview</variation>
</variations>
<command>$(ADD_JVM_LIB_DIR_TO_LIBPATH) $(JAVA_COMMAND) $(JVM_OPTIONS) \
--enable-native-access=ALL-UNNAMED \
-Dforeign.restricted=permit \
-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_210.xml$(Q) -testnames Jep442Tests_testLinkerFfi_DownCall \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)
</command>
<platformRequirements>bits.64,^arch.arm,^arch.riscv,^os.zos,^os.sunos</platformRequirements>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<impls>
<impl>openj9</impl>
</impls>
<versions>
<version>21+</version>
</versions>
</test>

<test>
<testCaseName>Jep442Tests_testLinkerFfi_UpCall</testCaseName>
<variations>
<variation>--enable-preview</variation>
</variations>
<command>$(ADD_JVM_LIB_DIR_TO_LIBPATH) $(JAVA_COMMAND) $(JVM_OPTIONS) \
--enable-native-access=ALL-UNNAMED \
-Dforeign.restricted=permit \
-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_210.xml$(Q) -testnames Jep442Tests_testLinkerFfi_UpCall \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)
</command>
<platformRequirements>bits.64,^arch.arm,^arch.riscv,^os.zos,^os.sunos</platformRequirements>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<impls>
<impl>openj9</impl>
</impls>
<versions>
<version>21+</version>
</versions>
</test>
</playlist>
28 changes: 1 addition & 27 deletions test/functional/Java21andUp/testng_210.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,10 @@
-->

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Java21 test suite" parallel="none" verbose="2">
<suite name="Java21+ test suite" parallel="none" verbose="2">
<test name="Jep425Tests_testVirtualThread">
<classes>
<class name="org.openj9.test.jep425.VirtualThreadTests"/>
</classes>
</test>
<test name="Jep442Tests_testLinkerFfi_DownCall">
<classes>
<class name="org.openj9.test.jep442.downcall.InvalidDownCallTests"/>
<class name="org.openj9.test.jep442.downcall.MultiCallTests"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests1"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests2"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests3"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests4"/>
<class name="org.openj9.test.jep442.downcall.MultiThreadingTests5"/>
<class name="org.openj9.test.jep442.downcall.PrimitiveTypeTests1"/>
<class name="org.openj9.test.jep442.downcall.PrimitiveTypeTests2"/>
<class name="org.openj9.test.jep442.downcall.StructTests1"/>
<class name="org.openj9.test.jep442.downcall.StructTests2"/>
</classes>
</test>
<test name="Jep442Tests_testLinkerFfi_UpCall">
<classes>
<class name="org.openj9.test.jep442.upcall.InvalidUpCallTests"/>
<class name="org.openj9.test.jep442.upcall.MultiUpcallMHTests"/>
<class name="org.openj9.test.jep442.upcall.MultiUpcallThrdsMHTests1"/>
<class name="org.openj9.test.jep442.upcall.MultiUpcallThrdsMHTests2"/>
<class name="org.openj9.test.jep442.upcall.UpcallMHWithMixedSigStruTests"/>
<class name="org.openj9.test.jep442.upcall.UpcallMHWithPrimTests"/>
<class name="org.openj9.test.jep442.upcall.UpcallMHWithStructTests"/>
</classes>
</test>
</suite>

0 comments on commit 77da18f

Please sign in to comment.