Subject: Re: bug#40907: Font-lock-mode hanging in Java buffers

From: Alan Mackenzie <[email-masked]>
Date: Wed, 29 Apr 2020 18:36:37 +0000

Hello, Adam.

On Mon, Apr 27, 2020 at 18:21:09 +0000, Adam Van Ymeren wrote:

> On 2020-04-27 5:38 p.m., Dmitry Gutov wrote:
> > On 27.04.2020 20:30, Adam Van Ymeren wrote:
> >> I've been doing a lot of Java work lately, and I'm having issues with 
> >> emacs hanging and spinning at 100% CPU.  I believe the culprit to be 
> >> font-lock-mode.  C-g doesn't save me either, I usually have to kill 
> >> emacs.  Any advice on how to debug this if C-g doesn't work?

> > You can send the USR2 signal to the Emacs process to try to interrupt 
> > what it's doing and enter the debugger:

> > kill -SIGUSR2 <pid>

> > To fix this, we'll most likely need the contents of the buffer that 
> > has the problem. If it's proprietary, you could try recreating the 
> > problem from scratch, or replacing all identifiers in the code with 
> > something else, etc.

> > You could also try a build of Emacs 27 first before doing all that.

> Wow SIGUSR2 is magical, thanks for that tip.  I reproduced it once 
> visiting a particular file but it's not happening reliably for me now.  
> Below is the stacktrace and the contents of the associated buffer, but 
> it's not reproducing reliably.  Now that I know about SIGUSR2 I'll 
> report back with a reliable repro once I figure one out.

The buffer copy you sent looks corrupted - it contains lots of
non-breaking spaces (or are these intended?) and it seems to be
double-spaced all the way through.  If it is corrupted, is there any
chance you could post a clean version, possibly by attaching it to your
email?

With that, there's a good chance your stack trace will be enough to be
able to debug this.

There's also a good chance the bug has already been diagnosed and fixed
(for the upcoming Emacs-27.1), but it will need some effort to verify
this.

> Here's the emacs stacktrace:

[ Double spacing removed from this ... ]

> Debugger entered--entering a function:

> * #f(compiled-function () #<bytecode 0xe5f179>)()
>    c-parse-state()
>    c-syntactic-skip-backward("^;{}" 5344 t)
>    c-fl-decl-start(5927)
>    c-context-expand-fl-region(5927 6427)
>    #f(compiled-function (fn) #<bytecode 0xec98d5>)(c-context-expand-fl-region)
>    mapc(#f(compiled-function (fn) #<bytecode 0xec98d5>) (c-context-expand-fl-region))
>    c-before-context-fl-expand-region(5927 6427)
>    c-font-lock-fontify-region(5927 6427 nil)
>    font-lock-fontify-region(5927 6427)
>    #f(compiled-function (fun) #<bytecode 0x14a42f5>)(font-lock-fontify-region)
>    run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x14a42f5>) font-lock-fontify-region)
>    jit-lock--run-functions(5927 6427)
>    jit-lock-fontify-now(5927 6427)
>    jit-lock-function(5927)
>    redisplay_internal\ \(C\ function\)()

> And the buffer contents are given after ====

> ===============

> /**

>   * @license

>   * Copyright 2017 The FOAM Authors. All Rights Reserved.

>   * http://www.apache.org/licenses/LICENSE-2.0

>   */

> package foam.dao;

> import foam.core.*;

> import foam.dao.index.*;

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).