Files
mercury/java/runtime/Native.c
James Goddard 1e8afc7bee Implement some library predicates for Java using JNI.
Estimated hours taken: 13
Branches: main

Implement some library predicates for Java using JNI.

java/runtime/Native.java.in:
	A new class which uses JNI to provide any native functionality
	required by predicates of the standard library in Java.
	So far it only provides methods relating to timing.

java/runtime/Native.c:
	Source code, written in C, which implements all the native methods of
	mercury.runtime.Native.  Note that this implementation makes use of the
	existing C implementation of the equivalent functions.

java/runtime/Mmakefile:
	Rules for compiling a shared object from Native.c.

library/time.m:
	Implement the following predicates for Java using Native interface:
		time__c_clock/3
		time__clocks_per_sec/1
		time__times/7

library/benchmarking.m:
	Implement the following predicates for Java using Native interface:
		get_user_cpu_miliseconds/1

library/Mmakefile:
	Renamed to library/Mmakefile.in, so as to have access to FULLARCH
	constant.

library/Mmakefile.in:
	Added rules for incorporating the Native shared object.
2004-02-05 03:56:05 +00:00

100 lines
2.1 KiB
C

/*
** Copyright (C) 2004 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
/*
** File: Native.c - Native code for java/runtime/Native.java
*/
#include <jni.h>
/*
* Class: Native
* Method: clock
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_mercury_runtime_Native_clock(JNIEnv *, jclass);
/*
* Class: Native
* Method: clocks_per_sec
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_mercury_runtime_Native_clocks_1per_1sec(
JNIEnv *, jclass);
/*
* Class: Native
* Method: times
* Signature: ()[I
*/
JNIEXPORT jintArray JNICALL Java_mercury_runtime_Native_times(
JNIEnv *, jclass);
/*
* Class: Native
* Method: get_user_cpu_miliseconds
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_mercury_runtime_Native_get_1user_1cpu_1miliseconds(
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_mercury_runtime_Native_clock(JNIEnv *env, jclass obj) {
return (MR_Integer) clock();
}
JNIEXPORT jint JNICALL
Java_mercury_runtime_Native_clocks_1per_1sec(JNIEnv *env, jclass obj) {
return CLOCKS_PER_SEC;
}
JNIEXPORT jintArray JNICALL
Java_mercury_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_mercury_runtime_Native_get_1user_1cpu_1miliseconds(
JNIEnv *env, jclass obj)
{
return MR_get_user_cpu_miliseconds();
}