GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Namespaces | Macros | Typedefs | Functions | Variables
ov-java.cc File Reference
#include "defun.h"
#include "error.h"
#include "errwarn.h"
#include "fpucw-wrappers.h"
#include <algorithm>
#include <map>
#include <iostream>
#include <fstream>
#include <string>
#include <clocale>
#include "Cell.h"
#include "cmd-edit.h"
#include "defaults.h"
#include "file-ops.h"
#include "file-stat.h"
#include "load-path.h"
#include "oct-env.h"
#include "oct-shlib.h"
#include "ov-java.h"
#include "parse.h"
#include "variables.h"
#include <jni.h>
Include dependency graph for ov-java.cc:

Go to the source code of this file.

Classes

class  java_local_ref< T >
 
class  octave::JVMArgs
 

Namespaces

 octave
 Octave interface to the compression and uncompression libraries.
 

Macros

#define BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID)
 
#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 JNIEnv void * args
 
typedef jsize bufLen
 
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 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
 
typedef jsize jsize * nVMs
 
typedef JNIEnv ** penv
 

Functions

static octave_value box (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg)
 Convert the Java object pointed to by jobj_arg with class jcls_arg to an Octave value. More...
 
static octave_value box_more (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg=0)
 
static octave_value check_exception (JNIEnv *jni_env)
 
static dim_vector compute_array_dimensions (JNIEnv *jni_env, jobject obj)
 
static octave_value convert_to_string (JNIEnv *jni_env, jobject java_object, bool force, char type)
 
OCTAVE_EXPORT octave_value_list F__java_exit__ (const octave_value_list &, int)
 
OCTAVE_EXPORT octave_value_list F__java_init__ (const octave_value_list &, int)
 
static jclass find_octave_class (JNIEnv *jni_env, const char *name)
 
OCTAVE_EXPORT octave_value_list FjavaObject (const octave_value_list &args, int) by calling the class const ructor with the arguments ar
 
static octave_value get_array_elements (JNIEnv *jni_env, jobject jobj, const octave_value_list &idx)
 
static long get_current_thread_ID (JNIEnv *jni_env)
 
static string_vector get_invoke_list (JNIEnv *jni_env, void *jobj_arg)
 
static std::string initial_class_path (void)
 
static std::string initial_java_dir (void)
 
static void initialize_java (void)
 
static void initialize_jvm (void)
 
static bool is_auto_convertible_number (JNIEnv *jni_env, jobject jobj)
 Return whether jobj shall be automatically converted to an Octave numeric value. More...
 
static int java_event_hook (void)
 
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)
 
typedef jint (JNICALL *JNI_CreateJavaVM_t)(JavaVM **pvm
 
static std::string jstring_to_string (JNIEnv *jni_env, jstring s)
 
static std::string jstring_to_string (JNIEnv *jni_env, jobject obj)
 
static jobject make_java_index (JNIEnv *jni_env, const octave_value_list &idx)
 
static std::string read_classpath_txt (const std::string &filepath)
 
static octave_value set_array_elements (JNIEnv *jni_env, jobject jobj, const octave_value_list &idx, const octave_value &rhs)
 
static void terminate_jvm (void)
 
static JNIEnv * thread_jni_env (void)
 
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 = 0
 
static bool jvm_attached = false
 
static octave::dynamic_library jvm_lib
 
static std::map< int,
octave_value
listener_map
 
ots The first example below
creates an uninitialized 
object
 
static int octave_java_refcount = 0
 
static std::map< int,
octave_value
octave_ref_map
 
static long octave_thread_ID = -1
 
bool Vdebug_java = false
 
bool Vjava_matrix_autoconversion = false
 
bool Vjava_unsigned_autoconversion = true
 

Macro Definition Documentation

#define BOX_PRIMITIVE_ARRAY (   JAVA_TYPE,
  JAVA_ID,
  JAVA_TYPE_CAP,
  OCTAVE_ID 
)
Value:
cls = jni_env->FindClass (JAVA_ID); \
if (jni_env->IsInstanceOf (jobj, cls)) \
{ \
const JAVA_TYPE ## Array jarr = reinterpret_cast<JAVA_TYPE ## Array> (jobj); \
const jsize len = jni_env->GetArrayLength (jarr); \
OCTAVE_ID ## NDArray d (dim_vector (len, 1)); \
JAVA_TYPE *buffer = reinterpret_cast<JAVA_TYPE *> (d.fortran_vec ()); \
jni_env->Get ## JAVA_TYPE_CAP ## ArrayRegion (jarr, 0, len, buffer); \
retval = d; \
break; \
}
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
if(nargin< 2) print_usage()
Definition: cellfun.cc:405
octave_value retval
Definition: data.cc:6294
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:126
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87

