changeset 11198:178625b2dbd5

8028357: Unnecessary allocation in AliasFileParser Reviewed-by: jbachorik
author redestad
date Wed, 31 Dec 2014 15:03:16 +0100
parents edd7a67585a5
children 9acaa4f57b0b
files src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AliasFileParser.java src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/CountedTimerTaskUtils.java src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v1_0/PerfDataBuffer.java src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java
diffstat 4 files changed, 8 insertions(+), 191 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AliasFileParser.java	Tue Dec 30 22:03:23 2014 +0000
+++ b/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AliasFileParser.java	Wed Dec 31 15:03:16 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
  */
 public class AliasFileParser {
     private static final String ALIAS = "alias";
-    private static final boolean DEBUG = false;
+    // 8028357 removed old, inefficient debug logging
 
     // other variables
     private URL inputfile;
@@ -64,21 +64,12 @@
         }
     }
 
-    private void logln(String s) {
-        if (DEBUG) {
-            System.err.println(s);
-        }
-    }
-
     /**
      * method to get the next token as a Token type
      */
     private void nextToken() throws IOException {
         st.nextToken();
         currentToken = new Token(st.ttype, st.sval);
-
-        logln("Read token: type = " + currentToken.ttype
-              + " string = " + currentToken.sval);
     }
 
     /**
@@ -90,8 +81,6 @@
 
         if ((currentToken.ttype == ttype)
                 && (currentToken.sval.compareTo(token) == 0)) {
-            logln("matched type: " + ttype + " and token = "
-                  + currentToken.sval);
             nextToken();
         } else {
             throw new SyntaxException(st.lineno());
@@ -105,7 +94,6 @@
      */
     private void match(int ttype) throws IOException, SyntaxException {
         if (currentToken.ttype == ttype) {
-            logln("matched type: " + ttype + ", token = " + currentToken.sval);
             nextToken();
         } else {
             throw new SyntaxException(st.lineno());
@@ -157,8 +145,6 @@
             } while ((currentToken.ttype != StreamTokenizer.TT_EOF)
                      && (currentToken.sval.compareTo(ALIAS) != 0));
 
-            logln("adding map entry for " + name + " values = " + aliases);
-
             map.put(name, aliases);
         }
     }
