changeset 6958:abbe4faaf0c1

added support for dumping an address to symbol map (with -G:+PrintAddressMap) to translate addresses in disassembled output (via new '-m' option to the hcfdis command)
author Doug Simon <doug.simon@oracle.com>
date Fri, 16 Nov 2012 12:39:26 +0100
parents 158e0c9645c5
children 9c71ad0a0652
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/AddressMap.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java mx/commands.py
diffstat 7 files changed, 117 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Thu Nov 15 22:55:44 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Fri Nov 16 12:39:26 2012 +0100
@@ -119,6 +119,9 @@
             printConfig(config);
         }
 
+        AddressMap.log(config.cardtableStartAddress, "CARDTABLE");
+        AddressMap.log(config.cardtableStartAddress, "SAFEPOINT_POLL_PAGE");
+
         target = createTarget();
         assert wordKind == null || wordKind.equals(target.wordKind);
         wordKind = target.wordKind;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Thu Nov 15 22:55:44 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Fri Nov 16 12:39:26 2012 +0100
@@ -527,6 +527,7 @@
             // lost the race - return the existing value instead
             type = (HotSpotResolvedJavaType) unsafe.getObject(javaMirror, offset);
         }
+        AddressMap.log(metaspaceKlass, type.toJava().getName());
         return type;
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/AddressMap.java	Fri Nov 16 12:39:26 2012 +0100
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot.meta;
+
+import java.io.*;
+
+import com.oracle.graal.debug.*;
+import com.oracle.graal.graph.*;
+import com.oracle.graal.phases.*;
+
+/**
+ * Utility for logging an address to symbol mapping to a file.
+ * This is useful when looking at disassembled code.
+ *
+ * @see GraalOptions#PrintAddressMap
+ */
+public class AddressMap {
+
+    private static PrintStream addressMapStream;
+    static {
+        synchronized (AddressMap.class) {
+            if (GraalOptions.PrintAddressMap) {
+                File file = new File("addressMap-" + System.currentTimeMillis() + ".log");
+                try {
+                    addressMapStream = new PrintStream(new FileOutputStream(file), true);
+                } catch (FileNotFoundException e) {
+                    throw new GraalInternalError("Could not open " + file.getAbsolutePath());
+                }
+                TTY.println("Logging {address -> symbol} map to %s", file);
+            }
+        }
+    }
+
+    public static void log(long address, String symbol) {
+        if (addressMapStream != null) {
+            synchronized (addressMapStream) {
+                addressMapStream.println("0x" + Long.toHexString(address) + " " + symbol);
+            }
+        }
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Thu Nov 15 22:55:44 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Fri Nov 16 12:39:26 2012 +0100
@@ -63,6 +63,7 @@
         this.metaspaceMethod = metaspaceMethod;
         this.holder = holder;
         HotSpotGraalRuntime.getInstance().getCompilerToVM().initializeMethod(metaspaceMethod, this);
+        AddressMap.log(metaspaceMethod, MetaUtil.format("%H.%n(%P):%R", this));
     }
 
     @Override
@@ -202,6 +203,7 @@
             long metaspaceMethodData = unsafe.getLong(null, metaspaceMethod + HotSpotGraalRuntime.getInstance().getConfig().methodDataOffset);
             if (metaspaceMethodData != 0) {
                 methodData = new HotSpotMethodData(metaspaceMethodData);
+                AddressMap.log(metaspaceMethodData, MetaUtil.format("MethodData{%H.%n(%P):%R}", this));
             }
         }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java	Thu Nov 15 22:55:44 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java	Fri Nov 16 12:39:26 2012 +0100
@@ -419,4 +419,12 @@
     public long prototypeMarkWord() {
         return HotSpotGraalRuntime.getInstance().getCompilerToVM().getPrototypeMarkWord(this);
     }
+
+    public long address() {
+        return metaspaceKlass;
+    }
+
+    public String symbol() {
+        return javaMirror.getName();
+    }
 }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java	Thu Nov 15 22:55:44 2012 +0100
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java	Fri Nov 16 12:39:26 2012 +0100
@@ -141,6 +141,7 @@
     public static int     PrintBinaryGraphPort               = 4445;
 
     // Other printing settings
+    public static boolean PrintAddressMap                    = ____;
     public static boolean PrintQueue                         = ____;
     public static boolean PrintCompilation                   = ____;
     public static boolean PrintProfilingInformation          = ____;
--- a/mx/commands.py	Thu Nov 15 22:55:44 2012 +0100
+++ b/mx/commands.py	Fri Nov 16 12:39:26 2012 +0100
@@ -26,7 +26,7 @@
 #
 # ----------------------------------------------------------------------------------------------------
 
-import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing
+import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing, types
 from os.path import join, exists, dirname, basename
 from argparse import ArgumentParser, REMAINDER
 from threading import Thread
@@ -1011,10 +1011,49 @@
 
     Run a tool over the input files to convert all embedded HexCodeFiles
     to a disassembled format."""
+
+    parser = ArgumentParser(prog='mx hcfdis');
+    parser.add_argument('-m', '--map', help='address to symbol map applied to disassembler output')
+    parser.add_argument('files', nargs=REMAINDER, metavar='files...')
+
+    args = parser.parse_args(args)
+    
     path = join(_graal_home, 'lib', 'hcfdis-1.jar')
     if not exists(path):
         mx.download(path, ['http://lafo.ssw.uni-linz.ac.at/hcfdis-1.jar'])
-    mx.run_java(['-jar', path] + args)
+    mx.run_java(['-jar', path] + args.files)
+    
+    if args.map is not None:
+        addressRE = re.compile(r'0[xX]([A-Fa-f0-9]+)')
+        with open(args.map) as fp:
+            lines = fp.read().splitlines()
+        symbols = dict()
+        for l in lines:
+            addressAndSymbol = l.split(' ', 1)
+            if len(addressAndSymbol) == 2:
+                address, symbol = addressAndSymbol;
+                if address.startswith('0x'): 
+                    address = long(address, 16)
+                    symbols[address] = symbol
+        for f in args.files:
+            with open(f) as fp:
+                lines = fp.read().splitlines()
+            updated = False
+            for i in range(0, len(lines)):
+                l = lines[i]
+                for m in addressRE.finditer(l):
+                    sval = m.group(0)
+                    val = long(sval, 16)
+                    sym = symbols.get(val)
+                    if sym:
+                        l = l.replace(sval, sym)
+                        updated = True
+                        lines[i] = l
+            if updated:
+                mx.log('updating ' + f)
+                with open('new_' + f, "w") as fp:
+                    for l in lines:
+                        print >> fp, l
 
 def jacocoreport(args):
     """create a JaCoCo coverage report