Skip to content

Commit

Permalink
Adapt tests for removal of java.lang.Compiler
Browse files Browse the repository at this point in the history
Add CompilerAccess to allow tests to compile in Java 21+, supported
by new "access" test shared library. Update tests to use the new
library as needed, and defining TEST_LIB_PATH for DDR tests on OSX.

Signed-off-by: Keith W. Campbell <[email protected]>
  • Loading branch information
keithc-ca committed Dec 6, 2023
1 parent a0b17c7 commit b2491ba
Show file tree
Hide file tree
Showing 16 changed files with 681 additions and 360 deletions.
1 change: 1 addition & 0 deletions runtime/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# 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
################################################################################

add_subdirectory(access)
if(OMR_OS_AIX)
add_subdirectory(aixerrmsg)
endif()
Expand Down
34 changes: 34 additions & 0 deletions runtime/tests/access/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
################################################################################
# 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
################################################################################

j9vm_add_library(access SHARED
compiler.cpp
)

target_link_libraries(access
PRIVATE
j9vm_interface
)

omr_add_exports(access
Java_org_openj9_test_util_CompilerAccess_registerNatives
)
126 changes: 126 additions & 0 deletions runtime/tests/access/compiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*******************************************************************************
* 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
*******************************************************************************/

/**
* @file compiler.cpp
* @brief File is compiled into shared library (access)
* in support of org.openj9.test.util.CompilerAccess.
*/

#include "j9.h"
#include "j9lib.h"
#include "jni.h"

struct NativeMapping
{
const char *methodName;
const char *methodSignature;
const char *implementationName;
const char *implementationSignature;
};

static const NativeMapping mappings[] =
{
{
"commandImpl",
"(Ljava/lang/Object;)Ljava/lang/Object;",
"Java_java_lang_Compiler_commandImpl",
"LLLL"
},
{
"compileClassImpl",
"(Ljava/lang/Class;)Z",
"Java_java_lang_Compiler_compileClassImpl",
"ZLLL"
},
{
"compileClassesImpl",
"(Ljava/lang/String;)Z",
"Java_java_lang_Compiler_compileClassesImpl",
"ZLLL"
},
{
"disable",
"()V",
"Java_java_lang_Compiler_disable",
"VLL"
},
{
"enable",
"()V",
"Java_java_lang_Compiler_enable",
"VLL"
},
};

#define METHOD_COUNT (sizeof(mappings) / sizeof(mappings[0]))

extern "C" jboolean
Java_org_openj9_test_util_CompilerAccess_registerNatives(JNIEnv *env, jclass clazz)
{
jboolean result = JNI_FALSE;
PORT_ACCESS_FROM_ENV(env);
uintptr_t j9jcl = 0;
JNINativeMethod methods[METHOD_COUNT];

if ((0 != j9sl_open_shared_library((char *)J9_JAVA_SE_DLL_NAME, &j9jcl, OMRPORT_SLOPEN_DECORATE))
|| (0 == j9jcl)
) {
j9tty_printf(PORTLIB,"CompilerAccess: could not open %s.\n", J9_JAVA_SE_DLL_NAME);
goto done;
}

for (uintptr_t i = 0; i < METHOD_COUNT; ++i) {
const NativeMapping *mapping = &mappings[i];
JNINativeMethod *method = &methods[i];
uintptr_t function = 0;

if ((0 != j9sl_lookup_name(
j9jcl,
(char *)mapping->implementationName,
&function,
(char *)mapping->implementationSignature))
|| (0 == function)
) {
j9tty_printf(PORTLIB,"CompilerAccess: '%s' not found.\n", mapping->implementationName);
goto done;
}

method->name = (char *)mapping->methodName;
method->signature = (char *)mapping->methodSignature;
method->fnPtr = (void *)function;
}

if (JNI_OK != env->RegisterNatives(clazz, methods, METHOD_COUNT)) {
j9tty_printf(PORTLIB,"CompilerAccess: RegisterNatives failed.\n");
goto done;
}

result = JNI_TRUE;

done:
if (0 != j9jcl) {
j9sl_close_shared_library(j9jcl);
}

return result;
}
37 changes: 37 additions & 0 deletions runtime/tests/access/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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
-->
<module xmlns:xi="http://www.w3.org/2001/XInclude">
<exports group="all">
<export name="Java_org_openj9_test_util_CompilerAccess_registerNatives"/>
</exports>
<artifact type="shared" name="access" appendrelease="false">
<phase>core quick j2se</phase>
<exports>
<group name="all"/>
</exports>
<includes>
<include path="j9include"/>
<include path="j9oti"/>
</includes>
</artifact>
</module>
Loading

0 comments on commit b2491ba

Please sign in to comment.