You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "jtulach (via GitHub)" <gi...@apache.org> on 2023/03/11 16:49:14 UTC

[GitHub] [netbeans] jtulach commented on a diff in pull request #5609: nb-javac: "Eat your own dog food" testing

jtulach commented on code in PR #5609:
URL: https://github.com/apache/netbeans/pull/5609#discussion_r1133119166


##########
nbbuild/antsrc/org/netbeans/nbbuild/CustomJavac.java:
##########
@@ -252,4 +276,144 @@ private static boolean isIgnored(
         return false;
     }
 
+    private static final class NbJavacLoader extends URLClassLoader {
+        private static final String MAIN_COMPILER_CP = "nbjavac.class.path";
+        private static final String MAIN_COMPILER_CLASS = "com.sun.tools.javac.Main";
+        private final Map<String, Class<?>> priorityLoaded;
+
+        private NbJavacLoader(URL[] urls, ClassLoader parent) {
+            super(urls, parent);
+            this.priorityLoaded = new HashMap<>();

Review Comment:
   I tried to cache the `Class<?>` in a static field and that isn't enough. The `CustomJavac` class is loaded again for each NetBeans project (and there are thousands of them). With:
   ```diff
   netbeans$ git diff
   diff --git nbbuild/antsrc/org/netbeans/nbbuild/CustomJavac.java nbbuild/antsrc/org/netbeans/nbbuild/CustomJavac.java
   index 2e17b218d4..a1a57d01b1 100644
   --- nbbuild/antsrc/org/netbeans/nbbuild/CustomJavac.java
   +++ nbbuild/antsrc/org/netbeans/nbbuild/CustomJavac.java
   @@ -52,6 +52,9 @@ import org.apache.tools.ant.util.JavaEnvUtils;
     * and a separate task for {@link #cleanUpStaleClasses}.
     */
    public class CustomJavac extends Javac {
   +  static {
   +    System.err.println("CustomJavac loaded by " + CustomJavac.class.getClassLoader());
   +  }
    
        public CustomJavac() {}
    
   ```
   I see a lot of "CustomJavac loaded by AntClassLoader[/home/devel/NetBeansProjects/netbeans/nbbuild/build/nbantext.jar]" messages.
   
   I'd like to share the NbJavac `Class<?>` among all such classloaders. Using (misusing) `System.getProperties` is a way to do that.
   
   Without this trick the build was really slowed down. With the trick the time to build NetBeans with `nb-javac` is comparable to regular JDK's Javac.



-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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