Skip to content

Commit ad44f4a

Browse files
authored
Implement multiple custom jvm arguments. (#794)
1 parent 64cdaf5 commit ad44f4a

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

docs/src/doc/user-guide/advanced/commandline-args-and-configuration.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ of the project to customize the behaviour of the Godot Kotlin/JVM binding.
55
Note that in case the same argument is used in both JSON and command-line, the command-line argument got the priority.
66

77

8-
| Command-line | Configuration json | Default value | Description | Example |
9-
|-------------------------------------|-------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|
10-
| --jvm-vm-type | vm_type | auto | Defines the VM to run on. Possible values are `auto`, `jvm`, `graal_native_image` and `art`. When set to `graal_native_image` it uses Graal native image. This has no effect on android platform. | `--jvm-vm-type=jvm` or `vm-type=jvm` |
11-
| --jvm-use-debug | use_debug | false | Defines if the jvm debug server should be started. | `--jvm-use_debug` or `use_debug=true` |
12-
| --jvm-debug-port | debug_port | 5005 | Defines the port to which you can attach a remote debugger. **Note:** the module `jdk.jdwp.agent` is needed in the embedded JRE if you want to debug your application. If you need `jmx`, also the module `jdk.management.agent` is needed | `--jvm-debug-port=5005` or `debug-port=5005` |
13-
| --jvm-debug-address | debug_address | localhost | Defines which adresses are allowed for debugging | `--jvm-debug-address=localhost` or `debug-address=localhost` |
14-
| --jvm-wait-for-debugger | wait_for_debugger | true | Accepted values: `true` or `false`. Defines if the jvm should suspend execution until a remote debugger is attached. Only effective if either `--jvm-debug-port` or `--jvm-debug-address` is set | `--wait-for-debugger` or `wait-for-debugger=true` |
15-
| --jvm-jmx-port | jmx_port | -1 (disabled) | Defines the jmx port. **Note:** the module `jdk.management.agent` is needed in the embedded JRE to be able to use jmx | `--jvm-jmx-port=5006` or `jmx-port=5006` |
16-
| --jvm-max-string-size | max_string_size | 512 | Maximum size of strings sent through the buffer. When above that value, strings are sent with a slower JNI Call. A bigger size means a bigger buffer. Increase if you need a lot of long strings and don't mind using more memory. One buffer exists for each thread | `--jvm-max-string-size=512` or `max-string-size=512` |
17-
| --jvm-disable-gc | disable_gc | false | Disables our GC. **Caution:** If you disable our GC you **will** have memory leaks as all Reference types and Native Types are not Garbage collected anymore | `--jvm-disable-gc` or `disable-gc=true` |
18-
| Not available | jvm_args | | Allows to set your own arguments for the JVM, make sure they are valid if you don't want the JVM not starting properly. Avoid overlapping with others arguments if you want to set debug or jmx. | |
8+
| Command-line | Configuration json | Default value | Description | Example |
9+
|-------------------------|---------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
10+
| --jvm-vm-type | vm_type | auto | Defines the VM to run on. Possible values are `auto`, `jvm`, `graal_native_image` and `art`. When set to `graal_native_image` it uses Graal native image. This has no effect on android platform. | `--jvm-vm-type=jvm` or `vm-type=jvm` |
11+
| --jvm-use-debug | use_debug | false | Defines if the jvm debug server should be started. | `--jvm-use_debug` or `use_debug=true` |
12+
| --jvm-debug-port | debug_port | 5005 | Defines the port to which you can attach a remote debugger. **Note:** the module `jdk.jdwp.agent` is needed in the embedded JRE if you want to debug your application. If you need `jmx`, also the module `jdk.management.agent` is needed | `--jvm-debug-port=5005` or `debug-port=5005` |
13+
| --jvm-debug-address | debug_address | localhost | Defines which adresses are allowed for debugging | `--jvm-debug-address=localhost` or `debug-address=localhost` |
14+
| --jvm-wait-for-debugger | wait_for_debugger | true | Accepted values: `true` or `false`. Defines if the jvm should suspend execution until a remote debugger is attached. Only effective if either `--jvm-debug-port` or `--jvm-debug-address` is set | `--wait-for-debugger` or `wait-for-debugger=true` |
15+
| --jvm-jmx-port | jmx_port | -1 (disabled) | Defines the jmx port. **Note:** the module `jdk.management.agent` is needed in the embedded JRE to be able to use jmx | `--jvm-jmx-port=5006` or `jmx-port=5006` |
16+
| --jvm-max-string-size | max_string_size | 512 | Maximum size of strings sent through the buffer. When above that value, strings are sent with a slower JNI Call. A bigger size means a bigger buffer. Increase if you need a lot of long strings and don't mind using more memory. One buffer exists for each thread | `--jvm-max-string-size=512` or `max-string-size=512` |
17+
| --jvm-disable-gc | disable_gc | false | Disables our GC. **Caution:** If you disable our GC you **will** have memory leaks as all Reference types and Native Types are not Garbage collected anymore | `--jvm-disable-gc` or `disable-gc=true` |
18+
| --custom-jvm-args | custom_jvm_args | | Allows to set your own arguments for the JVM, make sure they are valid if you don't want the JVM not starting properly. Avoid overlapping with others arguments if you want to set debug or jmx. | `--custom-jvm-args="-Xmx4g -Xms4g"`(Use space as a separator) or `custom_jvm_args=["-Xmx4g", "-Xms4g"]` |
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2+
"custom_jvm_args": [],
23
"debug_address": "*",
34
"debug_port": 5005,
45
"disable_gc": false,
56
"jmx_port": -1,
6-
"jvm_args": "",
77
"max_string_size": -1,
88
"use_debug": false,
9-
"version": "1.0",
9+
"version": "2.0",
1010
"vm_type": "auto",
1111
"wait_for_debugger": true
12-
}
12+
}

