Create configuration options specifically for JIT

This commit is contained in:
Struma 2021-01-09 06:37:24 -05:00 committed by Roza
parent 67a19c8b5b
commit c3b5623a3d
4 changed files with 61 additions and 19 deletions

View file

@ -840,28 +840,38 @@ static void mriBindingExecute() {
ruby_init();
rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
std::vector<const char*> rubyArgsC{""};
for(const auto& string : conf.rubyArgs)
rubyArgsC.push_back(string.c_str());
rubyArgsC.push_back("-e ");
std::vector<const char*> 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<char**>(rubyArgsC.data()));
} else {
node = ruby_options(rubyArgsC.size(), const_cast<char**>(rubyArgsC.data()));
}
void *node = ruby_process_options(rubyArgsC.size(), const_cast<char**>(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;

View file

@ -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)

View file

@ -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);

View file

@ -86,8 +86,6 @@ struct Config {
std::vector<std::string> rubyLoadpaths;
std::vector<std::string> rubyArgs;
/* Editor flags */
struct {
bool debug;
@ -100,6 +98,14 @@ struct Config {
std::string title;
} game;
// JIT Options
struct {
bool enabled;
int verboseLevel;
int maxCache;
int minCalls;
} jit;
/* Internal */
std::string customDataPath;
std::string commonDataPath;