[PPL-devel] [GIT] ppl/ppl(master): Cached Java method IDs for class parma_polyhedra_library/Pair.
Enea Zaffanella
zaffanella at cs.unipr.it
Mon May 4 08:11:08 CEST 2009
Module: ppl/ppl
Branch: master
Commit: 1806a003f1aede19f069ed2884f0a133669e987b
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=1806a003f1aede19f069ed2884f0a133669e987b
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Mon May 4 07:53:27 2009 +0200
Cached Java method IDs for class parma_polyhedra_library/Pair.
---
interfaces/Java/jni/ppl_java_common.cc | 25 +++++------------
interfaces/Java/jni/ppl_java_common.defs.hh | 4 +++
interfaces/Java/jni/ppl_java_common.inlines.hh | 28 +++++++++----------
interfaces/Java/jni/ppl_java_globals.cc | 13 +++++++++
.../Java/parma_polyhedra_library/Makefile.am | 4 ++-
interfaces/Java/parma_polyhedra_library/Pair.java | 5 +++
6 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/interfaces/Java/jni/ppl_java_common.cc b/interfaces/Java/jni/ppl_java_common.cc
index 5e127bc..895f1a4 100644
--- a/interfaces/Java/jni/ppl_java_common.cc
+++ b/interfaces/Java/jni/ppl_java_common.cc
@@ -60,6 +60,7 @@ Java_Class_Cache::Java_Class_Cache() {
Linear_Expression_Variable = NULL;
MIP_Problem_Status = NULL;
Optimization_Mode = NULL;
+ Pair = NULL;
Poly_Con_Relation = NULL;
Poly_Gen_Relation = NULL;
PPL_Object = NULL;
@@ -124,6 +125,7 @@ Java_Class_Cache::init_cache(JNIEnv* env) {
"parma_polyhedra_library/MIP_Problem_Status");
init_cache(env, Optimization_Mode,
"parma_polyhedra_library/Optimization_Mode");
+ init_cache(env, Pair, "parma_polyhedra_library/Pair");
init_cache(env, Poly_Con_Relation,
"parma_polyhedra_library/Poly_Con_Relation");
init_cache(env, Poly_Gen_Relation,
@@ -173,6 +175,7 @@ Java_Class_Cache::clear_cache(JNIEnv* env) {
clear_cache(env, Linear_Expression_Variable);
clear_cache(env, MIP_Problem_Status);
clear_cache(env, Optimization_Mode);
+ clear_cache(env, Pair);
clear_cache(env, Poly_Con_Relation);
clear_cache(env, Poly_Gen_Relation);
clear_cache(env, PPL_Object);
@@ -742,46 +745,32 @@ set_generator(JNIEnv* env, jobject dst, jobject src) {
void
set_pair_element(JNIEnv* env, jobject dst_pair, int arg, jobject src) {
- const char* field_name;
switch (arg) {
case 0:
- field_name = "first";
+ env->SetObjectField(dst_pair, cached_FMIDs.Pair_first_ID, src);
break;
case 1:
- field_name = "second";
+ env->SetObjectField(dst_pair, cached_FMIDs.Pair_second_ID, src);
break;
default:
assert(false);
throw std::runtime_error("PPL Java interface internal error: "
"pair value not allowed");
}
- jclass pair_class = env->FindClass("parma_polyhedra_library/Pair");
- CHECK_RESULT_ASSERT(env, pair_class);
- jfieldID fID = env->GetFieldID(pair_class, field_name, "Ljava/lang/Object;");
- CHECK_RESULT_ASSERT(env, fID);
- env->SetObjectField(dst_pair, fID, src);
}
jobject
get_pair_element(JNIEnv* env, int arg, jobject j_pair) {
- const char* field_name;
switch (arg) {
case 0:
- field_name = "first";
- break;
+ return env->GetObjectField(j_pair, cached_FMIDs.Pair_first_ID);
case 1:
- field_name = "second";
- break;
+ return env->GetObjectField(j_pair, cached_FMIDs.Pair_second_ID);
default:
assert(false);
throw std::runtime_error("PPL Java interface internal error: "
"pair value not allowed");
}
- jclass pair_class = env->FindClass("parma_polyhedra_library/Pair");
- CHECK_RESULT_ASSERT(env, pair_class);
- jfieldID fID = env->GetFieldID(pair_class, field_name, "Ljava/lang/Object;");
- CHECK_RESULT_ASSERT(env, fID);
- return env->GetObjectField(j_pair, fID);
}
jobject
diff --git a/interfaces/Java/jni/ppl_java_common.defs.hh b/interfaces/Java/jni/ppl_java_common.defs.hh
index a3d1c6e..1d66c20 100644
--- a/interfaces/Java/jni/ppl_java_common.defs.hh
+++ b/interfaces/Java/jni/ppl_java_common.defs.hh
@@ -167,6 +167,7 @@ public:
jclass Linear_Expression_Variable;
jclass MIP_Problem_Status;
jclass Optimization_Mode;
+ jclass Pair;
jclass Poly_Con_Relation;
jclass Poly_Gen_Relation;
jclass PPL_Object;
@@ -289,6 +290,9 @@ struct Java_FMID_Cache {
jfieldID Optimization_Mode_MAXIMIZATION_ID;
jfieldID Optimization_Mode_MINIMIZATION_ID;
jmethodID Optimization_Mode_ordinal_ID;
+ // Pair.
+ jfieldID Pair_first_ID;
+ jfieldID Pair_second_ID;
// Poly_Con_Relation and Poly_Gen_Relation.
jmethodID Poly_Con_Relation_init_ID;
jmethodID Poly_Gen_Relation_init_ID;
diff --git a/interfaces/Java/jni/ppl_java_common.inlines.hh b/interfaces/Java/jni/ppl_java_common.inlines.hh
index 3bdf57a..286d438 100644
--- a/interfaces/Java/jni/ppl_java_common.inlines.hh
+++ b/interfaces/Java/jni/ppl_java_common.inlines.hh
@@ -244,11 +244,10 @@ Partial_Function::Partial_Function(jobject j_p_func, JNIEnv* env)
inline bool
Partial_Function::has_empty_codomain() const {
- jclass j_partial_function_class
- = env->FindClass("parma_polyhedra_library/Partial_Function");
- CHECK_RESULT_ASSERT(env, j_partial_function_class);
+ jclass j_p_func_class = env->GetObjectClass(j_p_func);
+ CHECK_RESULT_ASSERT(env, j_p_func_class);
jmethodID j_has_empty_codomain_id
- = env->GetMethodID(j_partial_function_class, "has_empty_codomain", "()Z");
+ = env->GetMethodID(j_p_func_class, "has_empty_codomain", "()Z");
CHECK_RESULT_ASSERT(env, j_has_empty_codomain_id);
bool ret = env->CallBooleanMethod(j_p_func, j_has_empty_codomain_id);
CHECK_EXCEPTION_THROW(env);
@@ -257,11 +256,10 @@ Partial_Function::has_empty_codomain() const {
inline dimension_type
Partial_Function::max_in_codomain() const {
- jclass j_partial_function_class
- = env->FindClass("parma_polyhedra_library/Partial_Function");
- CHECK_RESULT_ASSERT(env, j_partial_function_class);
+ jclass j_p_func_class = env->GetObjectClass(j_p_func);
+ CHECK_RESULT_ASSERT(env, j_p_func_class);
jmethodID j_max_in_codomain_id
- = env->GetMethodID(j_partial_function_class, "max_in_codomain", "()J");
+ = env->GetMethodID(j_p_func_class, "max_in_codomain", "()J");
CHECK_RESULT_ASSERT(env, j_max_in_codomain_id);
jlong value = env->CallLongMethod(j_p_func, j_max_in_codomain_id);
CHECK_EXCEPTION_THROW(env);
@@ -270,21 +268,21 @@ Partial_Function::max_in_codomain() const {
inline bool
Partial_Function::maps(dimension_type i, dimension_type& j) const {
- jclass j_partial_function_class
- = env->FindClass("parma_polyhedra_library/Partial_Function");
- CHECK_RESULT_ASSERT(env, j_partial_function_class);
+ jclass j_p_func_class = env->GetObjectClass(j_p_func);
+ CHECK_RESULT_ASSERT(env, j_p_func_class);
jobject coeff = j_long_to_j_long_class(env, 0);
jobject new_by_ref = env->NewObject(cached_classes.By_Reference,
cached_FMIDs.By_Reference_init_ID,
coeff);
CHECK_RESULT_THROW(env, new_by_ref);
jmethodID j_maps_id
- = env->GetMethodID(j_partial_function_class, "maps",
- "(Ljava/lang/Long;Lparma_polyhedra_library/By_Reference;)Z");
+ = env->GetMethodID(j_p_func_class, "maps",
+ "(Ljava/lang/Long;"
+ "Lparma_polyhedra_library/By_Reference;)Z");
CHECK_RESULT_ASSERT(env, j_maps_id);
jboolean b = env->CallBooleanMethod(j_p_func, j_maps_id,
- j_long_to_j_long_class(env, i),
- new_by_ref);
+ j_long_to_j_long_class(env, i),
+ new_by_ref);
CHECK_EXCEPTION_THROW(env);
if (b) {
jobject long_value = get_by_reference(env, new_by_ref);
diff --git a/interfaces/Java/jni/ppl_java_globals.cc b/interfaces/Java/jni/ppl_java_globals.cc
index f3f3177..e073fed 100644
--- a/interfaces/Java/jni/ppl_java_globals.cc
+++ b/interfaces/Java/jni/ppl_java_globals.cc
@@ -46,6 +46,7 @@ site: http://www.cs.unipr.it/ppl/ . */
#include "parma_polyhedra_library_MIP_Problem.h"
#include "parma_polyhedra_library_MIP_Problem_Status.h"
#include "parma_polyhedra_library_Optimization_Mode.h"
+#include "parma_polyhedra_library_Pair.h"
#include "parma_polyhedra_library_Parma_Polyhedra_Library.h"
#include "parma_polyhedra_library_Poly_Con_Relation.h"
#include "parma_polyhedra_library_Poly_Gen_Relation.h"
@@ -487,6 +488,18 @@ Java_parma_1polyhedra_1library_Optimization_1Mode_initIDs
}
JNIEXPORT void JNICALL
+Java_parma_1polyhedra_1library_Pair_initIDs
+(JNIEnv* env, jclass j_pair_class) {
+ jfieldID fID;
+ fID = env->GetFieldID(j_pair_class, "first", "Ljava/lang/Object;");
+ CHECK_RESULT_ASSERT(env, fID);
+ cached_FMIDs.Pair_first_ID = fID;
+ fID = env->GetFieldID(j_pair_class, "second", "Ljava/lang/Object;");
+ CHECK_RESULT_ASSERT(env, fID);
+ cached_FMIDs.Pair_second_ID = fID;
+}
+
+JNIEXPORT void JNICALL
Java_parma_1polyhedra_1library_Poly_1Con_1Relation_initIDs
(JNIEnv* env, jclass j_poly_con_relation_class) {
jmethodID mID;
diff --git a/interfaces/Java/parma_polyhedra_library/Makefile.am b/interfaces/Java/parma_polyhedra_library/Makefile.am
index efe1e18..65444da 100644
--- a/interfaces/Java/parma_polyhedra_library/Makefile.am
+++ b/interfaces/Java/parma_polyhedra_library/Makefile.am
@@ -58,6 +58,7 @@ parma_polyhedra_library.Linear_Expression_Variable \
parma_polyhedra_library.MIP_Problem \
parma_polyhedra_library.MIP_Problem_Status \
parma_polyhedra_library.Optimization_Mode \
+parma_polyhedra_library.Pair \
parma_polyhedra_library.Parma_Polyhedra_Library \
parma_polyhedra_library.Poly_Con_Relation \
parma_polyhedra_library.Poly_Gen_Relation \
@@ -92,6 +93,7 @@ parma_polyhedra_library_Linear_Expression_Variable.h \
parma_polyhedra_library_MIP_Problem.h \
parma_polyhedra_library_MIP_Problem_Status.h \
parma_polyhedra_library_Optimization_Mode.h \
+parma_polyhedra_library_Pair.h \
parma_polyhedra_library_Parma_Polyhedra_Library.h \
parma_polyhedra_library_Poly_Con_Relation.h \
parma_polyhedra_library_Poly_Gen_Relation.h \
@@ -232,8 +234,8 @@ MIP_Problem.class \
MIP_Problem_Status.class \
Optimization_Mode.class \
Overflow_Error_Exception.class \
-Parma_Polyhedra_Library.class \
Pair.class \
+Parma_Polyhedra_Library.class \
Partial_Function.class \
Poly_Con_Relation.class \
Poly_Gen_Relation.class \
diff --git a/interfaces/Java/parma_polyhedra_library/Pair.java b/interfaces/Java/parma_polyhedra_library/Pair.java
index 649d3f9..3682e37 100644
--- a/interfaces/Java/parma_polyhedra_library/Pair.java
+++ b/interfaces/Java/parma_polyhedra_library/Pair.java
@@ -43,4 +43,9 @@ public class Pair<K, V> {
public V getSecond() {
return second;
}
+
+ private static native void initIDs();
+ static {
+ initIDs();
+ }
}
More information about the PPL-devel
mailing list