Skip to content

Commit f5c5add

Browse files
committed
Adapt jvm/
1 parent 8f08559 commit f5c5add

File tree

67 files changed

+794
-797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+794
-797
lines changed

src/jvm/jvm_variant.h

+77-78
Large diffs are not rendered by default.

src/jvm/lifecycle/class_loader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ClassLoader {
2222
jni::JClass load_class(jni::Env& env, const char* name);
2323
void set_as_context_loader(jni::Env& env);
2424

25-
static ClassLoader* create_instance(jni::Env& env, const String& full_jar_path, const jni::JObject& p_parent_loader);
25+
static ClassLoader* create_instance(jni::Env& env, const godot::String& full_jar_path, const jni::JObject& p_parent_loader);
2626
};
2727

2828
#endif// GODOT_JVM_CLASS_LOADER_H

src/jvm/lifecycle/jvm_manager.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ void JvmManager::finalize_jvm_wrappers(jni::Env& p_env, ClassLoader* class_loade
170170

171171
void JvmManager::close_jvm() {
172172
#if defined DYNAMIC_JVM || defined STATIC_JVM
173-
//TODO: Remove the return jvm when https://github.com/godotengine/godot/issues/95809 is resolved
174-
return;
175173
JVM_LOG_VERBOSE("Shutting down JVM ...");
176174
jni::Jvm::destroy();
177175
#endif

src/jvm/lifecycle/jvm_options.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ void JvmOptions::add_jni_checks() {
55
options.push_back("-Xcheck:jni");
66
}
77

8-
void JvmOptions::add_debug_options(uint16_t p_port, String& p_address, bool p_wait) {
9-
String jvm_debug_port = String::num_int64(p_port);
8+
void JvmOptions::add_debug_options(uint16_t p_port, godot::String& p_address, bool p_wait) {
9+
godot::String jvm_debug_port = godot::String::num_int64(p_port);
1010

11-
String suspend { p_wait ? "y" : "n" };
11+
godot::String suspend { p_wait ? "y" : "n" };
1212

13-
String debug_command {
13+
godot::String debug_command {
1414
vformat("-agentlib:jdwp=transport=dt_socket,server=y,suspend=%s,address=%s:%s", suspend, p_address, jvm_debug_port)
1515
};
1616
options.push_back(debug_command.utf8());
1717
}
1818

1919
void JvmOptions::add_jmx_option(uint16_t p_port) {
20-
String jvm_jmx_port = String::num_int64(p_port);
20+
godot::String jvm_jmx_port = godot::String::num_int64(p_port);
2121
options.push_back("-Djava.rmi.server.hostname=127.0.0.1");
2222
options.push_back("-Dcom.sun.management.jmxremote");
2323
options.push_back(vformat("-Dcom.sun.management.jmxremote.port=%s", jvm_jmx_port).utf8());
@@ -28,6 +28,6 @@ void JvmOptions::add_jmx_option(uint16_t p_port) {
2828
JVM_LOG_VERBOSE("Started JMX on port: %s", jvm_jmx_port);
2929
}
3030

31-
void JvmOptions::add_custom_options(const String& custom_options) {
31+
void JvmOptions::add_custom_options(const godot::String& custom_options) {
3232
options.push_back(custom_options.utf8());
3333
}

src/jvm/lifecycle/jvm_options.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class JvmOptions {
2424
godot::LocalVector<godot::CharString> options;
2525

2626
void add_jni_checks();
27-
void add_debug_options(uint16_t p_port, String& p_address, bool p_wait);
27+
void add_debug_options(uint16_t p_port, godot::String& p_address, bool p_wait);
2828
void add_jmx_option(uint16_t p_port);
29-
void add_custom_options(const String& custom_options);
29+
void add_custom_options(const godot::String& custom_options);
3030

3131
public:
3232
JvmOptions() = default;

src/jvm/lifecycle/jvm_user_configuration.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
#include <classes/json.hpp>
44

5-
bool JvmUserConfiguration::parse_configuration_json(const String& json_string, JvmUserConfiguration& json_config) {
5+
bool JvmUserConfiguration::parse_configuration_json(const godot::String& json_string, JvmUserConfiguration& json_config) {
66
bool is_invalid = false;
77
godot::JSON json;
88
godot::Error error {json.parse(json_string)};
9-
Variant result {json.get_data()};
9+
godot::Variant result {json.get_data()};
1010

11-
if (error != godot::OK || result.get_type() != Variant::DICTIONARY) {
11+
if (error != godot::OK || result.get_type() != godot::Variant::DICTIONARY) {
1212
JVM_ERR_FAIL_V_MSG(true, "Error parsing Godot Kotlin configuration file! Falling back to default configuration");
1313
}
1414

1515
godot::Dictionary json_dict = result;
1616
if (json_dict.has(VM_TYPE_JSON_IDENTIFIER)) {
17-
String value = json_dict[VM_TYPE_JSON_IDENTIFIER];
17+
godot::String value = json_dict[VM_TYPE_JSON_IDENTIFIER];
1818
JVM_DEV_VERBOSE("Value for json argument: %s -> %s", VM_TYPE_JSON_IDENTIFIER, value);
1919
if (value == AUTO_STRING) {
2020
json_config.vm_type = jni::JvmType::NONE;
@@ -31,7 +31,7 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
3131
json_dict.erase(VM_TYPE_JSON_IDENTIFIER);
3232
}
3333
if (json_dict.has(USE_DEBUG_JSON_IDENTIFIER)) {
34-
String boolean = json_dict[USE_DEBUG_JSON_IDENTIFIER];
34+
godot::String boolean = json_dict[USE_DEBUG_JSON_IDENTIFIER];
3535
JVM_DEV_VERBOSE("Value for json argument: %s -> %s", USE_DEBUG_JSON_IDENTIFIER, boolean);
3636
if (boolean == TRUE_STRING) {
3737
json_config.use_debug = true;
@@ -55,7 +55,7 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
5555
json_dict.erase(DEBUG_PORT_JSON_IDENTIFIER);
5656
}
5757
if (json_dict.has(DEBUG_ADDRESS_JSON_IDENTIFIER)) {
58-
String address = json_dict[DEBUG_ADDRESS_JSON_IDENTIFIER];
58+
godot::String address = json_dict[DEBUG_ADDRESS_JSON_IDENTIFIER];
5959
JVM_DEV_VERBOSE("Value for json argument: %s -> %s", DEBUG_ADDRESS_JSON_IDENTIFIER, address);
6060
if (address.is_valid_ip_address() || address == "*") {
6161
json_config.jvm_debug_address = address;
@@ -66,7 +66,7 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
6666
json_dict.erase(DEBUG_ADDRESS_JSON_IDENTIFIER);
6767
}
6868
if (json_dict.has(WAIT_FOR_DEBUGGER_JSON_IDENTIFIER)) {
69-
String boolean = json_dict[WAIT_FOR_DEBUGGER_JSON_IDENTIFIER];
69+
godot::String boolean = json_dict[WAIT_FOR_DEBUGGER_JSON_IDENTIFIER];
7070
JVM_DEV_VERBOSE("Value for json argument: %s -> %s", WAIT_FOR_DEBUGGER_JSON_IDENTIFIER, boolean);
7171
if (boolean == TRUE_STRING) {
7272
json_config.wait_for_debugger = true;
@@ -101,7 +101,7 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
101101
json_dict.erase(MAX_STRING_SIZE_JSON_IDENTIFIER);
102102
}
103103
if (json_dict.has(DISABLE_GC_JSON_IDENTIFIER)) {
104-
String boolean = json_dict[DISABLE_GC_JSON_IDENTIFIER];
104+
godot::String boolean = json_dict[DISABLE_GC_JSON_IDENTIFIER];
105105
JVM_DEV_VERBOSE("Value for json argument: %s -> %s", DISABLE_GC_JSON_IDENTIFIER, boolean);
106106
if (boolean == TRUE_STRING) {
107107
json_config.disable_gc = true;
@@ -120,7 +120,7 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
120120
}
121121

122122
if (json_dict.has(VERSION_JSON_IDENTIFIER)) {
123-
String version {json_dict[VERSION_JSON_IDENTIFIER]};
123+
godot::String version {json_dict[VERSION_JSON_IDENTIFIER]};
124124
JVM_DEV_VERBOSE("Value for json argument: %s -> %s", VERSION_JSON_IDENTIFIER, version);
125125
if (version != JSON_ARGUMENT_VERSION) {
126126
JVM_LOG_WARNING("Your existing jvm json configuration file was made for an older version of this binding. A "
@@ -136,8 +136,8 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
136136
if (!json_dict.is_empty()) {
137137
godot::Array keys = json_dict.keys();
138138
for (int i = 0; i < keys.size(); i++) {
139-
String key = keys[i];
140-
String value = json_dict[key];
139+
godot::String key = keys[i];
140+
godot::String value = json_dict[key];
141141
JVM_LOG_WARNING("Invalid json configuration argument name: %s", key);
142142
}
143143
is_invalid = true;
@@ -146,11 +146,11 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
146146
return is_invalid;
147147
}
148148

149-
String JvmUserConfiguration::export_configuration_to_json(const JvmUserConfiguration& configuration) {
149+
godot::String JvmUserConfiguration::export_configuration_to_json(const JvmUserConfiguration& configuration) {
150150
// This function assumes all values are valid.
151151
godot::Dictionary json;
152152

153-
String vm_type_value;
153+
godot::String vm_type_value;
154154
switch (configuration.vm_type) {
155155
case jni::JvmType::NONE:
156156
vm_type_value = AUTO_STRING;
@@ -184,7 +184,7 @@ String JvmUserConfiguration::export_configuration_to_json(const JvmUserConfigura
184184
return godot::JSON::stringify(json, " ", true, false);
185185
}
186186

187-
godot::Error split_argument(const String& cmd_arg, String& identifier, String& value) {
187+
godot::Error split_argument(const godot::String& cmd_arg, godot::String& identifier, godot::String& value) {
188188
godot::PackedStringArray jvm_debug_split {cmd_arg.split("=")};
189189

190190
if (jvm_debug_split.size() == 2) {
@@ -199,7 +199,7 @@ godot::Error split_argument(const String& cmd_arg, String& identifier, String& v
199199
return godot::OK;
200200
}
201201

202-
bool get_cmd_bool_or_default(const String& value, bool default_if_empty) {
202+
bool get_cmd_bool_or_default(const godot::String& value, bool default_if_empty) {
203203
if (value.is_empty()) {
204204
return default_if_empty;
205205
} else if (value == TRUE_STRING) {
@@ -211,15 +211,15 @@ bool get_cmd_bool_or_default(const String& value, bool default_if_empty) {
211211
}
212212
}
213213

214-
void JvmUserConfiguration::parse_command_line(const List<String>& args, godot::HashMap<String, Variant>& configuration_map) {
214+
void JvmUserConfiguration::parse_command_line(const godot::List<godot::String>& args, godot::HashMap<godot::String, godot::Variant>& configuration_map) {
215215
// We use a HashMap instead of JvmUserConfiguration so we can still make the difference between a
216216
// JvmUserConfiguration default value and the absence of the matching command line argument. Knowing this is
217217
// essential when merging with the json configuration later.
218218

219219
// Keep in sync with https://godot-kotl.in/en/latest/advanced/commandline-args/
220220
for (const auto& arg : args) {
221-
String identifier;
222-
String value;
221+
godot::String identifier;
222+
godot::String value;
223223
if (split_argument(arg, identifier, value) != godot::Error::OK) { continue; }
224224

225225
if (identifier == VM_TYPE_CMD_IDENTIFIER) {
@@ -272,7 +272,7 @@ void JvmUserConfiguration::parse_command_line(const List<String>& args, godot::H
272272
configuration_map[DISABLE_GC_CMD_IDENTIFIER] = get_cmd_bool_or_default(value, TRUE_STRING);
273273
} else if (identifier == JVM_ARGUMENTS_CMD_IDENTIFIER) {
274274
godot::Array arr {};
275-
for(String jvm_arg: value.split(" ")){
275+
for(godot::String jvm_arg: value.split(" ")){
276276
arr.append(arg);
277277
}
278278
configuration_map[JVM_ARGUMENTS_CMD_IDENTIFIER] = arr;
@@ -285,11 +285,11 @@ void JvmUserConfiguration::parse_command_line(const List<String>& args, godot::H
285285
}
286286

287287
template<typename T>
288-
void replace_json_value_by_cmd_value(const godot::HashMap<String, Variant>& map, T& json_value, const String& cmd_key) {
288+
void replace_json_value_by_cmd_value(const godot::HashMap<godot::String, godot::Variant>& map, T& json_value, const godot::String& cmd_key) {
289289
if (map.has(cmd_key)) { json_value = godot::VariantCaster<T>::cast(map[cmd_key]); }
290290
}
291291

292-
void JvmUserConfiguration::merge_with_command_line(JvmUserConfiguration& json_config, const godot::HashMap<String, Variant>& cmd_map) {
292+
void JvmUserConfiguration::merge_with_command_line(JvmUserConfiguration& json_config, const godot::HashMap<godot::String, godot::Variant>& cmd_map) {
293293
replace_json_value_by_cmd_value(cmd_map, json_config.vm_type, VM_TYPE_CMD_IDENTIFIER);
294294
replace_json_value_by_cmd_value(cmd_map, json_config.jvm_debug_port, DEBUG_PORT_CMD_IDENTIFIER);
295295
replace_json_value_by_cmd_value(cmd_map, json_config.jvm_debug_address, DEBUG_ADDRESS_CMD_IDENTIFIER);

src/jvm/lifecycle/jvm_user_configuration.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ struct JvmUserConfiguration {
5858
JvmUserConfiguration() = default;
5959
~JvmUserConfiguration() = default;
6060

61-
static bool parse_configuration_json(const String& json_string, JvmUserConfiguration& json_config);
62-
static String export_configuration_to_json(const JvmUserConfiguration& configuration);
61+
static bool parse_configuration_json(const godot::String& json_string, JvmUserConfiguration& json_config);
62+
static godot::String export_configuration_to_json(const JvmUserConfiguration& configuration);
6363

64-
static void parse_command_line(const List<String>& args, godot::HashMap<String, Variant>& configuration_map);
64+
static void parse_command_line(const godot::List<godot::String>& args, godot::HashMap<godot::String, godot::Variant>& configuration_map);
6565

66-
static void merge_with_command_line(JvmUserConfiguration& json_config, const godot::HashMap<String, Variant>& cmd_map);
66+
static void merge_with_command_line(JvmUserConfiguration& json_config, const godot::HashMap<godot::String, godot::Variant>& cmd_map);
6767
static void sanitize_and_log_configuration(JvmUserConfiguration& config);
6868
};
6969

src/jvm/wrapper/bootstrap.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ void Bootstrap::init_native_image(jni::Env& p_env) {
5555
wrapped.call_void_method(p_env, INIT_NATIVE_IMAGE);
5656
}
5757

58-
String Bootstrap::get_version(jni::Env& p_env) {
58+
godot::String Bootstrap::get_version(jni::Env& p_env) {
5959
jni::JString str {wrapped.call_object_method(p_env, GET_VERSION)};
60-
String ret {p_env.from_jstring(str)};
60+
godot::String ret {p_env.from_jstring(str)};
6161
str.delete_local_ref(p_env);
6262
return ret;
6363
}

src/jvm/wrapper/bootstrap.h

+8-12
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@ JVM_INSTANCE_WRAPPER(Bootstrap, "godot.runtime.Bootstrap") {
2323
// clang-format on
2424

2525
public:
26+
static void load_classes(JNIEnv * p_env, jobject p_this, jobjectArray p_classes);
27+
static void register_engine_type(JNIEnv * p_env, jobject p_this, jobjectArray p_classes_names, jobjectArray p_singleton_names);
2628

27-
static void load_classes(JNIEnv* p_env, jobject p_this, jobjectArray p_classes);
28-
static void register_engine_type(
29-
JNIEnv* p_env, jobject p_this, jobjectArray p_classes_names,
30-
jobjectArray p_singleton_names
31-
);
32-
33-
Bootstrap(jni::Env& p_env, jni::JObject p_wrapped);
29+
Bootstrap(jni::Env & p_env, jni::JObject p_wrapped);
3430
~Bootstrap() = default;
3531

36-
void init_jar(jni::Env& p_env, const jni::JObject& p_class_loader);
37-
void init_native_image(jni::Env& p_env);
38-
String get_version(jni::Env& p_env);
39-
void finish(jni::Env& p_env);
32+
void init_jar(jni::Env & p_env, const jni::JObject& p_class_loader);
33+
void init_native_image(jni::Env & p_env);
34+
godot::String get_version(jni::Env & p_env);
35+
void finish(jni::Env & p_env);
4036
};
4137

42-
#endif// GODOT_JVM_BOOTSTRAP_H
38+
#endif // GODOT_JVM_BOOTSTRAP_H

src/jvm/wrapper/bridge/bridges_utils.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ namespace bridges {
99
static inline T* from_uint_to_ptr(jlong raw_ptr) {
1010
return reinterpret_cast<T*>(static_cast<uintptr_t>(raw_ptr));
1111
}
12-
}// namespace bridge
12+
} // namespace bridges
1313

14-
#endif// GODOT_JVM_BRIDGES_UTILS_H
14+
#endif // GODOT_JVM_BRIDGES_UTILS_H

src/jvm/wrapper/bridge/callable_bridge.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "bridges_utils.h"
44
#include "constraints.h"
5+
#include "core/variant_allocator.h"
56
#include "jvm/wrapper/kotlin_callable_custom.h"
67
#include "jvm/wrapper/memory/transfer_context.h"
7-
#include "core/variant_allocator.h"
88

99
using namespace bridges;
1010

@@ -16,19 +16,27 @@ uintptr_t CallableBridge::engine_call_constructor_object_string_name(JNIEnv* p_r
1616
jni::Env env {p_raw_env};
1717
godot::Variant args[2] = {};
1818
TransferContext::get_instance().read_args(env, args);
19-
return reinterpret_cast<uintptr_t>(VariantAllocator::alloc(godot::Callable(args[0].operator godot::Object*(), args[1].operator godot::StringName())));
20-
}
21-
22-
uintptr_t CallableBridge::engine_call_constructor_kt_custom_callable(JNIEnv* p_raw_env, jobject p_instance,
23-
jobject p_kt_custom_callable_instance,
24-
jint p_variant_type_ordinal, jint p_hash_code,
25-
jboolean p_has_on_destroy) {
26-
jni::Env env {p_raw_env};
2719
return reinterpret_cast<uintptr_t>(
28-
VariantAllocator::alloc(godot::Callable(memnew(KotlinCallableCustom(env, p_kt_custom_callable_instance, static_cast<godot::Variant::Type>(p_variant_type_ordinal), p_hash_code, p_has_on_destroy))))
20+
VariantAllocator::alloc(godot::Callable(args[0].operator godot::Object*(), args[1].operator godot::StringName()))
2921
);
3022
}
3123

24+
uintptr_t CallableBridge::engine_call_constructor_kt_custom_callable(
25+
JNIEnv* p_raw_env,
26+
jobject p_instance,
27+
jobject p_kt_custom_callable_instance,
28+
jint p_variant_type_ordinal,
29+
jint p_hash_code,
30+
jboolean p_has_on_destroy
31+
) {
32+
jni::Env env {p_raw_env};
33+
return reinterpret_cast<uintptr_t>(VariantAllocator::alloc(
34+
godot::Callable(memnew(
35+
KotlinCallableCustom(env, p_kt_custom_callable_instance, static_cast<godot::Variant::Type>(p_variant_type_ordinal), p_hash_code, p_has_on_destroy)
36+
))
37+
));
38+
}
39+
3240
uintptr_t CallableBridge::engine_call_copy_constructor(JNIEnv* p_raw_env, jobject p_instance) {
3341
jni::Env env {p_raw_env};
3442
godot::Variant args[1] = {};

0 commit comments

Comments
 (0)