Skip to content

Commit

Permalink
Merge pull request #16585 from ChengJin01/ffi_disable_code_for_jep434…
Browse files Browse the repository at this point in the history
…_jdk20

Update FFI & Access related code in OpenJ9 for compilation in JDK20
  • Loading branch information
keithc-ca authored Feb 2, 2023
2 parents 85ef35e + 129039a commit d95b850
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 34 deletions.
45 changes: 44 additions & 1 deletion jcl/src/java.base/share/classes/java/lang/Access.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/
/*
* Copyright (c) 2007, 2022 IBM Corp. and others
* Copyright (c) 2007, 2023 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,9 @@
import com.ibm.oti.reflect.TypeAnnotationParser;

/*[IF Sidecar19-SE]*/
/*[IF JAVA_SPEC_VERSION >= 20]*/
import java.io.InputStream;
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */
import java.io.IOException;
import java.lang.module.ModuleDescriptor;
import java.net.URL;
Expand Down Expand Up @@ -487,13 +490,23 @@ public String join(String prefix, String suffix, String delimiter, String[] elem
return String.join(prefix, suffix, delimiter, elements, size);
}

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

public void addEnableNativeAccessToAllUnnamed() {
Module.implAddEnableNativeAccessToAllUnnamed();
}
/*[ELSE] JAVA_SPEC_VERSION >= 20 */
public boolean isEnableNativeAccess(Module mod) {
return mod.implIsEnableNativeAccess();
}

public void addEnableNativeAccessAllUnnamed() {
Module.implAddEnableNativeAccessAllUnnamed();
}
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */

public Module addEnableNativeAccess(Module mod) {
return mod.implAddEnableNativeAccess();
Expand Down Expand Up @@ -543,6 +556,35 @@ public void setContinuation(Thread thread, Continuation c) {
thread.setContinuation(c);
}

/*[IF JAVA_SPEC_VERSION >= 20]*/
public Object[] scopedValueCache() {
return Thread.scopedValueCache();
}

public void setScopedValueCache(Object[] cache) {
Thread.setScopedValueCache(cache);
}

public Object scopedValueBindings() {
return Thread.scopedValueBindings();
}

public Object findScopedValueBindings() {
return Thread.findScopedValueBindings();
}

public void setScopedValueBindings(Object scopeValueBindings) {
Thread.setScopedValueBindings(scopeValueBindings);
}

public void ensureMaterializedForStackWalk(Object obj) {
Thread.ensureMaterializedForStackWalk(obj);
}

public InputStream initialSystemIn() {
return System.initialIn;
}
/*[ELSE] JAVA_SPEC_VERSION >= 20 */
public Object[] extentLocalCache() {
return Thread.extentLocalCache();
}
Expand All @@ -558,6 +600,7 @@ public Object extentLocalBindings() {
public void setExtentLocalBindings(Object bindings) {
Thread.setExtentLocalBindings(bindings);
}
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */

public StackableScope headStackableScope(Thread thread) {
return thread.headStackableScopes();
Expand Down
13 changes: 11 additions & 2 deletions jcl/src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/
/*******************************************************************************
* Copyright (c) 1998, 2023 IBM Corp. and others
*
Expand Down Expand Up @@ -79,6 +79,11 @@ public final class System {
* Default input stream
*/
public static final InputStream in = null;

/*[IF JAVA_SPEC_VERSION >= 20]*/
static InputStream initialIn;
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */

/**
* Default output stream
*/
Expand Down Expand Up @@ -481,7 +486,11 @@ static void completeInitialization() {
/*[ENDIF]*/ // Sidecar18-SE-OpenJ9

/*[IF (Sidecar18-SE-OpenJ9|Sidecar19-SE)&!(PLATFORM-mz31|PLATFORM-mz64)]*/
setIn(new BufferedInputStream(new FileInputStream(FileDescriptor.in)));
InputStream tempIn = new BufferedInputStream(new FileInputStream(FileDescriptor.in));
setIn(tempIn);
/*[IF JAVA_SPEC_VERSION >= 20]*/
initialIn = tempIn;
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */
/*[ELSE]*/
/*[PR 100718] Initialize System.in after the main thread*/
setIn(com.ibm.jvm.io.ConsoleInputStream.localize(new BufferedInputStream(new FileInputStream(FileDescriptor.in))));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 19]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION == 19]*/
/*******************************************************************************
* Copyright (c) 2021, 2022 IBM Corp. and others
* Copyright (c) 2021, 2023 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 19]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION == 19]*/
/*******************************************************************************
* Copyright (c) 2021, 2022 IBM Corp. and others
* Copyright (c) 2021, 2023 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 19]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION == 19]*/
/*******************************************************************************
* Copyright (c) 2022, 2022 IBM Corp. and others
* Copyright (c) 2022, 2023 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 19]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION == 19]*/
/*******************************************************************************
* Copyright (c) 2022, 2022 IBM Corp. and others
* Copyright (c) 2022, 2023 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 19]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION == 19]*/
/*******************************************************************************
* Copyright (c) 2022, 2022 IBM Corp. and others
* Copyright (c) 2022, 2023 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 19]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION == 19]*/
/*******************************************************************************
* Copyright (c) 2022, 2022 IBM Corp. and others
* Copyright (c) 2022, 2023 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
24 changes: 23 additions & 1 deletion runtime/jcl/common/thread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1998, 2022 IBM Corp. and others
* Copyright (c) 1998, 2023 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 @@ -571,4 +571,26 @@ Java_java_lang_Thread_registerNatives(JNIEnv *env, jclass clazz)
}
#endif /* JAVA_SPEC_VERSION >= 19 */

#if JAVA_SPEC_VERSION >= 20

/* static native void ensureMaterializedForStackWalk(Object o);
*
* This is expected to invoke JVM_EnsureMaterializedForStackWalk and ensure
* that the stackwalk code sees a materialized value.
*
* @param env instance of JNIEnv
* @param unusedClass
* @param obj the object to be checked
*/
void JNICALL
Java_java_lang_Thread_ensureMaterializedForStackWalk(JNIEnv *env, jclass unusedClass, jobject obj)
{
/* An empty implementation is sufficient since the hotspot
* JVM_EnsureMaterializedForStackWalk() does nothing.
* https://github.com/eclipse-openj9/openj9/issues/16577
*/
}

#endif /* JAVA_SPEC_VERSION >= 20 */

}
9 changes: 8 additions & 1 deletion runtime/jcl/exports.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2019, 2022 IBM Corp. and others
# Copyright (c) 2019, 2023 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 @@ -688,3 +688,10 @@ if(NOT JAVA_SPEC_VERSION LESS 19)
Java_jdk_internal_vm_Continuation_unpin
)
endif()

