summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-05-29 03:49:42 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2018-05-29 03:49:42 +0300
commitdd9ffa55195ee6313bed3b505dc3c6769b92d360 (patch)
tree8b4be1273d2bf8b3fa3d8d61f7255209a0de3ffe
parent5c6008117bc4984719b058676182696d93bd1946 (diff)
jvm: superclass hack
Tries call method from generic java object or class if implementation is not found for the topmost level.
-rw-r--r--src/jvm/jvm.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/jvm/jvm.c b/src/jvm/jvm.c
index b52af46..914224c 100644
--- a/src/jvm/jvm.c
+++ b/src/jvm/jvm.c
@@ -525,10 +525,9 @@ JNIEnv_IsInstanceOf(JNIEnv* p0, jobject p1, jclass p2)
}
static void
-jvm_form_symbol(struct jvm *jvm, jmethodID method_id, char *symbol, const size_t symbol_sz)
+jvm_form_symbol(struct jvm *jvm, const struct jvm_method *method, char *symbol, const size_t symbol_sz)
{
- assert(jvm && method_id);
- struct jvm_method *method = &jvm_get_object_of_type(jvm, method_id, JVM_OBJECT_METHOD)->method;
+ assert(jvm && method);
verbose("%s::%s::%s", jvm_get_object_of_type(jvm, method->klass, JVM_OBJECT_CLASS)->klass.name.data, method->name.data, method->signature.data);
snprintf(symbol, symbol_sz, "%s_%s", jvm_get_object_of_type(jvm, method->klass, JVM_OBJECT_CLASS)->klass.name.data, method->name.data);
cstr_replace(symbol, '/', '_');
@@ -539,7 +538,21 @@ static void*
jvm_wrap_method(struct jvm *jvm, jmethodID method_id)
{
char symbol[255];
- jvm_form_symbol(jvm, method_id, symbol, sizeof(symbol));
+ struct jvm_method method = jvm_get_object_of_type(jvm, method_id, JVM_OBJECT_METHOD)->method;
+ jvm_form_symbol(jvm, &method, symbol, sizeof(symbol));
+
+ void *sym;
+ if ((sym = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol))))
+ return sym;
+
+ method.klass = jvm_make_class(jvm, "java/lang/Object");
+ jvm_form_symbol(jvm, &method, symbol, sizeof(symbol));
+
+ if ((sym = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol))))
+ return sym;
+
+ method.klass = jvm_make_class(jvm, "java/lang/Class");
+ jvm_form_symbol(jvm, &method, symbol, sizeof(symbol));
return wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
}