org.adoptopenjdk.jitwatch.model.bytecode.BytecodeAnnotations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jitwatch-jarscan-maven-plugin Show documentation
Show all versions of jitwatch-jarscan-maven-plugin Show documentation
A Maven plugin that scans the project artifact and its dependencies for methods that cannot be inlined by the JIT
compiler. It uses the JarScan utility from the JITWatch project to do that.
See https://github.com/AdoptOpenJDK/jitwatch .
/*
* 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;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_COLON;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_SPACE;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BytecodeAnnotations
{
private static final Logger logger = LoggerFactory.getLogger(BytecodeAnnotations.class);
private Map> annotationMap = new HashMap<>();
public void addAnnotation(int bci, LineAnnotation annotation)
{
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("BCI: {} Annotation: {}", bci, annotation.getAnnotation());
}
List existingAnnotations = annotationMap.get(bci);
if (existingAnnotations == null)
{
existingAnnotations = new ArrayList<>();
annotationMap.put(bci, existingAnnotations);
}
existingAnnotations.add(annotation);
}
public List getAnnotationsForBCI(int bci)
{
return annotationMap.get(bci);
}
public boolean hasAnnotationsForBCI(int bci)
{
return annotationMap.containsKey(bci);
}
public void clear()
{
annotationMap.clear();
}
public int annotatedLineCount()
{
return annotationMap.size();
}
public String toString()
{
StringBuilder builder = new StringBuilder();
for (Map.Entry> entry : annotationMap.entrySet())
{
for (LineAnnotation annotation : entry.getValue())
{
builder.append(entry.getKey()).append(S_SPACE).append(S_COLON).append(S_SPACE);
builder.append(annotation.toString()).append(S_NEWLINE).append(S_NEWLINE);
}
}
return builder.toString();
}
}