Skip to content

Commit

Permalink
Fix heuristic for matching nmethod address offset with disassembly. I…
Browse files Browse the repository at this point in the history
…ssue 265
  • Loading branch information
chriswhocodes committed Oct 5, 2017
1 parent 7e542d6 commit 96b15ad
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public void addAssembly(AssemblyMethod asmMethod)
}
else
{
logger.warn("{} Didn't find compilation to attach assembly for nativeAddress {} or entryAddress {}", getFullyQualifiedMemberName(),
logger.warn("{} Didn't find compilation to attach assembly for nativeAddress:{} or entryAddress:{}", getFullyQualifiedMemberName(),
asmMethod.getNativeAddress(), asmMethod.getEntryAddress());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AssemblyMethod parseAssembly(final String assemblyString)
AssemblyMethod method = new AssemblyMethod(architecture);

boolean seenInstructions = false;

for (int i = 0; i < lines.length; i++)
{
if (DEBUG_LOGGING_ASSEMBLY)
Expand Down Expand Up @@ -117,8 +117,12 @@ else if (line.startsWith(S_SEMICOLON))
if (instr == null && lastLine != null && lastLine.trim().startsWith(S_HASH) && !line.startsWith(S_HEX_PREFIX)
&& !line.contains(' ' + S_HEX_PREFIX))
{
// remove last newline
headerBuilder.setLength(headerBuilder.length() - S_NEWLINE.length());

if (headerBuilder.length() > 0)
{
// remove last newline
headerBuilder.setLength(headerBuilder.length() - S_NEWLINE.length());
}

headerBuilder.append(line).append(S_NEWLINE);

Expand Down Expand Up @@ -164,7 +168,7 @@ else if (instr == null && lastLine != null && lastLine.trim().startsWith(S_SEMIC
if (instr != null)
{
seenInstructions = true;

if (replaceLast)
{
currentBlock.replaceLastInstruction(instr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ public class AssemblyProcessor

private Architecture architecture = null;

private int jdkMajorVersion;

public AssemblyProcessor(int jdkMajorVersion)
public AssemblyProcessor()
{
this.jdkMajorVersion = jdkMajorVersion;
}

public List<AssemblyMethod> getAssemblyMethods()
Expand Down Expand Up @@ -109,32 +106,31 @@ public void handleLine(final String inLine)
line = S_HASH + S_SPACE + line;
}

if (jdkMajorVersion >= 9)
if (line.trim().startsWith("total in heap"))
{
if (line.trim().startsWith("total in heap"))
{
nativeAddress = getStartAddress(line);
String possibleNativeAddress = getStartAddress(line);

if (nativeAddress != null)
{
nativeAddress = nativeAddress.trim();
}
}
else if (line.trim().endsWith(" bytes"))
if (possibleNativeAddress != null)
{
entryAddress = getStartAddress(line);

if (entryAddress != null)
{
entryAddress = entryAddress.trim();
}
nativeAddress = possibleNativeAddress.trim();
}
else if (line.trim().endsWith("</print_nmethod>"))
}

if (line.trim().endsWith(" bytes"))
{
String possibleEntryAddress = getStartAddress(line);

if (possibleEntryAddress != null)
{
complete();
entryAddress = possibleEntryAddress.trim();
}
}

if (line.trim().endsWith("</print_nmethod>"))
{
complete();
}

if (line.startsWith(NATIVE_CODE_START) || line.startsWith("Compiled method")
|| line.startsWith("----------------------------------------------------------------------"))
{
Expand All @@ -150,14 +146,11 @@ else if (line.trim().endsWith("</print_nmethod>"))
complete();
}

if (jdkMajorVersion < 9)
{
nativeAddress = StringUtil.getSubstringBetween(line, NATIVE_CODE_START, S_COLON);
String possibleNativeAddress = StringUtil.getSubstringBetween(line, NATIVE_CODE_START, S_COLON);

if (nativeAddress != null)
{
nativeAddress = nativeAddress.trim();
}
if (possibleNativeAddress != null)
{
nativeAddress = possibleNativeAddress.trim();
}
}
else if (assemblyStarted)
Expand Down Expand Up @@ -237,7 +230,7 @@ public void complete()
{
if (DEBUG_LOGGING_ASSEMBLY)
{
logger.debug("Using assembly parser {}", parser.getClass().getName());
logger.debug("Using assembly parser {}", parser.getClass().getName());
}

AssemblyMethod assemblyMethod = parser.parseAssembly(asmString);
Expand All @@ -251,7 +244,7 @@ public void complete()
{
if (DEBUG_LOGGING_ASSEMBLY)
{
logger.error("No assembly parser found for {}", architecture);
logger.error("No assembly parser found for architecture '{}'", architecture);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void parseAssemblyLines()
logger.debug("parseAssemblyLines()");
}

AssemblyProcessor asmProcessor = new AssemblyProcessor(model.getJDKMajorVersion());
AssemblyProcessor asmProcessor = new AssemblyProcessor();

for (NumberedLine numberedLine : splitLog.getAssemblyLines())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,5 @@ public void testParseJDK9Assembly()

List<AssemblyInstruction> instructions4 = block4.getInstructions();
assertEquals(6, instructions4.size());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.adoptopenjdk.jitwatch.test;

import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.LOADED;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_OPEN_ANGLE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -20,6 +21,8 @@
import org.adoptopenjdk.jitwatch.model.assembly.AssemblyInstruction;
import org.adoptopenjdk.jitwatch.model.assembly.AssemblyMethod;
import org.adoptopenjdk.jitwatch.model.assembly.AssemblyProcessor;
import org.adoptopenjdk.jitwatch.model.assembly.AssemblyUtil;
import org.adoptopenjdk.jitwatch.model.assembly.IAssemblyParser;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -78,7 +81,7 @@ public void testSingleAsmMethod() throws ClassNotFoundException
IMetaMember createdMember = UnitTestUtil.setUpTestMember(model, getClass().getName(), "dummyMethod", void.class,
new Class<?>[0], nmethodAddress);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand Down Expand Up @@ -373,7 +376,7 @@ public void testARM7Assembly() throws ClassNotFoundException
IMetaMember member = UnitTestUtil.setUpTestMember(model, getClass().getName(), "add", int.class,
new Class<?>[] { int.class, int.class }, nmethodAddress);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand All @@ -394,9 +397,9 @@ public void testARM7Assembly() throws ClassNotFoundException
assertEquals(4, instructions.size());
}

private AssemblyProcessor performAssemblyParsingOn(int jdkMajorVersion, String[] lines)
private AssemblyProcessor performAssemblyParsingOn(String[] lines)
{
AssemblyProcessor asmProcessor = new AssemblyProcessor(jdkMajorVersion);
AssemblyProcessor asmProcessor = new AssemblyProcessor();

for (String line : lines)
{
Expand Down Expand Up @@ -443,7 +446,7 @@ public void testSingleAsmMethodInterrupted() throws ClassNotFoundException
IMetaMember member = UnitTestUtil.setUpTestMember(model, getClass().getName(), "add", int.class,
new Class<?>[] { int.class, int.class }, nmethodAddress);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand Down Expand Up @@ -513,7 +516,7 @@ public void testTwoMethodsWithOneInterrupted() throws ClassNotFoundException
IMetaMember member2 = UnitTestUtil.setUpTestMember(model, getClass().getName(), "add", int.class,
new Class<?>[] { int.class, int.class }, nmethodAddress2);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand Down Expand Up @@ -599,7 +602,7 @@ public void testRegressionWorksWithJMHIndentedLogs() throws ClassNotFoundExcepti
IMetaMember member = UnitTestUtil.setUpTestMember(model, "java.lang.String", "hashCode", int.class, new Class<?>[0],
nmethodAddress1);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand Down Expand Up @@ -666,7 +669,7 @@ public void testJMHPerfAnnotations() throws ClassNotFoundException
IMetaMember member = UnitTestUtil.setUpTestMember(model, getClass().getName(), "add", int.class,
new Class<?>[] { int.class, int.class }, nmethodAddress1);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand Down Expand Up @@ -726,7 +729,7 @@ public void testCanParseAssemblyAndNMethodUnmangled() throws Exception
IMetaMember member = UnitTestUtil.setUpTestMember(model, getClass().getName(), "dummyMethod2", void.class,
new Class<?>[] { Class.forName("[Ljava.lang.String;") }, nmethodAddress1);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand Down Expand Up @@ -793,7 +796,7 @@ public void testCanParseAssemblyWhenMethodCommentIsMangled() throws ClassNotFoun
IMetaMember member = UnitTestUtil.setUpTestMember(model, getClass().getName(), "add", int.class,
new Class<?>[] { int.class, int.class }, nmethodAddress1);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(8,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

asmProcessor.attachAssemblyToMembers(model.getPackageManager());

Expand Down Expand Up @@ -937,10 +940,7 @@ public void testJDK9NativeAndNonNativeAssembly()
" 0x00007f81ed8e80e8: sub $0x30,%rsp"
};


performAssemblyParsingOn(9 ,lines);

AssemblyProcessor asmProcessor = performAssemblyParsingOn(9,lines);
AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

assertEquals(3, asmProcessor.getAssemblyMethods().size());

Expand All @@ -960,4 +960,46 @@ public void testJDK9NativeAndNonNativeAssembly()
assertEquals("0x00007f81ed8e7f10", method2.getNativeAddress());
assertEquals("0x00007f81ed8e80c0", method2.getEntryAddress());
}

@Test
public void testRegressionGraalIssue265()
{
// <nmethod compile_id='125' compiler='C1' level='1' entry='0x00007fab74150300' size='736' address='0x00007fab74150190' relocation_offset='312'
// insts_offset='368' stub_offset='496' scopes_data_offset='648' scopes_pcs_offset='664' dependencies_offset='728' metadata_offset='640'
// method='java/lang/Integer intValue ()I' bytes='5' count='206' iicount='206' stamp='0.501'/>

String[] lines = new String[] {
"Loaded disassembler from /home/marschall/bin/java/graalvm-0.27/jre/lib/amd64/server/hsdis-amd64.so",
"----------------------------------------------------------------------",
"java/lang/Integer.intValue [0x00007fab74150300, 0x00007fab74150410] 272 bytes",
"[Disassembling for mach=&apos;i386:x86-64&apos;]",
"[Entry Point]",
"[Constants]",
" # {method} {0x00007fab6194cf00} &apos;intValue&apos; &apos;()I&apos; in &apos;java/lang/Integer&apos;",
" # [sp+0x40] (sp of caller)",
" 0x00007fab74150300: mov 0x8(%rsi),%r10d",
" 0x00007fab74150304: shl $0x3,%r10",
" 0x00007fab74150308: cmp %rax,%r10",
" 0x00007fab7415030b: jne 0x00007fab74047b60 ; {runtime_call}",
" 0x00007fab74150311: data16 data16 nopw 0x0(%rax,%rax,1)",
" 0x00007fab7415031c: data16 data16 xchg %ax,%ax",
"[Verified Entry Point]",
" 0x00007fab74150320: mov %eax,-0x14000(%rsp)",
" 0x00007fab74150327: push %rbp",
" 0x00007fab74150328: sub $0x30,%rsp ;*aload_0 {reexecute=0 rethrow=0 return_oop=0}",
" ; - java.lang.Integer::intValue@0 (line 893)",
" 0x00007fab7415032c: mov 0xc(%rsi),%eax ;*getfield value {reexecute=0 rethrow=0 return_oop=0}",
" ; - java.lang.Integer::intValue@1 (line 893)"
};

AssemblyProcessor asmProcessor = performAssemblyParsingOn(lines);

assertEquals(1, asmProcessor.getAssemblyMethods().size());

AssemblyMethod method0 = asmProcessor.getAssemblyMethods().get(0);

assertEquals("# {method} {0x00007fab6194cf00} 'intValue' '()I' in 'java/lang/Integer'", method0.getAssemblyMethodSignature());

assertEquals("0x00007fab74150300", method0.getEntryAddress());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.adoptopenjdk.jitwatch.compilation.CompilationUtil;
import org.adoptopenjdk.jitwatch.model.Compilation;
import org.adoptopenjdk.jitwatch.model.Task;
import org.adoptopenjdk.jitwatch.util.StringUtil;

public class CompilationTableRow
Expand Down Expand Up @@ -83,14 +84,14 @@ public String getCompiler()

if (result == null)
{
if (CompilationUtil.isStaleTask(compilation.getTagTask()))
result = "NA";

Task task = compilation.getTagTask();

if (task != null && CompilationUtil.isStaleTask(task))
{
result = "Stale task";
}
else
{
result = "NA";
}
}

return result;
Expand All @@ -99,7 +100,7 @@ public String getCompiler()
public String getLevel()
{
String result = null;

int level = compilation.getLevel();

if (level == -1)
Expand Down

0 comments on commit 96b15ad

Please sign in to comment.