You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2013/05/22 20:30:42 UTC

svn commit: r1485322 - in /db/derby/code/trunk: ./ java/build/org/apache/derbyBuild/ java/engine/org/apache/derby/iapi/services/cache/ tools/jar/

Author: kahatlen
Date: Wed May 22 18:30:41 2013
New Revision: 1485322

URL: http://svn.apache.org/r1485322
Log:
DERBY-5840: Clean up compiler warnings introduced by using Java 5 language features

Refactor ClassSizeCatalog to prevent unchecked conversion warnings when
ClassSize creates an instance via reflection and casts the result to
Hashtable<String, int[]>.

Introduce a new abstract ClassSizeCatalog class and rename the generated
class to ClassSizeCatalogImpl, which extends ClassSizeCatalog. ClassSize
can now access the catalog via the abstract class instead of casting it
unchecked to Hashtable<String, int[]>.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSizeCatalog.java   (with props)
Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/build/org/apache/derbyBuild/ClassSizeCrawler.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSize.java
    db/derby/code/trunk/tools/jar/extraDBMSclasses.properties

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1485322&r1=1485321&r2=1485322&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Wed May 22 18:30:41 2013
@@ -972,11 +972,11 @@
       Create the class size catalog, a java file
 
       Note that checking the up-to-date status of the files scanned by
-      ClassSizeCrawler will not always result in the ClassSizeCatalog
+      ClassSizeCrawler will not always result in the ClassSizeCatalogImpl
       being updated properly. We would have to be able to scan the full
       dependency tree. This does prevent recompilation in most cases,
       and requires it in the most obvious. If there is concern that
-      the ClassSizeCatalog may have changed significantly since the
+      the ClassSizeCatalogImpl may have changed significantly since the
       last build, run clobber and rebuild to regenerate it.
   -->
 
@@ -990,7 +990,7 @@
       </classpath>
       <jvmarg value="-DWS=${workspace}"/>
       <jvmarg value="-DclassDir=${out.dir}"/>
-      <jvmarg value="-Dout=${generated.cache.dir}/ClassSizeCatalog.java"/>
+      <jvmarg value="-Dout=${generated.cache.dir}/ClassSizeCatalogImpl.java"/>
       <jvmarg value="-Dprefix.1=org.apache.derby.iapi.types"/>            
       <jvmarg value="-Dprefix.2=org.apache.derby.impl"/>
       <arg value="org.apache.derby.iapi.types.DataValueDescriptor"/>
@@ -1006,8 +1006,8 @@
     </java>
 
     <javac
-      source="1.4"
-      target="1.4"
+      source="1.6"
+      target="1.6"
       bootclasspath="${empty}"
       nowarn="on"
       debug="${debug}"
@@ -1021,7 +1021,7 @@
       <classpath>
         <pathelement path="${compile.classpath}"/>
       </classpath>
-      <include name="${derby.dir}/iapi/services/cache/ClassSizeCatalog.java"/>
+      <include name="${derby.dir}/iapi/services/cache/ClassSizeCatalogImpl.java"/>
     </javac>
 
   </target>
@@ -1039,7 +1039,7 @@
                   targetfile="${out.dir}/org/apache/derby/iapi/store/raw/ContainerKey.class"/>
         <uptodate srcfile="${derby.engine.dir}/iapi/services/cache/SizedCacheable.java"
                   targetfile="${out.dir}/org/apache/derby/iapi/services/cache/SizedCacheable.class"/>
