From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: MPS: Bytecode stack Date: Mon, 06 May 2024 15:23:29 +0200 Message-ID: References: <3174C6A6-28A6-492E-A268-E391A13FEA36@gmail.com> <038B57D6-C449-4C10-85F8-69D0A7844219@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26612"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , Helmut Eller , Emacs Devel To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 06 15:24:23 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s3yKN-0006m9-4a for ged-emacs-devel@m.gmane-mx.org; Mon, 06 May 2024 15:24:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3yJj-00028Q-Dm; Mon, 06 May 2024 09:23:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3yJb-00026j-FJ for emacs-devel@gnu.org; Mon, 06 May 2024 09:23:37 -0400 Original-Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s3yJY-0001iU-VM; Mon, 06 May 2024 09:23:35 -0400 Original-Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a59c448b44aso282720166b.2; Mon, 06 May 2024 06:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715001811; x=1715606611; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DcaQxEOpAlNdjZuYTOSw3QTZE3uPdq0xskXJ/6TvDew=; b=AjIoFMNaEuO5Qjo3L6ILMqnDwHR3N7EtkmfdbU48pLkvKOLyAVge4WWuFjTDfuu5jp PIDV8E58kgkXv7K0cS1AhtH7IRcd4v9ZV5x3WFfMJz9X/SUMwdAeJtEp2ZRO2ZN7naIV CwkRYxWtk6UPIXx/wLp5pWuTrNJHsmkt1HKQ4z9rqZ6SZAr4MSbkK/IhnzMMtPeaBoNN V+cnF/RMANdPzE90gQrmsV0h6Bmv+G3xygyD2lI8bdks7fGJT33BJW2a0rw7kOJsu9Jl 0zAuLJifGqjXA5ytfXSy+lJmhmT2KbOkYOI/W2BiypEODkRLLOXeHoGxxyaUpUIFYTDJ s4YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715001811; x=1715606611; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DcaQxEOpAlNdjZuYTOSw3QTZE3uPdq0xskXJ/6TvDew=; b=F01nryiMozle1PJU9KUGdk5FB6B0Ycs2c7zCUC1uJR4UudjCYnoxYpUBUuLWUwk7w3 3+nM+dJMc+EiKijSnDg52noISwzDCsKdTS3x7wGHlYD9QTZOX0MjR/tg8Z+kEZapCF/z z7QSTfdjJxtXHX38lQ0JJRDEy2E+l9CsBSeyIhgm0MmH5oXij3iZZgkUPY+I4/e0MW6e LmjgGNIYOBdv1X1xRrmShfY6H37Bnpol1ChOP15Pm5fj9YCHHtZBhUgeEu5XmRRMyXWL qGIZhfhfwUJEKiuqmGpEm51YCQ1i49yFL5wq7Mh8Bj5XOOTNuTOjjULGuiWZeyaxEj6C wyPw== X-Forwarded-Encrypted: i=1; AJvYcCWHeSMWUVdR9P4y+Nff20reWcor3Yi0FE5ESQ2kX8O20C5KtTv4FG1FqZBuUE+U5CUJ6H24Ax6QK28LrRJsPzCdMsx0 X-Gm-Message-State: AOJu0Yxlqb0x7vZg063yytAoefUpSYmN9HOsxiLUSzSqUJC5g2MIaLuO wcdUfMmqxz/dqp2/Q84saxu8ZqUEKdewiBmRNOGnQVaZmkl2MKQbxm3wGQ== X-Google-Smtp-Source: AGHT+IHpBrL3Hhm3IPnnUB6gaVNhmt7sFShiMWfu1Ebgf7PmSTDnCghPrqVymZ0uA4SNWrcE5iOeiA== X-Received: by 2002:a17:907:2d88:b0:a59:d243:945 with SMTP id gt8-20020a1709072d8800b00a59d2430945mr1350244ejc.57.1715001810627; Mon, 06 May 2024 06:23:30 -0700 (PDT) Original-Received: from pro2.fritz.box (p4fe3a55e.dip0.t-ipconnect.de. [79.227.165.94]) by smtp.gmail.com with ESMTPSA id v5-20020a1709060b4500b00a59a05c273csm3451013ejg.87.2024.05.06.06.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 06:23:30 -0700 (PDT) In-Reply-To: <038B57D6-C449-4C10-85F8-69D0A7844219@gmail.com> ("Mattias =?utf-8?Q?Engdeg=C3=A5rd=22's?= message of "Mon, 6 May 2024 15:07:20 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=gerd.moellmann@gmail.com; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:318890 Archived-At: Mattias Engdeg=C3=A5rd writes: > 6 maj 2024 kl. 14.47 skrev Gerd M=C3=B6llmann : > >> It would be easiest if you'd look at scan_bc in igc.c on the branch > > I did, which is why I wondered whether I had understood the problem corre= ctly. Maybe we can help each other: > >> /* FIXME: AFAIU the current top frame starts at bc->fp->next_stack > > Does it? Look at the ASCII art in bytecode.c. During bytecode > execution, fp->next_stack is the lowest completely unused entry of the > bytecode stack, but that refers to the engine register `fp` which is > almost but not entirely in sync with `bc->fp`. There are gaps when > there is live data on the stack beyond bc->fp->next_stack, such as > during frame setup: > > 514 Lisp_Object *frame_base =3D bc->fp->next_stack; > 515 struct bc_frame *fp =3D (struct bc_frame *)(frame_base + max_stack= ); > 516=20 > 517 if ((char *)fp->next_stack > bc->stack_end) > 518 error ("Bytecode stack overflow"); > 519=20 > 520 /* Save the function object so that the bytecode and vector are > 521 held from removal by the GC. */ > 522 fp->fun =3D fun; > 523 /* Save previous stack pointer and pc in the new frame. If we came > 524 directly from outside, these will be NULL. */ > 525 fp->saved_top =3D top; > 526 fp->saved_pc =3D pc; > 527 fp->saved_fp =3D bc->fp; > 528 bc->fp =3D fp; > > which is why I was concerned about whether there might be a race > somewhere. Note, however, that in this particular window we don't > stash anything to the stack beyond bc->fp->next_stack that isn't > already accessible via ambig refs elsewhere (`fun` in particular). > > There may be similar gaps when we pop stack frames: return from a > function and in the catch and condition-case handling, but it would be > easier if I knew what I was looking for. Ok, let me try to explain. Thanks for looking into this! I made the bc stack(s) ambig roots (conservativly scanned, like with mark_memory). For the root address range I use the stack's start and end. Since that is quite large (512K?), I though it a good idea to scan less. So scan_bc tries to figure out an 'end' address that is smaller the whole stack's end. That's all it is about. How to find a realistic, scan end.