[m-rev.] for review: delete remaining support for Java native methods
Julien Fischer
jfischer at opturion.com
Tue Jan 21 14:41:24 AEDT 2025
Hi,
In the absence of objections or any other review comments, I shall commit
this one tonight.
Julien.
On Mon, 20 Jan 2025 at 04:01, Julien Fischer <jfischer at opturion.com> wrote:
>
> For review by anyone.
>
> The request for review is for the concept, the diff is trivial.
>
> -----------------------
>
> Delete remaining support for Java native methods.
>
> Prior to 2009 some of the standard library predicates were implemented using
> Java native methods. These were disabled or replaced by commit 9fc47f5c in
> order to give us pure Java versions of the runtime and standard libraries.
> However, the machinery for supporting native methods was left in place. This
> change deletes that machinery. We are not going to use it again.
>
> library/Mmakefile:
> Do not build Native.so. (From the looks of it we never installed it
> anyway.)
>
> java/runtime/Native.c:
> Delete the C implementations of the native methods ...
>
> java/runtime/Native.java.in:
> ... and the corresponding Java support for them.
>
> java/runtime/Mmakefile:
> Delete this Mmakefile, there is no longer anything for it to do.
>
> configure.ac:
> Do not create Native.java.
>
> Julien.
>
> diff --git a/configure.ac b/configure.ac
> index d761a11..f8469a4 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -5497,7 +5497,6 @@ bindist/bindist.INSTALL
> bindist/bindist.Makefile
> runtime/mercury_dotnet.cs
> java/runtime/Constants.java
> -java/runtime/Native.java
> compiler/COMP_FLAGS
> grade_lib/GRADE_LIB_FLAGS
> library/LIB_FLAGS
> diff --git a/java/runtime/Mmakefile b/java/runtime/Mmakefile
> deleted file mode 100644
> index 1e96cf4..0000000
> --- a/java/runtime/Mmakefile
> +++ /dev/null
> @@ -1,39 +0,0 @@
> -#-----------------------------------------------------------------------------#
> -# vim: ts=8 sw=8 noexpandtab ft=make
> -#-----------------------------------------------------------------------------#
> -
> -# Copyright (C) 2004 The University of Melbourne.
> -# Copyright (C) 2015, 2018 The Mercury team.
> -# This file is distributed under the terms specified in COPYING.LIB.
> -#
> -# This Makefile compiles the shared object for use with
> -# jmercury.runtime.Native.
> -#
> -
> -MERCURY_DIR = ../..
> -RUNTIME_DIR = $(MERCURY_DIR)/runtime
> -
> -include $(MERCURY_DIR)/Mmake.common
> -
> -NATIVE_PIC = Native.$(EXT_FOR_PIC_OBJECTS)
> -NATIVE_SO = Native.$(EXT_FOR_SHARED_LIB)
> -
> -MAIN_TARGET = $(NATIVE_SO)
> -
> -PIC_OBJS = $(RUNTIME_DIR)/mercury_timing.$(EXT_FOR_PIC_OBJECTS) \
> - $(NATIVE_PIC)
> -
> -CFLAGS = -I$(RUNTIME_DIR)
> -
> -$(NATIVE_SO): $(PIC_OBJS)
> - $(LINK_SHARED_OBJ) -o $(NATIVE_SO) $(PIC_OBJS)
> -
> -$(NATIVE_PIC): Native.c
> - $(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) \
> - $(CFLAGS_FOR_PIC) -o $(NATIVE_PIC) -c Native.c
> -
> -clean:
> - rm -f $(PIC_OBJS)
> -
> -realclean:
> - rm -f $(PIC_OBJS) $(NATIVE_SO) *.class
> diff --git a/java/runtime/Native.c b/java/runtime/Native.c
> deleted file mode 100644
> index 730fb23..0000000
> --- a/java/runtime/Native.c
> +++ /dev/null
> @@ -1,114 +0,0 @@
> -// vim: ts=4 sw=4 expandtab ft=c
> -//
> -// Copyright (C) 2004, 2006 The University of Melbourne.
> -// Copyright (C) 2018 The Mercury team.
> -// This file is distributed under the terms specified in COPYING.LIB.
> -//
> -
> -// File: Native.c - Native code for java/runtime/Native.java.
> -
> -#include <jni.h>
> -
> -/*
> - * Class: Native
> - * Method: clock
> - * Signature: ()I
> - */
> -JNIEXPORT jint JNICALL Java_jmercury_runtime_Native_clock(JNIEnv *, jclass);
> -
> -/*
> - * Class: Native
> - * Method: clocks_per_sec
> - * Signature: ()I
> - */
> -JNIEXPORT jint JNICALL Java_jmercury_runtime_Native_clocks_1per_1sec(
> - JNIEnv *, jclass);
> -
> -/*
> - * Class: Native
> - * Method: times
> - * Signature: ()[I
> - */
> -JNIEXPORT jintArray JNICALL Java_jmercury_runtime_Native_times(
> - JNIEnv *, jclass);
> -
> -/*
> - * Class: Native
> - * Method: clk_tck
> - * Signature: ()I
> - */
> -JNIEXPORT jint JNICALL Java_jmercury_runtime_Native_clk_1tck(JNIEnv *, jclass);
> -
> -/*
> - * Class: Native
> - * Method: get_user_cpu_milliseconds
> - * Signature: ()I
> - */
> -JNIEXPORT jint JNICALL
> Java_jmercury_runtime_Native_get_1user_1cpu_1milliseconds(
> - JNIEnv *, jclass);
> -
> -#include "mercury_imp.h"
> -#include "mercury_timing.h"
> -
> -#include <time.h>
> -#ifdef MR_HAVE_SYS_TYPES_H
> - #include <sys/types.h>
> -#endif
> -#ifdef MR_HAVE_SYS_TIMES_H
> - #include <sys/times.h>
> -#endif
> -#ifdef MR_HAVE_UNISTD_H
> - #include <unistd.h>
> -#endif
> -
> -JNIEXPORT jint JNICALL
> -Java_jmercury_runtime_Native_clock(JNIEnv *env, jclass obj) {
> - return (MR_Integer) clock();
> -}
> -
> -JNIEXPORT jint JNICALL
> -Java_jmercury_runtime_Native_clocks_1per_1sec(JNIEnv *env, jclass obj) {
> - return CLOCKS_PER_SEC;
> -}
> -
> -JNIEXPORT jintArray JNICALL
> -Java_jmercury_runtime_Native_times(JNIEnv *env, jclass obj) {
> - jint intarray[5];
> - jintArray result;
> -
> -#ifdef MR_HAVE_POSIX_TIMES
> - struct tms t;
> -
> - intarray[0] = (MR_Integer) times(&t);
> - intarray[1] = (MR_Integer) t.tms_utime;
> - intarray[2] = (MR_Integer) t.tms_stime;
> - intarray[3] = (MR_Integer) t.tms_cutime;
> - intarray[4] = (MR_Integer) t.tms_cstime;
> -#else
> - intarray[0] = -1;
> -#endif
> -
> - result = (*env)->NewIntArray(env, 5);
> - if (result != NULL) {
> - (*env)->SetIntArrayRegion(env, result, 0, 5, intarray);
> - }
> -
> - return result;
> -}
> -
> -JNIEXPORT jint JNICALL Java_jmercury_runtime_Native_clk_1tck(
> - JNIEnv *env, jclass obj)
> -{
> -#if defined(MR_CLOCK_TICKS_PER_SECOND)
> - return MR_CLOCK_TICKS_PER_SECOND;
> -#else
> - return -1;
> -#endif
> -}
> -
> -JNIEXPORT jint JNICALL
> -Java_jmercury_runtime_Native_get_1user_1cpu_1milliseconds(
> - JNIEnv *env, jclass obj)
> -{
> - return MR_get_user_cpu_milliseconds();
> -}
> diff --git a/java/runtime/Native.java.in b/java/runtime/Native.java.in
> deleted file mode 100644
> index 0f33077..0000000
> --- a/java/runtime/Native.java.in
> +++ /dev/null
> @@ -1,140 +0,0 @@
> -// vim: ts=4 sw=4 expandtab ft=java
> -//
> -// @configure_input@
> -//
> -// Copyright (C) 2004, 2006 The University of Melbourne.
> -// Copyright (C) 2018 The Mercury team.
> -// This file is distributed under the terms specified in COPYING.LIB.
> -//
> -//
> -// This class exists to provide any native functionality required by the Java
> -// implementation. It uses JNI to access a shared object which it searches
> -// for in all the directories listed in the current CLASSPATH.
> -//
> -// At the moment the only services provided are those relating to timing.
> -//
> -
> -package jmercury.runtime;
> -
> -public class Native {
> - /**
> - * SHARED_OBJ is the name of the shared object which contains
> - * all the compiled native code.
> - */
> - private static final java.lang.String SHARED_OBJ =
> - "Native. at EXT_FOR_SHARED_LIB@";
> -
> - /**
> - * attemptedLoad records whether or not the user has yet attempted
> - * to load the shared library.
> - */
> - private static boolean attemptedLoad = false;
> -
> - /**
> - * available and isAvailable() are true when native functionality
> - * is available. (ie SHARED_OBJ was loaded successfully)
> - */
> - private static boolean available = false;
> -
> - /**
> - * isAvailable() as the side effect of attempting to load the library
> - * if this has not already been done.
> - */
> - public static boolean isAvailable() {
> - if (!attemptedLoad) {
> - load_library();
> - }
> - return available;
> - }
> -
> - static {
> - load_library();
> - }
> -
> - /**
> - * load_library():
> - * Searches all the directories listed in the classpath,
> - * (including the directories containing each jar file) for the
> - * shared object SHARED_OBJ, and attempts to load this file if found.
> - * Also searches in the subdirectory Constants.MR_FULLARCH.
> - * Sets available to true if successful, false otherwise.
> - */
> - private static void load_library() {
> - attemptedLoad = true;
> -
> - java.util.StringTokenizer classpath =
> - new java.util.StringTokenizer(
> - java.lang.System.getProperty("java.class.path"),
> - java.lang.System.getProperty("path.separator")
> - );
> -
> - while (classpath.hasMoreTokens()) {
> - java.io.File dir;
> - java.io.File entry = new java.io.File(classpath.nextToken());
> -
> - try {
> - if (entry.isDirectory()) {
> - dir = entry;
> - } else {
> - dir = entry.getParentFile();
> - }
> - if (dir == null) {
> - dir = new java.io.File("");
> - }
> -
> - java.io.File match = new java.io.File(dir, SHARED_OBJ);
> - if (match.exists() == false) {
> - dir = new java.io.File(dir, Constants.MR_FULLARCH);
> - match = new java.io.File(dir, SHARED_OBJ);
> - }
> -
> - java.lang.System.load(match.getAbsolutePath());
> - available = true;
> - return;
> - }
> - catch (java.lang.Exception e) {
> - continue;
> - }
> - } // while classpath.hasMoreTokens()
> -
> - return;
> - } // load_library()
> -
> - /**
> - * clock():
> - * Calls clock() from the <time.h> library.
> - */
> - public static native int clock();
> -
> - /**
> - * clocks_per_sec():
> - * Returns the number of "clocks" per sec as defined by CLOCKS_PER_SEC.
> - */
> - public static native int clocks_per_sec();
> -
> - /**
> - * times():
> - * Calls times() from the <time.h> library. Results are returned
> - * in an int array of the form:
> - * { <return value>, utime, stime, cutime, cstime }
> - * If POSIX times are not available, <return value> will be set to -1,
> - * and the other values are undefined.
> - * Returns null if the array cannot be constructed.
> - */
> - public static native int[] times();
> -
> - /**
> - * clk_tck():
> - * Returns the number of "clock ticks" per second as defined by
> - * sysconf(_SC_CLK_TCK). A `clock_t' value returned by 'times()'
> - * can be divided by this value to obtain a time in seconds.
> - */
> - public static native int clk_tck();
> -
> - /**
> - * get_user_cpu_milliseconds():
> - * Native method to return the CPU time consumed by the process,
> - * in milliseconds, from an arbitrary initial time.
> - */
> - public static native int get_user_cpu_milliseconds();
> -}
> diff --git a/library/Mmakefile b/library/Mmakefile
> index 99f88bc..61933b6 100644
> --- a/library/Mmakefile
> +++ b/library/Mmakefile
> @@ -428,12 +428,6 @@ $(RT_LIB_NAME).jar: copy_java_runtime_files
> $(JAVAC) $(ALL_JAVACFLAGS) jmercury/runtime/*.java
> $(JAR) $(JAR_CREATE_FLAGS) $(RT_LIB_NAME).jar jmercury/runtime/*.class
> $(JAR) i $(RT_LIB_NAME).jar
> - # -+cd jmercury/runtime && mmake $(NATIVE_SO)
> - # -cp jmercury/runtime/$(NATIVE_SO) .
> -
> -# This shared object was used to implement some standard library methods,
> -# but currently not.
> -NATIVE_SO = Native.$(EXT_FOR_SHARED_LIB)
>
> #-----------------------------------------------------------------------------#
>
> @@ -566,7 +560,7 @@ realclean_local:
> rm -rf jmercury
> rm -f mr_int.class mr_float.class mr_char.class
> rm -f mr_int\$$*.class mr_float\$$*.class mr_char\$$*.class
> - rm -f $(STD_LIB_NAME).jar $(RT_LIB_NAME).jar $(NATIVE_SO)
> + rm -f $(STD_LIB_NAME).jar $(RT_LIB_NAME).jar
>
> #-----------------------------------------------------------------------------#
More information about the reviews
mailing list