You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2015/07/18 06:24:49 UTC

svn commit: r1691671 - in /commons/proper/bcel/trunk: pom.xml src/changes/changes.xml src/main/java/org/apache/bcel/generic/ObjectType.java src/test/java/org/apache/bcel/PerformanceTest.java

Author: chas
Date: Sat Jul 18 04:24:48 2015
New Revision: 1691671

URL: http://svn.apache.org/r1691671
Log:
BCEL-218 Remove caching from ObjectType

Modified:
    commons/proper/bcel/trunk/pom.xml
    commons/proper/bcel/trunk/src/changes/changes.xml
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ObjectType.java
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java

Modified: commons/proper/bcel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/pom.xml?rev=1691671&r1=1691670&r2=1691671&view=diff
==============================================================================
--- commons/proper/bcel/trunk/pom.xml (original)
+++ commons/proper/bcel/trunk/pom.xml Sat Jul 18 04:24:48 2015
@@ -41,8 +41,8 @@
   <properties>
     <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-    <maven.compiler.source>1.5</maven.compiler.source>
-    <maven.compiler.target>1.5</maven.compiler.target>
+    <maven.compiler.source>1.7</maven.compiler.source>
+    <maven.compiler.target>1.7</maven.compiler.target>
     <commons.componentid>bcel</commons.componentid>
     <commons.release.version>6.0</commons.release.version>
     <commons.release.desc>(Java 5.0+)</commons.release.desc>
@@ -202,6 +202,7 @@
         <configuration>
           <includes>
             <include>**/*TestCase.java</include>
+            <include>**/PerformanceTest.java</include>
           </includes>
           <excludes>
             <exclude>**/Abstract*</exclude>
@@ -350,6 +351,25 @@
       </properties>
     </profile>
 
+    <!-- Profile to build and run PerformanceTest. Use 'mvn test -Pjdk-rt' -->
+	<profile>
+	      <id>jdk-rt</id>
+	            <build>
+        <plugins>
+                <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/PerformanceTest.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+
+        </plugins>
+      </build>
+	      
+	</profile>
+	
     <!-- Profile to build and run the benchmarks. Use 'mvn test -Pbenchmark', and add '-Dbenchmark=foo' to run only the foo benchmark -->
     <profile>
       <id>benchmark</id>

Modified: commons/proper/bcel/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/changes/changes.xml?rev=1691671&r1=1691670&r2=1691671&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/changes/changes.xml (original)
+++ commons/proper/bcel/trunk/src/changes/changes.xml Sat Jul 18 04:24:48 2015
@@ -63,6 +63,12 @@ The <action> type attribute can be add,u
 
   <body>
     <release version="6.0" date="TBA" description="Major release with Java 7 and 8 support">
+      <action issue="BCEL-218" type="fix" due-to="chas">
+        Remove ObjectType cache.
+      </action>
+      <action issue="BCEL-184" type="fix" due-to="Jérôme Leroux">
+        The verifier now checks if methods with a void return type attempt to return an object.
+      </action>
       <action issue="BCEL-184" type="fix" due-to="Jérôme Leroux">
         The verifier now checks if methods with a void return type attempt to return an object.
       </action>

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ObjectType.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ObjectType.java?rev=1691671&r1=1691670&r2=1691671&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ObjectType.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/ObjectType.java Sat Jul 18 04:24:48 2015
@@ -17,9 +17,6 @@
  */
 package org.apache.bcel.generic;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
-
 import org.apache.bcel.Constants;
 import org.apache.bcel.Repository;
 import org.apache.bcel.classfile.JavaClass;
@@ -34,31 +31,9 @@ public class ObjectType extends Referenc
 
     private static final long serialVersionUID = -2819379966444533294L;
     private final String class_name; // Class name of type
-    private static final int MAX_CACHE_ENTRIES = 200;
-    private static final int INITIAL_CACHE_CAPACITY = (int)(MAX_CACHE_ENTRIES/0.75);
-    private static Map<String, ObjectType> cache;
-
-    public synchronized static ObjectType getInstance(String class_name) {
-        if (cache == null) {
-            cache = new LinkedHashMap<String, ObjectType>(INITIAL_CACHE_CAPACITY, 0.75f, true) {
-
-
-            private static final long serialVersionUID = 2101159231109718724L;
-
-            @Override
-            protected boolean removeEldestEntry(Map.Entry<String, ObjectType> eldest) {
-               return size() > MAX_CACHE_ENTRIES;
-            }
 
-        };
-        }
-        ObjectType result = cache.get(class_name);
-        if (result != null) {
-            return result;
-        }
-        result = new ObjectType(class_name);
-        cache.put(class_name, result);
-        return result;
+    public static ObjectType getInstance(String class_name) {
+        return new ObjectType(class_name);
     }
 
     /**

Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java?rev=1691671&r1=1691670&r2=1691671&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java (original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java Sat Jul 18 04:24:48 2015
@@ -19,20 +19,23 @@
 package org.apache.bcel;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Enumeration;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
-import junit.framework.TestCase;
-
 import org.apache.bcel.classfile.ClassParser;
 import org.apache.bcel.classfile.JavaClass;
 import org.apache.bcel.classfile.Method;
 import org.apache.bcel.generic.ClassGen;
 import org.apache.bcel.generic.InstructionList;
 import org.apache.bcel.generic.MethodGen;
+import org.junit.Assert;
+
+import junit.framework.TestCase;
 
 public final class PerformanceTest extends TestCase {
 
@@ -61,7 +64,7 @@ public final class PerformanceTest exten
         }
     }
 
-    private static void test(int fraction) throws IOException {
+    private static void test(File lib) throws IOException {
         NanoTimer total = new NanoTimer();
         NanoTimer parseTime = new NanoTimer();
         NanoTimer cgenTime = new NanoTimer();
@@ -69,17 +72,15 @@ public final class PerformanceTest exten
         NanoTimer mserTime = new NanoTimer();
         NanoTimer serTime = new NanoTimer();
 
-        total.start();
-
-        String javaHome = System.getProperty("java.home");
+        System.out.println("parsing " + lib);
 
-        JarFile jar = new JarFile(javaHome + "/lib/rt.jar");
+        total.start();
+        JarFile jar = new JarFile(lib);
         Enumeration<?> en = jar.entries();
-        int i = 0;
 
         while (en.hasMoreElements()) {
             JarEntry e = (JarEntry) en.nextElement();
-            if (e.getName().endsWith(".class") && i++ % fraction == 0) {
+            if (e.getName().endsWith(".class")) {
                 InputStream in = jar.getInputStream(e);
                 byte[] bytes = read(in);
 
@@ -127,9 +128,20 @@ public final class PerformanceTest exten
     }
 
     public void testPerformance() throws IOException {
-        test(1);
-        test(1);
-        test(1);        
+        File javaLib = new File(System.getProperty("java.home") + "/lib");
+        javaLib.listFiles(new FileFilter() {
+
+            public boolean accept(File file) {
+                if(file.getName().endsWith(".jar")) {
+                    try {
+                        test(file);
+                    } catch (IOException e) {
+                        Assert.fail(e.getMessage());
+                    }
+                }
+                return false;
+            }
+        });
     }
 
 }