Referenced by box().

#define TO_JAVA (   obj)    dynamic_cast<octave_java*> ((obj).internal_rep ())

Definition at line 1136 of file ov-java.cc.

Referenced by unbox().

#define TO_JCLASS (   obj)    reinterpret_cast<jclass> (obj)

Definition at line 63 of file ov-java.cc.

Referenced by box(), box_more(), octave_java::init(), and octave_java::release().

#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 
)
Value:
do \
{ \
const OCTAVE_T ## NDArray v = val.METHOD_T ## array_value (); \
JAVA_T ## Array jarr = jni_env->New ## JAVA_T_CAP ## Array (v.numel ()); \
const JAVA_T *jv = reinterpret_cast<const JAVA_T*> (v.data ()); \
jni_env->Set ## JAVA_T_CAP ## ArrayRegion (jarr, 0, v.numel (), jv); \
jobj = reinterpret_cast<jobject> (jarr); \
jcls = jni_env->GetObjectClass (jobj); \
} \
while (0)
while(ischar(s=fgets(fid))) fputs(stdout
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:126

Referenced by unbox().

#define UNBOX_PRIMITIVE_SCALAR (   OCTAVE_T,
  METHOD_T,
  JAVA_T,
  JAVA_CON 
)
Value:
do \
{ \
const OCTAVE_T ov = val.METHOD_T ## _value (); \
jclass_ref dcls (jni_env, jni_env->FindClass (JAVA_T)); \
const jfieldID fid = jni_env->GetStaticFieldID (dcls, "TYPE", "Ljava/lang/Class;"); \
const jmethodID mid = jni_env->GetMethodID (dcls, "<init>", JAVA_CON); \
jcls = reinterpret_cast<jclass> (jni_env->GetStaticObjectField (dcls, fid)); \
jobj = jni_env->NewObject (dcls, mid, ov); \
} \
while (0)
while(ischar(s=fgets(fid))) fputs(stdout
java_local_ref< jclass > jclass_ref
Definition: ov-java.cc:123
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068

Referenced by unbox().

Typedef Documentation

OCTAVE_EXPORT octave_value_list int64 nd deftypefn *return args
Initial value:
{
if (args.length () != 1)
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
JNIEnv void * args
Definition: ov-java.cc:67

Definition at line 67 of file ov-java.cc.

typedef jsize bufLen

Definition at line 70 of file ov-java.cc.

typedef java_local_ref<jbyteArray> jbyteArray_ref

Definition at line 127 of file ov-java.cc.

typedef java_local_ref<jclass> jclass_ref

Definition at line 123 of file ov-java.cc.

typedef java_local_ref<jdoubleArray> jdoubleArray_ref

Definition at line 128 of file ov-java.cc.

typedef java_local_ref<jintArray> jintArray_ref

Definition at line 126 of file ov-java.cc.

typedef java_local_ref<jobject> jobject_ref

Definition at line 122 of file ov-java.cc.

typedef java_local_ref<jobjectArray> jobjectArray_ref

Definition at line 125 of file ov-java.cc.

typedef java_local_ref<jstring> jstring_ref

Definition at line 124 of file ov-java.cc.

typedef java_local_ref<jthrowable> jthrowable_ref

Definition at line 129 of file ov-java.cc.

typedef jsize jsize* nVMs

Definition at line 70 of file ov-java.cc.

typedef JNIEnv** penv

Definition at line 67 of file ov-java.cc.

Function Documentation

static octave_value box ( JNIEnv *  jni_env,
void *  jobj_arg,
void *  jcls_arg 
)
static

Convert the Java object pointed to by jobj_arg with class jcls_arg to an Octave value.

Parameters
jni_envJNI environment pointer
jobj_argpointer to a Java object
jcls_argoptional pointer to the Java class of jobj_arg
Returns
  • numeric value as a double if jobj_arg is of type Byte, Short, Integer, Long, Float or Double
  • logical value if jobj_arg is of type Boolean
  • string value if jobj_arg is of type Character or String
  • Octave array of numeric, logical, or char type if jobj_arg is a Java array of primitive types
  • Octave matrix if jobj_arg is of type org.octave.Matrix and Vjava_matrix_autoconversion is enabled
  • Octave object if jobj_arg is of type org.octave.OctaveReference
  • octave_java object wrapping the Java object otherwise

Definition at line 1192 of file ov-java.cc.

References BOX_PRIMITIVE_ARRAY, octave_value::convert_to_str(), dims, dv, find_octave_class(), Array< T >::fortran_vec(), int16, int32, int64, is_auto_convertible_number(), octave_value::is_undefined(), jint(), jstring_to_string(), m, dim_vector::ndims(), Array< T >::numel(), octave_value(), dim_vector::resize(), retval, s, string, TO_JCLASS, and TO_JOBJECT.

Referenced by box_more(), octave_java::do_java_get(), octave_java::do_javaMethod(), get_array_elements(), axes::properties::get_property(), Java_org_octave_Octave_call(), Java_org_octave_Octave_doInvoke(), set_array_elements(), axes::properties::set_defaults(), shortcut_manager::shortcut_dialog(), octave::ft_text_renderer::text_to_pixels(), QtHandles::PopupMenuControl::update(), and uicontrol::properties::update_text_extent().

static octave_value box_more ( JNIEnv *  jni_env,
void *  jobj_arg,
void *  jcls_arg = 0 
)
static
static octave_value check_exception ( JNIEnv *  jni_env)
static
static dim_vector compute_array_dimensions ( JNIEnv *  jni_env,
jobject  obj 
)
static
static octave_value convert_to_string ( JNIEnv *  jni_env,
jobject  java_object,
bool  force,
char  type 
)
static
OCTAVE_EXPORT octave_value_list F__java_exit__ ( const octave_value_list ,
int   
)

Definition at line 2804 of file ov-java.cc.

References err_disabled_feature(), ovl(), and terminate_jvm().

Referenced by install_ov_java_fcns().

OCTAVE_EXPORT octave_value_list F__java_init__ ( const octave_value_list ,
int   
)

Definition at line 2776 of file ov-java.cc.

References err_disabled_feature(), initialize_java(), and retval.

Referenced by install_ov_java_fcns().

static jclass find_octave_class ( JNIEnv *  jni_env,
const char *  name 
)
static
OCTAVE_EXPORT octave_value_list FjavaObject ( const octave_value_list args,
int   
) const

Definition at line 2837 of file ov-java.cc.

static octave_value get_array_elements ( JNIEnv *  jni_env,
jobject  jobj,
const octave_value_list idx 
)
static
static long get_current_thread_ID ( JNIEnv *  jni_env)
static

Definition at line 1743 of file ov-java.cc.

References result.

Referenced by initialize_java(), and Java_org_octave_Octave_needThreadedInvokation().

static string_vector get_invoke_list ( JNIEnv *  jni_env,
void *  jobj_arg 
)
static
static std::string initial_class_path ( void  )
static
static std::string initial_java_dir ( void  )
static
static void initialize_java ( void  )
static
static void initialize_jvm ( void  )
static
static bool is_auto_convertible_number ( JNIEnv *  jni_env,
jobject  jobj 
)
static

Return whether jobj shall be automatically converted to an Octave numeric value.

If jobj is an instance of any of the numeric wrapper classes Byte, Integer, Long, Short, Float, or Double, then it will be converted using the java.lang.Number.doubleValue() method.

Parameters
jobjJava object being returned to Octave
Returns
true if jobj shall be converted into a numeric value automatically, false otherwise

Definition at line 1149 of file ov-java.cc.

Referenced by box().

static int java_event_hook ( void  )
static

Definition at line 1766 of file ov-java.cc.

References find_octave_class(), octave_set_default_fpucw(), and thread_jni_env().

Referenced by initialize_java().

JNIEXPORT jboolean JNICALL Java_org_octave_Octave_call ( JNIEnv *  env,
jclass  ,
jstring  funcName,
jobjectArray  argin,
jobjectArray  argout 
)

Definition at line 1810 of file ov-java.cc.

References box(), feval(), fname, jstring_to_string(), nargin, nargout(), string, and unbox().

JNIEXPORT void JNICALL Java_org_octave_Octave_doEvalString ( JNIEnv *  env,
jclass  ,
jstring  cmd 
)

Definition at line 1881 of file ov-java.cc.

References eval_string(), jstring_to_string(), s, and string.

JNIEXPORT void JNICALL Java_org_octave_Octave_doInvoke ( JNIEnv *  env,
jclass  ,
jint  ID,
jobjectArray  args 
)
JNIEXPORT jboolean JNICALL Java_org_octave_Octave_needThreadedInvokation ( JNIEnv *  env,
jclass   
)

Definition at line 1889 of file ov-java.cc.

References get_current_thread_ID(), and octave_thread_ID.

JNIEXPORT void JNICALL Java_org_octave_OctaveReference_doFinalize ( JNIEnv *  ,
jclass  ,
jint  ID 
)

Definition at line 1831 of file ov-java.cc.

typedef jint ( JNICALL *  JNI_CreateJavaVM_t)

Referenced by box(), make_java_index(), and unbox().

static std::string jstring_to_string ( JNIEnv *  jni_env,
jstring  s 
)
static
static std::string jstring_to_string ( JNIEnv *  jni_env,
jobject  obj 
)
static

Definition at line 688 of file ov-java.cc.

References jstring_to_string(), retval, and string.

static jobject make_java_index ( JNIEnv *  jni_env,
const octave_value_list idx 
)
static
static std::string read_classpath_txt ( const std::string filepath)
static
static octave_value set_array_elements ( JNIEnv *  jni_env,
jobject  jobj,
const octave_value_list idx,
const octave_value rhs 
)
static
static void terminate_jvm ( void  )
static

Definition at line 653 of file ov-java.cc.

References octave::dynamic_library::close(), jvm, and octave_set_default_fpucw().

Referenced by F__java_exit__().

static JNIEnv* thread_jni_env ( void  )
inlinestatic
static bool unbox ( JNIEnv *  jni_env,
const octave_value val,
jobject_ref jobj,
jclass_ref jcls 
)
static

Definition at line 1487 of file ov-java.cc.

References array(), octave_value::array_value(), octave_value::cellstr_value(), octave_value::class_name(), octave_value::columns(), java_local_ref< T >::detach(), dims, octave_value::dims(), dv, error(), find_octave_class(), Array< T >::fortran_vec(), found, int16, int32, octave_value::int32_array_value(), int64, octave_value::int8_array_value(), octave_value::is_bool_scalar(), octave_value::is_bool_type(), octave_value::is_cellstr(), octave_value::is_double_type(), octave_value::is_empty(), octave_value::is_float_type(), octave_value::is_int16_type(), octave_value::is_int32_type(), octave_value::is_int64_type(), octave_value::is_int8_type(), octave_value::is_java(), octave_value::is_matrix_type(), octave_value::is_range(), octave_value::is_real_matrix(), octave_value::is_real_scalar(), octave_value::is_real_type(), octave_value::is_string(), octave_value::is_uint16_type(), octave_value::is_uint32_type(), octave_value::is_uint64_type(), octave_value::is_uint8_type(), dim_vector::is_vector(), jint(), m, octave_value::matrix_value(), dim_vector::ndims(), Array< T >::numel(), octave_value::numel(), octave_value::rows(), s, string, octave_value::string_value(), octave_java::to_java(), TO_JAVA, TO_JOBJECT, uint16, uint32, octave_value::uint8_array_value(), UNBOX_PRIMITIVE_ARRAY, UNBOX_PRIMITIVE_SCALAR, and val.

Referenced by octave_java::do_java_set(), octave_java::do_javaMethod(), octave_java::do_javaObject(), Java_org_octave_Octave_call(), set_array_elements(), and unbox().

static bool unbox ( JNIEnv *  jni_env,
const octave_value_list args,
jobjectArray_ref jobjs,
jobjectArray_ref jclss 
)
static

Definition at line 1712 of file ov-java.cc.

References found, octave_value_list::length(), and unbox().

Variable Documentation

JavaVM* jvm = 0
static

Definition at line 170 of file ov-java.cc.

Referenced by initialize_java(), initialize_jvm(), terminate_jvm(), and thread_jni_env().

bool jvm_attached = false
static

Definition at line 171 of file ov-java.cc.

octave::dynamic_library jvm_lib
static

Definition at line 174 of file ov-java.cc.

std::map<int,octave_value> listener_map
static

Definition at line 176 of file ov-java.cc.

ots The first example below creates an uninitialized object
int octave_java_refcount = 0
static

Definition at line 178 of file ov-java.cc.

std::map<int,octave_value> octave_ref_map
static

Definition at line 177 of file ov-java.cc.

long octave_thread_ID = -1
static

Definition at line 179 of file ov-java.cc.

Referenced by initialize_java(), and Java_org_octave_Octave_needThreadedInvokation().

bool Vdebug_java = false

Definition at line 183 of file ov-java.cc.

Referenced by octave::JVMArgs::read_java_opts().

bool Vjava_matrix_autoconversion = false

Definition at line 181 of file ov-java.cc.

bool Vjava_unsigned_autoconversion = true

Definition at line 182 of file ov-java.cc.