Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove java.lang.Compiler for Java 21+ #18581

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions jcl/src/java.base/share/classes/java/lang/Compiler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*[INCLUDE-IF Sidecar16]*/
package java.lang;

/*[INCLUDE-IF JAVA_SPEC_VERSION < 21]*/
/*******************************************************************************
* Copyright IBM Corp. and others 1998
*
Expand All @@ -22,7 +20,8 @@
*
* 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
*******************************************************************************/

package java.lang;

/**
* This class is a placeholder for environments which
* explicitly manage the action of a "Just In Time"
Expand Down Expand Up @@ -82,8 +81,8 @@ public static boolean compileClass(Class<?> classToCompile) {

/**
* Compiles all classes whose name matches the argument
* using the JIT compiler. Answers true if the compilation
* was successful, or false if it failed or there was no
* using the JIT compiler. Answers true if the compilation
* was successful, or false if it failed or there was no
* JIT compiler available.
*
* @return boolean
Expand Down
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