From 1b9fb754fbeabeb4c3892917997208e1972fc338 Mon Sep 17 00:00:00 2001 From: Samuel Lepetit Date: Wed, 13 Jun 2012 11:56:14 +0200 Subject: [PATCH] Add VM API from MSG (experimental, still buggy in MSG C part anyway) --- CMakeLists.txt | 3 ++ org/simgrid/msg/VM.java | 79 ++++++++++++++++++++++++++++++++++++ src/jmsg_vm.c | 82 +++++++++++++++++++++++++++++++++++++ src/jmsg_vm.h | 90 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 org/simgrid/msg/VM.java create mode 100644 src/jmsg_vm.c create mode 100644 src/jmsg_vm.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ee4d1444d2..5a922ccb81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,8 @@ set(JMSG_C_SRC ${CMAKE_HOME_DIRECTORY}/src/jmsg_synchro.h ${CMAKE_HOME_DIRECTORY}/src/jmsg_rngstream.c ${CMAKE_HOME_DIRECTORY}/src/jmsg_rngstream.h + ${CMAKE_HOME_DIRECTORY}/src/jmsg_vm.c + ${CMAKE_HOME_DIRECTORY}/src/jmsg_vm.h ) set(JTRACE_C_SRC @@ -128,6 +130,7 @@ set(JMSG_JAVA_SRC ${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/Mutex.java ${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/Comm.java ${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/RngStream.java + ${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/VM.java ) set(JTRACE_JAVA_SRC org/simgrid/trace/Trace.java diff --git a/org/simgrid/msg/VM.java b/org/simgrid/msg/VM.java new file mode 100644 index 0000000000..c1a4de4830 --- /dev/null +++ b/org/simgrid/msg/VM.java @@ -0,0 +1,79 @@ +/* + * JNI interface to Cloud interface in Simgrid + * + * Copyright 2006,2007,2010,2012 The SimGrid Team. + * All right 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. + */ +package org.simgrid.msg; + +import org.simgrid.msg.Process; + +public class VM { + /** + * This attribute represents a bind between a java task object and + * a native task. Even if this attribute is public you must never + * access to it. It is set automatically during the build of the object. + */ + private long bind = 0; + + private int coreAmount; + /** + * @brief Create a new empty VM. + * @bug it is expected that in the future, the coreAmount parameter will be used + * to add extra constraints on the execution, but the argument is ignored for now. + */ + public VM(int coreAmount) { + this.coreAmount = coreAmount; + } + /** + * Natively implemented method starting the VM. + * @param coreAmount + */ + private native void start(int coreAmount); + + /** + * @brief Returns a new array containing all existing VMs. + */ + public static native VM[] all(); + + /** @brief Returns whether the given VM is currently suspended + */ + public native boolean isSuspended(); + /** @brief Returns whether the given VM is currently running + */ + public native boolean isRunning(); + /** @brief Add the given process into the VM. + * Afterward, when the VM is migrated or suspended or whatever, the process will have the corresponding handling, too. + */ + public native void bind(Process process); + /** @brief Removes the given process from the given VM, and kill it + * Will raise a ProcessNotFound exception if the process were not binded to that VM + */ + public native void unbind(Process process); + /** @brief Immediately change the host on which all processes are running + * + * No migration cost occurs. If you want to simulate this too, you want to use a + * Task.send() before or after, depending on whether you want to do cold or hot + * migration. + */ + public native void migrate(Host destination); + /** @brief Immediately suspend the execution of all processes within the given VM + * + * No suspension cost occurs. If you want to simulate this too, you want to + * use a \ref File.write() before or after, depending on the exact semantic + * of VM suspend to you. + */ + public native void suspend(); + /** @brief Immediately resumes the execution of all processes within the given VM + * + * No resume cost occurs. If you want to simulate this too, you want to + * use a \ref File.read() before or after, depending on the exact semantic + * of VM resume to you. + */ + public native void resume(); + +} \ No newline at end of file diff --git a/src/jmsg_vm.c b/src/jmsg_vm.c new file mode 100644 index 0000000000..f36a9f742d --- /dev/null +++ b/src/jmsg_vm.c @@ -0,0 +1,82 @@ +/* Functions related to the MSG VM API. */ + +/* Copyright (c) 2012. The SimGrid Team. */ + +/* 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 "jmsg_vm.h" +#include "jmsg_host.h" +#include "jmsg_process.h" +#include "jxbt_utilities.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); + +void jvm_bind(JNIEnv *env, jobject jvm, msg_vm_t vm) { + (*env)->SetLongField(env, jvm, jvm_field_bind, (jlong) (long) (vm)); +} +msg_vm_t jvm_get_native(JNIEnv *env, jobject jvm) { + msg_vm_t vm = (msg_vm_t)(*env)->GetLongField(env, jvm, jvm_field_bind); + return vm; +} + +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_nativeInit(JNIEnv *env, jclass cls) { + jclass jprocess_class_VM = (*env)->FindClass(env, "org/simgrid/msg/VM"); + jvm_field_bind = jxbt_get_jfield(env, jprocess_class_VM, "bind", "J"); + if (!jvm_field_bind) { + jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug.")); + } +} +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm, jobject jhost, jint jcoreamount) { + m_host_t host = jhost_get_native(env, jhost); + + msg_vm_t vm = MSG_vm_start(host, (int)jcoreamount); + + jvm_bind(env,jvm,vm); +} +JNIEXPORT jboolean JNICALL +Java_org_simgrid_msg_VM_isSuspended(JNIEnv *env, jobject jvm) { + msg_vm_t vm = jvm_get_native(env,jvm); + + return MSG_vm_is_suspended(vm) ? JNI_TRUE : JNI_FALSE; +} +JNIEXPORT jboolean JNICALL +Java_org_simgrid_msg_VM_isRunning(JNIEnv *env, jobject jvm) { + msg_vm_t vm = jvm_get_native(env,jvm); + + return MSG_vm_is_running(vm) ? JNI_TRUE : JNI_FALSE; +} +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_bind(JNIEnv *env, jobject jvm, jobject jprocess) { + msg_vm_t vm = jvm_get_native(env,jvm); + m_process_t process = jprocess_to_native_process(jprocess,env); + + MSG_vm_bind(vm,process); +} +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_unbind(JNIEnv *env, jobject jvm, jobject jprocess) { + msg_vm_t vm = jvm_get_native(env,jvm); + m_process_t process = jprocess_to_native_process(jprocess,env); + + MSG_vm_unbind(vm,process); +} +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_migrate(JNIEnv *env, jobject jvm, jobject jhost) { + msg_vm_t vm = jvm_get_native(env,jvm); + m_host_t host = jhost_get_native(env, jhost); + + MSG_vm_migrate(vm,host); +} +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_suspend(JNIEnv *env, jobject jvm) { + msg_vm_t vm = jvm_get_native(env,jvm); + + MSG_vm_suspend(vm); +} +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_resume(JNIEnv *env, jobject jvm) { + msg_vm_t vm = jvm_get_native(env,jvm); + + MSG_vm_resume(vm); +} diff --git a/src/jmsg_vm.h b/src/jmsg_vm.h new file mode 100644 index 0000000000..fa5a965f40 --- /dev/null +++ b/src/jmsg_vm.h @@ -0,0 +1,90 @@ +/* Functions related to the MSG VM API. */ + +/* Copyright (c) 2012. The SimGrid Team. */ + +/* 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_VM_H +#define MSG_VM_H + +#include +#include "msg/msg.h" + +jfieldID jvm_field_bind; + +void jvm_bind(JNIEnv *env, jobject jvm, msg_vm_t vm); +msg_vm_t jvm_get_native(JNIEnv *env, jobject jvm); + +/* + * Class org_simgrid_msg_VM + * Method nativeInit + * Signature ()V + */ +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_nativeInit(JNIEnv *env, jclass); +/** + * Class org_simgrid_msg_VM + * Method start + * Signature (I)V + */ +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm, jobject jhost, jint jcoreamount); +/** + * Class org_simgrid_msg_VM + * Method all + * Signature ()[Lorg/simgrid/msg/VM; + */ +JNIEXPORT jobjectArray JNICALL +Java_org_simgrid_msg_VM_all(JNIEnv *env, jclass cls); +/** + * Class org_simgrid_msg_VM + * Method isSuspended + * Signature ()B + */ +JNIEXPORT jboolean JNICALL +Java_org_simgrid_msg_VM_isSuspended(JNIEnv *env, jobject jvm); +/** + * Class org_simgrid_msg_VM + * Method isRunning + * Signature ()B + */ +JNIEXPORT jboolean JNICALL +Java_org_simgrid_msg_VM_isRunning(JNIEnv *env, jobject jvm); +/** + * Class org_simgrid_msg_VM + * Method bind + * Signature (Lorg/simgrid/msg/Process;)V + */ +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_bind(JNIEnv *env, jobject jvm, jobject jprocess); +/** + * Class org_simgrid_msg_VM + * Method unbind + * Signature (Lorg/simgrid/msg/Process;)V + */ +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_unbind(JNIEnv *env, jobject jvm, jobject jprocess); +/** + * Class org_simgrid_msg_VM + * Method migrate + * Signature (Lorg/simgrid/msg/Host;)V + */ +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_migrate(JNIEnv *env, jobject jvm, jobject jhost); +/** + * Class org_simgrid_msg_VM + * Method suspend + * Signature ()V + */ +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_suspend(JNIEnv *env, jobject jvm); +/** + * Class org_simgrid_msg_VM + * Method resume + * Signature ()V + */ +JNIEXPORT void JNICALL +Java_org_simgrid_msg_VM_resume(JNIEnv *env, jobject jvm); +#endif -- 2.20.1