In fix-unexpected-threaded-call, we will actually make concurrent hash accesses
from both the application and from the glib thread.

--- a/jni/src/jawimpl.c
+++ b/jni/src/jawimpl.c
@@ -92,7 +92,9 @@ typedef struct _JawInterfaceInfo {
 
 static gpointer jaw_impl_parent_class = NULL;
 
+static GMutex typeTableMutex;
 static GHashTable *typeTable = NULL;
+static GMutex objectTableMutex;
 static GHashTable *objectTable = NULL;
 static gboolean jaw_debug = FALSE;
 
@@ -106,7 +108,9 @@ object_table_insert (JNIEnv *jniEnv, job
                                           "hashCode",
                                           "()I");
   gint hash_key = (gint)(*jniEnv)->CallIntMethod(jniEnv, ac, jmid);
+  g_mutex_lock(&objectTableMutex);
   g_hash_table_insert(objectTable, GINT_TO_POINTER(hash_key), GINT_TO_POINTER(jaw_impl));
+  g_mutex_unlock(&objectTableMutex);
 }
 
 static JawImpl*
@@ -120,10 +124,15 @@ object_table_lookup (JNIEnv *jniEnv, job
                                           "()I" );
   gint hash_key = (gint)(*jniEnv)->CallIntMethod( jniEnv, ac, jmid );
   gpointer value = NULL;
+  g_mutex_lock(&objectTableMutex);
   if (objectTable==NULL)
+  {
     return NULL;
+    g_mutex_unlock(&objectTableMutex);
+  }
 
   value = g_hash_table_lookup(objectTable, GINT_TO_POINTER(hash_key));
+  g_mutex_unlock(&objectTableMutex);
   return (JawImpl*)value;
 }
 
@@ -138,7 +147,9 @@ object_table_remove(JNIEnv *jniEnv, jobj
                                           "()I" );
   gint hash_key = (gint)(*jniEnv)->CallIntMethod( jniEnv, ac, jmid );
 
+  g_mutex_lock(&objectTableMutex);
   g_hash_table_remove(objectTable, GINT_TO_POINTER(hash_key));
+  g_mutex_unlock(&objectTableMutex);
 }
 
 GHashTable*
@@ -147,6 +158,12 @@ jaw_impl_get_object_hash_table(void)
   return objectTable;
 }
 
+GMutex*
+jaw_impl_get_object_hash_table_mutex(void)
+{
+  return &objectTableMutex;
+}
+
 static void
 aggregate_interface(JNIEnv *jniEnv, JawObject *jaw_obj, guint tflag)
 {
@@ -265,8 +282,10 @@ jaw_impl_get_instance (JNIEnv *jniEnv, j
   if (jniEnv == NULL)
     return NULL;
 
+  g_mutex_lock(&objectTableMutex);
   if (objectTable == NULL)
     objectTable = g_hash_table_new (NULL, NULL);
+  g_mutex_unlock(&objectTableMutex);
 
   jaw_impl = object_table_lookup(jniEnv, ac);
 
@@ -411,11 +430,13 @@ jaw_impl_get_type (guint tflag)
     NULL
   };
 
+  g_mutex_lock(&typeTableMutex);
   if (typeTable == NULL) {
     typeTable = g_hash_table_new( NULL, NULL );
   }
 
   type = GPOINTER_TO_GTYPE(g_hash_table_lookup(typeTable, GUINT_TO_POINTER(tflag)));
+  g_mutex_unlock(&typeTableMutex);
   if (type == 0) {
     GTypeInfo tinfo = {
       sizeof(JawImplClass),
@@ -465,7 +486,9 @@ jaw_impl_get_type (guint tflag)
     if (tflag & INTERFACE_TABLE_CELL)
       g_type_add_interface_static (type, ATK_TYPE_TABLE_CELL, &atk_table_cell_info);
 
+    g_mutex_lock(&typeTableMutex);
     g_hash_table_insert(typeTable, GINT_TO_POINTER(tflag), GTYPE_TO_POINTER(type));
+    g_mutex_unlock(&typeTableMutex);
   }
 
   return type;
--- a/jni/src/jawimpl.h
+++ b/jni/src/jawimpl.h
@@ -52,6 +52,7 @@ struct _JawImpl
 JawImpl* jaw_impl_get_instance(JNIEnv*, jobject);
 JawImpl* jaw_impl_find_instance(JNIEnv*, jobject);
 GHashTable* jaw_impl_get_object_hash_table(void);
+GMutex* jaw_impl_get_object_hash_table_mutex(void);
 
 GType jaw_impl_get_type (guint);
 AtkRelationType jaw_impl_get_atk_relation_type(JNIEnv *jniEnv, jstring jrel_key);
--- a/jni/src/jawobject.c
+++ b/jni/src/jawobject.c
@@ -56,7 +56,6 @@ static AtkRelationSet *jaw_object_ref_re
 static AtkObject *jaw_object_ref_child(AtkObject *atk_obj, gint i);
 
 static gpointer parent_class = NULL;
-static GHashTable *object_table = NULL;
 static JawObject* jaw_object_table_lookup (JNIEnv *jniEnv, jobject ac);
 
 enum {
@@ -651,7 +650,8 @@ jaw_object_ref_child(AtkObject *atk_obj,
 static JawObject*
 jaw_object_table_lookup (JNIEnv *jniEnv, jobject ac)
 {
-  object_table = jaw_impl_get_object_hash_table();
+  GHashTable *object_table = jaw_impl_get_object_hash_table();
+  GMutex *object_table_mutex = jaw_impl_get_object_hash_table_mutex();
   jclass classAccessibleContext = (*jniEnv)->FindClass( jniEnv,
                                                        "javax/accessibility/AccessibleContext" );
   jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
@@ -663,7 +663,9 @@ jaw_object_table_lookup (JNIEnv *jniEnv,
   if (object_table == NULL)
     return NULL;
 
+  g_mutex_lock(object_table_mutex);
   value = g_hash_table_lookup(object_table, GINT_TO_POINTER(hash_key));
+  g_mutex_unlock(object_table_mutex);
   return (JawObject*)value;
 }
 
