Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Include/cpython/pystats.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ typedef struct _optimization_stats {
uint64_t recursive_call;
uint64_t low_confidence;
uint64_t unknown_callee;
uint64_t trace_immediately_deopts;
uint64_t executors_invalidated;
UOpStats opcode[PYSTATS_MAX_UOP_ID + 1];
uint64_t unsupported_opcode[256];
Expand Down
6 changes: 5 additions & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,16 @@ def __delattr__(cls, attr):
super().__delattr__(attr)

def __dir__(cls):
if issubclass(cls, Flag):
members = list(cls._member_map_.keys())
else:
members = cls._member_names_
interesting = set([
'__class__', '__contains__', '__doc__', '__getitem__',
'__iter__', '__len__', '__members__', '__module__',
'__name__', '__qualname__',
]
+ cls._member_names_
+ members
)
if cls._new_member_ is not object.__new__:
interesting.add('__new__')
Expand Down
40 changes: 17 additions & 23 deletions Lib/test/test_asyncio/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

MACOS = (sys.platform == 'darwin')
BUF_MULTIPLIER = 1024 if not MACOS else 64
HANDSHAKE_TIMEOUT = support.LONG_TIMEOUT


def tearDownModule():
Expand Down Expand Up @@ -257,15 +258,12 @@ def prog(sock):
await fut

async def start_server():
extras = {}
extras = dict(ssl_handshake_timeout=support.SHORT_TIMEOUT)

srv = await asyncio.start_server(
handle_client,
'127.0.0.1', 0,
family=socket.AF_INET,
ssl=sslctx,
**extras)
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)

try:
srv_socks = srv.sockets
Expand Down Expand Up @@ -322,14 +320,11 @@ def server(sock):
sock.close()

async def client(addr):
extras = {}
extras = dict(ssl_handshake_timeout=support.SHORT_TIMEOUT)

reader, writer = await asyncio.open_connection(
*addr,
ssl=client_sslctx,
server_hostname='',
**extras)
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)

writer.write(A_DATA)
self.assertEqual(await reader.readexactly(2), b'OK')
Expand All @@ -349,7 +344,8 @@ async def client_sock(addr):
reader, writer = await asyncio.open_connection(
sock=sock,
ssl=client_sslctx,
server_hostname='')
server_hostname='',
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)

writer.write(A_DATA)
self.assertEqual(await reader.readexactly(2), b'OK')
Expand Down Expand Up @@ -448,7 +444,7 @@ async def client(addr):
*addr,
ssl=client_sslctx,
server_hostname='',
ssl_handshake_timeout=support.SHORT_TIMEOUT)
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)
writer.close()
await self.wait_closed(writer)

Expand Down Expand Up @@ -610,7 +606,7 @@ def client():

extras = {}
if server_ssl:
extras = dict(ssl_handshake_timeout=support.SHORT_TIMEOUT)
extras = dict(ssl_handshake_timeout=HANDSHAKE_TIMEOUT)

f = loop.create_task(
loop.connect_accepted_socket(
Expand Down Expand Up @@ -659,7 +655,8 @@ async def client(addr):
reader, writer = await asyncio.open_connection(
*addr,
ssl=client_sslctx,
server_hostname='')
server_hostname='',
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)

self.assertEqual(await reader.readline(), b'A\n')
writer.write(b'B')
Expand Down Expand Up @@ -1152,14 +1149,11 @@ def do(func, *args):
await fut

async def start_server():
extras = {}

srv = await self.loop.create_server(
server_protocol_factory,
'127.0.0.1', 0,
family=socket.AF_INET,
ssl=sslctx_1,
**extras)
ssl=sslctx_1)

try:
srv_socks = srv.sockets
Expand Down Expand Up @@ -1209,14 +1203,11 @@ def server(sock):
sock.close()

async def client(addr):
extras = {}
extras = dict(ssl_handshake_timeout=support.SHORT_TIMEOUT)

