diff --git a/src/jni/methods.h b/src/jni/methods.h new file mode 100644 index 0000000000..7401e30618 --- /dev/null +++ b/src/jni/methods.h @@ -0,0 +1,38 @@ +#ifndef GODOT_JVM_METHODS_H +#define GODOT_JVM_METHODS_H + +#include + +namespace jni { + typedef jmethodID MethodID; + + struct VoidMethodID { + jmethodID methodId = nullptr; + }; + + struct BooleanMethodID { + jmethodID methodId = nullptr; + }; + + struct IntMethodID { + jmethodID methodId = nullptr; + }; + + struct LongMethodID { + jmethodID methodId = nullptr; + }; + + struct FloatMethodID { + jmethodID methodId = nullptr; + }; + + struct DoubleMethodID { + jmethodID methodId = nullptr; + }; + + struct ObjectMethodID { + jmethodID methodId = nullptr; + }; +}// namespace jni + +#endif// GODOT_JVM_METHODS_H diff --git a/src/jni/types.cpp b/src/jni/types.cpp index 8018dc5151..cd5b7bc614 100644 --- a/src/jni/types.cpp +++ b/src/jni/types.cpp @@ -60,49 +60,26 @@ namespace jni { return obj == nullptr; } - jint JObject::call_int_method(Env& env, MethodId method, jvalue* args) const { - auto ret = env.env->CallIntMethodA((jclass) obj, method, args); - env.check_exceptions(); - return ret; - } - - jdouble JObject::call_double_method(Env& env, MethodId method, jvalue* args) const { - jdouble ret = env.env->CallDoubleMethodA((jclass) obj, method, args); - env.check_exceptions(); - return ret; - } - - jlong JObject::call_long_method(Env& env, MethodId method, jvalue* args) const { - auto ret = env.env->CallLongMethodA((jclass) obj, method, args); - env.check_exceptions(); - return ret; - } - - jboolean JObject::call_boolean_method(Env& env, MethodId method, jvalue* args) const { - auto ret = env.env->CallBooleanMethodA((jclass) obj, method, args); - env.check_exceptions(); - return ret; - } bool JObject::is_same_object(Env& env, const JObject& other) const { return env.is_same_object(obj, other.obj); } - MethodId JClass::get_method_id(Env& env, const char* name, const char* signature) { + MethodID JClass::get_method_id(Env& env, const char* name, const char* signature) { auto id = env.env->GetMethodID((jclass) obj, name, signature); JVM_CRASH_COND_MSG(id == nullptr, vformat("Method not found: %s with signature: %s", name, signature)); env.check_exceptions(); return id; } - MethodId JClass::get_static_method_id(Env& env, const char* name, const char* signature) { + MethodID JClass::get_static_method_id(Env& env, const char* name, const char* signature) { auto id = env.env->GetStaticMethodID((jclass) obj, name, signature); JVM_CRASH_COND_MSG(id == nullptr, vformat("Method not found: %s with signature: %s", name, signature)); env.check_exceptions(); return id; } - FieldId JClass::get_static_field_id(Env& env, const char* name, const char* signature) { + FieldID JClass::get_static_field_id(Env& env, const char* name, const char* signature) { auto id = env.env->GetStaticFieldID((jclass) obj, name, signature); JVM_CRASH_COND_MSG(id == nullptr, vformat("Field not found: %s with signature: %s", name, signature)); env.check_exceptions(); @@ -114,24 +91,24 @@ namespace jni { env.check_exceptions(); } - MethodId JClass::get_constructor_method_id(Env& env, const char* signature) { + MethodID JClass::get_constructor_method_id(Env& env, const char* signature) { return get_method_id(env, "", signature); } - JObject JClass::new_instance(Env& env, MethodId ctor, jvalue* args) { + JObject JClass::new_instance(Env& env, MethodID ctor, jvalue* args) { auto ret = env.env->NewObjectA((jclass) obj, ctor, args); JVM_CRASH_COND_MSG(ret == nullptr, "Failed to instantiated object!"); env.check_exceptions(); return JObject(ret); } - JObject JClass::call_static_object_method(Env& env, MethodId method, jvalue* args) { + JObject JClass::call_static_object_method(Env& env, MethodID method, jvalue* args) { auto ret = env.env->CallStaticObjectMethodA((jclass) obj, method, args); env.check_exceptions(); return JObject(ret); } - JObject JClass::get_static_object_field(Env& env, FieldId field) { + JObject JClass::get_static_object_field(Env& env, FieldID field) { auto value = env.env->GetStaticObjectField((jclass) obj, field); env.check_exceptions(); return JObject(value); diff --git a/src/jni/types.h b/src/jni/types.h index 7b63d1f15c..6d475c5050 100644 --- a/src/jni/types.h +++ b/src/jni/types.h @@ -2,6 +2,7 @@ #define GODOT_LOADER_JOBJECT_H #include "env.h" +#include "methods.h" #include #include @@ -35,8 +36,7 @@ namespace jni { JValue() = default; }; - typedef jmethodID MethodId; - typedef jfieldID FieldId; + typedef jfieldID FieldID; class JObject { public: @@ -64,60 +64,98 @@ namespace jni { void delete_local_ref(Env& p_env); template - void call_void_method(Env& env, MethodId method, jvalue* args = {}) const; + void call_void_method(Env& p_env, VoidMethodID method, jvalue* args = {}) const; template - JObject call_object_method(Env& env, MethodId method, jvalue* args = {}) const; + jboolean call_boolean_method(Env& p_env, BooleanMethodID method, jvalue* args = {}) const; - jint call_int_method(Env& env, MethodId method, jvalue* args = {}) const; + template + jint call_int_method(Env& p_env, IntMethodID method, jvalue* args = {}) const; + + template + jlong call_long_method(Env& p_env, LongMethodID method, jvalue* args = {}) const; - jlong call_long_method(Env& env, MethodId method, jvalue* args = {}) const; + template + jdouble call_float_method(Env& p_env, FloatMethodID method, jvalue* args = {}) const; - jdouble call_double_method(Env& env, MethodId method, jvalue* args = {}) const; + template + jdouble call_double_method(Env& p_env, DoubleMethodID method, jvalue* args = {}) const; - jboolean call_boolean_method(Env& env, MethodId method, jvalue* args = {}) const; + template + JObject call_object_method(Env& p_env, ObjectMethodID method, jvalue* args = {}) const; bool is_null(); bool is_same_object(Env& env, const JObject& other) const; }; - template - void JObject::call_void_method(Env& env, MethodId method, jvalue* args) const { - env.env->CallVoidMethodA((jclass) obj, method, args); #ifdef DEV_ENABLED - env.check_exceptions(); +#define CHECK_EXCEPTION_TEMPLATE p_env.check_exceptions() #else - if constexpr (CHECK_EXCEPTION){ - env.check_exceptions(); - } +#define CHECK_EXCEPTION_TEMPLATE \ + if constexpr (CHECK_EXCEPTION) { p_env.check_exceptions(); } \ + (void) 0 #endif + + template + void JObject::call_void_method(Env& p_env, VoidMethodID method, jvalue* args) const { + p_env.env->CallVoidMethodA((jobject) obj, method.methodId, args); + CHECK_EXCEPTION_TEMPLATE; } template - JObject JObject::call_object_method(Env& env, MethodId method, jvalue* args) const { - JObject ret = env.env->CallObjectMethodA((jclass) obj, method, args); -#ifdef DEV_ENABLED - env.check_exceptions(); -#else - if constexpr (CHECK_EXCEPTION){ - env.check_exceptions(); - } -#endif + jboolean JObject::call_boolean_method(Env& p_env, BooleanMethodID method, jvalue* args) const { + return p_env.env->CallBooleanMethodA((jobject) obj, method.methodId, args); + CHECK_EXCEPTION_TEMPLATE; + } + + template + jint JObject::call_int_method(Env& p_env, IntMethodID method, jvalue* args) const { + return p_env.env->CallIntMethodA((jobject) obj, method.methodId, args); + CHECK_EXCEPTION_TEMPLATE; + } + + template + jlong JObject::call_long_method(Env& p_env, LongMethodID method, jvalue* args) const { + return p_env.env->CallLongMethodA((jobject) obj, method.methodId, args); + CHECK_EXCEPTION_TEMPLATE; + } + + template + jdouble JObject::call_float_method(Env& p_env, FloatMethodID method, jvalue* args) const { + jdouble ret = p_env.env->CallFloatMethodA((jobject) obj, method.methodId, args); + CHECK_EXCEPTION_TEMPLATE; + return ret; + } + + template + jdouble JObject::call_double_method(Env& p_env, DoubleMethodID method, jvalue* args) const { + jdouble ret = p_env.env->CallDoubleMethodA((jobject) obj, method.methodId, args); + CHECK_EXCEPTION_TEMPLATE; return ret; } + template + JObject JObject::call_object_method(Env& p_env, ObjectMethodID method, jvalue* args) const { + return p_env.env->CallObjectMethodA((jobject) obj, method.methodId, args); + CHECK_EXCEPTION_TEMPLATE; + } + class JString : public JObject { public: JString() = default; + JString(jstring string) : JObject(string) {} + explicit JString(JObject jObject) : JObject(jObject) {}; }; class JArray : public JObject { public: JArray() = default; + JArray(jarray array) : JObject(array) {} + explicit JArray(JObject jObject) : JObject(jObject) {}; int length(Env& env); @@ -126,7 +164,9 @@ namespace jni { class JObjectArray : public JArray { public: JObjectArray() = default; + JObjectArray(jarray array) : JArray(array) {} + explicit JObjectArray(JObject jObject) : JArray(jObject) {}; void set(Env& env, int index, JObject value); @@ -138,7 +178,9 @@ namespace jni { public: JByteArray() = default; JByteArray(Env& env, jsize size = 0); + JByteArray(jbyteArray array) : JArray(array) {} + explicit JByteArray(JObject jObject) : JArray(jObject) {}; void get_array_elements(Env& env, jbyte* arr, jsize size); @@ -149,7 +191,9 @@ namespace jni { public: JIntArray() = default; JIntArray(Env& env, jsize size = 0); + JIntArray(jbyteArray array) : JArray(array) {} + explicit JIntArray(JObject jObject) : JArray(jObject) {}; void get_array_elements(Env& env, jint* arr, jsize size); @@ -160,7 +204,9 @@ namespace jni { public: JLongArray() = default; JLongArray(Env& env, jsize size = 0); + JLongArray(jbyteArray array) : JArray(array) {} + explicit JLongArray(JObject jObject) : JArray(jObject) {}; void get_array_elements(Env& env, jlong* arr, jsize size); @@ -171,7 +217,9 @@ namespace jni { public: JFloatArray() = default; JFloatArray(Env& env, jsize size = 0); + JFloatArray(jbyteArray array) : JArray(array) {} + explicit JFloatArray(JObject jObject) : JArray(jObject) {}; void get_array_elements(Env& env, jfloat* arr, jsize size); @@ -182,7 +230,9 @@ namespace jni { public: JDoubleArray() = default; JDoubleArray(Env& env, jsize size = 0); + JDoubleArray(jbyteArray array) : JArray(array) {} + explicit JDoubleArray(JObject jObject) : JArray(jObject) {}; void get_array_elements(Env& env, jdouble* arr, jsize size); @@ -203,23 +253,23 @@ namespace jni { JClass() : JClass((jclass) nullptr) {} - JObject new_instance(Env& env, MethodId ctor, jvalue* args = {}); + JObject new_instance(Env& env, MethodID ctor, jvalue* args = {}); JObjectArray new_object_array(Env& env, int size, JObject initial = {}); - MethodId get_constructor_method_id(Env& env, const char* signature); + MethodID get_constructor_method_id(Env& env, const char* signature); - MethodId get_method_id(Env& env, const char* name, const char* signature); + MethodID get_method_id(Env& env, const char* name, const char* signature); - MethodId get_static_method_id(Env& env, const char* name, const char* signature); + MethodID get_static_method_id(Env& env, const char* name, const char* signature); - FieldId get_static_field_id(Env& env, const char* name, const char* signature); + FieldID get_static_field_id(Env& env, const char* name, const char* signature); void register_natives(Env& env, Vector methods); - JObject call_static_object_method(Env& env, MethodId method, jvalue* args = {}); + JObject call_static_object_method(Env& env, MethodID method, jvalue* args = {}); - JObject get_static_object_field(Env& env, FieldId field); + JObject get_static_object_field(Env& env, FieldID field); bool is_assignable_from(Env& env, JClass p_other) const; }; diff --git a/src/jvm_wrapper/bootstrap.cpp b/src/jvm_wrapper/bootstrap.cpp index 2033f6adc6..fcf1e2607e 100644 --- a/src/jvm_wrapper/bootstrap.cpp +++ b/src/jvm_wrapper/bootstrap.cpp @@ -50,7 +50,7 @@ void Bootstrap::init(jni::Env& p_env, const String& p_project_path, const String jni::JObject project_path = p_env.new_string(p_project_path.utf8().get_data()); jni::JObject jar_file {p_env.new_string(p_jar_file.utf8().get_data())}; jvalue args[3] = {jni::to_jni_arg(project_path), jni::to_jni_arg(jar_file), jni::to_jni_arg(p_class_loader)}; - wrapped.call_void_method(p_env, INIT, args); + wrapped.call_object_method(p_env, INIT, args); } void Bootstrap::finish(jni::Env& p_env) { diff --git a/src/jvm_wrapper/bootstrap.h b/src/jvm_wrapper/bootstrap.h index 1cba305f75..3aece7bee7 100644 --- a/src/jvm_wrapper/bootstrap.h +++ b/src/jvm_wrapper/bootstrap.h @@ -7,8 +7,8 @@ JVM_INSTANCE_WRAPPER(Bootstrap, "godot.runtime.Bootstrap") { JVM_CLASS(Bootstrap) // clang-format off - JNI_METHOD(INIT) - JNI_METHOD(FINISH) + JNI_OBJECT_METHOD(INIT) + JNI_VOID_METHOD(FINISH) INIT_JNI_BINDINGS( INIT_JNI_METHOD(INIT, "init", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)V") diff --git a/src/jvm_wrapper/bridge/callable_bridge.cpp b/src/jvm_wrapper/bridge/callable_bridge.cpp index 503adb9d1b..0d25b453df 100644 --- a/src/jvm_wrapper/bridge/callable_bridge.cpp +++ b/src/jvm_wrapper/bridge/callable_bridge.cpp @@ -2,8 +2,8 @@ #include "bridges_utils.h" #include "constraints.h" +#include "jvm_wrapper/kotlin_callable_custom.h" #include "jvm_wrapper/memory/transfer_context.h" -#include "kotlin_callable_custom.h" using namespace bridges; diff --git a/src/jvm_wrapper/bridge/gd_print_bridge.h b/src/jvm_wrapper/bridge/gd_print_bridge.h index 83f097f67a..14515f8e41 100644 --- a/src/jvm_wrapper/bridge/gd_print_bridge.h +++ b/src/jvm_wrapper/bridge/gd_print_bridge.h @@ -9,7 +9,7 @@ namespace bridges { SINGLETON_CLASS(GDPrintBridge) // clang-format off - JNI_METHOD(PRINT_STACKTRACE) + JNI_OBJECT_METHOD(PRINT_STACKTRACE) INIT_JNI_BINDINGS( INIT_JNI_METHOD(PRINT_STACKTRACE, "getStacktrace", "()Ljava/lang/String;") diff --git a/src/jvm_wrapper/bridge/kt_callable_bridge.cpp b/src/jvm_wrapper/bridge/kt_callable_bridge.cpp index d2f9aaaff0..edd2d6bc7a 100644 --- a/src/jvm_wrapper/bridge/kt_callable_bridge.cpp +++ b/src/jvm_wrapper/bridge/kt_callable_bridge.cpp @@ -1,5 +1,6 @@ #include "kt_callable_bridge.h" -#include "kotlin_callable_custom.h" + +#include "jvm_wrapper/kotlin_callable_custom.h" using namespace bridges; diff --git a/src/jvm_wrapper/bridge/node_path_bridge.h b/src/jvm_wrapper/bridge/node_path_bridge.h index 6ace19a732..97ff17cb64 100644 --- a/src/jvm_wrapper/bridge/node_path_bridge.h +++ b/src/jvm_wrapper/bridge/node_path_bridge.h @@ -8,7 +8,6 @@ namespace bridges { JVM_SINGLETON_WRAPPER(NodePathBridge, "godot.core.NodePath$Bridge") { SINGLETON_CLASS(NodePathBridge) - // clang-format off INIT_JNI_BINDINGS( INIT_NATIVE_METHOD("engine_call_constructor", "()J", NodePathBridge::engine_call_constructor) diff --git a/src/jvm_wrapper/jvm_instance_wrapper.h b/src/jvm_wrapper/jvm_instance_wrapper.h index 53d3578b79..76657ad6c2 100644 --- a/src/jvm_wrapper/jvm_instance_wrapper.h +++ b/src/jvm_wrapper/jvm_instance_wrapper.h @@ -1,6 +1,7 @@ #ifndef GODOT_JVM_JVM_INSTANCE_WRAPPER_H #define GODOT_JVM_JVM_INSTANCE_WRAPPER_H +#include "jni/methods.h" #include "jni/wrapper.h" #include "lifecycle/class_loader.h" @@ -12,9 +13,16 @@ friend class JvmInstanceWrapper; \ static inline constexpr const char* fq_name = NAME##QualifiedName; -#define JNI_METHOD(var_name) inline static jni::MethodId var_name {nullptr}; +#define JNI_VOID_METHOD(var_name) inline static jni::VoidMethodID var_name; +#define JNI_BOOLEAN_METHOD(var_name) inline static jni::BooleanMethodID var_name; +#define JNI_INT_METHOD(var_name) inline static jni::IntMethodID var_name; +#define JNI_LONG_METHOD(var_name) inline static jni::LongMethodID var_name; +#define JNI_FLOAT_METHOD(var_name) inline static jni::FloatMethodID var_name; +#define JNI_DOUBLE_METHOD(var_name) inline static jni::DoubleMethodID var_name; +#define JNI_OBJECT_METHOD(var_name) inline static jni::ObjectMethodID var_name; -#define INIT_JNI_METHOD(var_name, name, signature) var_name = clazz.get_method_id(p_env, name, signature); + +#define INIT_JNI_METHOD(var_name, name, signature) var_name.methodId = clazz.get_method_id(p_env, name, signature); #define INIT_NATIVE_METHOD(string_name, signature, function) \ methods.push_back({const_cast(string_name), const_cast(signature), (void*) function}); @@ -82,7 +90,7 @@ Derived* JvmInstanceWrapper::create_instance(jni::Env& p_env, C } else { cls = p_env.find_class(FqName); } - jni::MethodId ctor = cls.get_constructor_method_id(p_env, "()V"); + jni::MethodID ctor = cls.get_constructor_method_id(p_env, "()V"); jni::JObject instance = cls.new_instance(p_env, ctor); return new Derived(p_env, instance); } diff --git a/src/jvm_wrapper/jvm_singleton_wrapper.h b/src/jvm_wrapper/jvm_singleton_wrapper.h index d037c300f9..7666bd5663 100644 --- a/src/jvm_wrapper/jvm_singleton_wrapper.h +++ b/src/jvm_wrapper/jvm_singleton_wrapper.h @@ -80,7 +80,7 @@ bool JvmSingletonWrapper::initialize(jni::Env& p_env, ClassLoad } else { singleton_cls = p_env.find_class(FqName); } - jni::FieldId singleton_instance_field = + jni::FieldID singleton_instance_field = singleton_cls.get_static_field_id(p_env, "INSTANCE", vformat("L%s;", FqName).replace(".", "/").utf8().ptr()); jni::JObject singleton_instance = singleton_cls.get_static_object_field(p_env, singleton_instance_field); diff --git a/src/kotlin_callable_custom.cpp b/src/jvm_wrapper/kotlin_callable_custom.cpp similarity index 100% rename from src/kotlin_callable_custom.cpp rename to src/jvm_wrapper/kotlin_callable_custom.cpp diff --git a/src/kotlin_callable_custom.h b/src/jvm_wrapper/kotlin_callable_custom.h similarity index 92% rename from src/kotlin_callable_custom.h rename to src/jvm_wrapper/kotlin_callable_custom.h index d89da882db..6a191430d4 100644 --- a/src/kotlin_callable_custom.h +++ b/src/jvm_wrapper/kotlin_callable_custom.h @@ -1,7 +1,6 @@ #ifndef GODOT_JVM_KOTLIN_CALLABLE_CUSTOM_H #define GODOT_JVM_KOTLIN_CALLABLE_CUSTOM_H - #include "jvm_wrapper/jvm_instance_wrapper.h" #include "core/variant/callable.h" @@ -9,10 +8,10 @@ JVM_INSTANCE_WRAPPER(KtCallable, "godot.core.callable.KtCallable") { JVM_CLASS(KtCallable) // clang-format off - JNI_METHOD(INVOKE_NO_RETURN) - JNI_METHOD(INVOKE_WITH_RETURN) - JNI_METHOD(GET_RETURN_VARIANT_TYPE) - JNI_METHOD(HASH_CODE) + JNI_VOID_METHOD(INVOKE_NO_RETURN) + JNI_OBJECT_METHOD(INVOKE_WITH_RETURN) + JNI_INT_METHOD(GET_RETURN_VARIANT_TYPE) + JNI_INT_METHOD(HASH_CODE) INIT_JNI_BINDINGS( INIT_JNI_METHOD(INVOKE_NO_RETURN, "invokeNoReturn", "()V") diff --git a/src/jvm_wrapper/memory/long_string_queue.h b/src/jvm_wrapper/memory/long_string_queue.h index c727ea4de1..1aa14d06a5 100644 --- a/src/jvm_wrapper/memory/long_string_queue.h +++ b/src/jvm_wrapper/memory/long_string_queue.h @@ -6,8 +6,8 @@ JVM_SINGLETON_WRAPPER(LongStringQueue, "godot.core.LongStringQueue") { SINGLETON_CLASS(LongStringQueue) // clang-format off - JNI_METHOD(QUEUE_STRING) - JNI_METHOD(SET_STRING_MAX_SIZE) + JNI_VOID_METHOD(QUEUE_STRING) + JNI_VOID_METHOD(SET_STRING_MAX_SIZE) INIT_JNI_BINDINGS( INIT_JNI_METHOD(QUEUE_STRING, "queueString", "(Ljava/lang/String;)V") diff --git a/src/jvm_wrapper/memory/memory_manager.cpp b/src/jvm_wrapper/memory/memory_manager.cpp index be3bd81598..ef81b938ec 100644 --- a/src/jvm_wrapper/memory/memory_manager.cpp +++ b/src/jvm_wrapper/memory/memory_manager.cpp @@ -184,7 +184,7 @@ void MemoryManager::sync_memory(jni::Env& p_env) { void MemoryManager::clean_up(jni::Env& p_env) { LOG_VERBOSE("Cleaning JVM Memory...") - wrapped.call_boolean_method(p_env, CLEAN_UP); + wrapped.call_void_method(p_env, CLEAN_UP); LOG_VERBOSE("JVM Memory cleaned!") } diff --git a/src/jvm_wrapper/memory/memory_manager.h b/src/jvm_wrapper/memory/memory_manager.h index df00a9ac8f..29aa598345 100644 --- a/src/jvm_wrapper/memory/memory_manager.h +++ b/src/jvm_wrapper/memory/memory_manager.h @@ -12,11 +12,10 @@ JVM_SINGLETON_WRAPPER(MemoryManager, "godot.core.memory.MemoryManager") { SINGLETON_CLASS(MemoryManager) - JNI_METHOD(SYNC_MEMORY) - JNI_METHOD(SET_DISPLAY) - JNI_METHOD(CLEAN_UP) - JNI_METHOD(REMOVE_SCRIPT) - JNI_METHOD(DELETE_OBJECT) + JNI_OBJECT_METHOD(SYNC_MEMORY) + JNI_VOID_METHOD(CLEAN_UP) + JNI_VOID_METHOD(REMOVE_SCRIPT) + JNI_VOID_METHOD(DELETE_OBJECT) INIT_JNI_BINDINGS( INIT_JNI_METHOD(SYNC_MEMORY, "syncMemory", "([J)[J") diff --git a/src/jvm_wrapper/memory/transfer_context.h b/src/jvm_wrapper/memory/transfer_context.h index 372bc24c6f..1374c3fed4 100644 --- a/src/jvm_wrapper/memory/transfer_context.h +++ b/src/jvm_wrapper/memory/transfer_context.h @@ -8,7 +8,7 @@ JVM_SINGLETON_WRAPPER(TransferContext, "godot.core.memory.TransferContext") { SINGLETON_CLASS(TransferContext) - JNI_METHOD(GET_BUFFER) + JNI_OBJECT_METHOD(GET_BUFFER) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_BUFFER, "getBuffer", "()Ljava/nio/ByteBuffer;") diff --git a/src/jvm_wrapper/registration/kt_class.h b/src/jvm_wrapper/registration/kt_class.h index bae9657f86..cb55f84073 100644 --- a/src/jvm_wrapper/registration/kt_class.h +++ b/src/jvm_wrapper/registration/kt_class.h @@ -16,17 +16,17 @@ JVM_INSTANCE_WRAPPER(KtClass, "godot.core.KtClass") { JVM_CLASS(KtClass) // clang-format off - JNI_METHOD(GET_REGISTERED_NAME) - JNI_METHOD(GET_RELATIVE_SOURCE_PATH) - JNI_METHOD(GET_COMPILATION_TIME_RELATIVE_REGISTRATION_FILE_PATH) - JNI_METHOD(GET_REGISTERED_SUPERTYPES) - JNI_METHOD(GET_BASE_GODOT_CLASS) - JNI_METHOD(GET_FUNCTIONS) - JNI_METHOD(GET_PROPERTIES) - JNI_METHOD(GET_SIGNAL_INFOS) - JNI_METHOD(GET_CONSTRUCTORS) - JNI_METHOD(GET_HAS_NOTIFICATION) - JNI_METHOD(DO_NOTIFICATION) + JNI_OBJECT_METHOD(GET_REGISTERED_NAME) + JNI_OBJECT_METHOD(GET_RELATIVE_SOURCE_PATH) + JNI_OBJECT_METHOD(GET_COMPILATION_TIME_RELATIVE_REGISTRATION_FILE_PATH) + JNI_OBJECT_METHOD(GET_REGISTERED_SUPERTYPES) + JNI_OBJECT_METHOD(GET_BASE_GODOT_CLASS) + JNI_OBJECT_METHOD(GET_FUNCTIONS) + JNI_OBJECT_METHOD(GET_PROPERTIES) + JNI_OBJECT_METHOD(GET_SIGNAL_INFOS) + JNI_OBJECT_METHOD(GET_CONSTRUCTORS) + JNI_BOOLEAN_METHOD(GET_HAS_NOTIFICATION) + JNI_VOID_METHOD(DO_NOTIFICATION) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_REGISTERED_NAME, "getRegisteredName", "()Ljava/lang/String;") diff --git a/src/jvm_wrapper/registration/kt_constructor.h b/src/jvm_wrapper/registration/kt_constructor.h index 39c8a3e8a2..1da523a824 100644 --- a/src/jvm_wrapper/registration/kt_constructor.h +++ b/src/jvm_wrapper/registration/kt_constructor.h @@ -8,8 +8,8 @@ JVM_INSTANCE_WRAPPER(KtConstructor, "godot.core.KtConstructor") { JVM_CLASS(KtConstructor) // clang-format off - JNI_METHOD(GET_PARAMETER_COUNT) - JNI_METHOD(CONSTRUCT) + JNI_INT_METHOD(GET_PARAMETER_COUNT) + JNI_OBJECT_METHOD(CONSTRUCT) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_PARAMETER_COUNT, "getParameterCount", "()I") diff --git a/src/jvm_wrapper/registration/kt_function.h b/src/jvm_wrapper/registration/kt_function.h index 177ec3904d..304789163b 100644 --- a/src/jvm_wrapper/registration/kt_function.h +++ b/src/jvm_wrapper/registration/kt_function.h @@ -10,10 +10,10 @@ JVM_INSTANCE_WRAPPER(KtFunctionInfo, "godot.core.KtFunctionInfo") { JVM_CLASS(KtFunctionInfo) // clang-format off - JNI_METHOD(GET_NAME) - JNI_METHOD(GET_ARGUMENTS) - JNI_METHOD(GET_RETURN_VAL) - JNI_METHOD(GET_RPC_CONFIG) + JNI_OBJECT_METHOD(GET_NAME) + JNI_OBJECT_METHOD(GET_ARGUMENTS) + JNI_OBJECT_METHOD(GET_RETURN_VAL) + JNI_OBJECT_METHOD(GET_RPC_CONFIG) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_NAME, "getName", "()Ljava/lang/String;") @@ -39,10 +39,10 @@ JVM_INSTANCE_WRAPPER(KtFunction, "godot.core.KtFunction") { JVM_CLASS(KtFunction) // clang-format off - JNI_METHOD(GET_FUNCTION_INFO) - JNI_METHOD(GET_PARAMETER_COUNT) - JNI_METHOD(INVOKE) - JNI_METHOD(INVOKE_WITH_RETURN) + JNI_OBJECT_METHOD(GET_FUNCTION_INFO) + JNI_INT_METHOD(GET_PARAMETER_COUNT) + JNI_VOID_METHOD(INVOKE) + JNI_OBJECT_METHOD(INVOKE_WITH_RETURN) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_FUNCTION_INFO, "getFunctionInfo", "()Lgodot/core/KtFunctionInfo;") diff --git a/src/jvm_wrapper/registration/kt_object.h b/src/jvm_wrapper/registration/kt_object.h index fd67fff025..5e1bc17475 100644 --- a/src/jvm_wrapper/registration/kt_object.h +++ b/src/jvm_wrapper/registration/kt_object.h @@ -11,7 +11,7 @@ JVM_INSTANCE_WRAPPER(KtObject, "godot.core.KtObject") { JVM_CLASS(KtObject) // clang-format off - JNI_METHOD(ON_DESTROY) + JNI_VOID_METHOD(ON_DESTROY) INIT_JNI_BINDINGS( INIT_JNI_METHOD(ON_DESTROY, "_onDestroy", "()V") diff --git a/src/jvm_wrapper/registration/kt_property.h b/src/jvm_wrapper/registration/kt_property.h index 10e2456f6e..fa00ce95c0 100644 --- a/src/jvm_wrapper/registration/kt_property.h +++ b/src/jvm_wrapper/registration/kt_property.h @@ -10,12 +10,12 @@ JVM_INSTANCE_WRAPPER(KtPropertyInfo, "godot.core.KtPropertyInfo") { JVM_CLASS(KtPropertyInfo) // clang-format off - JNI_METHOD(GET_TYPE) - JNI_METHOD(GET_NAME) - JNI_METHOD(GET_CLASS_NAME) - JNI_METHOD(GET_HINT) - JNI_METHOD(GET_HINT_STRING) - JNI_METHOD(GET_USAGE) + JNI_INT_METHOD(GET_TYPE) + JNI_OBJECT_METHOD(GET_NAME) + JNI_OBJECT_METHOD(GET_CLASS_NAME) + JNI_INT_METHOD(GET_HINT) + JNI_OBJECT_METHOD(GET_HINT_STRING) + JNI_LONG_METHOD(GET_USAGE) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_TYPE, "getType", "()I") @@ -47,10 +47,9 @@ JVM_INSTANCE_WRAPPER(KtProperty, "godot.core.KtProperty") { JVM_CLASS(KtProperty) // clang-format off - JNI_METHOD(GET_KT_PROPERTY_INFO) - JNI_METHOD(IS_REF) - JNI_METHOD(CALL_GET) - JNI_METHOD(CALL_SET) + JNI_OBJECT_METHOD(GET_KT_PROPERTY_INFO) + JNI_VOID_METHOD(CALL_GET) + JNI_VOID_METHOD(CALL_SET) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_KT_PROPERTY_INFO, "getKtPropertyInfo", "()Lgodot/core/KtPropertyInfo;") diff --git a/src/jvm_wrapper/registration/kt_rpc_config.h b/src/jvm_wrapper/registration/kt_rpc_config.h index b292c89509..f665daeaee 100644 --- a/src/jvm_wrapper/registration/kt_rpc_config.h +++ b/src/jvm_wrapper/registration/kt_rpc_config.h @@ -10,10 +10,10 @@ JVM_INSTANCE_WRAPPER(KtRpcConfig, "godot.core.KtRpcConfig") { JVM_CLASS(KtRpcConfig) // clang-format off - JNI_METHOD(GET_RPC_MODE_ID) - JNI_METHOD(GET_RPC_CALL_LOCAL) - JNI_METHOD(GET_RPC_TRANSFER_MODE_ID) - JNI_METHOD(GET_RPC_CHANNEL) + JNI_INT_METHOD(GET_RPC_MODE_ID) + JNI_BOOLEAN_METHOD(GET_RPC_CALL_LOCAL) + JNI_INT_METHOD(GET_RPC_TRANSFER_MODE_ID) + JNI_INT_METHOD(GET_RPC_CHANNEL) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_RPC_MODE_ID, "getRpcModeId", "()I") diff --git a/src/jvm_wrapper/registration/kt_signal_info.h b/src/jvm_wrapper/registration/kt_signal_info.h index c9905f37ab..b21b48ff8b 100644 --- a/src/jvm_wrapper/registration/kt_signal_info.h +++ b/src/jvm_wrapper/registration/kt_signal_info.h @@ -9,8 +9,8 @@ JVM_INSTANCE_WRAPPER(KtSignalInfo, "godot.core.KtSignalInfo") { JVM_CLASS(KtSignalInfo) // clang-format off - JNI_METHOD(GET_NAME) - JNI_METHOD(GET_ARGUMENTS) + JNI_OBJECT_METHOD(GET_NAME) + JNI_OBJECT_METHOD(GET_ARGUMENTS) INIT_JNI_BINDINGS( INIT_JNI_METHOD(GET_NAME, "getName", "()Ljava/lang/String;") diff --git a/src/lifecycle/class_loader.cpp b/src/lifecycle/class_loader.cpp index f334f36c81..d133d9b12d 100644 --- a/src/lifecycle/class_loader.cpp +++ b/src/lifecycle/class_loader.cpp @@ -1,5 +1,7 @@ #include "class_loader.h" +#include "jni/methods.h" + #ifdef __ANDROID__ #include #endif @@ -19,13 +21,13 @@ ClassLoader::~ClassLoader() { #ifndef __ANDROID__ jni::JObject to_java_url(jni::Env& env, const String& bootstrapJar) { jni::JClass cls {env.find_class("java/io/File")}; - jni::MethodId ctor {cls.get_constructor_method_id(env, "(Ljava/lang/String;)V")}; + jni::MethodID ctor {cls.get_constructor_method_id(env, "(Ljava/lang/String;)V")}; jni::JObject path {env.new_string(bootstrapJar.utf8().get_data())}; jvalue args[1] = {jni::to_jni_arg(path)}; jni::JObject file {cls.new_instance(env, ctor, args)}; assert(!file.is_null()); - jni::MethodId to_url_method {cls.get_method_id(env, "toURL", "()Ljava/net/URL;")}; + jni::ObjectMethodID to_url_method {cls.get_method_id(env, "toURL", "()Ljava/net/URL;")}; jni::JObject url {file.call_object_method(env, to_url_method)}; assert(!url.is_null()); @@ -39,7 +41,7 @@ ClassLoader* ClassLoader::create_instance(jni::Env& env, const String& full_jar_ chmod(full_jar_path.utf8().get_data(), S_IRUSR | S_IRGRP | S_IROTH); jni::JClass class_loader_cls {env.find_class("dalvik/system/DexClassLoader")}; - jni::MethodId ctor {class_loader_cls.get_constructor_method_id(env, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)V") + jni::MethodID ctor {class_loader_cls.get_constructor_method_id(env, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)V") }; jni::JObject jar_path {env.new_string(full_jar_path.utf8().get_data())}; jvalue args[4] = { @@ -53,7 +55,7 @@ ClassLoader* ClassLoader::create_instance(jni::Env& env, const String& full_jar_ jni::JClass url_cls = env.find_class("java/net/URL"); jni::JObjectArray urls = url_cls.new_object_array(env, 1, {url}); jni::JClass class_loader_cls = env.find_class("java/net/URLClassLoader"); - jni::MethodId ctor = class_loader_cls.get_constructor_method_id(env, "([Ljava/net/URL;Ljava/lang/ClassLoader;)V"); + jni::MethodID ctor = class_loader_cls.get_constructor_method_id(env, "([Ljava/net/URL;Ljava/lang/ClassLoader;)V"); jvalue args[2] = {jni::to_jni_arg(urls), jni::to_jni_arg(p_parent_loader)}; #endif jni::JObject class_loader = class_loader_cls.new_instance(env, ctor, args); @@ -62,11 +64,11 @@ ClassLoader* ClassLoader::create_instance(jni::Env& env, const String& full_jar_ } jni::JClass ClassLoader::load_class(jni::Env& env, const char* name) { - static jmethodID loadClassMethodId; + static jni::ObjectMethodID loadClassMethodId; - if (loadClassMethodId == nullptr) { + if (loadClassMethodId.methodId == nullptr) { auto cls = env.find_class("java/lang/ClassLoader"); - loadClassMethodId = cls.get_method_id(env, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); + loadClassMethodId.methodId = cls.get_method_id(env, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); } jvalue args[1] = {static_cast(env.new_string(name)).value}; jni::JObject ret = wrapped.call_object_method(env, loadClassMethodId, args); @@ -75,14 +77,14 @@ jni::JClass ClassLoader::load_class(jni::Env& env, const char* name) { void ClassLoader::set_as_context_loader(jni::Env& env) { jni::JClass cls {env.find_class("java/lang/Thread")}; - jni::MethodId current_thread_method {cls.get_static_method_id(env, "currentThread", "()Ljava/lang/Thread;")}; - jni::JObject thread {cls.call_static_object_method(env, current_thread_method)}; + jni::ObjectMethodID current_thread_method {cls.get_static_method_id(env, "currentThread", "()Ljava/lang/Thread;")}; + jni::JObject thread {cls.call_static_object_method(env, current_thread_method.methodId)}; assert(!thread.is_null()); - _jmethodID* setContextClassLoaderMethod {cls.get_method_id(env, "setContextClassLoader", "(Ljava/lang/ClassLoader;)V")}; + jni::VoidMethodID setContextClassLoaderMethod {cls.get_method_id(env, "setContextClassLoader", "(Ljava/lang/ClassLoader;)V")}; jvalue args[1] = {jni::to_jni_arg(wrapped)}; - thread.call_void_method(env, setContextClassLoaderMethod, args); + wrapped.call_void_method(env, setContextClassLoaderMethod, args); } const jni::JObject& ClassLoader::get_wrapped() const { diff --git a/src/lifecycle/jvm_manager.cpp b/src/lifecycle/jvm_manager.cpp index dc0a348cfd..341a7d0377 100644 --- a/src/lifecycle/jvm_manager.cpp +++ b/src/lifecycle/jvm_manager.cpp @@ -4,6 +4,7 @@ #include "jvm_wrapper/bridge/callable_bridge.h" #include "jvm_wrapper/bridge/dictionary_bridge.h" #include "jvm_wrapper/bridge/gd_print_bridge.h" +#include "jvm_wrapper/bridge/kt_callable_bridge.h" #include "jvm_wrapper/bridge/node_path_bridge.h" #include "jvm_wrapper/bridge/packed_array_bridge.h" #include "jvm_wrapper/bridge/packed_byte_array_bridge.h" @@ -15,14 +16,14 @@ #include "jvm_wrapper/bridge/packed_string_array_bridge.h" #include "jvm_wrapper/bridge/packed_vector2_array_bridge.h" #include "jvm_wrapper/bridge/packed_vector3_array_bridge.h" +#include "jvm_wrapper/bridge/packed_vector4_array_bridge.h" #include "jvm_wrapper/bridge/string_name_bridge.h" #include "jvm_wrapper/bridge/variant_array_bridge.h" +#include "jvm_wrapper/kotlin_callable_custom.h" #include "jvm_wrapper/memory/memory_manager.h" -#include "kotlin_callable_custom.h" -#include "jvm_wrapper/bridge/kt_callable_bridge.h" -#include "jvm_wrapper/bridge/packed_vector4_array_bridge.h" #include + #include #ifdef __ANDROID__