Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xbase] Classloading in XbaseInterpreter(Updating XbaseInterpreter's classloader doesn't work)
[Xbase] Classloading in XbaseInterpreter [message #1804214] Wed, 20 March 2019 15:06 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I'm writing an interpreter for an Xbase-based DSL and would like to support loading classes from the same Java project as the DSL file. That way I can mix Java code and DSL code. I have a ClassLoader that uses the classpath entries of the Java project and it works fine. The next step is to react to changes to Java project classes and re-instantiate the classloader, so the interpreter doesn't use old classes. This also works in principle, however, some class caching mechanism prevents it from working properly. Even though my classloader correctly reloads changed classes, Xtext's ClassFinder class (as used by XbaseInterpreter and JavaReflectAccess) uses Class.forName(String, boolean, ClassLoader) and it apparently (according to https://blog.hargrave.io/2007/09/classforname-caches-defined-class-in.html) has its own caching that reuses obsolete classes.

I've been able to replace JavaReflectAccess with my own class (since it is injected I can override it in my Guice module) and make it use a custom ClassFinder that uses ClassLoader.loadClass directly (instead of Class.forName), but XbaseInterpreter has another instance of ClassFinder that cannot easily be replaced, since it is not injected, but created using new, is private and accessed directly in many methods. So although my approach seems to work, now XbaseInterpreter uses (directly and indirectly through JavaReflectAccess) two ClassFinder instances with different class loading logic and that seems wrong, so I wonder what to do. The best would be to have the XbaseInterpreter use the same instance as JavaReflectAccess, or allow the creation of the its own ClassFinder instance to be customised (e.g. in an overridable getClassFinder method, like JavaReflectAccess does).

Any suggestions?

Regards,

Hallvard
Re: [Xbase] Classloading in XbaseInterpreter [message #1804225 is a reply to message #1804214] Wed, 20 March 2019 17:38 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hey Hallvard,

overriding org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.setClassLoader(ClassLoader) and initializing the necessary fields reflectively should work.

Best
Sebastian
Re: [Xbase] Classloading in XbaseInterpreter [message #1804309 is a reply to message #1804225] Fri, 22 March 2019 08:43 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
@Hallvard, we could change the code as follows: https://github.com/eclipse/xtext-extras/pull/393
would that help for easier subclassing?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Referenced versions in xtext-dev-bom
Next Topic:Security Exception when building Projects with Xtend
Goto Forum:
  


Current Time: Thu Apr 18 01:05:20 GMT 2024

Powered by FUDForum. Page generated in 0.02301 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top