[issue43441] mutilcorevm: global variable next_version_tag cause method cache bug

2021-03-09 Thread junyixie


Change by junyixie :


--
type:  -> crash

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43441] mutilcorevm: global variable next_version_tag cause method cache bug

2021-03-08 Thread junyixie


junyixie  added the comment:

fix:
only main interpreter fini, clear method cache. 

void
_PyType_Fini(PyInterpreterState *interp)
{
if (_Py_IsMainInterpreter(interp)) {
clear_slotdefs();
_PyType_ClearCache(>type_cache);
}
}

when python4.0? type isolate, each interpreter dealloc should clear method 
cache.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43441] mutilcorevm: global variable next_version_tag cause method cache bug

2021-03-08 Thread junyixie


junyixie  added the comment:

when sub interpreter finalize. 
_PyType_ClearCache set next_version_tag = 0. 

Type shared between interpreters. 
another interpreter assign_version_tag "1" for a type, the type is first assign.

the dealloc interpreter had assign_version_tag  "1" for another type.

now, two different type has same version tag. it cause method cache wrong.


static unsigned int
_PyType_ClearCache(struct type_cache *cache)
{
#if MCACHE_STATS
size_t total = cache->hits + cache->collisions + cache->misses;
fprintf(stderr, "-- Method cache hits= %zd (%d%%)\n",
cache->hits, (int) (100.0 * cache->hits / total));
fprintf(stderr, "-- Method cache true misses = %zd (%d%%)\n",
cache->misses, (int) (100.0 * cache->misses / total));
fprintf(stderr, "-- Method cache collisions  = %zd (%d%%)\n",
cache->collisions, (int) (100.0 * cache->collisions / total));
fprintf(stderr, "-- Method cache size= %zd KiB\n",
sizeof(cache->hashtable) / 1024);
#endif

unsigned int cur_version_tag = next_version_tag - 1;
next_version_tag = 0;
type_cache_clear(cache, 0);

return cur_version_tag;
}

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43441] mutilcorevm: global variable next_version_tag cause method cache bug

2021-03-08 Thread junyixie


New submission from junyixie :

type->tp_version_tag = next_version_tag++;
when sub interpreters parallel, next_version_tag++ is thread-unsafe. may cause 
different type has same tp_version_tag.

cause method cache bug in _PyType_Lookup
#define MCACHE_HASH_METHOD(type, name)  \
MCACHE_HASH((type)->tp_version_tag, \
((PyASCIIObject *)(name))->hash)

if (MCACHE_CACHEABLE_NAME(name) &&
_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
/* fast path */
unsigned int h = MCACHE_HASH_METHOD(type, name);
struct type_cache *cache = get_type_cache();
struct type_cache_entry *entry = >hashtable[h];
if (entry->version == type->tp_version_tag && entry->name == name) {
#if MCACHE_STATS
cache->hits++;
#endif
return entry->value;
}
}



static int
assign_version_tag(struct type_cache *cache, PyTypeObject *type)
{
...
type->tp_version_tag = next_version_tag++;
...
}

--
components: Interpreter Core
messages: 388327
nosy: JunyiXie
priority: normal
severity: normal
status: open
title: mutilcorevm: global variable next_version_tag cause method cache bug
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com