Provides Octave's Java interface. More...
#include <algorithm>
#include <array>
#include <fstream>
#include <map>
#include <string>
#include <vector>
#include <clocale>
#include "Cell.h"
#include "builtin-defun-decls.h"
#include "cmd-edit.h"
#include "defaults.h"
#include "defun.h"
#include "error.h"
#include "errwarn.h"
#include "file-ops.h"
#include "file-stat.h"
#include "fpucw-wrappers.h"
#include "interpreter.h"
#include "interpreter-private.h"
#include "load-path.h"
#include "lo-sysdep.h"
#include "oct-env.h"
#include "oct-process.h"
#include "oct-shlib.h"
#include "ov-java.h"
#include "parse.h"
#include "variables.h"
#include <jni.h>
Go to the source code of this file.
Classes | |
class | java_local_ref< T > |
class | JVMArgs |
Macros | |
#define | BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID) |
#define | LIBJVM_FILE_NAME "libjvm.so" |
#define | TO_JAVA(obj) dynamic_cast<octave_java *> ((obj).internal_rep ()) |
#define | TO_JCLASS(obj) reinterpret_cast<jclass> (obj) |
#define | TO_JNIENV(env) reinterpret_cast<JNIEnv *> (env) |
#define | TO_JOBJECT(obj) reinterpret_cast<jobject> (obj) |
#define | UNBOX_PRIMITIVE_ARRAY(METHOD_T, OCTAVE_T, JAVA_T, JAVA_T_CAP) |
#define | UNBOX_PRIMITIVE_SCALAR(OCTAVE_T, METHOD_T, JAVA_T, JAVA_CON) |
Typedefs | |
typedef java_local_ref< jbyteArray > | jbyteArray_ref |
typedef java_local_ref< jclass > | jclass_ref |
typedef java_local_ref< jdoubleArray > | jdoubleArray_ref |
typedef java_local_ref< jintArray > | jintArray_ref |
typedef jint(JNICALL * | JNI_CreateJavaVM_t) (JavaVM **pvm, JNIEnv **penv, void *args) |
typedef jint(JNICALL * | JNI_GetCreatedJavaVMs_t) (JavaVM **pvm, jsize bufLen, jsize *nVMs) |
typedef java_local_ref< jobject > | jobject_ref |
typedef java_local_ref< jobjectArray > | jobjectArray_ref |
typedef java_local_ref< jstring > | jstring_ref |
typedef java_local_ref< jthrowable > | jthrowable_ref |
Functions | |
static octave_value | box (JNIEnv *jni_env, void *jobj, void *jcls_arg=nullptr) |
static octave_value | box_more (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg=nullptr) |
static octave_value | check_exception (JNIEnv *jni_env) |
static dim_vector | compute_array_dimensions (JNIEnv *jni_env, jobject obj) |
static jclass | find_octave_class (JNIEnv *jni_env, const char *name) |
static octave_value | get_array_elements (JNIEnv *jni_env, jobject jobj, const octave_value_list &idx) |
static std::string | get_jvm_lib_path_in_subdir (std::string java_home_path) |
static std::string | initial_class_path (void) |
Return the initial classpath. More... | |
static std::string | initial_java_dir (void) |
The java initialization directory is given by the environment variable OCTAVE_JAVA_DIR if defined; otherwise it is the directory of Octave's m-files defining Java functions. More... | |
static void | initialize_jvm (void) |
Initialize the java virtual machine (jvm) and field jvm if necessary. More... | |
JNIEXPORT jboolean JNICALL | Java_org_octave_Octave_call (JNIEnv *, jclass, jstring, jobjectArray, jobjectArray) |
JNIEXPORT void JNICALL | Java_org_octave_Octave_doEvalString (JNIEnv *, jclass, jstring) |
JNIEXPORT void JNICALL | Java_org_octave_Octave_doInvoke (JNIEnv *, jclass, jint, jobjectArray) |
JNIEXPORT jboolean JNICALL | Java_org_octave_Octave_needThreadedInvokation (JNIEnv *, jclass) |
JNIEXPORT void JNICALL | Java_org_octave_OctaveReference_doFinalize (JNIEnv *, jclass, jint) |
static std::string | jstring_to_string (JNIEnv *jni_env, jobject obj) |
static std::string | jstring_to_string (JNIEnv *jni_env, jstring s) |
Converts a Java string object to std::string. More... | |
static jobject | make_java_index (JNIEnv *jni_env, const octave_value_list &idx) |
static std::string | read_classpath_txt (const std::string &filepath) |
Return the classpath in the given file filepath as a string. More... | |
static void | terminate_jvm (void) |
Terminate the current jvm, if there is any. More... | |
static JNIEnv * | thread_jni_env (void) |
} More... | |
static bool | unbox (JNIEnv *jni_env, const octave_value &val, jobject_ref &jobj, jclass_ref &jcls) |
static bool | unbox (JNIEnv *jni_env, const octave_value_list &args, jobjectArray_ref &jobjs, jobjectArray_ref &jclss) |
Variables | |
static JavaVM * | jvm = nullptr |
The pointer to a java virtual machine either created in the current thread or attached this thread to it. More... | |
static bool | jvm_attached = false |
Whether the current thread is attached to the jvm given by jvm. More... | |
static octave::dynamic_library | jvm_lib |
Need to keep hold of the shared library handle until exit. More... | |
static std::map< int, octave_value > | listener_map |
static int | octave_java_refcount = 0 |
static std::map< int, octave_value > | octave_ref_map |
static long | octave_thread_ID = -1 |
The thread id of the currently executing thread or -1 if this is unknown. More... | |
bool | Vdebug_java = false |
bool | Vjava_matrix_autoconversion = false |
bool | Vjava_unsigned_autoconversion = true |
Provides Octave's Java interface.
Definition in file ov-java.cc.
#define BOX_PRIMITIVE_ARRAY | ( | JAVA_TYPE, | |
JAVA_ID, | |||
JAVA_TYPE_CAP, | |||
OCTAVE_ID | |||
) |
#define LIBJVM_FILE_NAME "libjvm.so" |
Definition at line 83 of file ov-java.cc.
#define TO_JAVA | ( | obj | ) | dynamic_cast<octave_java *> ((obj).internal_rep ()) |
#define TO_JCLASS | ( | obj | ) | reinterpret_cast<jclass> (obj) |
Definition at line 87 of file ov-java.cc.
Definition at line 89 of file ov-java.cc.
#define TO_JOBJECT | ( | obj | ) | reinterpret_cast<jobject> (obj) |
Definition at line 86 of file ov-java.cc.
#define UNBOX_PRIMITIVE_ARRAY | ( | METHOD_T, | |
OCTAVE_T, | |||
JAVA_T, | |||
JAVA_T_CAP | |||
) |
#define UNBOX_PRIMITIVE_SCALAR | ( | OCTAVE_T, | |
METHOD_T, | |||
JAVA_T, | |||
JAVA_CON | |||
) |
typedef java_local_ref<jbyteArray> jbyteArray_ref |
Definition at line 152 of file ov-java.cc.
typedef java_local_ref<jclass> jclass_ref |
Definition at line 148 of file ov-java.cc.
typedef java_local_ref<jdoubleArray> jdoubleArray_ref |
Definition at line 153 of file ov-java.cc.
typedef java_local_ref<jintArray> jintArray_ref |
Definition at line 151 of file ov-java.cc.
typedef jint(JNICALL * JNI_CreateJavaVM_t) (JavaVM **pvm, JNIEnv **penv, void *args) |
Definition at line 91 of file ov-java.cc.
typedef jint(JNICALL * JNI_GetCreatedJavaVMs_t) (JavaVM **pvm, jsize bufLen, jsize *nVMs) |
Definition at line 94 of file ov-java.cc.
typedef java_local_ref<jobject> jobject_ref |
Definition at line 147 of file ov-java.cc.
typedef java_local_ref<jobjectArray> jobjectArray_ref |
Definition at line 150 of file ov-java.cc.
typedef java_local_ref<jstring> jstring_ref |
Definition at line 149 of file ov-java.cc.
typedef java_local_ref<jthrowable> jthrowable_ref |
Definition at line 154 of file ov-java.cc.
|
static |
Referenced by CheckBoxControl::CheckBoxControl(), PopupMenuControl::PopupMenuControl(), get_array_elements(), ft_text_renderer::render(), shortcut_manager::shortcut_dialog(), ft_text_renderer::text_to_pixels(), ft_text_renderer::text_to_strlist(), CheckBoxControl::update(), and PopupMenuControl::update().
|
static |
|
static |
Definition at line 969 of file ov-java.cc.
References error(), jstring_to_string(), Matrix, and Vdebug_java.
Referenced by get_array_elements(), and make_java_index().
|
static |
Definition at line 1079 of file ov-java.cc.
References java_local_ref< T >::detach(), len, dim_vector::ndims(), octave_set_default_fpucw(), and dim_vector::resize().
|
static |
Definition at line 999 of file ov-java.cc.
References jstring_to_string().
Referenced by get_array_elements().
|
static |
Definition at line 1151 of file ov-java.cc.
References box(), check_exception(), find_octave_class(), make_java_index(), and octave_set_default_fpucw().
|
static |
Definition at line 513 of file ov-java.cc.
References LIBJVM_FILE_NAME.
Referenced by initialize_jvm().
|
static |
Return the initial classpath.
The initial classpath starts with a pointer to octave.jar
which is located in the initial java directory given by #java_init_dir().
javaclasspath.m
drops this. On the other hand, this is vital because octave.jar
contains the java core classes of octave's java interface.The rest of the classpath is read sequentially from files javaclasspath.txt
located in either:
Definition at line 423 of file ov-java.cc.
References dir_sep_str(), error(), initial_java_dir(), read_classpath_txt(), and tilde_expand().
Referenced by initialize_jvm().
|
static |
The java initialization directory is given by the environment variable OCTAVE_JAVA_DIR
if defined; otherwise it is the directory of Octave's m-files defining Java functions.
The Java initialization directory is the directory where resides:
octave.jar
, defining the java classes implementing octave's java interface,javaclasspath.txt
, defining the installation defined portion of the (static) classpath,java.opts
, defining the configurable options of the java virtual machine.Note that the (static) java classpath of the java virtual machine starts with octave.jar
, and that the static java classpath ends with what is read from javaclasspath.txt
located in the initial java directory. Moreover, the java virtual machine is created essentially with the options given by java.opts
.
Definition at line 344 of file ov-java.cc.
References dir_sep_str(), and fcn_file_dir().
Referenced by initial_class_path(), and initialize_jvm().
|
static |
Initialize the java virtual machine (jvm) and field jvm if necessary.
If the jvm exists and is initialized, jvm points to it, i.e. is not 0 and there is nothing to do.
If jvm is 0 and if at least one jvm exists, attach the current thread to it by setting jvm_attached. Otherwise, create a jvm with some hard- coded options:
classpath
is given by initial_class_path().Further options are read from the file java.opts
in the directory given by #java_init_dir().
Note that initial_class_path() determines the initial classpath. This is the static classpath which cannot be changed. Elements of the dynamic classpath can be added and removed using the m-file scripts javaaddpath.m
and javarmpath.m
.
The number of created jvm's.
Definition at line 671 of file ov-java.cc.
References dir_sep_str(), error(), get_jvm_lib_path_in_subdir(), initial_class_path(), initial_java_dir(), jvm, jvm_attached, jvm_lib, LIBJVM_FILE_NAME, and run_command_and_return_output().
JNIEXPORT jboolean JNICALL Java_org_octave_Octave_call | ( | JNIEnv * | , |
jclass | , | ||
jstring | , | ||
jobjectArray | , | ||
jobjectArray | |||
) |
JNIEXPORT void JNICALL Java_org_octave_Octave_doEvalString | ( | JNIEnv * | , |
jclass | , | ||
jstring | |||
) |
JNIEXPORT void JNICALL Java_org_octave_Octave_doInvoke | ( | JNIEnv * | , |
jclass | , | ||
jint | , | ||
jobjectArray | |||
) |
JNIEXPORT jboolean JNICALL Java_org_octave_Octave_needThreadedInvokation | ( | JNIEnv * | , |
jclass | |||
) |
JNIEXPORT void JNICALL Java_org_octave_OctaveReference_doFinalize | ( | JNIEnv * | , |
jclass | , | ||
jint | |||
) |
|
static |
Definition at line 872 of file ov-java.cc.
References jstring_to_string().
|
static |
Converts a Java string object to std::string.
{
Definition at line 857 of file ov-java.cc.
Referenced by check_exception(), find_octave_class(), and jstring_to_string().
|
static |
Definition at line 1114 of file ov-java.cc.
References check_exception(), and octave_value_list::length().
Referenced by get_array_elements().
|
static |
Return the classpath in the given file filepath
as a string.
In the classpath file, each line which is neither empty nor a comment, is interpreted as a segment of a path. Comment lines are those starting with a #
or with a %
in the very first column.
filepath | The path to the file (usually classpath.txt ) containing a portion of the classpath. |
filepath
which are neither comments nor empty without trailing whitespace separated by 'octave::directory_path::path_sep_str()'. The returned string also starts with that path separator. Definition at line 375 of file ov-java.cc.
References ifstream(), and tilde_expand().
Referenced by initial_class_path().
|
static |
Terminate the current jvm, if there is any.
Otherwise, detach the jvm if this thread is attached to it and unload it if this thread created it itself.
Definition at line 833 of file ov-java.cc.
References jvm, jvm_attached, jvm_lib, and octave_set_default_fpucw().
|
inlinestatic |
}
Returns a reference to the jni (java native interface) environment of the Java virtual machine jvm.
nullptr
. Definition at line 897 of file ov-java.cc.
References jvm.
Referenced by octave_java::is_instance_of(), and octave_java::is_java_string().
|
static |
|
static |
|
static |
The pointer to a java virtual machine either created in the current thread or attached this thread to it.
Definition at line 198 of file ov-java.cc.
Referenced by initialize_jvm(), terminate_jvm(), and thread_jni_env().
|
static |
Whether the current thread is attached to the jvm given by jvm.
This is false
also if no jvm exists, i.e. if jvm is nullptr
.
Definition at line 205 of file ov-java.cc.
Referenced by initialize_jvm(), and terminate_jvm().
|
static |
Need to keep hold of the shared library handle until exit.
Definition at line 211 of file ov-java.cc.
Referenced by initialize_jvm(), and terminate_jvm().
|
static |
Definition at line 213 of file ov-java.cc.
|
static |
Definition at line 215 of file ov-java.cc.
|
static |
Definition at line 214 of file ov-java.cc.
|
static |
The thread id of the currently executing thread or -1
if this is unknown.
Definition at line 221 of file ov-java.cc.
bool Vdebug_java = false |
Definition at line 225 of file ov-java.cc.
Referenced by check_exception(), JVMArgs::read_java_opts(), and JVMArgs::update().
bool Vjava_matrix_autoconversion = false |
Definition at line 223 of file ov-java.cc.
bool Vjava_unsigned_autoconversion = true |
Definition at line 224 of file ov-java.cc.