Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
74727b9
bpo-44347: [doc] clarify meaning of shutil.copytree's dirs_exist_ok …
jdevries3133 Jun 9, 2021
0fa96d1
bpo-44347: [doc] clarify shutil.copytree dirs_exist_ok kwarg
jdevries3133 Jun 10, 2021
318a99c
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Jun 10, 2021
9b262b8
bpo-44347: [doc|fix]: add NEWS.d entry, remove use of default context
jdevries3133 Jun 10, 2021
952dbf1
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Jun 10, 2021
e365e52
bpo-44347: [doc] better document argument shutil.copytree(dirs_exist_…
jdevries3133 Jun 11, 2021
eb3ee6f
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Jun 11, 2021
d340c87
bpo-44347: [doc|fix]: add missed updated docstring from previous commit
jdevries3133 Jun 11, 2021
dd2f5c3
bpo-44381: Windows build now allows enabling control flow guard (GH-2…
zooba Jun 11, 2021
d8837d8
bpo-40128: Fix IDLE autocomplete on macOS (GH-26672)
thsubaku9 Jun 11, 2021
869f2fa
bpo-44339: Fix math.pow corner case to comply with IEEE 754 (GH-26606)
mdickinson Jun 12, 2021
29584b7
bpo-43475: Fix the Python implementation of hash of Decimal NaN (GH-2…
serhiy-storchaka Jun 12, 2021
b63a793
Add more const modifiers. (GH-26691)
serhiy-storchaka Jun 12, 2021
feca673
bpo-44376 - reduce pow() overhead for small exponents (GH-26662)
tim-one Jun 12, 2021
b1e8a39
bpo-44396: Update multi-line-start location when reallocating tokeniz…
pablogsal Jun 12, 2021
732ecab
bpo-44389: Remove duplicate SSL_OP_NO_TLSv1_2 flag (GH-26680)
Jun 12, 2021
2a93215
bpo-43425: Update test_c_parser not to use TempdirManager (GH-26693)
corona10 Jun 12, 2021
50aee65
Fix typos in multiple files (GH-26689)
enjoy-binbin Jun 13, 2021
6966890
Fix a potential reference-counting bug in long_pow (GH-26690)
mdickinson Jun 13, 2021
d1a2233
bpo-44389: Fix deprecation of OP_NO_TLSv1_3 (GH-26700)
tiran Jun 13, 2021
67d241b
bpo-44310: Note that lru_cache keep references to both arguments and…
rhettinger Jun 14, 2021
0208b06
bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter (GH-26638)
markshannon Jun 14, 2021
ad667a2
Remove accidentally duplicated STAT_INC (GH-26718)
markshannon Jun 14, 2021
6109bfa
bpo-38291: Remove mention of typing.io and typing.re again (GH-26113)
srittau Jun 14, 2021
101dc7e
Fix typo in lnotab_notes.txt (GH-26711)
P403n1x87 Jun 14, 2021
ed3d0b5
bpo-44409: Fix error location in tokenizer errors that happen during …
pablogsal Jun 14, 2021
44d2ad8
Fix a typo in _make_class_unpicklable() docstring (GH-26729)
akulakov Jun 15, 2021
77b67cb
Add extra stats for attribute misses (GH-26732)
markshannon Jun 15, 2021
1628fb8
bpo-42064: Move sqlite3 types to global state (GH-26537)
Jun 15, 2021
c60a9c6
bpo-42972: _thread.RLock implements the GH protocol (GH-26734)
vstinner Jun 15, 2021
1d63579
bpo-44422: Fix threading.enumerate() reentrant call (GH-26727)
vstinner Jun 15, 2021
3e45844
[Enum] improve test, add andrei kulakov to ACKS (GH-26726)
ethanfurman Jun 15, 2021
3e2e824
bpo-43475: Add what's new entry for NaN hash changes (GH-26725)
mdickinson Jun 15, 2021
fc3ca19
bpo-43693: Eliminate unused "fast locals". (gh-26587)
ericsnowcurrently Jun 15, 2021
949a2b7
bpo-44342: [Enum] sync current docs to 3.10 (GH-26750)
ethanfurman Jun 16, 2021
b7f3aca
bpo-43795: Don't list private names in the limited API (GH-26740)
encukou Jun 16, 2021
8fc6dd3
bpo-44422: threading.Thread reuses the _delete() method (GH-26741)
vstinner Jun 16, 2021
66eab7a
bpo-38211: Clean up type_init() (GH-16257)
sir-sigurd Jun 16, 2021
e78f506
bpo-44392: Add Py_GenericAlias to C API docs (GH-26724)
Fidget-Spinner Jun 16, 2021
66c976d
bpo-44426: Use of 'complex' as a C variable name confuses Sphinx; cha…
mdickinson Jun 16, 2021
439482a
bpo-44389: Fix typo in ssl deprecation warning message (GH-26754)
j178 Jun 17, 2021
76bed3a
bpo-43908: Make heap types converted during 3.10 alpha immutable (GH-…
Jun 17, 2021
f446866
Do not clear globals or builtins when calling clear() on a frame obje…
markshannon Jun 17, 2021
3010391
bpo-43024: improve signature (in help, etc) for functions taking sent…
iritkatriel Jun 17, 2021
6e231c0
bpo-44310: Add a FAQ entry for caching method calls (GH-26731)
rhettinger Jun 17, 2021
9ad9fd7
bpo-44032: Move pointer to code object from frame-object to frame spe…
markshannon Jun 18, 2021
95aa9d6
Reorganize the pattern matching suite (GH-26661)
brandtbucher Jun 18, 2021
d808829
bpo-44451: Reset DeprecationWarning filters in test_importlib.test_en…
hroncok Jun 18, 2021
f3dd96a
bpo-43945: [Enum] reduce scope of new format() behavior (GH-26752)
ethanfurman Jun 18, 2021
d4b87bc
Add a note about NameError/AttributeError suggestions with custom err…
pablogsal Jun 18, 2021
32fd669
Remove dubious suggestion (GH-26789)
rhettinger Jun 19, 2021
df719d4
bpo-38820: Test with OpenSSL 3.0.0-beta1 (GH-26769)
tiran Jun 19, 2021
0cf3409
bpo-43298: Improved error message when building without the Windows S…
zooba Jun 19, 2021
07f631d
bpo-44426: Fix use of the C keyword 'default' as a variable name (GH-…
mdickinson Jun 19, 2021
f879593
Merge remote-tracking branch 'upstream/main' into pr_26643
terryjreedy Jun 19, 2021
d035783
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
a1f767c
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
7151b46
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
a0a46be
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
e02e998
bpo-38291: DeprecationWarning when importing typing.{io,re} (#26719)
srittau Jun 19, 2021
82ae9d6
bpo-44347: fix spelling
jdevries3133 Jun 20, 2021
568c773
Merge remote-tracking branch 'upstream/main' into pr_26643
terryjreedy Jun 20, 2021
b2d7cc0
bpo-44347: add note to further clarify edge case
jdevries3133 Jun 21, 2021
a07b324
bpo-44347: (small fix) remove redundant line from example
jdevries3133 Jun 21, 2021
48f30ee
bpo-44347: highlight relationship to os.makedirs
jdevries3133 Jun 21, 2021
5b8366a
small rewording fix
jdevries3133 Jul 1, 2021
60a0eb6
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Apr 8, 2022
8303dc5
revise old changes
jdevries3133 Apr 8, 2022
c169b1d
apply @JelleZijlstra's feedback
jdevries3133 Apr 9, 2022
ac3f837
update docstring
jdevries3133 Apr 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter (GH-26638)
* Add specializations of LOAD_GLOBAL.

* Add more stats.

* Remove old opcache; it is no longer used.

* Add NEWS
  • Loading branch information
markshannon authored and jdevries3133 committed Jun 19, 2021
commit 0208b06e7b90d39adcf817f0e8a394e73f3d579e
14 changes: 0 additions & 14 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,6 @@ struct PyCodeObject {
interpreter. */
union _cache_or_instruction *co_quickened;

/* Per opcodes just-in-time cache
*
* To reduce cache size, we use indirect mapping from opcode index to
* cache object:
* cache = co_opcache[co_opcache_map[next_instr - first_instr] - 1]
*/

// co_opcache_map is indexed by (next_instr - first_instr).
// * 0 means there is no cache for this opcode.
// * n > 0 means there is cache in co_opcache[n-1].
unsigned char *co_opcache_map;
_PyOpcache *co_opcache;
int co_opcache_flag; // used to determine when create a cache.
unsigned char co_opcache_size; // length of co_opcache.
};

/* Masks for co_flags above */
Expand Down
25 changes: 15 additions & 10 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ typedef struct {
uint32_t dk_version_or_hint;
} _PyLoadAttrCache;

typedef struct {
uint32_t module_keys_version;
uint32_t builtin_keys_version;
} _PyLoadGlobalCache;

/* Add specialized versions of entries to this union.
*
* Do not break the invariant: sizeof(SpecializedCacheEntry) == 8
Expand All @@ -62,6 +67,7 @@ typedef union {
_PyEntryZero zero;
_PyAdaptiveEntry adaptive;
_PyLoadAttrCache load_attr;
_PyLoadGlobalCache load_global;
} SpecializedCacheEntry;

#define INSTRUCTIONS_PER_ENTRY (sizeof(SpecializedCacheEntry)/sizeof(_Py_CODEUNIT))
Expand Down Expand Up @@ -254,8 +260,6 @@ PyAPI_FUNC(PyCodeObject *) _PyCode_New(struct _PyCodeConstructor *);

/* Private API */

int _PyCode_InitOpcache(PyCodeObject *co);

/* Getters for internal PyCodeObject data. */
PyAPI_FUNC(PyObject *) _PyCode_GetVarnames(PyCodeObject *);
PyAPI_FUNC(PyObject *) _PyCode_GetCellvars(PyCodeObject *);
Expand Down Expand Up @@ -318,24 +322,25 @@ cache_backoff(_PyAdaptiveEntry *entry) {
/* Specialization functions */

int _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);

#define SPECIALIZATION_STATS 0
#if SPECIALIZATION_STATS

typedef struct _specialization_stats {
typedef struct _stats {
uint64_t specialization_success;
uint64_t specialization_failure;
uint64_t loadattr_hit;
uint64_t loadattr_deferred;
uint64_t loadattr_miss;
uint64_t loadattr_deopt;
uint64_t hit;
uint64_t deferred;
uint64_t miss;
uint64_t deopt;
} SpecializationStats;

extern SpecializationStats _specialization_stats;
#define STAT_INC(name) _specialization_stats.name++
extern SpecializationStats _specialization_stats[256];
#define STAT_INC(opname, name) _specialization_stats[opname].name++
void _Py_PrintSpecializationStats(void);
#else
#define STAT_INC(name) ((void)0)
#define STAT_INC(opname, name) ((void)0)
#endif


Expand Down
3 changes: 3 additions & 0 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,7 @@ def jabs_op(name, op):
"LOAD_ATTR_WITH_HINT",
"LOAD_ATTR_SLOT",
"LOAD_ATTR_MODULE",
"LOAD_GLOBAL_ADAPTIVE",
"LOAD_GLOBAL_MODULE",
"LOAD_GLOBAL_BUILTIN",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Implement adaptive specialization for LOAD_GLOBAL

Two specialized forms of LOAD_GLOBAL are added:

* LOAD_GLOBAL_MODULE

* LOAD_GLOBAL_BUILTIN
74 changes: 6 additions & 68 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
/* not set */
co->co_weakreflist = NULL;
co->co_extra = NULL;
co->co_opcache_map = NULL;
co->co_opcache = NULL;
co->co_opcache_flag = 0;
co->co_opcache_size = 0;

co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE;
co->co_quickened = NULL;
}
Expand Down Expand Up @@ -912,55 +909,6 @@ new_linesiterator(PyCodeObject *code)
return li;
}


/******************
* the opcache
******************/

int
_PyCode_InitOpcache(PyCodeObject *co)
{
Py_ssize_t co_size = PyBytes_Size(co->co_code) / sizeof(_Py_CODEUNIT);
co->co_opcache_map = (unsigned char *)PyMem_Calloc(co_size, 1);
if (co->co_opcache_map == NULL) {
return -1;
}

const _Py_CODEUNIT *opcodes = (const _Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
Py_ssize_t opts = 0;

for (Py_ssize_t i = 0; i < co_size;) {
unsigned char opcode = _Py_OPCODE(opcodes[i]);
i++; // 'i' is now aligned to (next_instr - first_instr)

// TODO: LOAD_METHOD
if (opcode == LOAD_GLOBAL || opcode == LOAD_ATTR) {
opts++;
co->co_opcache_map[i] = (unsigned char)opts;
if (opts > 254) {
break;
}
}
}

if (opts) {
co->co_opcache = (_PyOpcache *)PyMem_Calloc(opts, sizeof(_PyOpcache));
if (co->co_opcache == NULL) {
PyMem_Free(co->co_opcache_map);
return -1;
}
}
else {
PyMem_Free(co->co_opcache_map);
co->co_opcache_map = NULL;
co->co_opcache = NULL;
}

co->co_opcache_size = (unsigned char)opts;
return 0;
}


/******************
* "extra" frame eval info (see PEP 523)
******************/
Expand Down Expand Up @@ -1207,15 +1155,6 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
static void
code_dealloc(PyCodeObject *co)
{
if (co->co_opcache != NULL) {
PyMem_Free(co->co_opcache);
}
if (co->co_opcache_map != NULL) {
PyMem_Free(co->co_opcache_map);
}
co->co_opcache_flag = 0;
co->co_opcache_size = 0;

if (co->co_extra != NULL) {
PyInterpreterState *interp = _PyInterpreterState_GET();
_PyCodeObjectExtra *co_extra = co->co_extra;
Expand Down Expand Up @@ -1442,12 +1381,11 @@ code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
res += co->co_ncellvars * sizeof(Py_ssize_t);
}

if (co->co_opcache != NULL) {
assert(co->co_opcache_map != NULL);
// co_opcache_map
res += PyBytes_GET_SIZE(co->co_code) / sizeof(_Py_CODEUNIT);
// co_opcache
res += co->co_opcache_size * sizeof(_PyOpcache);
if (co->co_quickened != NULL) {
Py_ssize_t count = co->co_quickened[0].entry.zero.cache_count;
count += (PyBytes_GET_SIZE(co->co_code)+sizeof(SpecializedCacheEntry)-1)/
sizeof(SpecializedCacheEntry);
res += count * sizeof(SpecializedCacheEntry);
}

return PyLong_FromSsize_t(res);
Expand Down
Loading