From c3b5623a3dca5c88ebf1fa8e376e7a9bc1b78251 Mon Sep 17 00:00:00 2001 From: Struma Date: Sat, 9 Jan 2021 06:37:24 -0500 Subject: [PATCH] Create configuration options specifically for JIT --- binding/binding-mri.cpp | 32 +++++++++++++++++++++----------- mkxp.json | 28 ++++++++++++++++++++++++---- src/config.cpp | 10 ++++++++-- src/config.h | 10 ++++++++-- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index ce22d800..adf0ba99 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -840,28 +840,38 @@ static void mriBindingExecute() { ruby_init(); rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding())); - std::vector rubyArgsC{""}; - for(const auto& string : conf.rubyArgs) - rubyArgsC.push_back(string.c_str()); - rubyArgsC.push_back("-e "); - - void *node = ruby_process_options(rubyArgsC.size(), const_cast(rubyArgsC.data())); + std::vector rubyArgsC{"mkxp-z"}; + rubyArgsC.push_back("-e "); + void *node; + if (conf.jit.enabled) { + std::string verboseLevel("--jit-verbose="); verboseLevel += std::to_string(conf.jit.verboseLevel); + std::string maxCache("--jit-max-cache="); maxCache += std::to_string(conf.jit.maxCache); + std::string minCalls("--jit-min-calls="); minCalls += std::to_string(conf.jit.minCalls); + rubyArgsC.push_back("--jit"); + rubyArgsC.push_back(verboseLevel.c_str()); + rubyArgsC.push_back(maxCache.c_str()); + rubyArgsC.push_back(minCalls.c_str()); + node = ruby_options(rubyArgsC.size(), const_cast(rubyArgsC.data())); + } else { + node = ruby_options(rubyArgsC.size(), const_cast(rubyArgsC.data())); + } + int state; bool valid = ruby_executable_node(node, &state); if (valid) state = ruby_exec_node(node); if (state || !valid) { - #if RAPI_FULL > 187 + // The message is formatted for and automatically spits + // out to the terminal, so let's leave it that way for now +/* VALUE exc = rb_errinfo(); - #else - VALUE exc = rb_gv_get("$!"); - #endif #if RAPI_FULL >= 250 VALUE msg = rb_funcall(exc, rb_intern("full_message"), 0); #else VALUE msg = rb_funcall(exc, rb_intern("message"), 0); #endif - showMsg(std::string("An argument passed to Ruby via 'rubyArg' is invalid:\n") + StringValueCStr(msg)); +*/ + showMsg("An error occurred while initializing Ruby. (Invalid JIT settings?)"); ruby_cleanup(state); shState->rtData().rqTermAck.set(); return; diff --git a/mkxp.json b/mkxp.json index 70c733e2..ce6bb29c 100644 --- a/mkxp.json +++ b/mkxp.json @@ -284,11 +284,31 @@ // "rubyLoadpath": ["/usr/lib64/ruby/", // "/usr/local/share/ruby/site_ruby"], - // Commandline arguments to pass to Ruby, such as to enable JIT. - // Only supported for Ruby ≥2. - // (default: none) + // Determines whether JIT is enabled. This probably + // won't work unless you also have the header file + // that it needs. Only works with Ruby 2.6 or higher. + // (default: false) // - // "rubyArg": ["--jit-verbose=1"], + // "JITEnable": false, + + // Determines what level of verbosity to use when + // logging JIT events. Starts at 0, which is next + // to nothing. Set it higher to see more. + // (default: 0) + // + // "JITVerboseLevel": 0, + + // Determines how many compiled methods that Ruby + // will keep in its cache. + // (default: 1000) + // + // "JITMaxCache": 1000, + + // Determines how many times a function has to be + // called before it is compiled. + // (default: 5) + // + // "JITMinCalls": 5, // SoundFont to use for midi playback (via fluidsynth) diff --git a/src/config.cpp b/src/config.cpp index b8cc0bd5..14977408 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -91,7 +91,10 @@ void Config::read(int argc, char *argv[]) { {"RTP", json::array({})}, {"fontSub", json::array({})}, {"rubyLoadpath", json::array({})}, - {"rubyArg", json::array({})} + {"JITEnable", false}, + {"JITVerboseLevel", 0}, + {"JITMaxCache", 1000}, + {"JITMinCalls", 5} }).as_object(); #define GUARD(exp) \ @@ -173,12 +176,15 @@ try { exp } catch (...) {} SET_OPT(pathCache, boolean); SET_OPT(encryptedGraphics, boolean); SET_OPT(useScriptNames, boolean); + SET_OPT_CUSTOMKEY(jit.enabled, JITEnable, boolean); + SET_OPT_CUSTOMKEY(jit.verboseLevel, JITVerboseLevel, integer); + SET_OPT_CUSTOMKEY(jit.maxCache, JITMaxCache, integer); + SET_OPT_CUSTOMKEY(jit.minCalls, JITMinCalls, integer); fillStringVec(opts["preloadScript"], preloadScripts); fillStringVec(opts["RTP"], rtps); fillStringVec(opts["fontSub"], fontSubs); fillStringVec(opts["rubyLoadpath"], rubyLoadpaths); - fillStringVec(opts["rubyArg"], rubyArgs); rgssVersion = clamp(rgssVersion, 0, 3); SE.sourceCount = clamp(SE.sourceCount, 1, 64); diff --git a/src/config.h b/src/config.h index bec07dae..d83f5bfd 100644 --- a/src/config.h +++ b/src/config.h @@ -86,8 +86,6 @@ struct Config { std::vector rubyLoadpaths; - std::vector rubyArgs; - /* Editor flags */ struct { bool debug; @@ -99,6 +97,14 @@ struct Config { std::string scripts; std::string title; } game; + + // JIT Options + struct { + bool enabled; + int verboseLevel; + int maxCache; + int minCalls; + } jit; /* Internal */ std::string customDataPath;