-        <available file="${generated.src.dir}/${derby.dir}/iapi/services/cache/ClassSizeCatalog.java"/>
+        <available file="${generated.src.dir}/${derby.dir}/iapi/services/cache/ClassSizeCatalogImpl.java"/>
       </and>
     </condition>
   </target>

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/ClassSizeCrawler.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/ClassSizeCrawler.java?rev=1485322&r1=1485321&r2=1485322&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/ClassSizeCrawler.java (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/ClassSizeCrawler.java Wed May 22 18:30:41 2013
@@ -27,15 +27,8 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.io.IOException;
-import java.io.FileOutputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.lang.SecurityException;
-import java.lang.ClassNotFoundException;
 import java.util.Hashtable;
 import java.util.Enumeration;
-import java.util.Calendar;
-import java.util.Date;
 
 /**
  * This class implements a program that catalogs the size estimate coefficients of various classes.
@@ -56,7 +49,7 @@ import java.util.Date;
  *<p>
  * The catalog is written as a java source file
  * into <i>out-file</i>, by default
- * <i>work-space</i>/java/org.apache.derby.iapi.services.cache.ClassSizeCatalog.java.
+ * <i>work-space</i>/java/org.apache.derby.iapi.services.cache.ClassSizeCatalogImpl.java.
  *<p>
  * <i>work-space</i> is the directory containing the java and classes directories. $WS in the
  * standard development environment. This property is required.
@@ -178,7 +171,7 @@ public class ClassSizeCrawler
 
         baseDir.setLength( baseDirLength);
         String outputFileName =
-          System.getProperty( "out", WS + "/java/org.apache.derby.iapi.services.cache.ClassSizeCatalog.java");
+          System.getProperty( "out", WS + "/java/org.apache.derby.iapi.services.cache.ClassSizeCatalogImpl.java");
         try
         {
             PrintWriter out = new PrintWriter( new FileWriter( outputFileName));
@@ -200,10 +193,9 @@ public class ClassSizeCrawler
                        "   limitations under the License.\n" +
                        " */\n");
             out.print( "package org.apache.derby.iapi.services.cache;\n" +
-                       "import java.util.Hashtable;\n" +
-                       "class ClassSizeCatalog extends java.util.Hashtable\n" +
+                       "class ClassSizeCatalogImpl extends ClassSizeCatalog\n" +
                        "{\n" +
-                       "    ClassSizeCatalog()\n" +
+                       "    ClassSizeCatalogImpl()\n" +
                        "    {\n");
             for( Enumeration e = classSizes.keys();
                  e.hasMoreElements();)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSize.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSize.java?rev=1485322&r1=1485321&r2=1485322&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSize.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSize.java Wed May 22 18:30:41 2013
@@ -29,7 +29,6 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Arrays;
 
-@SuppressWarnings("unchecked")
 public class ClassSize
 {
     public static final int refSize;
@@ -56,20 +55,8 @@ public class ClassSize
      * Used when the security manager will not let us look at the class fields.
      */
 
-    /* Do not let the compiler see ClassSizeCatalog. Otherwise it will try to
-     * compile it. This may fail because ClassSizeCatalog.java is not created
-     * until everything else has been compiled. Bury ClassSizeCatalog in a string.
-     */
-    private static java.util.Hashtable<String,int[]> catalog;
     static
     {
-        try
-        {
-            catalog = (java.util.Hashtable<String,int[]>)
-              Class.forName( "org.apache.derby.iapi.services.cache.ClassSizeCatalog").newInstance();
-        }
-        catch( Exception e){}
-
         // Figure out whether this is a 32 or 64 bit machine.
         int tmpRefSize = fetchRefSizeFromSystemProperties();
         // If we didn't understand the properties, or were not allowed to read
@@ -215,11 +202,13 @@ public class ClassSize
     {
         if( dummyCatalog)
             return 0;
-        
+
+        ClassSizeCatalog catalog = ClassSizeCatalog.getInstance();
+
         if( SanityManager.DEBUG)
 			SanityManager.ASSERT( catalog != null, "The class size catalog could not be initialized.");
         
-        int[] coeff = (int[]) catalog.get( cls.getName());
+        int[] coeff = catalog.get(cls.getName());
         if( coeff == null)
         {
             try

Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSizeCatalog.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSizeCatalog.java?rev=1485322&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSizeCatalog.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSizeCatalog.java Wed May 22 18:30:41 2013
@@ -0,0 +1,54 @@
+/*
+
+   Derby - Class org.apache.derby.iapi.services.cache.ClassSizeCatalog
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.iapi.services.cache;
+
+import java.util.Hashtable;
+
+/**
+ * Map from class names to size coefficients. The size coefficients can be
+ * used to estimate how much memory an instance of the class takes.
+ * @see ClassSize#getSizeCoefficients(Class)
+ */
+abstract class ClassSizeCatalog extends Hashtable<String, int[]> {
+    /** The singleton instance of this class. */
+    private static final ClassSizeCatalog INSTANCE;
+    static {
+        // Do not let the compiler see ClassSizeCatalogImpl. Otherwise it will
+        // try to compile it. This may fail because ClassSizeCatalogImpl.java
+        // is not created until everything else has been compiled. Bury
+        // ClassSizeCatalogImpl in a string.
+        try {
+            INSTANCE = (ClassSizeCatalog)
+                Class.forName(ClassSizeCatalog.class.getName() + "Impl")
+                    .newInstance();
+        } catch (Exception e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    /**
+     * Get the singleton {@code ClassSizeCatalog} instance.
+     */
+    static ClassSizeCatalog getInstance() {
+        return INSTANCE;
+    }
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/cache/ClassSizeCatalog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/tools/jar/extraDBMSclasses.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/jar/extraDBMSclasses.properties?rev=1485322&r1=1485321&r2=1485322&view=diff
==============================================================================
--- db/derby/code/trunk/tools/jar/extraDBMSclasses.properties (original)
+++ db/derby/code/trunk/tools/jar/extraDBMSclasses.properties Wed May 22 18:30:41 2013
@@ -65,7 +65,7 @@ derby.module.sql.dictictionary.java5.pro
 derby.module.diag.diagnosticable.generic=org.apache.derby.iapi.services.diag.DiagnosticableGeneric
 derby.module.diag.diagnostic.util=org.apache.derby.iapi.services.diag.DiagnosticUtil
 
-derby.module.internalUtil.classsizecatalogimpl=org.apache.derby.iapi.services.cache.ClassSizeCatalog
+derby.module.internalUtil.classsizecatalogimpl=org.apache.derby.iapi.services.cache.ClassSizeCatalogImpl
 
 derby.module.catalog.getprocedurecolumns=org.apache.derby.catalog.GetProcedureColumns
 derby.module.catalog.systemprocedures=org.apache.derby.catalog.SystemProcedures