changeset 1210:61f8242ff23c

7901405: -prof perfasm should recognize kernel symbols
author shade
date Thu, 23 Apr 2015 17:06:21 +0300
parents 172094a4b2c4
children 8a84b4f1822a
files jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java
diffstat 2 files changed, 28 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java	Thu Apr 23 14:40:38 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java	Thu Apr 23 17:06:21 2015 +0300
@@ -26,41 +26,11 @@
 
 import org.openjdk.jmh.infra.BenchmarkParams;
 import org.openjdk.jmh.infra.IterationParams;
-import org.openjdk.jmh.results.AggregationPolicy;
-import org.openjdk.jmh.results.Aggregator;
-import org.openjdk.jmh.results.BenchmarkResult;
-import org.openjdk.jmh.results.BenchmarkResultMetaData;
-import org.openjdk.jmh.results.Result;
-import org.openjdk.jmh.results.ResultRole;
-import org.openjdk.jmh.util.FileUtils;
-import org.openjdk.jmh.util.HashMultimap;
-import org.openjdk.jmh.util.HashMultiset;
-import org.openjdk.jmh.util.Multimap;
-import org.openjdk.jmh.util.Multiset;
-import org.openjdk.jmh.util.Multisets;
-import org.openjdk.jmh.util.Utils;
+import org.openjdk.jmh.results.*;
+import org.openjdk.jmh.util.*;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
+import java.io.*;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -633,7 +603,7 @@
         Long lastAddr = null;
         for (Long addr : addrs) {
             if (addr == 0) {
-                regions.add(new KernelRegion());
+                regions.add(new UnknownRegion());
                 continue;
             }
 
@@ -1053,19 +1023,19 @@
         }
     }
 
-    static class KernelRegion extends Region {
-        KernelRegion() {
-            super("<kernel>", 0L, 0L, Collections.singleton(0L));
+    static class UnknownRegion extends Region {
+        UnknownRegion() {
+            super("<unknown>", 0L, 0L, Collections.singleton(0L));
         }
 
         @Override
         public void printCode(PrintWriter pw, PerfEvents events) {
-            pw.println(" <no assembly is recorded, kernel region>");
+            pw.println(" <no assembly is recorded, unknown region>");
         }
 
         @Override
         public String getType() {
-            return "<kernel>";
+            return "<unknown>";
         }
     }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Apr 23 14:40:38 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Apr 23 17:06:21 2015 +0300
@@ -25,23 +25,14 @@
 package org.openjdk.jmh.profile;
 
 import org.openjdk.jmh.infra.BenchmarkParams;
-import org.openjdk.jmh.util.Deduplicator;
-import org.openjdk.jmh.util.FileUtils;
-import org.openjdk.jmh.util.InputStreamDrainer;
-import org.openjdk.jmh.util.Multiset;
-import org.openjdk.jmh.util.TreeMultiset;
-import org.openjdk.jmh.util.Utils;
+import org.openjdk.jmh.util.*;
 
 import java.io.BufferedReader;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.math.BigInteger;
+import java.util.*;
 
 public class LinuxPerfAsmProfiler extends AbstractPerfAsmProfiler {
 
@@ -185,19 +176,26 @@
                     continue;
                 }
 
+                // Try to parse the positive address lightly first.
+                // If that fails, try to parse the negative address.
+                // If that fails as well, then address is unresolvable.
+                Long addr;
                 try {
-                    Long addr = Long.valueOf(strAddr, 16);
-                    evs.add(addr);
-                    methods.put(addr, dedup.dedup(symbol));
-                    libs.put(addr, dedup.dedup(lib));
+                    addr = Long.valueOf(strAddr, 16);
                 } catch (NumberFormatException e) {
-                    // kernel addresses like "ffffffff810c1b00" overflow signed long,
-                    // record them as dummy address
-                    evs.add(0L);
+                    try {
+                        addr = new BigInteger(strAddr, 16).longValue();
+                    } catch (NumberFormatException e1) {
+                        addr = 0L;
+                    }
                 }
+
+                evs.add(addr);
+                methods.put(addr, dedup.dedup(symbol));
+                libs.put(addr, dedup.dedup(lib));
             }
 
-            methods.put(0L, "<kernel>");
+            methods.put(0L, "<unknown>");
 
             return new PerfEvents(tracedEvents, events, methods, libs);
         } catch (IOException e) {