changeset 16167:1f4955abca9b

mx: add jol command for java object layout introspection
author Andreas Woess <andreas.woess@jku.at>
date Fri, 20 Jun 2014 13:43:47 +0200
parents d69ede72299a
children b63f0428eb59
files mx/mx_graal.py mxtool/mx.py
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mx/mx_graal.py	Mon Jun 23 19:57:45 2014 +0200
+++ b/mx/mx_graal.py	Fri Jun 20 13:43:47 2014 +0200
@@ -1859,6 +1859,20 @@
 def isGraalEnabled(vm):
     return vm != 'original' and not vm.endswith('nograal')
 
+def jol(args):
+    """Java Object Layout"""
+    jolurl = "http://lafo.ssw.uni-linz.ac.at/truffle/jol/jol-internals.jar"
+    joljar = "lib/jol-internals.jar"
+    if not exists(joljar):
+        mx.download(joljar, [jolurl])
+
+    candidates = mx.findclass(args, logToConsole=False, matcher=lambda s, classname: s == classname or classname.endswith('.' + s) or classname.endswith('$' + s))
+    if len(candidates) > 10:
+        print "Found %d candidates. Please be more precise." % (len(candidates))
+        return
+
+    vm(['-javaagent:' + joljar, '-cp', os.pathsep.join([mx.classpath(), joljar]), "org.openjdk.jol.MainObjectInternals"] + candidates)
+
 def site(args):
     """create a website containing javadoc and the project dependency graph"""
 
@@ -2085,7 +2099,8 @@
         'vmfg': [vmfg, '[-options] class [args...]'],
         'deoptalot' : [deoptalot, '[n]'],
         'longtests' : [longtests, ''],
-        'sl' : [sl, '[SL args|@VM options]']
+        'sl' : [sl, '[SL args|@VM options]'],
+        'jol' : [jol, ''],
     }
 
     mx.add_argument('--jacoco', help='instruments com.oracle.* classes using JaCoCo', default='off', choices=['off', 'on', 'append'])
--- a/mxtool/mx.py	Mon Jun 23 19:57:45 2014 +0200
+++ b/mxtool/mx.py	Fri Jun 20 13:43:47 2014 +0200
@@ -4488,7 +4488,7 @@
         return kwargs.pop(0)
     return None
 
-def findclass(args, logToConsole=True):
+def findclass(args, logToConsole=True, matcher=lambda string, classname: string in classname):
     """find all classes matching a given substring"""
     matches = []
     for entry, filename in classpath_walk(includeBootClasspath=True):
@@ -4499,7 +4499,7 @@
                 classname = filename.replace(os.sep, '.')
             classname = classname[:-len('.class')]
             for a in args:
-                if a in classname:
+                if matcher(a, classname):
                     matches.append(classname)
                     if logToConsole:
                         log(classname)