From e2408520caa4ecf764ec0e8ca53d94fcd40dc242 Mon Sep 17 00:00:00 2001 From: Chris Newland Date: Wed, 12 Aug 2015 21:01:29 +0100 Subject: [PATCH] Uncommon trap detection --- .../jitwatch/chain/CompileChainWalker.java | 9 +- .../jitwatch/core/JITWatchConstants.java | 3 + .../jitwatch/loader/BytecodeLoader.java | 16 +- .../jitwatch/model/AbstractMetaMember.java | 40 + .../jitwatch/model/IMetaMember.java | 6 + .../jitwatch/model/MetaClass.java | 5 + .../model/bytecode/BCAnnotationType.java | 2 +- .../bytecode/BytecodeAnnotationBuilder.java | 66 +- .../model/bytecode/MemberBytecode.java | 9 +- .../jitwatch/ui/triview/TriView.java | 11 +- .../ui/triview/bytecode/ViewerBytecode.java | 28 +- .../jitwatch/util/InlineUtil.java | 17 +- .../jitwatch/util/UserInterfaceUtil.java | 2 + .../test/TestBytecodeAnnotationBuilder.java | 1180 ++++++----------- .../jitwatch/test/TestBytecodeLoader.java | 231 ++-- .../jitwatch/test/UnitTestUtil.java | 7 +- 16 files changed, 701 insertions(+), 931 deletions(-) diff --git a/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java b/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java index 27d2e168..0136b5f5 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java @@ -84,6 +84,8 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction { String tagName = child.getName(); Map tagAttrs = child.getAttrs(); + + //System.out.println("CCW: " + child.toString(false)); switch (tagName) { @@ -113,6 +115,8 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction case TAG_INLINE_FAIL: { + //System.out.println("INLINE FAIL!"); + inlined = false; // reset IMetaMember childCall = ParseUtil.lookupMember(methodID, parseDictionary, model); @@ -123,7 +127,7 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction parentNode.addChild(childNode); String reason = tagAttrs.get(ATTR_REASON); - String annotationText = InlineUtil.buildInlineAnnotationText(false, reason, callAttrs, methodAttrs); + String annotationText = InlineUtil.buildInlineAnnotationText(false, reason, callAttrs, methodAttrs, parseDictionary); childNode.setInlined(inlined, annotationText); } else @@ -136,9 +140,10 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction break; case TAG_INLINE_SUCCESS: + //System.out.println("INLINE SUCCESS!"); inlined = true; String reason = tagAttrs.get(ATTR_REASON); - inlineReason = InlineUtil.buildInlineAnnotationText(true, reason, callAttrs, methodAttrs); + inlineReason = InlineUtil.buildInlineAnnotationText(true, reason, callAttrs, methodAttrs, parseDictionary); break; case TAG_PARSE: // call depth diff --git a/src/main/java/org/adoptopenjdk/jitwatch/core/JITWatchConstants.java b/src/main/java/org/adoptopenjdk/jitwatch/core/JITWatchConstants.java index acfa922a..3e91e449 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/core/JITWatchConstants.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/core/JITWatchConstants.java @@ -93,6 +93,7 @@ private JITWatchConstants() public static final String TAG_ELIMINATE_ALLOCATION = "eliminate_allocation"; public static final String TAG_ELIMINATE_LOCK = "eliminate_lock"; public static final String TAG_JVMS = "jvms"; + public static final String TAG_UNCOMMON_TRAP = "uncommon_trap"; public static final String TAG_COMMAND = "command"; @@ -129,6 +130,8 @@ private JITWatchConstants() public static final String ATTR_BRANCH_PROB = "prob"; public static final String ATTR_COUNT = "count"; public static final String ATTR_PROF_FACTOR = "prof_factor"; + public static final String ATTR_ACTION = "action"; + public static final String ATTR_COMMENT = "comment"; public static final String ALWAYS = "always"; public static final String NEVER = "never"; diff --git a/src/main/java/org/adoptopenjdk/jitwatch/loader/BytecodeLoader.java b/src/main/java/org/adoptopenjdk/jitwatch/loader/BytecodeLoader.java index 90d32c04..b0d8b911 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/loader/BytecodeLoader.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/loader/BytecodeLoader.java @@ -139,9 +139,11 @@ private static ClassBC parsedByteCodeFrom(String fqClassName, String byteCodeStr if (byteCodeString != null) { + String[] bytecodeLines = byteCodeString.split(S_NEWLINE); + try { - result = parse(fqClassName, byteCodeString); + result = parse(fqClassName, bytecodeLines); } catch (Exception ex) { @@ -203,12 +205,10 @@ private static String[] buildClassPathFromClassLocations(Collection clas } // TODO refactor this class - better stateful than all statics - public static ClassBC parse(String fqClassName, String bytecode) + public static ClassBC parse(String fqClassName, String[] bytecodeLines) { ClassBC classBytecode = new ClassBC(fqClassName); - String[] lines = bytecode.split(S_NEWLINE); - int pos = 0; StringBuilder builder = new StringBuilder(); @@ -219,9 +219,9 @@ public static ClassBC parse(String fqClassName, String bytecode) MemberBytecode memberBytecode = null; - while (pos < lines.length) + while (pos < bytecodeLines.length) { - String line = lines[pos].trim(); + String line = bytecodeLines[pos].trim(); if (DEBUG_LOGGING_BYTECODE) { @@ -237,9 +237,9 @@ public static ClassBC parse(String fqClassName, String bytecode) section = changeSection(nextSection); pos++; - if (pos < lines.length) + if (pos < bytecodeLines.length) { - line = lines[pos].trim(); + line = bytecodeLines[pos].trim(); } } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/AbstractMetaMember.java b/src/main/java/org/adoptopenjdk/jitwatch/model/AbstractMetaMember.java index eebd12af..ba57df28 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/AbstractMetaMember.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/AbstractMetaMember.java @@ -41,6 +41,9 @@ import java.util.concurrent.ConcurrentHashMap; import org.adoptopenjdk.jitwatch.model.assembly.AssemblyMethod; +import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeInstruction; +import org.adoptopenjdk.jitwatch.model.bytecode.ClassBC; +import org.adoptopenjdk.jitwatch.model.bytecode.MemberBytecode; import org.adoptopenjdk.jitwatch.util.ParseUtil; import org.adoptopenjdk.jitwatch.util.StringUtil; import org.slf4j.Logger; @@ -244,6 +247,43 @@ public List getQueuedAttributes() return attrList; } + + @Override + public MemberBytecode getMemberBytecode() + { + MemberBytecode result = null; + + if (metaClass != null) + { + ClassBC classBytecode = metaClass.getClassBytecode(); + + if (classBytecode != null) + { + result = classBytecode.getMemberBytecode(this); + } + } + + return result; + } + + public List getInstructions() + { + List result = null; + + MemberBytecode memberBytecode = getMemberBytecode(); + + if (memberBytecode != null) + { + result = memberBytecode.getInstructions(); + } + else + { + result = new ArrayList<>(); + } + + return result; + } + @Override public MetaClass getMetaClass() diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/IMetaMember.java b/src/main/java/org/adoptopenjdk/jitwatch/model/IMetaMember.java index ab2f4e3d..64effae9 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/IMetaMember.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/IMetaMember.java @@ -9,12 +9,18 @@ import java.util.Map; import org.adoptopenjdk.jitwatch.model.assembly.AssemblyMethod; +import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeInstruction; +import org.adoptopenjdk.jitwatch.model.bytecode.MemberBytecode; public interface IMetaMember { List getQueuedAttributes(); MetaClass getMetaClass(); + + MemberBytecode getMemberBytecode(); + + List getInstructions(); void addJournalEntry(Tag entry); Journal getJournal(); diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/MetaClass.java b/src/main/java/org/adoptopenjdk/jitwatch/model/MetaClass.java index 475d1db9..2183a797 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/MetaClass.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/MetaClass.java @@ -115,6 +115,11 @@ public ClassBC getClassBytecode(IReadOnlyJITDataModel model, List classL return classBytecode; } + + public ClassBC getClassBytecode() + { + return classBytecode; + } private void loadInnerClasses(List innerClassNames, IReadOnlyJITDataModel model, List classLocations) { diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BCAnnotationType.java b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BCAnnotationType.java index 406cc880..119f96bc 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BCAnnotationType.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BCAnnotationType.java @@ -2,5 +2,5 @@ public enum BCAnnotationType { - BRANCH, INLINE_SUCCESS, INLINE_FAIL, ELIMINATED_ALLOCATION, LOCK_ELISION, LOCK_COARSEN, INTRINSIC_USED; + BRANCH, INLINE_SUCCESS, INLINE_FAIL, ELIMINATED_ALLOCATION, LOCK_ELISION, LOCK_COARSEN, INTRINSIC_USED, UNCOMMON_TRAP; } \ No newline at end of file diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotationBuilder.java b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotationBuilder.java index 6ac279d9..248e6459 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotationBuilder.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotationBuilder.java @@ -32,6 +32,7 @@ import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_JVMS; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_METHOD; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_PARSE; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_UNCOMMON_TRAP; import java.util.HashMap; import java.util.List; @@ -58,17 +59,14 @@ public class BytecodeAnnotationBuilder implements IJournalVisitable private IMetaMember member; - private List instructions; - private IReadOnlyJITDataModel model; private BytecodeAnnotations bcAnnotations = new BytecodeAnnotations(); - public BytecodeAnnotations buildBytecodeAnnotations(final IMetaMember member, final List instructions, - IReadOnlyJITDataModel model) throws AnnotationException + public BytecodeAnnotations buildBytecodeAnnotations(final IMetaMember member, IReadOnlyJITDataModel model) + throws AnnotationException { this.member = member; - this.instructions = instructions; this.model = model; bcAnnotations.clear(); @@ -120,7 +118,6 @@ public void visitTag(Tag tag, IParseDictionary parseDictionary) throws LogParseE case TAG_ELIMINATE_LOCK: visitTagEliminateLock(tag, parseDictionary); break; - } } @@ -134,7 +131,7 @@ private void visitTagParse(Tag tag, IParseDictionary parseDictionary) throws Log { final CompilerName compilerName = JournalUtil.getCompilerNameForLastTask(member.getJournal()); - buildParseTagAnnotations(tag, bcAnnotations, instructions, compilerName); + buildParseTagAnnotations(tag, bcAnnotations, compilerName, parseDictionary); } catch (Exception e) { @@ -144,7 +141,7 @@ private void visitTagParse(Tag tag, IParseDictionary parseDictionary) throws Log } private void visitTagEliminateAllocation(Tag tag, IParseDictionary parseDictionary) - { + { List childrenJVMS = tag.getNamedChildren(TAG_JVMS); for (Tag tagJVMS : childrenJVMS) @@ -157,7 +154,7 @@ private void visitTagEliminateAllocation(Tag tag, IParseDictionary parseDictiona { int bciValue = Integer.parseInt(bci); - BytecodeInstruction instr = getInstructionAtIndex(instructions, bciValue); + BytecodeInstruction instr = getInstructionAtIndex(bciValue); if (instr != null) { @@ -179,8 +176,8 @@ private void visitTagEliminateAllocation(Tag tag, IParseDictionary parseDictiona } } - bcAnnotations.addAnnotation(bciValue, - new LineAnnotation(builder.toString(), BCAnnotationType.ELIMINATED_ALLOCATION)); + bcAnnotations.addAnnotation(bciValue, new LineAnnotation(builder.toString(), + BCAnnotationType.ELIMINATED_ALLOCATION)); if (instr.getOpcode() == Opcode.NEW) { @@ -256,10 +253,10 @@ private void visitTagEliminateLock(Tag tag, IParseDictionary parseDictionary) if (bciValue != -1) { - bcAnnotations.addAnnotation(bciValue, - new LineAnnotation(builder.toString().trim(), BCAnnotationType.LOCK_ELISION)); + bcAnnotations.addAnnotation(bciValue, new LineAnnotation(builder.toString().trim(), + BCAnnotationType.LOCK_ELISION)); - BytecodeInstruction instr = getInstructionAtIndex(instructions, bciValue); + BytecodeInstruction instr = getInstructionAtIndex(bciValue); if (instr != null && instr.isLock()) { @@ -276,8 +273,18 @@ private void visitTagEliminateLock(Tag tag, IParseDictionary parseDictionary) } } - private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotations, List instructions, - CompilerName compilerName) throws AnnotationException + private void visitTagUncommonTrap(Tag tag) + { + UncommonTrap trap = UncommonTrap.parse(tag); + + if (trap != null) + { + bcAnnotations.addAnnotation(trap.getBCI(), new LineAnnotation(trap.toString(), BCAnnotationType.UNCOMMON_TRAP)); + } + } + + private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotations, CompilerName compilerName, IParseDictionary parseDictionary) + throws AnnotationException { if (DEBUG_LOGGING) { @@ -339,7 +346,7 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati logger.debug("BC Tag {} {}", currentBytecode, code); } - currentInstruction = getInstructionAtIndex(instructions, currentBytecode); + currentInstruction = getInstructionAtIndex(currentBytecode); if (DEBUG_LOGGING_BYTECODE) { @@ -393,7 +400,7 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati } String reason = tagAttrs.get(ATTR_REASON); - String annotationText = InlineUtil.buildInlineAnnotationText(true, reason, callAttrs, methodAttrs); + String annotationText = InlineUtil.buildInlineAnnotationText(true, reason, callAttrs, methodAttrs, parseDictionary); bcAnnotations.addAnnotation(currentBytecode, new LineAnnotation(annotationText, BCAnnotationType.INLINE_SUCCESS)); @@ -411,7 +418,7 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati } String reason = tagAttrs.get(ATTR_REASON); - String annotationText = InlineUtil.buildInlineAnnotationText(false, reason, callAttrs, methodAttrs); + String annotationText = InlineUtil.buildInlineAnnotationText(false, reason, callAttrs, methodAttrs, parseDictionary); bcAnnotations.addAnnotation(currentBytecode, new LineAnnotation(annotationText, BCAnnotationType.INLINE_FAIL)); } @@ -425,7 +432,7 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati { if (!sanityCheckBranch(currentInstruction)) { - throw new AnnotationException("Expected a branch instruction (in BRANCH)", currentBytecode, + throw new AnnotationException("Expected a branch instruction (BRANCH)", currentBytecode, currentInstruction); } @@ -442,24 +449,23 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati { if (!sanityCheckIntrinsic(currentInstruction)) { - for (BytecodeInstruction ins : instructions) - { - logger.info("! instruction: {}", ins); - } - - throw new AnnotationException("Expected an invoke instruction (IN INTRINSIC)", currentBytecode, + throw new AnnotationException("Expected an invoke instruction (INTRINSIC)", currentBytecode, currentInstruction); } StringBuilder reason = new StringBuilder(); reason.append("Intrinsic: ").append(tagAttrs.get(ATTR_ID)); - bcAnnotations.addAnnotation(currentBytecode, - new LineAnnotation(reason.toString(), BCAnnotationType.INTRINSIC_USED)); + bcAnnotations.addAnnotation(currentBytecode, new LineAnnotation(reason.toString(), + BCAnnotationType.INTRINSIC_USED)); } } break; + case TAG_UNCOMMON_TRAP: + visitTagUncommonTrap(child); + break; + default: break; } @@ -527,11 +533,11 @@ public static boolean sanityCheckBranch(BytecodeInstruction instr) return sane; } - private BytecodeInstruction getInstructionAtIndex(List instructions, int index) + private BytecodeInstruction getInstructionAtIndex(int index) { BytecodeInstruction found = null; - for (BytecodeInstruction instruction : instructions) + for (BytecodeInstruction instruction : member.getInstructions()) { if (instruction.getOffset() == index) { diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/MemberBytecode.java b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/MemberBytecode.java index 2fe9cc1d..bf3ca2f9 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/MemberBytecode.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/MemberBytecode.java @@ -26,6 +26,8 @@ public class MemberBytecode private ClassBC classBytecode; private static final Logger logger = LoggerFactory.getLogger(MemberBytecode.class); + + private BytecodeAnnotations bytecodeAnnotations = new BytecodeAnnotations(); public MemberBytecode(ClassBC classBytecode, MemberSignatureParts msp) { @@ -38,6 +40,11 @@ public ClassBC getClassBytecode() { return classBytecode; } + + public BytecodeAnnotations getBytecodeAnnotations() + { + return bytecodeAnnotations; + } public MemberSignatureParts getMemberSignatureParts() { @@ -67,7 +74,7 @@ public BytecodeInstruction getBytecodeAtOffset(int bci) { if (DEBUG_LOGGING_BYTECODE) { - // logger.debug("checking: {}", instruction); + logger.debug("checking: {}", instruction); } if (instruction.getOffset() == bci) diff --git a/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/TriView.java b/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/TriView.java index 09d9efe6..c84b1930 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/TriView.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/TriView.java @@ -510,7 +510,7 @@ public void setMember(IMetaMember member, boolean force, boolean jumpToSource) List allClassLocations = config.getAllClassLocations(); - ClassBC classBytecode = loadBytecodeForCurrentMember(allClassLocations); + ClassBC classBytecode = currentMember.getMetaClass().getClassBytecode(model, allClassLocations); if (!sameClass) { @@ -543,7 +543,7 @@ public void setMember(IMetaMember member, boolean force, boolean jumpToSource) updateStatusBarIfCompiled(statusBarBuilder); applyActionsIfOffsetMismatchDetected(statusBarBuilder); - viewerBytecode.setContent(currentMember, classBytecode, allClassLocations); + viewerBytecode.setContent(currentMember); setAssemblyPaneContent(); @@ -626,13 +626,6 @@ private void updateStatusBarIfCompiled(StringBuilder statusBarBuilder) } } - private ClassBC loadBytecodeForCurrentMember(List classLocations) - { - ClassBC classBytecode = currentMember.getMetaClass().getClassBytecode(model, classLocations); - - return classBytecode; - } - private void updateStatusBarWithClassInformation(ClassBC classBytecode, StringBuilder statusBarBuilder) { if (classBytecode != null) diff --git a/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/bytecode/ViewerBytecode.java b/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/bytecode/ViewerBytecode.java index 0579540b..ac9a9497 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/bytecode/ViewerBytecode.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/bytecode/ViewerBytecode.java @@ -105,9 +105,12 @@ public void highlightBytecodeOffset(int bci) highlightLine(index); } - public void setContent(final IMetaMember member, final ClassBC metaClassBytecode, final List classLocations) + public void setContent(final IMetaMember member) { offsetMismatchDetected = false; + instructions.clear(); + + ClassBC metaClassBytecode = member.getMetaClass().getClassBytecode(); if (metaClassBytecode != null) { @@ -130,7 +133,7 @@ public void setContent(final IMetaMember member, final ClassBC metaClassBytecode { try { - bcAnnotations = new BytecodeAnnotationBuilder().buildBytecodeAnnotations(member, instructions, model); + bcAnnotations = new BytecodeAnnotationBuilder().buildBytecodeAnnotations(member, model); } catch (AnnotationException annoEx) { @@ -193,17 +196,25 @@ private BytecodeLabel createLabel(final BytecodeInstruction instruction, int max if (annotationList != null && annotationList.size() > 0) { - BCAnnotationType type = annotationList.get(0).getType(); - - Color colour = UserInterfaceUtil.getColourForBytecodeAnnotation(type); + BCAnnotationType lastAnnotationType = annotationList.get(0).getType(); + + Color colour = UserInterfaceUtil.getColourForBytecodeAnnotation(lastAnnotationType); unhighlightedStyle = STYLE_UNHIGHLIGHTED + "-fx-text-fill:" + toRGBCode(colour) + C_SEMICOLON; instructionToolTipBuilder = new StringBuilder(); - + for (LineAnnotation annotation : annotationList) { - instructionToolTipBuilder.append(annotation.getAnnotation()).append(S_NEWLINE).append(S_NEWLINE); + if (annotation.getType() != lastAnnotationType + || lastAnnotationType != BCAnnotationType.UNCOMMON_TRAP) + { + instructionToolTipBuilder.append(S_NEWLINE); + } + + lastAnnotationType = annotation.getType(); + + instructionToolTipBuilder.append(annotation.getAnnotation()).append(S_NEWLINE); } } } @@ -214,9 +225,10 @@ private BytecodeLabel createLabel(final BytecodeInstruction instruction, int max { lblLine.getStyleClass().add("eliminated-allocation"); } - + if (instruction.isInvoke()) { + instructionToolTipBuilder.append(S_NEWLINE); instructionToolTipBuilder.append("Ctrl-click to inspect this method\nBackspace to return"); } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/util/InlineUtil.java b/src/main/java/org/adoptopenjdk/jitwatch/util/InlineUtil.java index a2a96a34..031290e9 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/util/InlineUtil.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/util/InlineUtil.java @@ -5,9 +5,17 @@ */ package org.adoptopenjdk.jitwatch.util; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_BYTES; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COUNT; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_HOLDER; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_IICOUNT; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_NAME; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_PROF_FACTOR; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE; + import java.util.Map; -import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.*; +import org.adoptopenjdk.jitwatch.model.IParseDictionary; public final class InlineUtil { @@ -16,10 +24,15 @@ private InlineUtil() } public static String buildInlineAnnotationText(boolean inlined, String reason, Map callAttrs, - Map methodAttrs) + Map methodAttrs, IParseDictionary parseDictionary) { StringBuilder builder = new StringBuilder(); + String holder = methodAttrs.get(ATTR_HOLDER); + String methodName = methodAttrs.get(ATTR_NAME); + + builder.append("Class: ").append(ParseUtil.lookupType(holder, parseDictionary)).append(S_NEWLINE); + builder.append("Method: ").append(methodName).append(S_NEWLINE); builder.append("Inlined: "); if (inlined) diff --git a/src/main/java/org/adoptopenjdk/jitwatch/util/UserInterfaceUtil.java b/src/main/java/org/adoptopenjdk/jitwatch/util/UserInterfaceUtil.java index dfdd84bf..a7375b59 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/util/UserInterfaceUtil.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/util/UserInterfaceUtil.java @@ -79,6 +79,8 @@ public static Color getColourForBytecodeAnnotation(BCAnnotationType type) return Color.RED; case INLINE_SUCCESS: return Color.GREEN; + case UNCOMMON_TRAP: + return Color.PURPLE; default: return Color.BLACK; } diff --git a/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeAnnotationBuilder.java b/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeAnnotationBuilder.java index 137a7106..bf2cb3cf 100644 --- a/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeAnnotationBuilder.java +++ b/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeAnnotationBuilder.java @@ -90,7 +90,7 @@ public void testSanityCheckBranchPass() @Test public void testJava7NonTieredLeaf() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -239,54 +239,31 @@ public void testJava7NonTieredLeaf() "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: goto 35 ", - "8: aload_0 ", - "9: lload_3 ", - "10: invokespecial #225 // Method leaf1:(J)J", - "13: lstore_3 ", - "14: aload_0 ", - "15: lload_3 ", - "16: invokespecial #228 // Method leaf2:(J)J", - "19: lstore_3 ", - "20: aload_0 ", - "21: lload_3 ", - "22: invokespecial #231 // Method leaf3:(J)J", - "25: lstore_3 ", - "26: aload_0 ", - "27: lload_3 ", - "28: invokespecial #234 // Method leaf4:(J)J", - "31: lstore_3 ", - "32: iinc 5, 1 ", - "35: iload 5 ", - "37: i2l ", - "38: lload_1 ", - "39: lcmp ", - "40: iflt 8 ", - "43: getstatic #52 // Field java/lang/System.out:Ljava/io/PrintStream;", - "46: new #58 // class java/lang/StringBuilder", - "49: dup ", + "" }; + + String[] bytecodeLines = new String[] { "0: lconst_0 ", "1: lstore_3 ", "2: iconst_0 ", + "3: istore 5 ", "5: goto 35 ", "8: aload_0 ", "9: lload_3 ", + "10: invokespecial #225 // Method leaf1:(J)J", "13: lstore_3 ", "14: aload_0 ", + "15: lload_3 ", "16: invokespecial #228 // Method leaf2:(J)J", "19: lstore_3 ", + "20: aload_0 ", "21: lload_3 ", "22: invokespecial #231 // Method leaf3:(J)J", + "25: lstore_3 ", "26: aload_0 ", "27: lload_3 ", + "28: invokespecial #234 // Method leaf4:(J)J", "31: lstore_3 ", "32: iinc 5, 1 ", + "35: iload 5 ", "37: i2l ", "38: lload_1 ", "39: lcmp ", + "40: iflt 8 ", "43: getstatic #52 // Field java/lang/System.out:Ljava/io/PrintStream;", + "46: new #58 // class java/lang/StringBuilder", "49: dup ", "50: ldc #237 // String testLeaf:", "52: invokespecial #62 // Method java/lang/StringBuilder.\"\":(Ljava/lang/String;)V", "55: lload_3 ", "56: invokevirtual #65 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", "59: invokevirtual #69 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "62: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "65: return " - }; + "62: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", "65: return " }; - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", new Class[]{long.class}); + IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", + new Class[] { long.class }); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C2, logLines, bytecodeLines); - assertEquals(9, result.annotatedLineCount()); + assertEquals(10, result.annotatedLineCount()); checkLine(result, 10, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); checkLine(result, 16, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); @@ -297,12 +274,14 @@ public void testJava7NonTieredLeaf() checkLine(result, 56, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); checkLine(result, 59, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); checkLine(result, 62, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); + checkLine(result, 62, "null_check", BCAnnotationType.UNCOMMON_TRAP); + } @Test public void testJava7NonTieredChain() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -478,60 +457,44 @@ public void testJava7NonTieredChain() "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: goto 23 ", - "8: aload_0 ", - "9: lload_3 ", - "10: invokespecial #190 // Method chainA1:(J)J", - "13: lstore_3 ", - "14: aload_0 ", - "15: lload_3 ", - "16: invokespecial #194 // Method chainB1:(J)J", - "19: lstore_3 ", - "20: iinc 5, 1 ", - "23: iload 5 ", - "25: i2l ", - "26: lload_1 ", - "27: lcmp ", - "28: iflt 8 ", + "" }; + + String[] bytecodeLines = new String[] { "0: lconst_0 ", "1: lstore_3 ", "2: iconst_0 ", + "3: istore 5 ", "5: goto 23 ", "8: aload_0 ", "9: lload_3 ", + "10: invokespecial #190 // Method chainA1:(J)J", "13: lstore_3 ", "14: aload_0 ", + "15: lload_3 ", "16: invokespecial #194 // Method chainB1:(J)J", "19: lstore_3 ", + "20: iinc 5, 1 ", "23: iload 5 ", "25: i2l ", "26: lload_1 ", + "27: lcmp ", "28: iflt 8 ", "31: getstatic #52 // Field java/lang/System.out:Ljava/io/PrintStream;", - "34: new #58 // class java/lang/StringBuilder", - "37: dup ", + "34: new #58 // class java/lang/StringBuilder", "37: dup ", "38: ldc #197 // String testCallChain:", "40: invokespecial #62 // Method java/lang/StringBuilder.\"\":(Ljava/lang/String;)V", "43: lload_3 ", "44: invokevirtual #65 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", "47: invokevirtual #69 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "50: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "53: return " - }; + "50: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", "53: return " }; - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain", new Class[]{long.class}); + IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain", + new Class[] { long.class }); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C2, logLines, bytecodeLines); - assertEquals(7, result.annotatedLineCount()); - + assertEquals(8, result.annotatedLineCount()); + checkLine(result, 10, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); checkLine(result, 16, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); checkLine(result, 28, "always", BCAnnotationType.BRANCH); checkLine(result, 40, "not reached", BCAnnotationType.INLINE_FAIL); checkLine(result, 44, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); checkLine(result, 47, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); + checkLine(result, 47, "null_check", BCAnnotationType.UNCOMMON_TRAP); checkLine(result, 50, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); } @Test public void testJava7TieredLeaf() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -647,50 +610,27 @@ public void testJava7TieredLeaf() "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: goto 35 ", - "8: aload_0 ", - "9: lload_3 ", - "10: invokespecial #225 // Method leaf1:(J)J", - "13: lstore_3 ", - "14: aload_0 ", - "15: lload_3 ", - "16: invokespecial #228 // Method leaf2:(J)J", - "19: lstore_3 ", - "20: aload_0 ", - "21: lload_3 ", - "22: invokespecial #231 // Method leaf3:(J)J", - "25: lstore_3 ", - "26: aload_0 ", - "27: lload_3 ", - "28: invokespecial #234 // Method leaf4:(J)J", - "31: lstore_3 ", - "32: iinc 5, 1 ", - "35: iload 5 ", - "37: i2l ", - "38: lload_1 ", - "39: lcmp ", - "40: iflt 8 ", - "43: getstatic #52 // Field java/lang/System.out:Ljava/io/PrintStream;", - "46: new #58 // class java/lang/StringBuilder", - "49: dup ", + "" }; + + String[] bytecodeLines = new String[] { "0: lconst_0 ", "1: lstore_3 ", "2: iconst_0 ", + "3: istore 5 ", "5: goto 35 ", "8: aload_0 ", "9: lload_3 ", + "10: invokespecial #225 // Method leaf1:(J)J", "13: lstore_3 ", "14: aload_0 ", + "15: lload_3 ", "16: invokespecial #228 // Method leaf2:(J)J", "19: lstore_3 ", + "20: aload_0 ", "21: lload_3 ", "22: invokespecial #231 // Method leaf3:(J)J", + "25: lstore_3 ", "26: aload_0 ", "27: lload_3 ", + "28: invokespecial #234 // Method leaf4:(J)J", "31: lstore_3 ", "32: iinc 5, 1 ", + "35: iload 5 ", "37: i2l ", "38: lload_1 ", "39: lcmp ", + "40: iflt 8 ", "43: getstatic #52 // Field java/lang/System.out:Ljava/io/PrintStream;", + "46: new #58 // class java/lang/StringBuilder", "49: dup ", "50: ldc #237 // String testLeaf:", "52: invokespecial #62 // Method java/lang/StringBuilder.\"\":(Ljava/lang/String;)V", "55: lload_3 ", "56: invokevirtual #65 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", "59: invokevirtual #69 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "62: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "65: return " - }; + "62: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", "65: return " }; - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", new Class[]{long.class}); + IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", + new Class[] { long.class }); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C1, logLines, bytecodeLines); @@ -718,7 +658,7 @@ public void testJava7TieredLeaf() @Test public void testJava7TieredChain() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -850,42 +790,25 @@ public void testJava7TieredChain() "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: goto 23 ", - "8: aload_0 ", - "9: lload_3 ", - "10: invokespecial #190 // Method chainA1:(J)J", - "13: lstore_3 ", - "14: aload_0 ", - "15: lload_3 ", - "16: invokespecial #194 // Method chainB1:(J)J", - "19: lstore_3 ", - "20: iinc 5, 1 ", - "23: iload 5 ", - "25: i2l ", - "26: lload_1 ", - "27: lcmp ", - "28: iflt 8 ", + "" }; + + String[] bytecodeLines = new String[] { "0: lconst_0 ", "1: lstore_3 ", "2: iconst_0 ", + "3: istore 5 ", "5: goto 23 ", "8: aload_0 ", "9: lload_3 ", + "10: invokespecial #190 // Method chainA1:(J)J", "13: lstore_3 ", "14: aload_0 ", + "15: lload_3 ", "16: invokespecial #194 // Method chainB1:(J)J", "19: lstore_3 ", + "20: iinc 5, 1 ", "23: iload 5 ", "25: i2l ", "26: lload_1 ", + "27: lcmp ", "28: iflt 8 ", "31: getstatic #52 // Field java/lang/System.out:Ljava/io/PrintStream;", - "34: new #58 // class java/lang/StringBuilder", - "37: dup ", + "34: new #58 // class java/lang/StringBuilder", "37: dup ", "38: ldc #197 // String testCallChain:", "40: invokespecial #62 // Method java/lang/StringBuilder.\"\":(Ljava/lang/String;)V", "43: lload_3 ", "44: invokevirtual #65 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", "47: invokevirtual #69 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "50: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "53: return " - }; + "50: invokevirtual #73 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", "53: return " }; - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain", new Class[]{long.class}); + IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain", + new Class[] { long.class }); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C1, logLines, bytecodeLines); @@ -902,7 +825,7 @@ public void testJava7TieredChain() @Test public void testJava8NonTieredLeaf() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -996,107 +919,59 @@ public void testJava8NonTieredLeaf() "", "", "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", + "", "", + "", "", "", + "", "", + "", "", + "", "", "", + "", "", + "", "", + "", "", "", + "", "", "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", + "", "", "", + "", "", + "", "", "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: iload 5 ", - "7: i2l ", - "8: lload_1 ", - "9: lcmp ", - "10: ifge 43 ", - "13: aload_0 ", - "14: lload_3 ", - "15: invokespecial #70 // Method leaf1:(J)J", - "18: lstore_3 ", - "19: aload_0 ", - "20: lload_3 ", - "21: invokespecial #71 // Method leaf2:(J)J", - "24: lstore_3 ", - "25: aload_0 ", - "26: lload_3 ", - "27: invokespecial #72 // Method leaf3:(J)J", - "30: lstore_3 ", - "31: aload_0 ", - "32: lload_3 ", - "33: invokespecial #73 // Method leaf4:(J)J", - "36: lstore_3 ", - "37: iinc 5, 1 ", - "40: goto 5 ", - "43: getstatic #13 // Field java/lang/System.out:Ljava/io/PrintStream;", - "46: new #14 // class java/lang/StringBuilder", - "49: dup ", + "" }; + + String[] bytecodeLines = new String[] { "0: lconst_0 ", "1: lstore_3 ", "2: iconst_0 ", + "3: istore 5 ", "5: iload 5 ", "7: i2l ", "8: lload_1 ", + "9: lcmp ", "10: ifge 43 ", "13: aload_0 ", "14: lload_3 ", + "15: invokespecial #70 // Method leaf1:(J)J", "18: lstore_3 ", "19: aload_0 ", + "20: lload_3 ", "21: invokespecial #71 // Method leaf2:(J)J", "24: lstore_3 ", + "25: aload_0 ", "26: lload_3 ", "27: invokespecial #72 // Method leaf3:(J)J", + "30: lstore_3 ", "31: aload_0 ", "32: lload_3 ", + "33: invokespecial #73 // Method leaf4:(J)J", "36: lstore_3 ", "37: iinc 5, 1 ", + "40: goto 5 ", "43: getstatic #13 // Field java/lang/System.out:Ljava/io/PrintStream;", + "46: new #14 // class java/lang/StringBuilder", "49: dup ", "50: invokespecial #15 // Method java/lang/StringBuilder.\"\":()V", "53: ldc #74 // String testLeaf:", "55: invokevirtual #17 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;", "58: lload_3 ", "59: invokevirtual #18 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", "62: invokevirtual #19 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "65: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "68: return " - }; + "65: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", "68: return " }; - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", new Class[]{long.class}); + IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", + new Class[] { long.class }); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C2, logLines, bytecodeLines); - assertEquals(10, result.annotatedLineCount()); + assertEquals(11, result.annotatedLineCount()); checkLine(result, 10, "never", BCAnnotationType.BRANCH); checkLine(result, 15, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); @@ -1108,216 +983,194 @@ public void testJava8NonTieredLeaf() checkLine(result, 59, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); checkLine(result, 62, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); checkLine(result, 65, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); + checkLine(result, 65, "null_check", BCAnnotationType.UNCOMMON_TRAP); } /* - * Clean up tests related to the workaround for the now-fixed TieredCompilation log bug + * Clean up tests related to the workaround for the now-fixed + * TieredCompilation log bug * - @Test - public void testJava8NonTieredChain() - { - String[] logLines = new String[]{ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: iload 5 ", - "7: i2l ", - "8: lload_1 ", - "9: lcmp ", - "10: ifge 31 ", - "13: aload_0 ", - "14: lload_3 ", - "15: invokespecial #58 // Method chainA1:(J)J", - "18: lstore_3 ", - "19: aload_0 ", - "20: lload_3 ", - "21: invokespecial #59 // Method chainB1:(J)J", - "24: lstore_3 ", - "25: iinc 5, 1 ", - "28: goto 5 ", - "31: getstatic #13 // Field java/lang/System.out:Ljava/io/PrintStream;", - "34: new #14 // class java/lang/StringBuilder", - "37: dup ", - "38: invokespecial #15 // Method java/lang/StringBuilder.\"\":()V", - "41: ldc #60 // String testCallChain:", - "43: invokevirtual #17 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;", - "46: lload_3 ", - "47: invokevirtual #18 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", - "50: invokevirtual #19 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "53: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "56: return " - }; - - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain2", new Class[]{long.class}); - - BytecodeAnnotations result = buildAnnotations(member, CompilerName.C2, logLines, bytecodeLines); - - assertEquals(8, result.annotatedLineCount()); - - checkLine(result, 10, "never", BCAnnotationType.BRANCH); - checkLine(result, 15, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); - checkLine(result, 21, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); - checkLine(result, 38, "not reached", BCAnnotationType.INLINE_FAIL); - checkLine(result, 43, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); - checkLine(result, 47, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); - checkLine(result, 50, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); - checkLine(result, 53, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); - } - */ + * @Test public void testJava8NonTieredChain() { String[] logLines = new + * String[]{ + * "" + * , "", + * "", "", + * "" + * , + * "" + * , "", + * "", + * "", + * "", + * "", + * "" + * , "", + * "" + * , "", + * "" + * , "", + * "", + * "", + * "", + * "", + * "" + * , "", + * "", + * "", + * "", + * "", "", + * "" + * , "", + * "", + * "", + * "", + * "", + * "", + * "", "", + * "", + * "", + * "", + * "", + * "", "", + * "", + * "" + * , "", + * "", + * "", "", + * "", + * "" + * , "", + * "", + * "", "", + * "" + * , "", + * "", + * "", + * "", + * "", + * "" + * , "", + * "", + * "", + * "", + * "", + * "", + * "" + * , "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", "", "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "" + * , "", + * "" + * , "", + * "" + * , "", + * "", + * "", "", "", + * "", + * "", + * "", + * "", + * "", "", "", + * "", + * "", + * "", + * "", + * "", "", "", + * "", + * "", + * "", "", + * "", + * "", + * "", + * "", "", "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", + * "", "", + * "", + * "", + * "" + * , + * "" + * , "" }; + * + * String[] bytecodeLines = new String[]{ "0: lconst_0 ", + * "1: lstore_3 ", "2: iconst_0 ", "3: istore 5 ", + * "5: iload 5 ", "7: i2l ", "8: lload_1 ", + * "9: lcmp ", "10: ifge 31 ", + * "13: aload_0 ", "14: lload_3 ", + * "15: invokespecial #58 // Method chainA1:(J)J", + * "18: lstore_3 ", "19: aload_0 ", "20: lload_3 ", + * "21: invokespecial #59 // Method chainB1:(J)J", + * "24: lstore_3 ", "25: iinc 5, 1 ", + * "28: goto 5 ", + * "31: getstatic #13 // Field java/lang/System.out:Ljava/io/PrintStream;" + * , "34: new #14 // class java/lang/StringBuilder", + * "37: dup ", + * "38: invokespecial #15 // Method java/lang/StringBuilder.\"\":()V" + * , "41: ldc #60 // String testCallChain:", + * "43: invokevirtual #17 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;" + * , "46: lload_3 ", + * "47: invokevirtual #18 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;" + * , + * "50: invokevirtual #19 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;" + * , + * "53: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V" + * , "56: return " }; + * + * IMetaMember member = UnitTestUtil.createTestMetaMember( + * "org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain2", new + * Class[]{long.class}); + * + * BytecodeAnnotations result = buildAnnotations(member, CompilerName.C2, + * logLines, bytecodeLines); + * + * assertEquals(8, result.annotatedLineCount()); + * + * checkLine(result, 10, "never", BCAnnotationType.BRANCH); + * checkLine(result, 15, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); + * checkLine(result, 21, "inline (hot)", BCAnnotationType.INLINE_SUCCESS); + * checkLine(result, 38, "not reached", BCAnnotationType.INLINE_FAIL); + * checkLine(result, 43, "MinInliningThreshold", + * BCAnnotationType.INLINE_FAIL); checkLine(result, 47, + * "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); checkLine(result, + * 50, "MinInliningThreshold", BCAnnotationType.INLINE_FAIL); + * checkLine(result, 53, "MinInliningThreshold", + * BCAnnotationType.INLINE_FAIL); } + */ @Test public void testJava8TieredLeaf() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -1381,103 +1234,52 @@ public void testJava8TieredLeaf() "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", "", + "", "", "", + "", "", + "", "", "", "", + "", "", "", + "", "", "", + "", "", "", + "", "", "", + "", "", "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: iload 5 ", - "7: i2l ", - "8: lload_1 ", - "9: lcmp ", - "10: ifge 43 ", - "13: aload_0 ", - "14: lload_3 ", - "15: invokespecial #70 // Method leaf1:(J)J", - "18: lstore_3 ", - "19: aload_0 ", - "20: lload_3 ", - "21: invokespecial #71 // Method leaf2:(J)J", - "24: lstore_3 ", - "25: aload_0 ", - "26: lload_3 ", - "27: invokespecial #72 // Method leaf3:(J)J", - "30: lstore_3 ", - "31: aload_0 ", - "32: lload_3 ", - "33: invokespecial #73 // Method leaf4:(J)J", - "36: lstore_3 ", - "37: iinc 5, 1 ", - "40: goto 5 ", - "43: getstatic #13 // Field java/lang/System.out:Ljava/io/PrintStream;", - "46: new #14 // class java/lang/StringBuilder", - "49: dup ", + "" }; + + String[] bytecodeLines = new String[] { "0: lconst_0 ", "1: lstore_3 ", "2: iconst_0 ", + "3: istore 5 ", "5: iload 5 ", "7: i2l ", "8: lload_1 ", + "9: lcmp ", "10: ifge 43 ", "13: aload_0 ", "14: lload_3 ", + "15: invokespecial #70 // Method leaf1:(J)J", "18: lstore_3 ", "19: aload_0 ", + "20: lload_3 ", "21: invokespecial #71 // Method leaf2:(J)J", "24: lstore_3 ", + "25: aload_0 ", "26: lload_3 ", "27: invokespecial #72 // Method leaf3:(J)J", + "30: lstore_3 ", "31: aload_0 ", "32: lload_3 ", + "33: invokespecial #73 // Method leaf4:(J)J", "36: lstore_3 ", "37: iinc 5, 1 ", + "40: goto 5 ", "43: getstatic #13 // Field java/lang/System.out:Ljava/io/PrintStream;", + "46: new #14 // class java/lang/StringBuilder", "49: dup ", "50: invokespecial #15 // Method java/lang/StringBuilder.\"\":()V", "53: ldc #74 // String testLeaf:", "55: invokevirtual #17 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;", "58: lload_3 ", "59: invokevirtual #18 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", "62: invokevirtual #19 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "65: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "68: return " - }; - - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", new Class[]{long.class}); + "65: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", "68: return " }; + IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testLeaf", + new Class[] { long.class }); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C1, logLines, bytecodeLines); @@ -1497,7 +1299,7 @@ public void testJava8TieredLeaf() @Test public void testJava8TieredChain() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -1577,94 +1379,50 @@ public void testJava8TieredChain() "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", "", + "", "", "", + "", "", + "", "", "", "", + "", "", "", + "", "", "", + "", "", "", + "", "", "", + "", "", "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: lconst_0 ", - "1: lstore_3 ", - "2: iconst_0 ", - "3: istore 5 ", - "5: iload 5 ", - "7: i2l ", - "8: lload_1 ", - "9: lcmp ", - "10: ifge 31 ", - "13: aload_0 ", - "14: lload_3 ", - "15: invokespecial #58 // Method chainA1:(J)J", - "18: lstore_3 ", - "19: aload_0 ", - "20: lload_3 ", - "21: invokespecial #59 // Method chainB1:(J)J", - "24: lstore_3 ", - "25: iinc 5, 1 ", - "28: goto 5 ", + "" }; + + String[] bytecodeLines = new String[] { "0: lconst_0 ", "1: lstore_3 ", "2: iconst_0 ", + "3: istore 5 ", "5: iload 5 ", "7: i2l ", "8: lload_1 ", + "9: lcmp ", "10: ifge 31 ", "13: aload_0 ", "14: lload_3 ", + "15: invokespecial #58 // Method chainA1:(J)J", "18: lstore_3 ", "19: aload_0 ", + "20: lload_3 ", "21: invokespecial #59 // Method chainB1:(J)J", "24: lstore_3 ", + "25: iinc 5, 1 ", "28: goto 5 ", "31: getstatic #13 // Field java/lang/System.out:Ljava/io/PrintStream;", - "34: new #14 // class java/lang/StringBuilder", - "37: dup ", + "34: new #14 // class java/lang/StringBuilder", "37: dup ", "38: invokespecial #15 // Method java/lang/StringBuilder.\"\":()V", "41: ldc #60 // String testCallChain:", "43: invokevirtual #17 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;", "46: lload_3 ", "47: invokevirtual #18 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;", "50: invokevirtual #19 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "53: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", - "56: return " - }; + "53: invokevirtual #20 // Method java/io/PrintStream.println:(Ljava/lang/String;)V", "56: return " }; - IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain", new Class[]{long.class}); + IMetaMember member = UnitTestUtil.createTestMetaMember("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", "testCallChain", + new Class[] { long.class }); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C1, logLines, bytecodeLines); @@ -1679,7 +1437,8 @@ public void testJava8TieredChain() checkLine(result, 53, "Inlined: Yes", BCAnnotationType.INLINE_SUCCESS); } - private BytecodeAnnotations buildAnnotations(IMetaMember member, CompilerName compiler, String[] logLines, String[] bytecodeLines) + private BytecodeAnnotations buildAnnotations(IMetaMember member, CompilerName compiler, String[] logLines, + String[] bytecodeLines) { TagProcessor tp = new TagProcessor(); @@ -1717,11 +1476,13 @@ private BytecodeAnnotations buildAnnotations(IMetaMember member, CompilerName co List instructions = BytecodeLoader.parseInstructions(bytecodeBuilder.toString()); + ((HelperMetaMethod) member).setInstructions(instructions); + BytecodeAnnotations bcAnnotations = null; try { - bcAnnotations = new BytecodeAnnotationBuilder().buildBytecodeAnnotations(member, instructions, new JITDataModel()); + bcAnnotations = new BytecodeAnnotationBuilder().buildBytecodeAnnotations(member, new JITDataModel()); } catch (AnnotationException annoEx) { @@ -1817,33 +1578,48 @@ private void checkLine(BytecodeAnnotations result, int index, String annotation, assertNotNull(lines); - assertTrue(lines.get(0).getAnnotation().contains(annotation)); - assertEquals(type, lines.get(0).getType()); + boolean matchedAnnotation = false; + boolean matchedType = false; + + for (LineAnnotation lineAnnotation : lines) + { + if (lineAnnotation.getAnnotation().contains(annotation)) + { + matchedAnnotation = true; + if (lineAnnotation.getType() == type) + { + matchedType = true; + } + } + } + + assertTrue(matchedAnnotation); + assertTrue(matchedType); } - + @Test public void testMemberMatchesParseTagWithExactParams() { String methodName = "print"; String klassName = "java.io.PrintStream"; - Class[] params = new Class[]{java.lang.String.class}; + Class[] params = new Class[] { java.lang.String.class }; Map attrsMethod = new HashMap<>(); Map attrsKlass = new HashMap<>(); Map attrsParse = new HashMap<>(); - + Map attrsTypeVoid = new HashMap<>(); Map attrsTypeString = new HashMap<>(); String idString = "1"; String nameString = "java.lang.String"; - + String idVoid = "2"; String nameVoid = S_TYPE_NAME_VOID; attrsTypeString.put(ATTR_ID, idString); attrsTypeString.put(ATTR_NAME, nameString); - + attrsTypeVoid.put(ATTR_ID, idVoid); attrsTypeVoid.put(ATTR_NAME, nameVoid); @@ -1877,33 +1653,33 @@ public void testMemberMatchesParseTagWithExactParams() IMetaMember member = UnitTestUtil.createTestMetaMember(klassName, methodName, params); String tagMethodID = tagParse.getAttribute(ATTR_METHOD); - + assertTrue(JournalUtil.memberMatchesMethodID(member, tagMethodID, parseDictionary)); } - + @Test public void testMemberDoesNotMatchParseTagWithInexactParams() { String methodName = "print"; String klassName = "java.io.PrintStream"; - Class[] params = new Class[]{java.lang.Object.class}; + Class[] params = new Class[] { java.lang.Object.class }; Map attrsMethod = new HashMap<>(); Map attrsKlass = new HashMap<>(); Map attrsParse = new HashMap<>(); - + Map attrsTypeVoid = new HashMap<>(); Map attrsTypeString = new HashMap<>(); String idString = "1"; String nameString = "java.lang.String"; - + String idVoid = "2"; String nameVoid = S_TYPE_NAME_VOID; attrsTypeString.put(ATTR_ID, idString); attrsTypeString.put(ATTR_NAME, nameString); - + attrsTypeVoid.put(ATTR_ID, idVoid); attrsTypeVoid.put(ATTR_NAME, nameVoid); @@ -1937,14 +1713,14 @@ public void testMemberDoesNotMatchParseTagWithInexactParams() IMetaMember member = UnitTestUtil.createTestMetaMember(klassName, methodName, params); String tagMethodID = tagParse.getAttribute(ATTR_METHOD); - + assertFalse(JournalUtil.memberMatchesMethodID(member, tagMethodID, parseDictionary)); } - + @Test public void testEliminatedHeapAllocationsCorrectKlass() { - String[] logLines = new String[]{ + String[] logLines = new String[] { "", "", "", @@ -2053,164 +1829,78 @@ public void testEliminatedHeapAllocationsCorrectKlass() "", "", "", - "", - "", + "", "", "", - "", - "", - "", + "", "", "", "", - "", - "", - "", + "", "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", - "", - "", - "", - "", - "", - "", - "", + "", "", "", + "", "", "", "", "", "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", + "", "", "", + "", "", "", + "", "", "", + "", "", "", "", + "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "", "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", "", + "", "", "", "", + "", "", "", + "", "", "", "", + "", "", "", - "", - "", - "", - "", - "", - "", + "", "", + "", "", + "", "", "", - "", - "", - "", - "", + "", "", + "", "", "", "", "", "", "", - "" - }; - - String[] bytecodeLines = new String[]{ - "0: iconst_0", - "1: istore_2", - "2: iconst_0", - "3: istore_3", - "4: iconst_0", - "5: istore 4", - "7: iload 4", - "9: ldc #5 // int 100000000", - "11: if_icmpge 84", - "14: ldc #6 // int 43981", - "16: istore 5", - "18: iconst_0", - "19: istore 6", - "21: aload_0", - "22: getfield #4 // Field random:Ljava/util/Random;", - "25: invokevirtual #7 // Method java/util/Random.nextBoolean:()Z", - "28: ifeq 35", - "31: ldc #6 // int 43981", - "33: istore 6", - "35: new #8 // class EscapeTest$Wrapper1", - "38: dup", - "39: aload_0", - "40: iload 5", - "42: invokespecial #9 // Method EscapeTest$Wrapper1.\"\":(LEscapeTest;I)V", - "45: astore 7", - "47: new #10 // class EscapeTest$Wrapper2", - "50: dup", - "51: aload_0", - "52: iload 6", - "54: invokespecial #11 // Method EscapeTest$Wrapper2.\"\":(LEscapeTest;I)V", - "57: astore 8", - "59: aload 7", - "61: aload 8", - "63: invokevirtual #12 // Method EscapeTest$Wrapper1.equals:(LEscapeTest$Wrapper2;)Z", - "66: ifeq 75", - "69: iinc 2, 1", - "72: goto 78", - "75: iinc 3, 1", - "78: iinc 4, 1", - "81: goto 7", - "84: new #13 // class java/lang/StringBuilder", - "87: dup", - "88: invokespecial #14 // Method java/lang/StringBuilder.\"\":()V", - "91: iload_2", - "92: invokevirtual #15 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;", - "95: ldc #16 // String /", - "97: invokevirtual #17 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;", - "100: iload_3", - "101: invokevirtual #15 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;", - "104: invokevirtual #18 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", - "107: astore_1", - "108: aload_1", - "109: areturn" - }; - + "" }; + + String[] bytecodeLines = new String[] { "0: iconst_0", "1: istore_2", "2: iconst_0", "3: istore_3", "4: iconst_0", + "5: istore 4", "7: iload 4", "9: ldc #5 // int 100000000", "11: if_icmpge 84", "14: ldc #6 // int 43981", + "16: istore 5", "18: iconst_0", "19: istore 6", "21: aload_0", + "22: getfield #4 // Field random:Ljava/util/Random;", + "25: invokevirtual #7 // Method java/util/Random.nextBoolean:()Z", "28: ifeq 35", "31: ldc #6 // int 43981", + "33: istore 6", "35: new #8 // class EscapeTest$Wrapper1", "38: dup", "39: aload_0", "40: iload 5", + "42: invokespecial #9 // Method EscapeTest$Wrapper1.\"\":(LEscapeTest;I)V", "45: astore 7", + "47: new #10 // class EscapeTest$Wrapper2", "50: dup", "51: aload_0", "52: iload 6", + "54: invokespecial #11 // Method EscapeTest$Wrapper2.\"\":(LEscapeTest;I)V", "57: astore 8", + "59: aload 7", "61: aload 8", + "63: invokevirtual #12 // Method EscapeTest$Wrapper1.equals:(LEscapeTest$Wrapper2;)Z", "66: ifeq 75", + "69: iinc 2, 1", "72: goto 78", "75: iinc 3, 1", "78: iinc 4, 1", "81: goto 7", + "84: new #13 // class java/lang/StringBuilder", "87: dup", + "88: invokespecial #14 // Method java/lang/StringBuilder.\"\":()V", "91: iload_2", + "92: invokevirtual #15 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;", + "95: ldc #16 // String /", + "97: invokevirtual #17 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;", + "100: iload_3", "101: invokevirtual #15 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;", + "104: invokevirtual #18 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;", "107: astore_1", + "108: aload_1", "109: areturn" }; + IMetaMember member = UnitTestUtil.createTestMetaMember(); BytecodeAnnotations result = buildAnnotations(member, CompilerName.C2, logLines, bytecodeLines); - + assertEquals(2, result.annotatedLineCount()); checkLine(result, 35, "EscapeTest$Wrapper1", BCAnnotationType.ELIMINATED_ALLOCATION); - checkLine(result, 47, "EscapeTest$Wrapper2", BCAnnotationType.ELIMINATED_ALLOCATION); + checkLine(result, 47, "EscapeTest$Wrapper2", BCAnnotationType.ELIMINATED_ALLOCATION); } } \ No newline at end of file diff --git a/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeLoader.java b/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeLoader.java index caf1b31d..22759533 100644 --- a/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeLoader.java +++ b/src/test/java/org/adoptopenjdk/jitwatch/test/TestBytecodeLoader.java @@ -5,7 +5,6 @@ */ package org.adoptopenjdk.jitwatch.test; -import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_NEWLINE; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_BYTECODE_STATIC_INITIALISER_SIGNATURE; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE; import static org.junit.Assert.assertEquals; @@ -312,76 +311,73 @@ public int add(int x, int y) @Test public void testLineNumberTable() throws ClassNotFoundException { - StringBuilder builder = new StringBuilder(); - - builder.append("Classfile TestBytecodeLoader.class").append(S_NEWLINE); - builder.append(" Last modified 18-May-2014; size 426 bytes").append(S_NEWLINE); - builder.append(" MD5 checksum d8d0af7620175f82d2c5c753b493196f").append(S_NEWLINE); - builder.append(" Compiled from \"TestBytecodeLoader.java\"").append(S_NEWLINE); - builder.append("public class org.adoptopenjdk.jitwatch.test.TestBytecodeLoader").append(S_NEWLINE); - builder.append(" SourceFile: \"TestBytecodeLoader.java\"").append(S_NEWLINE); - builder.append(" minor version: 0").append(S_NEWLINE); - builder.append(" major version: 51").append(S_NEWLINE); - builder.append(" flags: ACC_PUBLIC, ACC_SUPER").append(S_NEWLINE); - builder.append("Constant pool:").append(S_NEWLINE); - builder.append(" #1 = Methodref #3.#18 // java/lang/Object.\"\":()V").append(S_NEWLINE); - builder.append(" #2 = Class #19 // org/adoptopenjdk/jitwatch/test/TestBytecodeLoader").append( - S_NEWLINE); - builder.append(" #3 = Class #20 // java/lang/Object").append(S_NEWLINE); - builder.append(" #4 = Utf8 ").append(S_NEWLINE); - builder.append(" #5 = Utf8 ()V").append(S_NEWLINE); - builder.append(" #6 = Utf8 Code").append(S_NEWLINE); - builder.append(" #7 = Utf8 LineNumberTable").append(S_NEWLINE); - builder.append(" #8 = Utf8 LocalVariableTable").append(S_NEWLINE); - builder.append(" #9 = Utf8 this").append(S_NEWLINE); - builder.append(" #10 = Utf8 Lorg/adoptopenjdk/jitwatch/test/TestBytecodeLoader;").append(S_NEWLINE); - builder.append(" #11 = Utf8 add").append(S_NEWLINE); - builder.append(" #12 = Utf8 (II)I").append(S_NEWLINE); - builder.append(" #13 = Utf8 a").append(S_NEWLINE); - builder.append(" #14 = Utf8 I").append(S_NEWLINE); - builder.append(" #15 = Utf8 b").append(S_NEWLINE); - builder.append(" #16 = Utf8 SourceFile").append(S_NEWLINE); - builder.append(" #17 = Utf8 TestBytecodeLoader.java").append(S_NEWLINE); - builder.append(" #18 = NameAndType #4:#5 // \"\":()V").append(S_NEWLINE); - builder.append(" #19 = Utf8 org/adoptopenjdk/jitwatch/test/TestBytecodeLoader").append(S_NEWLINE); - builder.append(" #20 = Utf8 java/lang/Object").append(S_NEWLINE); - builder.append("{").append(S_NEWLINE); - builder.append(" public org.adoptopenjdk.jitwatch.test.TestBytecodeLoader();").append(S_NEWLINE); - builder.append(" flags: ACC_PUBLIC").append(S_NEWLINE); - builder.append(" Code:").append(S_NEWLINE); - builder.append(" stack=1, locals=1, args_size=1").append(S_NEWLINE); - builder.append(" 0: aload_0 ").append(S_NEWLINE); - builder.append(" 1: invokespecial #1 // Method java/lang/Object.\"\":()V").append(S_NEWLINE); - builder.append(" 4: return ").append(S_NEWLINE); - builder.append(" LineNumberTable:").append(S_NEWLINE); - builder.append(" line 3: 0").append(S_NEWLINE); - builder.append(" LocalVariableTable:").append(S_NEWLINE); - builder.append(" Start Length Slot Name Signature").append(S_NEWLINE); - builder.append(" 0 5 0 this Lorg/adoptopenjdk/jitwatch/test/TestBytecodeLoader;").append( - S_NEWLINE); - builder.append("").append(S_NEWLINE); - builder.append(" public int add(int, int);").append(S_NEWLINE); - builder.append(" flags: ACC_PUBLIC").append(S_NEWLINE); - builder.append(" Code:").append(S_NEWLINE); - builder.append(" stack=2, locals=3, args_size=3").append(S_NEWLINE); - builder.append(" 0: iload_1 ").append(S_NEWLINE); - builder.append(" 1: iload_2 ").append(S_NEWLINE); - builder.append(" 2: iadd ").append(S_NEWLINE); - builder.append(" 3: ireturn ").append(S_NEWLINE); - builder.append(" LineNumberTable:").append(S_NEWLINE); - builder.append(" line 7: 0").append(S_NEWLINE); - builder.append(" LocalVariableTable:").append(S_NEWLINE); - builder.append(" Start Length Slot Name Signature").append(S_NEWLINE); - builder.append(" 0 4 0 this Lorg/adoptopenjdk/jitwatch/test/TestBytecodeLoader;").append( - S_NEWLINE); - builder.append(" 0 4 1 a I").append(S_NEWLINE); - builder.append(" 0 4 2 b I").append(S_NEWLINE); - builder.append("}").append(S_NEWLINE); + String[] lines = new String[]{ + + "Classfile TestBytecodeLoader.class", + " Last modified 18-May-2014; size 426 bytes", + " MD5 checksum d8d0af7620175f82d2c5c753b493196f", + " Compiled from \"TestBytecodeLoader.java\"", + "public class org.adoptopenjdk.jitwatch.test.TestBytecodeLoader", + " SourceFile: \"TestBytecodeLoader.java\"", + " minor version: 0", + " major version: 51", + " flags: ACC_PUBLIC, ACC_SUPER", + "Constant pool:", + " #1 = Methodref #3.#18 // java/lang/Object.\"\":()V", + " #2 = Class #19 // org/adoptopenjdk/jitwatch/test/TestBytecodeLoader", + " #3 = Class #20 // java/lang/Object", + " #4 = Utf8 ", + " #5 = Utf8 ()V", + " #6 = Utf8 Code", + " #7 = Utf8 LineNumberTable", + " #8 = Utf8 LocalVariableTable", + " #9 = Utf8 this", + " #10 = Utf8 Lorg/adoptopenjdk/jitwatch/test/TestBytecodeLoader;", + " #11 = Utf8 add", + " #12 = Utf8 (II)I", + " #13 = Utf8 a", + " #14 = Utf8 I", + " #15 = Utf8 b", + " #16 = Utf8 SourceFile", + " #17 = Utf8 TestBytecodeLoader.java", + " #18 = NameAndType #4:#5 // \"\":()V", + " #19 = Utf8 org/adoptopenjdk/jitwatch/test/TestBytecodeLoader", + " #20 = Utf8 java/lang/Object", + "{", + " public org.adoptopenjdk.jitwatch.test.TestBytecodeLoader();", + " flags: ACC_PUBLIC", + " Code:", + " stack=1, locals=1, args_size=1", + " 0: aload_0 ", + " 1: invokespecial #1 // Method java/lang/Object.\"\":()V", + " 4: return ", + " LineNumberTable:", + " line 3: 0", + " LocalVariableTable:", + " Start Length Slot Name Signature", + " 0 5 0 this Lorg/adoptopenjdk/jitwatch/test/TestBytecodeLoader;", + "", + " public int add(int, int);", + " flags: ACC_PUBLIC", + " Code:", + " stack=2, locals=3, args_size=3", + " 0: iload_1 ", + " 1: iload_2 ", + " 2: iadd ", + " 3: ireturn ", + " LineNumberTable:", + " line 7: 0", + " LocalVariableTable:", + " Start Length Slot Name Signature", + " 0 4 0 this Lorg/adoptopenjdk/jitwatch/test/TestBytecodeLoader;", + " 0 4 1 a I", + " 0 4 2 b I", + "}"}; IMetaMember member = UnitTestUtil .createTestMetaMember(getClass().getName(), "add", new Class[] { int.class, int.class }); - ClassBC classBytecode = BytecodeLoader.parse(getClass().getName(), builder.toString()); + ClassBC classBytecode = BytecodeLoader.parse(getClass().getName(), lines); MemberBytecode memberBytecode = classBytecode.getMemberBytecode(member); @@ -427,15 +423,15 @@ public void testLineNumberTable() throws ClassNotFoundException @Test public void testClassFileVersion() { - StringBuilder builder = new StringBuilder(); + String[] lines = new String[]{ - builder.append("public class org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog").append(S_NEWLINE); - builder.append("SourceFile: \"MakeHotSpotLog.java\"").append(S_NEWLINE); - builder.append("minor version: 1").append(S_NEWLINE); - builder.append("major version: 51").append(S_NEWLINE); - builder.append("flags: ACC_PUBLIC, ACC_SUPER").append(S_NEWLINE); + "public class org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", + "SourceFile: \"MakeHotSpotLog.java\"", + "minor version: 1", + "major version: 51", + "flags: ACC_PUBLIC, ACC_SUPER"}; - ClassBC classBytecode = BytecodeLoader.parse("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", builder.toString()); + ClassBC classBytecode = BytecodeLoader.parse("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", lines); assertEquals(1, classBytecode.getMinorVersion()); assertEquals(51, classBytecode.getMajorVersion()); } @@ -443,20 +439,20 @@ public void testClassFileVersion() @Test public void testClassFileVersionWithRuntimeAnnotations() { - StringBuilder builder = new StringBuilder(); - - builder.append("public class org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog").append(S_NEWLINE); - builder.append("SourceFile: \"MakeHotSpotLog.java\"").append(S_NEWLINE); - builder.append(" RuntimeVisibleAnnotations:").append(S_NEWLINE); - builder.append(" 0: #49(#50=e#51.#52)").append(S_NEWLINE); - builder.append(" 0: #49(#50=e#51.#52)").append(S_NEWLINE); - builder.append(" 1: #53(#50=[e#54.#55])").append(S_NEWLINE); - builder.append(" 2: #56(#50=e#57.#58)").append(S_NEWLINE); - builder.append("minor version: 1").append(S_NEWLINE); - builder.append("major version: 51").append(S_NEWLINE); - builder.append("flags: ACC_PUBLIC, ACC_SUPER").append(S_NEWLINE); - - ClassBC classBytecode = BytecodeLoader.parse("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", builder.toString()); + String[] lines = new String[]{ + + "public class org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", + "SourceFile: \"MakeHotSpotLog.java\"", + " RuntimeVisibleAnnotations:", + " 0: #49(#50=e#51.#52)", + " 0: #49(#50=e#51.#52)", + " 1: #53(#50=[e#54.#55])", + " 2: #56(#50=e#57.#58)", + "minor version: 1", + "major version: 51", + "flags: ACC_PUBLIC, ACC_SUPER"}; + + ClassBC classBytecode = BytecodeLoader.parse("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog", lines); assertEquals(1, classBytecode.getMinorVersion()); assertEquals(51, classBytecode.getMajorVersion()); } @@ -464,32 +460,32 @@ public void testClassFileVersionWithRuntimeAnnotations() @Test public void testRegressionJMHSampleWithRuntimeAnnotations() { - StringBuilder builder = new StringBuilder(); - String bcSig = "public void measureWrong();"; - - builder.append(" ").append(bcSig).append(S_NEWLINE); - builder.append(" descriptor: ()V").append(S_NEWLINE); - builder.append(" flags: ACC_PUBLIC").append(S_NEWLINE); - builder.append(" Code:").append(S_NEWLINE); - builder.append(" stack=2, locals=1, args_size=1").append(S_NEWLINE); - builder.append(" 0: aload_0 ").append(S_NEWLINE); - builder.append(" 0: aload_0 ").append(S_NEWLINE); - builder.append(" 1: getfield #4 // Field x:D").append(S_NEWLINE); - builder.append(" 4: invokestatic #5 // Method java/lang/Math.log:(D)D").append(S_NEWLINE); - builder.append(" 7: pop2 ").append(S_NEWLINE); - builder.append(" 8: return ").append(S_NEWLINE); - builder.append(" LineNumberTable:").append(S_NEWLINE); - builder.append(" line 65: 0").append(S_NEWLINE); - builder.append(" line 66: 8").append(S_NEWLINE); - builder.append(" LocalVariableTable:").append(S_NEWLINE); - builder.append(" Start Length Slot Name Signature").append(S_NEWLINE); - builder.append(" 0 9 0 this Lorg/openjdk/jmh/samples/JMHSample_08_DeadCode;").append(S_NEWLINE); - builder.append(" RuntimeVisibleAnnotations:").append(S_NEWLINE); - builder.append(" 0: #35()").append(S_NEWLINE); - builder.append(" 0: #35()").append(S_NEWLINE); - - ClassBC classBytecode = BytecodeLoader.parse(getClass().getName(), builder.toString()); + + String[] lines = new String[]{ + + bcSig, + " descriptor: ()V", + " flags: ACC_PUBLIC", + " Code:", + " stack=2, locals=1, args_size=1", + " 0: aload_0 ", + " 0: aload_0 ", + " 1: getfield #4 // Field x:D", + " 4: invokestatic #5 // Method java/lang/Math.log:(D)D", + " 7: pop2 ", + " 8: return ", + " LineNumberTable:", + " line 65: 0", + " line 66: 8", + " LocalVariableTable:", + " Start Length Slot Name Signature", + " 0 9 0 this Lorg/openjdk/jmh/samples/JMHSample_08_DeadCode;", + " RuntimeVisibleAnnotations:", + " 0: #35()", + " 0: #35()"}; + + ClassBC classBytecode = BytecodeLoader.parse(getClass().getName(), lines); MemberSignatureParts msp = MemberSignatureParts.fromBytecodeSignature(getClass().getName(), bcSig); @@ -620,14 +616,7 @@ public void testStaticInitialiserRegression() " line 44: 60", " line 45: 74" }; - StringBuilder builder = new StringBuilder(); - - for (String line : lines) - { - builder.append(line).append(C_NEWLINE); - } - - ClassBC classBytecode = BytecodeLoader.parse(getClass().getName(), builder.toString()); + ClassBC classBytecode = BytecodeLoader.parse(getClass().getName(), lines); MemberSignatureParts msp = MemberSignatureParts.fromBytecodeSignature(getClass().getName(), S_BYTECODE_STATIC_INITIALISER_SIGNATURE); diff --git a/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestUtil.java b/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestUtil.java index 5efc0c0f..bf797577 100644 --- a/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestUtil.java +++ b/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestUtil.java @@ -14,7 +14,6 @@ import org.adoptopenjdk.jitwatch.model.JITDataModel; import org.adoptopenjdk.jitwatch.model.JITEvent; import org.adoptopenjdk.jitwatch.model.MetaClass; -import org.adoptopenjdk.jitwatch.model.MetaMethod; import org.adoptopenjdk.jitwatch.model.MetaPackage; import org.adoptopenjdk.jitwatch.util.ClassUtil; import org.adoptopenjdk.jitwatch.util.StringUtil; @@ -28,7 +27,7 @@ public static MetaClass createMetaClassFor(JITDataModel model, String fqClassNam return model.buildAndGetMetaClass(clazz); } - public static IMetaMember createTestMetaMember(String fqClassName, String methodName, Class[] params) + public static HelperMetaMethod createTestMetaMember(String fqClassName, String methodName, Class[] params) { String packageName = StringUtil.getPackageName(fqClassName); String className = StringUtil.getUnqualifiedClassName(fqClassName); @@ -37,9 +36,9 @@ public static IMetaMember createTestMetaMember(String fqClassName, String method MetaClass metaClass = new MetaClass(metaPackage, className); - return new MetaMethod(getMethod(fqClassName, methodName, params), metaClass); + return new HelperMetaMethod(getMethod(fqClassName, methodName, params), metaClass); } - + public static IMetaMember createTestMetaMember() { return createTestMetaMember("java.lang.String", "length", new Class[0]);