reader, writer = await asyncio.open_connection(
*addr,
ssl=client_sslctx,
server_hostname='',
**extras)
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)

writer.write(A_DATA)
self.assertEqual(await reader.readexactly(2), b'OK')
Expand Down Expand Up @@ -1286,7 +1277,8 @@ async def client(addr):
reader, writer = await asyncio.open_connection(
*addr,
ssl=client_sslctx,
server_hostname='')
server_hostname='',
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)
sslprotocol = writer.transport._ssl_protocol
writer.write(b'ping')
data = await reader.readexactly(4)
Expand Down Expand Up @@ -1398,7 +1390,8 @@ async def client(addr):
reader, writer = await asyncio.open_connection(
*addr,
ssl=client_sslctx,
server_hostname='')
server_hostname='',
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)
writer.write(b'ping')
data = await reader.readexactly(4)
self.assertEqual(data, b'pong')
Expand Down Expand Up @@ -1529,7 +1522,8 @@ async def client(addr):
reader, writer = await asyncio.open_connection(
*addr,
ssl=client_sslctx,
server_hostname='')
server_hostname='',
ssl_handshake_timeout=HANDSHAKE_TIMEOUT)
writer.write(b'ping')
data = await reader.readexactly(4)
self.assertEqual(data, b'pong')
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5529,12 +5529,16 @@ def test_enum_dict_standalone(self):
# helpers

def enum_dir(cls):
if issubclass(cls, Flag):
members = list(cls._member_map_.keys())
else:
members = cls._member_names_
interesting = set([
'__class__', '__contains__', '__doc__', '__getitem__',
'__iter__', '__len__', '__members__', '__module__',
'__name__', '__qualname__',
]
+ cls._member_names_
+ members
)
if cls._new_member_ is not object.__new__:
interesting.add('__new__')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug during JIT compilation failure which caused garbage collection debug assertions to fail.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Protect against specialization failures in the tracing JIT compiler for performance reasons.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flag: a ``dir()`` on a ``Flag`` enumeration now shows non-canonical members.
(i.e. aliases).
24 changes: 23 additions & 1 deletion Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,25 @@ _PyJit_translate_single_bytecode_to_trace(
target--;
}

if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]] > 0) {
uint16_t backoff = (this_instr + 1)->counter.value_and_backoff;
// adaptive_counter_cooldown is a fresh specialization.
// trigger_backoff_counter is what we set during tracing.
// All tracing backoffs should be freshly specialized or untouched.
// If not, that indicates a deopt during tracing, and
// thus the "actual" instruction executed is not the one that is
// in the instruction stream, but rather the deopt.
// It's important we check for this, as some specializations might make
// no progress (they can immediately deopt after specializing).
// We do this to improve performance, as otherwise a compiled trace
// will just deopt immediately.
if (backoff != adaptive_counter_cooldown().value_and_backoff &&
backoff != trigger_backoff_counter().value_and_backoff) {
OPT_STAT_INC(trace_immediately_deopts);
opcode = _PyOpcode_Deopt[opcode];
}
}

int old_stack_level = _tstate->jit_tracer_state.prev_state.instr_stacklevel;

// Strange control-flow
Expand Down Expand Up @@ -1291,6 +1310,10 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil
assert(next_exit == -1);
assert(dest == executor->trace);
assert(dest->opcode == _START_EXECUTOR);
// Note: we MUST track it here before any Py_DECREF(executor) or
// linking of executor. Otherwise, the GC tries to untrack a
// still untracked object during dealloc.
_PyObject_GC_TRACK(executor);
_Py_ExecutorInit(executor, dependencies);
#ifdef Py_DEBUG
char *python_lltrace = Py_GETENV("PYTHON_LLTRACE");
Expand Down Expand Up @@ -1319,7 +1342,6 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil
return NULL;
}
#endif
_PyObject_GC_TRACK(executor);
return executor;
}

Expand Down
Loading