From 5756f1f43e65d79db9916e247788c15dbf7f263e Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sat, 2 Jan 2021 03:00:39 +0100 Subject: [PATCH] LuaJIT on Android fixes (#7094) * Don't flag Android as should_restrict_JIT And allow disabling the C blitter, to put the workaround to the test... * Add a -d, --debug flag to the log function Catches KOReader's debug, as well as (our) dlopen & luajit logging * Bump android-luajit-launcher https://github.com/koreader/android-luajit-launcher/pull/283 https://github.com/koreader/android-luajit-launcher/pull/282 * Bump base (https://github.com/koreader/koreader-base/pull/1279) --- base | 2 +- frontend/apps/filemanager/filemanagermenu.lua | 2 +- frontend/device/android/device.lua | 10 ++-- kodev | 56 +++++++++++++++++-- platform/android/luajit-launcher | 2 +- 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/base b/base index 7c1057f8e..395936d25 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 7c1057f8e9c54265938a10364342dbfeb0b36e6b +Subproject commit 395936d25688e8bb19d67133ce1c24206f602f8e diff --git a/frontend/apps/filemanager/filemanagermenu.lua b/frontend/apps/filemanager/filemanagermenu.lua index aaddde7dd..2f45d5774 100644 --- a/frontend/apps/filemanager/filemanagermenu.lua +++ b/frontend/apps/filemanager/filemanagermenu.lua @@ -355,7 +355,7 @@ function FileManagerMenu:setUpdateItemTable() end, }) end - if not (Device.should_restrict_JIT or Device:isAndroid()) then + if not Device.should_restrict_JIT then local Blitbuffer = require("ffi/blitbuffer") table.insert(self.menu_items.developer_options.sub_item_table, { text = _("Disable C blitter"), diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index 71d5c6f03..4b3fc4e74 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -119,7 +119,9 @@ local Device = Generic:new{ -- required for those modules where it *really* matters (e.g., ffi/blitbuffer.lua). -- This is also why we try to actually avoid entering actual loops in the Lua blitter on Android, -- and instead attempt to do most of everything via the C implementation. - should_restrict_JIT = true, + -- NOTE: Since https://github.com/koreader/android-luajit-launcher/pull/283, we've patched LuaJIT + -- to ensure that the initial mcode alloc works, and sticks around, which is why this is no longer enabled. + should_restrict_JIT = false, } function Device:init() @@ -387,9 +389,9 @@ local function processEvents() if poll_state >= 0 then if source[0] ~= nil then if source[0].id == C.LOOPER_ID_MAIN then - local cmd = C.android_app_read_cmd(android.app) - C.android_app_pre_exec_cmd(android.app, cmd) - C.android_app_post_exec_cmd(android.app, cmd) + local cmd = android.glue.android_app_read_cmd(android.app) + android.glue.android_app_pre_exec_cmd(android.app, cmd) + android.glue.android_app_post_exec_cmd(android.app, cmd) elseif source[0].id == C.LOOPER_ID_INPUT then local event = ffi.new("AInputEvent*[1]") while android.lib.AInputQueue_getEvent(android.app.inputQueue, event) >= 0 do diff --git a/kodev b/kodev index f38456c15..c808133ef 100755 --- a/kodev +++ b/kodev @@ -1073,7 +1073,11 @@ OPTIONS: function kodev-log() { LOG_HELP_MSG=" -usage: log +usage: log + +OPTIONS: + + -d, --debug more verbose logs (e.g., debug builds) TARGET: @@ -1084,13 +1088,53 @@ TARGET: exit 1 } + # Defaults + ignore_translation=0 + + declare opt + declare -r E_OPTERR=85 + declare -r short_opts="dh" + declare -r long_opts="debug, help" + + if ! opt=$(getopt -o "${short_opts}" --long "${long_opts}" --name "kodev" -- "${@}"); then + echo "${LOG_HELP_MSG}" + exit ${E_OPTERR} + fi + + eval set -- "${opt}" + + while true; do + PARAM="${1}" + # Support using an = assignment with short options (e.g., -f=blah instead of -f blah). + VALUE="${2/#=/}" + case "${PARAM}" in + -d | --debug) + export KODEBUG=1 + ;; + -h | --help) + echo "${LOG_HELP_MSG}" + exit 0 + ;; + --) + break + ;; + *) + echo "ERROR: unknown option \"${PARAM}\"" + echo "${RELEASE_HELP_MSG}" + exit 1 + ;; + esac + shift + done + shift + case "${1}" in - -h | --help) - echo "${LOG_HELP_MSG}" - exit 0 - ;; android) - adb logcat 'KOReader:I ActivityManager:* AndroidRuntime:* DEBUG:* *:F' + if [ -n "${KODEBUG}" ]; then + adb logcat 'KOReader:* ActivityManager:* AndroidRuntime:* DEBUG:* *:F dlopen:* LuaJIT:*' + else + adb logcat 'KOReader:I ActivityManager:* AndroidRuntime:* DEBUG:* *:F' + fi ;; *) echo "Unsupported target: $1." diff --git a/platform/android/luajit-launcher b/platform/android/luajit-launcher index 9099a388a..af9b9d30c 160000 --- a/platform/android/luajit-launcher +++ b/platform/android/luajit-launcher @@ -1 +1 @@ -Subproject commit 9099a388a09259285bcc9f96dde2149005113d36 +Subproject commit af9b9d30c10451a3be423d8fb55f05945a3133f6