--- a/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/CountedTimerTaskUtils.java	Tue Dec 30 22:03:23 2014 +0000
+++ b/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/CountedTimerTaskUtils.java	Wed Dec 31 15:03:16 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,7 @@
  */
 public class CountedTimerTaskUtils {
 
-    private static final boolean DEBUG = false;
+    // 8028357 removed old, inefficient debug logging
 
     /**
      * Reschedule a CountedTimeTask at a different interval. Probably not
@@ -58,14 +58,6 @@
         long lastRun = oldTask.scheduledExecutionTime();
         long expired = now - lastRun;
 
-        if (DEBUG) {
-            System.err.println("computing timer delay: "
-                               + " oldInterval = " + oldInterval
-                               + " newInterval = " + newInterval
-                               + " samples = " + oldTask.executionCount()
-                               + " expired = " + expired);
-        }
-
         /*
          * check if original task ever ran - if not, then lastRun is
          * undefined and we simply set the delay to 0.
@@ -76,12 +68,6 @@
             delay = remainder >= 0 ? remainder : 0;
         }
 
-        if (DEBUG) {
-            System.err.println("rescheduling sampler task: interval = "
-                               + newInterval
-                               + " delay = " + delay);
-        }
-
         timer.schedule(newTask, delay, newInterval);
     }
 }
--- a/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v1_0/PerfDataBuffer.java	Tue Dec 30 22:03:23 2014 +0000
+++ b/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v1_0/PerfDataBuffer.java	Wed Dec 31 15:03:16 2014 +0100
@@ -44,7 +44,8 @@
  */
 public class PerfDataBuffer extends PerfDataBufferImpl {
 
-    private static final boolean DEBUG = false;
+    // 8028357 removed old, inefficient debug logging
+
     private static final int syncWaitMs =
             Integer.getInteger("sun.jvmstat.perdata.syncWaitMs", 5000);
     private static final ArrayList<Monitor> EMPTY_LIST = new ArrayList<Monitor>(0);
@@ -268,18 +269,13 @@
          * loop waiting for the ticks counter to be non zero. This is
          * an indication that the jvm is initialized.
          */
-        log("synchWithTarget: " + lvmid + " ");
         while (ticks.longValue() == 0) {
-            log(".");
-
             try { Thread.sleep(20); } catch (InterruptedException e) { }
 
             if (System.currentTimeMillis() > timeLimit) {
-                lognl("failed: " + lvmid);
                 throw new MonitorException("Could Not Synchronize with target");
             }
         }
-        lognl("success: " + lvmid);
     }
 
     /**
@@ -291,24 +287,18 @@
                       throws MonitorException {
         Monitor monitor = null;
 
-        log("polling for: " + lvmid + "," + name + " ");
-
         pollForEntry = nextEntry;
         while ((monitor = map.get(name)) == null) {
-            log(".");
 
             try { Thread.sleep(20); } catch (InterruptedException e) { }
 
             long t = System.currentTimeMillis();
             if ((t > timeLimit) || (overflow.intValue() > 0)) {
-                lognl("failed: " + lvmid + "," + name);
-                dumpAll(map, lvmid);
                 throw new MonitorException("Could not find expected counter");
             }
 
             getNewMonitors(map);
         }
-        lognl("success: " + lvmid + "," + name);
         return monitor;
     }
 
@@ -481,8 +471,6 @@
 
         // check for the end of the buffer
         if (nextEntry == buffer.limit()) {
-            lognl("getNextMonitorEntry():"
-                  + " nextEntry == buffer.limit(): returning");
             return null;
         }
 
@@ -614,37 +602,4 @@
         nextEntry = entryStart + entryLength;
         return monitor;
     }
-
-    /**
-     * Method to dump debugging information
-     */
-    private void dumpAll(Map<String, Monitor> map, int lvmid) {
-        if (DEBUG) {
-            Set<String> keys = map.keySet();
-
-            System.err.println("Dump for " + lvmid);
-            int j = 0;
-            for (Iterator<String> i = keys.iterator(); i.hasNext(); j++) {
-                Monitor monitor = map.get(i.next());
-                System.err.println(j + "\t" + monitor.getName()
-                                   + "=" + monitor.getValue());
-            }
-            System.err.println("nextEntry = " + nextEntry
-                               + " pollForEntry = " + pollForEntry);
-            System.err.println("Buffer info:");
-            System.err.println("buffer = " + buffer);
-        }
-    }
-
-    private void lognl(String s) {
-        if (DEBUG) {
-            System.err.println(s);
-        }
-    }
-
-    private void log(String s) {
-        if (DEBUG) {
-            System.err.print(s);
-        }
-    }
 }
