diff options
| author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-09-27 20:03:09 +0000 |
|---|---|---|
| committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-09-27 20:03:09 +0000 |
| commit | e7e0af0e596269221f9717a3658cffbeee7a5c2a (patch) | |
| tree | 18763461cdb28ee640435eb7d63f5a857583660c /libjava/java/lang/natClass.cc | |
| parent | b2382601bb72b7c9f8e1e1c461498f6e03c8217e (diff) | |
| download | ppe42-gcc-e7e0af0e596269221f9717a3658cffbeee7a5c2a.tar.gz ppe42-gcc-e7e0af0e596269221f9717a3658cffbeee7a5c2a.zip | |
PR libgcj/23367:
* include/jvm.h (_Jv_FreeMethodCache): Declare.
* java/lang/natClass.cc (MCACHE_SIZE): Conditional on HAVE_TLS.
(struct _Jv_mcache): Likewise.
(method_cache): Likewise.
(_Jv_FindMethodInCache): Do nothing unless TLS is available.
(_Jv_AddMethodToCache): Likewise.
(_Jv_FreeMethodCache): New function.
* java/lang/natThread.cc (finish_): Call _Jv_FreeMethodCache.
* aclocal.m4, configure, include/config.h.in: Rebuilt.
* configure.ac: Invoke GCC_CHECK_TLS.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@104707 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/lang/natClass.cc')
| -rw-r--r-- | libjava/java/lang/natClass.cc | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc index fa52713cc36..bd68eb22435 100644 --- a/libjava/java/lang/natClass.cc +++ b/libjava/java/lang/natClass.cc @@ -879,8 +879,10 @@ _Jv_LookupDeclaredMethod (jclass klass, _Jv_Utf8Const *name, return NULL; } +#ifdef HAVE_TLS + // NOTE: MCACHE_SIZE should be a power of 2 minus one. -#define MCACHE_SIZE 1023 +#define MCACHE_SIZE 31 struct _Jv_mcache { @@ -888,37 +890,60 @@ struct _Jv_mcache _Jv_Method *method; }; -static _Jv_mcache method_cache[MCACHE_SIZE + 1]; +static __thread _Jv_mcache *method_cache; +#endif // HAVE_TLS static void * _Jv_FindMethodInCache (jclass klass, _Jv_Utf8Const *name, _Jv_Utf8Const *signature) { - int index = name->hash16 () & MCACHE_SIZE; - _Jv_mcache *mc = method_cache + index; - _Jv_Method *m = mc->method; - - if (mc->klass == klass - && m != NULL // thread safe check - && _Jv_equalUtf8Consts (m->name, name) - && _Jv_equalUtf8Consts (m->signature, signature)) - return mc->method->ncode; +#ifdef HAVE_TLS + _Jv_mcache *cache = method_cache; + if (cache) + { + int index = name->hash16 () & MCACHE_SIZE; + _Jv_mcache *mc = &cache[index]; + _Jv_Method *m = mc->method; + + if (mc->klass == klass + && _Jv_equalUtf8Consts (m->name, name) + && _Jv_equalUtf8Consts (m->signature, signature)) + return mc->method->ncode; + } +#endif // HAVE_TLS return NULL; } static void -_Jv_AddMethodToCache (jclass klass, - _Jv_Method *method) +_Jv_AddMethodToCache (jclass klass, _Jv_Method *method) { - _Jv_MonitorEnter (&java::lang::Class::class$); - - int index = method->name->hash16 () & MCACHE_SIZE; - - method_cache[index].method = method; - method_cache[index].klass = klass; +#ifdef HAVE_TLS + if (method_cache == NULL) + method_cache = (_Jv_mcache *) _Jv_MallocUnchecked((MCACHE_SIZE + 1) + * sizeof (_Jv_mcache)); + // If the allocation failed, just keep going. + if (method_cache != NULL) + { + int index = method->name->hash16 () & MCACHE_SIZE; + method_cache[index].method = method; + method_cache[index].klass = klass; + } +#endif // HAVE_TLS +} - _Jv_MonitorExit (&java::lang::Class::class$); +// Free this thread's method cache. We explicitly manage this memory +// as the GC does not yet know how to scan TLS on all platforms. +void +_Jv_FreeMethodCache () +{ +#ifdef HAVE_TLS + if (method_cache != NULL) + { + _Jv_Free(method_cache); + method_cache = NULL; + } +#endif // HAVE_TLS } void * |

