From ce9cbf0e2aea0198cb08a735a3ad36c6471f5468 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 25 Feb 2017 08:47:15 +0100 Subject: [PATCH] useless cleanups to the Java bindings --- src/bindings/java/JavaContext.cpp | 13 +- src/bindings/java/JavaContext.hpp | 13 +- src/bindings/java/jmsg.cpp | 9 +- src/bindings/java/jmsg.h | 28 ++- src/bindings/java/jmsg_as.cpp | 39 ++--- src/bindings/java/jmsg_as.h | 32 ++-- src/bindings/java/jmsg_comm.cpp | 5 +- src/bindings/java/jmsg_comm.h | 17 +- src/bindings/java/jmsg_file.cpp | 5 +- src/bindings/java/jmsg_file.h | 14 +- src/bindings/java/jmsg_host.cpp | 28 +-- src/bindings/java/jmsg_host.h | 183 +++----------------- src/bindings/java/jmsg_process.cpp | 64 +++---- src/bindings/java/jmsg_process.h | 248 ++++----------------------- src/bindings/java/jmsg_rngstream.cpp | 7 +- src/bindings/java/jmsg_rngstream.h | 32 ++-- src/bindings/java/jmsg_storage.cpp | 15 +- src/bindings/java/jmsg_storage.h | 125 ++------------ src/bindings/java/jmsg_synchro.cpp | 5 +- src/bindings/java/jmsg_synchro.h | 7 +- src/bindings/java/jmsg_task.cpp | 59 +++---- src/bindings/java/jmsg_task.h | 197 +-------------------- src/bindings/java/jmsg_vm.cpp | 12 +- src/bindings/java/jmsg_vm.h | 5 +- src/bindings/java/jtrace.cpp | 10 +- src/bindings/java/jtrace.h | 14 +- src/bindings/java/jxbt_utilities.cpp | 8 +- src/bindings/java/jxbt_utilities.h | 3 +- 28 files changed, 266 insertions(+), 931 deletions(-) diff --git a/src/bindings/java/JavaContext.cpp b/src/bindings/java/JavaContext.cpp index 6298d26cf5..ba70dde478 100644 --- a/src/bindings/java/JavaContext.cpp +++ b/src/bindings/java/JavaContext.cpp @@ -1,7 +1,6 @@ -/* context_java - implementation of context switching for java threads */ +/* Context switching within the JVM. */ -/* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -12,13 +11,9 @@ #include "JavaContext.hpp" #include "jxbt_utilities.h" #include "src/simix/smx_private.h" -#include "xbt/dynar.h" -#include -#include -#include -#include +#include "xbt/ex.hpp" -extern JavaVM *__java_vm; +extern "C" JavaVM* __java_vm; XBT_LOG_NEW_DEFAULT_CATEGORY(jmsg, "MSG for Java(TM)"); diff --git a/src/bindings/java/JavaContext.hpp b/src/bindings/java/JavaContext.hpp index a1a7ba16e6..d0d6a4e713 100644 --- a/src/bindings/java/JavaContext.hpp +++ b/src/bindings/java/JavaContext.hpp @@ -1,5 +1,6 @@ -/* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team. - * All rights reserved. */ +/* Context switching within the JVM. */ + +/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -8,17 +9,13 @@ #define SIMGRID_JAVA_JAVA_CONTEXT_HPP #include - #include -#include -#include -#include - +#include "simgrid/simix.h" #include "src/simix/smx_private.h" +#include "xbt/xbt_os_thread.h" #include "jmsg.h" -#include "jmsg_process.h" namespace simgrid { namespace kernel { diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 41db649cc2..944919d0ff 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -1,7 +1,6 @@ /* Java Wrappers to the MSG API. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -187,17 +186,17 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv * env, jclass cls) { msg_netzone_t as = MSG_environment_get_routing_root(); - jobject jas = jas_new_instance(env); + jobject jas = jnetzone_new_instance(env); if (!jas) { jxbt_throw_jni(env, "java As instantiation failed"); return nullptr; } - jas = jas_ref(env, jas); + jas = jnetzone_ref(env, jas); if (!jas) { jxbt_throw_jni(env, "new global ref allocation failed"); return nullptr; } - jas_bind(jas, as, env); + jnetzone_bind(jas, as, env); return (jobject) jas; } diff --git a/src/bindings/java/jmsg.h b/src/bindings/java/jmsg.h index deba4ac89f..df0868d527 100644 --- a/src/bindings/java/jmsg.h +++ b/src/bindings/java/jmsg.h @@ -1,7 +1,6 @@ /* Java Wrappers to the MSG API. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -13,6 +12,15 @@ SG_BEGIN_DECL() +/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ +#ifndef JNIEXPORT +#define JNIEXPORT +#endif +#ifndef JNICALL +#define JNICALL +#endif +/* end of eclipse-mandated pimple */ + extern int JAVA_HOST_LEVEL; extern int JAVA_STORAGE_LEVEL; @@ -23,33 +31,17 @@ JNIEnv *get_current_thread_env(); */ void jmsg_throw_status(JNIEnv *env, msg_error_t status); -/* - * Class org_simgrid_msg_Msg - * Method getClock - * Signature ()D - */ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Msg_getClock(JNIEnv *, jclass); - -/** - * Class org_simgrid_msg_Msg - * Method run - */ JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass cls); JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs); - JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit(); JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_debug(JNIEnv *, jclass, jstring); - JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_verb(JNIEnv *, jclass, jstring); - JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_info(JNIEnv *, jclass, jstring); - JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_warn(JNIEnv *, jclass, jstring); - JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_error(JNIEnv *, jclass, jstring); - JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_critical(JNIEnv *, jclass, jstring); JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls, jstring jplatformFile); diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index 1fefe77df5..8124ac4a15 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -1,19 +1,13 @@ -/* Functions related to the java host instances. */ +/* Java bindings of the NetZones. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include -#include - #include "simgrid/s4u/NetZone.hpp" -#include +#include "simgrid/s4u/host.hpp" -#include "simgrid/msg.h" #include "jmsg_as.h" #include "jmsg_host.h" #include "jxbt_utilities.h" @@ -26,25 +20,28 @@ SG_BEGIN_DECL() static jmethodID jas_method_As_constructor; static jfieldID jas_field_As_bind; -jobject jas_new_instance(JNIEnv * env) { +jobject jnetzone_new_instance(JNIEnv* env) +{ jclass cls = jxbt_get_class(env, "org/simgrid/msg/As"); return env->NewObject(cls, jas_method_As_constructor); } -jobject jas_ref(JNIEnv * env, jobject jas) { +jobject jnetzone_ref(JNIEnv* env, jobject jas) +{ return env->NewGlobalRef(jas); } -void jas_unref(JNIEnv * env, jobject jas) { +void jnetzone_unref(JNIEnv* env, jobject jas) +{ env->DeleteGlobalRef(jas); } -void jas_bind(jobject jas, simgrid::s4u::NetZone* netzone, JNIEnv* env) +void jnetzone_bind(jobject jas, simgrid::s4u::NetZone* netzone, JNIEnv* env) { env->SetLongField(jas, jas_field_As_bind, (jlong)(uintptr_t)(netzone)); } -simgrid::s4u::NetZone* jas_get_native(JNIEnv* env, jobject jas) +simgrid::s4u::NetZone* jnetzone_get_native(JNIEnv* env, jobject jas) { return (simgrid::s4u::NetZone*)(uintptr_t)env->GetLongField(jas, jas_field_As_bind); } @@ -59,7 +56,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_As_nativeInit(JNIEnv* env, jclass cl } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) { - simgrid::s4u::NetZone* as = jas_get_native(env, jas); + simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas); return env->NewStringUTF(as->name()); } @@ -68,7 +65,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, job jobjectArray jtable; jobject tmp_jas; simgrid::s4u::NetZone* tmp_as; - simgrid::s4u::NetZone* self_as = jas_get_native(env, jas); + simgrid::s4u::NetZone* self_as = jnetzone_get_native(env, jas); xbt_dict_t dict = self_as->children(); int count = xbt_dict_length(dict); @@ -88,17 +85,17 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, job char *key; xbt_dict_foreach(dict,cursor,key,tmp_as) { - tmp_jas = jas_new_instance(env); + tmp_jas = jnetzone_new_instance(env); if (!tmp_jas) { jxbt_throw_jni(env, "java As instantiation failed"); return nullptr; } - tmp_jas = jas_ref(env, tmp_jas); + tmp_jas = jnetzone_ref(env, tmp_jas); if (!tmp_jas) { jxbt_throw_jni(env, "new global ref allocation failed"); return nullptr; } - jas_bind(tmp_jas, tmp_as, env); + jnetzone_bind(tmp_jas, tmp_as, env); env->SetObjectArrayElement(jtable, index, tmp_jas); index++; @@ -107,7 +104,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, job } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) { - simgrid::s4u::NetZone* as = jas_get_native(env, jas); + simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas); if (!as) { jxbt_throw_notbound(env, "as", jas); @@ -133,7 +130,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo jobject jhost; jstring jname; msg_host_t host; - simgrid::s4u::NetZone* as = jas_get_native(env, jas); + simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas); xbt_dynar_t table = as->hosts(); int count = xbt_dynar_length(table); diff --git a/src/bindings/java/jmsg_as.h b/src/bindings/java/jmsg_as.h index aeac8bab4c..8e5f65e4ef 100644 --- a/src/bindings/java/jmsg_as.h +++ b/src/bindings/java/jmsg_as.h @@ -1,7 +1,6 @@ -/* Functions related to the java As instances. */ +/* Functions related to the java As instances. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -13,21 +12,26 @@ SG_BEGIN_DECL() -jobject jas_new_instance(JNIEnv * env); -jobject jas_ref(JNIEnv * env, jobject jas); -void jas_unref(JNIEnv * env, jobject jas); -void jas_bind(jobject jas, msg_netzone_t as, JNIEnv* env); -simgrid::s4u::NetZone* jas_get_native(JNIEnv* env, jobject jas); +/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ +#ifndef JNIEXPORT +#define JNIEXPORT +#endif +#ifndef JNICALL +#define JNICALL +#endif +/* end of eclipse-mandated pimple */ + +jobject jnetzone_new_instance(JNIEnv* env); +jobject jnetzone_ref(JNIEnv* env, jobject jnetzone); +void jnetzone_unref(JNIEnv* env, jobject jnetzone); +void jnetzone_bind(jobject jas, msg_netzone_t as, JNIEnv* env); +simgrid::s4u::NetZone* jnetzone_get_native(JNIEnv* env, jobject jnetzone); JNIEXPORT void JNICALL Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls); - JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas); - -JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas); - +JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv* env, jobject jnetzone); JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jhost, jobject jname); - -JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas); +JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv* env, jobject jnetzone); SG_END_DECL() #endif /*!MSG_JAS_H */ diff --git a/src/bindings/java/jmsg_comm.cpp b/src/bindings/java/jmsg_comm.cpp index fa87558994..772b40d8ed 100644 --- a/src/bindings/java/jmsg_comm.cpp +++ b/src/bindings/java/jmsg_comm.cpp @@ -1,7 +1,6 @@ -/* Functions related to the java comm instances */ +/* Java bindings to the Comm API */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ diff --git a/src/bindings/java/jmsg_comm.h b/src/bindings/java/jmsg_comm.h index 7df257c5c7..a727c2f6a9 100644 --- a/src/bindings/java/jmsg_comm.h +++ b/src/bindings/java/jmsg_comm.h @@ -1,18 +1,27 @@ -/* Functions related to the java comm instances */ +/* Java bindings to the Comm API */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #ifndef MSG_JCOMM_H #define MSG_JCOMM_H + +#include "simgrid/msg.h" #include -#include SG_BEGIN_DECL() +/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ +#ifndef JNIEXPORT +#define JNIEXPORT +#endif +#ifndef JNICALL +#define JNICALL +#endif +/* end of eclipse-mandated pimple */ + /** This function binds the task associated with the communication to the java communication object. */ void jcomm_bind_task(JNIEnv *env, jobject jcomm); diff --git a/src/bindings/java/jmsg_file.cpp b/src/bindings/java/jmsg_file.cpp index 5b203d9b98..8243f6ab5c 100644 --- a/src/bindings/java/jmsg_file.cpp +++ b/src/bindings/java/jmsg_file.cpp @@ -1,7 +1,6 @@ -/* Functions related to the java file API. */ +/* Java bindings of the file API. */ -/* Copyright (c) 2012-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2015. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ diff --git a/src/bindings/java/jmsg_file.h b/src/bindings/java/jmsg_file.h index dcd96e9c21..d4b509e254 100644 --- a/src/bindings/java/jmsg_file.h +++ b/src/bindings/java/jmsg_file.h @@ -1,7 +1,6 @@ -/* Functions related to the java file API. */ +/* Java bindings of the file API. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2015. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -13,6 +12,15 @@ SG_BEGIN_DECL() +/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ +#ifndef JNIEXPORT +#define JNIEXPORT +#endif +#ifndef JNICALL +#define JNICALL +#endif +/* end of eclipse-mandated pimple */ + jfieldID jfile_field_bind; void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t fd); diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 8211551449..cecd8a2017 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -1,21 +1,13 @@ /* Functions related to the java host instances. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include -#include -#include - -#include - -#include +#include "simgrid/plugins/energy.h" +#include "simgrid/s4u/host.hpp" -#include "simgrid/msg.h" #include "jmsg.h" #include "jmsg_host.h" #include "jxbt_utilities.h" @@ -50,19 +42,6 @@ msg_host_t jhost_get_native(JNIEnv * env, jobject jhost) { return (msg_host_t) (uintptr_t) env->GetLongField(jhost, jhost_field_Host_bind); } -const char *jhost_get_name(jobject jhost, JNIEnv * env) { - msg_host_t host = jhost_get_native(env, jhost); - return host->cname(); -} - -jboolean jhost_is_valid(jobject jhost, JNIEnv * env) { - if (env->GetLongField(jhost, jhost_field_Host_bind)) { - return JNI_TRUE; - } else { - return JNI_FALSE; - } -} - JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls) { jclass class_Host = env->FindClass("org/simgrid/msg/Host"); jhost_method_Host_constructor = env->GetMethodID(class_Host, "", "()V"); @@ -368,7 +347,6 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, j env->ReleaseStringUTFChars((jstring) jname, name); } -#include "simgrid/plugins/energy.h" JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); diff --git a/src/bindings/java/jmsg_host.h b/src/bindings/java/jmsg_host.h index 461d69cc30..deebb1641f 100644 --- a/src/bindings/java/jmsg_host.h +++ b/src/bindings/java/jmsg_host.h @@ -1,7 +1,6 @@ /* Functions related to the java host instances. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -14,186 +13,50 @@ SG_BEGIN_DECL() -/** - * This function returns a new java host instance. - * - * @param env The environment of the current thread - * - * @return A new java host object. - * - * @exception If the class Host is not found the function throws the ClassNotFoundException. If the constructor of - * this class is not found the function throws the exception NotSuchMethodException. - */ +/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ +#ifndef JNIEXPORT +#define JNIEXPORT +#endif +#ifndef JNICALL +#define JNICALL +#endif +/* end of eclipse-mandated pimple */ + +/** Returns a new java instance of an host. */ jobject jhost_new_instance(JNIEnv * env); -/** - * This function returns a global reference to the java host instance specified by the parameter jhost. - * - * @param jhost The original java host instance. - * @param env The environment of the current thread - * - * @return The global reference to the original java host instance. - */ +/** Take a ref onto the java instance (to prevent its collection) */ jobject jhost_ref(JNIEnv * env, jobject jhost); -/** - * This function delete a global reference to a java host instance. - * - * @param The global refernce to delete. - * @param env The environment of the current thread - */ +/** Release a ref onto the java instance */ void jhost_unref(JNIEnv * env, jobject jhost); -/** - * This function associated a native host to a java host instance. - * - * @param jhost The java host instance. - * @param host The native host to bind. - * @param env The environment of the current thread - * - * @exception If the class Host is not found the function throws the ClassNotFoundException. If the field bind of - * this class is not found the function throws the exception NotSuchFieldException. - */ +/** Binds a native instance to a java instance. */ void jhost_bind(jobject jhost, msg_host_t host, JNIEnv * env); -/** - * This function returns a native host from a java host instance. - * - * @param jhost The java host object from which get the native host. - * @param env The environment of the current thread - * - * @return The function returns the native host associated to the java host object. - * - * @exception If the class Host is not found the function throws the ClassNotFoundException. If the field bind of - * this class is not found the function throws the exception NotSuchFieldException. - */ +/** Extracts the native instance associated to a java instance. */ msg_host_t jhost_get_native(JNIEnv * env, jobject jhost); -/** - * This function returns the name of a MSG host. - * - * @param jhost A java host object. - * @param env The environment of the current thread - * - * @return The name of the host. - */ -const char *jhost_get_name(jobject jhost, JNIEnv * env); - -/** - * This function tests if a java host instance is valid. - * A java host object is valid if it is bind to a native host. - * - * @param jhost The host to test the validity. - * @param env The environment of the current thread - * - * @return If the java host is valid the function returns true. Otherwise the function returns false. - */ -jboolean jhost_is_valid(jobject jhost, JNIEnv * env); - -/* - * Class org_simgrid_msg_Host - * Method nativeInit - * Signature (); - */ +/** Initialize the native world, called from the Java world at startup */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls); -/* - * Class org_simgrid_msg_Host - * Method getByName - * Signature (Ljava/lang/String;)Lsimgrid/msg/Host; - */ -JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName (JNIEnv *env, jclass cls, jstring jname); - -/** - * This function start the host if it is off - * - * @param jhost The host to test the validity. - * @param env The environment of the current thread - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_on(JNIEnv *env, jobject jhost); - -/** - * This function stop the host if it is on - * - * @param jhost The host to test the validity. - * @param env The environment of the current thread - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost); - -/* - * Class org_simgrid_msg_Host - * Method currentHost - * Signature ()Lsimgrid/msg/Host; - */ -JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost (JNIEnv *env, jclass cls); - -/* - * Class org_simgrid_msg_Host - * Method getCount - * Signature ()I - */ +/* Implement the Java API */ + +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv* env, jclass cls, jstring jname); +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv* env, jclass cls); JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount (JNIEnv *env, jclass cls); -/* - * Class org_simgrid_msg_Host - * Method getSpeed - * Signature ()D - */ +JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_on(JNIEnv* env, jobject jhost); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv* env, jobject jhost); +JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv* env, jobject jhost); JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed (JNIEnv *env, jobject jhost); - -/* - * Class org_simgrid_msg_Host - * Method getCoreNumber - * Signature ()D - */ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber (JNIEnv *env, jobject jhost); - -/* - * Class org_simgrid_msg_Host - * Method getProperty - * Signature (Ljava/lang/String;)Ljava/lang/String; - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname); - -/* - * Class org_simgrid_msg_Host - * Method setProperty - * Signature (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jobject jvalue); - -/* - * Class org_simgrid_msg_Host - * Method isOn - * Signature ()Z - */ -JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn (JNIEnv *env, jobject jhost); - -/* - * Class org_simgrid_msg_Host - * Method getMountedStorage - * Signature: ()[Lorg/simgrid/msg/Storage; - */ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost); - -/* - * Class org_simgrid_msg_Host - * Method getAttachedStorageList - */ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIEnv * env, jobject jhost); - -/* - * Class org_simgrid_msg_Host - * Method getStorageContent - */ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getStorageContent(JNIEnv * env, jobject jhost); - -/** - * Class org_simgrid_msg_Host - * Method all - */ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv *env, jclass cls); - JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, jclass cls_arg, jobject jname); JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost); diff --git a/src/bindings/java/jmsg_process.cpp b/src/bindings/java/jmsg_process.cpp index 9d62ccf6f6..6862679d2d 100644 --- a/src/bindings/java/jmsg_process.cpp +++ b/src/bindings/java/jmsg_process.cpp @@ -1,7 +1,6 @@ /* Functions related to the java process instances. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -22,35 +21,28 @@ SG_BEGIN_DECL() jfieldID jprocess_field_Process_bind; jfieldID jprocess_field_Process_host; jfieldID jprocess_field_Process_killTime; -jfieldID jprocess_field_Process_id; +// jfieldID jprocess_field_Process_id; jfieldID jprocess_field_Process_name; jfieldID jprocess_field_Process_pid; jfieldID jprocess_field_Process_ppid; -jobject native_to_java_process(msg_process_t process) +jobject jprocess_from_native(msg_process_t process) { simgrid::kernel::context::JavaContext* context = (simgrid::kernel::context::JavaContext*) MSG_process_get_smx_ctx(process); return context->jprocess; } -jobject jprocess_new_global_ref(jobject jprocess, JNIEnv * env) +jobject jprocess_ref(jobject jprocess, JNIEnv* env) { return env->NewGlobalRef(jprocess); } -void jprocess_delete_global_ref(jobject jprocess, JNIEnv * env) +void jprocess_unref(jobject jprocess, JNIEnv* env) { env->DeleteGlobalRef(jprocess); } -void jprocess_join(jobject jprocess, JNIEnv * env) -{ - msg_process_t process = jprocess_to_native_process(jprocess,env); - simgrid::kernel::context::JavaContext* context = (simgrid::kernel::context::JavaContext*) MSG_process_get_smx_ctx(process); - xbt_os_thread_join(context->thread,nullptr); -} - -msg_process_t jprocess_to_native_process(jobject jprocess, JNIEnv * env) +msg_process_t jprocess_to_native(jobject jprocess, JNIEnv* env) { return (msg_process_t)(intptr_t)env->GetLongField(jprocess, jprocess_field_Process_bind); } @@ -60,40 +52,24 @@ void jprocess_bind(jobject jprocess, msg_process_t process, JNIEnv * env) env->SetLongField(jprocess, jprocess_field_Process_bind, (intptr_t)process); } -jlong jprocess_get_id(jobject jprocess, JNIEnv * env) -{ - return (intptr_t)env->GetLongField(jprocess, jprocess_field_Process_id); -} - jstring jprocess_get_name(jobject jprocess, JNIEnv * env) { jstring jname = (jstring) env->GetObjectField(jprocess, jprocess_field_Process_name); return (jstring) env->NewGlobalRef(jname); } -jboolean jprocess_is_valid(jobject jprocess, JNIEnv * env) -{ - jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Process", "bind", "J"); - - if (!id) - return JNI_FALSE; - - return env->GetLongField(jprocess, id) ? JNI_TRUE : JNI_FALSE; -} - JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) { jclass jprocess_class_Process = env->FindClass("org/simgrid/msg/Process"); xbt_assert(jprocess_class_Process, "Native initialization of msg/Process failed. Please report that bug"); jprocess_field_Process_name = jxbt_get_jfield(env, jprocess_class_Process, "name", "Ljava/lang/String;"); jprocess_field_Process_bind = jxbt_get_jfield(env, jprocess_class_Process, "bind", "J"); - jprocess_field_Process_id = jxbt_get_jfield(env, jprocess_class_Process, "id", "J"); jprocess_field_Process_pid = jxbt_get_jfield(env, jprocess_class_Process, "pid", "I"); jprocess_field_Process_ppid = jxbt_get_jfield(env, jprocess_class_Process, "ppid", "I"); jprocess_field_Process_host = jxbt_get_jfield(env, jprocess_class_Process, "host", "Lorg/simgrid/msg/Host;"); jprocess_field_Process_killTime = jxbt_get_jfield(env, jprocess_class_Process, "killTime", "D"); - xbt_assert(jprocess_field_Process_id && jprocess_field_Process_name && jprocess_field_Process_pid && - jprocess_field_Process_ppid && jprocess_field_Process_host, + xbt_assert(jprocess_field_Process_name && jprocess_field_Process_pid && jprocess_field_Process_ppid && + jprocess_field_Process_host, "Native initialization of msg/Process failed. Please report that bug"); } @@ -125,7 +101,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject } /* create a global java process instance */ - jprocess = jprocess_new_global_ref(jprocess_arg, env); + jprocess = jprocess_ref(jprocess_arg, env); if (!jprocess) { jxbt_throw_jni(env, "Can't get a global ref to the java process"); return; @@ -181,7 +157,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jcl return nullptr; } - jobject jprocess = native_to_java_process(process); + jobject jprocess = jprocess_from_native(process); if (!jprocess) { jxbt_throw_jni(env, "get process failed"); @@ -192,7 +168,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jcl } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); @@ -222,7 +198,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getCurrentProcess(JNIEnv return nullptr; } - jprocess = native_to_java_process(process); + jprocess = jprocess_from_native(process); if (!jprocess) jxbt_throw_jni(env, xbt_strdup("SIMIX_process_get_jprocess() failed")); @@ -232,7 +208,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getCurrentProcess(JNIEnv JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_suspend(JNIEnv * env, jobject jprocess) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); @@ -247,7 +223,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_suspend(JNIEnv * env, jobjec JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_resume(JNIEnv * env, jobject jprocess) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); @@ -261,7 +237,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_resume(JNIEnv * env, jobject } JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setAutoRestart (JNIEnv *env, jobject jprocess, jboolean jauto_restart) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); xbt_ex_t e; int auto_restart = jauto_restart == JNI_TRUE ? 1 : 0; @@ -280,7 +256,7 @@ JNICALL Java_org_simgrid_msg_Process_setAutoRestart (JNIEnv *env, jobject jproce } JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart (JNIEnv *env, jobject jprocess) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); xbt_ex_t e; if (!process) { @@ -298,7 +274,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart (JNIEnv *env, jobjec } JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env, jobject jprocess) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); @@ -343,7 +319,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobjec JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv * env, jobject jprocess) { /* get the native instances from the java ones */ - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); return; @@ -358,7 +334,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv * env, jobject j JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate(JNIEnv * env, jobject jprocess, jobject jhost) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); @@ -388,7 +364,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_yield(JNIEnv* env, jclass cl } JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , jobject jprocess, jdouble jkilltime) { - msg_process_t process = jprocess_to_native_process(jprocess, env); + msg_process_t process = jprocess_to_native(jprocess, env); MSG_process_set_kill_time(process, (double)jkilltime); } diff --git a/src/bindings/java/jmsg_process.h b/src/bindings/java/jmsg_process.h index 3c4bf5f868..c05c176bd0 100644 --- a/src/bindings/java/jmsg_process.h +++ b/src/bindings/java/jmsg_process.h @@ -1,7 +1,6 @@ /* Functions related to the java process instances. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -9,9 +8,8 @@ #ifndef MSG_JPROCESS_H #define MSG_JPROCESS_H +#include "simgrid/msg.h" #include -#include -#include SG_BEGIN_DECL(); @@ -24,225 +22,49 @@ SG_BEGIN_DECL(); #endif /* end of eclipse-mandated pimple */ -//Cached java fields -extern jfieldID jprocess_field_Process_bind; -extern jfieldID jprocess_field_Process_host; -extern jfieldID jprocess_field_Process_killTime; -extern jfieldID jprocess_field_Process_id; -extern jfieldID jprocess_field_Process_name; +// Cached java fields accessed by the rest of the code (FIXME: they should not) extern jfieldID jprocess_field_Process_pid; extern jfieldID jprocess_field_Process_ppid; -jobject native_to_java_process(msg_process_t process); - -/** - * This function returns a global reference to the java process instance specified by the parameter jprocess. - * - * @param jprocess The original java process instance. - * @param env The env of the current thread - * - * @return The global reference to the original java process instance. - */ -jobject jprocess_new_global_ref(jobject jprocess, JNIEnv * env); - -/** - * This function delete a global reference to a java process instance. - * If the java process is alive the function joins it and stops it before. - * - * @param jprocess The global refernce to delete. - * @param env The env of the current thread - * - * @see jprocess_join() - * @see jprocess_exit() - */ -void jprocess_delete_global_ref(jobject jprocess, JNIEnv * env); - -/** - * This function waits for a java process to terminate. - * - * @param jprocess The java process to wait for. - * @param env The env of the current thread - * - * @exception If the class Process is not found the function throws the ClassNotFoundException. If the method - join() of this class is not found the function throws the exception NotSuchMethodException. - */ -void jprocess_join(jobject jprocess, JNIEnv * env); - -/** - * This function associated a native process to a java process instance. - * - * @param jprocess The java process instance. - * @param process The native process to bind. - * @param env The env of the current thread - * - * @exception If the class Process is not found the function throws the ClassNotFoundException. If the field - * bind of this class is not found the function throws the exception NotSuchFieldException. - */ +/** Take a ref onto the java instance (to prevent its collection) */ +jobject jprocess_ref(jobject jprocess, JNIEnv* env); + +/** Release a ref onto the java instance */ +void jprocess_unref(jobject jprocess, JNIEnv* env); + +/** Binds a native instance to a java instance. */ void jprocess_bind(jobject jprocess, msg_process_t process, JNIEnv * env); -/** - * This function returns a native process from a java process instance. - * - * @param jprocess The java process object from which get the native process. - * @param env The env of the current thread - * - * @return The function returns the native process associated to the java process object. - * - * @exception If the class Process is not found the function throws the ClassNotFoundException. If the field - * bind of this class is not found the function throws the exception NotSuchFieldException. - */ -msg_process_t jprocess_to_native_process(jobject jprocess, JNIEnv * env); - -/** - * This function gets the id of the specified java process. - * - * @param jprocess The java process to get the id. - * @param env The env of the current thread - * - * @exception If the class Process is not found the function throws the ClassNotFoundException. If the field id - * of this class is not found the function throws the exception NotSuchFieldException. - * - * @return The id of the specified java process. - */ -jlong jprocess_get_id(jobject jprocess, JNIEnv * env); - -/** - * This function tests if a java process instance is valid. - * A java process object is valid if it is bind to a native process. - * - * @param jprocess The java process to test the validity. - * @param env The env of the current thread - * - * @return If the java process is valid the function returns true. Otherwise the function returns false. - */ -jboolean jprocess_is_valid(jobject jprocess, JNIEnv * env); - -/** - * This function gets the name of the specified java process. - * - * @param jprocess The java process to get the name. - * @param env The env of the current thread - * - * @exception If the class Process is not found the function throws the ClassNotFoundException. If the field name - * of this class is not found the function throws the exception NotSuchFieldException. - * - * @return The name of the specified java process. - */ +/** Extract the java instance from the native one */ +jobject jprocess_from_native(msg_process_t process); + +/** Extract the native instance from the java one */ +msg_process_t jprocess_to_native(jobject jprocess, JNIEnv* env); + +/** Get the name of a java instance. */ jstring jprocess_get_name(jobject jprocess, JNIEnv * env); -/* - * Class org_simgrid_msg_Process - * Method nativeInit - * Signature (); - */ +/** Initialize the native world, called from the Java world at startup */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls); -/* - * Class org_simgrid_msg_Process - * Method create - * Signature (Lorg/simgrid/msg/Host;)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject jprocess_arg, jobject jhostname); - -/* - * Class org_simgrid_msg_Process - * Method killAll - * Signature (I)I - */ -JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll (JNIEnv *, jclass, jint); - -/* - * Class org_simgrid_msg_Process - * Method fromPID - * Signature (I)Lorg/simgrid/msg/Process; - */ -JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID (JNIEnv *, jclass, jint); - -/* - * Class org_simgrid_msg_Process - * Method getProperty - * Signature (D)V - */ -JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname); - -/* - * Class org_simgrid_msg_Process - * Method currentProcess - * Signature ()Lorg/simgrid/msg/Process; - */ -JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getCurrentProcess (JNIEnv *, jclass); - -/* - * Class org_simgrid_msg_Process - * Method suspend - * Signature (Lorg/simgrid/msg/Process;)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_suspend(JNIEnv * env, jobject jprocess); - -/* - * Class org_simgrid_msg_Process - * Method resume - * Signature (Lorg/simgrid/msg/Process;)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_resume (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Process - * Method setAutoRestart - * Signature (Lorg/simgrid/msg/Process;Z)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setAutoRestart (JNIEnv *, jobject, jboolean); - -/* - * Class org_simgrid_msg_Process - * Method restart - * Signature (Lorg/simgrid/msg/Process;)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Process - * Method isSuspended - * Signature (Lorg/simgrid/msg/Process;)Z - */ -JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Process_isSuspended (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Process - * Method sleep - * Signature (DI)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep (JNIEnv *, jclass, jlong, jint); - -/* - * Class org_simgrid_msg_Process - * Method waitFor - * Signature (D)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor (JNIEnv *, jobject, jdouble); - -/* - * Class org_simgrid_msg_Process - * Method kill - * Signature (Lorg/simgrid/msg/Process;)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Process - * Method migrate - * Signature (Lorg/simgrid/msg/Host;)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate (JNIEnv *, jobject, jobject); - +/* Implement the Java API */ + +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv* env, jobject jprocess_arg, jobject jhostname); +JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll(JNIEnv* env, jclass, jint); +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv* env, jclass, jint); +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv* env, jobject jprocess, jobject jname); +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getCurrentProcess(JNIEnv* env, jclass); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_suspend(JNIEnv* env, jobject jprocess); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_resume(JNIEnv* env, jobject jprocess); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setAutoRestart(JNIEnv* env, jobject jprocess, jboolean); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart(JNIEnv* env, jobject jprocess); +JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Process_isSuspended(JNIEnv* env, jobject jprocess); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv* env, jclass, jlong, jint); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor(JNIEnv* env, jobject jprocess, jdouble); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv* env, jobject jprocess); +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate(JNIEnv* env, jobject jprocess, jobject); JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_yield(JNIEnv* env, jclass cls); -/* - * Class org_simgrid_msg_Process - * Method setKillTime - * Signature (D)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime (JNIEnv *, jobject, jdouble); - +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime(JNIEnv* env, jobject jprocess, jdouble); JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclass cls); SG_END_DECL(); diff --git a/src/bindings/java/jmsg_rngstream.cpp b/src/bindings/java/jmsg_rngstream.cpp index 08bccc4c45..aa1a05013f 100644 --- a/src/bindings/java/jmsg_rngstream.cpp +++ b/src/bindings/java/jmsg_rngstream.cpp @@ -1,12 +1,11 @@ -/* Functions related to the RngStream Java port */ +/* Java binding of the RngStream library */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include +#include "xbt/sysdep.h" #include "jmsg_rngstream.h" #include "jxbt_utilities.h" diff --git a/src/bindings/java/jmsg_rngstream.h b/src/bindings/java/jmsg_rngstream.h index b7c28c4a39..0cc952d4eb 100644 --- a/src/bindings/java/jmsg_rngstream.h +++ b/src/bindings/java/jmsg_rngstream.h @@ -1,43 +1,41 @@ -/* Functions related to the RngStream Java port */ +/* Java binding of the RngStream library */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #ifndef MSG_RNGSTREAM_H #define MSG_RNGSTREAM_H + +#include "xbt/RngStream.h" #include -#include SG_BEGIN_DECL() +/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ +#ifndef JNIEXPORT +#define JNIEXPORT +#endif +#ifndef JNICALL +#define JNICALL +#endif +/* end of eclipse-mandated pimple */ + RngStream jrngstream_to_native(JNIEnv *env, jobject jrngstream); JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeInit(JNIEnv *env, jclass cls); - JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_create(JNIEnv *env, jobject jrngstream, jstring name); - JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream); - -JNIEXPORT jboolean JNICALL -Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv *env, jobject jrngstream, jintArray seed); - +JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv* env, jobject jrngstream, + jintArray seed); JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetStart(JNIEnv *env, jobject jrngstream); - JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetStartSubstream(JNIEnv *env, jobject jrngstream); - JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetNextSubstream(JNIEnv *env, jobject jrngstream); - JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_setAntithetic(JNIEnv *env, jobject jrngstream, jboolean ja); - JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setSeed(JNIEnv *env, jobject jrngstream, jintArray jseed); - JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_advanceState(JNIEnv *env, jobject jrngstream, jint e, jint g); - JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_RngStream_randU01(JNIEnv *env, jobject jrngstream); - JNIEXPORT jint JNICALL Java_org_simgrid_msg_RngStream_randInt(JNIEnv *env, jobject jrngstream, jint i, jint j); SG_END_DECL() diff --git a/src/bindings/java/jmsg_storage.cpp b/src/bindings/java/jmsg_storage.cpp index 427d2429b8..8afa119525 100644 --- a/src/bindings/java/jmsg_storage.cpp +++ b/src/bindings/java/jmsg_storage.cpp @@ -1,15 +1,13 @@ -/* Functions related to the java storage API. */ +/* Java bindings of the Storage API. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include - #include "simgrid/msg.h" +#include "surf/surf_routing.h" + #include "jmsg.h" #include "jmsg_storage.h" #include "jxbt_utilities.h" @@ -53,11 +51,6 @@ void jstorage_unref(JNIEnv * env, jobject jstorage) { env->DeleteGlobalRef(jstorage); } -const char *jstorage_get_name(jobject jstorage, JNIEnv * env) { - msg_storage_t storage = jstorage_get_native(env, jstorage); - return MSG_storage_get_name(storage); -} - JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, jclass cls, jstring jname) { msg_storage_t storage; jobject jstorage; diff --git a/src/bindings/java/jmsg_storage.h b/src/bindings/java/jmsg_storage.h index 14f7fbc911..b8bd820953 100644 --- a/src/bindings/java/jmsg_storage.h +++ b/src/bindings/java/jmsg_storage.h @@ -1,144 +1,49 @@ -/* Functions related to the java storage API. */ +/* Java bindings of the Storage API. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #ifndef MSG_JSTORAGE_H #define MSG_JSTORAGE_H -#include + #include "simgrid/msg.h" +#include SG_BEGIN_DECL() -/** - * This function returns a new java storage instance. - * - * @param env The environment of the current thread - * - * @return A new java storage object. - * - * @exception If the class Storage is not found the function throws the ClassNotFoundException. If the constructor of - * this class is not found the function throws the exception NotSuchMethodException. - */ +/** Returns a new java instance of a storage. */ jobject jstorage_new_instance(JNIEnv * env); -/** - * This function associated a native storage to a java storage instance. - * - * @param jstorage The java storage instance. - * @param storage The native storage to bind. - * @param env The environment of the current thread - * - * @exception If the class Storage is not found the function throws the ClassNotFoundException. If the field bind - * of this class is not found the function throws the exception NotSuchFieldException. - */ +/** Binds a native instance to a java instance. */ void jstorage_bind(jobject jstorage, msg_storage_t storage, JNIEnv * env); -/** - * This function returns a native storage from a java storage instance. - * - * @param jstorage The java storage object from which get the native storage. - * @param env The environment of the current thread - * - * @return The function returns the native storage associated to the java storage object. - * - * @exception If the class Storage is not found the function throws the ClassNotFoundException. If the field bind - * of this class is not found the function throws the exception NotSuchFieldException. - */ +/** Extracts the native instance associated to a java instance. */ msg_storage_t jstorage_get_native(JNIEnv * env, jobject jstorage); -/** - * Class org_simgrid_msg_Storage - * Method nativeInit - * Signature ()V - */ +/** Initialize the native world, called from the Java world at startup */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Storage_nativeInit(JNIEnv *env, jclass cls); -/** - * This function returns a global reference to the java storage instance specified by the parameter jstorage. - * - * @param jstorage The original java storage instance. - * @param env The environment of the current thread - * - * @return The global reference to the original java storage instance. - */ +/** Take a ref onto the java instance (to prevent its collection) */ jobject jstorage_ref(JNIEnv * env, jobject jstorage); -/** - * This function delete a global reference to a java storage instance. - * - * @param The global reference to delete. - * @param env The environment of the current thread - */ +/** Release a ref onto the java instance */ void jstorage_unref(JNIEnv * env, jobject jstorage); -/** - * This function returns the name of a MSG storage. - * - * @param jstorage A java storage object. - * @param env The environment of the current thread - * - * @return The name of the storage. - */ +/** Get the name of a java instance. */ const char *jstorage_get_name(jobject jstorage, JNIEnv * env); -/* - * Class org_simgrid_msg_Storage - * Method getByName - * Signature (Ljava/lang/String;)Lsimgrid/msg/Storage; - */ -JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv *env, jclass cls, jstring jname); +/* Implement the Java API */ -/* - * Class org_simgrid_msg_Storage - * Method getSize - * Signature ()D - */ +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv* env, jclass cls, jstring jname); JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getSize(JNIEnv *env, jobject jstorage); - -/* - * Class org_simgrid_msg_Storage - * Method getFreeSize - * Signature ()D - */ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getFreeSize(JNIEnv *env, jobject jstorage); - -/* - * Class org_simgrid_msg_Storage - * Method getUsedSize - * Signature ()D - */ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv *env, jobject jstorage); - -/* - * Class org_simgrid_msg_Storage - * Method getProperty - * Signature (Ljava/lang/String;)Ljava/lang/String; - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getProperty(JNIEnv *env, jobject jstorage, jobject jname); - -/* - * Class org_simgrid_msg_Storage - * Method setProperty - * Signature (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; - */ -JNIEXPORT void JNICALL -Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject jname, jobject jvalue); - -/* - * Class org_simgrid_msg_Storage - * Method getHost - * Signature (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; - */ +JNIEXPORT void JNICALL Java_org_simgrid_msg_Storage_setProperty(JNIEnv* env, jobject jstorage, jobject jname, + jobject jvalue); JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getHost(JNIEnv * env,jobject jstorage); - -/** - * Class org_simgrid_msg_Storage - * Method all - */ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv *env, jclass cls); SG_END_DECL() diff --git a/src/bindings/java/jmsg_synchro.cpp b/src/bindings/java/jmsg_synchro.cpp index 9314977a5f..d25b97b14b 100644 --- a/src/bindings/java/jmsg_synchro.cpp +++ b/src/bindings/java/jmsg_synchro.cpp @@ -1,7 +1,6 @@ -/* Functions exporting the simgrid synchronization mechanisms to the Java world */ +/* Java bindings of the Synchronization API. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ diff --git a/src/bindings/java/jmsg_synchro.h b/src/bindings/java/jmsg_synchro.h index 4db16a7109..2e698cb8c5 100644 --- a/src/bindings/java/jmsg_synchro.h +++ b/src/bindings/java/jmsg_synchro.h @@ -1,7 +1,6 @@ -/* Functions related to the java process instances. */ +/* Java bindings of the Synchronization API. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -10,8 +9,6 @@ #define MSG_JSYNCHRO_H #include -#include -#include SG_BEGIN_DECL() diff --git a/src/bindings/java/jmsg_task.cpp b/src/bindings/java/jmsg_task.cpp index 7be5a84299..f0da73932b 100644 --- a/src/bindings/java/jmsg_task.cpp +++ b/src/bindings/java/jmsg_task.cpp @@ -1,16 +1,10 @@ /* Functions related to the java task instances. */ -/* Copyright (c) 2007, 2009-2010, 2013-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include -#include - -#include #include #include "jmsg.h" @@ -37,16 +31,11 @@ void jtask_bind(jobject jtask, msg_task_t task, JNIEnv * env) env->SetLongField(jtask, jtask_field_Task_bind, (intptr_t)task); } -msg_task_t jtask_to_native_task(jobject jtask, JNIEnv * env) +msg_task_t jtask_to_native(jobject jtask, JNIEnv* env) { return (msg_task_t)(intptr_t)env->GetLongField(jtask, jtask_field_Task_bind); } -jboolean jtask_is_valid(jobject jtask, JNIEnv * env) -{ - return env->GetLongField(jtask, jtask_field_Task_bind) ? JNI_TRUE : JNI_FALSE; -} - JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls) { jclass jtask_class_Comm = env->FindClass("org/simgrid/msg/Comm"); jclass jtask_class_Task = env->FindClass("org/simgrid/msg/Task"); @@ -167,7 +156,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env, jo JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_cancel(JNIEnv * env, jobject jtask) { - msg_task_t ptask = jtask_to_native_task(jtask, env); + msg_task_t ptask = jtask_to_native(jtask, env); if (!ptask) { jxbt_throw_notbound(env, "task", jtask); @@ -181,7 +170,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_cancel(JNIEnv * env, jobject jt JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute(JNIEnv * env, jobject jtask) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -198,7 +187,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute(JNIEnv * env, jobject j JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setBound(JNIEnv * env, jobject jtask, jdouble bound) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -208,7 +197,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setBound(JNIEnv * env, jobject } JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobject jtask) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -221,7 +210,7 @@ JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobjec JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobject jtask) { msg_process_t process; - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -232,13 +221,13 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobj if (process == nullptr) { return nullptr; } - return (jobject) native_to_java_process(process); + return (jobject)jprocess_from_native(process); } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource(JNIEnv * env, jobject jtask) { msg_host_t host; - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -259,7 +248,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource(JNIEnv * env, jobj JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Task_getFlopsAmount(JNIEnv * env, jobject jtask) { - msg_task_t ptask = jtask_to_native_task(jtask, env); + msg_task_t ptask = jtask_to_native(jtask, env); if (!ptask) { jxbt_throw_notbound(env, "task", jtask); @@ -269,7 +258,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Task_getFlopsAmount(JNIEnv * env, } JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setName(JNIEnv *env, jobject jtask, jobject jname) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -285,7 +274,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setName(JNIEnv *env, jobject jt JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setPriority(JNIEnv * env, jobject jtask, jdouble priority) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -296,7 +285,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setPriority(JNIEnv * env, jobje JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setFlopsAmount (JNIEnv *env, jobject jtask, jdouble computationAmount) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -307,7 +296,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setFlopsAmount (JNIEnv *env, jo JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setBytesAmount (JNIEnv *env, jobject jtask, jdouble dataSize) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { jxbt_throw_notbound(env, "task", jtask); @@ -322,7 +311,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_send(JNIEnv * env,jobject jtask msg_error_t rv; const char *alias = env->GetStringUTFChars(jalias, 0); - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { env->ReleaseStringUTFChars(jalias, alias); @@ -346,7 +335,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_sendBounded(JNIEnv * env,jobjec msg_error_t rv; const char *alias = env->GetStringUTFChars(jalias, 0); - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { env->ReleaseStringUTFChars(jalias, alias); @@ -504,7 +493,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject j jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor); const char* mailbox = env->GetStringUTFChars(jmailbox, 0); - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { env->ReleaseStringUTFChars(jmailbox, mailbox); @@ -540,7 +529,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isendBounded(JNIEnv *env, jo jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor); mailbox = env->GetStringUTFChars(jmailbox, 0); - task = jtask_to_native_task(jtask, env); + task = jtask_to_native(jtask, env); if (!task) { env->ReleaseStringUTFChars(jmailbox, mailbox); @@ -563,11 +552,11 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isendBounded(JNIEnv *env, jo JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_nativeFinalize(JNIEnv * env, jobject jtask) { - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); - if (!task) { - jxbt_throw_notbound(env, "task", jtask); - return; + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return; } MSG_task_destroy(task); @@ -588,7 +577,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jta { const char *alias = env->GetStringUTFChars(jalias, 0); - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { env->ReleaseStringUTFChars(jalias, alias); @@ -608,7 +597,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsendBounded(JNIEnv * env, jobj { const char *alias = env->GetStringUTFChars(jalias, 0); - msg_task_t task = jtask_to_native_task(jtask, env); + msg_task_t task = jtask_to_native(jtask, env); if (!task) { env->ReleaseStringUTFChars(jalias, alias); diff --git a/src/bindings/java/jmsg_task.h b/src/bindings/java/jmsg_task.h index e3846559bb..81e165a6bb 100644 --- a/src/bindings/java/jmsg_task.h +++ b/src/bindings/java/jmsg_task.h @@ -1,7 +1,6 @@ /* Functions related to the java task instances. */ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -14,230 +13,50 @@ SG_BEGIN_DECL() -/** - * This function associated a native task to a java task instance. - * - * @param jtask The java task instance. - * @param task The native task to bind. - * @param env The environment of the current thread. - * - * @exception If the class Task is not found the function throws the ClassNotFoundException. If the field bind of - * this class is not found the function throws the exception NotSuchFieldException. - */ +/** Binds a native instance to a java instance. */ void jtask_bind(jobject jtask, msg_task_t task, JNIEnv * env); -/** - * This function returns a native task from a java task instance. - * - * @param jtask The java task object from which get the native task. - * @param env The environment of the current thread. - * - * @return The function returns the native task associated to the java task object. - * - * @exception If the class Task is not found the function throws the ClassNotFoundException. If the field bind of - * this class is not found the function throws the exception NotSuchFieldException. - */ -msg_task_t jtask_to_native_task(jobject jtask, JNIEnv * env); +/** Extract the native instance from the java one */ +msg_task_t jtask_to_native(jobject jtask, JNIEnv* env); -/** - * This function tests if a java task instance is valid. - * A java task object is valid if it is bind to a native task. - * - * @param jtask The java task to test the validity. - * @param env The environment of the current thread. - * - * @return If the java task is valid the function returns true. Otherwise the function returns false. - */ -jboolean jtask_is_valid(jobject jtask, JNIEnv * env); - -/* - * Class org_simgrid_msg_Task - * Method nativeInit - * Signature (); - */ +/** Initialize the native world, called from the Java world at startup */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls); -/* - * Class org_simgrid_msg_Task - * Method create - */ +/* Implement the Java API */ + JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_create (JNIEnv * env, jobject jtask, jstring jname, jdouble jcomputeDuration, jdouble jmessageSize); JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_nativeFinalize(JNIEnv * env, jobject jtask); - -/* - * Class org_simgrid_msg_Task - * Method parallelCreate - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_parallelCreate (JNIEnv *, jobject, jstring, jobjectArray, jdoubleArray, jdoubleArray); - -/* - * Class org_simgrid_msg_Task - * Method destroy - * Signature (Lsimgrid/msg/Task;)V - */ -/* JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_destroy (JNIEnv *, jobject); */ - -/* - * Class org_simgrid_msg_Task - * Method cancel - * Signature ()V - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_cancel (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Task - * Method execute - * Signature ()V - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Task - * Method setBound - * Signature ()V - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setBound (JNIEnv *, jobject, jdouble); - -/* - * Class org_simgrid_msg_Task - * Method getName - * Signature ()Ljava/lang/String; - */ JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Task - * Method getSender - * Signature ()Lsimgrid/msg/Process; - */ +JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setName(JNIEnv* env, jobject jtask, jobject jname); JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Task - * Method getSource - * Signature ()Lsimgrid/msg/Host; - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource (JNIEnv *, jobject); - -/* - * Class org_simgrid_msg_Task - * Method getFlopsAmount - * Signature ()D - */ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Task_getFlopsAmount (JNIEnv *, jobject); - -/** - * Class org_simgrid_msg_Task - * Method setName - * Signature (Ljava/lang/string;)V - */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setName(JNIEnv *env, jobject jtask, jobject jname); - -/* - * Class org_simgrid_msg_Task - * Method setPriority - * Signature (D)V - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setPriority (JNIEnv *, jobject, jdouble); - -/** - * Class org_simgrid_msg_Task - * Method setComputeDuration - * Signature (D)V - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setFlopsAmount (JNIEnv *env, jobject jtask, jdouble computationAmount); - -/** - * Class org_simgrid_msg_Task - * Method setDataSize - * Signature (D)V - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setBytesAmount (JNIEnv *env, jobject jtask, jdouble dataSize); -/** - * Class org_simgrid_msg_Task - * Method send - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_send (JNIEnv *, jobject, jstring, jdouble); - -/** - * Class org_simgrid_msg_Task - * Method sendBounded - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_sendBounded (JNIEnv *, jobject, jstring, jdouble, jdouble); - -/** - * Class org_simgrid_msg_Task - * Method receive - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receive (JNIEnv *, jclass, jstring, jdouble, jobject); - -/** - * Class org_simgrid_msg_Task - * Method irecv - * Signature (Ljava/lang/String;)Lorg/simgrid/msg/Comm; - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass cls, jstring jmailbox); - -/** - * Class org_simgrid_msg_Task - * Method receiveBounded - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receiveBounded(JNIEnv * env, jclass cls, jstring jalias, jdouble jtimeout, jobject jhost, jdouble rate); - -/** - * Class org_simgrid_msg_Task - * Method irecvBounded - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecvBounded(JNIEnv * env, jclass cls, jstring jmailbox, jdouble rate); - -/** - * Class org_simgrid_msg_Task - * Method isend - * Signature (Lorg/simgrid/msg/Task;Ljava/lang/String;)Lorg/simgrid/msg/Comm; - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject jtask, jstring jmailbox); - -/** - * Class org_simgrid_msg_Task - * Method isendBounded - */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isendBounded(JNIEnv *env, jobject jtask, jstring jmailbox, jdouble maxrate); - -/** - * Class org_simgrid_msg_Task - * Method dsend - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jtask, jstring jalias); - -/** - * Class org_simgrid_msg_Task - * Method dsendBounded - */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsendBounded(JNIEnv * env, jobject jtask, jstring jalias, jdouble maxrate); - -/** - * Class org_simgrid_msg_Task - * Method listen - */ JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Task_listen(JNIEnv *, jclass, jstring); - -/** - * Class org_simgrid_msg_Task - * Method listenFromHost - */ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Task_listenFromHost(JNIEnv *, jclass, jstring, jobject); - -/** - * Class org_simgrid_msg_Task - * Method listenFrom - */ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Task_listenFrom(JNIEnv *, jclass, jstring); SG_END_DECL() diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index 93124880a4..12d1fe113a 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -1,20 +1,14 @@ -/* Functions related to the MSG VM API. */ +/* Functions related to the Virtual Machines. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include - -#include "jmsg.h" #include "jmsg_vm.h" #include "jmsg_host.h" -#include "jmsg_process.h" #include "jxbt_utilities.h" -#include "simgrid/msg.h" -#include +#include "xbt/ex.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); diff --git a/src/bindings/java/jmsg_vm.h b/src/bindings/java/jmsg_vm.h index dd89414bc5..36267c94f5 100644 --- a/src/bindings/java/jmsg_vm.h +++ b/src/bindings/java/jmsg_vm.h @@ -1,7 +1,6 @@ -/* Functions related to the MSG VM API. */ +/* Functions related to the Virtual Machines. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ diff --git a/src/bindings/java/jtrace.cpp b/src/bindings/java/jtrace.cpp index d097358f24..26c64daf99 100644 --- a/src/bindings/java/jtrace.cpp +++ b/src/bindings/java/jtrace.cpp @@ -1,16 +1,12 @@ -/* Java Wrappers to the TRACE API. */ +/* Java bindings of the Trace API. */ -/* Copyright (c) 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -// Please note, this file strongly relies on the jmsg.cpp, -// It will be great that a JNI expert gives a look to validate it - Adrien ;) - #include "jtrace.h" -#include +#include "simgrid/instr.h" /* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ #ifndef JNIEXPORT diff --git a/src/bindings/java/jtrace.h b/src/bindings/java/jtrace.h index 377f071477..61d6807291 100644 --- a/src/bindings/java/jtrace.h +++ b/src/bindings/java/jtrace.h @@ -1,4 +1,6 @@ -/* Copyright (c) 2013-2016. The SimGrid Team. All rights reserved. */ +/* Java bindings of the Trace API. */ + +/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -8,6 +10,16 @@ #ifndef _Included_org_simgrid_trace_Trace #define _Included_org_simgrid_trace_Trace + +/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ +#ifndef JNIEXPORT +#define JNIEXPORT +#endif +#ifndef JNICALL +#define JNICALL +#endif +/* end of eclipse-mandated pimple */ + #ifdef __cplusplus extern "C" { #endif diff --git a/src/bindings/java/jxbt_utilities.cpp b/src/bindings/java/jxbt_utilities.cpp index c1e5b4a5ac..ba5d746554 100644 --- a/src/bindings/java/jxbt_utilities.cpp +++ b/src/bindings/java/jxbt_utilities.cpp @@ -1,17 +1,15 @@ /* Various JNI helper functions */ -/* Copyright (c) 2007-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include /* abort */ -#include "xbt/misc.h" #include "xbt/sysdep.h" -#include "xbt/str.h" #include "jxbt_utilities.h" +#include /* abort */ + SG_BEGIN_DECL() jclass jxbt_get_class(JNIEnv * env, const char *name) diff --git a/src/bindings/java/jxbt_utilities.h b/src/bindings/java/jxbt_utilities.h index 2b0830e90d..4bb2b09ba3 100644 --- a/src/bindings/java/jxbt_utilities.h +++ b/src/bindings/java/jxbt_utilities.h @@ -1,7 +1,6 @@ /* Various JNI helper functions */ -/* Copyright (c) 2007-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -- 2.20.1