Blob Blame History Raw
From cf428b66d5779cbbbb08846ae526a9a5f1043863 Mon Sep 17 00:00:00 2001
From: Stephan Bergmann <sbergman@redhat.com>
Date: Fri, 13 Jan 2012 11:38:24 +0100
Subject: [PATCH] Confine JDBC driver to thread-affine apartment for Java 6
 performance

... so that the massive number of the JDBC driver's calls to JNI Attach/Detach-
CurrentThread are guaranteed not to happen on the main thread (where they are
extremely expensive, see
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6978641> "Fix for 6929067
introduces additional overhead in thread creation/termination paths").

(cherry-picked from <http://cgit.freedesktop.org/libreoffice/core/commit/?id=bb59742bcf4883af5876a2ffadcc4a689e414b60>)
---
 connectivity/source/drivers/jdbc/jservices.cxx |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/connectivity/source/drivers/jdbc/jservices.cxx b/connectivity/source/drivers/jdbc/jservices.cxx
index aebe76b..1a438be 100644
--- a/connectivity/source/drivers/jdbc/jservices.cxx
+++ b/connectivity/source/drivers/jdbc/jservices.cxx
@@ -93,7 +93,15 @@ component_getImplementationEnvironment(
                 uno_Environment	** /*ppEnv*/
             )
 {
-    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+    // Recent Java 6 VMs make calls to JNI Attach/DetachCurrentThread (which
+    // this code does extensively) very expensive.  A follow-up JVM fix reduced
+    // the overhead significantly again for all threads but the main thread.  So
+    // a quick hack to improve performance of this component again is to confine
+    // it in the affine apartment (where all code will run on a single,
+    // dedicated thread that is guaranteed no to be the main thread).  However,
+    // a better fix would still be to redesign the code so that it does not call
+    // Attach/DetachCurrentThread so frequently:
+    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ":affine";
 }
 
 //---------------------------------------------------------------------------------------
-- 
1.7.7.5