--- a/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java	Tue Dec 30 22:03:23 2014 +0000
+++ b/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java	Wed Dec 31 15:03:16 2014 +0100
@@ -62,7 +62,8 @@
  */
 public class PerfDataBuffer extends PerfDataBufferImpl {
 
-    private static final boolean DEBUG = false;
+    // 8028357 removed old, inefficient debug logging
+
     private static final int syncWaitMs =
             Integer.getInteger("sun.jvmstat.perdata.syncWaitMs", 5000);
     private static final ArrayList<Monitor> EMPTY_LIST = new ArrayList<>(0);
@@ -264,20 +265,15 @@
         long timeLimit = System.currentTimeMillis() + syncWaitMs;
 
         // loop waiting for the accessible indicater to be non-zero
-        log("synchWithTarget: " + lvmid + " ");
         while (!prologue.isAccessible()) {
 
-            log(".");
-
             // give the target jvm a chance to complete initializatoin
             try { Thread.sleep(20); } catch (InterruptedException e) { }
 
             if (System.currentTimeMillis() > timeLimit) {
-                logln("failed: " + lvmid);
                 throw new MonitorException("Could not synchronize with target");
             }
         }
-        logln("success: " + lvmid);
     }
 
     /**
@@ -306,8 +302,6 @@
 
         // check for end of the buffer
         if (nextEntry == buffer.limit()) {
-            logln("getNextMonitorEntry():"
-                  + " nextEntry == buffer.limit(): returning");
             return null;
         }
 
@@ -346,9 +340,6 @@
         byte varByte = buffer.get();
         int dataOffset = buffer.getInt();
 
-        dump_entry_fixed(entryStart, nameOffset, vectorLength, typeCodeByte,
-                         flags, unitsByte, varByte, dataOffset);
-
         // convert common attributes to their object types
         Units units = Units.toUnits(unitsByte);
         Variability variability = Variability.toVariability(varByte);
@@ -439,8 +430,6 @@
         // set the position to the start of the data item
         buffer.position(entryStart + dataOffset);
 
-        dump_entry_variable(name, buffer, dataSize);
-
         if (vectorLength == 0) {
             // create a scalar Monitor object
             if (typeCode == TypeCode.LONG) {
@@ -514,103 +503,4 @@
         nextEntry = entryStart + entryLength;
         return monitor;
     }
-
-    /**
-     * Method to dump debugging information
-     */
-    private void dumpAll(Map<String, Monitor> map, int lvmid) {
-        if (DEBUG) {
-            Set<String> keys = map.keySet();
-
-            System.err.println("Dump for " + lvmid);
-            int j = 0;
-            for (Iterator<String> i = keys.iterator(); i.hasNext(); j++) {
-                Monitor monitor = map.get(i.next());
-                System.err.println(j + "\t" + monitor.getName()
-                                   + "=" + monitor.getValue());
-            }
-            System.err.println("nextEntry = " + nextEntry);
-            System.err.println("Buffer info:");
-            System.err.println("buffer = " + buffer);
-        }
-    }
-
-    /**
-     * Method to dump the fixed portion of an entry.
-     */
-    private void dump_entry_fixed(int entry_start, int nameOffset,
-                                  int vectorLength, byte typeCodeByte,
-                                  byte flags, byte unitsByte, byte varByte,
-                                  int dataOffset) {
-        if (DEBUG) {
-            System.err.println("Entry at offset: 0x"
-                               + Integer.toHexString(entry_start));
-            System.err.println("\tname_offset = 0x"
-                               + Integer.toHexString(nameOffset));
-            System.err.println("\tvector_length = 0x"
-                               + Integer.toHexString(vectorLength));
-            System.err.println("\tdata_type = 0x"
-                               + Integer.toHexString(typeCodeByte));
-            System.err.println("\tflags = 0x"
-                               + Integer.toHexString(flags));
-            System.err.println("\tdata_units = 0x"
-                               + Integer.toHexString(unitsByte));
-            System.err.println("\tdata_variability = 0x"
-                               + Integer.toHexString(varByte));
-            System.err.println("\tdata_offset = 0x"
-                               + Integer.toHexString(dataOffset));
-        }
-    }
-
-    private void dump_entry_variable(String name, ByteBuffer bb, int size) {
-        if (DEBUG) {
-            char[] toHex = new char[] { '0', '1', '2', '3',
-                                        '4', '5', '6', '7',
-                                        '8', '9', 'a', 'b',
-                                        'c', 'd', 'e', 'f' };
-
-            ByteBuffer data = bb.slice();
-            data.limit(size);
-
-            System.err.println("\tname = " + name);
-            System.err.println("\tdata = ");
-
-            int count=0;
-            while (data.hasRemaining()) {
-                byte b = data.get();
-                byte high = (byte)((b >> 8) & 0x0f);
-                byte low = (byte)(b & 0x0f);
-
-                if (count % 16 == 0) {
-                    System.err.print("\t\t" + Integer.toHexString(count / 16)
-                                     + ": ");
-                }
-
-                System.err.print(String.valueOf(toHex[high])
-                                 + String.valueOf(toHex[low]));
-
-                count++;
-                if (count % 16 == 0) {
-                    System.err.println();
-                } else {
-                    System.err.print(" ");
-                }
-            }
-            if (count % 16 != 0) {
-                System.err.println();
-            }
-        }
-    }
-
-    private void logln(String s) {
-        if (DEBUG) {
-            System.err.println(s);
-        }
-    }
-
-    private void log(String s) {
-        if (DEBUG) {
-            System.err.print(s);
-        }
-    }
 }