Skip to content

Commit fc6a854

Browse files
authored
SQL Server Linux: JavaExtension -> Reduce minimum SPEES execution time down from 5 seconds. (#50)
* updated JavaExtensionUtils::CleanupJvm() to be platform specific. Where Linux code nulls g_jvm instead of calling destroyJVM() which causes execution delay on SPEES for sql server linux * Update build scripts for proper tarball creation and update cleanupjvm method to be split per platform * remove jvmdestroy for quicker spees execution since process exit will shutdown jvm. * update javaextensionutils to have platform specific shutdownvm() func which doesn't call destroy jvm on linux to improve spees execution. * updated code comments and removed extra new lines. * add newline to prevent change marker. * updated comments to reflect new methods. * revert shell script changes so that we don't need to change pipelines * revert changes * work item number tracking. * updated condition to just set g_jvm to null for linux . Updated comment to clarify this scenario is linux only.
1 parent e51909e commit fc6a854

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed

language-extensions/java/include/JavaExtensionUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class JavaExtensionUtils
7878
//
7979
static fn_createJvm LoadJvm(const std::string &jvmPath);
8080

81+
// Cleans up the JVM instance
82+
//
83+
static void ShutdownJvm(JavaVM *jvm);
84+
8185
// Unloads the JVM library
8286
//
8387
static void UnloadJvm();

language-extensions/java/src/JavaExtensionUtils.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,9 @@ JNIEnv* JavaExtensionUtils::CreateJvm()
296296
//
297297
void JavaExtensionUtils::CleanupJvm()
298298
{
299-
// Destroy the JVM
299+
// Call platform specific function to shutdown the JVM
300300
//
301-
if (g_jvm != nullptr)
302-
{
303-
int rc = g_jvm->DestroyJavaVM();
304-
if (rc == 0)
305-
{
306-
g_jvm = nullptr;
307-
}
308-
else
309-
{
310-
string msg = "Failed to destroy JVM. JNI error code: " + to_string(rc) + ".";
311-
312-
LOG_ERROR(msg);
313-
}
314-
}
301+
ShutdownJvm(g_jvm);
315302

316303
// Call platform specific function to unload JVM library
317304
//

language-extensions/java/src/linux/JavaExtensionUtils_linux.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ JavaExtensionUtils::fn_createJvm JavaExtensionUtils::LoadJvm(const string& jvmPa
163163
return reinterpret_cast<fn_createJvm>(dlsym(g_jvmLib, "JNI_CreateJavaVM"));
164164
}
165165

166+
//----------------------------------------------------------------------------
167+
// Name: JavaExtensionUtils::ShutdownJvm
168+
//
169+
// Description:
170+
// Cleans up JVM resources. When running on Linux, clean up operation
171+
// doesn't call Invocation API function DestroyJavaVM() because
172+
// ExtHost process exit defers to OS for resource cleanup
173+
// and SPEES query doesn't hang.
174+
// Follow up investigation tracked via work item: 3090980
175+
//
176+
void JavaExtensionUtils::ShutdownJvm(JavaVM *jvm)
177+
{
178+
LOG("Cleaning up JVM");
179+
jvm = nullptr;
180+
}
181+
166182
//----------------------------------------------------------------------------
167183
// Name: JavaExtensionUtils::UnloadJvm
168184
//

language-extensions/java/src/windows/JavaExtensionUtils_win.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,32 @@ JavaExtensionUtils::fn_createJvm JavaExtensionUtils::LoadJvm(const string& jvmPa
147147
return reinterpret_cast<fn_createJvm>(GetProcAddress(g_jvmDll, "JNI_CreateJavaVM"));
148148
}
149149

150+
//----------------------------------------------------------------------------
151+
// Name: JavaExtensionUtils::ShutdownJvm
152+
//
153+
// Description:
154+
// Cleans up JVM resources by calling the Invocation API function: DestroyJavaVM.
155+
//
156+
void JavaExtensionUtils::ShutdownJvm(JavaVM *jvm)
157+
{
158+
// Destroy the JVM
159+
//
160+
LOG("Shutting down JVM");
161+
if (jvm != nullptr)
162+
{
163+
int rc = jvm->DestroyJavaVM();
164+
if (rc == 0)
165+
{
166+
jvm = nullptr;
167+
}
168+
else
169+
{
170+
string msg = "Failed to destroy JVM. JNI error code: " + to_string(rc) + ".";
171+
LOG_ERROR(msg);
172+
}
173+
}
174+
}
175+
150176
//----------------------------------------------------------------------------
151177
// Name: JavaExtensionUtils::UnloadJvm
152178
//

0 commit comments

Comments
 (0)