Skip to content

Commit

Permalink
🎄 Javet v1.0.5 (#114)
Browse files Browse the repository at this point in the history
* Fixed crash issue for Android
* Upgraded Javet engine pool to expose more statistics
* Upgraded Javet engine pool scheduling algorithm
  • Loading branch information
caoccao authored Nov 26, 2021
1 parent 10f7371 commit 6192b67
Show file tree
Hide file tree
Showing 452 changed files with 8,382 additions and 2,860 deletions.
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,33 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
<!-- Mac OS (x86_64 Only) -->
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet-macos</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
Gradle Kotlin DSL
^^^^^^^^^^^^^^^^^

.. code-block:: kotlin
implementation("com.caoccao.javet:javet:1.0.4") // Linux or Windows
implementation("com.caoccao.javet:javet-macos:1.0.4") // Mac OS (x86_64 Only)
implementation("com.caoccao.javet:javet-android:1.0.3") // Android (arm, arm64, x86 and x86_64)
implementation("com.caoccao.javet:javet:1.0.5") // Linux or Windows
implementation("com.caoccao.javet:javet-macos:1.0.5") // Mac OS (x86_64 Only)
implementation("com.caoccao.javet:javet-android:1.0.5") // Android (arm, arm64, x86 and x86_64)
Gradle Groovy DSL
^^^^^^^^^^^^^^^^^

.. code-block:: groovy
implementation 'com.caoccao.javet:javet:1.0.4' // Linux or Windows
implementation 'com.caoccao.javet:javet-macos:1.0.4' // Mac OS (x86_64 Only)
implementation 'com.caoccao.javet:javet-android:1.0.3' // Android (arm, arm64, x86 and x86_64)
implementation 'com.caoccao.javet:javet:1.0.5' // Linux or Windows
implementation 'com.caoccao.javet:javet-macos:1.0.5' // Mac OS (x86_64 Only)
implementation 'com.caoccao.javet:javet-android:1.0.5' // Android (arm, arm64, x86 and x86_64)
Hello Javet
-----------
Expand Down
2 changes: 1 addition & 1 deletion android/javet-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {
id("com.android.library")
}

version = "1.0.4"
version = "1.0.5"

android {
compileSdk = 30
Expand Down
2 changes: 1 addition & 1 deletion android/javet-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.caoccao.javet"
android:versionCode="1"
android:versionName="1.0.4"
android:versionName="1.0.5"
>

</manifest>
4 changes: 2 additions & 2 deletions android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.caoccao.javet</groupId>
<artifactId>javet-android</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
<name>javet</name>
<packaging>aar</packaging>
<description>Javet is Java + V8 (JAVa + V + EighT). It is an awesome way of embedding V8 in Java.</description>
Expand All @@ -29,7 +29,7 @@
<connection>scm:git:git://github.com/caoccao/Javet.git</connection>
<developerConnection>scm:git:git@github.com:caoccao/caoccao.git</developerConnection>
<url>https://github.com/caoccao/Javet</url>
<tag>1.0.4</tag>
<tag>1.0.5</tag>
</scm>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {
}

group = "com.caoccao.javet"
version = "1.0.4"
version = "1.0.5"

dependencies {
testImplementation("org.eclipse.jetty.websocket:websocket-server:9.4.38.v20210224")
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage for V8: sh build-android.sh -DV8_DIR=${HOME}/v8 -DCMAKE_ANDROID_NDK=${HOME}/android -DCMAKE_ANDROID_ARCH=arm64
# Usage for Node: sh build-android.sh -DNODE_DIR=${HOME}/node -DCMAKE_ANDROID_NDK=${HOME}/android -DCMAKE_ANDROID_ARCH=arm64
JAVET_VERSION=1.0.4
JAVET_VERSION=1.0.5
rm -rf build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage for V8: sh build-linux.sh -DV8_DIR=${HOME}/v8
# Usage for Node: sh build-linux.sh -DNODE_DIR=${HOME}/node
JAVET_VERSION=1.0.4
JAVET_VERSION=1.0.5
rm -rf build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage for V8: sh build-macos.sh -DV8_DIR=${HOME}/v8
# Usage for Node: sh build-macos.sh -DNODE_DIR=${HOME}/node
JAVET_VERSION=1.0.4
JAVET_VERSION=1.0.5
rm -rf build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-windows.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
REM Usage for V8: build -DV8_DIR=C:\v8
REM Usage for Node: build -DNODE_DIR=C:\node
SET JAVET_VERSION=1.0.4
SET JAVET_VERSION=1.0.5
rd /s/q build
mkdir build
cd build
Expand Down
123 changes: 85 additions & 38 deletions cpp/jni/com_caoccao_javet_interop_V8Native.cpp

Large diffs are not rendered by default.

64 changes: 36 additions & 28 deletions cpp/jni/javet_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ namespace Javet {

jclassV8Runtime = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/interop/V8Runtime"));
jmethodIDV8RuntimeGetV8Module = jniEnv->GetMethodID(jclassV8Runtime, "getV8Module", "(Ljava/lang/String;Lcom/caoccao/javet/values/reference/IV8Module;)Lcom/caoccao/javet/values/reference/IV8Module;");
jmethodIDV8RuntimeGCEpilogueCallback = jniEnv->GetMethodID(jclassV8Runtime, "gcEpilogueCallback", "(II)V");
jmethodIDV8RuntimeGCPrologueCallback = jniEnv->GetMethodID(jclassV8Runtime, "gcPrologueCallback", "(II)V");
jmethodIDV8RuntimeReceiveGCEpilogueCallback = jniEnv->GetMethodID(jclassV8Runtime, "receiveGCEpilogueCallback", "(II)V");
jmethodIDV8RuntimeReceiveGCPrologueCallback = jniEnv->GetMethodID(jclassV8Runtime, "receiveGCPrologueCallback", "(II)V");
jmethodIDV8RuntimeReceivePromiseRejectCallback = jniEnv->GetMethodID(jclassV8Runtime, "receivePromiseRejectCallback", "(ILcom/caoccao/javet/values/reference/V8ValuePromise;Lcom/caoccao/javet/values/V8Value;)V");
jmethodIDV8RuntimeRemoveCallbackContext = jniEnv->GetMethodID(jclassV8Runtime, "removeCallbackContext", "(J)V");
}
Expand Down Expand Up @@ -105,7 +105,7 @@ namespace Javet {
FETCH_JNI_ENV(GlobalJavaVM);
auto externalV8Runtime = v8Runtime->externalV8Runtime;
jobject mIV8Module = jniEnv->CallObjectMethod(
externalV8Runtime, jmethodIDV8RuntimeGCEpilogueCallback, (jint)v8GCType, (jint)v8GCCallbackFlags);
externalV8Runtime, jmethodIDV8RuntimeReceiveGCEpilogueCallback, (jint)v8GCType, (jint)v8GCCallbackFlags);
}
}
}
Expand All @@ -124,7 +124,7 @@ namespace Javet {
FETCH_JNI_ENV(GlobalJavaVM);
auto externalV8Runtime = v8Runtime->externalV8Runtime;
jobject mIV8Module = jniEnv->CallObjectMethod(
externalV8Runtime, jmethodIDV8RuntimeGCPrologueCallback, (jint)v8GCType, (jint)v8GCCallbackFlags);
externalV8Runtime, jmethodIDV8RuntimeReceiveGCPrologueCallback, (jint)v8GCType, (jint)v8GCCallbackFlags);
}
}
}
Expand Down Expand Up @@ -255,26 +255,32 @@ namespace Javet {
callbackContext,
thisObject,
externalArgs);
if (jniEnv->ExceptionCheck()) {
Javet::Exceptions::ThrowV8Exception(jniEnv, v8Context, "Uncaught JavaError in function callback");
}
else if (isReturnResult) {
if (mResult == nullptr) {
args.GetReturnValue().SetUndefined();
}
else {
args.GetReturnValue().Set(Javet::Converter::ToV8Value(jniEnv, v8Context, mResult));
}
}
if (thisObject != nullptr) {
jniEnv->DeleteLocalRef(thisObject);
}
if (externalArgs != nullptr) {
jniEnv->DeleteLocalRef(externalArgs);
}
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
if (jniEnv->ExceptionCheck()) {
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
}
Javet::Exceptions::ThrowV8Exception(jniEnv, v8Context, "Uncaught JavaError in function callback");
}
else {
if (isReturnResult) {
if (mResult == nullptr) {
args.GetReturnValue().SetUndefined();
}
else {
args.GetReturnValue().Set(Javet::Converter::ToV8Value(jniEnv, v8Context, mResult));
}
}
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
}
}
}
}
Expand Down Expand Up @@ -308,7 +314,14 @@ namespace Javet {
callbackContext,
thisObject,
nullptr);
if (thisObject != nullptr) {
jniEnv->DeleteLocalRef(thisObject);
}
if (jniEnv->ExceptionCheck()) {
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
}
Javet::Exceptions::ThrowV8Exception(jniEnv, v8Context, "Uncaught JavaError in property getter callback");
}
else {
Expand All @@ -317,15 +330,10 @@ namespace Javet {
}
else {
args.GetReturnValue().Set(Javet::Converter::ToV8Value(jniEnv, v8Context, mResult));
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
}
}
if (thisObject != nullptr) {
jniEnv->DeleteLocalRef(thisObject);
}
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
}
}
}
}
Expand Down Expand Up @@ -363,16 +371,16 @@ namespace Javet {
callbackContext,
thisObject,
mPropertyValue);
if (jniEnv->ExceptionCheck()) {
Javet::Exceptions::ThrowV8Exception(jniEnv, v8Context, "Uncaught JavaError in property setter callback");
}
if (thisObject != nullptr) {
jniEnv->DeleteLocalRef(thisObject);
}
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
}
if (jniEnv->ExceptionCheck()) {
Javet::Exceptions::ThrowV8Exception(jniEnv, v8Context, "Uncaught JavaError in property setter callback");
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/jni/javet_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace Javet {

static jclass jclassV8Runtime;
static jmethodID jmethodIDV8RuntimeGetV8Module;
static jmethodID jmethodIDV8RuntimeGCEpilogueCallback;
static jmethodID jmethodIDV8RuntimeGCPrologueCallback;
static jmethodID jmethodIDV8RuntimeReceiveGCEpilogueCallback;
static jmethodID jmethodIDV8RuntimeReceiveGCPrologueCallback;
static jmethodID jmethodIDV8RuntimeReceivePromiseRejectCallback;
static jmethodID jmethodIDV8RuntimeRemoveCallbackContext;

Expand Down
19 changes: 12 additions & 7 deletions cpp/jni/javet_exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ namespace Javet {
return false;
}

void ThrowJavetCompilationException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch) {
jobject ThrowJavetCompilationException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch) {
if (v8TryCatch.HasTerminated()) {
LOG_ERROR("Compilation has been terminated.");
ThrowJavetTerminatedException(jniEnv, v8TryCatch.CanContinue());
return ThrowJavetTerminatedException(jniEnv, v8TryCatch.CanContinue());
}
else {
LOG_ERROR("Compilation exception.");
Expand All @@ -89,17 +89,19 @@ namespace Javet {
jniEnv->DeleteLocalRef(javetCompilationException);
jniEnv->DeleteLocalRef(javetScriptingError);
}
return nullptr;
}

void ThrowJavetConverterException(JNIEnv* jniEnv, const char* message) {
jobject ThrowJavetConverterException(JNIEnv* jniEnv, const char* message) {
LOG_ERROR(*message);
jniEnv->ThrowNew(jclassJavetConverterException, message);
return nullptr;
}

void ThrowJavetExecutionException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch) {
jobject ThrowJavetExecutionException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch) {
if (v8TryCatch.HasTerminated()) {
LOG_ERROR("Execution has been terminated.");
ThrowJavetTerminatedException(jniEnv, v8TryCatch.CanContinue());
return ThrowJavetTerminatedException(jniEnv, v8TryCatch.CanContinue());
}
else {
LOG_ERROR("Execution exception.");
Expand All @@ -111,9 +113,10 @@ namespace Javet {
jniEnv->Throw(javetExecutionException);
jniEnv->DeleteLocalRef(javetExecutionException);
}
return nullptr;
}

void ThrowJavetOutOfMemoryException(JNIEnv* jniEnv, v8::Isolate* v8Isolate, const char* message) {
jobject ThrowJavetOutOfMemoryException(JNIEnv* jniEnv, v8::Isolate* v8Isolate, const char* message) {
LOG_ERROR(*message);
jstring jStringExceptionMessage = Javet::Converter::ToJavaString(jniEnv, message);
jobject jObjectHeapStatistics = Javet::Monitor::GetHeapStatistics(jniEnv, v8Isolate);
Expand All @@ -125,14 +128,16 @@ namespace Javet {
jniEnv->DeleteLocalRef(jStringExceptionMessage);
jniEnv->DeleteLocalRef(jObjectHeapStatistics);
jniEnv->Throw(javetOutOfMemoryException);
return nullptr;
}

void ThrowJavetTerminatedException(JNIEnv* jniEnv, bool canContinue) {
jobject ThrowJavetTerminatedException(JNIEnv* jniEnv, bool canContinue) {
jthrowable javetTerminatedException = (jthrowable)jniEnv->NewObject(
jclassJavetTerminatedException,
jmethodIDJavetTerminatedExceptionConstructor,
canContinue);
jniEnv->Throw(javetTerminatedException);
return nullptr;
}

void ThrowV8Exception(JNIEnv* jniEnv, const V8LocalContext& v8Context, const char* defaultMessage) {
Expand Down
10 changes: 5 additions & 5 deletions cpp/jni/javet_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ namespace Javet {
void Initialize(JNIEnv* jniEnv);

bool HandlePendingException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const char* message = nullptr);
void ThrowJavetCompilationException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch);
void ThrowJavetConverterException(JNIEnv* jniEnv, const char* message);
void ThrowJavetExecutionException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch);
void ThrowJavetOutOfMemoryException(JNIEnv* jniEnv, v8::Isolate* v8Isolate, const char* message);
void ThrowJavetTerminatedException(JNIEnv* jniEnv, bool canContinue);
jobject ThrowJavetCompilationException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch);
jobject ThrowJavetConverterException(JNIEnv* jniEnv, const char* message);
jobject ThrowJavetExecutionException(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch);
jobject ThrowJavetOutOfMemoryException(JNIEnv* jniEnv, v8::Isolate* v8Isolate, const char* message);
jobject ThrowJavetTerminatedException(JNIEnv* jniEnv, bool canContinue);
void ThrowV8Exception(JNIEnv* jniEnv, const V8LocalContext& v8Context, const char* defaultMessage);
}
}
Loading

0 comments on commit 6192b67

Please sign in to comment.