# Java 20+
if(NOT JAVA_SPEC_VERSION LESS 20)
omr_add_exports(jclse
Java_java_lang_Thread_ensureMaterializedForStackWalk
)
endif()
3 changes: 2 additions & 1 deletion runtime/jcl/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, 2022 IBM Corp. and others
Copyright (c) 2006, 2023 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 @@ -41,6 +41,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<xi:include href="uma/se15_exports.xml"></xi:include>
<xi:include href="uma/se16_exports.xml"></xi:include>
<xi:include href="uma/se19_exports.xml"></xi:include>
<xi:include href="uma/se20_exports.xml"></xi:include>

<xi:include href="uma/vendor_jcl_exports.xml">
<xi:fallback/>
Expand Down
24 changes: 24 additions & 0 deletions runtime/jcl/uma/se20_exports.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
Copyright (c) 2023, 2023 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
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 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
-->
<exports group="se20">
<export name="Java_java_lang_Thread_ensureMaterializedForStackWalk" />
</exports>
29 changes: 17 additions & 12 deletions test/functional/Java19andUp/build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2022, 2022 IBM Corp. and others
Copyright (c) 2022, 2023 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 @@ -49,17 +49,22 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<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>
<if>
<equals arg1="${JDK_VERSION}" arg2="19"/>
<then>
<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>
</then>
</if>
</target>

<target name="dist" depends="compile" description="generate the distribution">
Expand Down
8 changes: 4 additions & 4 deletions test/functional/Java19andUp/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<impl>openj9</impl>
</impls>
<versions>
<version>19+</version>
<version>19</version>
</versions>
</test>

Expand Down Expand Up @@ -81,7 +81,7 @@
<impl>openj9</impl>
</impls>
<versions>
<version>19+</version>
<version>19</version>
</versions>
</test>

Expand Down Expand Up @@ -110,7 +110,7 @@
<impl>openj9</impl>
</impls>
<versions>
<version>19+</version>
<version>19</version>
</versions>
</test>

Expand Down Expand Up @@ -139,7 +139,7 @@
<impl>openj9</impl>
</impls>
<versions>
<version>19+</version>
<version>19</version>
</versions>
</test>
</playlist>

0 comments on commit d95b850

Please sign in to comment.