Bug 573449 - Enable blackbox resolution against workspace metamodels
Summary: Enable blackbox resolution against workspace metamodels
Status: NEW
Alias: None
Product: QVTo
Classification: Modeling
Component: Engine (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-10 05:15 EDT by Christopher Gerking CLA
Modified: 2022-01-10 12:05 EST (History)
1 user (show)

See Also:


Attachments
Performance demo (3.54 KB, application/x-zip-compressed)
2021-06-09 03:48 EDT, Christopher Gerking CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Gerking CLA 2021-05-10 05:15:35 EDT
Since bug 472482 has been closed, it is now possible to resolve Java blackboxes within the workspace. What is still missing is the possibility to resolve these blackboxes against metamodels that are also located in the workspace. Such metamodels are not found, so the blackboxes cannot be compiled successfully.
Comment 1 Christopher Gerking CLA 2021-05-10 09:17:57 EDT
(In reply to Christopher Gerking from comment #0)
> Since bug 472482 has been closed
Apparently it was not yet closed.

Anyway, fix proposed on cgerking/573449. It uses EcorePlugin.getEPackageNsURIToGenModelLocationMap(...) to find the corresponding genmodel of a workspace metamodel, and then reads the Java class names from the genmodel.

Since workspace metamodels are dynamic, the corresponding Java blackbox providers must be unloaded and then reloaded. This was not the case before because registered metamodels were not expected to change.

Unfortunately, to read the genmodels, the fix introduces a new plugin dependency on org.eclipse.emf.codegen.ecore. Perhaps this could be avoided by using reflection, especially since this plugin should not be required during standalone execution.
Comment 2 Ed Willink CLA 2021-05-22 15:42:52 EDT
In reply to Christopher Gerking from Bug 573659
> When it comes to bug 573449, I'm still unhappy
> about the new dependency to org.eclipse.emf.codegen.ecore. Standalone users
> might not have this plugin on their classpath.

org.eclipse.emf.codegen.ecore is a moderately common ecore plugin and the much less common org.eclipse.emf.ecore.change is already required. (org.eclipse.acceleo.engine has a org.eclipse.emf.codegen.ecore dependency.)

You could make the dependecy optional and catch the Class Load failure exception.

You could use eGet and dynamic EMF to avoid the dependency altogether.

A bit late for M3 on Tuesday but let's do thois for RC1 a week later.
Comment 3 Ed Willink CLA 2021-05-22 16:33:33 EDT
(In reply to Ed Willink from comment #2)
> A bit late for M3 on Tuesday but let's do thois for RC1 a week later.

Opps. Got confused. Pushed to mastter for M3.
Comment 4 Eclipse Genie CLA 2021-06-07 08:22:11 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181515
Comment 5 Christopher Gerking CLA 2021-06-07 08:24:58 EDT
(In reply to Christopher Gerking from comment #1)
> Since workspace metamodels are dynamic, the corresponding Java blackbox
> providers must be unloaded and then reloaded.
Fixing a minor concurrency issue on cgerking/573449. If the loading is not snchronized, it might happen that two different versions of the same blackbox are loaded.

Ready for RC2.
Comment 6 Eclipse Genie CLA 2021-06-07 16:51:40 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181546
Comment 7 Christopher Gerking CLA 2021-06-07 16:57:46 EDT
(In reply to Ed Willink from comment #2)
> You could make the dependecy optional and catch the Class Load failure
> exception.
Done on cgerking/573449.
Comment 8 Eclipse Genie CLA 2021-06-08 10:02:47 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181601
Comment 9 Eclipse Genie CLA 2021-06-08 10:02:49 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181600
Comment 10 Eclipse Genie CLA 2021-06-08 12:36:24 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181623
Comment 11 Christopher Gerking CLA 2021-06-08 12:37:40 EDT
Important performance improvements pushed to cgerking/573449.
Comment 12 Eclipse Genie CLA 2021-06-08 16:51:03 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181646
Comment 13 Eclipse Genie CLA 2021-06-08 16:51:05 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181645
Comment 14 Eclipse Genie CLA 2021-06-08 16:51:07 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181647
Comment 15 Eclipse Genie CLA 2021-06-08 16:51:09 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181648
Comment 16 Christopher Gerking CLA 2021-06-08 18:09:39 EDT
No idea why the latest builds failed. The log reports a problem with org.eclipse.qvto.releng.tycho. Locally everything is still green.
Comment 17 Ed Willink CLA 2021-06-09 03:04:49 EDT
(In reply to Christopher Gerking from comment #16)
> No idea why the latest builds failed.

"[cross-project-issues-dev] Problem with repo.eclipse.org and simrel gerrit verification" received "Repo.eclipse was down most of the afternoon https://www.eclipsestatus.io/incidents/9zv3vwwhn0rg" response. Do you subscribe to cross-project-issues-dev? 

----

The "Simplify search for GenClassifiers" commit seems to be a useful rather than necessary fix, which if nothing else is a different algorithm with associated bug hazards. Definitely not necessary (or appropriate) as a post RC2 fix.

----

The "Reduce performance overhead for computing GenModel locations" fix seems to just duplicate EMF's static cache with a local non-static cache. For a first access, the new subroutine call offsets the EMF subrotione call overhead. For multiple accesses the new fix seems worse. Definitely not necessary as a post RC2 fix. Maybe I misunderstnad so it could be useful.
Comment 18 Christopher Gerking CLA 2021-06-09 03:46:10 EDT
(In reply to Ed Willink from comment #17)
> Do you subscribe to cross-project-issues-dev? 
Yes, sorry. I overlooked it.


> The "Simplify search for GenClassifiers" commit seems to be a useful rather
> than necessary fix, which if nothing else is a different algorithm with
> associated bug hazards. Definitely not necessary (or appropriate) as a post
> RC2 fix.
Right. It probably doesn't make a big difference.

Unlike the "Make org.eclipse.emf.codegen.ecore dependency optional" commit. This one is important to avoid a new dependency (especially in standalone mode, where org.eclipse.emf.codegen.ecore is not required at all in 2021-03). So this could avoid a breaking change.


> The "Reduce performance overhead for computing GenModel locations" fix seems
> to just duplicate EMF's static cache with a local non-static cache.
Is there actually a static cache? Is seems as if getEPackageNsURIToGenModelLocationMap(...) invokes PDEHelper.computeModels(...) again and again.

This and the other remaining fixes include important performance improvements. I will provide an example project for demonstration, which compiles forever using the current master.
Comment 19 Christopher Gerking CLA 2021-06-09 03:48:31 EDT
Created attachment 286548 [details]
Performance demo

Demo project that compiles forever (if org.eclipse.ocl.pivot is in the same workspace)
Comment 20 Ed Willink CLA 2021-06-09 04:35:35 EDT
Compiles forever is definitely not good, but surely there are a finite number of calls, so long time perhaps, but not forever. Forever implies an infinite loop, possibly by inadvertently triggering a rebuild. The loop needs to be identified.

Yes the PDEHelper is repeatedly invoked if there is PDE support, since I suppose detecting target platform changes is too hard. Does QVTo need PDE support?
Comment 21 Christopher Gerking CLA 2021-06-09 04:44:53 EDT
(In reply to Ed Willink from comment #20)
> Compiles forever is definitely not good, but surely there are a finite
> number of calls, so long time perhaps, but not forever.
Right, it's very long not forever. The reasons are that the NsURIToGenModelLocationMap is repeatedly computed and that the same genmodels are reloaded again and again. In both cases, caching does the trick.


> Does QVTo need PDE support?
Not necessarily, but org.eclipse.m2m.qvt.oml.runtime.jdt does.
Comment 22 Ed Willink CLA 2021-06-09 05:40:34 EDT
Reviewing your 4 rebased commits to try to do something to day.

----

"Make org.eclipse.emf.codegen.ecore dependency optional" looks harmless enough but have you actually tested it?

IIRC the "instanceof GenClassifier" will be compiled when the surrounding function is compiled and so outside the try catch block. If you want fine grained load detection you must use forName or load. Or wrap the failure in a function such as

if (genModelContent != null) {
    try {
        ... = resolveGenModelContent(...)
    }
    catch (...)

----

The GenClassifier changes worry me since I see a change to the support GenXXX hierarchy assuming a root GenModel. IIRC once usedGenPackages are involved things get harder. So I am far from convinced that your changes do not exchange rather than fix problems..

----

I would like to see a fix to the 'forever', but I want to see as little else changing as possible.
Comment 23 Eclipse Genie CLA 2021-06-09 06:31:47 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181692
Comment 24 Christopher Gerking CLA 2021-06-09 06:35:08 EDT
(In reply to Ed Willink from comment #22)
> IIRC the "instanceof GenClassifier" will be compiled when the surrounding
> function is compiled and so outside the try catch block. 
I wasn't aware of that.


> Or wrap the failure in a function 
Prototyped on cgerking/573449.


> I see a change to the support GenXXX hierarchy assuming a root GenModel. 
Yes, that was my assumption. 


> So I am far from convinced that your changes do not exchange rather than 
> fix problems..
I see, however the previous code traversing the GenXXX hierarchy was new for 2021-06 as well, so previously there was no GenModel support at all. That's why the change shouldn't cause any regressions.


> I would like to see a fix to the 'forever', but I want to see as little else
> changing as possible.
There is no 'forever', I just exaggerated. But the test project shows me that it can take a very very long time.
Comment 25 Ed Willink CLA 2021-06-09 09:29:16 EDT
How about ewillink/573449 for the 3.10.4 R-build with the rest held over to 3.10.5?
Comment 26 Ed Willink CLA 2021-06-09 09:32:00 EDT
Sorry for the delay. Bugzilla is not notifying again and I didn't notice that my previous reply collided in mid-air.

Yes there is no regression wrt 2021-03, but every change post RC2 has not been exercised by anyone so is really dangerous.
Comment 28 Eclipse Genie CLA 2021-06-10 05:51:50 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/181762
Comment 29 Christopher Gerking CLA 2021-06-10 06:44:29 EDT
(In reply to Ed Willink from comment #25)
> How about ewillink/573449 for the 3.10.4 R-build with the rest held over to
> 3.10.5?
Addressed the GenModel traversal on cgerking/573449 again. Compared to the current aproach of traversing EcoreUtil.getAllContents(...), using GenModel.findGenClassifier(...) seems way more efficient. This is due to internal caching and more intelligent search strategies (scanning only the relevant GenPackage instead of all).


(In reply to Ed Willink from comment #22)
> I see a change to the support GenXXX hierarchy assuming a root GenModel.
Is this assumption invalid? Do we need to prepare for a *.genmodel without a GenModel at its root?
Comment 30 Eclipse Genie CLA 2021-09-05 08:08:40 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/184991
Comment 31 Eclipse Genie CLA 2021-09-08 05:52:23 EDT
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/185139
Comment 32 Ed Willink CLA 2021-09-09 06:32:53 EDT
Installing cgerking/master that aggregates this fix seems good. I see a couple of momentary "QVTo Analyzing" in the progress view, but almost too quick to see. Excellent.
Comment 34 Christopher Gerking CLA 2021-09-13 06:26:44 EDT
(In reply to Ed Willink from comment #32)
> Installing cgerking/master that aggregates this fix seems good.
Pushed to master.
Comment 35 Christopher Gerking CLA 2022-01-06 07:38:59 EST
(In reply to Christopher Gerking from comment #1)
> Since workspace metamodels are dynamic, the corresponding Java blackbox
> providers must be unloaded and then reloaded.
Made a stupid mistake here because the EPackage.Registry used to control the unload/reload must obviously be local to the individual blackbox units, not to their overarching blackbox provider. Otherwise only the first unit provided by that provider will be reloaded. 

This is a careless mistake caused by the nesting of the descriptor as an inner class of the provider. Thus the fPackageRegistry field was just placed inside the wrong class, so move it from the blackbox provider to the blackbox unit.
Comment 36 Eclipse Genie CLA 2022-01-06 07:39:47 EST
New Gerrit change created: https://git.eclipse.org/r/c/mmt/org.eclipse.qvto/+/189344
Comment 37 Ed Willink CLA 2022-01-06 14:04:29 EST
(In reply to Christopher Gerking from comment #35)
> Otherwise only the first unit provided by that provider will be reloaded. 

Is this the Bug 577992 use case?

If so, let's have that as a regression test.
Comment 38 Christopher Gerking CLA 2022-01-10 06:53:58 EST
(In reply to Ed Willink from comment #37)
> Is this the Bug 577992 use case?
No, it has nothing to do with it.

> If so, let's have that as a regression test.
To make this a regression test, we would need to implement a whole usage scenario in which a blackbox is first compiled, then changed to a different signature, then recompiled. If this happens, and there is more than one blackbox candidate in the respective project, only the (lexicographically) first one will actually reload and reflect the signature change. As you can see, it's quite a corner case that will be hard to encode as an automated test.