You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sd...@apache.org on 2021/07/22 09:27:30 UTC
[netbeans] branch master updated: Force bytecode parsing. Cache
resource misses.
This is an automated email from the ASF dual-hosted git repository.
sdedic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new d57e684 Force bytecode parsing. Cache resource misses.
new 27c8f57 Merge pull request #3068 from sdedic/groovy/parser-performance2
d57e684 is described below
commit d57e68408125d48be76a6ad1fd30ed2950a1ef24
Author: Svata Dedic <sv...@oracle.com>
AuthorDate: Tue Jul 20 12:41:55 2021 +0200
Force bytecode parsing. Cache resource misses.
---
.../groovy/editor/compiler/ClassNodeCache.java | 77 +++++++++++++++++++++-
.../groovy/editor/compiler/CompilationUnit.java | 6 +-
groovy/libs.groovy/nbproject/project.xml | 19 +++++-
3 files changed, 97 insertions(+), 5 deletions(-)
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/ClassNodeCache.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/ClassNodeCache.java
index 79599a3..5ef03a7 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/ClassNodeCache.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/ClassNodeCache.java
@@ -20,11 +20,13 @@ package org.netbeans.modules.groovy.editor.compiler;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyResourceLoader;
+import java.io.IOException;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -42,6 +44,7 @@ import org.netbeans.api.java.source.ClasspathInfo;
import org.netbeans.api.java.source.JavaSource;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.URLMapper;
+import org.openide.util.Enumerations;
/**
*
@@ -108,6 +111,18 @@ public final class ClassNodeCache {
return result;
}
+ public boolean isNonExistentResource(@NonNull final CharSequence name) {
+ return nonExistent.containsKey(name);
+ }
+
+ public void addNonExistentResource(@NonNull final CharSequence name) {
+ LOG.log(
+ Level.FINE,
+ "Unreachable resource: {0}", //NOI18N
+ name);
+ nonExistent.putIfAbsent(name, null);
+ }
+
public boolean isNonExistent (@NonNull final CharSequence name) {
if (!isValidClassName(name)) {
return true;
@@ -305,7 +320,7 @@ public final class ClassNodeCache {
private final GroovyResourceLoader resourceLoader
= (String filename) -> AccessController.doPrivileged(
(PrivilegedAction<URL>) () -> getSourceFile(filename));
-
+
public ParsingClassLoader(
@NonNull ClassPath path,
@NonNull CompilerConfiguration config,
@@ -315,21 +330,77 @@ public final class ClassNodeCache {
this.path = path;
this.cache = cache;
}
-
+
@Override
public Class loadClass(
final String name,
final boolean lookupScriptFiles,
final boolean preferClassOverScript,
final boolean resolve) throws ClassNotFoundException, CompilationFailedException {
+ LOG.log(Level.FINE, "Parser {4} asking for {0}, scripts {1}, classOverScript {2}, resolve {3}",
+ new Object[] { name, lookupScriptFiles, preferClassOverScript, resolve,
+ System.identityHashCode(this)
+ });
+ String rn = null;
if (preferClassOverScript && !lookupScriptFiles) {
+ rn = name.replace(".", "/") + ".class";
+ if (cache.isNonExistentResource(rn)) {
+ LOG.log(Level.FINE, " -> cached NONE");
+ throw CNF;
+ }
+
//Ideally throw CNF but we need to workaround fix of issue #206811
//which hurts performance.
if (cache.isNonExistent(name)) {
+ LOG.log(Level.FINE, " -> cached NONE");
throw CNF;
}
}
- return super.loadClass(name, lookupScriptFiles, preferClassOverScript, resolve);
+ boolean ok = false;
+ try {
+ Class c = super.loadClass(name, lookupScriptFiles, preferClassOverScript, resolve);
+ ok = true;
+ return c;
+ } finally {
+ if (!ok && rn != null) {
+ cache.addNonExistentResource(rn);
+ }
+ }
+ }
+
+ @Override
+ public Enumeration<URL> getResources(String name) throws IOException {
+ if (cache.isNonExistentResource(name)) {
+ return Enumerations.empty();
+ }
+ Enumeration<URL> en = super.getResources(name);
+ if (!en.hasMoreElements()) {
+ cache.addNonExistentResource(name);
+ }
+ return en;
+ }
+
+ @Override
+ public URL getResource(String name) {
+ if (cache.isNonExistentResource(name)) {
+ return null;
+ }
+ URL u = super.getResource(name);
+ if (u == null) {
+ LOG.log(Level.FINE, " -> caching nonexistent: " + name);
+ cache.addNonExistentResource(name);
+ }
+ return u;
+ }
+
+ @Override
+ public URL findResource(String name) {
+ if (cache.isNonExistentResource(name)) {
+ return null;
+ }
+ LOG.log(Level.FINE, "Parser {1} findResource {0}",
+ new Object[] { name, System.identityHashCode(this) });
+ return super.findResource(name);
}
@Override
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/CompilationUnit.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/CompilationUnit.java
index 7c56fd5..66f5378 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/CompilationUnit.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/CompilationUnit.java
@@ -39,6 +39,7 @@ import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.GenericsType;
import org.codehaus.groovy.ast.MixinNode;
import org.codehaus.groovy.control.ClassNodeResolver.LookupResult;
+import org.codehaus.groovy.control.ClassNodeResolver;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.java.source.ClasspathInfo;
@@ -64,6 +65,9 @@ public final class CompilationUnit extends org.codehaus.groovy.control.Compilati
@NonNull final ClassNodeCache classNodeCache) {
super(configuration, security, loader, transformationLoader);
+ Map<String, Boolean> opts = this.configuration.getOptimizationOptions();
+ opts.put("classLoaderResolving", Boolean.FALSE);
+ this.configuration.setOptimizationOptions(opts);
this.ast = new CompileUnit(parser, this.classLoader,
(n) -> {
LookupResult lr = getClassNodeResolver().resolveName(n, this);
@@ -75,7 +79,7 @@ public final class CompilationUnit extends org.codehaus.groovy.control.Compilati
},
security, this.configuration, cpInfo, classNodeCache);
}
-
+
private static class CompileUnit extends org.codehaus.groovy.ast.CompileUnit {
private final Function<String, ClassNode> classResolver;
private final ClassNodeCache cache;
diff --git a/groovy/libs.groovy/nbproject/project.xml b/groovy/libs.groovy/nbproject/project.xml
index 6e04e95..1e11dab 100644
--- a/groovy/libs.groovy/nbproject/project.xml
+++ b/groovy/libs.groovy/nbproject/project.xml
@@ -29,7 +29,24 @@
<friend>org.netbeans.modules.groovy.editor</friend>
<friend>org.netbeans.modules.groovy.refactoring</friend>
<friend>org.netbeans.modules.groovy.support</friend>
- <subpackages>groovy</subpackages>
+ <package>groovy</package>
+ <package>groovy.beans</package>
+ <package>groovy.cli</package>
+ <package>groovy.grape</package>
+ <package>groovy.inspect</package>
+ <package>groovy.io</package>
+ <package>groovy.lang</package>
+ <package>groovy.lang.groovydoc</package>
+ <package>groovy.namespace</package>
+ <package>groovy.security</package>
+ <package>groovy.transform</package>
+ <package>groovy.transform.builder</package>
+ <package>groovy.transform.options</package>
+ <package>groovy.transform.stc</package>
+ <package>groovy.ui</package>
+ <package>groovy.util</package>
+ <package>groovy.util.logging</package>
+ <package>groovy.xml</package>
<package>groovyjarjarantlr</package>
<package>groovyjarjarasm.asm</package>
<package>org.codehaus.groovy</package>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists