jlahoda commented on issue #4054:
URL: https://github.com/apache/netbeans/issues/4054#issuecomment-1407651558

   > > Hm - I don't think incrementing the pointer when toPhase does not reach 
the expected phase is correct - that would might mean the given file won't be 
run again.
   > 
   > I don't understand this part tbh. Why would anything change if it is ran 
again with the exact same state? Also when stop is set to true it will be reset 
on the next loop iteration without ever doing anything?
   
   So, NetBeans, for a long time, allowed to process projects that would not 
fit into the memory while parsed&attributed. There were several tricks combined 
to let that happen, and one of them ability to re-load a class, that is already 
load from a classfile, from a source. That was part of the patched nb-javac, as 
ordinary javac cannot do that.
   
   So, while processing many source files, it created an instance of javac, 
invoked the task for the first file, the task typically parsed&attributed 
(using all dependencies from classfiles), then the task was invoked for the 
second file (possibly re-loading an existing class load from classfile, but 
this time from source), etc. And if, at some point, the javac instance could 
not fit into memory, the toPhase signaled that, the task returned immediately, 
the infrastructure thrown away that instance of javac, created a new one, and 
started the task with the given file again (which then parsed&attributed it in 
the new javac instance, etc.). So, multi-file tasks generally can be called 
multiple (2) times for the same file, if there's not enough memory to process 
all at once.
   
   With the removal of nb-javac, we've lost the ability to re-load classes from 
sources, so there was a need to do it differently. So, the current approach is 
"all at once or file-by-file" (either all files will fit into the memory, or 
the processing will run slowly creating a javac instance for each file), but it 
may still happen the processing will start in the "all" way, and then drop to 
"file-by-file", and that is again indicated by the toPhase result. I.e. if the 
achieved phase is not high enough, the task should stop, and it will be called 
again (in a file-by-file mode in practice, but the task should not care). So, 
this is the reason why we can't blindly increment the pointer, as that may lead 
to skipping some files (although in practice it would be rare, see below).
   
   The reason for the pointer is that hint may in general force a change in 
dependencies - they may, e.g. say that a new dependency should be added, and we 
need to throw away the javac instance, and create a new one. This is what the 
pointer and `stop` variable are trying to achieve. In practice, this is not 
really common, and the ` while (currentPointer.get() < toProcess.size())` loop 
is executed only once.
   
   Also, normally when javac crashes during toPhase, there will actually be an 
exception thrown, which is handled properly by the task.
   
   In this particular case, however, there is a single file, so most of the 
machinery described above is not useful, and it is also a file opened in the 
editor, and hence javac has already been run on it, so not exception is thrown.
   
   I was doing some experiments, and the solution probably is incrementing the 
pointer, we just need to limit that to only these conditions. I should be able 
to submit a PR shortly.
   
   > 
   > the original code when imported the first time looked like this: 
https://github.com/emilianbold/netbeans-releases/blob/2216f9361692d8bf818c086e028e86aff0ffaf7f/java.hints/src/org/netbeans/modules/java/hints/jackpot/impl/batch/BatchSearch.java#L297-L323
   > 
   > comment links to this bug: 
https://bz.apache.org/netbeans/show_bug.cgi?id=192481
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to