-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
IntrinsicFinder.java
119 lines (98 loc) · 3.11 KB
/
IntrinsicFinder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* 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.core;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_HOLDER;
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_NAME;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_DOT;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_SLASH;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_CALL;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_INTRINSIC;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_METHOD;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.LogParseException;
import org.adoptopenjdk.jitwatch.model.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class IntrinsicFinder implements IJournalVisitable
{
private Map<String, String> result;
private static final Logger logger = LoggerFactory.getLogger(IntrinsicFinder.class);
public IntrinsicFinder()
{
}
public Map<String, String> findIntrinsics(IMetaMember member)
{
result = new HashMap<>();
if (member != null)
{
try
{
JournalUtil.visitParseTagsOfLastTask(member.getJournal(), this);
}
catch (LogParseException e)
{
logger.error("Error while finding intrinsics for member {}", member, e);
}
}
return result;
}
@Override
public void visitTag(Tag parseTag, IParseDictionary parseDictionary) throws LogParseException
{
String currentMethod = null;
String holder = null;
List<Tag> allChildren = parseTag.getChildren();
for (Tag childTag : allChildren)
{
String tagName = childTag.getName();
Map<String, String> attrs = childTag.getAttrs();
switch (tagName)
{
case TAG_METHOD:
{
currentMethod = attrs.get(ATTR_NAME);
holder = attrs.get(ATTR_HOLDER);
}
break;
// changes member context
case TAG_CALL:
{
String methodID = attrs.get(ATTR_METHOD);
Tag methodTag = parseDictionary.getMethod(methodID);
currentMethod = methodTag.getAttribute(ATTR_NAME);
holder = methodTag.getAttribute(ATTR_HOLDER);
}
break;
case TAG_INTRINSIC:
{
if (holder != null && currentMethod != null)
{
Tag klassTag = parseDictionary.getKlass(holder);
String intrinsic = childTag.getAttribute(ATTR_ID);
if (klassTag != null)
{
String fqName = klassTag.getAttribute(ATTR_NAME).replace(C_SLASH, C_DOT) + C_DOT + currentMethod;
result.put(fqName, intrinsic);
}
}
holder = null;
currentMethod = null;
break;
}
default:
break;
}
}
}
}