src/gd_kotlin.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ void GDKotlin::set_jvm_options() {
189189
"You are using custom arguments for the JVM. Make sure they are valid or you risk the JVM to "
190190
"not launch properly"
191191
);
192-
jvm_options.add_custom_options(user_configuration.jvm_args);
192+
for (String jvm_arg : user_configuration.jvm_args) {
193+
jvm_options.add_custom_options(jvm_arg);
194+
}
193195
}
194196
}
195197

@@ -266,10 +268,7 @@ bool GDKotlin::initialize_core_library() {
266268
jni::Env env {jni::Jvm::current_env()};
267269

268270
if (!JvmManager::initialize_jvm_wrappers(env, bootstrap_class_loader)) {
269-
DISPLAY_ERROR(
270-
"The boostrap.jar is invalid and can't be loaded.",
271-
"Check if your build.gradle file use the same version as the editor."
272-
);
271+
DISPLAY_ERROR("The boostrap.jar is invalid and can't be loaded.", "Check if your build.gradle file use the same version as the editor.");
273272
}
274273

275274
if (user_configuration.max_string_size != -1) {
@@ -410,7 +409,7 @@ void GDKotlin::display_initialization_error_hint(String cause, String hint) {
410409
}
411410

412411
void GDKotlin::validate_state() {
413-
// Don't invalidate the state because everything is either loaded or the Kotlin project has simply not be built.
412+
// Don't invalidate the state because everything is either loaded or the Kotlin project has simply not be built.
414413
if (state == State::CORE_LIBRARY_INITIALIZED || state == State::JVM_SCRIPTS_INITIALIZED) { return; }
415414

416415
finalize_down_to(NOT_STARTED);

src/lifecycle/jvm_user_configuration.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool JvmUserConfiguration::parse_configuration_json(const String& json_string, J
2626
json_config.vm_type = jni::JvmType::ART;
2727
} else {
2828
is_invalid = true;
29-
JVM_LOG_WARNING("Wrong JVM type in configuration file: %s. It will be ignored", value);;
29+
JVM_LOG_WARNING("Wrong JVM type in configuration file: %s. It will be ignored", value);
3030
}
3131
json_dict.erase(VM_TYPE_JSON_IDENTIFIER);
3232
}
@@ -232,7 +232,7 @@ void JvmUserConfiguration::parse_command_line(const List<String>& args, HashMap<
232232
} else if (value == ART_STRING) {
233233
configuration_map[VM_TYPE_CMD_IDENTIFIER] = jni::JvmType::ART;
234234
} else {
235-
JVM_LOG_WARNING("Wrong JVM type in command line arguments: %s. It will be ignored", value);;
235+
JVM_LOG_WARNING("Wrong JVM type in command line arguments: %s. It will be ignored", value);
236236
}
237237
} else if (identifier == USE_DEBUG_CMD_IDENTIFIER) {
238238
configuration_map[USE_DEBUG_CMD_IDENTIFIER] = get_cmd_bool_or_default(value, TRUE_STRING);
@@ -248,7 +248,7 @@ void JvmUserConfiguration::parse_command_line(const List<String>& args, HashMap<
248248
if (value.is_valid_ip_address()) {
249249
configuration_map[DEBUG_ADDRESS_CMD_IDENTIFIER] = value;
250250
} else {
251-
JVM_LOG_WARNING("Invalid JVM address value command line arguments: %s. It will be ignored", value);;
251+
JVM_LOG_WARNING("Invalid JVM address value command line arguments: %s. It will be ignored", value);
252252
}
253253
} else if (identifier == WAIT_FOR_DEBUGGER_CMD_IDENTIFIER) {
254254
configuration_map[WAIT_FOR_DEBUGGER_CMD_IDENTIFIER] = get_cmd_bool_or_default(value, TRUE_STRING);
@@ -270,6 +270,12 @@ void JvmUserConfiguration::parse_command_line(const List<String>& args, HashMap<
270270
}
271271
} else if (identifier == DISABLE_GC_CMD_IDENTIFIER) {
272272
configuration_map[DISABLE_GC_CMD_IDENTIFIER] = get_cmd_bool_or_default(value, TRUE_STRING);
273+
} else if (identifier == JVM_ARGUMENTS_CMD_IDENTIFIER) {
274+
Array arr {};
275+
for(String jvm_arg: value.split(" ")){
276+
arr.append(arg);
277+
}
278+
configuration_map[JVM_ARGUMENTS_CMD_IDENTIFIER] = arr;
273279
}
274280

275281
for (const auto& map_element : configuration_map) {
@@ -285,7 +291,6 @@ void replace_json_value_by_cmd_value(const HashMap<String, Variant>& map, T& jso
285291

286292
void JvmUserConfiguration::merge_with_command_line(JvmUserConfiguration& json_config, const HashMap<String, Variant>& cmd_map) {
287293
replace_json_value_by_cmd_value(cmd_map, json_config.vm_type, VM_TYPE_CMD_IDENTIFIER);
288-
289294
replace_json_value_by_cmd_value(cmd_map, json_config.jvm_debug_port, DEBUG_PORT_CMD_IDENTIFIER);
290295
replace_json_value_by_cmd_value(cmd_map, json_config.jvm_debug_address, DEBUG_ADDRESS_CMD_IDENTIFIER);
291296
replace_json_value_by_cmd_value(cmd_map, json_config.wait_for_debugger, WAIT_FOR_DEBUGGER_CMD_IDENTIFIER);
@@ -296,10 +301,10 @@ void JvmUserConfiguration::merge_with_command_line(JvmUserConfiguration& json_co
296301
json_config.use_debug = true;
297302
}
298303
replace_json_value_by_cmd_value(cmd_map, json_config.use_debug, DEBUG_PORT_CMD_IDENTIFIER);
299-
300304
replace_json_value_by_cmd_value(cmd_map, json_config.jvm_jmx_port, JMX_PORT_CMD_IDENTIFIER);
301305
replace_json_value_by_cmd_value(cmd_map, json_config.max_string_size, MAX_STRING_SIZE_CMD_IDENTIFIER);
302306
replace_json_value_by_cmd_value(cmd_map, json_config.disable_gc, DISABLE_GC_CMD_IDENTIFIER);
307+
replace_json_value_by_cmd_value(cmd_map, json_config.jvm_args, JVM_ARGUMENTS_CMD_IDENTIFIER);
303308
}
304309

305310
void JvmUserConfiguration::sanitize_and_log_configuration(JvmUserConfiguration& config) {

src/lifecycle/jvm_user_configuration.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef GODOT_JVM_JVM_USER_CONFIGURATION_H
22
#define GODOT_JVM_JVM_USER_CONFIGURATION_H
33

4+
#include "core/variant/typed_array.h"
45
#include "jni/jvm.h"
56

67
// JSON IDENTIFIER
@@ -13,7 +14,7 @@ static constexpr const char* JMX_PORT_JSON_IDENTIFIER {"jmx_port"};
1314
static constexpr const char* WAIT_FOR_DEBUGGER_JSON_IDENTIFIER {"wait_for_debugger"};
1415
static constexpr const char* MAX_STRING_SIZE_JSON_IDENTIFIER {"max_string_size"};
1516
static constexpr const char* DISABLE_GC_JSON_IDENTIFIER {"disable_gc"};
16-
static constexpr const char* JVM_ARGUMENTS_JSON_IDENTIFIER {"jvm_args"};
17+
static constexpr const char* JVM_ARGUMENTS_JSON_IDENTIFIER {"custom_jvm_args"};
1718

1819
// COMMAND LINE IDENTIFIER
1920
static constexpr const char* VM_TYPE_CMD_IDENTIFIER {"--jvm-vm-type"};
@@ -24,6 +25,7 @@ static constexpr const char* WAIT_FOR_DEBUGGER_CMD_IDENTIFIER {"--wait-for-debug
2425
static constexpr const char* JMX_PORT_CMD_IDENTIFIER {"--jvm-jmx-port"};
2526
static constexpr const char* MAX_STRING_SIZE_CMD_IDENTIFIER {"--jvm-max-string-size"};
2627
static constexpr const char* DISABLE_GC_CMD_IDENTIFIER {"--jvm-disable-gc"};
28+
static constexpr const char* JVM_ARGUMENTS_CMD_IDENTIFIER {"--custom-jvm-args"};
2729

2830
// VALUE
2931
static constexpr const char* AUTO_STRING {"auto"};
@@ -32,7 +34,7 @@ static constexpr const char* GRAAL_NATIVE_IMAGE_STRING {"graal_native_image"};
3234
static constexpr const char* ART_STRING {"art"};
3335
static constexpr const char* TRUE_STRING {"true"};
3436
static constexpr const char* FALSE_STRING {"false"};
35-
static constexpr const char* JSON_ARGUMENT_VERSION {"1.0"};
37+
static constexpr const char* JSON_ARGUMENT_VERSION {"2.0"};
3638

3739

3840
struct JvmUserConfiguration {
@@ -50,7 +52,7 @@ struct JvmUserConfiguration {
5052

5153
bool disable_gc {false};
5254

53-
String jvm_args {""};
55+
Array jvm_args;
5456

5557
JvmUserConfiguration() = default;
5658
~JvmUserConfiguration() = default;

0 commit comments

Comments
 (0)