diff --git a/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java b/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java index 0136b5f5..baa92e60 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileChainWalker.java @@ -8,7 +8,7 @@ import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ID; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_METHOD; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_REASON; -import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.DEBUG_LOGGING; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_ID; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_BC; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_CALL; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_INLINE_FAIL; @@ -21,13 +21,12 @@ import org.adoptopenjdk.jitwatch.journal.IJournalVisitable; import org.adoptopenjdk.jitwatch.journal.JournalUtil; -import org.adoptopenjdk.jitwatch.model.IMetaMember; import org.adoptopenjdk.jitwatch.model.IParseDictionary; import org.adoptopenjdk.jitwatch.model.IReadOnlyJITDataModel; +import org.adoptopenjdk.jitwatch.model.Journal; import org.adoptopenjdk.jitwatch.model.LogParseException; import org.adoptopenjdk.jitwatch.model.Tag; -import org.adoptopenjdk.jitwatch.util.InlineUtil; -import org.adoptopenjdk.jitwatch.util.ParseUtil; +import org.adoptopenjdk.jitwatch.util.TooltipUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,26 +38,18 @@ public class CompileChainWalker implements IJournalVisitable private CompileNode root = null; - private IMetaMember metaMember = null; - public CompileChainWalker(IReadOnlyJITDataModel model) { this.model = model; } - public CompileNode buildCallTree(IMetaMember metaMember) + public CompileNode buildCallTree(Journal journal) { - if (DEBUG_LOGGING) - { - logger.debug("buildCallTree: {}", metaMember.toStringUnqualifiedMethodName(false)); - } - this.root = null; - this.metaMember = metaMember; try { - JournalUtil.visitParseTagsOfLastTask(metaMember, this); + JournalUtil.visitParseTagsOfLastTask(journal, this); } catch (LogParseException lpe) { @@ -71,21 +62,15 @@ public CompileNode buildCallTree(IMetaMember metaMember) private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDictionary parseDictionary) { String methodID = null; - boolean inlined = false; - String inlineReason = null; + CompileNode lastNode = null; Map methodAttrs = new HashMap<>(); Map callAttrs = new HashMap<>(); - // TODO - this switch code is appearing a lot - // should probably refactor with an interface - // or visitor pattern for (Tag child : parseTag.getChildren()) { String tagName = child.getName(); Map tagAttrs = child.getAttrs(); - - //System.out.println("CCW: " + child.toString(false)); switch (tagName) { @@ -98,7 +83,6 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction case TAG_METHOD: { methodID = tagAttrs.get(ATTR_ID); - inlined = false; // reset methodAttrs.clear(); methodAttrs.putAll(tagAttrs); } @@ -107,7 +91,6 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction case TAG_CALL: { methodID = tagAttrs.get(ATTR_METHOD); - inlined = false; callAttrs.clear(); callAttrs.putAll(tagAttrs); } @@ -115,60 +98,39 @@ 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); - - if (childCall != null) - { - CompileNode childNode = new CompileNode(childCall, methodID); - parentNode.addChild(childNode); - - String reason = tagAttrs.get(ATTR_REASON); - String annotationText = InlineUtil.buildInlineAnnotationText(false, reason, callAttrs, methodAttrs, parseDictionary); - childNode.setInlined(inlined, annotationText); - } - else - { - logger.error("TAG_INLINE_FAIL Failed to create CompileNode with null member. Method was {}", methodID); - } - + handleInline(parentNode, methodID, parseDictionary, false, methodAttrs, callAttrs, tagAttrs); methodID = null; + lastNode = null; } 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, parseDictionary); + { + lastNode = handleInline(parentNode, methodID, parseDictionary, true, methodAttrs, callAttrs, tagAttrs); break; + } case TAG_PARSE: // call depth { String childMethodID = tagAttrs.get(ATTR_METHOD); - IMetaMember childCall = ParseUtil.lookupMember(childMethodID, parseDictionary, model); + CompileNode nextParent = parentNode; - if (childCall != null) + if (lastNode != null) { - CompileNode childNode = new CompileNode(childCall, childMethodID); + nextParent = lastNode; + } + else if (child.getNamedChildren(TAG_PARSE).size() > 0) + { + CompileNode childNode = new CompileNode(childMethodID); parentNode.addChild(childNode); - if (methodID != null && methodID.equals(childMethodID)) - { - childNode.setInlined(inlined, inlineReason); - } - - processParseTag(child, childNode, parseDictionary); - } - else - { - logger.error("TAG_PARSE Failed to create CompileNode with null member. Method was {}", childMethodID); + nextParent = childNode; } + + processParseTag(child, nextParent, parseDictionary); + } break; @@ -178,17 +140,33 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction } } + private CompileNode handleInline(CompileNode parentNode, String methodID, IParseDictionary parseDictionary, boolean inlined, + Map methodAttrs, Map callAttrs, Map tagAttrs) + { + CompileNode childNode = new CompileNode(methodID); + parentNode.addChild(childNode); + + String reason = tagAttrs.get(ATTR_REASON); + String tooltip = TooltipUtil.buildInlineAnnotationText(inlined, reason, callAttrs, methodAttrs, parseDictionary); + + childNode.setInlined(inlined); + childNode.setCompiled(methodAttrs.containsKey(ATTR_COMPILE_ID)); + childNode.setTooltipText(tooltip); + + return childNode; + } + @Override public void visitTag(Tag parseTag, IParseDictionary parseDictionary) throws LogParseException { - String id = parseTag.getAttribute(ATTR_METHOD); + String methodID = parseTag.getAttribute(ATTR_METHOD); // only initialise on first parse tag. // there may be multiple if late_inline // is detected if (root == null) { - root = new CompileNode(metaMember, id); + root = CompileNode.createRootNode(methodID, parseDictionary, model); } processParseTag(parseTag, root, parseDictionary); diff --git a/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileNode.java b/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileNode.java index e71e5cc9..de97e5bc 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileNode.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/chain/CompileNode.java @@ -9,15 +9,17 @@ import java.util.List; import org.adoptopenjdk.jitwatch.model.IMetaMember; +import org.adoptopenjdk.jitwatch.model.IParseDictionary; +import org.adoptopenjdk.jitwatch.model.IReadOnlyJITDataModel; +import org.adoptopenjdk.jitwatch.util.ParseUtil; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.*; public class CompileNode -{ - private IMetaMember member; - +{ + private boolean compiled = false; private boolean inlined = false; - private String inlineReason = null; + private String tooltip; private List children; @@ -25,9 +27,20 @@ public class CompileNode private String methodID = null; - public CompileNode(IMetaMember member, String methodID) + private IParseDictionary parseDictionary; + private IReadOnlyJITDataModel model; + + public static CompileNode createRootNode(String methodID, IParseDictionary parseDictionary, IReadOnlyJITDataModel model) + { + CompileNode root = new CompileNode(methodID); + root.parseDictionary = parseDictionary; + root.model = model; + + return root; + } + + public CompileNode(String methodID) { - this.member = member; this.methodID = methodID; children = new ArrayList<>(); @@ -38,15 +51,14 @@ public String getMethodID() return methodID; } - public IMetaMember getMember() + public void setInlined(boolean inlined) { - return member; + this.inlined = inlined; } - public void setInlined(boolean inlined, String reason) + public void setCompiled(boolean compiled) { - this.inlined = inlined; - this.inlineReason = reason; + this.compiled = compiled; } public boolean isInlined() @@ -54,9 +66,9 @@ public boolean isInlined() return inlined; } - public String getInlineReason() + public boolean isCompiled() { - return inlineReason; + return compiled; } public void addChild(CompileNode child) @@ -75,6 +87,17 @@ public CompileNode getParent() return parent; } + public void setTooltipText(String tooltip) + { + this.tooltip = tooltip; + } + + + public String getTooltipText() + { + return tooltip; + } + @Override public String toString() { @@ -84,10 +107,36 @@ public String toString() return builder.toString(); } + + private CompileNode getRoot() + { + if (parent == null) + { + return this; + } + else + { + return getParent().getRoot(); + } + } + + public IMetaMember getMember() + { + CompileNode root = getRoot(); + + return ParseUtil.lookupMember(methodID, root.parseDictionary, root.model); + } + + public String getMemberName() + { + CompileNode root = getRoot(); + + return ParseUtil.getMethodName(methodID, root.parseDictionary); + } private void show(CompileNode node, StringBuilder builder, int depth) { - if (depth > 0) + if (depth >= 0) { for (int i = 0; i < depth; i++) { @@ -96,11 +145,11 @@ private void show(CompileNode node, StringBuilder builder, int depth) builder.append(" -> "); - builder.append(node.getMember().getMemberName()); + builder.append(node.getMemberName()); - builder.append("["); + builder.append(" ["); - if (node.getMember().isCompiled()) + if (node.isCompiled()) { builder.append("C"); } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/core/IntrinsicFinder.java b/src/main/java/org/adoptopenjdk/jitwatch/core/IntrinsicFinder.java index d9b57fe2..9d04b840 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/core/IntrinsicFinder.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/core/IntrinsicFinder.java @@ -42,13 +42,16 @@ public Map findIntrinsics(IMetaMember member) { result = new HashMap<>(); - try + if (member != null) { - JournalUtil.visitParseTagsOfLastTask(member, this); - } - catch (LogParseException e) - { - logger.error("Error while finding intrinsics", e); + try + { + JournalUtil.visitParseTagsOfLastTask(member.getJournal(), this); + } + catch (LogParseException e) + { + logger.error("Error while finding intrinsics for member {}", member, e); + } } return result; diff --git a/src/main/java/org/adoptopenjdk/jitwatch/histo/InlineSizeHistoVisitable.java b/src/main/java/org/adoptopenjdk/jitwatch/histo/InlineSizeHistoVisitable.java index 26e96473..aade28cd 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/histo/InlineSizeHistoVisitable.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/histo/InlineSizeHistoVisitable.java @@ -48,15 +48,15 @@ public void reset() @Override public void visit(IMetaMember metaMember) { - if (metaMember.isCompiled()) + if (metaMember != null && metaMember.isCompiled()) { try { - JournalUtil.visitParseTagsOfLastTask(metaMember, this); + JournalUtil.visitParseTagsOfLastTask(metaMember.getJournal(), this); } catch (LogParseException e) { - logger.error("Could not build histo", e); + logger.error("Could not build histo for {}", metaMember.getMemberName(), e); } } } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/journal/JournalUtil.java b/src/main/java/org/adoptopenjdk/jitwatch/journal/JournalUtil.java index b8e58150..2aeadb3c 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/journal/JournalUtil.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/journal/JournalUtil.java @@ -42,22 +42,15 @@ private JournalUtil() { } - public static void visitParseTagsOfLastTask(IMetaMember member, IJournalVisitable visitable) throws LogParseException + public static void visitParseTagsOfLastTask(Journal journal, IJournalVisitable visitable) throws LogParseException { - if (member == null) - { - throw new LogParseException("Cannot get Journal for null IMetaMember"); - } - - Journal journal = member.getJournal(); - Task lastTask = getLastTask(journal); if (lastTask == null) { if (!isJournalForCompile2NativeMember(journal)) { - logger.warn("No Task found in Journal for member {}", member); + logger.warn("No Task found in Journal"); if (journal != null && journal.getEntryList().size() > 0) { @@ -88,22 +81,15 @@ public static void visitParseTagsOfLastTask(IMetaMember member, IJournalVisitabl } } - public static void visitOptimizerTagsOfLastTask(IMetaMember member, IJournalVisitable visitable) throws LogParseException + public static void visitOptimizerTagsOfLastTask(Journal journal, IJournalVisitable visitable) throws LogParseException { - if (member == null) - { - throw new LogParseException("Cannot get Journal for null IMetaMember"); - } - - Journal journal = member.getJournal(); - Task lastTask = getLastTask(journal); if (lastTask == null) { if (!isJournalForCompile2NativeMember(journal)) { - logger.warn("No Task found in Journal for member {}", member); + logger.warn("No Task found in Journal"); if (journal != null && journal.getEntryList().size() > 0) { @@ -338,11 +324,11 @@ private static Tag getOptimizerPhase(Task lastTask) int count = parsePhases.size(); - if (count != 1) + if (count > 1) { logger.warn("Unexpected optimizer phase count: {}", count); - } - else + } + else if (count == 1) { optimizerPhase = parsePhases.get(0); } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/IParseDictionary.java b/src/main/java/org/adoptopenjdk/jitwatch/model/IParseDictionary.java index 13719a85..67da6dd6 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/IParseDictionary.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/IParseDictionary.java @@ -18,4 +18,6 @@ public interface IParseDictionary Tag getKlass(String id); Tag getMethod(String id); + + String toString(); } \ No newline at end of file diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/ParseDictionary.java b/src/main/java/org/adoptopenjdk/jitwatch/model/ParseDictionary.java index fb56122c..bbaca2df 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/ParseDictionary.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/ParseDictionary.java @@ -49,4 +49,18 @@ public void setMethod(String id, Tag method) { methodMap.put(id, method); } -} + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("ParseDictionary [typeMap="); + builder.append(typeMap); + builder.append(", klassMap="); + builder.append(klassMap); + builder.append(", methodMap="); + builder.append(methodMap); + builder.append("]"); + return builder.toString(); + } +} \ No newline at end of file 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 119f96bc..81bef749 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BCAnnotationType.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BCAnnotationType.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Chris Newland. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.model.bytecode; public enum BCAnnotationType 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 248e6459..e51111c5 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotationBuilder.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotationBuilder.java @@ -47,7 +47,7 @@ import org.adoptopenjdk.jitwatch.model.IReadOnlyJITDataModel; import org.adoptopenjdk.jitwatch.model.LogParseException; import org.adoptopenjdk.jitwatch.model.Tag; -import org.adoptopenjdk.jitwatch.util.InlineUtil; +import org.adoptopenjdk.jitwatch.util.TooltipUtil; import org.adoptopenjdk.jitwatch.util.ParseUtil; import org.adoptopenjdk.jitwatch.util.StringUtil; import org.slf4j.Logger; @@ -71,34 +71,37 @@ public BytecodeAnnotations buildBytecodeAnnotations(final IMetaMember member, IR bcAnnotations.clear(); - if (!member.isCompiled()) + if (member != null) { - return bcAnnotations; - } - - try - { - JournalUtil.visitParseTagsOfLastTask(member, this); - JournalUtil.visitOptimizerTagsOfLastTask(member, this); - } - catch (LogParseException e) - { - logger.error("Error building bytecode annotations", e); + if (!member.isCompiled()) + { + return bcAnnotations; + } - Throwable cause = e.getCause(); + try + { + JournalUtil.visitParseTagsOfLastTask(member.getJournal(), this); - if (cause != null) + JournalUtil.visitOptimizerTagsOfLastTask(member.getJournal(), this); + } + catch (LogParseException e) { - logger.error("Cause", cause); + logger.error("Error building bytecode annotations", e); - if (cause instanceof AnnotationException) + Throwable cause = e.getCause(); + + if (cause != null) { - throw (AnnotationException) cause; + logger.error("Cause", cause); + + if (cause instanceof AnnotationException) + { + throw (AnnotationException) cause; + } } } } - return bcAnnotations; } @@ -283,8 +286,8 @@ private void visitTagUncommonTrap(Tag tag) } } - private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotations, CompilerName compilerName, IParseDictionary parseDictionary) - throws AnnotationException + private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotations, CompilerName compilerName, + IParseDictionary parseDictionary) throws AnnotationException { if (DEBUG_LOGGING) { @@ -400,7 +403,8 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati } String reason = tagAttrs.get(ATTR_REASON); - String annotationText = InlineUtil.buildInlineAnnotationText(true, reason, callAttrs, methodAttrs, parseDictionary); + String annotationText = TooltipUtil.buildInlineAnnotationText(true, reason, callAttrs, methodAttrs, + parseDictionary); bcAnnotations.addAnnotation(currentBytecode, new LineAnnotation(annotationText, BCAnnotationType.INLINE_SUCCESS)); @@ -418,7 +422,8 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati } String reason = tagAttrs.get(ATTR_REASON); - String annotationText = InlineUtil.buildInlineAnnotationText(false, reason, callAttrs, methodAttrs, parseDictionary); + String annotationText = TooltipUtil.buildInlineAnnotationText(false, reason, callAttrs, methodAttrs, + parseDictionary); bcAnnotations.addAnnotation(currentBytecode, new LineAnnotation(annotationText, BCAnnotationType.INLINE_FAIL)); } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotations.java b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotations.java index f3490569..da05fbb1 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotations.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/BytecodeAnnotations.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Chris Newland. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.model.bytecode; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.DEBUG_LOGGING_BYTECODE; diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/InnerClassRelationship.java b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/InnerClassRelationship.java index 257fc836..bca2e7d1 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/InnerClassRelationship.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/InnerClassRelationship.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Chris Newland. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.model.bytecode; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_DOT; diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/SourceMapper.java b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/SourceMapper.java index aec40508..992cea2a 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/SourceMapper.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/SourceMapper.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Chris Newland. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.model.bytecode; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.DEBUG_LOGGING_TRIVIEW; diff --git a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/UncommonTrap.java b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/UncommonTrap.java index b9da3fa1..141d035c 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/UncommonTrap.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/UncommonTrap.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Chris Newland. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.model.bytecode; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ACTION; @@ -67,11 +72,11 @@ public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("UncommonTrap"); - builder.append("("); + builder.append("Uncommon trap"); + builder.append(" ("); builder.append("reason:"); builder.append(reason); - builder.append(" action:"); + builder.append(", action:"); builder.append(action); if (comment != null) diff --git a/src/main/java/org/adoptopenjdk/jitwatch/suggestion/AttributeSuggestionWalker.java b/src/main/java/org/adoptopenjdk/jitwatch/suggestion/AttributeSuggestionWalker.java index d90dbb10..23db8de7 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/suggestion/AttributeSuggestionWalker.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/suggestion/AttributeSuggestionWalker.java @@ -148,13 +148,13 @@ public AttributeSuggestionWalker(IReadOnlyJITDataModel model) @Override public void visit(IMetaMember metaMember) { - if (metaMember.isCompiled()) + if (metaMember != null && metaMember.isCompiled()) { this.metaMember = metaMember; try { - JournalUtil.visitParseTagsOfLastTask(metaMember, this); + JournalUtil.visitParseTagsOfLastTask(metaMember.getJournal(), this); } catch (LogParseException e) { diff --git a/src/main/java/org/adoptopenjdk/jitwatch/toplist/InliningFailReasonTopListVisitable.java b/src/main/java/org/adoptopenjdk/jitwatch/toplist/InliningFailReasonTopListVisitable.java index b548164a..20080697 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/toplist/InliningFailReasonTopListVisitable.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/toplist/InliningFailReasonTopListVisitable.java @@ -33,11 +33,11 @@ public InliningFailReasonTopListVisitable(IReadOnlyJITDataModel model, boolean s @Override public void visit(IMetaMember metaMember) { - if (metaMember.isCompiled()) + if (metaMember != null && metaMember.isCompiled()) { try { - JournalUtil.visitParseTagsOfLastTask(metaMember, this); + JournalUtil.visitParseTagsOfLastTask(metaMember.getJournal(), this); } catch (LogParseException e) { diff --git a/src/main/java/org/adoptopenjdk/jitwatch/ui/CompileChainStage.java b/src/main/java/org/adoptopenjdk/jitwatch/ui/CompileChainStage.java index e30b688d..80f7eb7e 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/ui/CompileChainStage.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/ui/CompileChainStage.java @@ -5,7 +5,6 @@ */ package org.adoptopenjdk.jitwatch.ui; -import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_NEWLINE; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; @@ -22,7 +21,6 @@ import javafx.stage.WindowEvent; import org.adoptopenjdk.jitwatch.chain.CompileNode; -import org.adoptopenjdk.jitwatch.model.IMetaMember; import org.adoptopenjdk.jitwatch.util.UserInterfaceUtil; public class CompileChainStage extends Stage @@ -64,8 +62,8 @@ public CompileChainStage(final JITWatchUI parent, CompileNode root) scrollPane.setContent(pane); Scene scene = UserInterfaceUtil.getScene(scrollPane, JITWatchUI.WINDOW_WIDTH, JITWatchUI.WINDOW_HEIGHT); - - setTitle("Compile Chain: " + root.getMember().toString()); + + setTitle("Compile Chain: " + root.getMemberName()); setScene(scene); @@ -89,7 +87,9 @@ public void redraw() if (rootNode.getChildren().size() == 0) { - Text text = new Text("No method calls made by " + rootNode.getMember().toStringUnqualifiedMethodName(false) + " were inlined or JIT compiled"); + + + Text text = new Text("No method calls made by " + rootNode.getMemberName() + " were inlined or JIT compiled"); text.setX(X_OFFSET); text.setY(y); @@ -152,16 +152,16 @@ private void show(CompileNode node, double x, double parentY, int depth) private String getLabelText(CompileNode node) { - IMetaMember member = node.getMember(); + String memberName = node.getMemberName(); - return member == null ? "Unknown" : member.getMemberName(); + return memberName == null ? "Unknown" : memberName; } private double plotNode(final CompileNode node, final double x, final double parentY, final int depth) { String labelText = getLabelText(node); - PlotNode plotNode = buildNode(labelText, x, y, node.isInlined(), node.getMember().isCompiled()); + PlotNode plotNode = buildNode(labelText, x, y, node.isInlined(), node.isCompiled()); if (depth > 0) { @@ -185,7 +185,7 @@ private double plotNode(final CompileNode node, final double x, final double par initialiseRectWithOnMouseClickedEventHandler(node, plotNode.rect); initialiseRectWithOnMouseClickedEventHandler(node, plotNode.text); - Tooltip tip = new Tooltip(getToolTipText(node)); + Tooltip tip = new Tooltip(node.getTooltipText()); Tooltip.install(plotNode.rect, tip); Tooltip.install(plotNode.text, tip); @@ -228,34 +228,6 @@ private PlotNode buildNode(String labelText, double x, double y, boolean inlined return result; } - private String getToolTipText(CompileNode node) - { - StringBuilder tipBuilder = new StringBuilder(); - tipBuilder.append(node.getMember().toString()).append(C_NEWLINE); - - tipBuilder.append("JIT Compiled: "); - - if (node.getMember().isCompiled()) - { - tipBuilder.append("Yes\n"); - } - else - { - tipBuilder.append("No\n"); - } - - String inlineReason = node.getInlineReason(); - - if (inlineReason != null) - { - tipBuilder.append(inlineReason); - } - - tipBuilder.append(C_NEWLINE); - - return tipBuilder.toString(); - } - private Color getColourForCompilation(boolean isCompiled) { if (isCompiled) diff --git a/src/main/java/org/adoptopenjdk/jitwatch/ui/JITWatchUI.java b/src/main/java/org/adoptopenjdk/jitwatch/ui/JITWatchUI.java index 452f2ea1..775d68fd 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/ui/JITWatchUI.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/ui/JITWatchUI.java @@ -854,11 +854,11 @@ public void openTextViewer(String title, String content) public void openCompileChain(IMetaMember member) { - if (member.isCompiled()) + if (member != null && member.isCompiled()) { CompileChainWalker walker = new CompileChainWalker(logParser.getModel()); - CompileNode root = walker.buildCallTree(member); + CompileNode root = walker.buildCallTree(member.getJournal()); if (root != 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 ac9a9497..ee6d4047 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 @@ -109,7 +109,7 @@ public void setContent(final IMetaMember member) { offsetMismatchDetected = false; instructions.clear(); - + ClassBC metaClassBytecode = member.getMetaClass().getClassBytecode(); if (metaClassBytecode != null) @@ -118,7 +118,7 @@ public void setContent(final IMetaMember member) if (memberBytecode != null) { - instructions = memberBytecode.getInstructions(); + instructions.addAll(memberBytecode.getInstructions()); } } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/util/ParseUtil.java b/src/main/java/org/adoptopenjdk/jitwatch/util/ParseUtil.java index 0085a092..97f5b9e2 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/util/ParseUtil.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/util/ParseUtil.java @@ -852,6 +852,22 @@ public static List getMethodTagArguments(Tag methodTag, IParseDictionary return result; } + + public static String getMethodName(String methodID, IParseDictionary parseDictionary) + { + String result = null; + + Tag methodTag = parseDictionary.getMethod(methodID); + + if (methodTag != null) + { + String methodName = methodTag.getAttribute(ATTR_NAME); + + result = StringUtil.replaceXMLEntities(methodName); + } + + return result; + } public static IMetaMember lookupMember(String methodId, IParseDictionary parseDictionary, IReadOnlyJITDataModel model) { @@ -955,32 +971,22 @@ public static String lookupType(String typeOrKlassID, IParseDictionary parseDict { String result = null; - // logger.debug("Looking up type: {}", typeOrKlassID); - if (typeOrKlassID != null) { Tag typeTag = parseDictionary.getType(typeOrKlassID); - - // logger.debug("Type? {}", typeTag); - + if (typeTag == null) { typeTag = parseDictionary.getKlass(typeOrKlassID); - - // logger.debug("Klass? {}", typeTag); } if (typeTag != null) { String typeAttrName = typeTag.getAttribute(ATTR_NAME); - // logger.debug("Name {}", typeAttrName); - if (typeAttrName != null) { result = typeAttrName.replace(S_SLASH, S_DOT); - - result = ParseUtil.expandParameterType(result); } } } diff --git a/src/main/java/org/adoptopenjdk/jitwatch/util/InlineUtil.java b/src/main/java/org/adoptopenjdk/jitwatch/util/TooltipUtil.java similarity index 87% rename from src/main/java/org/adoptopenjdk/jitwatch/util/InlineUtil.java rename to src/main/java/org/adoptopenjdk/jitwatch/util/TooltipUtil.java index 031290e9..d79d18f1 100644 --- a/src/main/java/org/adoptopenjdk/jitwatch/util/InlineUtil.java +++ b/src/main/java/org/adoptopenjdk/jitwatch/util/TooltipUtil.java @@ -6,6 +6,7 @@ package org.adoptopenjdk.jitwatch.util; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_BYTES; +import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_ID; 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; @@ -17,9 +18,9 @@ import org.adoptopenjdk.jitwatch.model.IParseDictionary; -public final class InlineUtil +public final class TooltipUtil { - private InlineUtil() + private TooltipUtil() { } @@ -33,6 +34,18 @@ public static String buildInlineAnnotationText(boolean inlined, String reason, M builder.append("Class: ").append(ParseUtil.lookupType(holder, parseDictionary)).append(S_NEWLINE); builder.append("Method: ").append(methodName).append(S_NEWLINE); + + builder.append("JIT Compiled: "); + + if (methodAttrs.containsKey(ATTR_COMPILE_ID)) + { + builder.append("Yes\n"); + } + else + { + builder.append("No\n"); + } + builder.append("Inlined: "); if (inlined) diff --git a/src/main/resources/examples/InliningChains.java b/src/main/resources/examples/InliningChains.java new file mode 100644 index 00000000..5a6d381a --- /dev/null +++ b/src/main/resources/examples/InliningChains.java @@ -0,0 +1,121 @@ +public class InliningChains +{ + public static void main(String[] args) + { + new InliningChains(); + } + + public InliningChains() + { + long count = 0; + + for (int i = 0; i < 100_000; i++) + { + count = chainA1(count); + count = chainB1(count); + } + + System.out.println("InliningChains: " + count); + } + + private long chainA1(long count) + { + return 1 + chainA2(count); + } + + private long chainA2(long count) + { + return 2 + chainA3(count); + } + + private long chainA3(long count) + { + return 3 + chainA4(count); + } + + private long chainA4(long count) + { + // last link will not be inlined + return bigMethod(count, 4); + } + + private long chainB1(long count) + { + return chainB2(count) - 1; + } + + private long chainB2(long count) + { + return chainB3(count) - 2; + } + + private long chainB3(long count) + { + return count - 3; + } + + private long bigMethod(long count, int i) + { + long a, b, c, d, e, f, g; + + a = count; + b = count; + c = count; + d = count; + e = count; + f = count; + g = count; + + a += i; + b += i; + c += i; + d += i; + e += i; + f += i; + g += i; + + a += 1; + b += 2; + c += 3; + d += 4; + e += 5; + f += 6; + g += 7; + + a += i; + b += i; + c += i; + d += i; + e += i; + f += i; + g += i; + + a -= 7; + b -= 6; + c -= 5; + d -= 4; + e -= 3; + f -= 2; + g -= 1; + + a++; + b++; + c++; + d++; + e++; + f++; + g++; + + a /= 2; + b /= 2; + c /= 2; + d /= 2; + e /= 2; + f /= 2; + g /= 2; + + long result = a + b + c + d + e + f + g; + + return result; + } +} \ No newline at end of file diff --git a/src/test/java/org/adoptopenjdk/jitwatch/test/HelperMetaMethod.java b/src/test/java/org/adoptopenjdk/jitwatch/test/HelperMetaMethod.java index 190db412..f04b4c3b 100644 --- a/src/test/java/org/adoptopenjdk/jitwatch/test/HelperMetaMethod.java +++ b/src/test/java/org/adoptopenjdk/jitwatch/test/HelperMetaMethod.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Chris Newland. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.test; import java.lang.reflect.Method; diff --git a/src/test/java/org/adoptopenjdk/jitwatch/test/TestAssemblyLabels.java b/src/test/java/org/adoptopenjdk/jitwatch/test/TestAssemblyLabels.java index a2416ac8..a4ecff3f 100644 --- a/src/test/java/org/adoptopenjdk/jitwatch/test/TestAssemblyLabels.java +++ b/src/test/java/org/adoptopenjdk/jitwatch/test/TestAssemblyLabels.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Philip Aston. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.test; import static java.util.Arrays.asList; diff --git a/src/test/java/org/adoptopenjdk/jitwatch/test/TestCompileChain.java b/src/test/java/org/adoptopenjdk/jitwatch/test/TestCompileChain.java index 13dd9ef4..d4afcb4f 100644 --- a/src/test/java/org/adoptopenjdk/jitwatch/test/TestCompileChain.java +++ b/src/test/java/org/adoptopenjdk/jitwatch/test/TestCompileChain.java @@ -5,36 +5,156 @@ */ package org.adoptopenjdk.jitwatch.test; -import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_TYPE_NAME_VOID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.HashMap; +import static org.junit.Assert.*; import java.util.List; import org.adoptopenjdk.jitwatch.chain.CompileChainWalker; import org.adoptopenjdk.jitwatch.chain.CompileNode; import org.adoptopenjdk.jitwatch.core.TagProcessor; -import org.adoptopenjdk.jitwatch.model.IMetaMember; import org.adoptopenjdk.jitwatch.model.JITDataModel; import org.adoptopenjdk.jitwatch.model.Journal; -import org.adoptopenjdk.jitwatch.model.MemberSignatureParts; -import org.adoptopenjdk.jitwatch.model.MetaClass; import org.adoptopenjdk.jitwatch.model.Tag; -import org.adoptopenjdk.jitwatch.util.ClassUtil; import org.adoptopenjdk.jitwatch.util.StringUtil; import org.junit.Test; public class TestCompileChain { + @Test + public void testRegressionTwoInlinesC2() throws Exception + { + String[] lines = new String[] { + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" }; + + CompileNode root = buildCompileNodeForXML(lines); + + // root + // -> deposit() + // -> deposit() + + List rootChildren = root.getChildren(); + + assertEquals(2, rootChildren.size()); + + CompileNode child0 = rootChildren.get(0); + CompileNode child1 = rootChildren.get(1); + + assertEquals("deposit", child0.getMemberName()); + assertTrue(child0.isInlined()); + + assertEquals("deposit", child1.getMemberName()); + assertTrue(child1.isInlined()); + } - // test disabled until I remove the workaround for broken Tiered logs in J8 public void testJava8TieredCompilation() throws Exception { - String[] lines = new String[]{ + String[] lines = new String[] { "", "", "", @@ -153,55 +273,32 @@ public void testJava8TieredCompilation() throws Exception "", "", "", - "" - }; - - JITDataModel testModel = new JITDataModel(); - String fqClassName = "org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog"; - String methodName = "testCallChain3"; - - try - { - testModel.buildAndGetMetaClass(ClassUtil.loadClassWithoutInitialising(fqClassName)); - - String fqClassNameSB = "java.lang.AbstractStringBuilder"; - testModel.buildAndGetMetaClass(ClassUtil.loadClassWithoutInitialising(fqClassNameSB)); - } - catch (ClassNotFoundException cnfe) - { - fail(); - } - - MetaClass metaClass = testModel.getPackageManager().getMetaClass(fqClassName); - - MemberSignatureParts msp = MemberSignatureParts.fromLogCompilationSignature("org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog " + methodName + " ()V"); - - IMetaMember testMember = metaClass.getMemberForSignature(msp); - - CompileNode root = buildCompileNodeForXML(lines, testMember, testModel); + "" }; -// private void testCallChain3() -// { -// long count = 0; -// int iterations = 100_000; -// for (int i = 0; i < iterations; i++) -// { -// if (test(i, iterations)) -// { -// count = chainC1(count); -// } -// else -// { -// count = chainC2(count); -// } -// } -// System.out.println("testCallChain2: " + count); -// } + CompileNode root = buildCompileNodeForXML(lines); + + // private void testCallChain3() + // { + // long count = 0; + // int iterations = 100_000; + // for (int i = 0; i < iterations; i++) + // { + // if (test(i, iterations)) + // { + // count = chainC1(count); + // } + // else + // { + // count = chainC2(count); + // } + // } + // System.out.println("testCallChain2: " + count); + // } // root // -> test() // -> chainC1() -> chainC2() - // -> chainC3() + // -> chainC3() // -> chainC2() // -> java.lang.AbstractStringBuilder() -> java.lang.Object() // -> append() @@ -215,14 +312,14 @@ public void testJava8TieredCompilation() throws Exception int pos = 0; - assertEquals("test", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("chainC1", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("chainC2", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("java.lang.AbstractStringBuilder", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("append", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("append", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("toString", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("println", rootChildren.get(pos++).getMember().getMemberName()); + assertEquals("test", rootChildren.get(pos++).getMemberName()); + assertEquals("chainC1", rootChildren.get(pos++).getMemberName()); + assertEquals("chainC2", rootChildren.get(pos++).getMemberName()); + assertEquals("java.lang.AbstractStringBuilder", rootChildren.get(pos++).getMemberName()); + assertEquals("append", rootChildren.get(pos++).getMemberName()); + assertEquals("append", rootChildren.get(pos++).getMemberName()); + assertEquals("toString", rootChildren.get(pos++).getMemberName()); + assertEquals("println", rootChildren.get(pos++).getMemberName()); } @Test @@ -421,60 +518,83 @@ public void testJava7LateInlineRegression() "", "", "", - "" - }; - - JITDataModel testModel = new JITDataModel(); - - String methodName = "testCallChain"; - String fqClassName = "org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog"; - - try - { - testModel.buildAndGetMetaClass(ClassUtil.loadClassWithoutInitialising(fqClassName)); - - String fqClassNameSB = "java.lang.AbstractStringBuilder"; - testModel.buildAndGetMetaClass(ClassUtil.loadClassWithoutInitialising(fqClassNameSB)); - } - catch (ClassNotFoundException cnfe) - { - fail(); - } - - List paramList = new ArrayList<>(); - paramList.add("long"); - - MetaClass metaClass = testModel.getPackageManager().getMetaClass(fqClassName); - IMetaMember testMember = metaClass.getMemberForSignature(MemberSignatureParts.fromParts(fqClassName, methodName, S_TYPE_NAME_VOID, paramList)); - - assertNotNull(testMember); + "" }; - CompileNode root = buildCompileNodeForXML(lines, testMember, testModel); + CompileNode root = buildCompileNodeForXML(lines); // root // -> chainA1() -> chainA2() -> chainA3() -> chainA4() -> bigMethod() // -> chainB1() -> chainB2() -> chainB3() + // -> java.lang.AbstractStringBuilder() -> java.lang.Object() // -> append() // -> append() // -> toString() // -> println // -> java.lang.AbstractStringBuilder() -> java.lang.Object() - + List rootChildren = root.getChildren(); - assertEquals(7, rootChildren.size()); + assertEquals(8, rootChildren.size()); - int pos = 0; + CompileNode child0 = rootChildren.get(0); + CompileNode child1 = rootChildren.get(1); + CompileNode child2 = rootChildren.get(2); + CompileNode child3 = rootChildren.get(3); + CompileNode child4 = rootChildren.get(4); + CompileNode child5 = rootChildren.get(5); + CompileNode child6 = rootChildren.get(6); + CompileNode child7 = rootChildren.get(7); - assertEquals("chainA1", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("chainB1", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("append", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("append", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("toString", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("println", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("java.lang.AbstractStringBuilder", rootChildren.get(pos++).getMember().getMemberName()); - } + assertEquals("chainA1", child0.getMemberName()); + assertTrue(child0.isInlined()); + + assertEquals("chainB1", child1.getMemberName()); + assertTrue(child1.isInlined()); + + assertEquals("", child2.getMemberName()); + assertTrue(child2.isInlined()); + + assertEquals("append", child3.getMemberName()); + assertTrue(!child3.isInlined()); + + assertEquals("append", child4.getMemberName()); + assertTrue(!child4.isInlined()); + + assertEquals("toString", child5.getMemberName()); + assertTrue(!child5.isInlined()); + + assertEquals("println", child6.getMemberName()); + assertTrue(!child6.isInlined()); + + assertEquals("", child7.getMemberName()); + assertTrue(child7.isInlined()); + + List child0Children = child0.getChildren(); + assertEquals(1, child0Children.size()); + CompileNode child0child0 = child0Children.get(0); + assertEquals("chainA2", child0child0.getMemberName()); + assertTrue(child0child0.isInlined()); + + List child0child0Children = child0child0.getChildren(); + assertEquals(1, child0child0Children.size()); + CompileNode child0child0child0 = child0child0Children.get(0); + assertEquals("chainA3", child0child0child0.getMemberName()); + assertTrue(child0child0child0.isInlined()); + + List child0child0child0Children = child0child0child0.getChildren(); + assertEquals(1, child0child0child0Children.size()); + CompileNode child0child0child0child0 = child0child0child0Children.get(0); + assertEquals("chainA4", child0child0child0child0.getMemberName()); + assertTrue(child0child0child0child0.isInlined()); + + List child0child0child0child0Children = child0child0child0child0.getChildren(); + assertEquals(1, child0child0child0child0Children.size()); + CompileNode child0child0child0child0child0 = child0child0child0child0Children.get(0); + assertEquals("bigMethod", child0child0child0child0child0.getMemberName()); + assertTrue(!child0child0child0child0child0.isInlined()); + + } @Test public void testJava8LateInlineRegression() @@ -620,87 +740,135 @@ public void testJava8LateInlineRegression() "", "", "", - "", "", - "", "", - "", "", - "", "", "", - "", "", - "", "", - "", "", "", - "", "", - "", "", - "", "", "", - "", "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", "", - "", "", - "", "", - "", "", "", - "", "", - "", "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", "", - "", "", - "", "", - "", "", + "", + "", + "", + "", + "", + "", "", - "", "", - "", "", + "", + "", + "", + "", "", "", "", "" }; - JITDataModel testModel = new JITDataModel(); - - String methodName = "testCallChain"; - String fqClassName = "org.adoptopenjdk.jitwatch.demo.MakeHotSpotLog"; - - try - { - testModel.buildAndGetMetaClass(ClassUtil.loadClassWithoutInitialising(fqClassName)); - - String fqClassNameSB = "java.lang.AbstractStringBuilder"; - testModel.buildAndGetMetaClass(ClassUtil.loadClassWithoutInitialising(fqClassNameSB)); - } - catch (ClassNotFoundException cnfe) - { - fail(); - } - - List paramList = new ArrayList<>(); - paramList.add("long"); - - MetaClass metaClass = testModel.getPackageManager().getMetaClass(fqClassName); - IMetaMember testMember = metaClass.getMemberForSignature(MemberSignatureParts.fromParts(fqClassName, methodName, S_TYPE_NAME_VOID, paramList)); - - assertNotNull(testMember); - - CompileNode root = buildCompileNodeForXML(lines, testMember, testModel); + CompileNode root = buildCompileNodeForXML(lines); // root // -> chainA1() -> chainA2() -> chainA3() -> chainA4() -> bigMethod() // -> chainB1() -> chainB2() -> chainB3() + // -> java.lang.AbstractStringBuilder() -> java.lang.Object() // -> append() // -> append() // -> toString() // -> println // -> java.lang.AbstractStringBuilder() -> java.lang.Object() - + List rootChildren = root.getChildren(); - assertEquals(7, rootChildren.size()); - - int pos = 0; + assertEquals(8, rootChildren.size()); - assertEquals("chainA1", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("chainB1", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("append", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("append", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("toString", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("println", rootChildren.get(pos++).getMember().getMemberName()); - assertEquals("java.lang.AbstractStringBuilder", rootChildren.get(pos++).getMember().getMemberName()); + CompileNode child0 = rootChildren.get(0); + CompileNode child1 = rootChildren.get(1); + CompileNode child2 = rootChildren.get(2); + CompileNode child3 = rootChildren.get(3); + CompileNode child4 = rootChildren.get(4); + CompileNode child5 = rootChildren.get(5); + CompileNode child6 = rootChildren.get(6); + CompileNode child7 = rootChildren.get(7); + + assertEquals("chainA1", child0.getMemberName()); + assertTrue(child0.isInlined()); + + assertEquals("chainB1", child1.getMemberName()); + assertTrue(child1.isInlined()); + + assertEquals("", child2.getMemberName()); + assertTrue(child2.isInlined()); + + assertEquals("append", child3.getMemberName()); + assertTrue(!child3.isInlined()); + + assertEquals("append", child4.getMemberName()); + assertTrue(!child4.isInlined()); + + assertEquals("toString", child5.getMemberName()); + assertTrue(!child5.isInlined()); + + assertEquals("println", child6.getMemberName()); + assertTrue(!child6.isInlined()); + + assertEquals("", child7.getMemberName()); + assertTrue(child7.isInlined()); + + List child0Children = child0.getChildren(); + assertEquals(1, child0Children.size()); + CompileNode child0child0 = child0Children.get(0); + assertEquals("chainA2", child0child0.getMemberName()); + assertTrue(child0child0.isInlined()); + + List child0child0Children = child0child0.getChildren(); + assertEquals(1, child0child0Children.size()); + CompileNode child0child0child0 = child0child0Children.get(0); + assertEquals("chainA3", child0child0child0.getMemberName()); + assertTrue(child0child0child0.isInlined()); + + List child0child0child0Children = child0child0child0.getChildren(); + assertEquals(1, child0child0child0Children.size()); + CompileNode child0child0child0child0 = child0child0child0Children.get(0); + assertEquals("chainA4", child0child0child0child0.getMemberName()); + assertTrue(child0child0child0child0.isInlined()); + + List child0child0child0child0Children = child0child0child0child0.getChildren(); + assertEquals(1, child0child0child0child0Children.size()); + CompileNode child0child0child0child0child0 = child0child0child0child0Children.get(0); + assertEquals("bigMethod", child0child0child0child0child0.getMemberName()); + assertTrue(!child0child0child0child0child0.isInlined()); } - private CompileNode buildCompileNodeForXML(String[] lines, IMetaMember member, JITDataModel model) + private CompileNode buildCompileNodeForXML(String[] lines) { TagProcessor tp = new TagProcessor(); @@ -712,7 +880,7 @@ private CompileNode buildCompileNodeForXML(String[] lines, IMetaMember member, J { line = line.trim(); line = StringUtil.replaceXMLEntities(line); - + tag = tp.processLine(line); if (count++ < lines.length - 1) @@ -723,18 +891,15 @@ private CompileNode buildCompileNodeForXML(String[] lines, IMetaMember member, J assertNotNull(tag); - member.setCompiledAttributes(new HashMap()); - - Journal journal = member.getJournal(); + Journal journal = new Journal(); journal.addEntry(tag); - CompileChainWalker walker = new CompileChainWalker(model); + CompileChainWalker walker = new CompileChainWalker(new JITDataModel()); - CompileNode root = walker.buildCallTree(member); + CompileNode root = walker.buildCallTree(journal); assertNotNull(root); return root; - } } \ No newline at end of file diff --git a/src/test/java/org/adoptopenjdk/jitwatch/test/TestResourceLoader.java b/src/test/java/org/adoptopenjdk/jitwatch/test/TestResourceLoader.java index f103c33d..a091cbd8 100644 --- a/src/test/java/org/adoptopenjdk/jitwatch/test/TestResourceLoader.java +++ b/src/test/java/org/adoptopenjdk/jitwatch/test/TestResourceLoader.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2013, 2014 Chris Newland. + * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD + * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki + */ package org.adoptopenjdk.jitwatch.test; import static org.junit.Assert.*;