From cf4bdd948401d6320dd142d3945a212774019425 Mon Sep 17 00:00:00 2001 From: Ced Naru Date: Tue, 17 Sep 2024 01:54:38 +0200 Subject: [PATCH] Rework logging --- src/editor/godot_kotlin_jvm_editor.cpp | 9 +- src/gd_kotlin.cpp | 30 +++---- src/jni/env.cpp | 7 +- src/jni/env.h | 8 -- src/jni/jvm.cpp | 6 +- src/jni/types.cpp | 10 +-- src/jni/types.h | 11 +-- src/jvm_wrapper/bootstrap.cpp | 8 +- src/jvm_wrapper/bootstrap.h | 2 +- src/jvm_wrapper/jvm_instance_wrapper.h | 7 +- src/jvm_wrapper/jvm_singleton_wrapper.h | 3 +- src/jvm_wrapper/memory/memory_manager.cpp | 4 +- src/jvm_wrapper/memory/transfer_context.cpp | 6 +- src/jvm_wrapper/memory/type_manager.cpp | 13 +-- src/jvm_wrapper/registration/kt_class.cpp | 22 ++--- src/kotlin_editor_export_plugin.cpp | 29 +++--- src/lifecycle/jvm_manager.cpp | 12 +-- src/lifecycle/jvm_options.cpp | 2 +- src/lifecycle/jvm_user_configuration.cpp | 89 +++++++++---------- src/logging.h | 69 +++++++------- .../jvm_resource_format_saver.cpp | 2 +- src/script/jvm_script.cpp | 6 +- src/script/jvm_script_manager.cpp | 8 +- src/script/jvm_script_manager.h | 4 +- 24 files changed, 166 insertions(+), 201 deletions(-) diff --git a/src/editor/godot_kotlin_jvm_editor.cpp b/src/editor/godot_kotlin_jvm_editor.cpp index 6b09ee5f3c..2fc4a48551 100644 --- a/src/editor/godot_kotlin_jvm_editor.cpp +++ b/src/editor/godot_kotlin_jvm_editor.cpp @@ -16,7 +16,7 @@ void GodotKotlinJvmEditor::on_file_system_dock_file_moved(// NOLINT(readability- const String& new_file ) { if (file.ends_with(String(".") + GODOT_JVM_REGISTRATION_FILE_EXTENSION)) { - LOG_WARNING( + JVM_WARNING( vformat("You should not move registration files in the godot editor! Use the IDE for that. File moved: %s -> %s", file, new_file) ); } @@ -26,7 +26,7 @@ void GodotKotlinJvmEditor::on_file_system_dock_file_removed(// NOLINT(readabilit const String& file ) { if (file.ends_with(String(".") + GODOT_JVM_REGISTRATION_FILE_EXTENSION)) { - LOG_WARNING(vformat("You should not remove registration files in the godot editor! Use the IDE for that. File removed: %s", file)); + JVM_WARNING("You should not remove registration files in the godot editor! Use the IDE for that. File removed: %s", file); } } @@ -38,8 +38,7 @@ void GodotKotlinJvmEditor::on_file_system_dock_folder_moved(// NOLINT(readabilit String file_path = dir_access->get_next(); while (!file_path.is_empty()) { if (file_path.ends_with(String(".") + GODOT_JVM_REGISTRATION_FILE_EXTENSION)) { - LOG_WARNING(vformat("You should not move folders with registration files in the godot editor! Use the IDE for that. Folder moved: %s", folder) - ); + JVM_WARNING("You should not move folders with registration files in the godot editor! Use the IDE for that. Folder moved: %s", folder); break; } file_path = dir_access->get_next(); @@ -52,7 +51,7 @@ void GodotKotlinJvmEditor::on_menu_option_pressed(int menu_option) { about_dialog->popup_centered(); break; default: - LOG_ERROR("Invalid menu option. Please file a bugreport to " + JVM_ERR_FAIL_MSG("Invalid menu option. Please file a bugreport to " "https://github.com/utopia-rise/godot-kotlin-jvm/issues"); } } diff --git a/src/gd_kotlin.cpp b/src/gd_kotlin.cpp index be93af5555..7540de3edb 100644 --- a/src/gd_kotlin.cpp +++ b/src/gd_kotlin.cpp @@ -36,14 +36,14 @@ void GDKotlin::fetch_user_configuration() { // The function is going to mutate the provided configuration with the valid values found in the file. // If some of the values parsed in the file are invalid, it will return true; - LOG_VERBOSE("Parsing JSON configuration file...") + JVM_VERBOSE("Parsing JSON configuration file..."); invalid_file_content = JvmUserConfiguration::parse_configuration_json(content, user_configuration); if (invalid_file_content) { - LOG_WARNING("Configuration file is malformed. One or several settings might not be applied."); + JVM_WARNING("Configuration file is malformed. One or several settings might not be applied."); } } else { // No need for a warning, it's most likely the first time the project is run. - LOG_INFO("No JVM user_configuration file found. Default settings for your platform will be used."); + JVM_LOG("No JVM user_configuration file found. Default settings for your platform will be used."); } #ifdef TOOLS_ENABLED @@ -52,15 +52,15 @@ void GDKotlin::fetch_user_configuration() { if (invalid_file_content || !configuration_file_exist) { Ref file_access = FileAccess::open(JVM_CONFIGURATION_PATH, FileAccess::WRITE); String json = JvmUserConfiguration::export_configuration_to_json(user_configuration); - LOG_INFO(vformat("Writing a new configuration file to disk at %s", JVM_CONFIGURATION_PATH)); + JVM_LOG("Writing a new configuration file to disk at %s", JVM_CONFIGURATION_PATH); file_access->store_string(json); } #endif HashMap cmd_argument_map; - LOG_VERBOSE("Parsing commandline arguments...") + JVM_VERBOSE("Parsing commandline arguments..."); JvmUserConfiguration::parse_command_line(OS::get_singleton()->get_cmdline_args(), cmd_argument_map); - LOG_VERBOSE("Creating final JVM Configuration...") + JVM_VERBOSE("Creating final JVM Configuration..."); JvmUserConfiguration::merge_with_command_line(user_configuration, cmd_argument_map); JvmUserConfiguration::sanitize_and_log_configuration(user_configuration); } @@ -83,7 +83,7 @@ void GDKotlin::set_jvm_options() { if (user_configuration.jvm_jmx_port >= 0) { jvm_options.add_jmx_option(user_configuration.jvm_jmx_port); } if (!Engine::get_singleton()->is_editor_hint() && !user_configuration.jvm_args.is_empty()) { - LOG_WARNING("You are using custom arguments for the JVM. Make sure they are valid or you risk the JVM to not " + JVM_WARNING("You are using custom arguments for the JVM. Make sure they are valid or you risk the JVM to not " "launch properly"); jvm_options.add_custom_options(user_configuration.jvm_args); } @@ -103,7 +103,7 @@ String GDKotlin::copy_new_file_to_user_dir(const String& file_name) { #ifndef __ANDROID__ if (!FileAccess::exists(file_user_path) || FileAccess::get_md5(file_user_path) != FileAccess::get_md5(file_res_path)) { - LOG_VERBOSE(vformat("%s file has changed. Copying it from res:// to user://.", file_name)); + JVM_VERBOSE("%s file has changed. Copying it from res:// to user://.", file_name); #else // as per suggestion of https://developer.android.com/about/versions/14/behavior-changes-14#safer-dynamic-code-loading, we first delete existing files and then copy them again // if we don't do this, subsequent app starts where the files already exist, error out @@ -115,7 +115,7 @@ String GDKotlin::copy_new_file_to_user_dir(const String& file_name) { Error err; Ref dir_access {DirAccess::open(BUILD_DIRECTORY, &err)}; - JVM_ERR_FAIL_COND_V_MSG(err != OK, "", vformat("Cannot open %s file in res://.", file_name)); + JVM_ERR_FAIL_COND_V_MSG(err != OK, "", "Cannot open %s file in res://.", file_name); dir_access->copy(file_res_path, file_user_path); @@ -144,7 +144,7 @@ bool GDKotlin::load_bootstrap() { #endif JVM_ERR_FAIL_COND_V_MSG(!FileAccess::exists(bootstrap_jar), false, error_text); - LOG_VERBOSE(vformat("Loading bootstrap jar: %s", bootstrap_jar)); + JVM_VERBOSE("Loading bootstrap jar: %s", bootstrap_jar); bootstrap_class_loader = ClassLoader::create_instance(env, bootstrap_jar, jni::JObject(nullptr)); bootstrap_class_loader->set_as_context_loader(env); @@ -181,7 +181,7 @@ bool GDKotlin::load_user_code() { #else String user_code_path {copy_new_file_to_user_dir(USER_CODE_FILE)}; #endif - LOG_VERBOSE(vformat("Loading usercode file at: %s", user_code_path)); + JVM_VERBOSE("Loading usercode file at: %s", user_code_path); // TODO: Rework this part when cpp reloading done, can't check what's happening in the Kotlin code from here. ClassLoader* user_class_loader = ClassLoader::create_instance( env, @@ -264,7 +264,7 @@ bool GDKotlin::load_dynamic_lib() { #ifdef TOOLS_ENABLED else if (String environment_jvm = get_path_to_environment_jvm(); !environment_jvm.is_empty() && FileAccess::exists(environment_jvm)) { - LOG_WARNING(vformat("Godot-JVM: You really should embed a JRE in your project with jlink! See the " + JVM_WARNING(vformat("Godot-JVM: You really should embed a JRE in your project with jlink! See the " "documentation if you don't know how to do that")); path_to_jvm_lib = environment_jvm; } else { @@ -281,7 +281,7 @@ bool GDKotlin::load_dynamic_lib() { } #else else { - JVM_ERR_FAIL_V_MSG(false, vformat("No embedded JRE found at: %s!", get_path_to_embedded_jvm())); + JVM_ERR_FAIL_V_MSG(false, "No embedded JRE found at: %s!", get_path_to_embedded_jvm()); } #endif @@ -301,11 +301,11 @@ bool GDKotlin::load_dynamic_lib() { break; default: // Sanity check. Should never happen - JVM_CRASH_NOW_MSG("Tried to load a VM that's neither the JVM nor Graal Native Image"); + JVM_DEV_ASSERT(false, "Tried to load a VM that's neither the JVM nor Graal Native Image"); } if (OS::get_singleton()->open_dynamic_library(path_to_jvm_lib, jvm_dynamic_library_handle) != OK) { - JVM_ERR_FAIL_V_MSG(false, vformat("Failed to load the jvm dynamic library from path %s!", path_to_jvm_lib)); + JVM_ERR_FAIL_V_MSG(false, "Failed to load the jvm dynamic library from path %s!", path_to_jvm_lib); } return true; } diff --git a/src/jni/env.cpp b/src/jni/env.cpp index c43883c1c3..528d9dd73f 100644 --- a/src/jni/env.cpp +++ b/src/jni/env.cpp @@ -10,7 +10,7 @@ namespace jni { void Env::push_local_frame(int capacity) { auto result = env->PushLocalFrame(capacity); - JVM_CRASH_COND_MSG(result != JNI_OK, "Failed to push local frame!"); + JVM_ERR_FAIL_COND_MSG(result != JNI_OK, "Failed to push local frame!"); } void Env::pop_local_frame() { @@ -24,7 +24,8 @@ namespace jni { //Support fully qualified class names with "a/b/c" and "a.b.c" format JClass Env::find_class(const char* name) { jclass cls = env->FindClass(String(name).replace(".", "/").utf8()); - JVM_CRASH_COND_MSG(cls == nullptr, vformat("Class not found: %s", name)); + JVM_DEV_ASSERT(cls, vformat("Class not found: %s", name)); + check_exceptions(); return JClass(cls); } @@ -96,7 +97,7 @@ namespace jni { if (exception.is_empty()) { exception = "An exception has occurred!"; } - HANDLE_JVM_EXCEPTIONS(true, exception); + JVM_ERR_FAIL_MSG(exception); } } diff --git a/src/jni/env.h b/src/jni/env.h index a888603a1a..f73c8c7941 100644 --- a/src/jni/env.h +++ b/src/jni/env.h @@ -6,14 +6,6 @@ #include #include -#ifdef TOOLS_ENABLED -#define HANDLE_JVM_EXCEPTIONS(condition, message) JVM_ERR_FAIL_COND_MSG(condition, message) -#elif DEBUG_ENABLED -#define HANDLE_JVM_EXCEPTIONS(condition, message) JVM_CRASH_COND_MSG(condition, message) -#else -#define HANDLE_JVM_EXCEPTIONS(condition, message) JVM_ERR_FAIL_COND_MSG(condition, message) -#endif - namespace jni { class JObject; diff --git a/src/jni/jvm.cpp b/src/jni/jvm.cpp index 1222074e12..f38112978b 100644 --- a/src/jni/jvm.cpp +++ b/src/jni/jvm.cpp @@ -30,13 +30,13 @@ namespace jni { #else jint result = _instance->vm->AttachCurrentThreadAsDaemon((void**) &r_env, nullptr); #endif - JVM_CRASH_COND_MSG(result != JNI_OK, "Failed to attach vm to current thread!"); + JVM_DEV_ASSERT(result == JNI_OK, "Failed to attach vm to current thread!"); env = new Env(r_env); } void Jvm::detach() { jint result = _instance->vm->DetachCurrentThread(); - JVM_CRASH_COND_MSG(result != JNI_OK, "Failed to detach vm to current thread!"); + JVM_DEV_ASSERT(result == JNI_OK, "Failed to detach vm to current thread!"); delete env; env = nullptr; } @@ -45,7 +45,7 @@ namespace jni { if (unlikely(!env)) { JNIEnv* r_env; jint result = _instance->vm->GetEnv((void**) &r_env, _instance->version); - JVM_CRASH_COND_MSG(result == JNI_EDETACHED, "Current thread is not attached!"); + JVM_DEV_ASSERT(result != JNI_EDETACHED, "Current thread is not attached!"); env = new Env(r_env); } return *env; diff --git a/src/jni/types.cpp b/src/jni/types.cpp index cd5b7bc614..69061b957b 100644 --- a/src/jni/types.cpp +++ b/src/jni/types.cpp @@ -67,21 +67,21 @@ namespace jni { 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)); + JVM_DEV_ASSERT(id, 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) { 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)); + JVM_DEV_ASSERT(id, 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) { 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)); + JVM_DEV_ASSERT(id, vformat("Field not found: %s with signature: %s", name, signature)); env.check_exceptions(); return id; } @@ -97,7 +97,7 @@ namespace jni { 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!"); + JVM_DEV_ASSERT(ret, "Failed to instantiated object!"); env.check_exceptions(); return JObject(ret); } @@ -116,7 +116,7 @@ namespace jni { JObjectArray JClass::new_object_array(Env& env, int size, JObject initial) { auto ret = env.env->NewObjectArray(size, (jclass) obj, initial.obj); - JVM_CRASH_COND_MSG(ret == nullptr, "Failed to instantiated object array!"); + JVM_DEV_ASSERT(ret, "Failed to instantiated object array!"); return JObjectArray(ret); } diff --git a/src/jni/types.h b/src/jni/types.h index 232eb467bb..c0cf699019 100644 --- a/src/jni/types.h +++ b/src/jni/types.h @@ -247,15 +247,10 @@ namespace jni { class JClass : public JObject { public: - explicit JClass(jclass cls) : JObject(cls) {} + JClass() = default; + JClass(jclass clazz): JObject(clazz){}; - explicit JClass(jobject cls) : JObject(cls) {} - - JClass(const JClass&) = default; - - JClass& operator=(const JClass&) = default; - - JClass() : JClass((jclass) nullptr) {} + explicit JClass(JObject jObject): JObject(jObject){}; JObject new_instance(Env& env, MethodID ctor, jvalue* args = {}); diff --git a/src/jvm_wrapper/bootstrap.cpp b/src/jvm_wrapper/bootstrap.cpp index fcf1e2607e..9bc732a40b 100644 --- a/src/jvm_wrapper/bootstrap.cpp +++ b/src/jvm_wrapper/bootstrap.cpp @@ -13,7 +13,7 @@ void Bootstrap::load_classes(JNIEnv* p_env, jobject p_this, jobjectArray p_class KtClass* kt_class = new KtClass(env, jni_classes.get(env, i)); kt_class->fetch_members(env); classes.append(kt_class); - LOG_DEV_VERBOSE(vformat("Loaded class %s : %s", kt_class->registered_class_name, kt_class->base_godot_class)); + JVM_DEV_VERBOSE("Loaded class %s : %s", kt_class->registered_class_name, kt_class->base_godot_class); } j_object.delete_local_ref(env); @@ -24,7 +24,7 @@ void Bootstrap::load_classes(JNIEnv* p_env, jobject p_this, jobjectArray p_class void Bootstrap::register_engine_type(JNIEnv* p_env, jobject p_this, jobjectArray p_classes_names, jobjectArray p_singleton_names) { #ifdef DEV_ENABLED - LOG_VERBOSE("Starting to register managed engine types..."); + JVM_VERBOSE("Starting to register managed engine types..."); #endif jni::Env env(p_env); @@ -39,7 +39,7 @@ void Bootstrap::register_engine_type(JNIEnv* p_env, jobject p_this, jobjectArray engine_types.delete_local_ref(env); singleton_names.delete_local_ref(env); #ifdef DEV_ENABLED - LOG_VERBOSE("Done registering managed engine types..."); + JVM_VERBOSE("Done registering managed engine types..."); #endif } @@ -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_object_method(p_env, INIT, args); + wrapped.call_void_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 3aece7bee7..38c8ecc01a 100644 --- a/src/jvm_wrapper/bootstrap.h +++ b/src/jvm_wrapper/bootstrap.h @@ -7,7 +7,7 @@ JVM_INSTANCE_WRAPPER(Bootstrap, "godot.runtime.Bootstrap") { JVM_CLASS(Bootstrap) // clang-format off - JNI_OBJECT_METHOD(INIT) + JNI_VOID_METHOD(INIT) JNI_VOID_METHOD(FINISH) INIT_JNI_BINDINGS( diff --git a/src/jvm_wrapper/jvm_instance_wrapper.h b/src/jvm_wrapper/jvm_instance_wrapper.h index 76657ad6c2..cdbd16dbae 100644 --- a/src/jvm_wrapper/jvm_instance_wrapper.h +++ b/src/jvm_wrapper/jvm_instance_wrapper.h @@ -9,7 +9,7 @@ inline constexpr char NAME##QualifiedName[] = FQNAME; \ class NAME : public JvmInstanceWrapper -#define JVM_CLASS(NAME) \ +#define JVM_CLASS(NAME) \ friend class JvmInstanceWrapper; \ static inline constexpr const char* fq_name = NAME##QualifiedName; @@ -21,7 +21,6 @@ #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.methodId = clazz.get_method_id(p_env, name, signature); #define INIT_NATIVE_METHOD(string_name, signature, function) \ @@ -57,7 +56,7 @@ public: template class JvmInstanceWrapper { protected: - bool is_weak; + bool is_weak = false; jni::JObject wrapped; explicit JvmInstanceWrapper(jni::Env& p_env, jni::JObject p_wrapped); @@ -76,7 +75,7 @@ class JvmInstanceWrapper { }; template -JvmInstanceWrapper::JvmInstanceWrapper(jni::Env& p_env, jni::JObject p_wrapped) : is_weak(false) { +JvmInstanceWrapper::JvmInstanceWrapper(jni::Env& p_env, jni::JObject p_wrapped) { // When created, it's a strong reference by default wrapped = p_wrapped.new_global_ref(p_env); p_wrapped.delete_local_ref(p_env); diff --git a/src/jvm_wrapper/jvm_singleton_wrapper.h b/src/jvm_wrapper/jvm_singleton_wrapper.h index 7666bd5663..4b70ab80ea 100644 --- a/src/jvm_wrapper/jvm_singleton_wrapper.h +++ b/src/jvm_wrapper/jvm_singleton_wrapper.h @@ -57,8 +57,7 @@ class JvmSingletonWrapper : public JvmInstanceWrapper { template Derived* JvmSingletonWrapper::create_instance(jni::Env& p_env) { - LOG_ERROR("Can't create a new instance of a this class. Returning the singleton instead"); - return _instance; + JVM_ERR_FAIL_V_MSG(_instance, "Can't create a new instance of a this class. Returning the singleton instead"); } template diff --git a/src/jvm_wrapper/memory/memory_manager.cpp b/src/jvm_wrapper/memory/memory_manager.cpp index ef81b938ec..d1c891f4dc 100644 --- a/src/jvm_wrapper/memory/memory_manager.cpp +++ b/src/jvm_wrapper/memory/memory_manager.cpp @@ -183,9 +183,9 @@ void MemoryManager::sync_memory(jni::Env& p_env) { } void MemoryManager::clean_up(jni::Env& p_env) { - LOG_VERBOSE("Cleaning JVM Memory...") + JVM_VERBOSE("Cleaning JVM Memory..."); wrapped.call_void_method(p_env, CLEAN_UP); - LOG_VERBOSE("JVM Memory cleaned!") + JVM_VERBOSE("JVM Memory cleaned!"); } void MemoryManager::queue_dead_object(Object* obj) { diff --git a/src/jvm_wrapper/memory/transfer_context.cpp b/src/jvm_wrapper/memory/transfer_context.cpp index dd15ba7215..bc0b0fc8c9 100644 --- a/src/jvm_wrapper/memory/transfer_context.cpp +++ b/src/jvm_wrapper/memory/transfer_context.cpp @@ -16,7 +16,7 @@ SharedBuffer* TransferContext::get_and_rewind_buffer(jni::Env& p_env) { if (unlikely(!shared_buffer.is_init())) { jni::JObject buffer = wrapped.call_object_method(p_env, GET_BUFFER); - JVM_CRASH_COND_MSG(buffer.is_null(), "Buffer is null"); + JVM_DEV_ASSERT(!buffer.is_null(), "Buffer is null"); auto* address {static_cast(p_env.get_direct_buffer_address(buffer))}; #ifdef DEBUG_ENABLED shared_buffer = SharedBuffer {address, 0, p_env.get_direct_buffer_capacity(buffer)}; @@ -77,7 +77,7 @@ void TransferContext::icall(JNIEnv* rawEnv, jobject instance, jlong j_ptr, jlong MethodBind* method_bind {reinterpret_cast(static_cast(j_method_ptr))}; - JVM_DEV_ASSERT(args_size <= MAX_FUNCTION_ARG_COUNT, vformat("Cannot have more than %s arguments for method call but tried to call method \"%s::%s\" with %s args", MAX_FUNCTION_ARG_COUNT, method_bind->get_instance_class(), method_bind->get_name(), args_size)); + JVM_DEV_ASSERT(args_size <= MAX_FUNCTION_ARG_COUNT, "Cannot have more than %s arguments for method call but tried to call method \"%s::%s\" with %s args", MAX_FUNCTION_ARG_COUNT, method_bind->get_instance_class(), method_bind->get_name(), args_size); Callable::CallError r_error {Callable::CallError::CALL_OK}; @@ -113,6 +113,6 @@ void TransferContext::icall(JNIEnv* rawEnv, jobject instance, jlong j_ptr, jlong } #ifdef DEBUG_ENABLED - JVM_CRASH_COND_MSG(r_error.error != Callable::CallError::CALL_OK, vformat("Call to method %s failed.", method_bind->get_name())); + JVM_ERR_FAIL_COND_MSG(r_error.error != Callable::CallError::CALL_OK, "Call to method %s failed.", method_bind->get_name()); #endif } diff --git a/src/jvm_wrapper/memory/type_manager.cpp b/src/jvm_wrapper/memory/type_manager.cpp index 34be2c6b2e..01230f1be7 100644 --- a/src/jvm_wrapper/memory/type_manager.cpp +++ b/src/jvm_wrapper/memory/type_manager.cpp @@ -29,7 +29,7 @@ void TypeManager::register_engine_types(jni::Env& p_env, jni::JObjectArray& p_en engine_type_names.insert(i, class_name); java_engine_types_constructors[class_name] = i; #ifdef DEV_ENABLED - LOG_VERBOSE(vformat("Registered %s engine type with index %s.", class_name, i)); + JVM_VERBOSE("Registered %s engine type with index %s.", class_name, i); #endif type.delete_local_ref(p_env); } @@ -51,15 +51,8 @@ uintptr_t TypeManager::get_method_bind_ptr(JNIEnv* p_raw_env, jobject j_instance MethodBind* bind {ClassDB::get_method(class_name, method_name)}; - if(!bind){ - LOG_ERROR(vformat("Method %s from Class %s doesn't exist. Check that your JVM Godot-Kotlin library matches this Godot version.", method_name, class_name)); - return 0; - } - - if(bind->get_hash() != hash){ - LOG_ERROR(vformat("Hash mismatch for Method %s from Class %s. Check that your JVM Godot-Kotlin library matches this Godot version.", method_name, class_name)); - return 0; - } + JVM_ERR_FAIL_COND_V_MSG(!bind, 0, "Method %s from Class %s doesn't exist. Check that your JVM Godot-Kotlin library matches this Godot version.", method_name, class_name); + JVM_ERR_FAIL_COND_V_MSG(bind->get_hash() != hash, 0, "Hash mismatch for Method %s from Class %s. Check that your JVM Godot-Kotlin library matches this Godot version.", method_name, class_name); return reinterpret_cast(bind); diff --git a/src/jvm_wrapper/registration/kt_class.cpp b/src/jvm_wrapper/registration/kt_class.cpp index 1752d84360..bef3a4535d 100644 --- a/src/jvm_wrapper/registration/kt_class.cpp +++ b/src/jvm_wrapper/registration/kt_class.cpp @@ -41,7 +41,7 @@ KtObject* KtClass::create_instance(jni::Env& env, const Variant** p_args, int p_ #endif KtObject* jvm_instance {constructor->create_instance(env, p_args, p_owner)}; - LOG_DEV_VERBOSE(vformat("Instantiated a Jvm script: %s", registered_class_name)); + JVM_DEV_VERBOSE(vformat("Instantiated a Jvm script: %s", registered_class_name)); return jvm_instance; } @@ -90,9 +90,7 @@ void KtClass::fetch_registered_supertypes(jni::Env& env) { for (int i = 0; i < classesArray.length(env); i++) { StringName parent_name = StringName(env.from_jstring(jni::JString(classesArray.get(env, i)))); registered_supertypes.append(parent_name); -#ifdef DEBUG_ENABLED - LOG_VERBOSE(vformat("%s user type is parent of %s.", parent_name, registered_class_name)); -#endif + JVM_DEV_VERBOSE("%s user type is parent of %s.", parent_name, registered_class_name); } classesArray.delete_local_ref(env); } @@ -103,9 +101,7 @@ void KtClass::fetch_methods(jni::Env& env) { jni::JObject object = functionsArray.get(env, i); auto* ktFunction {new KtFunction(env, object)}; methods[ktFunction->get_name()] = ktFunction; -#ifdef DEV_ENABLED - LOG_VERBOSE(vformat("Fetched method %s for class %s", ktFunction->get_name(), registered_class_name)); -#endif + JVM_DEV_VERBOSE("Fetched method %s for class %s", ktFunction->get_name(), registered_class_name); } functionsArray.delete_local_ref(env); } @@ -115,9 +111,7 @@ void KtClass::fetch_properties(jni::Env& env) { for (int i = 0; i < propertiesArray.length(env); i++) { auto* ktProperty {new KtProperty(env, propertiesArray.get(env, i))}; properties[ktProperty->get_name()] = ktProperty; -#ifdef DEV_ENABLED - LOG_VERBOSE(vformat("Fetched property %s for class %s", ktProperty->get_name(), registered_class_name)); -#endif + JVM_DEV_VERBOSE("Fetched property %s for class %s", ktProperty->get_name(), registered_class_name); } propertiesArray.delete_local_ref(env); } @@ -127,9 +121,7 @@ void KtClass::fetch_signals(jni::Env& env) { for (int i = 0; i < signal_info_array.length(env); i++) { auto* kt_signal_info {new KtSignalInfo(env, signal_info_array.get(env, i))}; signal_infos[kt_signal_info->name] = kt_signal_info; -#ifdef DEV_ENABLED - LOG_VERBOSE(vformat("Fetched signal %s for class %s", kt_signal_info->name, registered_class_name)); -#endif + JVM_DEV_VERBOSE("Fetched signal %s for class %s", kt_signal_info->name, registered_class_name); } signal_info_array.delete_local_ref(env); } @@ -141,9 +133,7 @@ void KtClass::fetch_constructors(jni::Env& env) { KtConstructor* kt_constructor {nullptr}; if (constructor.obj != nullptr) { kt_constructor = new KtConstructor(env, constructor); -#ifdef DEV_ENABLED - LOG_VERBOSE(vformat("Fetched constructor with %s parameters for class %s", i, registered_class_name)); -#endif + JVM_DEV_VERBOSE("Fetched constructor with %s parameters for class %s", i, registered_class_name); } constructors[i] = kt_constructor; } diff --git a/src/kotlin_editor_export_plugin.cpp b/src/kotlin_editor_export_plugin.cpp index c27cbe57da..1d768b621d 100644 --- a/src/kotlin_editor_export_plugin.cpp +++ b/src/kotlin_editor_export_plugin.cpp @@ -14,7 +14,7 @@ static constexpr const char* all_jvm_feature {"export-all-jvm"}; static constexpr const char* ios_jdk_version {"21"}; void KotlinEditorExportPlugin::_export_begin(const HashSet& p_features, bool p_debug, const String& p_path, int p_flags) { - LOG_INFO("Beginning Godot-Jvm specific exports."); + JVM_LOG("Beginning Godot-Jvm specific exports."); // Add mandatory jars to pck Vector files_to_add; @@ -46,20 +46,20 @@ void KotlinEditorExportPlugin::_export_begin(const HashSet& p_features, if (is_arm64 || is_universal) { String jre_path{String(RES_DIRECTORY).path_join(MACOS_EMBEDDED_JRE_ARM_DIRECTORY)}; if (!DirAccess::exists(jre_path)) { - LOG_ERROR_WITH_ALERT(vformat("JRE does not exist at %s! make sure you've created an embedded JRE using jlink!", jre_path)); + JVM_ERR_FAIL_MSG("JRE does not exist at %s! make sure you've created an embedded JRE using jlink!", jre_path); } add_macos_plugin_file(jre_path); } if (is_x64 || is_universal) { String jre_path{String(RES_DIRECTORY).path_join(MACOS_EMBEDDED_JRE_AMD_DIRECTORY)}; if (!DirAccess::exists(jre_path)) { - LOG_ERROR_WITH_ALERT(vformat("JRE does not exist at %s! make sure you've created an embedded JRE using jlink!", jre_path)); + JVM_ERR_FAIL_MSG("JRE does not exist at %s! make sure you've created an embedded JRE using jlink!", jre_path); } add_macos_plugin_file(jre_path); } if (!is_arm64 && !is_x64 && !is_universal) { - LOG_ERROR_WITH_ALERT("This desktop architecture is not supported for export. Only arm64 and x86_64 are supported by Godot Kotlin/JVM!"); + JVM_ERR_FAIL_MSG("This desktop architecture is not supported for export. Only arm64 and x86_64 are supported by Godot Kotlin/JVM!"); } } else if (is_linux_export || is_windows_export) { // on windows and linux the embedded jre can be added as a normal export dir @@ -87,24 +87,23 @@ void KotlinEditorExportPlugin::_export_begin(const HashSet& p_features, } } if (!is_arm64 && !is_x64) { - LOG_ERROR_WITH_ALERT("This desktop architecture is not supported for export. Only arm64 and x86_64 are supported by Godot Kotlin/JVM!"); + JVM_ERR_FAIL_MSG("This desktop architecture is not supported for export. Only arm64 and x86_64 are supported by Godot Kotlin/JVM!"); } if(jre_dir.is_empty() || target_dir.is_empty()) { - LOG_ERROR_WITH_ALERT("Could not find a jre directory for the current export configuration"); + JVM_ERR_FAIL_MSG("Could not find a jre directory for the current export configuration"); } // copy the jre to res Error error; Ref dir_access {DirAccess::open(jre_dir, &error)}; if (error != OK) { - LOG_ERROR_WITH_ALERT(vformat("Cannot open directory %s", jre_dir)); + JVM_ERR_FAIL_MSG("Cannot open directory %s", jre_dir); } if (dir_access->copy_dir(jre_dir, target_dir) != OK) { - LOG_ERROR_WITH_ALERT(vformat("Cannot copy %s folder to export folder, please make sure you created a JRE directory at the root of your project using jlink for the platform you want to export.", jre_dir) - ); + JVM_ERR_FAIL_MSG("Cannot copy %s folder to export folder, please make sure you created a JRE directory at the root of your project using jlink for the platform you want to export.", jre_dir); } } else { - LOG_ERROR_WITH_ALERT("Current desktop export target platform is not supported by Godot Kotlin/JVM! Only supported desktop targets are linux, macos and windows"); + JVM_ERR_FAIL_MSG("Current desktop export target platform is not supported by Godot Kotlin/JVM! Only supported desktop targets are linux, macos and windows"); } } @@ -117,7 +116,7 @@ void KotlinEditorExportPlugin::_export_begin(const HashSet& p_features, } else if (is_macos_export) { files_to_add.push_back(String(BUILD_DIRECTORY) + MACOS_GRAAL_NATIVE_IMAGE_FILE); } else { - LOG_ERROR_WITH_ALERT("Export target platform is not supported for graalvm export"); + JVM_ERR_FAIL_MSG("Export target platform is not supported for graalvm export"); } } @@ -149,18 +148,18 @@ void KotlinEditorExportPlugin::_export_begin(const HashSet& p_features, ProjectSettings::get_singleton()->globalize_path(base_ios_build_dir.path_join(IOS_GRAAL_NATIVE_IMAGE_FILE)) ); } else { - LOG_ERROR_WITH_ALERT("Godot Kotlin/JVM doesn't handle this platform"); + JVM_ERR_FAIL_MSG("Godot Kotlin/JVM doesn't handle this platform"); } for (const String& file_to_add : files_to_add) { if (!FileAccess::exists(file_to_add)) { - LOG_ERROR_WITH_ALERT(vformat("File can't be found, it won't be exported: %s", file_to_add)); + JVM_ERR_FAIL_MSG("File can't be found, it won't be exported: %s", file_to_add); } add_file(file_to_add, FileAccess::get_file_as_bytes(file_to_add), false); - LOG_INFO(vformat("Exporting %s", file_to_add)); + JVM_LOG("Exporting %s", file_to_add); } - LOG_INFO("Finished Godot-Jvm specific exports."); + JVM_LOG("Finished Godot-Jvm specific exports."); } void KotlinEditorExportPlugin::_generate_export_configuration_file(jni::JvmType vm_type) { diff --git a/src/lifecycle/jvm_manager.cpp b/src/lifecycle/jvm_manager.cpp index 341a7d0377..0f9dd389af 100644 --- a/src/lifecycle/jvm_manager.cpp +++ b/src/lifecycle/jvm_manager.cpp @@ -43,7 +43,7 @@ CreateJavaVM get_create_jvm_function(void* lib_handle) { return &JNI_CreateJavaVM; #else // Sanity check in case we mess up preprocessors - JVM_CRASH_NOW_MSG("Current configuration doesn't provide a way to create a JVM!"); + JVM_DEV_ASSERT(false, "Current configuration doesn't provide a way to create a JVM!"); #endif } @@ -60,12 +60,12 @@ bool JvmManager::initialize_or_get_jvm(void* lib_handle, JvmUserConfiguration& u for (auto i = 0; i < static_cast(nOptions); i++) { args.options[i].optionString = jvm_options.options[i].ptrw(); - LOG_DEV_VERBOSE(vformat("JVM argument %s: %s", i, args.options[i].optionString)); + JVM_DEV_VERBOSE("JVM argument %s: %s", i, args.options[i].optionString); } std::locale global; - LOG_VERBOSE("Starting JVM ..."); + JVM_VERBOSE("Starting JVM ..."); JNIEnv* jni_env {nullptr}; CreateJavaVM func {get_create_jvm_function(lib_handle)}; @@ -82,12 +82,12 @@ bool JvmManager::initialize_or_get_jvm(void* lib_handle, JvmUserConfiguration& u JVM_ERR_FAIL_COND_V_MSG(result != JNI_OK, false, "Failed to create a new vm!"); #elif defined PROVIDED_JVM - LOG_VERBOSE("Retrieving existing JVM ..."); + JVM_VERBOSE("Retrieving existing JVM ..."); jni::Env env {get_jni_env()}; java_vm = env.get_jvm(); #else // Sanity check in case we mess up preprocessors - JVM_CRASH_COND_MSG(java_vm == nullptr, "Current configuration doesn't allow to create or fetch a JVM."); + JVM_DEV_ASSERT(java_vm, "Current configuration doesn't allow to create or fetch a JVM."); #endif jni::Jvm::initialize(java_vm, user_configuration.vm_type, jvm_options.version); @@ -159,7 +159,7 @@ void JvmManager::destroy_jni_classes() { void JvmManager::close_jvm() { #if defined DYNAMIC_JVM || defined STATIC_JVM - LOG_VERBOSE("Shutting down JVM ..."); + JVM_VERBOSE("Shutting down JVM ..."); jni::Jvm::destroy(); #endif } diff --git a/src/lifecycle/jvm_options.cpp b/src/lifecycle/jvm_options.cpp index b3f2960cd2..84f038cb22 100644 --- a/src/lifecycle/jvm_options.cpp +++ b/src/lifecycle/jvm_options.cpp @@ -25,7 +25,7 @@ void JvmOptions::add_jmx_option(uint16_t p_port) { options.push_back("-Dcom.sun.management.jmxremote.local.only=false"); options.push_back("-Dcom.sun.management.jmxremote.authenticate=false"); options.push_back("-Dcom.sun.management.jmxremote.ssl=false"); - LOG_VERBOSE(vformat("Started JMX on port: %s", jvm_jmx_port)); + JVM_VERBOSE("Started JMX on port: %s", jvm_jmx_port); } void JvmOptions::add_custom_options(const String& custom_options) { diff --git a/src/lifecycle/jvm_user_configuration.cpp b/src/lifecycle/jvm_user_configuration.cpp index b61376f865..20d2c968c4 100644 --- a/src/lifecycle/jvm_user_configuration.cpp +++ b/src/lifecycle/jvm_user_configuration.cpp @@ -9,14 +9,13 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J Variant result {json.get_data()}; if (error != OK || result.get_type() != Variant::DICTIONARY) { - LOG_ERROR("Error parsing Godot Kotlin configuration file! Falling back to default configuration"); - return true; + JVM_ERR_FAIL_V_MSG(true, "Error parsing Godot Kotlin configuration file! Falling back to default configuration"); } Dictionary json_dict = result; if (json_dict.has(VM_TYPE_JSON_IDENTIFIER)) { String value = json_dict[VM_TYPE_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", VM_TYPE_JSON_IDENTIFIER, value)) + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", VM_TYPE_JSON_IDENTIFIER, value); if (value == AUTO_STRING) { json_config.vm_type = jni::JvmType::NONE; } else if (value == JVM_STRING) { @@ -27,110 +26,110 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J json_config.vm_type = jni::JvmType::ART; } else { is_invalid = true; - LOG_WARNING(vformat("Wrong JVM type in configuration file: %s. It will be ignored", value)); + JVM_WARNING("Wrong JVM type in configuration file: %s. It will be ignored", value);; } json_dict.erase(VM_TYPE_JSON_IDENTIFIER); } if (json_dict.has(USE_DEBUG_JSON_IDENTIFIER)) { String boolean = json_dict[USE_DEBUG_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", USE_DEBUG_JSON_IDENTIFIER, boolean)); + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", USE_DEBUG_JSON_IDENTIFIER, boolean); if (boolean == TRUE_STRING) { json_config.use_debug = true; } else if (boolean == FALSE_STRING) { json_config.use_debug = false; } else { is_invalid = true; - LOG_WARNING(vformat("Invalid Use Debug value in configuration file: %s. It will be ignored", boolean)); + JVM_WARNING("Invalid Use Debug value in configuration file: %s. It will be ignored", boolean); } json_dict.erase(USE_DEBUG_JSON_IDENTIFIER); } if (json_dict.has(DEBUG_PORT_JSON_IDENTIFIER)) { int32_t port = json_dict[DEBUG_PORT_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", DEBUG_PORT_JSON_IDENTIFIER, port)); + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", DEBUG_PORT_JSON_IDENTIFIER, port); if (port >= 0 && port <= 65535) { json_config.jvm_debug_port = port; } else { is_invalid = true; - LOG_WARNING(vformat("Invalid JVM port value in configuration file: %s. It will be ignored", port)); + JVM_WARNING("Invalid JVM port value in configuration file: %s. It will be ignored", port); } json_dict.erase(DEBUG_PORT_JSON_IDENTIFIER); } if (json_dict.has(DEBUG_ADDRESS_JSON_IDENTIFIER)) { String address = json_dict[DEBUG_ADDRESS_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", DEBUG_ADDRESS_JSON_IDENTIFIER, address)); + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", DEBUG_ADDRESS_JSON_IDENTIFIER, address); if (address.is_valid_ip_address() || address == "*") { json_config.jvm_debug_address = address; } else { is_invalid = true; - LOG_WARNING(vformat("Invalid JVM address value in configuration file: %s. It will be ignored", address)); + JVM_WARNING("Invalid JVM address value in configuration file: %s. It will be ignored", address); } json_dict.erase(DEBUG_ADDRESS_JSON_IDENTIFIER); } if (json_dict.has(WAIT_FOR_DEBUGGER_JSON_IDENTIFIER)) { String boolean = json_dict[WAIT_FOR_DEBUGGER_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", WAIT_FOR_DEBUGGER_JSON_IDENTIFIER, boolean)); + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", WAIT_FOR_DEBUGGER_JSON_IDENTIFIER, boolean); if (boolean == TRUE_STRING) { json_config.wait_for_debugger = true; } else if (boolean == FALSE_STRING) { json_config.wait_for_debugger = false; } else { is_invalid = true; - LOG_WARNING(vformat("Invalid Waiting for Debugger value in configuration file: %s. It will be ignored", boolean)); + JVM_WARNING("Invalid Waiting for Debugger value in configuration file: %s. It will be ignored", boolean); } json_dict.erase(WAIT_FOR_DEBUGGER_JSON_IDENTIFIER); } if (json_dict.has(JMX_PORT_JSON_IDENTIFIER)) { int32_t port = json_dict[JMX_PORT_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", JMX_PORT_JSON_IDENTIFIER, port)); + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", JMX_PORT_JSON_IDENTIFIER, port); if (port >= -1 && port <= 65535) { json_config.jvm_jmx_port = port; } else { is_invalid = true; - LOG_WARNING(vformat("Invalid JMX port value in configuration file: %s. It will be ignored", port)); + JVM_WARNING("Invalid JMX port value in configuration file: %s. It will be ignored", port); } json_dict.erase(JMX_PORT_JSON_IDENTIFIER); } if (json_dict.has(MAX_STRING_SIZE_JSON_IDENTIFIER)) { int32_t size = json_dict[MAX_STRING_SIZE_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", MAX_STRING_SIZE_JSON_IDENTIFIER, size)); + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", MAX_STRING_SIZE_JSON_IDENTIFIER, size); if (size >= -1) { json_config.max_string_size = size; } else { is_invalid = true; - LOG_WARNING(vformat("Invalid Maximum String Size value in configuration file: %s. It will be ignored", size)); + JVM_WARNING("Invalid Maximum String Size value in configuration file: %s. It will be ignored", size); } json_dict.erase(MAX_STRING_SIZE_JSON_IDENTIFIER); } if (json_dict.has(DISABLE_GC_JSON_IDENTIFIER)) { String boolean = json_dict[DISABLE_GC_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", DISABLE_GC_JSON_IDENTIFIER, boolean)); + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", DISABLE_GC_JSON_IDENTIFIER, boolean); if (boolean == TRUE_STRING) { json_config.disable_gc = true; } else if (boolean == FALSE_STRING) { json_config.disable_gc = false; } else { is_invalid = true; - LOG_WARNING(vformat("Invalid Disable GC value in configuration file: %s. It will be ignored", boolean)); + JVM_WARNING("Invalid Disable GC value in configuration file: %s. It will be ignored", boolean); } json_dict.erase(DISABLE_GC_JSON_IDENTIFIER); } if (json_dict.has(JVM_ARGUMENTS_JSON_IDENTIFIER)) { json_config.jvm_args = json_dict[JVM_ARGUMENTS_JSON_IDENTIFIER]; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", JVM_ARGUMENTS_JSON_IDENTIFIER, json_config.jvm_args)) + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", JVM_ARGUMENTS_JSON_IDENTIFIER, json_config.jvm_args); json_dict.erase(JVM_ARGUMENTS_JSON_IDENTIFIER); } if (json_dict.has(VERSION_JSON_IDENTIFIER)) { String version {json_dict[VERSION_JSON_IDENTIFIER]}; - LOG_DEV_VERBOSE(vformat("Value for json argument: %s -> %s", VERSION_JSON_IDENTIFIER, version)) + JVM_DEV_VERBOSE("Value for json argument: %s -> %s", VERSION_JSON_IDENTIFIER, version); if (version != JSON_ARGUMENT_VERSION) { - LOG_WARNING("Your existing jvm json configuration file was made for an older version of this binding. A " + JVM_WARNING("Your existing jvm json configuration file was made for an older version of this binding. A " "new will one will be created. Your previous settings should remain if compatible."); is_invalid = true; } json_dict.erase(VERSION_JSON_IDENTIFIER); } else { - LOG_WARNING("No version found in the configuration file"); + JVM_WARNING("No version found in the configuration file"); is_invalid = true; } @@ -139,7 +138,7 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J for (int i = 0; i < keys.size(); i++) { String key = keys[i]; String value = json_dict[key]; - LOG_WARNING(vformat("Invalid json configuration argument name: %s", key)); + JVM_WARNING("Invalid json configuration argument name: %s", key); } is_invalid = true; } @@ -195,8 +194,7 @@ Error split_argument(const String& cmd_arg, String& identifier, String& value) { identifier = jvm_debug_split[0]; value = ""; } else { - LOG_ERROR(vformat("Can't parse command-line argument: %s", cmd_arg)); - return Error::ERR_PARSE_ERROR; + JVM_ERR_FAIL_V_MSG(Error::ERR_PARSE_ERROR, "Can't parse command-line argument: %s", cmd_arg); } return OK; } @@ -209,8 +207,7 @@ bool get_cmd_bool_or_default(const String& value, bool default_if_empty) { } else if (value == FALSE_STRING) { return false; } else { - LOG_ERROR(vformat("Command line argument can't be parsed as a boolean value: %s. It will be treated as false", value)); - return false; + JVM_ERR_FAIL_V_MSG(false, "Command line argument can't be parsed as a boolean value: %s. It will be treated as false", value); } } @@ -235,7 +232,7 @@ void JvmUserConfiguration::parse_command_line(const List& args, HashMap< } else if (value == ART_STRING) { configuration_map[VM_TYPE_CMD_IDENTIFIER] = jni::JvmType::ART; } else { - LOG_WARNING(vformat("Wrong JVM type in command line arguments: %s. It will be ignored", value)); + JVM_WARNING("Wrong JVM type in command line arguments: %s. It will be ignored", value);; } } else if (identifier == USE_DEBUG_CMD_IDENTIFIER) { configuration_map[USE_DEBUG_CMD_IDENTIFIER] = get_cmd_bool_or_default(value, TRUE_STRING); @@ -245,13 +242,13 @@ void JvmUserConfiguration::parse_command_line(const List& args, HashMap< if (port >= 0 && port <= 65535) { configuration_map[DEBUG_PORT_CMD_IDENTIFIER] = port; } else { - LOG_WARNING(vformat("Invalid JVM port value in command line arguments: %s. It will be ignored", port)); + JVM_WARNING("Invalid JVM port value in command line arguments: %s. It will be ignored", port); } } else if (identifier == DEBUG_ADDRESS_CMD_IDENTIFIER) { if (value.is_valid_ip_address()) { configuration_map[DEBUG_ADDRESS_CMD_IDENTIFIER] = value; } else { - LOG_WARNING(vformat("Invalid JVM address value command line arguments: %s. It will be ignored", value)); + JVM_WARNING("Invalid JVM address value command line arguments: %s. It will be ignored", value);; } } else if (identifier == WAIT_FOR_DEBUGGER_CMD_IDENTIFIER) { configuration_map[WAIT_FOR_DEBUGGER_CMD_IDENTIFIER] = get_cmd_bool_or_default(value, TRUE_STRING); @@ -261,7 +258,7 @@ void JvmUserConfiguration::parse_command_line(const List& args, HashMap< if (port >= 0 && port <= 65535) { configuration_map[JMX_PORT_CMD_IDENTIFIER] = port; } else { - LOG_WARNING(vformat("Invalid JMX port value command line arguments: %s. It will be ignored", port)); + JVM_WARNING("Invalid JMX port value command line arguments: %s. It will be ignored", port); } } else if (identifier == MAX_STRING_SIZE_CMD_IDENTIFIER) { int64_t size = -1; @@ -269,14 +266,14 @@ void JvmUserConfiguration::parse_command_line(const List& args, HashMap< if (value.is_valid_int() && size >= -1) { configuration_map[MAX_STRING_SIZE_CMD_IDENTIFIER] = size; } else { - LOG_WARNING(vformat("Invalid Maximum String Size value in configuration file: %s. It will be ignored", size)); + JVM_WARNING("Invalid Maximum String Size value in configuration file: %s. It will be ignored", size); } } else if (identifier == DISABLE_GC_CMD_IDENTIFIER) { configuration_map[DISABLE_GC_CMD_IDENTIFIER] = get_cmd_bool_or_default(value, TRUE_STRING); } for (const auto& map_element : configuration_map) { - LOG_DEV_VERBOSE(vformat("Value for commandline argument: %s -> %s", map_element.key, map_element.value)) + JVM_DEV_VERBOSE("Value for commandline argument: %s -> %s", map_element.key, map_element.value); } } } @@ -307,56 +304,56 @@ void JvmUserConfiguration::merge_with_command_line(JvmUserConfiguration& json_co void JvmUserConfiguration::sanitize_and_log_configuration(JvmUserConfiguration& config) { if (config.max_string_size != -1) { - LOG_WARNING(vformat( + JVM_WARNING( "The max string size was changed to %s which can modify the size of the shared buffer. " "Be aware that it might impact performance and memory usage.", config.max_string_size - )); + ); } if (config.disable_leak_warning_on_close) { - LOG_WARNING("You won't be notified if your Kotlin code got instances leaking"); + JVM_WARNING("You won't be notified if your Kotlin code got instances leaking"); } if (!config.jvm_args.is_empty()) { - LOG_WARNING(vformat("Custom JVM arguments are provided, be sure they are valid: %s", config.jvm_args)); + JVM_WARNING("Custom JVM arguments are provided, be sure they are valid: %s", config.jvm_args); } #ifdef __ANDROID__ if (config.vm_type == jni::JvmType::NONE) { config.vm_type = jni::JvmType::ART; - LOG_INFO("You are running on Android. VM automatically set to ART"); + JVM_LOG("You are running on Android. VM automatically set to ART"); } else if (config.vm_type != jni::JvmType::ART) { config.vm_type = jni::JvmType::ART; - LOG_WARNING("You are running on Android. Switching VM to ART"); + JVM_WARNING("You are running on Android. Switching VM to ART"); } #elif IOS_ENABLED if (config.vm_type == jni::JvmType::NONE) { config.vm_type = jni::JvmType::GRAAL_NATIVE_IMAGE; - LOG_INFO("You are running on iOS. VM automatically set to Graal native_image"); + JVM_LOG("You are running on iOS. VM automatically set to Graal native_image"); } else if (config.vm_type != jni::JvmType::GRAAL_NATIVE_IMAGE) { config.vm_type = jni::JvmType::GRAAL_NATIVE_IMAGE; - LOG_WARNING("You are running on iOS. Switching VM to Graal native_image"); + JVM_WARNING("You are running on iOS. Switching VM to Graal native_image"); } #else if (config.vm_type == jni::JvmType::NONE) { config.vm_type = jni::JvmType::JVM; - LOG_INFO("You are running on desktop. VM automatically set to JVM"); + JVM_LOG("You are running on desktop. VM automatically set to JVM"); } else if (config.vm_type == jni::JvmType::ART) { config.vm_type = jni::JvmType::JVM; - LOG_WARNING("You can't run ART on desktop. Switching VM to JVM"); + JVM_WARNING("You can't run ART on desktop. Switching VM to JVM"); } #endif else { switch (config.vm_type) { case jni::JvmType::JVM: - LOG_INFO(vformat("VM set to %s", JVM_STRING)); + JVM_LOG("VM set to %s", JVM_STRING); break; case jni::JvmType::GRAAL_NATIVE_IMAGE: - LOG_INFO(vformat("VM set to %s", GRAAL_NATIVE_IMAGE_STRING)); + JVM_LOG("VM set to %s", GRAAL_NATIVE_IMAGE_STRING); break; case jni::JvmType::ART: - LOG_INFO(vformat("VM set to %s", ART_STRING)); + JVM_LOG("VM set to %s", ART_STRING); break; case jni::JvmType::NONE: // Should never happen. diff --git a/src/logging.h b/src/logging.h index f1f075a627..920f1a1e2e 100644 --- a/src/logging.h +++ b/src/logging.h @@ -5,46 +5,47 @@ #include -#define LOG_VERBOSE(message) print_verbose(vformat("Godot-JVM: %s", message)) -#define LOG_INFO(message) print_line(vformat("Godot-JVM: %s", message)) -#define LOG_WARNING(message) WARN_PRINT(vformat("Godot-JVM: %s", message)) -#define LOG_ERROR(message) ERR_PRINT(vformat("Godot-JVM: %s", message)) -#define LOG_ERROR_WITH_ALERT(message) \ - OS::get_singleton()->alert(message, "Fatal error"); \ - ERR_PRINT(vformat("Godot-JVM: %s", message)) - -#define JVM_ERR_FAIL_MSG(message) ERR_FAIL_EDMSG(vformat("Godot-JVM: %s", message)) -#define JVM_ERR_FAIL_V_MSG(ret_var, message) ERR_FAIL_V_EDMSG(ret_var, vformat("Godot-JVM: %s", message)) -#define JVM_ERR_FAIL_COND_MSG(condition, message) ERR_FAIL_COND_EDMSG(condition, vformat("Godot-JVM: %s", message)) -#define JVM_ERR_FAIL_COND_V_MSG(condition, ret_var, message) \ - ERR_FAIL_COND_V_EDMSG(condition, ret_var, vformat("Godot-JVM: %s", message)) - -#ifdef DEBUG_ENABLED -#define JVM_CRASH_COND_MSG(condition, message) \ - if (unlikely(condition)) { OS::get_singleton()->alert(message, "Fatal error"); } \ - CRASH_COND_MSG(condition, vformat("Godot-JVM: %s", message)) -#define JVM_CRASH_NOW_MSG(message) \ - OS::get_singleton()->alert(message, "Fatal error"); \ - CRASH_NOW_MSG(vformat("Godot-JVM: %s", message)) +inline String format_prefix{"Godot-JVM: "}; + +#define JVM_STRING_FORMAT(message, ...) vformat(format_prefix + message, ##__VA_ARGS__) + +#define JVM_LOG(message, ...) print_line(JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_VERBOSE(message, ...) print_verbose(JVM_STRING_FORMAT(message, ##__VA_ARGS__)) (void) 0 +#define JVM_WARNING(message, ...) WARN_PRINT(JVM_STRING_FORMAT(message, ##__VA_ARGS__)) + +#ifdef TOOLS_ENABLED +#define JVM_ERR_FAIL_MSG(message, ...) ERR_FAIL_EDMSG(JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_ERR_FAIL_V_MSG(ret_var, message, ...) \ + ERR_FAIL_V_EDMSG(ret_var, JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_ERR_FAIL_COND_MSG(condition, message, ...) \ + ERR_FAIL_COND_EDMSG(condition, JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_ERR_FAIL_COND_V_MSG(condition, ret_var, message, ...) \ + ERR_FAIL_COND_V_EDMSG(condition, ret_var, JVM_STRING_FORMAT(message, ##__VA_ARGS__)) #else -#define JVM_CRASH_COND_MSG(condition, message) CRASH_COND_MSG(condition, vformat("Godot-JVM: %s", message)) -#define JVM_CRASH_NOW_MSG(message) CRASH_NOW_MSG(vformat("Godot-JVM: %s", message)) +#define JVM_ERR_CONTINUE_MSG(message) , ... ERR_PRINT_ED(JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_ERR_FAIL_MSG(message, ...) ERR_FAIL_MSG(JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_ERR_FAIL_V_MSG(ret_var, message, ...) \ + ERR_FAIL_V_MSG(ret_var, JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_ERR_FAIL_COND_MSG(condition, message, ...) \ + ERR_FAIL_COND_MSG(condition, JVM_STRING_FORMAT(message, ##__VA_ARGS__)) +#define JVM_ERR_FAIL_COND_V_MSG(condition, ret_var, message, ...) \ + ERR_FAIL_COND_V_MSG(condition, ret_var, JVM_STRING_FORMAT(message, ##__VA_ARGS__)) #endif #ifdef DEV_ENABLED -#define LOG_DEV(message) LOG_INFO(message) -#define LOG_DEV_VERBOSE(message) LOG_VERBOSE(message) -#define JVM_DEV_ASSERT(m_cond, message) \ - if (unlikely(!(m_cond))) { \ - _err_print_error(FUNCTION_STR, __FILE__, __LINE__, vformat("Godot-JVM: %s", message)); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define JVM_DEV_LOG(message, ...) JVM_LOG(message, ##__VA_ARGS__) +#define JVM_DEV_VERBOSE(message, ...) JVM_VERBOSE(message, ##__VA_ARGS__) +#define JVM_DEV_ASSERT(m_cond, message, ...) \ + if (unlikely(!(m_cond))) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, JVM_STRING_FORMAT(message, ##__VA_ARGS__)); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void) 0) #else -#define LOG_DEV(message) -#define LOG_DEV_VERBOSE(message) -#define JVM_DEV_ASSERT(m_cond, message) +#define JVM_DEV_LOG(message, ...) +#define JVM_DEV_VERBOSE(message, ...) +#define JVM_DEV_ASSERT(m_cond, message, ...) #endif #endif// GODOT_JVM_LOGGING_H \ No newline at end of file diff --git a/src/resource_format/jvm_resource_format_saver.cpp b/src/resource_format/jvm_resource_format_saver.cpp index 7cb8570de2..ab4f5ea462 100644 --- a/src/resource_format/jvm_resource_format_saver.cpp +++ b/src/resource_format/jvm_resource_format_saver.cpp @@ -20,7 +20,7 @@ Error JvmResourceFormatSaver::save(const Ref& p_resource, const String ERR_FAIL_COND_V(kotlin_script.is_null(), ERR_INVALID_PARAMETER); if (!FileAccess::exists(p_path) && p_path.get_extension() == GODOT_JVM_REGISTRATION_FILE_EXTENSION) { - LOG_WARNING("It's not recommended to create .gdj files directly as they are generated automatically from jvm source files " + JVM_WARNING("It's not recommended to create .gdj files directly as they are generated automatically from jvm source files " "when building your project.\n" "Register a class with a matching name if you don't want this file to get deleted the next " "time you build."); diff --git a/src/script/jvm_script.cpp b/src/script/jvm_script.cpp index 0073029bec..fc94e12315 100644 --- a/src/script/jvm_script.cpp +++ b/src/script/jvm_script.cpp @@ -86,7 +86,7 @@ ScriptInstance* JvmScript::_instance_create(const Variant** p_args, int p_arg_co nullptr, vformat("Invalid script %s was attempted to be used. Make sure you have properly built your project.", get_path()) ); - LOG_DEV_VERBOSE(vformat("Try to create %s instance.", kotlin_class->registered_class_name)); + JVM_DEV_VERBOSE("Try to create %s instance.", kotlin_class->registered_class_name); #endif jni::Env env = jni::Jvm::current_env(); @@ -235,9 +235,9 @@ void JvmScript::update_script() { const String& property_name {exported_property.name}; if(exported_property.type != Variant::OBJECT) { - LOG_DEV_VERBOSE(vformat("Get default value for %s property from %s:",exported_property.name, kotlin_class->registered_class_name)); + JVM_DEV_VERBOSE("Get default value for %s property from %s:", exported_property.name, kotlin_class->registered_class_name); kotlin_script_instance->get_or_default(property_name, default_value); - LOG_DEV_VERBOSE(vformat(" %s",default_value.stringify())); + JVM_DEV_VERBOSE(" %s", default_value.stringify()); } exported_members_default_value_cache[property_name] = default_value; } diff --git a/src/script/jvm_script_manager.cpp b/src/script/jvm_script_manager.cpp index 3edf241bc9..acfc1845f2 100644 --- a/src/script/jvm_script_manager.cpp +++ b/src/script/jvm_script_manager.cpp @@ -22,7 +22,7 @@ void JvmScriptManager::create_and_update_scripts(Vector& classes) { path_scripts_map.clear(); #endif - LOG_DEV("Loading JVM Scripts..."); + JVM_DEV_LOG("Loading JVM Scripts..."); // Named Script for (KtClass* kotlin_class : classes) { @@ -39,13 +39,13 @@ void JvmScriptManager::create_and_update_scripts(Vector& classes) { named_script_cache.erase(script_name); - LOG_DEV_VERBOSE(vformat("JVM Script updated: %s", script_name)); + JVM_DEV_VERBOSE("JVM Script updated: %s", script_name); } else { #endif named_script.instantiate(); named_script->kotlin_class = kotlin_class; - LOG_DEV_VERBOSE(vformat("JVM Script created: %s", script_name)); + JVM_DEV_VERBOSE("JVM Script created: %s", script_name); #ifdef TOOLS_ENABLED } #endif @@ -66,7 +66,7 @@ void JvmScriptManager::create_and_update_scripts(Vector& classes) { Ref script {keyValue.value}; StringName name {keyValue.key}; if (script->kotlin_class) { - LOG_DEV_VERBOSE(vformat("JVM Script deleted: %s", script->kotlin_class->registered_class_name)); + JVM_DEV_VERBOSE("JVM Script deleted: %s", script->kotlin_class->registered_class_name); delete script->kotlin_class; script->kotlin_class = nullptr; } diff --git a/src/script/jvm_script_manager.h b/src/script/jvm_script_manager.h index bf138cf051..c95f52aca5 100644 --- a/src/script/jvm_script_manager.h +++ b/src/script/jvm_script_manager.h @@ -54,7 +54,7 @@ Ref