roc-java icon indicating copy to clipboard operation
roc-java copied to clipboard

Detach current thread only at its exit

Open MatteoArella opened this issue 5 years ago • 3 comments

Actually we are calling AttachCurrentThread and DetachCurrentThread inside the logger_handler function (https://github.com/roc-project/roc-java/blob/master/roc_jni/src/main/cpp/logger.cpp);

As it has been discussed at #18 this can slow down performances.

A more efficient solution would involve detaching thread just before its exit, as it's described at https://developer.android.com/training/articles/perf-jni#threads:

you can use pthread_key_create() to define a destructor function that will be called before the thread exits, and call DetachCurrentThread() from there. (Use that key with pthread_setspecific() to store the JNIEnv in thread-local-storage).

MatteoArella avatar Jun 09 '20 16:06 MatteoArella

let me take this up @MatteoArella @gavv what I need before working on this-

  • get started doc to do a dev setup
  • steps to repro the issue

panwarab avatar Oct 01 '20 05:10 panwarab

Great!

A dev setup can be obtained running travis-ci jobs locally.

Linux

  1. build libroc:
    scripts/travis/linux/before_install.sh
    scripts/travis/linux/install.sh
    
  2. build roc-java and run tests:
    ./gradlew build
    

Android

  1. export some env variables for android environment configuration, for example:

    export JAVA_VERSION=8 
    export ANDROID_API=28
    export ANDROID_BUILD_TOOLS_VERSION=28.0.3
    export ANDROID_NDK_VERSION=21.1.6352462
    export ROC_BASE_DIR=/tmp/roc-build   # libroc prefix destination path
    
  2. build libroc for all android ABIs with:

    scripts/travis/android/install.sh
    
  3. build android subproject and run instrumented tests:

    scripts/travis/android/script.sh
    

The step 3 will run a fresh docker container and a new AVD at each execution; if it's needed to only build and test android subproject (only after steps 1-2 are done) you can just run /bin/bash on rocstreaming/env-android:jdk$JAVA_VERSION docker image with:

docker run -it --rm --privileged --env API=$ANDROID_API \
    --env BUILD_TOOLS_VERSION=$ANDROID_BUILD_TOOLS_VERSION \
    --env NDK_VERSION=$ANDROID_NDK_VERSION \
    --env ROC_BASE_DIR=$ROC_BASE_DIR \
    -v $PWD:$PWD -v $ROC_BASE_DIR:$ROC_BASE_DIR \
    -v android-sdk:/sdk -w $PWD \
        rocstreaming/env-android:jdk$JAVA_VERSION /bin/bash

then create an AVD

device --name "roc_device" --image "default" --api "${API}" create
device --name "roc_device" start

and finally build and test roc-android

cd android
./gradlew build
./gradlew cAT --info --stacktrace

Additional infos about our env-android docker image are available here.

MatteoArella avatar Oct 02 '20 19:10 MatteoArella

@masterskipper Hi, do you still have plans on this issue?

gavv avatar Dec 04 '20 11:12 gavv